[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lon-capa-cvs
Subject:    [LON-CAPA-cvs] cvs: loncom /interface slotrequest.pm
From:       raeburn <raeburn () source ! lon-capa ! org>
Date:       2015-09-25 2:03:29
Message-ID: cvsraeburn1443146609 () cvsserver
[Download RAW message or body]

This is a MIME encoded message


raeburn		Fri Sep 25 02:03:29 2015 EDT

  Modified files:              
    /loncom/interface	slotrequest.pm 
  Log:
  - Reservations screen for students.
    - If all problems in a folder have useslots set to map or map_map and
      slotstatus is the same for each problem, slot actions menu shown for  
      folder, and rows for individual resources are hidden.
    - Arrow to left of folder icon toggles display.
  
  
["raeburn-20150925020329.txt" (text/plain)]

Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.126 loncom/interface/slotrequest.pm:1.127
--- loncom/interface/slotrequest.pm:1.126	Wed Sep 23 23:04:53 2015
+++ loncom/interface/slotrequest.pm	Fri Sep 25 02:03:29 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.126 2015/09/23 23:04:53 raeburn Exp $
+# $Id: slotrequest.pm,v 1.127 2015/09/25 02:03:29 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -245,6 +245,42 @@
         }
     }
 }
+
+function toggleSlotMap(maprownum) {
+    if (document.getElementById('arrow'+maprownum)) {
+        var img = document.getElementById('arrow'+maprownum);
+        var rowdisplay;
+        var celldisplay = '';
+        if (img.src.indexOf('arrow.open.gif')!=-1) {
+            img.src = '/adm/lonIcons/arrow.closed.gif';
+            rowdisplay = 'none';
+        }
+        else {
+            img.src = '/adm/lonIcons/arrow.open.gif';
+            rowdisplay = 'table-row';
+            celldisplay = 'none';
+        }
+        var resrows;
+        var maptext;
+        if (document.getElementsByClassName) {
+            resrows = document.getElementsByClassName('LC_slotmaprow_'+maprownum);
+            maptext = document.getElementsByClassName('LC_slotmaptext_'+maprownum);
+        } else {
+            resrows = \
getElementsByClassName(document.body,'LC_slotmaprow_'+maprownum); +            \
maptext = getElementsByClassName(document.body,'LC_slotmaptext_'+maprownum); +        \
} +        if (resrows.length) {
+            for (var i=0; i<resrows.length; i++) {
+                resrows[i].style.display = rowdisplay;   
+            }
+        }
+        if (maptext.length) { 
+            for (var i=0; i<maptext.length; i++) {
+                maptext[i].style.display = celldisplay;
+            }
+        }
+    }
+}
 // ]]>
 </script>
 ENDSCRIPT
