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

raeburn raeburn@source.lon-capa.org
Fri, 30 Oct 2009 04:44:57 -0000


raeburn		Fri Oct 30 04:44:57 2009 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonpickcourse.pm loncreateuser.pm 
  Log:
  - Update names in Roles drop down (Course Level) when DC selects 
     a Community in which to assign new role to a user.   
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.904 loncom/interface/loncommon.pm:1.905
--- loncom/interface/loncommon.pm:1.904	Wed Oct 28 08:47:56 2009
+++ loncom/interface/loncommon.pm	Fri Oct 30 04:44:56 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.904 2009/10/28 08:47:56 droeschl Exp $
+# $Id: loncommon.pm,v 1.905 2009/10/30 04:44:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -482,7 +482,7 @@
 }
 
 sub coursebrowser_javascript {
-    my ($domainfilter,$sec_element,$formname)=@_;
+    my ($domainfilter,$sec_element,$formname,$role_element)=@_;
     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role.');
     my $id_functions = &javascript_index_functions();
     my $output = '
@@ -548,8 +548,8 @@
     }
 $id_functions
 ENDSTDBRW
-    if ($sec_element ne '') {
-        $output .= &setsec_javascript($sec_element,$formname);
+    if (($sec_element ne '') || ($role_element ne '')) {
+        $output .= &setsec_javascript($sec_element,$formname,$role_element);
     }
     $output .= '
 // ]]>
@@ -661,7 +661,28 @@
 }
 
 sub setsec_javascript {
-    my ($sec_element,$formname) = @_;
+    my ($sec_element,$formname,$role_element) = @_;
+    my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
+        $communityrolestr);
+    if ($role_element ne '') {
+        my @allroles = ('st','ta','ep','in','ad');
+        foreach my $crstype ('Course','Community') {
+            if ($crstype eq 'Community') {
+                foreach my $role (@allroles) {
+                    push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
+                }
+                push(@communityrolenames,&Apache::lonnet::plaintext('co'));
+            } else {
+                foreach my $role (@allroles) {
+                    push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
+                }
+                push(@courserolenames,&Apache::lonnet::plaintext('cc'));
+            }
+        }
+        $rolestr = '"'.join('","',@allroles).'"';
+        $courserolestr = '"'.join('","',@courserolenames).'"';
+        $communityrolestr = '"'.join('","',@communityrolenames).'"';
+    }
     my $setsections = qq|
 function setSect(sectionlist) {
     var sectionsArray = new Array();
@@ -695,11 +716,49 @@
         }
     }
 }
+
+function setRole(crstype) {
 |;
+    if ($role_element eq '') {
+        $setsections .= '    return;
+}
+';
+    } else {
+        $setsections .= qq|
+    var elementLength = document.$formname.$role_element.length;
+    var allroles = Array($rolestr);
+    var courserolenames = Array($courserolestr);
+    var communityrolenames = Array($communityrolestr);
+    if (elementLength != undefined) {
+        if (document.$formname.$role_element.options[5].value == 'cc') {
+            if (crstype == 'Course') {
+                return;
+            } else {
+                allroles[5] = 'co';
+                for (var i=0; i<6; i++) {
+                    document.$formname.$role_element.options[i].value = allroles[i];
+                    document.$formname.$role_element.options[i].text = communityrolenames[i];
+                }
+            }
+        } else {
+            if (crstype == 'Community') {
+                return;
+            } else {
+                allroles[5] = 'cc';
+                for (var i=0; i<6; i++) {
+                    document.$formname.$role_element.options[i].value = allroles[i];
+                    document.$formname.$role_element.options[i].text = courserolenames[i];
+                }
+            }
+        }
+    }
+    return;
+}
+|;
+    }
     return $setsections;
 }
 
-
 sub selectcourse_link {
    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
    my $linktext = &mt('Select Course');
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.86 loncom/interface/lonpickcourse.pm:1.87
--- loncom/interface/lonpickcourse.pm:1.86	Wed Aug 19 19:51:22 2009
+++ loncom/interface/lonpickcourse.pm	Fri Oct 30 04:44:56 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.86 2009/08/19 19:51:22 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.87 2009/10/30 04:44:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -102,7 +102,10 @@
 
     if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) && 
         ($env{'form.pickedcourse'})) {
-            $loaditem{'onload'} .= 'setSections()';
+        if ($env{'form.form'} eq 'cu') {
+            $loaditem{'onload'} .= 'setRoles();';
+        }
+        $loaditem{'onload'} .= 'setSections();';
     }
     my $js = &js_changer();
     $r->print(&Apache::loncommon::start_page($title,$js,
@@ -252,7 +255,12 @@
     my $output;
     #javascript for reporting sections and groups then closing
     if ($env{'form.pickedcourse'}) {
-        my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
+        my %coursedescription = 
+            &Apache::lonnet::coursedescription($env{'form.pickedcourse'},
+                                               {'one_time' => '1'});
+        my $cdom = $coursedescription{'domain'};
+        my $cnum = $coursedescription{'num'};
+        my $crstype = $coursedescription{'type'};
         my $sec_element = 'currsec';
         my $grplist_element = 'groups';
         my ($sections,$groups) =
@@ -266,7 +274,10 @@
 function setSections() {
     opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
     window.opener.setSect('$seclist');
-    self.close()
+    self.close();
+}
+function setRoles() {
+    window.opener.setRole('$crstype');
 }
 </script>
 |;
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.318 loncom/interface/loncreateuser.pm:1.319
--- loncom/interface/loncreateuser.pm:1.318	Fri Oct 30 03:51:15 2009
+++ loncom/interface/loncreateuser.pm	Fri Oct 30 04:44:56 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.318 2009/10/30 03:51:15 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.319 2009/10/30 04:44:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5943,7 +5943,7 @@
                       '<input type="hidden" name="dccourse" value="" />';
     my $courseform='<b>'.&Apache::loncommon::selectcourse_link
             ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
-    my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
+    my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role');
     my %lt=&Apache::lonlocal::texthash(
                     'rol'  => "Role",
                     'grs'  => "Section",