[LON-CAPA-cvs] cvs: loncom /interface lonuserutils.pm
raeburn
raeburn@source.lon-capa.org
Tue, 02 Feb 2010 05:56:09 -0000
This is a MIME encoded message
--raeburn1265090169
Content-Type: text/plain
raeburn Tue Feb 2 05:56:09 2010 EDT
Modified files:
/loncom/interface lonuserutils.pm
Log:
- Improvements to client-side javascript used in pop-up section picker,
displayed when modifying role section for existing users.
- trim leading and trailing spaces
- ignore "new" section names which duplicate selected items in
"existing sections" drop down.
- only call str.split(/,/) on strings containing ,
--raeburn1265090169
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100202055609.txt"
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.114 loncom/interface/lonuserutils.pm:1.115
--- loncom/interface/lonuserutils.pm:1.114 Wed Jan 20 16:46:23 2010
+++ loncom/interface/lonuserutils.pm Tue Feb 2 05:56:09 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.114 2010/01/20 16:46:23 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.115 2010/02/02 05:56:09 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -4839,11 +4839,14 @@
function setSections(formname,crstype) {
var re1 = /^currsec_/;
var re2 =/\\W/;
+ var trimleading = /^\\s+/;
+ var trimtrailing = /\\s+\$/;
var groups = new Array($groupslist);
for (var i=0;i<formname.elements.length;i++) {
var str = formname.elements[i].name;
var checkcurr = str.match(re1);
if (checkcurr != null) {
+ var num = i;
if ($checkincluded) {
$rolecode
if (role == 'cc' || role == 'co') {
@@ -4855,42 +4858,52 @@
} else {
var sections = '';
var numsec = 0;
- var sections;
- for (var j=0; j<formname.elements[i].length; j++) {
- if (formname.elements[i].options[j].selected == true ) {
- if (formname.elements[i].options[j].value != "") {
+ var fromexisting = new Array();
+ for (var j=0; j<formname.elements[num].length; j++) {
+ if (formname.elements[num].options[j].selected == true ) {
+ var addsec = formname.elements[num].options[j].value;
+ if (addsec != "") {
+ fromexisting.push(addsec);
if (numsec == 0) {
- if (formname.elements[i].options[j].value != "") {
- sections = formname.elements[i].options[j].value;
- numsec ++;
- }
- }
- else {
- sections = sections + "," + formname.elements[i].options[j].value
- numsec ++;
+ sections = addsec;
+ } else {
+ sections = sections + "," + addsec;
}
+ numsec ++;
}
}
}
- if (numsec > 0) {
- if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
- sections = sections + "," + formname.elements[i+1].value;
- }
- }
- else {
- sections = formname.elements[i+1].value;
- }
- var newsecs = formname.elements[i+1].value;
- var numsplit;
+ var newsecs = formname.elements[num+1].value;
var validsecs = new Array();
+ var validsecstr = '';
var badsecs = new Array();
if (newsecs != null && newsecs != "") {
- numsplit = newsecs.split(/,/g);
+ var numsplit;
+ if (newsecs.indexOf(',') == -1) {
+ numsplit = new Array(newsecs);
+ } else {
+ numsplit = newsecs.split(/,/g);
+ }
for (var i=0; i<numsplit.length; i++) {
- if (re2.test(numsplit[i]) == true) {
- badsecs.push(numsplit[i]);
+ var newsec = numsplit[i];
+ newsec = newsec.replace(trimleading,'');
+ newsec = newsec.replace(trimtrailing,'');
+ if (re2.test(newsec) == true) {
+ badsecs.push(newsec);
} else {
- validsecs.push(numsplit[i]);
+ if (newsec != '') {
+ var isnew = 1;
+ if (fromexisting != null) {
+ for (var m=0; m<fromexisting.length; m++) {
+ if (newsec == fromexisting[m]) {
+ isnew = 0;
+ }
+ }
+ }
+ if (isnew == 1) {
+ validsecs.push(newsec);
+ }
+ }
}
}
if (badsecs.length > 0) {
@@ -4899,7 +4912,6 @@
}
numsec = numsec + validsecs.length;
}
-
if ((role == 'st') && (numsec > 1)) {
if (crstype == 'Community') {
alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
@@ -4907,25 +4919,36 @@
alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
}
return;
- }
- else {
- if (numsplit != null) {
- for (var j=0; j<numsplit.length; j++) {
- if ((numsplit[j] == 'all') ||
- (numsplit[j] == 'none')) {
- alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
+ } else {
+ if (validsecs != null) {
+ for (var j=0; j<validsecs.length; j++) {
+ if (validsecstr == '' || validsecstr == null) {
+ validsecstr = validsecs[j];
+ } else {
+ validsecstr += ','+validsecs[j];
+ }
+ if ((validsecs[j] == 'all') ||
+ (validsecs[j] == 'none')) {
+ alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
return;
}
for (var k=0; k<groups.length; k++) {
- if (numsplit[j] == groups[k]) {
- alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
+ if (validsecs[j] == groups[k]) {
+ alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
return;
}
}
}
}
- formname.elements[i+2].value = sections;
}
+ if ((validsecstr != '') && (validsecstr != null)) {
+ if (numsec > 0) {
+ sections = sections + "," + validsecstr;
+ } else {
+ sections = validsecstr;
+ }
+ }
+ formname.elements[num+2].value = sections;
}
}
}
--raeburn1265090169--