[LON-CAPA-cvs] cvs: loncom /auth lonroles.pm /interface loncommon.pm lonpickcourse.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Fri, 12 Nov 2004 23:29:56 -0000


This is a MIME encoded message

--raeburn1100302196
Content-Type: text/plain

raeburn		Fri Nov 12 18:29:56 2004 EDT

  Modified files:              
    /loncom/auth	lonroles.pm 
    /loncom/interface	loncommon.pm lonpickcourse.pm 
  Log:
  Users with multiple DC roles can now select a CC role from any of the domains in which they are DC. Extra click eliminated -- selection in Pickcourse window loads CC role in opener window. 
  
  
--raeburn1100302196
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20041112182956.txt"

Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.108 loncom/auth/lonroles.pm:1.109
--- loncom/auth/lonroles.pm:1.108	Fri Nov 12 10:33:32 2004
+++ loncom/auth/lonroles.pm	Fri Nov 12 18:29:55 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.108 2004/11/12 15:33:32 raeburn Exp $
+# $Id: lonroles.pm,v 1.109 2004/11/12 23:29:55 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -105,7 +105,14 @@
             foreach my $envkey (keys %ENV) {
                 if ($envkey =~ m-^form\.cc\./(\w+)/(\w+)$-) {
                     if ($dcroles{$1}) {
-                        unless ($ENV{'user.role.cc./'.$1.'/'.$2}) {
+                        my $cckey = 'user.role.cc./'.$1.'/'.$2;
+                        if ($ENV{$cckey}) {
+                            my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
+                            &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
+                            unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
+                                &set_privileges($1,$2);
+                            }
+                        } else {
                             &set_privileges($1,$2);
                         }
                     }
@@ -761,18 +768,6 @@
     }
 }
 
