[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Thu, 09 Nov 2006 21:57:41 -0000
raeburn Thu Nov 9 16:57:41 2006 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
Dynamic population of select boxes containing sections in a course following course selection via lonpickcourse in a window fired off by loncommon::selectcourse_link() now occurs via a javascript function -setSect() - in the opener window to satisfy IE 6. Also selected domain is now propagated from opener window to domain selector in child window (as generated by lonpickcourse).
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.467 loncom/interface/loncommon.pm:1.468
--- loncom/interface/loncommon.pm:1.467 Wed Nov 1 17:22:31 2006
+++ loncom/interface/loncommon.pm Thu Nov 9 16:57:40 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.467 2006/11/01 22:22:31 www Exp $
+# $Id: loncommon.pm,v 1.468 2006/11/09 21:57:40 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -386,20 +386,27 @@
}
sub coursebrowser_javascript {
- my ($domainfilter)=@_;
+ my ($domainfilter,$sec_element,$formname)=@_;
my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
- return (<<ENDSTDBRW);
+ my $output = '
<script type="text/javascript" language="Javascript" >
- var stdeditbrowser;
+ var stdeditbrowser;'."\n";
+ $output .= <<"ENDSTDBRW";
function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
var url = '/adm/pickcourse?';
- var filter;
- if (filter != null) {
- if (filter != '') {
- url += 'filter='+filter+'&';
- }
+ var domainfilter = '';
+ var formid = getFormIdByName(formname);
+ if (formid > -1) {
+ var domid = getIndexByName(formid,udom);
+ if (domid > -1) {
+ if (document.forms[formid].elements[domid].type == 'select-one') {
+ domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
+ }
+ if (document.forms[formid].elements[domid].type == 'hidden') {
+ domainfilter=document.forms[formid].elements[domid].value;
+ }
+ }
}
- var domainfilter='$domainfilter';
if (domainfilter != null) {
if (domainfilter != '') {
url += 'domainfilter='+domainfilter+'&';
@@ -408,11 +415,18 @@
url += 'form=' + formname + '&cnumelement='+uname+
'&cdomelement='+udom+
'&cnameelement='+desc;
- if (extra_element !=null && extra_element != '' && formname == 'rolechoice') {
- url += '&roleelement='+extra_element;
- if (domainfilter == null || domainfilter == '') {
- url += '&domainfilter='+extra_element;
+ if (extra_element !=null && extra_element != '') {
+ if (formname == 'rolechoice') {
+ url += '&roleelement='+extra_element;
+ if (domainfilter == null || domainfilter == '') {
+ url += '&domainfilter='+extra_element;
+ }
}
+ else {
+ if (formname == 'portform') {
+ url += '&setroles='+extra_element;
+ }
+ }
}
if (multflag !=null && multflag != '') {
url += '&multiple='+multflag;
@@ -435,9 +449,69 @@
stdeditbrowser = open(url,title,options,'1');
stdeditbrowser.focus();
}
-</script>
+
+ function getFormIdByName(formname) {
+ for (var i=0;i<document.forms.length;i++) {
+ if (document.forms[i].name == formname) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ function getIndexByName(formid,item) {
+ for (var i=0;i<document.forms[formid].elements.length;i++) {
+ if (document.forms[formid].elements[i].name == item) {
+ return i;
+ }
+ }
+ return -1;
+ }
ENDSTDBRW
+ if ($sec_element ne '') {
+ $output .= &setsec_javascript($sec_element,$formname);
+ }
+ $output .= '
+</script>';
+ return $output;
+}
+
+sub setsec_javascript {
+ my ($sec_element,$formname) = @_;
+ my $setsections = qq|
+function setSect(sectionlist) {
+ var sectionsArray = sectionlist.split(",");
+ var numSections = sectionsArray.length;
+ document.$formname.$sec_element.length = 0;
+ if (numSections == 0) {
+ document.$formname.$sec_element.multiple=false;
+ document.$formname.$sec_element.size=1;
+ document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
+ } else {
+ if (numSections == 1) {
+ document.$formname.$sec_element.multiple=false;
+ document.$formname.$sec_element.size=1;
+ document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
+ document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
+ document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
+ } else {
+ for (var i=0; i<numSections; i++) {
+ document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
+ }
+ document.$formname.$sec_element.multiple=true
+ if (numSections < 3) {
+ document.$formname.$sec_element.size=numSections;
+ } else {
+ document.$formname.$sec_element.size=3;
+ }
+ document.$formname.$sec_element.options[0].selected = false
+ }
+ }
}
+|;
+ return $setsections;
+}
+
sub selectcourse_link {
my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;