--- loncom/interface/lonextresedit.pm 2020/10/25 20:14:42 1.8.2.4.2.2 +++ loncom/interface/lonextresedit.pm 2017/12/18 22:56:45 1.23 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: lonextresedit.pm,v 1.8.2.4.2.2 2020/10/25 20:14:42 raeburn Exp $ +# $Id: lonextresedit.pm,v 1.23 2017/12/18 22:56:45 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -161,6 +161,9 @@ sub process_changes { $newurl = $1; $marker = $2; $args = $3; + if ((!$symb) && (!$supplementalflag)) { + $symb = "uploaded/$cdom/$cnum/$folder.$container"."___$newidx"."___adm/$cdom/$cnum/$marker/ext.tool"; + } } } if ($supplementalflag) { @@ -170,7 +173,7 @@ sub process_changes { } if ($folder && $container) { if ($env{'form.importdetail'}) { - my ($errtext,$fatal,$mismatchedid,@imports); + my ($errtext,$fatal,$mismatchedid,$needreload,$newgradable,@imports); if (!$supplementalflag) { if (($oldidx) && ($oldidx != $newidx)) { $mismatchedid = 1; @@ -181,9 +184,27 @@ sub process_changes { } elsif (($newtitle eq $oldtitle) && ($newurl eq $oldurl)) { if ($type eq 'tool') { if ($args) { - ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args); - unless ($updated) { - $output = &mt('No change'); + ($updated,$newgradable,$errormsg) = &update_exttool($marker,$cdom,$cnum, + $supplementalflag,$args); + if ($updated) { + if ($newgradable) { + my $map = "/uploaded/$cdom/$cnum/$folder.$container"; + my ($errtext,$fatal) = &LONCAPA::map::mapread($map); + if ($fatal) { + $errormsg = &mt('Update failed: [_1].',$errtext); + } else { + &LONCAPA::map::storeparameter($residx,'parameter_0_gradable', + $newgradable,'string_yesno'); + my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,1); + if ($errtext) { + $errormsg = &mt('Update failed: [_1].',$errtext); + } else { + $needreload = 1; + } + } + } + } else { + $output = &mt('No change'); } } else { $output = &mt('No change'); @@ -202,13 +223,25 @@ sub process_changes { my $ext = 'true'; if ($type eq 'tool') { if ($args) { - ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args); + ($updated,$newgradable,$errormsg) = &update_exttool($marker,$cdom,$cnum, + $supplementalflag,$args); + if ($newgradable) { + &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$newgradable, + 'string_yesno'); + $needreload = 1; + } } $ext = 'false'; } + my $dotimeupdate; + unless ($supplementalflag) { + if (($newgradable) || ($newurl ne $oldurl)) { + $dotimeupdate = 1; + } + } $LONCAPA::map::resources[$residx] = join(':', ($savetitle,$saveurl,$ext,'normal','res')); - my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1); + my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,$dotimeupdate); if ($errtext) { $errormsg = &mt('Update failed: [_1].',$errtext); } else { @@ -230,19 +263,24 @@ sub process_changes { &Apache::lonnet::devalidate_title_cache($symb); } } - } - my ($furl,$ferr) = - &Apache::lonuserstate::readmap("$cdom/$cnum"); - if ($ferr) { - $errormsg = &mt('Reload failed: [_1].',$ferr); - } else { - unless ($supplementalflag) { - &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum); - } + $needreload = 1; } } } } + if ($needreload) { + my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum"); + if ($ferr) { + $errormsg = &mt('Reload failed: [_1].',$ferr); + } else { + &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome, + $cdom.'_'.$cnum); + } + } + if (($type eq 'tool') && ($newgradable)) { + my $uri = &Apache::lonnet::declutter($url); + &Apache::lonnet::devalidate_cache_new('meta',$uri); + } } else { $output = &mt('No change'); } @@ -257,15 +295,16 @@ sub process_changes { } sub update_exttool { - my ($marker,$cdom,$cnum,$args) = @_; - my (%newhash,$changed,@deleted,$errormsg); + my ($marker,$cdom,$cnum,$supplementalflag,$args) = @_; + my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); + my (%newhash,$changed,$newgradable,@deleted,$errormsg); ($newhash{'target'},$newhash{'width'},$newhash{'height'},$newhash{'linktext'},$newhash{'explanation'}, - $newhash{'crslabel'},$newhash{'crstitle'},$newhash{'crsappend'}) = split(/:/,$args); + $newhash{'crslabel'},$newhash{'crstitle'},$newhash{'crsappend'},$newhash{'gradable'}) = split(/:/,$args); foreach my $item ('linktext','explanation','crslabel','crstitle','crsappend') { $newhash{$item} = &unescape($newhash{$item}); } my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); - foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle','crsappend') { + foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle','crsappend','gradable') { $newhash{$item} =~ s/^\s+//; $newhash{$item} =~ s/\s+$//; if (($item eq 'width') || ($item eq 'height') || ($item eq 'linktext') || ($item eq 'explanation')) { @@ -276,8 +315,19 @@ sub update_exttool { $newhash{$item} = ''; } } + } elsif ($item eq 'gradable') { + unless ($newhash{$item} == 1) { + $newhash{$item} = ''; + } } if ($toolhash{$item} ne $newhash{$item}) { + if (($item eq 'gradable') && (!$supplementalflag)) { + if ($newhash{$item}) { + $newgradable = 'yes'; + } else { + $newgradable = 'no'; + } + } if ($newhash{$item} eq '') { unless (($item eq 'target') || ((($item eq 'width') || ($item eq 'height')) && @@ -305,7 +355,7 @@ sub update_exttool { if (@deleted) { &Apache::lonnet::del('exttool_'.$marker,\@deleted,$cdom,$cnum); } - return ($changed,$errormsg); + return ($changed,$newgradable,$errormsg); } sub extedit_form { @@ -334,16 +384,16 @@ sub extedit_form { } my ($formname,$formid,$toggle,$fieldsetid,$urlid,$dispdivstyle,$dimendivstyle, $windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle, - $appendstyle,$legend,$urlelem,$toolelem,%toolattr); + $appendstyle,$gradablestyle,$legend,$urlelem,$toolelem,%toolattr); $formname = 'new'.$type; $toggle = $type; $fieldsetid = 'upload'.$type.'form'; $urlid = $type.'url'; map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight', 'crstitlediv','crslabeldiv','crsappenddiv', - 'crstitle','crslabel','crsappend','windiv', - 'linktextdiv','explanationdiv','linktext', - 'explanation','providerurl'); + 'gradablediv','crstitle','crslabel','crsappend', + 'windiv','linktextdiv','explanationdiv', + 'linktext','explanation','providerurl'); $dispdivstyle = 'display:none'; $dimendivstyle = 'display:none'; $windivstyle = 'display:none'; @@ -352,6 +402,7 @@ sub extedit_form { $labelstyle = 'display:none'; $titlestyle = 'display:none'; $appendstyle = 'display:none'; + $gradablestyle = 'display:none'; if ($supplementalflag) { $formname = 'newsupp'.$type; $toggle = 'supp'.$type; @@ -361,7 +412,7 @@ sub extedit_form { } my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,$crstitle,$crslabel, $crsappend,$fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget, - $linktext,$explanation,$providerurl,%chkstate); + $linktext,$explanation,$providerurl,$chkgrd,$chknogrd,%chkstate); $fieldsetstyle = 'display: none;'; $action = '/adm/coursedocs'; my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http'); @@ -470,6 +521,11 @@ sub extedit_form { $height = $toolhash{'height'}; $linktext = $toolhash{'linktext'}; $explanation = $toolhash{'explanation'}; + if ($toolhash{'gradable'}) { + $chkgrd = ' checked="checked"'; + } else { + $chknogrd = ' checked="checked"'; + } if (ref($ltitools->{$toolhash{'id'}}->{'crsconf'}) eq 'HASH') { if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'title'}) { $crstitle = $toolhash{'crstitle'}; @@ -494,6 +550,7 @@ sub extedit_form { } } $toolelem = ''.$image.' '.$tooltitle.'
'; + $gradablestyle = 'display:inline'; } } } @@ -526,6 +583,7 @@ sub extedit_form { $crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'}; $crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'}; $crsappend = ''; + $chknogrd = ' checked="checked"'; } $toolelem .= '
'. ''.&mt('Display target:').' '. @@ -563,7 +621,13 @@ sub extedit_form { ''.&mt('Append to URL[_1]', ' ('.$providerurl.')
'). '