-sub dc_script {
-    my $response = (<<"END");
-function setDCchoice(caller) {
-    var dcname = "dc./"+caller+"/"
-    document.rolechoice.dcselected.value = caller
-    document.rolechoice.elements[3].name = dcname
-    document.rolechoice.submit()
-}
-END
-    return $response;
-}
-                                                                                 
 sub check_fordc {
     my ($dcroles,$then) = @_;
     my $numdc = 0;
@@ -796,14 +791,26 @@
 
 sub courselink {
     my ($dcdom) = @_;
-    my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'dom');
+    my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,$dcdom);
+    my $verify_script = &coursepick_jscript($dcdom);
+    my $courseform=&Apache::loncommon::selectcourse_link
+                     ('rolechoice','dccourse_'.$dcdom,'dcdomain_'.$dcdom,'coursedesc_'.$dcdom);
+    my $hiddenitems = '<input type="hidden" name="dcdomain_'.$dcdom.'" value="'.$dcdom.'" />'.
+                      '<input type="hidden" name="origdom_'.$dcdom.'" value="'.$dcdom.'" />'.
+                      '<input type="hidden" name="dccourse_'.$dcdom.'" value="" />'.
+                      '<input type="hidden" name="coursedesc_'.$dcdom.'" value="" />';
+    return $cb_jscript.$verify_script.$courseform.$hiddenitems;
+}
+
+sub coursepick_jscript {
+    my ($dcdom) = @_;
     my $verify_script = <<"END";
 <script>
 function verifyCoursePick(caller) {
     var numbutton = getIndex(caller)
-    var pickedCourse = document.rolechoice.dccourse.value
-    var pickedDomain = document.rolechoice.dcdomain.value
-    if (document.rolechoice.dcdomain.value == document.rolechoice.origdom.value) {
+    var pickedCourse = document.rolechoice.dccourse_$dcdom.value
+    var pickedDomain = document.rolechoice.dcdomain_$dcdom.value
+    if (document.rolechoice.dcdomain_$dcdom.value == document.rolechoice.origdom_$dcdom.value) {
         if (pickedCourse != '') {
             if (numbutton != -1) {
                 var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
@@ -819,10 +826,9 @@
         alert("You can only use this screen to select courses in the current domain")
     }
 }
-
-function getIndex(what) {
+function getIndex(caller) {
     for (var i=0;i<document.rolechoice.elements.length;i++) {
-        if (what == document.rolechoice.elements[i]) {
+        if (document.rolechoice.elements[i] == caller) {
             return i;
         }
     }
@@ -830,15 +836,42 @@
 }
 </script>
 END
-    my $courseform=&Apache::loncommon::selectcourse_link
-                     ('rolechoice','dccourse','dcdomain','coursedesc');
-    my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
-                      '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
-                      '<input type="hidden" name="dccourse" value="" />'.
-                      '<input type="hidden" name="coursedesc" value="" />';
-    return $cb_jscript.$verify_script.$courseform.$hiddenitems;
+    return $verify_script;
 }
 
+sub processpick {
+    my $dcdom = shift;
+    my $process_pick = <<"END";
+<script>
+function process_pick(dom) {
+    var numbutton = getIndex(dom)
+    var pickedCourse = opener.document.rolechoice.dccourse_$dcdom.value
+    var pickedDomain = opener.document.rolechoice.dcdomain_$dcdom.value
+    if (opener.document.rolechoice.dcdomain_$dcdom.value == opener.document.rolechoice.origdom_$dcdom.value) {
+        if (pickedCourse != '') {
+            if (numbutton != -1) {
+                var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
+                opener.document.rolechoice.elements[numbutton+1].name = courseTarget
+                opener.document.rolechoice.submit()
+            }
+        }
+    }
+}
+ 
+function getIndex(dom) {
+    var callername = 'ccpick_'+dom
+    for (var i=0;i<opener.document.rolechoice.elements.length;i++) {
+        var elemname = opener.document.rolechoice.elements[i].name
+        if (elemname == callername) {
+            return i;
+        }
+    }
+    return -1;
+}
+</script>
+END
+    return $process_pick;
+}
 
 sub select_recent_courses {
     my ($r,$roletext)=@_;
@@ -852,6 +885,7 @@
                     '</td></tr>'."\n";
     foreach my $courseid (sort keys %recent) {
         unless ($courseid =~/^error\:/) {
+            print STDERR "$courseid\n";
             my ($dom,$crs) = split/_/,$courseid;
             $numrecent ++;
             my $crskey = 'user.role.cc./'.$dom.'/'.$crs;
@@ -864,12 +898,12 @@
 }
 
 sub allcourses_row {
-    my ($dcdom) = @_;
+    my $dcdom = shift;
     my $ccrole = Apache::lonnet::plaintext('cc');
     my $selectlink = &courselink($dcdom);
     my $output = '<tr bgcolor="#77FF77">'.
               '<td><input type="button" value="'.
-              &mt('Select').'" name="ccpick_'.$dcdom.'/" '.
+              &mt('Select').'" name="ccpick_'.$dcdom.'"'.
               'onClick="verifyCoursePick(this)">'.
               '<input type="hidden" name="pick_'.$dcdom.'" value="1"></td>'.
               '<td><font color="#002200">'.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.229 loncom/interface/loncommon.pm:1.230
--- loncom/interface/loncommon.pm:1.229	Thu Nov 11 18:45:36 2004
+++ loncom/interface/loncommon.pm	Fri Nov 12 18:29:56 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.229 2004/11/11 23:45:36 albertel Exp $
+# $Id: loncommon.pm,v 1.230 2004/11/12 23:29:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -375,9 +375,10 @@
 }
 
 sub coursebrowser_javascript {
-    my ($domainfilter)=@_;
+    my ($domainfilter,$roleelement)=@_;
    return (<<ENDSTDBRW);
 <script type="text/javascript" language="Javascript" >
+    var extra_element = "$roleelement" 
     var stdeditbrowser;
     function opencrsbrowser(formname,uname,udom,desc) {
         var url = '/adm/pickcourse?';
@@ -396,6 +397,9 @@
         url += 'form=' + formname + '&cnumelement='+uname+
 	                            '&cdomelement='+udom+
                                     '&cnameelement='+desc;
+        if (extra_element != '') {
+            url += '&roleelement=$roleelement';
+        }
         var title = 'Course_Browser';
         var options = 'scrollbars=1,resizable=1,menubar=0';
         options += ',width=700,height=600';
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.17 loncom/interface/lonpickcourse.pm:1.18
--- loncom/interface/lonpickcourse.pm:1.17	Tue Jun 29 10:56:32 2004
+++ loncom/interface/lonpickcourse.pm	Fri Nov 12 18:29:56 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.17 2004/06/29 14:56:32 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.18 2004/11/12 23:29:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -52,7 +52,7 @@
     &Apache::loncommon::get_unprocessed_cgi
         ($ENV{'QUERY_STRING'},['domainfilter','descriptfilter',
 			       'sincefilter','form','cnumelement',
-			       'cdomelement','cnameelement']);
+			       'cdomelement','cnameelement','roleelement']);
 # domain filter and selection
     my $domainfilter=$ENV{'form.domainfilter'};
     $domainfilter=~s/\W//g;
@@ -90,6 +90,15 @@
 	$name_input ='<input type="hidden" name="cnameelement" value="'.
 	    $ENV{'form.cnameelement'}.'" />';
     }
+    my $submitopener = '';
+    my $autosubmit = '';
+    my $roleelement = '';
+    my $roledom = $ENV{'form.roleelement'};
+    if ($roledom) {
+        $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
+        $submitopener = &Apache::lonroles::processpick($roledom);
+        $autosubmit = 'process_pick("'.$roledom.'")';
+    }
     $r->print(<<ENDSCRIPT);
 <script>
 function gochoose(cname,cdom,cdesc) {
@@ -100,15 +109,17 @@
     for (i=0;i<slct.length;i++) {
         if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
     }
+    $autosubmit
     self.close();
 }
 </script>
+$submitopener
 <form method="post">
 <input type="hidden" name="cnumelement" value="$ENV{'form.cnumelement'}" />
 <input type="hidden" name="cdomelement" value="$ENV{'form.cdomelement'}" />
 $name_input
 <input type="hidden" name="form" value="$ENV{'form.form'}" />
-
+$roleelement
 $lt{'cac'}: $sincefilterform
 <br />
 $lt{'cdo'}: $domainselectform
@@ -155,7 +166,7 @@
     }
     $r->print('</body></html>');
     return OK;
-} 
+}
 
 1;
 __END__

--raeburn1100302196--