--- loncom/interface/lonnavmaps.pm 2004/08/10 20:52:03 1.274 +++ loncom/interface/lonnavmaps.pm 2004/09/09 09:49:50 1.287 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.274 2004/08/10 20:52:03 matthew Exp $ +# $Id: lonnavmaps.pm,v 1.287 2004/09/09 09:49:50 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -84,7 +84,7 @@ my %colormap = my $hurryUpColor = "#FF0000"; sub launch_win { - my ($mode,$script)=@_; + my ($mode,$script,$toplinkitems)=@_; my $result; if ($script ne 'no') { $result.=''; } if ($mode eq 'link') { - $result.='' - .&mt("Launch navigation in separate window")." "; + &add_linkitem($toplinkitems,'launchnav','launch_navmapwin()', + "Launch navigation window"); } return $result; } @@ -119,6 +119,23 @@ window.status='Done.'; ENDCLOSE } +sub nav_control_js { + my $nav=($ENV{'environment.remotenavmap'} eq 'on'); + return (<send_http_header; + my %toplinkitems=(); + if ($ENV{QUERY_STRING} eq 'collapseExternal') { &Apache::lonnet::put('environment',{'remotenavmap' => 'off'}); &Apache::lonnet::appenv('environment.remotenavmap' => 'off'); + my $menu=&Apache::lonmenu::reopenmenu(); + my $navstatus=&Apache::lonmenu::get_nav_status(); + if ($menu) { + $menu=(<print(<<"ENDSUBM"); @@ -195,11 +232,12 @@ ENDSUBM $r->print("\n"); $r->print("".&mt('Navigate Course Contents').""); # ------------------------------------------------------------ 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=''; my $more_unload; + my $body_only=''; if ($ENV{'environment.remotenavmap'} eq 'on') { $r->print(''); # FIXME need to be smarter to only catch window close events # $more_unload="collapse()" + $body_only=1; } if ($ENV{'form.register'}) { $addentries=' onLoad="'.&Apache::lonmenu::loadevents(). @@ -221,14 +260,15 @@ ENDSUBM # Header $r->print(''. &Apache::loncommon::bodytag('Navigate Course Contents','', - $addentries,'','',$ENV{'form.register'})); - $r->print(''. - &Apache::loncommon::help_open_menu('','Navigation Screen','Navigation_Screen','',undef,'RAT')); + $addentries,$body_only,'', + $ENV{'form.register'})); + $r->print(''); $r->rflush(); # Check that it's defined if (!($navmap->courseMapDefined())) { + $r->print(&Apache::loncommon::help_open_menu('','Navigation Screen','Navigation_Screen','',undef,'RAT')); $r->print('Coursemap undefined.' . ''); return OK; @@ -270,18 +310,16 @@ ENDSUBM } if ($ENV{'environment.remotenavmap'} ne 'on') { - $r->print(&launch_win('link','yes')); + $r->print(&launch_win('link','yes',\%toplinkitems)); } if ($ENV{'environment.remotenavmap'} eq 'on') { -# $r->print("" . - $r->print("" . - &mt("Close separate navigation window"). - "    "); + &add_linkitem(\%toplinkitems,'closenav','collapse()', + "Close navigation window"); } my $jumpToFirstHomework = 0; # Check to see if the student is jumping to next open, do-able problem - if ($ENV{QUERY_STRING} eq 'jumpToFirstHomework') { + if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) { $jumpToFirstHomework = 1; # Find the next homework problem that they can do. my $iterator = $navmap->getIterator(undef, undef, undef, 1); @@ -314,8 +352,9 @@ ENDSUBM $r->print("All homework assignments have been completed.

"); } } else { - $r->print("" . - &mt("Go To My First Homework Problem")."    "); + &add_linkitem(\%toplinkitems,'firsthomework', + 'location.href="navmaps?jumpToFirstHomework"', + "Show Me My First Homework Problem"); } my $suppressEmptySequences = 0; @@ -324,34 +363,40 @@ ENDSUBM # 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(); }; + &add_linkitem(\%toplinkitems,'everything', + 'location.href="locatnavmaps?sort='.$ENV{'form.sort'}.'"', + "Show Everything"); $r->print("

".&mt("Uncompleted Homework")."

