[LON-CAPA-cvs] cvs: loncom /interface lonparmset.pm

neumanie neumanie@source.lon-capa.org
Wed, 17 Jun 2009 20:01:58 -0000


neumanie		Wed Jun 17 20:01:58 2009 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  Change the view in "Select Enclosing Map or Folder" to a tree view. The tree view was implement in the function mapmenu.
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.460 loncom/interface/lonparmset.pm:1.461
--- loncom/interface/lonparmset.pm:1.460	Wed Jun 10 16:06:13 2009
+++ loncom/interface/lonparmset.pm	Wed Jun 17 20:01:57 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.460 2009/06/10 16:06:13 bisitz Exp $
+# $Id: lonparmset.pm,v 1.461 2009/06/17 20:01:57 neumanie Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1589,17 +1589,57 @@
 
 sub mapmenu {
     my ($r,$allmaps,$pschp,$maptitles)=@_;
-
+    my $navmap = Apache::lonnavmaps::navmap->new();
+    my $tree=[];
+    my $treeinfo={};
+    if (defined($navmap)) {
+        my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
+        my $curRes;
+        my $depth = 0;
+
+        while ($curRes = $it->next()) {
+            if ($curRes == $it->BEGIN_MAP()) {
+                $depth++;
+            }
+            if ($curRes == $it->END_MAP()) {
+                $depth--;
+            }
+            if (ref($curRes)) {
+                if (($curRes->is_sequence()) || ($curRes->is_page())) {
+                    my $type = 'sequence';
+                    if ($curRes->is_page()) {
+                        $type = 'page';
+                    }
+                    my $id= $curRes->id();
+                    my ($mapid,$resid)=split(/\./,$id);
+                    push(@$tree,$mapid);
+                    $treeinfo->{$mapid} = {
+                                    depth => $depth,
+                                    type  => $type,
+                                    };
+                }
+            }
+        }
+    }	
     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Enclosing Map or Folder')));
-    $r->print('<select name="pschp">');
-    $r->print('<option value="all">'.&mt('All Maps or Folders').'</option>');
-    foreach (sort {$$allmaps{$a} cmp $$allmaps{$b}} keys %{$allmaps}) {
-	$r->print('<option value="'.$_.'"');
-	if (($pschp eq $_)) { $r->print(' selected="selected"'); }
-	$r->print('>'.$$maptitles{$_}.($$allmaps{$_}!~/^uploaded/?' ['.$$allmaps{$_}.']':'').'</option>');
+    if ((ref($tree) eq 'ARRAY') && (ref($treeinfo) eq 'HASH')) {
+        my $icon = '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
+        $r->print('<table><tr><td>'.$icon.'<label>&nbsp;<input type="radio" name="pschp" value="all"/>'.&mt('All Maps or Folders').'</td></tr>');
+        foreach my $mapid (@{$tree}) {
+            my $depth = $treeinfo->{$mapid}->{'depth'};
+            my $indent = ('&nbsp;'x$depth);
+            $icon =  '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
+            if ($treeinfo->{$mapid}->{'type'} eq 'page') {
+                $icon = '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" />';
+            }
+            $r->print('<tr><td>'.$indent.$icon.'<label>&nbsp;<input type ="radio" name="pschp" value="'.$mapid.'"');
+            if ($pschp eq $mapid) {
+                $r->print(' checked="checked"');
+            }
+            $r->print('/>'.$$maptitles{$mapid}.($$allmaps{$mapid}!~/^uploaded/?' ['.$$allmaps{$mapid}.']':'').'</label></td></tr>');
+        }
+        $r->print('</table>');
     }
-    $r->print("</select>");
-
 }
 
 sub levelmenu {