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

raeburn raeburn at source.lon-capa.org
Wed Dec 26 19:24:45 EST 2012


raeburn		Thu Dec 27 00:24:45 2012 EDT

  Modified files:              
    /loncom/interface	lonmenu.pm 
  Log:
  - Consistent interface.
    "Switch course role to ..." select box replaced with css-based drop down
    list similar to one used in primary menu for list of "Personal" functions.
  
  
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.400 loncom/interface/lonmenu.pm:1.401
--- loncom/interface/lonmenu.pm:1.400	Wed Dec 26 23:50:26 2012
+++ loncom/interface/lonmenu.pm	Thu Dec 27 00:24:45 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.400 2012/12/26 23:50:26 raeburn Exp $
+# $Id: lonmenu.pm,v 1.401 2012/12/27 00:24:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -331,6 +331,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';
@@ -363,12 +365,12 @@
 
         if ($$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>$roles_selector</li>"
-                                     : '';
+                        $env{'course.' . $env{'request.course.id'} . '.num'}
+                );
+            $menu .= $switcher;
         } else {
             $menu .= &prep_menuitem(\@$menuitem);
         }
@@ -396,6 +398,9 @@
     if ($menu) {
         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
     }
+    if ($roleswitcher_form) {
+        $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
+    }
     return $menu;
 }
 
@@ -1569,7 +1574,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';
@@ -1657,7 +1662,6 @@
             }
         }
     }
-    my $switchtext;
     if ($crstype eq 'Community') {
         $switchtext = &mt('Switch community role to...')
     } else {
@@ -1665,34 +1669,34 @@
     }
     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 @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".
+            '</form>'."\n";
         foreach my $role (@roles_order) {
             if (defined($courseroles{$role})) {
-                $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>'; 
+                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>'; 
+                 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 {
@@ -1831,9 +1835,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;
     } 
@@ -1850,7 +1853,6 @@
                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
                     document.rolechooser.destinationurl.value = '/adm/menu';
                 } else {
-                    document.rolechooser.elements[roleitem].selectedIndex = 0;
                     return;
                 }
             }
@@ -1886,21 +1888,19 @@
             fullrole += '/'+secchoice;
         }
     } else {
-        document.rolechooser.elements[roleitem].selectedIndex = 0;
         if (secchoice != null) {
             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
         }
         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;
@@ -2028,7 +2028,7 @@
                         push(@{$primary_submenu{$parent}},\@entries);
                     } elsif ($configline=~/^scnd\:/) {
                         my @entries = (split(/\:/, $configline))[1..5];
-                        push(@secondary_menu,\@entries); 
+                        push(@secondary_menu,\@entries);
                     } elsif ($configline) {
                         push(@desklines,$configline);
                     }




More information about the LON-CAPA-cvs mailing list