'. - '
'; + ''. + '
'. + ''.&mt('Gradable').' '. + ''.(' 'x2). + '
'; } my $chooser = $toolelem; if ($type eq 'ext') { @@ -695,6 +759,7 @@ sub extedit_javascript { my $append = $toolsref->{$key}->{'crsconf'}->{'append'}; $toolsjs .= ' ltitoolsAppend['.$i.'] = '."'$append';\n"; } + $i++; } } @@ -702,12 +767,6 @@ sub extedit_javascript { my %js_lt = &Apache::lonlocal::texthash( invurl => 'Invalid URL', titbl => 'Title is blank', - mixfra => 'Show preview in pop-up? (http in https page + no framing)', - mixonly => 'Show preview in pop-up? (http in https page)', - fraonly => 'Show preview in pop-up? (framing disallowed)', - nopopup => 'Pop-up blocked', - nopriv => 'Insufficient privileges to use preview', - badurl => 'URL is not: http://hostname/path or https://hostname/path', invtool => 'Please select an external tool', ); &js_escape(\%js_lt); @@ -824,7 +883,7 @@ function setExternal(extform,residx,type if (residx > 0) { labelinput += '_'+residx; titleinput += '_'+residx; - appendinput += '_'+residx; + appendinput += '_'+residx; } if (document.getElementById(labelinput)) { var crslabel = document.getElementById(labelinput).value; @@ -847,6 +906,32 @@ function setExternal(extform,residx,type } else { info += ':'; } + var gradablediv = prefix+'toolgradablediv'; + if (residx > 0) { + gradablediv += '_'+residx; + } + if (document.getElementById(gradablediv)) { + if (document.getElementById(gradablediv).style.display == 'inline') { + if (extform.exttoolgradable.length) { + for (var i=0; i 0) { eval("extform.importdetail.value=title+'='+info+'='+residx;extform.submit();"); @@ -875,73 +960,14 @@ function extUrlPreview(caller,protocol) var url = document.getElementById(caller).value; if (regexp.test(url)) { var http_regex = /^http\:\/\//gi; - var mixed = 0; - var noiframe = 0; - var nopriv = 0; - var badurl = 0; - var name = "externalpreview"; if ((protocol == 'https') && (http_regex.test(url))) { - mixed = 1; - } - var http = new XMLHttpRequest(); - var lcurl = "/adm/exturlcheck"; - var params = "exturl="+url; - http.open("POST",lcurl, true); - http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - http.onreadystatechange = function() { - if (http.readyState == 4) { - if (http.status == 200) { - if (http.responseText.length > 0) { - if (http.responseText == 1) { - noiframe = 1; - } else if (http.responseText == -1) { - nopriv = 1; - } else if (http.responseText == 0) { - badurl = 1; - } - } - openPreviewWindow(url,name,noiframe,mixed,nopriv,badurl); - } - } - } - http.send(params); - } else { - alert("$js_lt{'invurl'}"); - } - } -} - -var previewLCWindow = null; -function openPreviewWindow(url,name,noiframe,mixed,nopriv,badurl) { - if (previewLCWindow !=null) { - previewLCWindow.close(); - } - if (badurl) { - alert("$js_lt{'badurl'}"); - } else if (nopriv) { - alert("$js_lt{'nopriv'}"); - } else if ((noiframe == 1) || (mixed == 1)) { - var encurl = encodeURI(url); - var msg; - if (mixed == 1) { - if (noiframe == 1) { - msg = "$js_lt{'mixfra'}"; + window.open(url,"externalpreview","height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1"); } else { - msg = "$js_lt{'mixonly'}"; + openMyModal(url,500,400,'yes'); } } else { - msg = "$js_lt{'fraonly'}"; - } - if (confirm(msg)) { - previewLCWindow = window.open(url,name,"height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1"); - if (previewLCWindow != null) { - previewLCWindow.focus(); - } else { - alert("$js_lt{'nopopup'}"); - } + alert("$js_lt{'invurl'}"); } - } else { - openMyModal(url,500,400,'yes'); } } @@ -957,6 +983,7 @@ function updateExttool(caller,form,suppl labeldiv = prefix+'toolcrslabeldiv'; titlediv = prefix+'toolcrstitlediv'; appenddiv = prefix+'toolcrsappenddiv'; + gradablediv = prefix+'toolgradablediv'; providerurl = prefix+'toolproviderurl'; labelinput = prefix+'toolcrslabel'; titleinput = prefix+'toolcrstitle'; @@ -994,6 +1021,9 @@ function updateExttool(caller,form,suppl if (document.getElementById(appenddiv)) { document.getElementById(appenddiv).style.display = 'none'; } + if (document.getElementById(gradablediv)) { + document.getElementById(gradablediv).style.display = 'none'; + } } else { if (ltitools.length > 0) { for (var j=0; j