--- loncom/interface/lonpickcourse.pm 2016/11/02 22:41:18 1.122 +++ loncom/interface/lonpickcourse.pm 2017/01/05 16:17:11 1.125 @@ -1,7 +1,7 @@ # The LearningOnline Network # Pick a course # -# $Id: lonpickcourse.pm,v 1.122 2016/11/02 22:41:18 raeburn Exp $ +# $Id: lonpickcourse.pm,v 1.125 2017/01/05 16:17:11 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -37,13 +37,32 @@ use Apache::lonnet; use Apache::lonlocal; use Apache::longroup; use LONCAPA qw(:DEFAULT :match); +use JSON::DWIW; sub handler { my $r = shift; + 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'},1); + if ((ref($possroles) eq 'ARRAY') && (ref($description) eq 'HASH')) { + my $response = []; + if (@{$possroles}) { + foreach my $role (@{$possroles}) { + push(@{$response}, + { name => $role, + desc => $description->{$role}, + }); + } + } + $r->print(JSON::DWIW->to_json({roles => $response})); + } + return OK; + } &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK if $r->header_only; - + # ------------------------------------------------------------ Print the screen # Get parameters from query string @@ -53,7 +72,8 @@ sub handler { 'multiple','type','setroles','fixeddom','cloner', 'crscode','crsdom']); my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement, - $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom,$crscode,$crsdom); + $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom,$crscode, + $crsdom,$rolechooser); # Get course type - Course, Community or Placement. $type = $env{'form.type'}; @@ -75,6 +95,25 @@ sub handler { $roleelement = ''; $submitopener = &processpick(); $autosubmit = 'process_pick("'.$roledom.'","'.$rolename.'")'; + if ($rolename eq 'dh') { + 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.', + ); + + $rolechooser = <<"END"; +
+

$lt{'preamble'}

+
+
+
+ +
+

$lt{'cancel'}

+
+END + } } if ($env{'form.typeelement'} ne '') { $typeelement = ''; @@ -149,7 +188,8 @@ sub handler { # print javascript functions for choosing a course if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) || $onlyown) { - $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction)); + $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction, + $rolename,$rolechooser)); } $r->print(&Apache::lonhtmlcommon::scripttag($jscript)); $r->print($submitopener); @@ -400,7 +440,7 @@ sub display_matched_courses { $action = '/adm/portfolio'; } my $numcourses = keys(%courses); - $r->print('
'); + $r->print(''); if ($env{'form.form'} eq 'modifycourse') { if ($numcourses > 0) { my $ccrole = 'cc'; @@ -429,39 +469,36 @@ sub display_matched_courses { $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(''); + $possrole = 1; + } + if ($possrole) { + $r->print(''); } } } - if ($possrole) { + if ($possrole) { $r->print('
'); } $r->print('  ") + .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: "$lt{'ok'}", + click: function() { + var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val(); + process_pick(cdom,rolename); + \$("#LC_adhocrole_chooser").dialog( "close" ); + $lastaction; + } + }, + { + text: "$lt{'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() + process_pick(cdom,rolename); + \$("#LC_adhocrole_chooser").dialog( "close" ); + $lastaction; + }); + } + } + } } -|; - return &Apache::lonhtmlcommon::scripttag($output); +http.send(params); + } else { + $autosubmit + $lastaction + } +} + +ENDJS + return $rolechooser.&Apache::lonhtmlcommon::scripttag($output); } 1; @@ -1038,9 +1156,9 @@ Side Effects: None =item * X -B: +B: -Input: 4 - course type; single (0) or multiple courses (1); in context of DC selecting a CC role in a course: javascript code from &processpick(); final action to take after user chooses course(s): either close window, or submit form for display of next page etc. +Input: 5 - course type; single (0) or multiple courses (1); in context of DC selecting a CC role in a course: javascript code from &processpick(); final action to take after user chooses course(s): either close window, or submit form for display of next page etc.; rolename (e.g., dh) of user's current role. Output: 1 $output - javascript wrapped in EscriptEE/scriptE tags