"); $ENV{'form.filter'} = ''; $ENV{'form.condition'} = 1; $resource_no_folder_link = 1; } else { - $r->print("" . - &mt("Show Only Uncompleted Homework")."    "); + &add_linkitem(\%toplinkitems,'uncompleted', + 'location.href="navmaps?sort='.$ENV{'form.sort'}. + '&showOnlyHomework=1"', + "Show Only Uncompleted Homework"); } - $r->print("
+ my %selected=($ENV{'form.sort'} => 'selected=on'); + my $sort_html=(" - Sort by: + + -
"); # renderer call - my $renderArgs = { 'cols' => [0,2,3], + my $renderArgs = { 'cols' => [0,1,2,3], 'sort' => $ENV{'form.sort'}, 'url' => '/adm/navmaps', 'navmap' => $navmap, @@ -359,7 +404,10 @@ ENDSUBM 'suppressEmptySequences' => $suppressEmptySequences, 'filterFunc' => $filterFunc, 'resource_no_folder_link' => $resource_no_folder_link, - 'r' => $r}; + 'sort_html'=> $sort_html, + 'r' => $r, + 'caller' => 'navmapsdisplay', + 'linkitems' => \%toplinkitems}; my $render = render($renderArgs); $navmap->untieHashes(); @@ -631,7 +679,7 @@ sub timeToHumanString { } # Not this year, so show the year - my $timeStr = strftime("on %A, %b %e %G at %I:%M %P", localtime($time)); + my $timeStr = strftime("on %A, %b %e %Y at %I:%M %P", localtime($time)); $timeStr =~ s/12:00 am/00:00/; $timeStr =~ s/12:00 pm/noon/; return $timeStr; @@ -1370,10 +1418,7 @@ sub render { #$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); @@ -1483,20 +1528,27 @@ sub render { } if ($printCloseAll && !$args->{'resource_no_folder_link'}) { + my ($link,$text); if ($condition) { - $result.="".&mt('Close All Folders').""; + $link='"navmaps?condition=0&filter=&'.$queryString. + '&here='.&Apache::lonnet::escape($here).'"'; + $text='Close All Folders'; } else { - $result.="".&mt('Open All Folders').""; - } + $link='"navmaps?condition=1&filter=&'.$queryString. + '&here='.&Apache::lonnet::escape($here).'"'; + $text='Open All Folders'; + } + if ($args->{'caller'} eq 'navmapsdisplay') { + &add_linkitem($args->{'linkitems'},'changefolder', + 'location.href='.$link,$text); + } else { + $result.=''.&mt($text).''; + } $result .= "\n"; } # Check for any unread discussions in all resources. - if (!$args->{'resource_no_folder_link'}) { + if ($args->{'caller'} eq 'navmapsdisplay') { my $totdisc = 0; my $haveDisc = ''; my @allres=$navmap->retrieveResources(); @@ -1514,20 +1566,42 @@ sub render { } if ($totdisc > 0) { $haveDisc =~ s/:$//; - my %lt = &Apache::lonlocal::texthash( - 'mapr' => 'Mark all posts read', - ); - $result .= (<$lt{'mapr'} (Help: NavMaps_MarkPostsLink) + my $navurl = $ENV{'QUERY_STRING'}; + &add_linkitem($args->{'linkitems'},'clearbubbles', + 'document.clearbubbles.submit()', + 'Mark all posts read'); + $result .= (< END + } + } + + if ($args->{'caller'} eq 'navmapsdisplay') { + $result .= ''; + if ($ENV{'environment.remotenavmap'} ne 'on') { + $result .= ''; } else { - $result .= '
'; + $result .= ''; + } + $result.=&show_linkitems($args->{'linkitems'}); + if ($args->{'sort_html'}) { + if ($ENV{'environment.remotenavmap'} ne 'on') { + $result.=''. + ''; + } else { + $result.=''; + } } + $result .= '
'. + &Apache::loncommon::help_open_menu('','Navigation Screen','Navigation_Screen','',undef,'RAT').' 
   '.$args->{'sort_html'}.'

'. + $args->{'sort_html'}.'
'; + } elsif ($args->{'sort_html'}) { + $result.=$args->{'sort_html'}; } + $result .= "
\n"; if ($r) { $r->print($result); @@ -1603,8 +1677,14 @@ END 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, @@ -1617,8 +1697,12 @@ END 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); @@ -1827,6 +1911,45 @@ if (location.href.indexOf('#curloc')==-1 return $result; } +sub add_linkitem { + my ($linkitems,$name,$cmd,$text)=@_; + $$linkitems{$name}{'cmd'}=$cmd; + $$linkitems{$name}{'text'}=&mt($text); +} + +sub show_linkitems { + my ($linkitems)=@_; + my @linkorder = ("launchnav","closenav","firsthomework","everything", + "uncompleted","changefolder","clearbubbles"); + + my $result .= (< + +
+   +
'."\n"; + return $result; +} + 1; package Apache::lonnavmaps::navmap; @@ -2211,9 +2334,14 @@ sub getById { sub getBySymb { my $self = shift; my $symb = shift; + my ($mapUrl, $id, $filename) = &Apache::lonnet::decode_symb($symb); my $map = $self->getResourceByUrl($mapUrl); - return $self->getById($map->map_pc() . '.' . $id); + my $returnvalue = undef; + if (ref($map)) { + $returnvalue = $self->getById($map->map_pc() .'.'.$id); + } + return $returnvalue; } sub getByMapPc { @@ -2407,6 +2535,7 @@ in the filter function. =cut + sub getResourceByUrl { my $self = shift; my $resUrl = shift; @@ -3904,6 +4033,7 @@ sub extractParts { } + # These hashes probably do not need names that end with "Hash".... my %responseIdHash; my %responseTypeHash; @@ -3939,17 +4069,27 @@ sub extractParts { } } my $resorder = &Apache::lonnet::metadata($self->src(),'responseorder'); + # + # Reorder the arrays in the %responseIdHash and %responseTypeHash if ($resorder) { my @resorder=split(/,/,$resorder); foreach my $part (keys(%responseIdHash)) { - my %resids = map { ($_,1) } @{ $responseIdHash{$part} }; + my $i=0; + my %resids = map { ($_,$i++) } @{ $responseIdHash{$part} }; my @neworder; foreach my $possibleid (@resorder) { if (exists($resids{$possibleid})) { - push(@neworder,$possibleid); + push(@neworder,$resids{$possibleid}); } } - $responseIdHash{$part}=\@neworder; + my @ids; + my @type; + foreach my $element (@neworder) { + push (@ids,$responseIdHash{$part}->[$element]); + push (@type,$responseTypeHash{$part}->[$element]); + } + $responseIdHash{$part}=\@ids; + $responseTypeHash{$part}=\@type; } } $self->{RESPONSE_IDS} = \%responseIdHash;