--- loncom/interface/lonmenu.pm 2013/11/24 15:32:39 1.422 +++ loncom/interface/lonmenu.pm 2015/05/28 12:37:14 1.431.2.4 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.422 2013/11/24 15:32:39 raeburn Exp $ +# $Id: lonmenu.pm,v 1.431.2.4 2015/05/28 12:37:14 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 @@ -283,8 +310,14 @@ sub primary_menu { $menu{$position} .= prep_menuitem($menuitem); } } - return ("
    $menu{'left'}
", - "
    $menu{'right'}
"); + my @output = ('',''); + if ($menu{'left'} ne '') { + $output[0] = "
    $menu{'left'}
"; + } + if ($menu{'right'} ne '') { + $output[1] = "
    $menu{'right'}
"; + } + return @output; } #returns hashref {user=>'',dom=>''} containing: @@ -493,32 +526,74 @@ sub create_submenu { ''. ' ▼'. ''; + + 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 .= '
  • '; + my $title; + if ($translate) { - $menu .= &mt($item->[1]); + $title = &mt($item->[1]); } else { - $menu .= $item->[1]; + $title = $item->[1]; + } + + if ($count == 1 && !$first_level) { + $bordertop = 'border-top: 1px solid black;'; + } + if ($count == $numsub) { + $borderbot = 'border-bottom: 1px solid black;'; + } + + # href is a reference to another submenu + if (ref($href) eq 'ARRAY') { + $menu .= '
  • '; + $menu .= '

    ' + . $title . '

    '; + $menu .= ''; + $menu .= '
  • '; + } else { # href is the actual hyperlink and does not represent another submenu + # for the current menu title + 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; + } + unless (($href eq '') || ($href =~ /^\#/)) { + $target = ' target="_top"'; + } + + $menu .= '
  • '; + $menu .= '' . $title . ''; + $menu .= '
  • '; } - $menu .= ''; } } - $menu .= ''; return $menu; } @@ -701,6 +776,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); @@ -759,11 +837,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])); @@ -1483,8 +1647,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 (< 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)) { + $donebutton = &done_button_js($interval[1]); + } } else { $currdisp = 'none'; $expand = '◄ '; @@ -2108,8 +2303,9 @@ sub countdown_timer { $title = $alttxt.' '; } my $desc = &mt('Countdown to due date/time'); - return < $collapse