[LON-CAPA-cvs] cvs: loncom /interface lonmodifycourse.pm lonpickcourse.pm
raeburn
raeburn at source.lon-capa.org
Thu Jan 5 11:17:11 EST 2017
raeburn Thu Jan 5 16:17:11 2017 EDT
Modified files:
/loncom/interface lonmodifycourse.pm lonpickcourse.pm
Log:
Ad hoc roles for helpdesk personnel.
- Entering a course with one of the available ad hoc roles via
Main Menu > View a course or community (Domain helpdesk role)
uses modal pop-up to select role, after choosing course, if more
than one ad hoc role is available to current user.
-------------- next part --------------
Index: loncom/interface/lonmodifycourse.pm
diff -u loncom/interface/lonmodifycourse.pm:1.89 loncom/interface/lonmodifycourse.pm:1.90
--- loncom/interface/lonmodifycourse.pm:1.89 Thu Nov 10 21:42:19 2016
+++ loncom/interface/lonmodifycourse.pm Thu Jan 5 16:17:11 2017
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# handler for DC-only modifiable course settings
#
-# $Id: lonmodifycourse.pm,v 1.89 2016/11/10 21:42:19 raeburn Exp $
+# $Id: lonmodifycourse.pm,v 1.90 2017/01/05 16:17:11 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -203,28 +203,24 @@
$settingsoption = &mt('View or modify course settings which only a [_1] may modify.',$dctitle);
}
} elsif (&Apache::lonnet::allowed('rar',$dom)) {
- my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
- 'adhocroles.'.$dom);
- if (keys(%adhocroles)) {
- my @adhoc = split(',',$adhocroles{'adhocroles.'.$dom});
- if (@adhoc > 1) {
+ my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($dom);
+ if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) {
+ if (@{$roles_by_num} > 1) {
if ($type eq 'Community') {
- $roleoption = &mt('Enter the community with one of the available ad hoc roles: [_1].',
- join(', ', at adhoc));
+ $roleoption = &mt('Enter the community with one of the available ad hoc roles');
} elsif ($type eq 'Placement') {
- $roleoption = &mt('Enter the placement test with one of the available ad hoc roles: [_1].',
- join(', ', at adhoc));
+ $roleoption = &mt('Enter the placement test with one of the available ad hoc roles.');
} else {
- $roleoption = &mt('Enter the course with one of the available ad hoc roles: [_1].',
- join(', ', at adhoc));
+ $roleoption = &mt('Enter the course with one of the available ad hoc roles.');
}
} else {
+ my $rolename = $description->{$roles_by_num->[0]};
if ($type eq 'Community') {
- $roleoption = &mt('Enter the community with the ad hoc role of: [_1]',$adhoc[0]);
+ $roleoption = &mt('Enter the community with the ad hoc role of: [_1]',$rolename);
} elsif ($type eq 'Placement') {
- $roleoption = &mt('Enter the placement test with the ad hoc role of: [_1]',$adhoc[0]);
+ $roleoption = &mt('Enter the placement test with the ad hoc role of: [_1]',$rolename);
} else {
- $roleoption = &mt('Enter the course with the ad hoc role of: [_1]',$adhoc[0]);
+ $roleoption = &mt('Enter the course with the ad hoc role of: [_1]',$rolename);
}
}
}
@@ -245,14 +241,131 @@
}
sub print_course_selection_page {
- my ($r,$dom,$domdesc) = @_;
+ my ($r,$dom,$domdesc,$permission) = @_;
my $type = $env{'form.type'};
if (!defined($type)) {
$type = 'Course';
}
&print_header($r,$type);
-# Criteria for course search
+ if ($permission->{'adhocrole'} eq 'custom') {
+ my %lt = &Apache::lonlocal::texthash(
+ title => 'Ad hoc role selection',
+ preamble => 'Please choose an ad hoc role in the course.',
+ cancel => 'Click "OK" to enter the course, or "Cancel" to choose a different course.',
+ );
+ my %jslt = &Apache::lonlocal::texthash (
+ none => 'You are not eligible to use an ad hoc role for the selected course',
+ ok => 'OK',
+ exit => 'Cancel',
+ );
+ &js_escape(\%jslt);
+ $r->print(<<"END");
+<script type="text/javascript">
+// <![CDATA[
+\$(document).ready(function(){
+ \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
+});
+
+function gochoose(cname,cdom,cdesc) {
+ document.courselist.pickedcourse.value = cdom+'_'+cname;
+ \$("#LC_choose_adhoc").empty();
+ var pickedaction = \$('input[name=phase]:checked', '#LCcoursepicker').val();
+ if (pickedaction == 'adhocrole') {
+ var http = new XMLHttpRequest();
+ var url = "/adm/pickcourse";
+ var params = "cid="+cdom+"_"+cname+"&context=adhoc";
+ http.open("POST", url, true);
+ http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ http.onreadystatechange = function() {
+ if (http.readyState == 4 && http.status == 200) {
+ var data = \$.parseJSON(http.responseText);
+ var len = data.roles.length;
+ if (len == '' || len == null || len == 0) {
+ alert('$jslt{none}');
+ } else {
+ if (len == 1) {
+ \$( '[name="adhocrole"]' )[0].value = data.roles[0].name;
+ document.courselist.submit();
+ } else {
+ var str = '';
+ for (var i=0; i<data.roles.length; i++) {
+ \$("<label><input type='radio' value='"+data.roles[i].name+"' name='LC_get_role' id='LC_get_role_"+i+"' />"+data.roles[i].desc+"</label><span> </span>")
+ .appendTo("#LC_choose_adhoc");
+ }
+ \$( "#LC_get_role_0").prop("checked", true);
+ \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
+ \$( "#LC_adhocrole_chooser" ).dialog("open");
+ \$( "#LC_adhocrole_chooser" ).dialog({
+ height: 400,
+ width: 500,
+ modal: true,
+ resizable: false,
+ buttons: [
+ {
+ text: "$jslt{'ok'}",
+ click: function() {
+ var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val();
+ \$( '[name="adhocrole"]' )[0].value = rolename;
+ document.courselist.submit();
+ }
+ },
+ {
+ text: "$jslt{'exit'}",
+ click: function() {
+ \$("#LC_adhocrole_chooser").dialog( "close" );
+ }
+ }
+ ],
+ });
+ \$( "#LC_adhocrole_chooser" ).find( "form" ).on( "submit", function( event ) {
+ event.preventDefault();
+ var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val()
+ \$( '[name="adhocrole"]' )[0].value = rolename;
+ document.courselist.submit();
+ \$("#LC_adhocrole_chooser").dialog( "close" );
+ });
+ }
+ }
+ }
+ }
+ http.send(params);
+ } else {
+ document.courselist.submit();
+ }
+ return;
+}
+// ]]>
+</script>
+
+<div id="LC_adhocrole_chooser" title="$lt{'title'}">
+ <p>$lt{'preamble'}</p>
+ <form name="LChelpdeskadhoc" id="LChelpdeskpicker" action="">
+ <div id="LC_choose_adhoc">
+ </div>
+ <input type="hidden" name="adhocrole" id="LCadhocrole" value="" />
+ <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
+ </form>
+ <p>$lt{'cancel'}</p>
+</div>
+END
+ } elsif ($permission->{'adhocrole'} eq 'coord') {
+ $r->print(<<"END");
+<script type="text/javascript">
+// <![CDATA[
+
+function gochoose(cname,cdom,cdesc) {
+ document.courselist.pickedcourse.value = cdom+'_'+cname;
+ document.courselist.submit();
+ return;
+}
+
+// ]]>
+</script>
+END
+ }
+
+# Criteria for course search
my ($filterlist,$filter) = &get_filters();
my $action = '/adm/modifycourse';
my $dctitle = &Apache::lonnet::plaintext('dc');
@@ -497,29 +610,25 @@
}
sub print_adhocrole_selected {
- my ($r,$type) = @_;
+ my ($r,$type,$permission) = @_;
&print_header($r,$type);
my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
my ($newrole,$selectrole);
- if (&Apache::lonnet::allowed('ccc',$cdom)) {
+ if ($permission->{'adhocrole'} eq 'coord') {
if ($type eq 'Community') {
$newrole = "co./$cdom/$cnum";
} else {
$newrole = "cc./$cdom/$cnum";
}
$selectrole = 1;
- } elsif (&Apache::lonnet::allowed('rar',$cdom)) {
- my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
- 'adhocroles.'.$cdom);
- if (keys(%adhocroles)) {
- my $possrole = $env{'form.adhocrole'};
- if ($possrole ne '') {
- my @adhoc = split(',',$adhocroles{'adhocroles.'.$cdom});
- if (grep(/^\Q$possrole\E$/, at adhoc)) {
- my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
- $newrole = "cr/$cdom/$confname/$possrole./$cdom/$cnum";
- $selectrole = 1;
- }
+ } elsif ($permission->{'adhocrole'} eq 'custom') {
+ my ($okroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.pickedcourse'},1);
+ if (ref($okroles) eq 'ARRAY') {
+ my $possrole = $env{'form.adhocrole'};
+ if (($possrole ne '') && (grep(/^\Q$possrole\E$/,@{$okroles}))) {
+ my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
+ $newrole = "cr/$cdom/$confname/$possrole./$cdom/$cnum";
+ $selectrole = 1;
}
}
}
@@ -2067,13 +2176,7 @@
if ($phase eq 'setparms') {
$js .= $javascript_validations;
} elsif ($phase eq 'courselist') {
- $js .= qq|
-
-function gochoose(cname,cdom,cdesc) {
- document.courselist.pickedcourse.value = cdom+'_'+cname;
- document.courselist.submit();
-}
-
+ $js .= <<"ENDJS";
function hide_searching() {
if (document.getElementById('searching')) {
document.getElementById('searching').style.display = 'none';
@@ -2081,7 +2184,7 @@
return;
}
-|;
+ENDJS
} elsif ($phase eq 'setquota') {
my $invalid = &mt('The quota you entered contained invalid characters.');
my $alert = &mt('You must enter a number');
@@ -2347,6 +2450,7 @@
catsettings => 'edit',
processcat => 'edit',
selfenroll => 'edit',
+ adhocrole => 'coord',
);
} elsif (&Apache::lonnet::allowed('rar',$dom)) {
$allowed = 1;
@@ -2358,6 +2462,7 @@
setparms => 'view',
catsettings => 'view',
selfenroll => 'view',
+ adhocrole => 'custom',
);
}
return ($allowed,\%permission);
@@ -2412,7 +2517,7 @@
{href=>"javascript:changePage(document.$phase,'courselist')",
text=>$choose_text});
if ($phase eq 'courselist') {
- &print_course_selection_page($r,$dom,$domdesc);
+ &print_course_selection_page($r,$dom,$domdesc,$permission);
} else {
my ($checked,$cdesc,$coursehash) = &check_course($dom,$domdesc);
if ($checked eq 'ok') {
@@ -2435,7 +2540,7 @@
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:changePage(document.$phase,'adhocrole')",
text=>$enter_text});
- &print_adhocrole_selected($r,$type);
+ &print_adhocrole_selected($r,$type,$permission);
} else {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:changePage(document.$phase,'menu')",
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.124 loncom/interface/lonpickcourse.pm:1.125
--- loncom/interface/lonpickcourse.pm:1.124 Tue Jan 3 17:47:57 2017
+++ loncom/interface/lonpickcourse.pm Thu Jan 5 16:17:11 2017
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.124 2017/01/03 17:47:57 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.125 2017/01/05 16:17:11 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -44,7 +44,7 @@
if ($env{'form.context'} eq 'adhoc') {
&Apache::loncommon::content_type($r,'application/json');
$r->send_http_header;
- my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.cid'});
+ my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.cid'},1);
if ((ref($possroles) eq 'ARRAY') && (ref($description) eq 'HASH')) {
my $response = [];
if (@{$possroles}) {
@@ -440,7 +440,7 @@
$action = '/adm/portfolio';
}
my $numcourses = keys(%courses);
- $r->print('<form name="courselist" method="post" action="'.$action.'">');
+ $r->print('<form name="courselist" method="post" action="'.$action.'" id="LCcoursepicker">');
if ($env{'form.form'} eq 'modifycourse') {
if ($numcourses > 0) {
my $ccrole = 'cc';
@@ -469,39 +469,36 @@
$r->print(&mt('Enter the course with the role of [_1].',$cctitle));
}
} elsif (&Apache::lonnet::allowed('rar',$crsdom)) {
- my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
- 'adhocroles.'.$crsdom);
- if ($adhocroles{'adhocroles.'.$crsdom} ne '') {
- $possrole = 1;
- $r->print($roleradio);
- my @adhoc = split(/,/,$adhocroles{'adhocroles.'.$crsdom});
- if (@adhoc > 1) {
- my %adhochash;
- map { $adhochash{$_} = $_; } @adhoc;
- my $selector = &Apache::loncommon::select_form($adhoc[0],'adhocrole',\%adhochash);
+ my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($crsdom);
+ if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) {
+ if (@{$roles_by_num} > 1) {
+ $r->print($roleradio);
if ($type eq 'Community') {
- $r->print(&mt('Enter the community with one of the available ad hoc roles: [_1].',
- $selector));
+ $r->print(&mt('Enter the community with one of the available ad hoc roles.'));
} elsif ($type eq 'Placement') {
- $r->print(&mt('Enter the placement test with one of the available ad hoc roles: [_1].',
- $selector));
+ $r->print(&mt('Enter the placement test with one of the available ad hoc roles.'));
} else {
- $r->print(&mt('Enter the course with one of the available ad hoc roles: [_1].',
- $selector));
+ $r->print(&mt('Enter the course with one of the available ad hoc roles.'));
}
- } else {
+ $possrole = 1;
+ } elsif (@{$roles_by_num} == 1) {
+ $r->print($roleradio);
+ my $rolename = $description->{$roles_by_num->[0]};
if ($type eq 'Community') {
- $r->print(&mt('Enter the community with the ad hoc role of: [_1]',$adhoc[0]));
+ $r->print(&mt('Enter the community with the ad hoc role of: [_1]',$rolename));
} elsif ($type eq 'Placement') {
- $r->print(&mt('Enter the placement test with the ad hoc role of: [_1]',$adhoc[0]));
+ $r->print(&mt('Enter the placement test with the ad hoc role of: [_1]',$rolename));
} else {
- $r->print(&mt('Enter the course with the ad hoc role of: [_1]',$adhoc[0]));
+ $r->print(&mt('Enter the course with the ad hoc role of: [_1]',$rolename));
}
- $r->print('<input type="hidden" name="adhocrole" value="'.$adhoc[0].'" />');
+ $possrole = 1;
+ }
+ if ($possrole) {
+ $r->print('<input type="hidden" name="adhocrole" value="" />');
}
}
}
- if ($possrole) {
+ if ($possrole) {
$r->print('</label></span><br />');
}
$r->print('<span class="LC_nobreak"><label>'
@@ -766,7 +763,7 @@
$r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
$r->print('<input type="hidden" name="action" value="rolepicker" />');
} elsif ($env{'form.form'} eq 'modifycourse') {
- $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state']));
+ $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state','adhocrole']));
} else {
$r->print('<input type="hidden" name="cnumelement" value="'.
$env{'form.cnumelement'}.'" />'."\n".
@@ -872,7 +869,9 @@
my $output;
if ($rolechooser) {
$output .= qq|
-\$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
+\$(document).ready(function(){
+ \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
+});
|;
}
$output .= qq|
More information about the LON-CAPA-cvs
mailing list