--- loncom/interface/slotrequest.pm 2015/09/23 23:04:53 1.126 +++ loncom/interface/slotrequest.pm 2015/09/25 02:03:29 1.127 @@ -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 uncheckSlotRadio() { } } } + +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 ENDSCRIPT @@ -1043,7 +1079,7 @@ sub get_description { } 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 @@ sub show_choices { $output .= ' '. &mt('Return to last resource').''; } - $r->print($output); - return; + if ($class) { + return '
'.$output.'
'; + } else { + return $output; + } } if (@{$available} > 1) { my $numavailable = scalar(@{$available}); @@ -1204,8 +1243,11 @@ STUFF if (@{$available} > 1) { $output .= ''; } - $r->print($output); - return; + if ($class) { + return '
'.$output.'
'; + } else { + return $output; + } } sub to_show { @@ -1769,18 +1811,93 @@ sub manage_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; 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 .= ''; + + } else { + $mapitem .= ''; + } + } + foreach my $symb (@ordered) { + if (ref($output{$symb}) eq 'HASH') { + my $bgcolor = $backgrounds[$output{$symb}{'rownum'} % $numcolors]; + $currmapoutput .= $output{$symb}{'header'}. + ''.$output{$symb}{'info'}. + $output{$symb}{'data'}.''."\n"; + } + } + } else { + foreach my $symb (@ordered) { + if (ref($output{$symb}) eq 'HASH') { + my $bgcolor = $backgrounds[$output{$symb}{'rownum'} % $numcolors]; + $currmapoutput .= $output{$symb}{'header'}. + ''.$output{$symb}{'info'}. + $output{$symb}{'data'}.''."\n"; + } + } + } + if ($mapitem) { + if ($got_map_slot) { + $mapitem =~ s{(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 @@ sub manage_reservations { 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 @@ sub manage_reservations { $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 @@ sub manage_reservations { $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(''.$item.''."\n"); + if (ref($maprows[$i]) eq 'ARRAY') { + if ($i < scalar(@maprows)-1) { + $mapitem .= ''. + ''."\n"; + } else { + $mapitem .= + ''."\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(''; + $output{$symb}{'info'} .= '" />'.$title.''.(' ' x6).''; + my $hasaction; if ($status == $resource->OPEN) { if ($get_choices) { $hasaction = 1; + $output{$symb}{'hasaction'} = $hasaction; } } + my $class = 'LC_slottext_'.$mapnum; if ($hasaction) { - $result .= ''. - ''. + ''; } else { - $result .= ''; - } - $r->print($result); - if ($hasaction) { - my @got_slots=&check_for_reservation($symb,'allslots'); - if ($got_slots[0] =~ /^error: /) { - $r->print(''. - &mt('An error occurred determining slot availability.'). - ''); - } 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(''); + $output{$symb}{'data'} = ''; } - $r->print(''); } } } @@ -1952,20 +2067,53 @@ sub manage_reservations { sub show_map_row { my ($depth,$location,$type,$title,$maprows) = @_; - my $output = ''."\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 = ''. + &mt('An error occurred determining slot availability.'). + ''; + } 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 @@ sub handler { } if ($env{'form.requestattempt'}) { $r->print('
'); - &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('
'); } elsif ($env{'form.command'} eq 'release') { &release_slot($r,$symb);
'. + $output{$repsymb}{'msg'}. + ''. + &slot_chooser($repsymb,$class,$formnum,$allavailable,$slots, + $consumed_uniqueperiods). + ''. + $output{$repsymb}{'msg'}. + '
'.join('',@{$maprows[$i]}).' 
'.$maprows[$i][0]. + ''. + $maprows[$i][1].(' ' x6).'
'."\n"); + $output{$symb}{'info'} = ''; for (my $i=0; $i<$depth; $i++) { - $r->print(''); + $output{$symb}{'info'} .= ''; } - my $result = ''. - 'src().'?symb='.$symb.'">'. + ''.&mt('Task');
+                    $output{$symb}{'info'} .= 'task.gif'.$title.''.(' ' x6).''.$msg.''; + $output{$symb}{'data'} = ''.$msg.''. + &slot_chooser($symb,$class,$reservable,$allavailable,$slots, + $consumed_uniqueperiods).''.$msg.''. + ''.$msg.''. + '
'; - for (my $i=0; $i<$depth-1; $i++) { - $output .= ''; + my $spacers; + for (my $i=0; $i<$depth-2; $i++) { + $spacers .= ''; } + my $icon; if ($type eq 'page') { - $output .= ' '."\n"; + $icon = ' '."\n"; } else { - $output .= ' '."\n"; + $icon = ' '."\n"; } - $output .= $title.'