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

bisitz bisitz@source.lon-capa.org
Tue, 04 Aug 2009 18:02:30 -0000


This is a MIME encoded message

--bisitz1249408950
Content-Type: text/plain

bisitz		Tue Aug  4 18:02:30 2009 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  - Optimized User Change Logs:
      - Optimized navigation
          - Use buttons instead of simple links
          - Also offer buttons above table now
      - Simplified way to find out if table needs to be printed
  
  - Tidied up code:
      - Added some comments
      - XHTML: lower case HTML attributes (onClick, onFocus)
      - Properly include Javascript
      - Added some code line breaks for better readability
  
  - HTML Code Corrections
      - Corrected Context selection preselection
      - Corrected unbalanced tags:
          - Added missing </span> to "Changes/page" selection
          - Added missing </td> to "Update Display"
  
  (Work in progress)
  
  
--bisitz1249408950
Content-Type: text/plain
Content-Disposition: attachment; filename="bisitz-20090804180230.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.300 loncom/interface/loncreateuser.pm:1.301
--- loncom/interface/loncreateuser.pm:1.300	Mon Jul 27 14:09:14 2009
+++ loncom/interface/loncreateuser.pm	Tue Aug  4 18:02:30 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.300 2009/07/27 14:09:14 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.301 2009/08/04 18:02:30 bisitz Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -143,6 +143,7 @@
     $custom_off = ' checked="checked" ';
     my $quota_javascript = <<"END_SCRIPT";
 <script type="text/javascript">
+// <![CDATA[
 function quota_changes(caller) {
     if (caller == "custom") {
         if (document.cu.customquota[0].checked) {
@@ -153,6 +154,7 @@
         document.cu.customquota[1].checked = true;
     }
 }
+// ]]>
 </script>
 END_SCRIPT
     if ($quotatype eq 'custom') {
@@ -335,7 +337,9 @@
 
     my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
         '<script type="text/javascript">'."\n".
-        &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset}).
+        '// <![CDATA['."\n".
+        &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
+        '// ]]>'."\n".
         '</script>'."\n";
 
     my %loaditems = (
@@ -502,7 +506,7 @@
     
     return <<END;
 <script type="text/javascript" language="Javascript">
-
+// <![CDATA[
     function pclose() {
         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                  "height=350,width=350,scrollbars=no,menubar=no");
@@ -519,7 +523,7 @@
     }
 
     $nondc_setsection_code
-
+// ]]>
 </script>
 END
 }
@@ -538,6 +542,7 @@
 
     my $jscript = (<<ENDSCRIPT);
 <script type="text/javascript">
+// <![CDATA[
 function pickuser(uname,udom) {
     document.usersrchform.seluname.value=uname;
     document.usersrchform.seludom.value=udom;
@@ -546,6 +551,7 @@
 }
 
 $jsback
+// ]]>
 </script>
 ENDSCRIPT
 
@@ -794,7 +800,9 @@
 $response
 $forminfo
 <script type="text/javascript" language="Javascript">
+// <![CDATA[
 $loginscript
+// ]]>
 </script>
 <input type='hidden' name='makeuser' value='1' />
 <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
@@ -851,7 +859,7 @@
                             } else {
                                 if ($authtype eq 'int') {
                                     $varauth = '<br />'.
-&mt('[_1] Internally authenticated (with initial password [_2])','','<input type="password" size="10" name="intarg" value="" />')."<label><input type=\"checkbox\" name=\"visible\" onClick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
+&mt('[_1] Internally authenticated (with initial password [_2])','','<input type="password" size="10" name="intarg" value="" />')."<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
                                 } elsif ($authtype eq 'loc') {
                                     $varauth = '<br />'.
 &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
@@ -993,7 +1001,7 @@
     } ## End of new user/old user logic
 
     if ($env{'form.action'} eq 'singlestudent') {
-        $r->print('<br /><input type="button" value="'.&mt('Enroll Student').'" onClick="setSections(this.form)" />'."\n");
+        $r->print('<br /><input type="button" value="'.&mt('Enroll Student').'" onclick="setSections(this.form)" />'."\n");
     } else {
         $r->print('<h3>'.&mt('Add Roles').'</h3>');
         my $addrolesdisplay = 0;
@@ -1006,14 +1014,14 @@
                 $addrolesdisplay = $add_domainroles;
             }
             $r->print(&course_level_dc($env{'request.role.domain'},'Course'));
-            $r->print('<br /><input type="button" value="'.&mt('Save').'" onClick="setCourse()" />'."\n");
+            $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
         } elsif ($context eq 'author') {
             if ($addrolesdisplay) {
                 $r->print('<br /><input type="button" value="'.&mt('Save').'"');
                 if ($newuser) {
-                    $r->print(' onClick="auth_check()" \>'."\n");
+                    $r->print(' onclick="auth_check()" \>'."\n");
                 } else {
-                    $r->print('onClick="this.form.submit()" \>'."\n");
+                    $r->print('onclick="this.form.submit()" \>'."\n");
                 }
             } else {
                 $r->print('<br /><a href="javascript:backPage(document.cu)">'.
@@ -1021,7 +1029,7 @@
             }
         } else {
             $r->print(&course_level_table(%inccourses));
-            $r->print('<br /><input type="button" value="'.&mt('Save').'" onClick="setSections(this.form)" />'."\n");
+            $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
         }
     }
     $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
