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

raeburn raeburn at source.lon-capa.org
Sun Sep 27 10:21:48 EDT 2015


raeburn		Sun Sep 27 14:21:48 2015 EDT

  Modified files:              
    /loncom/interface	slotrequest.pm 
  Log:
  - Reservations screen for students.
    - Maintain alternating background colors when toggling hide/display
      for resources with slot control within folders. 
  
  
-------------- next part --------------
Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.128 loncom/interface/slotrequest.pm:1.129
--- loncom/interface/slotrequest.pm:1.128	Fri Sep 25 16:13:00 2015
+++ loncom/interface/slotrequest.pm	Sun Sep 27 14:21:48 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for requesting to have slots added to a students record
 #
-# $Id: slotrequest.pm,v 1.128 2015/09/25 16:13:00 raeburn Exp $
+# $Id: slotrequest.pm,v 1.129 2015/09/27 14:21:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -261,7 +261,7 @@
     }
 }
 
-function toggleSlotMap(maprownum) {
+function toggleSlotMap(maprownum,rownum) {
     if (document.getElementById('arrow'+maprownum)) {
         var img = document.getElementById('arrow'+maprownum);
         var rowdisplay;
@@ -278,20 +278,81 @@
         var resrows;
         var maptext;
         if (document.getElementsByClassName) {
-            resrows = document.getElementsByClassName('LC_slotmaprow_'+maprownum);
+            resrows = document.getElementsByClassName('LC_slotresrow_'+maprownum);
             maptext = document.getElementsByClassName('LC_slotmaptext_'+maprownum);
         } else {
-            resrows = getElementsByClassName(document.body,'LC_slotmaprow_'+maprownum);
+            resrows = getElementsByClassName(document.body,'LC_slotresrow_'+maprownum);
             maptext = getElementsByClassName(document.body,'LC_slotmaptext_'+maprownum);
         }
+        if (maptext.length) {
+            for (var i=0; i<maptext.length; i++) {
+                maptext[i].style.display = celldisplay;
+            }
+        }
         if (resrows.length) {
+           var mapbgidx = 0;
+           var rowclasses = ['LC_even_row','LC_odd_row'];
+           var mapbgClass = 'LC_even_row';
+           var regExpBg = /LC_odd_row/i;
+           if (rowdisplay == 'table-row') {
+                if (document.getElementById('LC_slotmaprow_'+rownum)) {
+                    mapbgClass = document.getElementById('LC_slotmaprow_'+rownum).className;
+                    if (regExpBg.test(mapbgClass)) {
+                        mapbgidx = 1;
+                    }
+                }
+            }
             for (var i=0; i<resrows.length; i++) {
-                resrows[i].style.display = rowdisplay;   
+                resrows[i].style.display = rowdisplay;
+                if (rowdisplay == 'table-row') {
+                    mapbgidx ++;        
+                    var bgcolnew = mapbgidx % 2;
+                    var bgcolold = (mapbgidx+1) % 2;
+                    var k = i+parseInt(rownum)+1; 
+                    if (document.getElementById('LC_slotresrow_'+k)) {
+                        document.getElementById('LC_slotresrow_'+k).className = document.getElementById('LC_slotresrow_'+k).className.replace(rowclasses[bgcolold],rowclasses[bgcolnew]);
+                    }
+                }
             }
-        }
-        if (maptext.length) { 
-            for (var i=0; i<maptext.length; i++) {
-                maptext[i].style.display = celldisplay;
+            if (document.getElementById('LC_slot_reservations')) {
+                var numrowsOdd = resrows.length % 2;
+                if (numrowsOdd) {
+                    var lastbgClass = 'LC_even_row';
+                    var idx = 0;
+                    var lastresnum = parseInt(rownum) + resrows.length; 
+                    if (rowdisplay == 'none') {
+                        lastresnum = rownum;
+                        if (document.getElementById('LC_slotmaprow_'+rownum)) {
+                            lastbgClass = document.getElementById('LC_slotmaprow_'+rownum).className;
+                        }
+                    } else {
+                        lastresnum = parseInt(rownum) + resrows.length;
+                        if (document.getElementById('LC_slotresrow_'+lastresnum)) {
+                            lastbgClass = document.getElementById('LC_slotresrow_'+lastresnum).className;
+                        }
+                    }
+                    if (regExpBg.test(lastbgClass)) {
+                        idx = 1;
+                    }
+                    var table = document.getElementById('LC_slot_reservations');
+                    if ((table.rows.length) && (table.rows.length >= lastresnum)) {
+                        for (var i=lastresnum; i<table.rows.length; i++) {
+                            if (table.rows[i].style.display != 'none') {
+                                idx ++;
+                                var bgcolnew = idx % 2;
+                                var bgcolold = (idx+1) % 2;  
+                                j = i+1;
+                                if (document.getElementById('LC_slotmaprow_'+j)) {
+                                    document.getElementById('LC_slotmaprow_'+j).className = rowclasses[bgcolnew];
+                                } else {
+                                    if (document.getElementById('LC_slotresrow_'+j)) {
+                                        document.getElementById('LC_slotresrow_'+j).className = document.getElementById('LC_slotresrow_'+j).className.replace(rowclasses[bgcolold],rowclasses[bgcolnew]);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
             }
         }
     }
@@ -1816,25 +1877,21 @@
         return;
     }
     my (%parent,%shownparent,%container,%container_title,%contents);
-    my ($depth,$count,$reservable,$lastcontainer,$rownum) = (0,0,0,0,0);
+    my ($depth,$count,$reservable,$lastcontainer,$rownum,$shown) = (0,0,0,0,0,0);
     my @backgrounds = ("LC_odd_row","LC_even_row");
     my $numcolors = scalar(@backgrounds);
     my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif");
     my $slotheader = '<p>'.
                  &mt('Your reservation status for any such assignments is listed below:').
                  '</p>'.
-                 '<table class="LC_data_table LC_tableOfContent">'."\n";
+                 '<table class="LC_data_table LC_tableOfContent" id="LC_slot_reservations">'."\n";
     my $shownheader = 0;
     my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
     my (@ordered,%output,$mapitem,$got_map_slot,$currmapoutput,$mapnum);
     $mapnum = 0;
+    $shown = 0;
     while (my $resource = $it->next()) {
         if ($resource == $it->BEGIN_MAP()) {
-            @ordered=();
-            undef(%output);
-            $currmapoutput = '';
-            $got_map_slot = '';
-            $mapitem = '';
             $depth++;
             $parent{$depth} = $lastcontainer;
         }
@@ -1881,23 +1938,30 @@
                                     '</span></td>';
                     }
                 }
+                my $counter = 0;
                 foreach my $symb (@ordered) {
                     if (ref($output{$symb}) eq 'HASH') {
-                        my $bgcolor = $backgrounds[$output{$symb}{'rownum'} % $numcolors];
+                        $counter ++;
+                        my $bgcolor = $backgrounds[($output{$symb}{'shown'} + $counter) % $numcolors];
                         $currmapoutput .= $output{$symb}{'header'}.
-                                          '<tr class="'.$bgcolor.' LC_slotmaprow_'.$output{$symb}{'mapnum'}.'"'.
-                                          ' style="display:none">'.$output{$symb}{'info'}.
+                                          '<tr class="'.$bgcolor.' LC_slotresrow_'.$output{$symb}{'mapnum'}.'"'.
+                                          ' style="display:none" id="LC_slotresrow_'.$output{$symb}{'rownum'}.'">'.
+                                          $output{$symb}{'info'}.
                                           $output{$symb}{'data'}.'</tr>'."\n";
                     }
                 }
             } else {
+                my $counter = 0;
                 foreach my $symb (@ordered) {
                     if (ref($output{$symb}) eq 'HASH') {
-                        my $bgcolor = $backgrounds[$output{$symb}{'rownum'} % $numcolors];
+                        $counter ++;
+                        my $bgcolor = $backgrounds[($output{$symb}{'shown'} + $counter) % $numcolors];
                         $currmapoutput .= $output{$symb}{'header'}.
-                                          '<tr class="'.$bgcolor.' LC_slotmaprow_'.$output{$symb}{'mapnum'}.'"'.
-                                          ' style="display:table-row">'.$output{$symb}{'info'}.
+                                          '<tr class="'.$bgcolor.' LC_slotresrow_'.$output{$symb}{'mapnum'}.'"'.
+                                          ' style="display:table-row" id="LC_slotresrow_'.$output{$symb}{'rownum'}.'">'.
+                                          $output{$symb}{'info'}.
                                           $output{$symb}{'data'}.'</tr>'."\n";
+                        $shown ++;
                     }
                 }
             }
@@ -1910,6 +1974,11 @@
                 }
             }
             $r->print($mapitem.$currmapoutput);
+            @ordered=();
+            undef(%output);
+            $currmapoutput = '';
+            $got_map_slot = '';
+            $mapitem = '';
         }
         if (ref($resource)) {
             my $symb = $resource->symb();
@@ -2003,21 +2072,24 @@
                     for (my $i=0; $i<@maprows; $i++) {
                         $mapnum ++;
                         $rownum ++;
-                        my $bgcolor = $backgrounds[$rownum % $numcolors];
+                        $shown ++;
+                        my $bgcolor = $backgrounds[$shown % $numcolors];
                         if (!$shownheader) {
                             $mapitem .= $slotheader;
                             $shownheader = 1;
                         }
                         if (ref($maprows[$i]) eq 'ARRAY') {
                             if ($i < scalar(@maprows)-1) {
-                                $mapitem .= '<tr class="'.$bgcolor.'"><td>'.join('',@{$maprows[$i]}).'</td>'.
+                                $mapitem .= '<tr class="'.$bgcolor.'" id="LC_slotmaprow_'.$rownum.'">'.
+                                            '<td>'.join('',@{$maprows[$i]}).'</td>'.
                                             '<td colspan="2"> </td></tr>'."\n";
                             } else {
                                 $mapitem .= 
-                                   '<tr class="'.$bgcolor.'"><td>'.$maprows[$i][0].
+                                   '<tr class="'.$bgcolor.'" id="LC_slotmaprow_'.$rownum.'">'.
+                                   '<td>'.$maprows[$i][0].
                                    '<img src="/adm/lonIcons/arrow.open.gif" id="arrow'.$mapnum.'" '.
                                    'alt="arrow" onmouseover="this.style.cursor=\'pointer\'" '.
-                                   'onclick="'."toggleSlotMap('$mapnum');".'" />'.
+                                   'onclick="'."toggleSlotMap('$mapnum','$rownum');".'" />'.
                                    $maprows[$i][1].(' ' x6).'</td>'."\n";
                             }
                         }
@@ -2026,6 +2098,7 @@
                 }
                 $rownum ++;
                 $output{$symb}{'rownum'} = $rownum;
+                $output{$symb}{'shown'} = $shown;
                 if (!$shownheader) {
                     $output{$symb}{'header'} = $slotheader;
                     $shownheader = 1;


More information about the LON-CAPA-cvs mailing list