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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Thu, 29 May 2008 00:43:21 -0000


This is a MIME encoded message

--raeburn1212021801
Content-Type: text/plain

raeburn		Wed May 28 20:43:21 2008 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm 
  Log:
  Bug 5595 and bug 5711.
  Improvements to display of available actions for user lists.
  
  
--raeburn1212021801
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080528204321.txt"

Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.55 loncom/interface/lonuserutils.pm:1.56
--- loncom/interface/lonuserutils.pm:1.55	Mon May 19 13:10:19 2008
+++ loncom/interface/lonuserutils.pm	Wed May 28 20:43:21 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.55 2008/05/19 17:10:19 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.56 2008/05/29 00:43:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1926,94 +1926,14 @@
     }
     if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
         my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
-        my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
-        my $singconfirm = &mt(' for a single user?');
-        my $multconfirm = &mt(' for multiple users?');
         my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
-        my %lt = &Apache::lonlocal::texthash( 
-              acwi => 'Access will be set to start immediately',
-              asyo => 'as you did not select an end date in the pop-up window',
-              accw => 'Access will be set to continue indefinitely',
-              asyd => 'as you did not select an end date in the pop-up window',
-              sewi => "Sections will be switched to 'No section'",
-              ayes => "as you either selected the 'No section' option",
-              oryo => 'or you did not select a section in the pop-up window',
-              arol => 'A role with no section will be added',
-              swbs => 'Sections will be switched to:',
-              rwba => 'Roles will be added for section(s):',
-        );
+        my $verify_action_js = &bulkaction_javascript($formname);
         $r->print(<<END);
 
 <script type="text/javascript" language="Javascript">
 $check_uncheck_js
 
-function verify_action (field) {
-    var numchecked = 0;
-    var singconf = '$singconfirm';
-    var multconf = '$multconfirm';
-    if (field.length > 0) {
-        for (i = 0; i < field.length; i++) {
-            if (field[i].checked == true) {
-               numchecked ++;
-            }
-        }
-    } else {
-        if (field.checked == true) {
-            numchecked ++;
-        }
-    }
-    if (numchecked == 0) {
-        alert("$alert");
-    } 
-    else {
-        var message = document.$formname.bulkaction[document.$formname.bulkaction.selectedIndex].text;
-        var choice = document.$formname.bulkaction[document.$formname.bulkaction.selectedIndex].value;
-        if (numchecked == 1) { 
-            message += singconf;
-        } 
-        else {
-            message += multconf; 
-        }
-        if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
-            var datemsg = '';
-            if ((document.$formname.startdate_month.value == '') && 
-                (document.$formname.startdate_day.value  == '') &&
-                (document.$formname.startdate_year.value == '')) {
-                datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
-            }
-            if ((document.$formname.enddate_month.value == '') &&
-                (document.$formname.enddate_day.value  == '') &&
-                (document.$formname.enddate_year.value == '')) {
-                datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
-            }
-            if (datemsg != '') {
-                message += "\\n"+datemsg;
-            }
-        }
-        if (choice == 'chgsec') {
-            var rolefilter = document.$formname.showrole.options[document.$formname.showrole.selectedIndex].value;
-            var retained =  document.$formname.retainsec.value;
-            var secshow = document.$formname.newsecs.value;
-            if (secshow == '') {
-                if (rolefilter == 'st' || retained == 0 || retained == "") {
-                    message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n"; 
-                } else {
-                    message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
-                }
-            } else {
-                if (rolefilter == 'st' || retained == 0 || retained == "") {
-                    message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
-                } else {
-                    message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
-                }
-            }
-        }
-        if (confirm(message)) {
-            document.$formname.phase.value = 'bulkchange';
-            document.$formname.submit();
-        }
-    }
-}
+$verify_action_js
 
 function username_display_launch(username,domain) {
     var target;
@@ -2074,12 +1994,11 @@
                        'clicker'    => "clicker id",
                        'photo'      => "photo",
                        'extent'     => "extent",
-                       'go'         => "go",
                        'pr'         => "Proceed",
                        'ca'         => "check all",
                        'ua'         => "uncheck all",
                        'ac'         => "Action to take for selected users",
-                       'link'       => "Behavior of username links",
+                       'link'       => "Behavior of clickable username link for each user",
                        'aboutme'    => "Display a user's personal page",
                        'owin'       => "Open in a new window",
                        'modify'     => "Modify a user's information",
@@ -2127,7 +2046,7 @@
     if ($mode ne 'autoenroll') {
         $results_description = &results_header_row($rolefilter,$statusmode,
                                                    $context,$permission,$mode);
-        $r->print('<b>'.$results_description.'</b><br />');
+        $r->print('<b>'.$results_description.'</b><br /><br />');
     }
     my ($output,$actionselect,%canchange,%canchangesec);
     if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
@@ -2142,33 +2061,12 @@
 <input type="hidden" name="srchterm" value="" />
 <input type="hidden" name="srchdomain" value="" /> 
 END
-            $output = '<p>';
-            my @linkdests = ('aboutme');
-            if ($permission->{'cusr'}) {
-                unshift (@linkdests,'modify');
-            }
-            $output .= '<span class="LC_nobreak">'.$lt{'link'}.':&nbsp;';
-            my $usernamelink = $env{'form.usernamelink'};
-            if ($usernamelink eq '') {
-                $usernamelink = 'aboutme';
-            }
-            foreach my $item (@linkdests) {
-                my $checkedstr = '';
-                if ($item eq $usernamelink) {
-                    $checkedstr = ' checked="checked" ';
-                }
-                $output .= '<label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.'>&nbsp;'.$lt{$item}.'</label>&nbsp;&nbsp;';
-            }
-            my $checkwin;
-            if ($env{'form.userwin'}) { 
-                $checkwin = 'checked = "checked"'; 
-            }
-            $output .= '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="userwin" value="1" $checkwin />'.$lt{'owin'}.'</span><br />';
             if ($actionselect) {
                 $output .= <<"END";
-$lt{'ac'}:&nbsp;$actionselect <input type="button" value="$lt{'go'}" onclick="javascript:opendatebrowser(this.form,'$formname','go')" /></p>
-<p><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" /> &nbsp;
-<input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.$formname.actionlist)" /><br /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action(document.$formname.actionlist)" />
+<div class="LC_left_float"><fieldset><legend><b>$lt{'ac'}</b></legend>
+$actionselect
+<br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" /> &nbsp;
+<input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.$formname.actionlist)" /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action('actionlist')" /></fieldset></div>
 END
                 my @allroles;
                 if ($env{'form.showrole'} eq 'Any') {
@@ -2210,8 +2108,31 @@
                     }
                 }
             }