@@ -1089,7 +1097,11 @@
                                    $nondc_setsection_code,$groupslist);
     my ($jsback,$elements) = &crumb_utilities();
     $js .= "\n".
-           '<script type="text/javascript">'."\n".$jsback."\n".'</script>';
+           '<script type="text/javascript">'."\n".
+           '// <![CDATA['."\n".
+           $jsback."\n".
+           '// ]]>'."\n".
+           '</script>'."\n";
     return $js;
 }
 
@@ -1442,7 +1454,9 @@
             my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
             $outcome = <<ENDBADAUTH;
 <script type="text/javascript" language="Javascript">
+// <![CDATA[
 $loginscript
+// ]]>
 </script>
 <span class="LC_error">$lt{'err'}:
 $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
@@ -1471,7 +1485,9 @@
                                                );
             $outcome =
                        '<script type="text/javascript" language="Javascript">'."\n".
+                       '// <![CDATA['."\n".
                        $loginscript."\n".
+                       '// ]]>'."\n".
                        '</script>'."\n".
                        '<h3>'.$lt{'ld'}.'</h3>'.
                        &Apache::loncommon::start_data_table().
@@ -1802,7 +1818,10 @@
     my $newuser = 0;
     my ($jsback,$elements) = &crumb_utilities();
     my $jscript = '<script type="text/javascript">'."\n".
-                  $jsback."\n".'</script>'."\n";
+                  '// <![CDATA['."\n".
+                  $jsback."\n".
+                  '// ]]>'."\n".
+                  '</script>'."\n";
     my %breadcrumb_text = &singleuser_breadcrumb();
     my $args;
     if ($env{'form.popup'}) {
@@ -3242,13 +3261,16 @@
     my ($jsback,$elements) = &crumb_utilities();
     my $button_code = "\n";
     my $head_script = "\n";
-    $head_script .= '<script type="text/javascript">'."\n";
+    $head_script .= '<script type="text/javascript">'."\n"
+                   .'// <![CDATA['."\n";
     my @template_roles = ("cc","in","ta","ep","st");
     foreach my $role (@template_roles) {
         $head_script .= &make_script_template($role);
         $button_code .= &make_button_code($role).' ';
     }
-    $head_script .= "\n".$jsback."\n".'</script>'."\n";
+    $head_script .= "\n".$jsback."\n"
+                   .'// ]]>'."\n"
+                   .'</script>'."\n";
     $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
    &Apache::lonhtmlcommon::add_breadcrumb
      ({href=>"javascript:backPage(document.form1,'pickrole','')",
@@ -3378,7 +3400,7 @@
 sub make_button_code {
     my ($role) = @_;
     my $label = &Apache::lonnet::plaintext($role);
-    my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
+    my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
     return ($button_code);
 }
 # ---------------------------------------------------------- Call to definerole
@@ -3391,7 +3413,11 @@
         return;
     }
     my ($jsback,$elements) = &crumb_utilities();
-    my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
+    my $jscript = '<script type="text/javascript">'
+                 .'// <![CDATA['."\n"
+                 .$jsback."\n"
+                 .'// ]]>'."\n"
+                 .'</script>'."\n";
 
     $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
     &Apache::lonhtmlcommon::add_breadcrumb
@@ -3763,7 +3789,11 @@
 
 sub add_script {
     my ($js) = @_;
-    return '<script type="text/javascript">'."\n".$js."\n".'</script>';
+    return '<script type="text/javascript">'."\n"
+          .'// <![CDATA['."\n"
+          .$js."\n"
+          .'// ]]>'."\n"
+          .'</script>'."\n";
 }
 
 sub verify_user_display {
@@ -4143,7 +4173,9 @@
     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 
     my $output = '<script type="text/javascript">'."\n".
+                 '// <![CDATA['."\n".
                  $setsec_js."\n".$selfenroll_js."\n".
+                 '// ]]>'."\n".
                  '</script>'."\n".
                  '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
     my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
@@ -4939,13 +4971,6 @@
     my (%whodunit,%changed,$version);
     ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
     $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version));
-    my $showntablehdr = 0;
-    my $tablehdr = &Apache::loncommon::start_data_table().
-                   &Apache::loncommon::start_data_table_header_row().
-                   '<th>&nbsp;</th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
-                   '</th><th>'.&mt('Changed User').'</th><th>'.&mt('Role').'</th><th>'.&mt('Section').'</th><th>'.
-                   &mt('Context').'</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
-                   &Apache::loncommon::end_data_table_header_row();
     my ($minshown,$maxshown);
     $minshown = 1;
     my $count = 0;
@@ -4955,6 +4980,9 @@
             $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
         }
     }
