[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface lonmenu.pm

raeburn raeburn at source.lon-capa.org
Thu Dec 27 00:52:01 EST 2012


raeburn		Thu Dec 27 05:52:01 2012 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	lonmenu.pm 
  Log:
  - For 2.11
    - Backport 1.400, 1.401, 1.402, 1.403
  
  
-------------- next part --------------
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.369.2.29 loncom/interface/lonmenu.pm:1.369.2.30
--- loncom/interface/lonmenu.pm:1.369.2.29	Sat Dec 22 15:08:10 2012
+++ loncom/interface/lonmenu.pm	Thu Dec 27 05:52:00 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.369.2.29 2012/12/22 15:08:10 raeburn Exp $
+# $Id: lonmenu.pm,v 1.369.2.30 2012/12/27 05:52:00 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -351,6 +351,8 @@
                      $env{'course.' . $env{'request.course.id'} . '.domain'},
                      $env{'course.' . $env{'request.course.id'} . '.num'});
 
+    my ($roleswitcher_js,$roleswitcher_form);
+
     foreach my $menuitem (@secondary_menu) {
         # evaluate conditions 
         next if    ref($menuitem)  ne 'ARRAY';
@@ -413,12 +415,12 @@
             }
         } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
             # special treatment for role selector
-            my $roles_selector = &roles_selector(
+            ($roleswitcher_js,$roleswitcher_form,my $switcher) =
+                &roles_selector(
                         $env{'course.' . $env{'request.course.id'} . '.domain'},
-                        $env{'course.' . $env{'request.course.id'} . '.num'}  );
-
-            $menu .= $roles_selector ? "<li style=\"padding: 0 0.8em;\">$roles_selector</li>"
-                                     : '';
+                        $env{'course.' . $env{'request.course.id'} . '.num'}
+                );
+            $menu .= $switcher;
         } else {
             $menu .= &prep_menuitem(\@$menuitem);
         }
@@ -446,6 +448,9 @@
     if ($menu) {
         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
     }
+    if ($roleswitcher_form) {
+        $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
+    }
     return $menu;
 }
 
@@ -2078,7 +2083,7 @@
     my $now = time;
     my (%courseroles,%seccount,%courseprivs);
     my $is_cc;
-    my $role_selector;
+    my ($js,$form,$switcher,$switchtext);
     my $ccrole;
     if ($crstype eq 'Community') {
         $ccrole = 'co';
@@ -2168,40 +2173,69 @@
     }
     my $switchtext;
     if ($crstype eq 'Community') {
-        $switchtext = &mt('Switch community role to...')
+        $switchtext = &mt('Switch community role')
     } else {
-        $switchtext = &mt('Switch course role to...')
+        $switchtext = &mt('Switch course role')
     }
     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