+            $output .= '<div class="LC_left_float"><fieldset><legend><b>'.$lt{'link'}.'</b></legend>'.
+                       '<table><tr>';
+            my @linkdests = ('aboutme');
+            if ($permission->{'cusr'}) {
+                unshift (@linkdests,'modify');
+            }
+            $output .= '<td>';
+            my $usernamelink = $env{'form.usernamelink'};
+            if ($usernamelink eq '') {
+                $usernamelink = 'aboutme';
+            }
+            foreach my $item (@linkdests) {
+                my $checkedstr = '';
+                if ($item eq $usernamelink) {
+                    $checkedstr = ' checked="checked" ';
+                }
+                $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.'>&nbsp;'.$lt{$item}.'</label></span><br />';
+            }
+            my $checkwin;
+            if ($env{'form.userwin'}) {
+                $checkwin = 'checked = "checked"';
+            }
+            $output .= '</td><td valign="top"><span class="LC_nobreak"><input type="checkbox" name="userwin" value="1" '.$checkwin.'/>'.$lt{'owin'}.'</span></td></tr></table></fieldset></div>';
         }
-        $output .= "\n<p>\n".
+        $output .= "\n".'<div class="LC_clear_float_footer">&nbsp;</div>'."\n".
                   &Apache::loncommon::start_data_table().
                   &Apache::loncommon::start_data_table_header_row();
         if ($mode eq 'autoenroll') {
@@ -2607,6 +2528,125 @@
     }
 }
 