+
+    # Collect user change log data
+    my $content = '';
     foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
         next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
                  ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
@@ -4976,10 +5004,7 @@
         }
         $count ++;
         next if ($count < $minshown);
-        if (!$showntablehdr) {
-            $r->print($tablehdr);
-            $showntablehdr = 1;
-        }
+
         if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
             $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
                 &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
@@ -5018,21 +5043,43 @@
         if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
             $chgcontext = $lt{$chgcontext};
         }
-        $r->print(&Apache::loncommon::start_data_table_row().'<td>'.$count.'</td><td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td><td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td><td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td><td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'}).'</td><td>'.$sec.'</td><td>'.$chgcontext.'</td><td>'.$rolestart.'</td><td>'.$roleend.'</td>'.&Apache::loncommon::end_data_table_row()."\n");
+        $content .=
+            &Apache::loncommon::start_data_table_row()
+           .'<td>'.$count.'</td>'
+           .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
+           .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
+           .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
+           .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'}).'</td>'
+           .'<td>'.$sec.'</td>'
+           .'<td>'.$chgcontext.'</td>'
+           .'<td>'.$rolestart.'</td>'
+           .'<td>'.$roleend.'</td>'
+           .&Apache::loncommon::end_data_table_row();
+    }
+
+    # Form Footer
+    my $form_footer =
+        '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
+       .'<input type="hidden" name="action" value="changelogs" />'
+       .'</form>';
+
+    # Only display table, if content is available (has been collected above)
+    if (!$content) {
+        $r->print('<p class="LC_info">'
+                 .&mt('There are no records to display.')
+                 .'</p>'
+        );
+        $r->print($form_footer);
+        return;
     }
