[LON-CAPA-cvs] cvs: loncom(version_2_9_X) /interface loncommon.pm
raeburn
raeburn@source.lon-capa.org
Fri, 14 Aug 2009 08:07:11 -0000
raeburn Fri Aug 14 08:07:11 2009 EDT
Modified files: (Branch: version_2_9_X)
/loncom/interface loncommon.pm
Log:
- Backport 1.876.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.692.4.8 loncom/interface/loncommon.pm:1.692.4.9
--- loncom/interface/loncommon.pm:1.692.4.8 Fri Aug 14 07:52:03 2009
+++ loncom/interface/loncommon.pm Fri Aug 14 08:07:11 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.692.4.8 2009/08/14 07:52:03 raeburn Exp $
+# $Id: loncommon.pm,v 1.692.4.9 2009/08/14 08:07:11 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -483,26 +483,16 @@
sub coursebrowser_javascript {
my ($domainfilter,$sec_element,$formname)=@_;
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 $output = '
+ my $id_functions = &javascript_index_functions();
+ my $output = '
<script type="text/javascript" language="JavaScript">
// <![CDATA[
var stdeditbrowser;'."\n";
- $output .= <<"ENDSTDBRW";
+
+ $output .= <<"ENDSTDBRW";
function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
var url = '/adm/pickcourse?';
- 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 = getDomainFromSelectbox(formname,udom);
if (domainfilter != null) {
if (domainfilter != '') {
url += 'domainfilter='+domainfilter+'&';
@@ -550,24 +540,7 @@
stdeditbrowser = open(url,title,options,'1');
stdeditbrowser.focus();
}
-
- 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;
- }
+$id_functions
ENDSTDBRW
if ($sec_element ne '') {
$output .= &setsec_javascript($sec_element,$formname);
@@ -578,6 +551,103 @@
return $output;
}
+sub javascript_index_functions {
+ return <<"ENDJS";
+
+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;
+}
+
+function getDomainFromSelectbox(formname,udom) {
+ var userdom;
+ var formid = getFormIdByName(formname);
+ if (formid > -1) {
+ var domid = getIndexByName(formid,udom);
+ if (domid > -1) {
+ if (document.forms[formid].elements[domid].type == 'select-one') {
+ userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
+ }
+ if (document.forms[formid].elements[domid].type == 'hidden') {
+ userdom=document.forms[formid].elements[domid].value;
+ }
+ }
+ }
+ return userdom;
+}
+
+ENDJS
+
+}
+
+sub userbrowser_javascript {
+ my $id_functions = &javascript_index_functions();
+ return <<"ENDUSERBRW";
+
+function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom) {
+ var url = '/adm/pickuser?';
+ var userdom = getDomainFromSelectbox(formname,udom);
+ if (userdom != null) {
+ if (userdom != '') {
+ url += 'srchdom='+userdom+'&';
+ }
+ }
+ url += 'form=' + formname + '&unameelement='+uname+
+ '&udomelement='+udom+
+ '&ulastelement='+ulast+
+ '&ufirstelement='+ufirst+
+ '&uemailelement='+uemail+
+ '&hideudomelement='+hideudom+
+ '&coursedom='+crsdom;
+ var title = 'User_Browser';
+ var options = 'scrollbars=1,resizable=1,menubar=0';
+ options += ',width=700,height=600';
+ var stdeditbrowser = open(url,title,options,'1');
+ stdeditbrowser.focus();
+}
+
+function fix_domain (formname,udom,origdom) {
+ var formid = getFormIdByName(formname);
+ if (formid > -1) {
+ 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; }
+ }
+ }
+ if (slct.type == 'hidden') {
+ slct.value = fixeddom;
+ }
+ }
+ }
+ }
+ return;
+}
+
+$id_functions
+ENDUSERBRW
+}
+
+
sub setsec_javascript {
my ($sec_element,$formname) = @_;
my $setsections = qq|
@@ -639,6 +709,14 @@
&mt('Select Author').'</a>';
}
+sub selectuser_link {
+ my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
+ $coursedom,$linktext) = @_;
+ return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
+ "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom'".
+ ');">'.$linktext.'</a>';
+}
+
sub check_uncheck_jscript {
my $jscript = <<"ENDSCRT";
function checkAll(field) {
@@ -7039,24 +7117,20 @@
$new_user_create
-<table>
- <tr>
- <td>$lt{'doma'}:</td>
- <td>$domform</td>
- </td>
- </tr>
- <tr>
- <td>$lt{'usr'}:</td>
- <td>$srchbysel
- $srchtypesel
- <input type="text" size="15" name="srchterm" value="$srchterm" />
- $srchinsel
- </td>
- </tr>
-</table>
-<br />
END_BLOCK
+ $output .= &Apache::lonhtmlcommon::start_pick_box().
+ &Apache::lonhtmlcommon::row_title($lt{'doma'}).
+ $domform.
+ &Apache::lonhtmlcommon::row_closure().
+ &Apache::lonhtmlcommon::row_title($lt{'usr'}).
+ $srchbysel.
+ $srchtypesel.
+ '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
+ $srchinsel.
+ &Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::end_pick_box().
+ '<br />';
return $output;
}