[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonpickuser.pm lonrequestcourse.pm

raeburn raeburn@source.lon-capa.org
Sun, 06 Sep 2009 19:09:55 -0000


This is a MIME encoded message

--raeburn1252264195
Content-Type: text/plain

raeburn		Sun Sep  6 19:09:55 2009 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonrequestcourse.pm lonpickuser.pm 
  Log:
  - Bug 5995.
   - Username field in "Additional" personnel accepts type-in input from user.
   - "Search for User" link provided for requestors who want to search.
   - "Check username" link provided for requestors who know the username and
     want to check it and/or complete the user information fields from stored data.
   - Javascript function - openuserbrowser() takes additional argument - caller - to trigger immediate username search if "check username" link used.
   - Javascript function - fix_domain() now fixes domain selector in opener 
     only after a username and domain have been set from the pickuser pop-up.
  
  
--raeburn1252264195
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090906190955.txt"

Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.887 loncom/interface/loncommon.pm:1.888
--- loncom/interface/loncommon.pm:1.887	Fri Aug 28 22:47:07 2009
+++ loncom/interface/loncommon.pm	Sun Sep  6 19:09:54 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.887 2009/08/28 22:47:07 raeburn Exp $
+# $Id: loncommon.pm,v 1.888 2009/09/06 19:09:54 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -602,7 +602,7 @@
     my $id_functions = &javascript_index_functions();
     return <<"ENDUSERBRW";
 
-function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom) {
+function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
     var url = '/adm/pickuser?';
     var userdom = getDomainFromSelectbox(formname,udom);
     if (userdom != null) {
@@ -617,6 +617,9 @@
                                 '&uemailelement='+uemail+
                                 '&hideudomelement='+hideudom+
                                 '&coursedom='+crsdom;
+    if ((caller != null) && (caller != undefined)) {
+        url += '&caller='+caller;
+    }
     var title = 'User_Browser';
     var options = 'scrollbars=1,resizable=1,menubar=0';
     options += ',width=700,height=600';
@@ -624,23 +627,27 @@
     stdeditbrowser.focus();
 }
 
-function fix_domain (formname,udom,origdom) {
+function fix_domain (formname,udom,origdom,uname) {
     var formid = getFormIdByName(formname);
     if (formid > -1) {
+        var unameid = getIndexByName(formid,uname);
         var domid = getIndexByName(formid,udom);
         var hidedomid = getIndexByName(formid,origdom);
         if (hidedomid > -1) {
             var fixeddom = document.forms[formid].elements[hidedomid].value;
-            if (domid > -1) {
-                var slct = document.forms[formid].elements[domid];
-                if (slct.type == 'select-one') {
-                    var i;
-                    for (i=0;i<slct.length;i++) {
-                        if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
+            var unameval = document.forms[formid].elements[unameid].value;
+            if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
+                if (domid > -1) {
+                    var slct = document.forms[formid].elements[domid];
+                    if (slct.type == 'select-one') {
+                        var i;
+                        for (i=0;i<slct.length;i++) {
+                            if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
+                        }
+                    }
+                    if (slct.type == 'hidden') {
+                        slct.value = fixeddom;
                     }
-                }
-                if (slct.type == 'hidden') {
-                    slct.value = fixeddom;
                 }
             }
         }
@@ -648,6 +655,10 @@
     return;
 }
 
+function userCheck (formname) {
+
+}
+
 $id_functions
 ENDUSERBRW
 }
@@ -715,9 +726,9 @@
 
 sub selectuser_link {
     my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
-        $coursedom,$linktext) = @_;
+        $coursedom,$linktext,$caller) = @_;
     return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
-           "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom'".
+           "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
            ');">'.$linktext.'</a>';
 }
 
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.28 loncom/interface/lonrequestcourse.pm:1.29
--- loncom/interface/lonrequestcourse.pm:1.28	Sat Sep  5 20:24:15 2009
+++ loncom/interface/lonrequestcourse.pm	Sun Sep  6 19:09:54 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.28 2009/09/05 20:24:15 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.29 2009/09/06 19:09:54 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1252,7 +1252,6 @@
     if ($env{'form.addperson'}) {
         $persontotal ++;
     }
-    my $userlinktxt = &mt('Set User');
     my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
 
     my $roleoptions;
@@ -1311,16 +1310,12 @@
     for (my $i=0; $i<$persontotal; $i++) { 
         my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
         my $linkargstr = join("','",@linkargs);
-        my $userlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,$userlinktxt);
-        my $uname_form = '<input type="text" name="person_'.$i.'_uname" value=""'.
-                         ' onFocus="this.blur();'.
-                         'openuserbrowser('."'$formname','$linkargstr','$dom'".');" />';
+        my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
         my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
-                       "'person_".$i."_hidedom'".');'.
-                       'openuserbrowser('."'$formname','$linkargstr','$dom'".');';
+                       "'person_".$i."_hidedom','person_".$i."_uname'".');';
         my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
                                                             1,$onchange).
-                        '<input type="hidden" name="person_'.$i.'_hidedom" value="'.$dom.'" />';
+                        '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
         my %form_elems;
         foreach my $item (@items) {
             next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
@@ -1336,12 +1331,19 @@
         }
         $sectionselector .= $newtitle.
             '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
+        my $usersrchlinktxt = &mt('Search for user');
+        my $usersrchlink =  &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
+                            $usersrchlinktxt);
+        my $userchklinktxt = &mt('Check username');
+        my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
+                            $userchklinktxt,'checkusername');
         $output .= 
-            &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel').'<br />'.
-                                              '<span class="LC_nobreak">'.$userlink.
-                                              '</span>').
-            '<table><tr><td align="center" valign="top">'.&mt('Username').'<br />'.$uname_form.'</td>'."\n".
-            '<td align="center" valign="top" colspan="2">'.&mt('Domain').'<br />'.$udom_form.'</td></tr><tr>'."\n".
+            &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
+            '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
+            '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
+            &mt('Username').':&nbsp;'.$uname_form.'&nbsp;'.$userchklink.'</span><br />'."\n".
+            '<span class="LC_nobreak">'.&mt('Domain').':&nbsp;'.$udom_form.'</span></td>'.
+            '</tr>'."\n".'<tr>'.
             '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
             '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
             '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
@@ -1887,8 +1889,7 @@
     my %lt = &clone_text();
     my $output .= 
         &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
-        '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();'.
-        'opencrsbrowser('."'$formname','clonecrs','clonedom','','','','$type'".');" />'.
+        '<input type="text" size="25" name="clonecrs" value=""  />'.
         '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
         &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
         $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
Index: loncom/interface/lonpickuser.pm
diff -u loncom/interface/lonpickuser.pm:1.3 loncom/interface/lonpickuser.pm:1.4
--- loncom/interface/lonpickuser.pm:1.3	Wed Aug 19 19:57:53 2009
+++ loncom/interface/lonpickuser.pm	Sun Sep  6 19:09:54 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Search for a user
 #
-# $Id: lonpickuser.pm,v 1.3 2009/08/19 19:57:53 raeburn Exp $
+# $Id: lonpickuser.pm,v 1.4 2009/09/06 19:09:54 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -71,7 +71,7 @@
     # Get parameters from query string
     &Apache::loncommon::get_unprocessed_cgi
         ($ENV{'QUERY_STRING'},['srchdom','form','udomelement','unameelement','ulastelement',
-                               'ufirstelement','uemailelement','hideudomelement','coursedom']);
+                               'ufirstelement','uemailelement','hideudomelement','coursedom','caller']);
     my $js;
 
     if (($env{'form.phase'} eq 'get_user_info') || 
@@ -89,6 +89,77 @@
 // ]]>
 </script>
 ENDSP
+    } elsif ($env{'form.caller'} eq 'checkusername') {
+        $js = <<"ENDCHK";
+<script type="text/javascript">
+// <![CDATA[
+function checkUser() {
+    var uname = opener.document.$env{'form.form'}.$env{'form.unameelement'}.value;
+    var udom;
+    var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
+    if (slct.options == undefined) {
+        udom = opener.document.$env{'form.form'}.$env{'form.udomelement'}.value;
+    } else {
+        udom = slct.options[slct.selectedIndex].value;
+    }
+    if (uname != '') {
+        document.userpicker.srchterm.value = uname;
+        document.userpicker.srchdomain.value = udom;
+    }
+    document.userpicker.submit();
+}
+// ]]>
+</script>
+ENDCHK
+    } elsif ($env{'form.phase'} eq '') {
+        $js = <<"ENDSET";
+<script type="text/javascript">
+// <![CDATA[
+function setUserSearch() {
+    var uname = opener.document.$env{'form.form'}.$env{'form.unameelement'}.value;
+    var udom;
+    var slct=opener.document.$env{'form.form'}.$env{'form.udomelement'};
+    if (slct.options == undefined) {
+        udom = opener.document.$env{'form.form'}.$env{'form.udomelement'}.value;
+    } else {
+        udom = slct.options[slct.selectedIndex].value;
+    }
+    if (uname != '') {
+        document.userpicker.srchterm.value = uname;
+        var seldom = document.userpicker.srchdomain;
+        if (seldom.options != undefined) {
+            var i;
+            for (i=0;i<seldom.length;i++) {
+                if (seldom.options[i].value==udom) { seldom.selectedIndex=i; }
+            }
+        }
+        var selby = document.userpicker.srchby;
+        if (selby.options != undefined) {
+            var i;
+            for (i=0;i<selby.length;i++) {
+                if (selby.options[i].value=="uname") { selby.selectedIndex=i; }
+            }
+        }
+        var seltype = document.userpicker.srchtype;
+        if (seltype.options != undefined) {
+            var i;
+            for (i=0;i<seltype.length;i++) {
+                if (seltype.options[i].value=="exact") { seltype.selectedIndex=i; }
+            }
+        }
+        var selin = document.userpicker.srchin;
+        if (selin.options != undefined) {
+            var i;
+            for (i=0;i<selin.length;i++) {
+                if (selin.options[i].value=="dom") { selin.selectedIndex=i; }
+            }
+        }
+    }
+    return;
+}
+// ]]>
+</script>
+ENDSET
     }
     my $startargs = {'no_nav_bar'  => 1, };
     if ($env{'form.phase'} eq 'store_newuser') {
@@ -98,9 +169,18 @@
         my $newlast = $env{'form.newlast'};
         my $newemail = $env{'form.newemail'};
         $startargs->{'add_entries'} = { onload => 'javascript:gochoose('."'$uname','$udom','$newfirst','$newlast','$newemail'".');' };
+    } elsif ($env{'form.caller'} eq 'checkusername') {
+        $startargs->{'add_entries'} = { onload => 'javascript:checkUser();' };
+    } elsif ($env{'form.phase'} eq '') {
+        $startargs->{'add_entries'} = { onload => 'javascript:setUserSearch();' };
     }
     $r->print(&Apache::loncommon::start_page('Selecting course personnel',
                                              $js,$startargs));
+    if ($env{'form.caller'} eq 'checkusername') {
+        $r->print(&check_user_form().
+                  &Apache::loncommon::end_page());
+        return OK;
+    }
     my %toset = (
                   uname   => 'unameelement',
                   udom    => 'udomelement',
@@ -142,12 +222,8 @@
     my $opener_elems = '<input type="hidden" name="form" value="'.
                        $env{'form.form'}.'" />'."\n".
                        '<input type="hidden" name="coursedom" value="'.
-                       $env{'form.coursedom'}.'" />'."\n";
-    foreach my $item (keys(%toset)) {
-        if (exists($env{'form.'.$toset{$item}})) {
-            $opener_elems .= '<input type="hidden" name="'.$toset{$item}.'" value="'.$env{'form.'.$toset{$item}}.'" />'."\n";
-        }
-    }
+                       $env{'form.coursedom'}.'" />'."\n".
+                       &set_opener_elems();
     unless ($env{'form.phase'} eq 'define_newuser') { 
         $r->print(<<"ENDBLOCK");
 <h3>$headertext</h3>
@@ -159,7 +235,7 @@
 </form>
 ENDBLOCK
     }
-    if ($env{'form.phase'} eq 'get_user_info') {
+    if (($env{'form.phase'} eq 'get_user_info') && ($env{'form.srchterm'} ne '')) {
         $r->print('<hr /><div>'.&mt('Searching ...').'</div>');
         $r->rflush();
         my ($currstate,$response,$forcenewuser,$results) = 
@@ -266,4 +342,37 @@
 ENDGC
 }
 
+sub check_user_form {
+    return '
+<form action="/adm/pickuser" method="post" name="userpicker">
+<input type="hidden" name="form" value="'.$env{'form.form'}.'" />
+<input type="hidden" name="coursedom" value="'.$env{'form.coursedom'}.'" />'."\n".
+                 &set_opener_elems().'
+<input type="hidden" name="srchby" value="uname" />
+<input type="hidden" name="srchin" value="dom" />
+<input type="hidden" name="srchterm" value="" />
+<input type="hidden" name="srchdomain" value="" />
+<input type="hidden" name="srchtype" value="exact" />
+<input type="hidden" name="phase" value="get_user_info" />
+</form>'."\n";
+}
+
+sub set_opener_elems {
+    my %toset = (
+                  uname   => 'unameelement',
+                  udom    => 'udomelement',
+                  first   => 'ufirstelement',
+                  lastn   => 'ulastelement',
+                  email   => 'uemailelement',
+                  hidedom => 'hideudomelement',
+                );
+    my $output;
+    foreach my $item (keys(%toset)) {
+        if (exists($env{'form.'.$toset{$item}})) {
+            $output .= '<input type="hidden" name="'.$toset{$item}.'" value="'.$env{'form.'.$toset{$item}}.'" />'."\n";
+        }
+    }
+    return $output;
+}
+
 1;

--raeburn1252264195--