[LON-CAPA-cvs] cvs: loncom /interface portfolio.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Thu, 09 Nov 2006 22:33:33 -0000
This is a MIME encoded message
--raeburn1163111613
Content-Type: text/plain
raeburn Thu Nov 9 17:33:33 2006 EDT
Modified files:
/loncom/interface portfolio.pm
Log:
Selection of roles, access types, sections and groups for each entry in a course-based condition for access to a portfolio file now occurs in a separate window. Display of select boxes occurs immediately for new entries for existing course-based conditions, but after course selection via lonpickcourse for new course-based conditions. Results of choices are stored in hidden form elements in opener window.
--raeburn1163111613
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20061109173333.txt"
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.171 loncom/interface/portfolio.pm:1.172
--- loncom/interface/portfolio.pm:1.171 Mon Nov 6 15:02:58 2006
+++ loncom/interface/portfolio.pm Thu Nov 9 17:33:32 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network
# portfolio browser
#
-# $Id: portfolio.pm,v 1.171 2006/11/06 20:02:58 rezaferry Exp $
+# $Id: portfolio.pm,v 1.172 2006/11/09 22:33:32 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -874,7 +874,7 @@
if ($scope eq 'guest') {
$r->print(&mt('Passphrase').': '.$content->{'password'});
} elsif ($scope eq 'course') {
- $r->print('<table><tr>');
+ $r->print('<table width="100%"><tr>');
$r->print('<th>'.&mt('Roles').'</th><th>'.
&mt('Access').'</th><th>'.
&mt('Sections').'</th>');
@@ -1336,7 +1336,7 @@
$r->print(&Apache::loncommon::start_data_table_header_row());
$r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</th><th>'.
&mt('Dates available').'</th>');
- if ($type eq 'course') {
+ if ($type eq 'course' && $status eq 'old') {
$r->print('<th>'.&mt('Allowed [_1] member affiliations',$type).
'</th>');
$colspan ++;
@@ -1373,34 +1373,37 @@
sub course_js {
return qq|
<script type="text/javascript">
-function setRoleOptions(caller,num,cdom,cnum,type) {
- addIndexnum = getCallerIndex(caller);
- updateIndexnum = getIndex('update',num);
- if (caller.checked) {
- document.portform.elements[updateIndexnum].checked = true;
- var url = '/adm/portfolio?action=rolepicker&setroles='+addIndexnum+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
+function setRoleOptions(num,roleid,cdom,cnum,type) {
+ updateIndexNum = getIndexByValue('update',num);
+ var addItem = 'add_role_'+num;
+ var addIndexNum = getIndexByName(addItem);
+ if (document.portform.elements[addItem].checked) {
+ document.portform.elements[updateIndexNum].checked = true;
+ var url = '/adm/portfolio?action=rolepicker&setroles='+num+'_'+roleid+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
var title = 'Roles_Chooser';
var options = 'scrollbars=1,resizable=1,menubar=0';
options += ',width=700,height=600';
rolebrowser = open(url,title,options,'1');
rolebrowser.focus();
} else {
- for (var j=0;j<5;j++) {
- document.portform.elements[addIndexnum+j].value = '';
+ addArray = new Array ('role','access','section','group');
+ for (var j=0;j<addArray.length;j++) {
+ var itemIndex = getIndexByName(addArray[j]+'_'+num+'_'+roleid);
+ document.portform.elements[itemIndex].value = '';
}
}
}
-function getCallerIndex(caller) {
+function getIndexByName(item) {
for (var i=0;i<document.portform.elements.length;i++) {
- if (document.portform.elements[i] == caller) {
+ if (document.portform.elements[i].name == item) {
return i;
}
}
return -1;
}
-function getIndex(name,value) {
+function getIndexByValue(name,value) {
for (var i=0;i<document.portform.elements.length;i++) {
if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
return i;
@@ -1433,33 +1436,53 @@
my %course_description = &Apache::lonnet::coursedescription($cid);
$r->print('<td><input type="hidden" name="crsdom_'.$num.'" value="'.$content->{'domain'}.'" /><input type="hidden" name="crsnum_'.$num.'" value="'.$content->{'number'}.'" />'.$course_description{'description'}.'</td>');
} elsif ($status eq 'new') {
- $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,undef,undef,$uctype).' <input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
+ $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,$num.'_1',undef,$uctype).' <input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
}
- $r->print('<td>'.&dateboxes($num,$start,$end).'</td>');
- $r->print('<td><table><tr>');
- $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Roles').'</th><th>'.
- &mt('Access').'</th><th>'.&mt('Sections').'</th><th>'.
- &mt('Groups').'</th></tr>');
+ $r->print('<td>'.&dateboxes($num,$start,$end));
+ my $newrole_id = 1;
if ($status eq 'old') {
+ $r->print('</td><td>');
my $max_id = 0;
- foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
- if ($role_id > $max_id) {
- $max_id = $role_id;
- }
- $max_id ++;
- my $role_selects = &role_selectors($num,$role_id,$status,$type,$content,'display');
- $r->print('<tr><td><span style="white-space: nowrap"><label><input type="checkbox" name="delete_role_'.$num.'" value="'.$role_id.'" />'.&mt('Delete').'</label></span><br /><input type="hidden" name="preserve_role_'.$num.'" value="'.$role_id.'" /></td>'.$role_selects.'</tr>');
- }
- $r->print('</table><br />'.&mt('Add a roles-based condition').' <input type="checkbox" name ="add_role_'.$num.'" onClick="javascript:setRoleOptions(this,'."'$num','$content->{'domain'}','$content->{'number'}','$uctype'".')" value="'.$max_id.'" /><input type="hidden" name="role_'.$num.'_'.$max_id.'" /><input type="hidden" name="access_'.$num.'_'.$max_id.'" /><input type="hidden" name="section_'.$num.'_'.$max_id.'" /><input type="hidden" name="group_'.$num.'_'.$max_id.'" /></td>');
- } elsif ($status eq 'new') {
- my $role_id = 1;
- my $role_selects = &role_selectors($num,$role_id,$status,$type,undef,'display');
- $r->print('<tr><td><input type="checkbox" name="add_role_'.$num.'" value="'.$role_id.'" checked="checked" />'.&mt('Add').'<input type="hidden" name="grplist_'.$num.'_'.$role_id.'" /></td>'.$role_selects);
- $r->print('</tr></table></td>');
+ if (keys(%{$content->{'roles'}}) > 0) {
+ $r->print('<table><tr><th>'.&mt('Action').'</th>'.
+ '<th>'.&mt('Roles').'</th>'.
+ '<th>'.&mt('Access').'</th>'.
+ '<th>'.&mt('Sections').'</th>'.
+ '<th>'.&mt('Groups').'</th></tr>');
+ foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
+ if ($role_id > $max_id) {
+ $max_id = $role_id;
+ }
+ $max_id ++;
+ my $role_selects = &role_selectors($num,$role_id,$type,$content,'display');
+ $r->print('<tr><td><span style="white-space: nowrap"><label><input type="checkbox" name="delete_role_'.$num.'" value="'.$role_id.'" />'.&mt('Delete').'</label></span><br /><input type="hidden" name="preserve_role_'.$num.'" value="'.$role_id.'" /></td>'.$role_selects.'</tr>');
+ }
+ $r->print('</table>');
+ }
+ $r->print('<br />'.&mt('Add a roles-based condition').
+ ' <input type="checkbox" name ="add_role_'.
+ $num.'" onClick="javascript:setRoleOptions('."'$num',
+ '$max_id','$content->{'domain'}','$content->{'number'}',
+ '$uctype'".')" value="" />');
+ $newrole_id = $max_id;
+ } else {
+ $r->print('<input type="hidden" name ="add_role_'.$num.'" value="" />');
}
+ $r->print(&add_course_role($num,$newrole_id));
+ $r->print('</td>');
return;
}
+sub add_course_role {
+ my ($num,$max_id) = @_;
+ my $output;
+ $output .='<input type="hidden" name="role_'.$num.'_'.$max_id.'" />'.
+ '<input type="hidden" name="access_'.$num.'_'.$max_id.'" />'.
+ '<input type="hidden" name="section_'.$num.'_'.$max_id.'" />'.
+ '<input type="hidden" name="group_'.$num.'_'.$max_id.'" />';
+ return $output;
+}
+
sub domains_row {
my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
@@ -1562,21 +1585,12 @@
}
sub role_selectors {
- my ($num,$role_id,$status,$type,$content,$caller) = @_;
+ my ($num,$role_id,$type,$content,$caller) = @_;
my ($output,$cdom,$cnum,$longid);
if ($caller eq 'display') {
$longid = '_'.$num.'_'.$role_id;
- if ($status eq 'new') {
- foreach my $item ('role','access','section','group') {
- $output .= '<td><select name="'.$item.$longid.'">'.
- '<option value="">'.&mt('Pick [_1] first',$type).
- '</option></select></td>';
- }
- return $output;
- } else {
- $cdom = $$content{'domain'};
- $cnum = $$content{'number'};
- }
+ $cdom = $$content{'domain'};
+ $cnum = $$content{'number'};
} elsif ($caller eq 'rolepicker') {
$cdom = $env{'form.cdom'};
$cnum = $env{'form.cnum'};
@@ -1614,7 +1628,7 @@
'role' => $allroles,
'access' => \@allaccesses,
'section' => $sections,
- 'group' => $groups,
+ 'group' => $groups,
);
foreach my $item ('role','access','section','group') {
$output .= '<td><select name="'.$item.$longid.'" multiple="true" size="4">'."\n";
@@ -1638,16 +1652,21 @@
sub role_options_window {
my ($r) = @_;
- my $cdom = $env{'form.cdom'};
- my $cnum = $env{'form.cnum'};
my $type = $env{'form.type'};
- my $addindex = $env{'form.setroles'};
- my $role_selects = &role_selectors(1,1,'new',$type,undef,'rolepicker');
+ my $rolenum = $env{'form.setroles'};
+ my ($num,$role_id) = ($rolenum =~ /^([\d_]+)_(\d+)$/);
+ my $role_elements;
+ foreach my $item ('role','access','section','group') {
+ $role_elements .= "'".$item.'_'.$rolenum."',";
+ }
+ $role_elements =~ s/,$//;
+ my $role_selects = &role_selectors($num,$role_id,$type,undef,
+ 'rolepicker');
$r->print(<<"END_SCRIPT");
<script type="text/javascript">
function setRoles() {
- var addidx = $addindex+1;
- for (var i=0; i<4; i++) {
+ var role_elements = new Array($role_elements);
+ for (var i=0; i<role_elements.length; i++) {
var copylist = '';
for (var j=0; j<document.rolepicker.elements[i].length; j++) {
if (document.rolepicker.elements[i].options[j].selected) {
@@ -1655,10 +1674,23 @@
}
}
copylist = copylist.substr(0,copylist.length-1);
- opener.document.portform.elements[addidx+i].value = copylist;
+ var openerItem = getIndexByName(role_elements[i]);
+ opener.document.portform.elements[openerItem].value = copylist;
}
+ var roleAdder = getIndexByName('add_role_$num');
+ opener.document.portform.elements[roleAdder].value = '$role_id';
self.close();
}
+
+function getIndexByName(item) {
+ for (var i=0;i<opener.document.portform.elements.length;i++) {
+ if (opener.document.portform.elements[i].name == item) {
+ return i;
+ }
+ }
+ return -1;
+}
+
</script>
END_SCRIPT
$r->print(&mt('Select roles, course status, section(s) and group(s) for users who will be able to access the portfolio file.'));
--raeburn1163111613--