+sub bulkaction_javascript {
+    my ($formname,$caller) = @_;
+    my $docstart = 'document';
+    if ($caller eq 'popup') {
+        $docstart = 'opener.document';
+    }
+    my %lt = &Apache::lonlocal::texthash(
+              acwi => 'Access will be set to start immediately',
+              asyo => 'as you did not select an end date in the pop-up window',
+              accw => 'Access will be set to continue indefinitely',
+              asyd => 'as you did not select an end date in the pop-up window',
+              sewi => "Sections will be switched to 'No section'",
+              ayes => "as you either selected the 'No section' option",
+              oryo => 'or you did not select a section in the pop-up window',
+              arol => 'A role with no section will be added',
+              swbs => 'Sections will be switched to:',
+              rwba => 'Roles will be added for section(s):',
+            );
+    my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
+    my $noaction = &mt("You need to select an action to take for the user(s) you have selected"); 
+    my $singconfirm = &mt(' for a single user?');
+    my $multconfirm = &mt(' for multiple users?');
+    my $output = <<"ENDJS";
+function verify_action (field) {
+    var numchecked = 0;
+    var singconf = '$singconfirm';
+    var multconf = '$multconfirm';
+    if ($docstart.$formname.elements[field].length > 0) {
+        for (i=0; i<$docstart.$formname.elements[field].length; i++) {
+            if ($docstart.$formname.elements[field][i].checked == true) {
+               numchecked ++;
+            }
+        }
+    } else {
+        if ($docstart.$formname.elements[field].checked == true) {
+            numchecked ++;
+        }
+    }
+    if (numchecked == 0) {
+        alert("$alert");
+        return;
+    } else {
+        var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
+        var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
+        if (choice == '') {
+            alert("$noaction");
+            return;
+        } else {
+            if (numchecked == 1) {
+                message += singconf;
+            } else {
+                message += multconf;
+            }
+ENDJS
+    if ($caller ne 'popup') {
+        $output .= <<"NEWWIN";
+            if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
+                opendatebrowser(document.$formname,'$formname','go');
+                return;
+
+            } else {
+                if (confirm(message)) {
+                    document.$formname.phase.value = 'bulkchange';
+                    document.$formname.submit();
+                    return;
+                }
+            }
+NEWWIN
+    } else {
+        $output .= <<"POPUP";
+            if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
+                var datemsg = '';
+                if (($docstart.$formname.startdate_month.value == '') &&
+                    ($docstart.$formname.startdate_day.value  == '') &&
+                    ($docstart.$formname.startdate_year.value == '')) {
+                    datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
+                }
+                if (($docstart.$formname.enddate_month.value == '') &&
+                    ($docstart.$formname.enddate_day.value  == '') &&
+                    ($docstart.$formname.enddate_year.value == '')) {
+                    datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
+                }
+                if (datemsg != '') {
+                    message += "\\n"+datemsg;
+                }
+            }
+            if (choice == 'chgsec') {
+                var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
+                var retained =  $docstart.$formname.retainsec.value;
+                var secshow = $docstart.$formname.newsecs.value;
+                if (secshow == '') {
+                    if (rolefilter == 'st' || retained == 0 || retained == "") {
+                        message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
+                    } else {
+                        message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
+                    }
+                } else {
+                    if (rolefilter == 'st' || retained == 0 || retained == "") {
+                        message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
+                    } else {
+                        message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
+                    }
+                }
+            }
+            if (confirm(message)) {
+                $docstart.$formname.phase.value = 'bulkchange';
+                $docstart.$formname.submit();
+                window.close();
+            }
+POPUP
+    }
+    $output .= '
+        }
+    }
+}
+';
+    return $output;
+}
+
 sub print_username_link {
     my ($mode,$in) = @_;
     my $output;
@@ -2691,7 +2731,7 @@
         }
     }
     if ($options) {
-        $output = '<select name="bulkaction" onchange="javascript:opendatebrowser(this.form,'."'$formname','change'".')" />'."\n".
+        $output = '<select name="bulkaction">'."\n".
                   '<option value="" selected="selected">'.
                   &mt('Please select').'</option>'."\n".$options."\n".'</select>';
         if ($choices{'dates'}) {
@@ -2707,7 +2747,8 @@
                 '<input type="hidden" name="enddate_year" value="" />'."\n".
                 '<input type="hidden" name="enddate_hour" value="" />'."\n".
                 '<input type="hidden" name="enddate_minute" value="" />'."\n".
-                '<input type="hidden" name="enddate_second" value="" />'."\n";
+                '<input type="hidden" name="enddate_second" value="" />'."\n".
+                '<input type="hidden" name="no_end_date" value="" />'."\n";
             if ($context eq 'course') {
                 $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
             }
@@ -2733,20 +2774,6 @@
     $output .= <<"ENDONE";
     function opendatebrowser(callingform,formname,calledby) {
         var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
-        if (bulkaction == 'revoke' || bulkaction == 'delete' || bulkaction == '') {
-            if (calledby == 'go') {
-                if (bulkaction == 'revoke') {
-                    alert("$nopopup{'revoke'}");
-                }
-                if (bulkaction == 'delete') {
-                    alert("$nopopup{'delete'}"); 
-                }
-                if (bulkaction == '') {
-                    alert("$nopopup{'none'}");
-                }
-            }
-            return;
-        }
         var url = '/adm/createuser?';
         var type = '';
         var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
@@ -2800,9 +2827,7 @@
         setSections(formname);
         if (seccheck == 'ok') {
             opener.document.$callingform.newsecs.value = formname.sections.value;
-            window.close();
         }
-        return;
 END
     } else {
         if ($context eq 'course') {
@@ -2836,13 +2861,22 @@
     opener.document.$callingform.enddate_hour.value =  formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
     opener.document.$callingform.enddate_minute.value =  formname.enddate_minute.value;
     opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
-    window.close();
+    if (formname.no_end_date.checked) {
+        opener.document.$callingform.no_end_date.value = '1';
+    } else {
+        opener.document.$callingform.no_end_date.value = '0';
+    }
 END
     }
-    $output .= '
+    my $verify_action_js = &bulkaction_javascript($callingform,'popup');
+    $output .= <<"ENDJS";
+    verify_action('actionlist');
 }
+
+$verify_action_js
+
 </script>
-';
+ENDJS
     my %lt = &Apache::lonlocal::texthash (
                  chac => 'Access dates to apply for selected users',
                  chse => 'Changes in section affiliation to apply to selected users',
@@ -2899,8 +2933,7 @@
         $output .= $info.$secbox;
     }
     $output .= '<p>'.
-&mt('Use "Save" to update the main window with your selections.').'<br /><br />'.
-'<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
+'<input type="button" name="dateselection" value="'.&mt('Make changes').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
 '</form>';
     return $output;
 }

--raeburn1212021801--