Diff for /loncom/interface/lonmenu.pm between versions 1.369.2.57 and 1.369.2.58

version 1.369.2.57, 2016/08/13 21:14:50 version 1.369.2.58, 2016/09/15 02:25:12
Line 132  Inputs: 6 - (a) link and (b) target for Line 132  Inputs: 6 - (a) link and (b) target for
             (f) optional class for <li> element in primary menu, for which              (f) optional class for <li> element in primary menu, for which
                 sub menu is being generated.                  sub menu is being generated.
   
   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()  =item innerregister()
   
Line 285  sub primary_menu { Line 312  sub primary_menu {
                                                            undef,'tools')));                                                             undef,'tools')));
                     push(@primsub,$item);                      push(@primsub,$item);
                 }                  }
                   if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
                       $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
                   } else {
                       $title = &mt($title);
                   }
                 if (@primsub > 0) {                  if (@primsub > 0) {
                     $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);                      $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
                 } elsif ($link) {                  } elsif ($link) {
Line 536  sub create_submenu { Line 568  sub create_submenu {
     if ($target ne '') {      if ($target ne '') {
         $disptarget = ' target="'.$target.'"';          $disptarget = ' target="'.$target.'"';
     }      }
     my $name;  
     if ($title eq 'Personal') {  
         if ($env{'user.name'} && $env{'user.domain'}) {  
             $name = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});  
         } else {  
             $name = &mt($title);  
         }  
     } else {  
         $name = &mt($title);  
     }  
     my $menu = '<li class="LC_hoverable '.$addclass.'">'.      my $menu = '<li class="LC_hoverable '.$addclass.'">'.
                '<a href="'.$link.'"'.$disptarget.'>'.                 '<a href="'.$link.'"'.$disptarget.'>'.
                '<span class="LC_nobreak">'.$name.                 '<span class="LC_nobreak">'.$title.
                '<span class="LC_fontsize_small" style="font-weight:normal;">'.                 '<span class="LC_fontsize_small" style="font-weight:normal;">'.
                ' &#9660;</span></span></a>'.                 ' &#9660;</span></span></a>'.
                '<ul>';                 '<ul>';
   
       # $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 .= '</ul></li>';
   
       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) = @_;
       unless (@{$submenu}) {
           return '';
       }
   
       my $menu = '';
     my $count = 0;      my $count = 0;
     my $numsub = scalar(@{$submenu});      my $numsub = scalar(@{$submenu});
     foreach my $item (@{$submenu}) {      foreach my $item (@{$submenu}) {
         $count ++;          $count ++;
         if (ref($item) eq 'ARRAY') {          if (ref($item) eq 'ARRAY') {
             my $href = $item->[0];              my $href = $item->[0];
             if ($href =~ /(aboutme|rss\.html)$/) {              my $bordertop;
                 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 $borderbot;              my $borderbot;
             if ($count == $numsub) {              my $title;
                 $borderbot = 'border-bottom:1px solid black;';  
             }  
             unless (($href eq '') || ($href =~ /^\#/)) {  
                 $target = ' target="_top"';  
             }  
             $menu .= '<li style="margin:0;padding:0;'.  
                      $borderbot.'"><a href="'.$href.'"'.$target.'>';  
             if ($translate) {              if ($translate) {
                 $menu .= &mt($item->[1]);                   $title = &mt($item->[1]);
             } else {              } 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 .= '<li style="margin:0;padding:0;'.$bordertop . $borderbot . '">';
                   $menu .= '<p><span class="LC_primary_menu_innertitle">'
                                           . $title . '</span><span class="LC_primary_menu_innerarrow">&#9654;</span></p>';
                   $menu .= '<ul>';
                   $menu .= &build_submenu($target, $href, $translate);
                   $menu .= '</ul>';
                   $menu .= '</li>';
               } 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 .= '<li style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
                   $menu .= '<a href="'.$href.'"'.$target.'>' .  $title . '</a>';
                   $menu .= '</li>';
             }              }
             $menu .= '</a></li>';  
         }          }
     }      }
     $menu .= '</ul></li>';  
     return $menu;      return $menu;
 }  }
   
Line 2285  sub roles_selector { Line 2346  sub roles_selector {
     my $now = time;      my $now = time;
     my (%courseroles,%seccount,%courseprivs);      my (%courseroles,%seccount,%courseprivs);
     my $is_cc;      my $is_cc;
     my ($js,$form,$switcher,$switchtext);      my ($js,$form,$switcher);
     my $ccrole;      my $ccrole;
     if ($crstype eq 'Community') {      if ($crstype eq 'Community') {
         $ccrole = 'co';          $ccrole = 'co';
Line 2373  sub roles_selector { Line 2434  sub roles_selector {
             }              }
         }          }
     }      }
     $switchtext = 'Switch role'; # do not translate here  
     my @roles_order = ($ccrole,'in','ta','ep','ad','st');      my @roles_order = ($ccrole,'in','ta','ep','ad','st');
     my $numdiffsec;      my $numdiffsec;
     if (keys(%seccount) == 1) {      if (keys(%seccount) == 1) {
Line 2429  sub roles_selector { Line 2489  sub roles_selector {
             }              }
         }          }
         if (@submenu > 0) {          if (@submenu > 0) {
             $switcher = &create_submenu('','',$switchtext,\@submenu);              $switcher = &create_submenu('','',&mt('Switch role'),\@submenu);
         }          }
     }      }
     return ($js,$form,$switcher);      return ($js,$form,$switcher);

Removed from v.1.369.2.57  
changed lines
  Added in v.1.369.2.58


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>