-    if (keys(%courseroles) > 1) {
-        $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
-        $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
-                          <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
-        $role_selector .= '<option value="">'.$switchtext.'</option>';
+    my $numdiffsec;
+    if (keys(%seccount) == 1) {
+        foreach my $key (keys(%seccount)) {
+            $numdiffsec = $seccount{$key};
+        }
+    }
+    if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
+        my @submenu;
+        $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
+        $form = 
+            '<form name="rolechooser" method="post" action="/adm/roles">'."\n".
+            '  <input type="hidden" name="destinationurl" value="'.
+            &HTML::Entities::encode($destinationurl).'" />'."\n".
+            '  <input type="hidden" name="gotorole" value="1" />'."\n".
+            '  <input type="hidden" name="selectrole" value="" />'."\n".
+            '  <input type="hidden" name="switchrole" value="" />'."\n";
+        if ($destsymb ne '') {
+            $form .= '   <input type="hidden" name="destsymb" value="'.
+                         &HTML::Entities::encode($destsymb).'" />'."\n";
+        }
+        $form .= '</form>'."\n";
         foreach my $role (@roles_order) {
+            my $include;
             if (defined($courseroles{$role})) {
-                $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>'; 
+                if ($env{'request.role'} =~ m{^\Q$role\E}) {
+                    if ($seccount{$role} > 1) {
+                        $include = 1;
+                    }
+                } else {
+                    $include = 1;
+                }
+            }
+            if ($include) {
+                push(@submenu,['javascript:adhocRole('."'$role'".')',
+                               &Apache::lonnet::plaintext($role,$crstype)]);
             }
         }
         foreach my $role (sort(keys(%courseroles))) {
             if ($role =~ /^cr/) {
-                $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
+                my $include;
+                if ($env{'request.role'} =~ m{^\Q$role\E}) {
+                    if ($seccount{$role} > 1) {
+                        $include = 1;
+                    }
+                } else {
+                    $include = 1;
+                }
+                if ($include) {
+                    push(@submenu,['javascript:adhocRole('."'$role'".')',
+                                   &Apache::lonnet::plaintext($role)]);
+                }
             }
         }
-        $role_selector .= '</select>'."\n";
-        if ($destsymb ne '') {
-            $role_selector .= '<input type="hidden" name="destsymb" value="'.
-                              &HTML::Entities::encode($destsymb).'" />'."\n";
+        if (@submenu > 0) {
+            $switcher = &create_submenu('','',$switchtext,\@submenu);
         }
-        $role_selector .=
-               '<input type="hidden" name="destinationurl" value="'.
-               &HTML::Entities::encode($destinationurl).'" />'."\n".
-               '<input type="hidden" name="gotorole" value="1" />'."\n".
-               '<input type="hidden" name="selectrole" value="" />'."\n".
-               '<input type="hidden" name="switch" value="1" />'."\n".
-               '</form>';
     }
-    return $role_selector;
+    return ($js,$form,$switcher);
 }
 
 sub get_all_courseroles {
@@ -2340,9 +2374,8 @@
     return <<"END";
 <script type="text/javascript">
 //<![CDATA[
-function adhocRole(roleitem) {
+function adhocRole(newrole) {
     $js
-    var newrole =  document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
     if (newrole == '') {
         return;
     } 
@@ -2359,7 +2392,6 @@
                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
                     document.rolechooser.destinationurl.value = '/adm/menu';
                 } else {
-                    document.rolechooser.elements[roleitem].selectedIndex = 0;
                     return;
                 }
             }
@@ -2402,14 +2434,13 @@
         return;
     }
     if (fullrole == "$env{'request.role'}") {
-        document.rolechooser.elements[roleitem].selectedIndex = 0;
         return;
     }
     itemid = retrieveIndex('gotorole');
     if (itemid != -1) {
         document.rolechooser.elements[itemid].name = fullrole;
     }
-    document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
+    document.rolechooser.switchrole.value = fullrole;
     document.rolechooser.selectrole.value = '1';
     document.rolechooser.submit();
     return;
@@ -2531,16 +2562,16 @@
                         $category_names{$entries[2]}=$entries[3];
                     } elsif ($configline=~/^prim\:/) {
                         my @entries = (split(/\:/, $configline))[1..5];
-                        push @primary_menu, \@entries;
+                        push(@primary_menu,\@entries);
                     } elsif ($configline=~/^primsub\:/) {
                         my ($parent, at entries) = (split(/\:/, $configline))[1..4];
-                        push (@{$primary_submenu{$parent}},\@entries);
+                        push(@{$primary_submenu{$parent}},\@entries);
                     } elsif ($configline=~/^scnd\:/) {
                         my @entries = (split(/\:/, $configline))[1..5];
-                        push @secondary_menu, \@entries; 
+                        push(@secondary_menu,\@entries);
                     } elsif ($configline=~/^scndsub\:/) {
                         my ($parent, at entries) = (split(/\:/, $configline))[1..4];
-                        push (@{$secondary_submenu{$parent}},\@entries);
+                        push(@{$secondary_submenu{$parent}},\@entries);
                     } elsif ($configline) {
                         push(@desklines,$configline);
                     }


More information about the LON-CAPA-cvs mailing list