@@ -1043,7 +1079,7 @@
 }
 
 sub show_choices {
-    my ($r,$symb,$formname,$num,$slots,$consumed_uniqueperiods,$available,$got_slots)=@_;
 +    my ($symb,$formname,$num,$class,$slots,$consumed_uniqueperiods,$available,$got_slots)=@_;
  my $output;
     &Apache::lonxml::debug("Checking Slots");
     if (!ref($available) eq 'ARRAY') {
@@ -1055,8 +1091,11 @@
             $output .= ' <a href="/adm/flip?postdata=return:">'.
                        &mt('Return to last resource').'</a>';
         }
-        $r->print($output);
-        return;
+        if ($class) {
+            return '<div class="'.$class.'">'.$output.'</div>';
+        } else {
+            return $output;
+        }
     }
     if (@{$available} > 1) {
         my $numavailable = scalar(@{$available});
@@ -1204,8 +1243,11 @@
     if (@{$available} > 1) {
         $output .= '</div></fieldset>';
     }
-    $r->print($output);
-    return;
+    if ($class) {
+        return '<div class="'.$class.'">'.$output.'</div>';
+    } else {
+        return $output;
+    }
 }
 
 sub to_show {
@@ -1769,18 +1811,93 @@
                  '<table class="LC_data_table LC_tableOfContent">'."\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;
     while (my $resource = $it->next()) {
         if ($resource == $it->BEGIN_MAP()) {
+            @ordered=();
+            undef(%output);
+            $currmapoutput = '';
+            $got_map_slot = '';
+            $mapitem = '';
             $depth++;
             $parent{$depth} = $lastcontainer;
         }
         if ($resource == $it->END_MAP()) {
             $depth--;
             $lastcontainer = $parent{$depth};
+            my %allstatuses;
+            foreach my $symb (@ordered) {
+                if (ref($output{$symb}) eq 'HASH') {
+                    if (($output{$symb}{'type'} eq 'map_map') || \
($output{$symb}{'type'} eq 'map')) { +                        if \
($output{$symb}{'slotstatus'} ne '') { +                            if \
(ref($allstatuses{$output{$symb}{'slotstatus'}}) eq 'ARRAY') { +                      \
push(@{$allstatuses{$output{$symb}{'slotstatus'}}},$symb); +                          \
} else { +                                $allstatuses{$output{$symb}{'slotstatus'}} \
= [$symb]; +                            }
+                        }
+                    }
+                }
+            }
+            if (keys(%allstatuses) == 1) {
+                $got_map_slot = 1;
+                my $repsymb;
+                my @values = values(%allstatuses);
+                if (ref($values[0]) eq 'ARRAY') {
+                    if (ref($output{$values[0][0]}) eq 'HASH') {
+                        $repsymb = $values[0][0];
+                    }
+                }
+                if (($mapitem) && ($repsymb)) {
+                    my $formnum = $mapnum.'_'.$output{$repsymb}{'reservable'};
+                    my $class = 'LC_slotmaptext_'.$mapnum;
+                    if ($output{$repsymb}{'hasaction'}) {
+                        $mapitem .= '<td valign="top"><span class="'.$class.'">'.
+                                    $output{$repsymb}{'msg'}.
+                                    '</span></td><td valign="top">'.
+                                    \
&slot_chooser($repsymb,$class,$formnum,$allavailable,$slots, +                        \
$consumed_uniqueperiods). +                                   '</td>';
+
+                    } else {
+                        $mapitem .= '<td colspan="2" valign="middle"><span \
class="'.$class.'">'. +                                    $output{$repsymb}{'msg'}.
+                                    '</span></td>';
+                    }
+                }
+                foreach my $symb (@ordered) {
+                    if (ref($output{$symb}) eq 'HASH') {
+                        my $bgcolor = $backgrounds[$output{$symb}{'rownum'} % \
$numcolors]; +                        $currmapoutput .= $output{$symb}{'header'}.
+                                          '<tr class="'.$bgcolor.' \
LC_slotmaprow_'.$output{$symb}{'mapnum'}.'"'. +                                       \
' style="display:none">'.$output{$symb}{'info'}. +                                    \
$output{$symb}{'data'}.'</tr>'."\n"; +                    }
+                }
+            } else {
+                foreach my $symb (@ordered) {
+                    if (ref($output{$symb}) eq 'HASH') {
+                        my $bgcolor = $backgrounds[$output{$symb}{'rownum'} % \
$numcolors]; +                        $currmapoutput .= $output{$symb}{'header'}.
+                                          '<tr class="'.$bgcolor.' \
LC_slotmaprow_'.$output{$symb}{'mapnum'}.'"'. +                                       \
' style="display:table-row">'.$output{$symb}{'info'}. +                               \
$output{$symb}{'data'}.'</tr>'."\n"; +                    }
+                }
+            }
+            if ($mapitem) {
+                if ($got_map_slot) {
+                    $mapitem =~ s{(<img \
src=\"/adm/lonIcons/arrow\.)open(\.gif\")}{$1closed$2}; +                    $mapitem \
.= '</tr>'."\n"; +                } else {
+                    $mapitem .= '<td colspan="2">&nbsp;</td></tr>'."\n";
+                }
+            }
+            $r->print($mapitem.$currmapoutput);
         }
         if (ref($resource)) {
             my $symb = $resource->symb();
-            my $ressymb = $symb;
             $contents{$lastcontainer} ++;
             next if (!$resource->is_problem() && !$resource->is_sequence() && 
                      !$resource->is_page());
@@ -1793,10 +1910,15 @@
             if ($resource->is_problem()) {
                 my ($useslots) = $resource->slot_control();
                 next if (($useslots eq '') || ($useslots =~ /^\s*no\s*$/i));
+                push(@ordered,$symb); 
+                $output{$symb}{type} = $useslots;  
                 my ($msg,$get_choices,$slotdescription);
                 my $title = $resource->compTitle();
                 my $status = $resource->simpleStatus('0');
                 my ($slot_status,$date,$slot_name) = $resource->check_for_slot('0');
+
+                $output{$symb}{'slotstatus'} = $slot_status;
+                $output{$symb}{'slotname'} = $slot_name; 
                 if ($slot_name ne '') {
                     my %slot=&Apache::lonnet::get_slot($slot_name);
                     $slotdescription=&get_description($slot_name,\%slot);
@@ -1840,7 +1962,9 @@
                         $msg = &Apache::lonnavmaps::getDescription($resource,'0'); 
                     }
                 }
+                $output{$symb}{'msg'} = $msg;
                 $reservable ++;
+                $output{$symb}{'reservable'} = $reservable;
                 my $treelevel = $depth;
                 my $higherup = $lastcontainer;
                 if ($depth > 1) {
@@ -1861,76 +1985,67 @@
                         $treelevel --;
                         $higherup = $parent{$treelevel};
                     }
-                    foreach my $item (@maprows) {
+                    for (my $i=0; $i<@maprows; $i++) {
+                        $mapnum ++;
                         $rownum ++;
                         my $bgcolor = $backgrounds[$rownum % $numcolors];
                         if (!$shownheader) {
-                            $r->print($slotheader);
+                            $mapitem .= $slotheader;
                             $shownheader = 1;
                         }
-                        $r->print('<tr class="'.$bgcolor.'">'.$item.'</tr>'."\n");
+                        if (ref($maprows[$i]) eq 'ARRAY') {
+                            if ($i < scalar(@maprows)-1) {
+                                $mapitem .= '<tr \
class="'.$bgcolor.'"><td>'.join('',@{$maprows[$i]}).'</td>'. +                        \
'<td colspan="2">&nbsp;</td></tr>'."\n"; +                            } else {
+                                $mapitem .= 
+                                   '<tr class="'.$bgcolor.'"><td>'.$maprows[$i][0].
+                                   '<img src="/adm/lonIcons/arrow.open.gif" \
id="arrow'.$mapnum.'" '. +                                   'alt="arrow" \
onmouseover="this.style.cursor=\'pointer\'" '. +                                   \
'onclick="'."toggleSlotMap('$mapnum');".'" />'. +                                   \
$maprows[$i][1].('&nbsp;' x6).'</td>'."\n"; +                            }
+                        }
                     }
+                    $output{$symb}{'mapnum'} = $mapnum;
                 }
                 $rownum ++;
-                my $bgcolor = $backgrounds[$rownum % $numcolors];
+                $output{$symb}{'rownum'} = $rownum;
                 if (!$shownheader) {
-                    $r->print($slotheader);
+                    $output{$symb}{'header'} = $slotheader;
                     $shownheader = 1;
                 }
-                $r->print('<tr class="'.$bgcolor.'"><td>'."\n");
+                $output{$symb}{'info'} = '<td>';
                 for (my $i=0; $i<$depth; $i++) {
-                    $r->print('<img src="'.$location.'" alt="" />');
+                    $output{$symb}{'info'} .= '<img src="'.$location.'" alt="" />';
                 }
-                my $result = '<a href="'.$resource->src().'?symb='.$symb.'">'.
-                             '<img class="LC_contentImage" src="/adm/lonIcons/';
+                $output{$symb}{'info'} .= '<a \
href="'.$resource->src().'?symb='.$symb.'">'. +                                       \
'<img class="LC_contentImage" src="/adm/lonIcons/';  if ($resource->is_task()) {
-                    $result .= 'task.gif" alt="'.&mt('Task');
+                    $output{$symb}{'info'} .= 'task.gif" alt="'.&mt('Task');
                 } else {
-                    $result .= 'problem.gif" alt="'.&mt('Problem');
+                    $output{$symb}{'info'} .= 'problem.gif" alt="'.&mt('Problem');
                 }
-                $result .= '" /><b>'.$title.'</b></a>'.('&nbsp;' x6).'</td>';
+                $output{$symb}{'info'} .= '" /><b>'.$title.'</b></a>'.('&nbsp;' \
x6).'</td>'; +
                 my $hasaction;
                 if ($status == $resource->OPEN) {
                     if ($get_choices) {
                         $hasaction = 1;
+                        $output{$symb}{'hasaction'} = $hasaction;
                     }
                 }
+                my $class = 'LC_slottext_'.$mapnum;
                 if ($hasaction) {
-                    $result .= '<td valign="top">'.$msg.'</td>'.
-                               '<td valign="top">';
+                    $output{$symb}{'data'} = '<td valign="top"><span \
class="'.$class.'">'.$msg.'</span></td>'. +                                           \
'<td valign="top">'. +                                             \
&slot_chooser($symb,$class,$reservable,$allavailable,$slots, +                        \
$consumed_uniqueperiods).'</td>';  } else {
-                    $result .= '<td colspan="2" valign="middle">'.$msg.'</td>';
-                }
-                $r->print($result);
-                if ($hasaction) {
-                    my @got_slots=&check_for_reservation($symb,'allslots');
-                    if ($got_slots[0] =~ /^error: /) {
-                        $r->print('<span class="LC_error">'.
-                                  &mt('An error occurred determining slot \
                availability.').
-                                  '</span>');
-                    } else {
-                        my $formname = 'manageres_'.$reservable;
-                        if (ref($allavailable) eq 'ARRAY') {
-                            my @available;
-                            if (ref($slots) eq 'HASH') {
-                                foreach my $slot (@{$allavailable}) {
-                                # not allowed for this resource
-                                    if (ref($slots->{$slot}) eq 'HASH') {
-                                        if ((defined($slots->{$slot}->{'symb'})) && 
-                                            ($slots->{$slot}->{'symb'} ne $symb)) {
-                                            next;
-                                        }
-                                    }
-                                    push(@available,$slot);
-                                }
-                            }  
-                            \
                &show_choices($r,$symb,$formname,$reservable,$slots,$consumed_uniqueperiods,
                
-                                          \@available,\@got_slots);
-                        }
-                    }
-                    $r->print('</td>');
+                    $output{$symb}{'data'} = '<td colspan="2" valign="middle">'.
+                                             '<span \
class="'.$class.'">'.$msg.'</span>'. +                                             \
'</td>';  }
-                $r->print('</tr>');
             }
         }
     }
@@ -1952,20 +2067,53 @@
 
 sub show_map_row {
     my ($depth,$location,$type,$title,$maprows) = @_;
-    my $output = '<td>';
-    for (my $i=0; $i<$depth-1; $i++) {
-        $output .= '<img src="'.$location.'" alt="" />';
+    my $spacers;
+    for (my $i=0; $i<$depth-2; $i++) {
+        $spacers .= '<img src="'.$location.'" alt="" />';
     }
+    my $icon;
     if ($type eq 'page') {
-        $output .= '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" \
/>&nbsp;'."\n"; +        $icon = '<img src="/adm/lonIcons/navmap.page.open.gif" \
alt="" />&nbsp;'."\n";  } else {
-        $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" \
/>&nbsp;'."\n"; +        $icon = '<img src="/adm/lonIcons/navmap.folder.open.gif" \
alt="" />&nbsp;'."\n";  }
-    $output .= $title.'</td><td colspan="2">&nbsp;</td>'."\n";
-    unshift (@{$maprows},$output);
+    $icon .= $title;
+    unshift (@{$maprows},[$spacers,$icon]);
     return;
 }
 
+sub slot_chooser {
+    my ($symb,$class,$formnum,$allavailable,$slots,$consumed_uniqueperiods) = @_;
+    my $output;
+    my @got_slots=&check_for_reservation($symb,'allslots');
+    if ($got_slots[0] =~ /^error: /) {
+        $output = '<span class="'.$class.'"><span class="LC_error">'.
+                  &mt('An error occurred determining slot availability.').
+                  '</span></span>';
+    } else {
+        my $formname = 'manageres_'.$formnum;
+        if (ref($allavailable) eq 'ARRAY') {
+            my @available;
+            if (ref($slots) eq 'HASH') {
+                foreach my $slot (@{$allavailable}) {
+                    # not allowed for this resource
+                    if (ref($slots->{$slot}) eq 'HASH') {
+                        if ((defined($slots->{$slot}->{'symb'})) &&
+                            ($slots->{$slot}->{'symb'} ne $symb)) {
+                            next;
+                        }
+                    }
+                    push(@available,$slot);
+                }
+            }
+            $output .= &show_choices($symb,$formname,$formnum,$class,
+                                     $slots,$consumed_uniqueperiods,
+                                     \@available,\@got_slots);
+        }
+    }
+    return $output;
+}
+
 sub show_reservations {
     my ($r,$uname,$udom) = @_;
     if (!defined($uname)) {
@@ -3018,7 +3166,7 @@
 	}
 	if ($env{'form.requestattempt'}) {
             $r->print('<div class="LC_left_float">'); 
-	    &show_choices($r,$symb,undef,undef,\%slots,$consumed_uniqueperiods,$available,$got_slots);
 +	    $r->print(&show_choices($symb,undef,undef,undef,\%slots,$consumed_uniqueperiods,$available,$got_slots));
                
             $r->print('</div><div \
style="padding:0;clear:both;margin:0;border:0"></div>');  } elsif \
($env{'form.command'} eq 'release') {  &release_slot($r,$symb);



_______________________________________________
LON-CAPA-cvs mailing list
LON-CAPA-cvs@mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic