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

raeburn raeburn@source.lon-capa.org
Sun, 19 Sep 2010 20:18:57 -0000


raeburn		Sun Sep 19 20:18:57 2010 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm 
  Log:
  - Do not include call to javascript: set_auth_radio_buttons() if only one type
    of authentication is assignable.
  - Eliminate javascript error reports for fields for authentication types which can not be set (and therefore do not appear in form).
  
  - &print_upload_manager_header(), &upload_manager_javascript_reverse_associate(), &upload_manager_javascript_forward_associate() take additional argument -
    ref to %can_assign.
  
  
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.122 loncom/interface/lonuserutils.pm:1.123
--- loncom/interface/lonuserutils.pm:1.122	Tue Sep 14 06:02:35 2010
+++ loncom/interface/lonuserutils.pm	Sun Sep 19 20:18:57 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.122 2010/09/14 06:02:35 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.123 2010/09/19 20:18:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -295,7 +295,8 @@
 }
 
 sub print_upload_manager_header {
-    my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype)=@_;
+    my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
+        $can_assign)=@_;
     my $javascript;
     #
     if (! exists($env{'form.upfile_associate'})) {
@@ -309,9 +310,9 @@
         }
     }
     if ($env{'form.upfile_associate'} eq 'reverse') {
-        $javascript=&upload_manager_javascript_reverse_associate();
+        $javascript=&upload_manager_javascript_reverse_associate($can_assign);
     } else {
-        $javascript=&upload_manager_javascript_forward_associate();
+        $javascript=&upload_manager_javascript_forward_associate($can_assign);
     }
     #
     # Deal with restored settings
@@ -585,6 +586,31 @@
 ###############################################################
 ###############################################################
 sub upload_manager_javascript_forward_associate {
+    my ($can_assign) = @_;
+    my $auth_update;
+    if (ref($can_assign) eq 'HASH') {
+        if (keys(%{$can_assign}) > 1) {
+            $auth_update = <<"END";
+   // If we set the password, make the password form below correspond to
+   // the new value.
+   if (nw==9) {
+      changed_radio('int',document.studentform);
+      set_auth_radio_buttons('int',document.studentform);
+END
+        }
+        if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
+           $auth_update .= "      vf.krbarg.value='';\n";
+        }
+        if ($can_assign->{'int'}) {
+           $auth_update .= "      vf.intarg.value='';\n";
+        }
+        if ($can_assign->{'loc'}) {
+           $auth_update .= "      vf.locarg.value='';\n";
+        }
+        $auth_update .= "
+   }\n";
+    }
+
     return(<<ENDPICK);
 function verify(vf,sec_caller) {
     var founduname=0;
@@ -661,15 +687,7 @@
          }
       }
    }
-   // If we set the password, make the password form below correspond to
-   // the new value.
-   if (nw==9) {
-       changed_radio('int',document.studentform);
-       set_auth_radio_buttons('int',document.studentform);
-       vf.intarg.value='';
-       vf.krbarg.value='';
-       vf.locarg.value='';
-   }
+   $auth_update
 }
 
 function clearpwd(vf) {
@@ -687,6 +705,29 @@
 ###############################################################
 ###############################################################
 sub upload_manager_javascript_reverse_associate {
+    my ($can_assign) = @_;
+    my $auth_update; 
+    if (ref($can_assign) eq 'HASH') {
+        if (keys(%{$can_assign}) > 1) {
+            $auth_update = <<"END";
+   // initial password specified, pick internal authentication
+   if (tf==8 && nw!=0) {
+      changed_radio('int',document.studentform);
+      set_auth_radio_buttons('int',document.studentform);
+END
+        }
+        if ($can_assign->{'krb'}) {      
+           $auth_update .= "      vf.krbarg.value='';\n";
+        }
+        if ($can_assign->{'int'}) {
+           $auth_update .= "      vf.intarg.value='';\n";
+        }
+        if ($can_assign->{'loc'}) {
+           $auth_update .= "      vf.locarg.value='';\n";
+        }
+        $auth_update .= "
+   }\n";
+    }
     return(<<ENDPICK);
 function verify(vf,sec_caller) {
     var founduname=0;
@@ -726,14 +767,7 @@
    if ((tf>=2) && (tf<=5) && (nw!=0)) {
       eval('vf.f1.selectedIndex=0;')
    }
-   // intial password specified, pick internal authentication
-   if (tf==8 && nw!=0) {
-       changed_radio('int',document.studentform);
-       set_auth_radio_buttons('int',document.studentform);
-       vf.krbarg.value='';
-       vf.intarg.value='';
-       vf.locarg.value='';
-   }
+   $auth_update
 }
 
 function clearpwd(vf) {
@@ -978,8 +1012,9 @@
     my ($krbdef,$krbdefdom) =
         &Apache::loncommon::get_kerberos_defaults($defdom);
     #
+    my ($authnum,%can_assign) =  &Apache::loncommon::get_assignable_auth($defdom);
     &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
-                                 $permission,$crstype);
+                                 $permission,$crstype,\%can_assign);
     my $i;
     my $keyfields;
     if ($total>=0) {