--- loncom/interface/lonmenu.pm 2013/12/27 14:17:59 1.424
+++ loncom/interface/lonmenu.pm 2015/09/14 13:45:01 1.437
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.424 2013/12/27 14:17:59 raeburn Exp $
+# $Id: lonmenu.pm,v 1.437 2015/09/14 13:45:01 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -128,6 +128,33 @@ Inputs: 4 - (a) link and (b) target for
(c) title for text wrapped by anchor tag in top level item.
(d) reference to array of arrays of sub-menu items.
+ The underlying datastructure used in (d) contains data from mydesk.tab.
+ It consists of an array which has an array for each item appearing in
+ the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
+ create_submenu() supports also the creation of XHTML for nested dropdown
+ menus represented by unordered lists. This is done by replacing the
+ scalar used for the link with an arrayreference containing the menuitems
+ for the nested menu. This can be done recursively so that the next menu
+ may also contain nested submenus.
+
+ Example:
+ [ # begin of datastructure
+ ["/home/", "Home", "condition1"], # 1st item of the 1st layer menu
+ [ # 2nd item of the 1st layer menu
+ [ # anon. array for nested menu
+ ["/path1", "Path1", undef], # 1st item of the 2nd layer menu
+ ["/path2", "Path2", undef], # 2nd item of the 2nd layer menu
+ [ # 3rd item of the 2nd layer menu
+ [[...], [...], ..., [...]], # containing another menu layer
+ "Sub-Sub-Menu", # title for this container
+ undef
+ ]
+ ], # end of array/nested menu
+ "Sub-Menu", # title for the container item
+ undef
+ ] # end of 2nd item of the 1st layer menu
+]
+
=item innerregister()
This gets called in order to register a URL in the body of the document
@@ -261,6 +288,11 @@ sub primary_menu {
push(@primsub,$item);
}
if (@primsub > 0) {
+ if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
+ $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
+ } else {
+ $title = &mt($title);
+ }
$menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
} elsif ($link) {
$menu{$position} .= '
';
+
+ # $link and $title are only used in the initial string written in $menu
+ # as seen above, not needed for nested submenus
+ $menu .= &build_submenu($target, $submenu, $translate, '1');
+ $menu .= '
';
+
+ return $menu;
+}
+
+# helper routine for create_submenu
+# build the dropdown (and nested submenus) recursively
+# see perldoc create_submenu documentation for further information
+sub build_submenu {
+ my ($target, $submenu, $translate, $first_level) = @_;
+ if (!defined(@{$submenu})) {
+ return '';
+ }
+
+ my $menu = '';
my $count = 0;
my $numsub = scalar(@{$submenu});
foreach my $item (@{$submenu}) {
$count ++;
if (ref($item) eq 'ARRAY') {
my $href = $item->[0];
- if ($href =~ /(aboutme|rss\.html)$/) {
- next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
- $href =~ s/\[domain\]/$env{'user.domain'}/g;
- $href =~ s/\[user\]/$env{'user.name'}/g;
- }
+ my $bordertop;
my $borderbot;
- if ($count == $numsub) {
- $borderbot = 'border-bottom:1px solid black;';
- }
- $menu .= '
';
}
}
- $menu .= '';
return $menu;
}
@@ -570,8 +634,18 @@ sub innerregister {
&& $maptitle ne $coursetitle);
push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
+ my @tools;
+ if ($env{'request.filename'} =~ /\.page$/) {
+ my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
+ if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
+ @tools = @{$breadcrumb_tools{'tools'}};
+ }
+ }
&Apache::lonhtmlcommon::clear_breadcrumbs();
&Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
+ if (@tools) {
+ &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',@tools);
+ }
} else {
$resurl = $env{'request.noversionuri'};
my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
@@ -707,6 +781,9 @@ sub innerregister {
my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
if ($currdir =~ m-/$-) {
$is_const_dir = 1;
+ if ($thisdisfn eq '') {
+ $is_const_dir = 2;
+ }
} else {
$currdir =~ s|[^/]+$||;
my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
@@ -765,11 +842,15 @@ if(length($annotation) > 0){
}
$menuitems.="&Notes&&annotate()&";
$menuitems.="Make notes and annotations about this resource&&1\n";
+my $is_mobile;
+if ($env{'browser.mobile'}) {
+ $is_mobile = 1;
+}
unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
$menuitems.=(< 'WARNING!',
+ button => 'Done',
+ preamble => 'You are trying to end this timed event early.',
+ map => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
+ resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).',
+ ok => 'Click "OK" if you are completely finished.',
+ cancel => 'Click "Cancel" to continue working.',
+ );
+ my $confirm;
+ if (($type eq 'map') || ($type eq 'resource')) {
+ $confirm = $lt{'preamble'}.' '.$lt{$type}.' '.$lt{'ok'}.' '.$lt{'cancel'};
+ }
+ if ($confirm) {
+ return <
+
+
+
+
+
+
$confirm
+
+
+
+
+END
+ } else {
+ return;
+ }
+}
+
sub utilityfunctions {
my ($httphost) = @_;
my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
@@ -1489,8 +1659,26 @@ sub utilityfunctions {
my $countdown = &countdown_toggle_js();
+ my $hostvar = '
+function setLCHost() {
+ var lcHostname="";
+';
+ if ($httphost =~ m{^https?\://}) {
+ $hostvar .= ' var lcServer="'.$httphost.'";'."\n".
+ ' var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
+ ' var match = hostReg.exec(lcServer);'."\n".
+ ' if (match.length) {'."\n".
+ ' if (match[1] == location.hostname) {'."\n".
+ ' lcHostname=lcServer;'."\n".
+ ' }'."\n".
+ ' }'."\n";
+ }
+
+ $hostvar .= ' return lcHostname;'."\n".
+'}'."\n";
+
return (< 0) {
- $switcher = &create_submenu('','',$switchtext,\@submenu);
+ $switcher = &create_submenu('','',&mt('Switch role'),\@submenu);
}
}
return ($js,$form,$switcher);
@@ -2089,10 +2286,12 @@ sub countdown_timer {
}
my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
my @interval=&Apache::lonnet::EXT("resource.0.interval");
+ my ($timelimit,$usesdone);
if (@interval > 1) {
+ ($timelimit,$usesdone) = split(/_/,$interval[0]);
my $first_access=&Apache::lonnet::get_first_access($interval[1]);
if ($first_access > 0) {
- if ($first_access+$interval[0] > time) {
+ if ($first_access+$timelimit > time) {
$hastimeleft = 1;
}
}
@@ -2100,11 +2299,16 @@ sub countdown_timer {
if (($duedate && $duedate > time) ||
(!$duedate && $hastimeleft) ||
($slot_name ne '' && $slothastime)) {
- my ($collapse,$expand,$alttxt,$title,$currdisp);
+ my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
if ((@interval > 1 && $hastimeleft) ||
($type eq 'Task' && $slothastime)) {
$currdisp = 'inline';
$collapse = '► ';
+ if ((@interval > 1) && ($hastimeleft)) {
+ if ($usesdone eq 'done') {
+ $donebutton = &done_button_js($interval[1]);
+ }
+ }
} else {
$currdisp = 'none';
$expand = '◄ ';
@@ -2114,8 +2318,9 @@ sub countdown_timer {
$title = $alttxt.' ';
}
my $desc = &mt('Countdown to due date/time');
- return <
$collapse