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

bowersj2 lon-capa-cvs@mail.lon-capa.org
Tue, 29 Oct 2002 20:17:39 -0000


bowersj2		Tue Oct 29 15:17:39 2002 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  Shows "Close all Folders" when you select "Open all Folders", which used to say
  "Open all Resources".
  
  Starting to get code to jump to the current URL or most recently opened 
  folder.
  
  
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.90 loncom/interface/lonnavmaps.pm:1.91
--- loncom/interface/lonnavmaps.pm:1.90	Mon Oct 28 16:11:39 2002
+++ loncom/interface/lonnavmaps.pm	Tue Oct 29 15:17:39 2002
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.90 2002/10/28 21:11:39 bowersj2 Exp $
+# $Id: lonnavmaps.pm,v 1.91 2002/10/29 20:17:39 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -926,17 +926,21 @@
     my $queryAdd = "postdata=" . &Apache::lonnet::escape($currenturl) .
         "&alreadyHere=1";
 
-    $r->print('<a href="navmaps?condition=1&filter=">Show All Resources</a><br /><br />');
-
-    # Begin the HTML table
-    # four cols: resource + indent, chat+feedback, icon, text string
-    $r->print('<table cellspacing="0" cellpadding="3" border="0" bgcolor="#FFFFFF">' ."\n");
-
     my $condition = 0;
     if ($ENV{'form.condition'}) {
         $condition = 1;
     }
 
+    if ($condition) {
+        $r->print('<a href="navmaps?condition=0&filter=">Close All Folders</a><br /><br />');
+    } else {
+        $r->print('<a href="navmaps?condition=1&filter=">Open All Folders</a><br /><br />');
+    }
+
+    # Begin the HTML table
+    # four cols: resource + indent, chat+feedback, icon, text string
+    $r->print('<table cellspacing="0" cellpadding="3" border="0" bgcolor="#FFFFFF">' ."\n");
+
     # This needs to be updated to use symbs from the remote, 
     # instead of uris. The changes to this and the main rendering
     # loop should be obvious.
@@ -946,8 +950,12 @@
     my $mapIterator = $navmap->getIterator(undef, undef, {}, 1);
     my $found = 0;
     my $depth = 1;
+    my $currentUrlIndex = 0; # keeps track of when the current resource is found,
+                             # so we can back up a few and put the anchor above the
+                             # current resource
     $mapIterator->next(); # discard the first BEGIN_MAP
     my $curRes = $mapIterator->next();
+    my $counter = 0;
     
     while ($depth > 0) {
         if ($curRes == $mapIterator->BEGIN_MAP()) {
@@ -957,12 +965,16 @@
             $depth--;
         }
 
+        if (ref($curRes)) { $counter++; }
+
         my $mapStack = $mapIterator->getStack();
         if ($currenturl && !$ENV{'form.alreadyHere'} && ref($curRes) && 
             $curRes->src() eq $currenturl) {
             # If this is the correct resource, be sure to 
             # show it by making sure the containing maps
             # are open.
+
+            $currentUrlIndex = $counter;
             
             for my $map (@{$mapStack}) {
                 if ($condition) {
@@ -1009,6 +1021,8 @@
     my @backgroundColors = ("#FFFFFF", "#F6F6F6");
     my $rowNum = 0;
 
+    $counter = 0;
+
     while ($depth > 0) {
         # If we're in a new style course, and this is a BEGIN_MAP, END_MAP, or
         # map resource and the stack depth is only one, just plain ignore this resource
@@ -1041,6 +1055,8 @@
             $depth--;
         }
 
+        if (ref($curRes)) { $counter++; }
+
         if ($depth == 1) { $deltadepth = 0; } # we're done shifting, because we're
                                               # out of the inlined map
 
@@ -1231,9 +1247,17 @@
                 $rowNum++;
                 my $backgroundColor = $backgroundColors[$rowNum % scalar(@backgroundColors)];
 
-                # FIRST COL: The resource indentation, branch icon, and name
+                # FIRST COL: The resource indentation, branch icon, name, and anchor
                 $r->print("  <tr bgcolor=\"$backgroundColor\"><td align=\"left\" valign=\"center\" width=\"60%\">\n");
 
+                # anchor for current resource... - 5 is deliberate: If it's that
+                # high on the screen, don't bother focusing on it. Also this will
+                # print multiple anchors if this is an expanded multi-part problem...
+                # who cares?
+                if ($counter == $currentUrlIndex - 5) {
+                    $r->print('<a name="current" />');
+                }
+
                 # print indentation
                 for (my $i = 0; $i < $indentLevel - $deltalevel + $deltadepth; $i++) {
                     $r->print($indentString);
@@ -2207,7 +2231,7 @@
         $self->{RECURSIVE_ITERATOR} =
           Apache::lonnavmaps::iterator->new ($self->{NAV_MAP}, $firstResource, 
                      $finishResource, $self->{FILTER}, $self->{ALREADY_SEEN},
-                                             $self->{CONDITION});
+                                             $self->{CONDITION}, $self->{DIRECTION});
     }
 
     return $self->{HERE};