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

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 13 Aug 2004 22:08:16 -0000


albertel		Fri Aug 13 18:08:16 2004 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  - okay much sexier now.
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.275 loncom/interface/lonnavmaps.pm:1.276
--- loncom/interface/lonnavmaps.pm:1.275	Fri Aug 13 16:12:11 2004
+++ loncom/interface/lonnavmaps.pm	Fri Aug 13 18:08:16 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.275 2004/08/13 20:12:11 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.276 2004/08/13 22:08:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -100,7 +100,7 @@
     }
     if ($mode eq 'link') {
 	$result.='<a href="javascript:launch_navmapwin();void(0);">'
-	    .&mt("Launch navigation in separate window")."</a> ";
+	    .&mt("Launch navigation window")."</a>&nbsp;&nbsp;&nbsp;&nbsp;";
     }
     return $result;
 }
@@ -206,7 +206,7 @@
     $r->print("<html><head>\n");
     $r->print("<title>".&mt('Navigate Course Contents')."</title>");
 # ------------------------------------------------------------ Get query string
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register','sort']);
+    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register','sort','showOnlyHomework']);
     
 # ----------------------------------------------------- Force menu registration
     my $addentries='';
@@ -286,7 +286,7 @@
     if ($ENV{'environment.remotenavmap'} eq 'on') {
 #        $r->print("<a href='navmaps?collapseExternal'>" .
         $r->print("<a href='javascript:collapse();void(0);'>" .
-		  &mt("Close separate navigation window").
+		  &mt("Close navigation window").
 		  "</a>&nbsp;&nbsp;&nbsp;&nbsp;");
     } 
 
@@ -335,30 +335,33 @@
 
     # Display only due homework.
     my $showOnlyHomework = 0;
-    if ($ENV{QUERY_STRING} eq 'showOnlyHomework') {
+    if ($ENV{'form.showOnlyHomework'} eq "1") {
         $showOnlyHomework = 1;
         $suppressEmptySequences = 1;
         $filterFunc = sub { my $res = shift; 
                             return $res->completable() || $res->is_map();
                         };
+        $r->print("<a href='navmaps?sort=$ENV{'form.sort'}'>" .
+		  &mt("Show Everything")."</a>&nbsp;&nbsp;&nbsp;&nbsp;");
         $r->print("<p><font size='+2'>".&mt("Uncompleted Homework")."</font></p>");
         $ENV{'form.filter'} = '';
         $ENV{'form.condition'} = 1;
 	$resource_no_folder_link = 1;
     } else {
-        $r->print("<a href='navmaps?showOnlyHomework'>" .
+        $r->print("<a href='navmaps?sort=$ENV{'form.sort'}&showOnlyHomework=1'>" .
        &mt("Show Only Uncompleted Homework")."</a>&nbsp;&nbsp;&nbsp;&nbsp;");
     }
 
-    $r->print("<form>
+    my %selected=($ENV{'form.sort'} => 'selected=on');
+    my $sort_html=("<form>
                  <nobr>
-                    Sort by:
+                    <input type=\"hidden\" name=\"showOnlyHomework\" value=\"".$ENV{'form.showOnlyHomework'}."\" />
+                    <input type=\"submit\" value=\"".&mt('Sort by:')."\" />
                     <select name=\"sort\">
-                       <option value=\"\"></option>
-                       <option value=\"title\">Title</option>
-                       <option value=\"duedate\">Duedate</option>
+                       <option value=\"default\" $selected{'default'}>".&mt('Default')."</option>
+                       <option value=\"title\"   $selected{'title'}  >".&mt('Title')."</option>
+                       <option value=\"duedate\" $selected{'duedate'}>".&mt('Duedate')."</option>
                     </select>
-                    <input type=\"submit\" name=\"Sort\" />
                  </nobr>
                </form>");
     # renderer call
@@ -370,6 +373,7 @@
                        'suppressEmptySequences' => $suppressEmptySequences,
                        'filterFunc' => $filterFunc,
 		       'resource_no_folder_link' => $resource_no_folder_link,
+		       'sort_html'=> $sort_html,
                        'r' => $r};
     my $render = render($renderArgs);
     $navmap->untieHashes();
@@ -1381,10 +1385,7 @@
             #$currenturl=~s/^[^\/]+//;
             
             $here = $jump = &Apache::lonnet::symbread($currenturl);
-        } else {
-	    &Apache::lonnet::logthis("Hrrm,");
-	    
-	}
+        }
 
         # Step three: Ensure the folders are open
         my $mapIterator = $navmap->getIterator(undef, undef, undef, 1);
@@ -1539,6 +1540,9 @@
 	    $result .= '<br />';
 	}
     }
+
+    if ($args->{'sort_html'}) { $result.=$args->{'sort_html'}; }
+
     $result .= "<br />\n";
     if ($r) {
         $r->print($result);
@@ -1614,8 +1618,14 @@
     my @resources;
     my $code='';# sub { !(shift->is_map();) };
     if ($args->{'sort'} eq 'title') {
-	@resources=$navmap->retrieveResources(undef,
-					       sub { !shift->is_map(); });
+        my $oldFilterFunc = $filterFunc;
+	my $filterFunc= 
+	    sub {
+		my ($res)=@_;
+		if ($res->is_map()) { return 0;}
+		return &$oldFilterFunc($res);
+	    };
+	@resources=$navmap->retrieveResources(undef,$filterFunc);
 	@resources= sort {lc($a->compTitle) cmp lc($b->compTitle)} @resources;
     } elsif ($args->{'sort'} eq 'duedate') {
 	@resources=$navmap->retrieveResources(undef,
@@ -1628,8 +1638,12 @@
 		lc($a->compTitle) cmp lc($b->compTitle)
 	    }
 	} @resources;
+    } else {
+	#unknow sort mechanism or default
+	undef($args->{'sort'});
     }
 
+
     while (1) {
 	if ($args->{'sort'}) {
 	    $curRes = shift(@resources);