-    if ($showntablehdr) {
-        $r->print(&Apache::loncommon::end_data_table().'<br />');
-        if (($curr{'page'} > 1) || ($more_records)) {
-            $r->print('<table><tr>');
-            if ($curr{'page'} > 1) {
-                $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
-            }
-            if ($more_records) {
-                $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
-            }
-            $r->print('</tr></table>');
-            $r->print(<<"ENDSCRIPT");
+
+    # Content to display, so create navigation and display table
+
+    # Create Navigation:
+    # Navigation Script
+    my $nav_script = <<"ENDSCRIPT";
 <script type="text/javascript">
+// <![CDATA[
 function chgPage(caller) {
     if (caller == 'previous') {
         document.$formname.page.value --;
@@ -5043,14 +5090,54 @@
     document.$formname.submit(); 
     return;
 }
+// ]]>
 </script>
 ENDSCRIPT
-        }
-    } else {
-        $r->print(&mt('There are no records to display'));
-    }
-    $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
-              '<input type="hidden" name="action" value="changelogs" /></form>');
+    # Navigation Buttons
+    my $nav_links;
+    $nav_links = '<p>';
+    if (($curr{'page'} > 1) || ($more_records)) {
+        if ($curr{'page'} > 1) {
+            $nav_links .= '<input type="button"'
+                         .' onclick="javascript:chgPage('."'previous'".');"'
+                         .' value="'.&mt('Previous [_1] changes',$curr{'show'})
+                         .'" /> ';
+        }
+        if ($more_records) {
+            $nav_links .= '<input type="button"'
+                         .' onclick="javascript:chgPage('."'next'".');"'
+                         .' value="'.&mt('Next [_1] changes',$curr{'show'})
+                         .'" />';
+        }
+    }
+    $nav_links .= '</p>';
+
+    # Table Header
+    my $tableheader =
+        &Apache::loncommon::start_data_table()
+       .&Apache::loncommon::start_data_table_header_row()
+       .'<th>&nbsp;</th>'
+       .'<th>'.&mt('When').'</th>'
+       .'<th>'.&mt('Who made the change').'</th>'
+       .'<th>'.&mt('Changed User').'</th>'
+       .'<th>'.&mt('Role').'</th>'
+       .'<th>'.&mt('Section').'</th>'
+       .'<th>'.&mt('Context').'</th>'
+       .'<th>'.&mt('Start').'</th>'
+       .'<th>'.&mt('End').'</th>'
+       .&Apache::loncommon::end_data_table_header_row();
+
+    # Print Content
+    $r->print(
+        $nav_script
+       .$nav_links
+       .&Apache::loncommon::start_data_table()
+       .$tableheader
+       .$content
+       .&Apache::loncommon::end_data_table()
+       .$nav_links
+       .$form_footer
+    );
     return;
 }
 
@@ -5059,7 +5146,7 @@
     my $context = 'course';
     my $nolink = 1;
     my $output = '<table><tr><td valign="top">'.
-                 '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b><br />'.
+                 '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
                  &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
                                               (&mt('all'),5,10,20,50,100,1000,10000)).
                  '</td><td>&nbsp;&nbsp;</td>';
@@ -5072,9 +5159,13 @@
                                             $curr->{'rolelog_end_date'},undef,
                                             undef,undef,undef,undef,undef,undef,$nolink);
     my %lt = &rolechg_contexts();
-    $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br /><table><tr><td>'.&mt('After:').
-               '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
-               $endform.'</td></tr></table></td><td>&nbsp;&nbsp;</td>'.
+    $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
+               '<table><tr><td>'.&mt('After:').
+               '</td><td>'.$startform.'</td></tr>'.
+               '<tr><td>'.&mt('Before:').'</td>'.
+               '<td>'.$endform.'</td></tr></table>'.
+               '</td>'.
+               '<td>&nbsp;&nbsp;</td>'.
                '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
                '<select name="role"><option value="any"';
     if ($curr->{'role'} eq 'any') {
@@ -5095,20 +5186,24 @@
         }
         $output .= '  <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
     }
-    $output .= '</select></td><td>&nbsp;&nbsp;</td><td valign="top"><b>'.
+    $output .= '</select></td>'.
+               '<td>&nbsp;&nbsp;</td>'.
+               '<td valign="top"><b>'.
                &mt('Context:').'</b><br /><select name="chgcontext">';
     foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll') {
         my $selstr = '';
         if ($curr->{'chgcontext'} eq $chgtype) {
-            $output .= $selstr = ' selected="selected"';
+            $selstr = ' selected="selected"';
         }
         if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
             next if (!&Apache::lonnet::auto_run($cnum,$cdom));
         }
         $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
     }
-    $output .= '</select></td><td>&nbsp;&nbsp;</td><td valign="middle"><input type="submit" value="'.
-               &mt('Update Display').'" /></tr></table>'.
+    $output .= '</select></td>'.
+               '<td>&nbsp;&nbsp;</td>'.
+               '<td valign="middle"><input type="submit" value="'.
+               &mt('Update Display').'" /></td></tr></table>'.
                '<span class="LC_roleslog_note">'.
                &mt('[_1]Note:[_2] Only changes made from servers running LON-CAPA 2.6.99.0 or later are displayed.');
     if ($version) {
@@ -5742,7 +5837,7 @@
                  '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
                  &Apache::loncommon::end_data_table_header_row();
     my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
-                     '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
+                     '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
                      '<td><select name="role">'."\n";
     foreach my $role (@roles) {
         my $plrole=&Apache::lonnet::plaintext($role);

--bisitz1249408950--