From 1a0332cd9dc623b677fa7e6e2168d8a622a6adf9 Mon Sep 17 00:00:00 2001 From: Richard Lobb Date: Fri, 26 Jul 2024 19:03:31 +1200 Subject: [PATCH] Regression: Reset button and Ajax downloads of question fields in author form weren't working. --- amd/build/authorform.min.js | 2 +- amd/build/authorform.min.js.map | 2 +- amd/build/resetbutton.min.js | 2 +- amd/build/resetbutton.min.js.map | 2 +- amd/src/authorform.js | 2 +- amd/src/resetbutton.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/amd/build/authorform.min.js b/amd/build/authorform.min.js index 74a2703a9..826252cb2 100644 --- a/amd/build/authorform.min.js +++ b/amd/build/authorform.min.js @@ -5,6 +5,6 @@ * @copyright Richard Lobb, 2015, The University of Canterbury * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("qtype_coderunner/authorform",["jquery","qtype_coderunner/userinterfacewrapper","core/str"],(function($,ui,str){let currentQtype="";var JSON_TO_FORM_MAP={template:["#id_template","value",""],iscombinatortemplate:["#id_iscombinatortemplate","checked","",function(value){return"1"===value}],cputimelimitsecs:["#id_cputimelimitsecs","value",""],memlimitmb:["#id_memlimitmb","value",""],sandbox:["#id_sandbox","value","DEFAULT"],sandboxparams:["#id_sandboxparams","value",""],testsplitterre:["#id_testsplitterre","value","",function(splitter){return splitter.replace("\n","\\n")}],allowmultiplestdins:["#id_allowmultiplestdins","checked","",function(value){return"1"===value}],grader:["#id_grader","value","EqualityGrader"],resultcolumns:["#id_resultcolumns","value",""],language:["#id_language","value",""],acelang:["#id_acelang","value",""],uiplugin:["#id_uiplugin","value","ace"]};return{initEditForm:function(){var typeCombo=$("#id_coderunnertype"),prototypeDisplay=$("#id_isprototype"),template=$("#id_template"),evaluatePerStudent=$("#id_templateparamsevalpertry"),globalextra=$("#id_globalextra"),prototypeextra=$("#id_prototypeextra"),useace=$("#id_useace"),language=$("#id_language"),acelang=$("#id_acelang"),customise=$("#id_customise"),isCombinator=$("#id_iscombinatortemplate"),testSplitterRe=$("#id_testsplitterre"),allowMultipleStdins=$("#id_allowmultiplestdins"),customisationFieldSet=$("#id_customisationheader"),advancedCustomisation=$("#id_advancedcustomisationheader"),isCustomised=customise.prop("checked"),prototypeType=$("#id_prototypetype"),preloadHdr=$("#id_answerpreloadhdr"),courseId=$('input[name="courseid"]').prop("value"),questiontypeHelpDiv=$("#qtype-help"),precheck=$("select#id_precheck"),testtypedivs=$("div.testtype"),testsection=$("#id_testcasehdr"),brokenQuestion=$("#id_broken_question"),badQuestionLoad=$("#id_bad_question_load"),uiplugin=$("#id_uiplugin"),uiparameters=$("#id_uiparameters");function setUi(taId,uiname){var lang,uiWrapper,ta=$(document.getElementById(taId)),paramsJson=ta.attr("data-params"),params={};ta.attr("data-prototypeextra",prototypeextra.val()),ta.attr("data-globalextra",globalextra.val()),ta.attr("data-test0",$("#id_testcode_0").val());try{params=JSON.parse(paramsJson)}catch(err){}"none"===(uiname=uiname.toLowerCase())&&(uiname=""),"id_templateparams"==taId||"id_uiparameters"==taId?lang="":(lang=language.prop("value"),"id_template"!==taId&&acelang.prop("value")&&(lang=function(acelang){var langs,i;if(acelang.indexOf(",")<0)return acelang;for(langs=acelang.split(","),i=0;i0?langs[0]:""}(acelang.prop("value")))),uiWrapper=ta[0].current_ui_wrapper,ta.attr("data-lang",lang),uiWrapper?(params.lang=lang,uiWrapper.loadUi(uiname,params)):uiWrapper=new ui.InterfaceWrapper(uiname,taId)}function setUis(){let uiname=uiplugin.val(),answer=$("#id_answer"),enableUi=!0;if("html"===uiname&&""!==answer.attr("data-params"))try{!1===JSON.parse(answer.attr("data-params")).enable_in_editor&&(enableUi=!1)}catch(error){alert("Invalid UI parameters.")}enableUi&&(setUi("id_answer",uiname),setUi("id_answerpreload",uiname))}function setCustomisationVisibility(isVisible){var display=isVisible?"block":"none";customisationFieldSet.css("display",display),advancedCustomisation.css("display",display),isVisible&&useace.prop("checked")&&setUi("id_template","ace")}function copyFieldsFromQuestionType(newType,response){var formspecifier,attrval,isCombinatorEnabled;for(var key in function(stateOn){var uiWrapper,taIds=["id_template","id_uiparameters"];if(useace.prop("checked"))for(var i=0;i3&&(attrval=(0,formspecifier[3])(attrval)),$(formspecifier[0]).prop(formspecifier[1],attrval);customise.prop("checked",!1),str.get_string("coderunner_question_type","qtype_coderunner").then((function(s){var title,coderunner_descr,html,resultHtml;questiontypeHelpDiv.html((title=newType,coderunner_descr=s,html=response.questiontext,resultHtml='

',resultHtml+=coderunner_descr,resultHtml+=title+"

\n"+html))})),setCustomisationVisibility(!1),isCombinatorEnabled=isCombinator.prop("checked"),testSplitterRe.prop("disabled",!isCombinatorEnabled),allowMultipleStdins.prop("disabled",!isCombinatorEnabled)}function langStringAlert(key,extra){window.hasOwnProperty("behattesting")&&window.behattesting||str.get_string(key,"qtype_coderunner").then((function(s){var message=s.replace(/\n/g," ");extra&&(message+="\n"+extra),alert(message)}))}function loadCustomisationFields(){let newType=typeCombo.children("option:selected").text();""!==newType&&"Undefined"!==newType&&(typeCombo.children("option:first-child").prop("disabled","disabled"),$.getJSON(M.cfg.wwwroot+"/question/type/coderunner/ajax.php",{qtype:newType,courseid:courseId,sesskey:M.cfg.sesskey},(function(outcome){if($("#id_qtype_coderunner_warning_div").empty(),outcome.success)copyFieldsFromQuestionType(newType,outcome),setUis(),loadUiParametersDescription(),currentQtype=newType,$("#id_qtype_coderunner_error_div").empty();else{const errorObject=function(questionType,error){const errorObject=JSON.parse(error);return str.get_string("prototype_error","qtype_coderunner").then((function(s){str.get_string(errorObject.alert,"qtype_coderunner",questionType).then((function(str){langStringAlert("prototype_load_failure",str);let errorMessage=s+"\n";errorMessage+=str+"\n",errorMessage+="CourseId: "+courseId+", qtype: "+questionType,template.prop("value",errorMessage)}))})),errorObject}(newType,outcome.error);currentQtype!==newType&&"duplicateprototype"===errorObject.error&&(!function(currentType,errorObject,newType){str.get_string("loadprototypeerror","qtype_coderunner",{oldtype:currentType,crtype:newType,outputstring:errorObject.extras}).then((function(str){$("#id_qtype_coderunner_warning_div").append($("

"+str+"

"))}))}(currentQtype,errorObject,newType),$("#id_coderunnertype").val(currentQtype))}})).fail((function(){langStringAlert("error_loading_prototype"),template.prop("value","*** AJAX ERROR. DON'T SAVE THIS! ***"),str.get_string("ajax_error","qtype_coderunner").then((function(s){template.prop("value",s)}))})))}function updateUiParamsDescription(uiInfo){let currentuiparameters=uiparameters.val(),paramDescriptionDiv=$(".ui_parameters_descr");if(paramDescriptionDiv.empty(),null===uiInfo||0==uiInfo.uiparamstable.length&&""===currentuiparameters.trim())uiparameters.val(""),$("#fgroup_id_uiparametergroup").hide();else{paramDescriptionDiv.append(uiInfo.header);let showhidebutton=$('");if(0!=uiInfo.uiparamstable.length){paramDescriptionDiv.append(showhidebutton);let table=$(function(uiParamInfo){var param,i,html='
\n',hdrs=uiParamInfo.columnheaders;for(html+="\n",i=0;i\n";return html+"
"+hdrs[0]+""+hdrs[1]+""+hdrs[2]+"
"+(param=uiParamInfo.uiparamstable[i])[0]+""+param[1]+""+param[2]+"
\n"}(uiInfo));paramDescriptionDiv.append(table),table.hide(),showhidebutton.click((function(){showhidebutton.html()==uiInfo.showdetails?(table.show(),showhidebutton.html(uiInfo.hidedetails)):(table.hide(),showhidebutton.html(uiInfo.showdetails))}))}$("#fgroup_id_uiparametergroup").show(),useace.prop("checked")&&setUi("id_uiparameters","ace")}}function loadUiParametersDescription(){let newUi=uiplugin.children("option:selected").text();""===newUi||"none"===newUi?updateUiParamsDescription(null):$.getJSON(M.cfg.wwwroot+"/question/type/coderunner/ajax.php",{uiplugin:newUi,courseid:courseId,sesskey:M.cfg.sesskey},updateUiParamsDescription).fail((function(){langStringAlert("error_loading_ui_descr","UI: ".concat(newUi))}))}function set_testtype_visibilities(){"3"===precheck.val()?testtypedivs.show():testtypedivs.hide()}function check_ace_lang(){"ace"===uiplugin.val()&&setUis()}0!=prototypeType.prop("value")&&(testsection.css("display","none"),prototypeDisplay.removeAttr("hidden"),1==prototypeType.prop("value")&&(str.get_string("proceed_at_own_risk","qtype_coderunner").then((function(s){alert(s)})),prototypeType.prop("disabled",!0),customise.prop("disabled",!0))),function(){let messagePara=null;""!==brokenQuestion.prop("value")&&(messagePara=$("

"+brokenQuestion.prop("value")+"

"),$("#id_qtype_coderunner_error_div").append(messagePara))}(),badQuestionLoad.prop("hidden"),currentQtype=typeCombo.children("option:selected").text(),setCustomisationVisibility(isCustomised),isCustomised?(setUis(),str.get_string("info_unavailable","qtype_coderunner").then((function(s){questiontypeHelpDiv.html("

"+s+"

")}))):loadCustomisationFields(),set_testtype_visibilities(),useace.prop("checked")&&(setUi("id_templateparams","ace"),setUi("id_uiparameters","ace")),loadUiParametersDescription(),customise.on("change",(function(){customise.prop("checked")?setCustomisationVisibility(!0):str.get_string("confirm_proceed","qtype_coderunner").then((function(s){window.confirm(s)?setCustomisationVisibility(!1):customise.prop("checked",!0)}))})),acelang.on("change",check_ace_lang),language.on("change",(function(){useace.prop("checked")&&setUi("id_template","ace"),check_ace_lang()})),typeCombo.on("change",(function(){customise.prop("checked")?str.get_string("question_type_changed","qtype_coderunner").then((function(s){window.confirm(s)&&loadCustomisationFields()})):loadCustomisationFields()})),useace.on("change",(function(){useace.prop("checked")?(setUi("id_template","ace"),setUi("id_templateparams","ace"),setUi("id_uiparameters","ace")):(setUi("id_template",""),setUi("id_templateparams",""),setUi("id_uiparameters",""))})),evaluatePerStudent.on("change",(function(){evaluatePerStudent.is(":checked")&&langStringAlert("templateparamsusingsandbox")})),uiplugin.on("change",(function(){setUis(),loadUiParametersDescription()})),precheck.on("change",set_testtype_visibilities),prototypeType.on("change",(function(){"0"==prototypeType.prop("value")?(testsection.css("display","block"),prototypeDisplay.attr("hidden","1")):(testsection.css("display","none"),prototypeDisplay.removeAttr("hidden"))})),new MutationObserver((function(){setUis()})).observe(preloadHdr.get(0),{attributes:!0,attributeFilter:["class"]}),$("button.replaceexpectedwithgot").click((function(){var gotPre=$(this).prev('pre[id^="id_got_"]'),testCaseId=gotPre.attr("id").replace("id_got_","");$("#id_expected_"+testCaseId).val(gotPre.text()),$("#id_fail_expected_"+testCaseId).html(gotPre.text()),$(".failrow_"+testCaseId).addClass("fixed"),$(this).prop("disabled",!0)})),$(".btn-primary").click((function(){typeCombo.prop("disabled",!1)}))}}})); +define("qtype_coderunner/authorform",["jquery","qtype_coderunner/userinterfacewrapper","core/str"],(function($,ui,str){let currentQtype="";var JSON_TO_FORM_MAP={template:["#id_template","value",""],iscombinatortemplate:["#id_iscombinatortemplate","checked","",function(value){return"1"===value}],cputimelimitsecs:["#id_cputimelimitsecs","value",""],memlimitmb:["#id_memlimitmb","value",""],sandbox:["#id_sandbox","value","DEFAULT"],sandboxparams:["#id_sandboxparams","value",""],testsplitterre:["#id_testsplitterre","value","",function(splitter){return splitter.replace("\n","\\n")}],allowmultiplestdins:["#id_allowmultiplestdins","checked","",function(value){return"1"===value}],grader:["#id_grader","value","EqualityGrader"],resultcolumns:["#id_resultcolumns","value",""],language:["#id_language","value",""],acelang:["#id_acelang","value",""],uiplugin:["#id_uiplugin","value","ace"]};return{initEditForm:function(){var typeCombo=$("#id_coderunnertype"),prototypeDisplay=$("#id_isprototype"),template=$("#id_template"),evaluatePerStudent=$("#id_templateparamsevalpertry"),globalextra=$("#id_globalextra"),prototypeextra=$("#id_prototypeextra"),useace=$("#id_useace"),language=$("#id_language"),acelang=$("#id_acelang"),customise=$("#id_customise"),isCombinator=$("#id_iscombinatortemplate"),testSplitterRe=$("#id_testsplitterre"),allowMultipleStdins=$("#id_allowmultiplestdins"),customisationFieldSet=$("#id_customisationheader"),advancedCustomisation=$("#id_advancedcustomisationheader"),isCustomised=customise.prop("checked"),prototypeType=$("#id_prototypetype"),preloadHdr=$("#id_answerpreloadhdr"),courseId=$('input[name="courseid"]').prop("value"),questiontypeHelpDiv=$("#qtype-help"),precheck=$("select#id_precheck"),testtypedivs=$("div.testtype"),testsection=$("#id_testcasehdr"),brokenQuestion=$("#id_broken_question"),badQuestionLoad=$("#id_bad_question_load"),uiplugin=$("#id_uiplugin"),uiparameters=$("#id_uiparameters");function setUi(taId,uiname){var lang,uiWrapper,ta=$(document.getElementById(taId)),paramsJson=ta.attr("data-params"),params={};ta.attr("data-prototypeextra",prototypeextra.val()),ta.attr("data-globalextra",globalextra.val()),ta.attr("data-test0",$("#id_testcode_0").val());try{params=JSON.parse(paramsJson)}catch(err){}"none"===(uiname=uiname.toLowerCase())&&(uiname=""),"id_templateparams"==taId||"id_uiparameters"==taId?lang="":(lang=language.prop("value"),"id_template"!==taId&&acelang.prop("value")&&(lang=function(acelang){var langs,i;if(acelang.indexOf(",")<0)return acelang;for(langs=acelang.split(","),i=0;i0?langs[0]:""}(acelang.prop("value")))),uiWrapper=ta[0].current_ui_wrapper,ta.attr("data-lang",lang),uiWrapper?(params.lang=lang,uiWrapper.loadUi(uiname,params)):uiWrapper=new ui.InterfaceWrapper(uiname,taId)}function setUis(){let uiname=uiplugin.val(),answer=$("#id_answer"),enableUi=!0;if("html"===uiname&&""!==answer.attr("data-params"))try{!1===JSON.parse(answer.attr("data-params")).enable_in_editor&&(enableUi=!1)}catch(error){alert("Invalid UI parameters.")}enableUi&&(setUi("id_answer",uiname),setUi("id_answerpreload",uiname))}function setCustomisationVisibility(isVisible){var display=isVisible?"block":"none";customisationFieldSet.css("display",display),advancedCustomisation.css("display",display),isVisible&&useace.prop("checked")&&setUi("id_template","ace")}function copyFieldsFromQuestionType(newType,response){var formspecifier,attrval,isCombinatorEnabled;for(var key in function(stateOn){var uiWrapper,taIds=["id_template","id_uiparameters"];if(useace.prop("checked"))for(var i=0;i3&&(attrval=(0,formspecifier[3])(attrval)),$(formspecifier[0]).prop(formspecifier[1],attrval);customise.prop("checked",!1),str.get_string("coderunner_question_type","qtype_coderunner").then((function(s){var title,coderunner_descr,html,resultHtml;questiontypeHelpDiv.html((title=newType,coderunner_descr=s,html=response.questiontext,resultHtml='

',resultHtml+=coderunner_descr,resultHtml+=title+"

\n"+html))})),setCustomisationVisibility(!1),isCombinatorEnabled=isCombinator.prop("checked"),testSplitterRe.prop("disabled",!isCombinatorEnabled),allowMultipleStdins.prop("disabled",!isCombinatorEnabled)}function langStringAlert(key,extra){window.hasOwnProperty("behattesting")&&window.behattesting||str.get_string(key,"qtype_coderunner").then((function(s){var message=s.replace(/\n/g," ");extra&&(message+="\n"+extra),alert(message)}))}function loadCustomisationFields(){let newType=typeCombo.children("option:selected").text();""!==newType&&"Undefined"!==newType&&(typeCombo.children("option:first-child").prop("disabled","disabled"),$.getJSON(M.cfg.wwwroot+"/question/type/coderunner/ajax.php",{qtype:newType,courseid:courseId,sesskey:M.cfg.sesskey},(function(outcome){if($("#id_qtype_coderunner_warning_div").empty(),outcome.success)copyFieldsFromQuestionType(newType,outcome),setUis(),loadUiParametersDescription(),currentQtype=newType,$("#id_qtype_coderunner_error_div").empty();else{const errorObject=function(questionType,error){const errorObject=JSON.parse(error);return str.get_string("prototype_error","qtype_coderunner").then((function(s){str.get_string(errorObject.alert,"qtype_coderunner",questionType).then((function(str){langStringAlert("prototype_load_failure",str);let errorMessage=s+"\n";errorMessage+=str+"\n",errorMessage+="CourseId: "+courseId+", qtype: "+questionType,template.prop("value",errorMessage)}))})),errorObject}(newType,outcome.error);currentQtype!==newType&&"duplicateprototype"===errorObject.error&&(!function(currentType,errorObject,newType){str.get_string("loadprototypeerror","qtype_coderunner",{oldtype:currentType,crtype:newType,outputstring:errorObject.extras}).then((function(str){$("#id_qtype_coderunner_warning_div").append($("

"+str+"

"))}))}(currentQtype,errorObject,newType),$("#id_coderunnertype").val(currentQtype))}})).fail((function(){langStringAlert("error_loading_prototype"),template.prop("value","*** AJAX ERROR. DON'T SAVE THIS! ***"),str.get_string("ajax_error","qtype_coderunner").then((function(s){template.prop("value",s)}))})))}function updateUiParamsDescription(uiInfo){let currentuiparameters=uiparameters.val(),paramDescriptionDiv=$(".ui_parameters_descr");if(paramDescriptionDiv.empty(),null===uiInfo||0==uiInfo.uiparamstable.length&&""===currentuiparameters.trim())uiparameters.val(""),$("#fgroup_id_uiparametergroup").hide();else{paramDescriptionDiv.append(uiInfo.header);let showhidebutton=$('");if(0!=uiInfo.uiparamstable.length){paramDescriptionDiv.append(showhidebutton);let table=$(function(uiParamInfo){var param,i,html='
\n',hdrs=uiParamInfo.columnheaders;for(html+="\n",i=0;i\n";return html+"
"+hdrs[0]+""+hdrs[1]+""+hdrs[2]+"
"+(param=uiParamInfo.uiparamstable[i])[0]+""+param[1]+""+param[2]+"
\n"}(uiInfo));paramDescriptionDiv.append(table),table.hide(),showhidebutton.click((function(){showhidebutton.html()==uiInfo.showdetails?(table.show(),showhidebutton.html(uiInfo.hidedetails)):(table.hide(),showhidebutton.html(uiInfo.showdetails))}))}$("#fgroup_id_uiparametergroup").show(),useace.prop("checked")&&setUi("id_uiparameters","ace")}}function loadUiParametersDescription(){let newUi=uiplugin.children("option:selected").text();""===newUi||"none"===newUi?updateUiParamsDescription(null):$.getJSON(M.cfg.wwwroot+"/question/type/coderunner/ajax.php",{uiplugin:newUi,courseid:courseId,sesskey:M.cfg.sesskey},updateUiParamsDescription).fail((function(){langStringAlert("error_loading_ui_descr","UI: ".concat(newUi))}))}function set_testtype_visibilities(){"3"===precheck.val()?testtypedivs.show():testtypedivs.hide()}function check_ace_lang(){"ace"===uiplugin.val()&&setUis()}0!=prototypeType.prop("value")&&(testsection.css("display","none"),prototypeDisplay.removeAttr("hidden"),1==prototypeType.prop("value")&&(str.get_string("proceed_at_own_risk","qtype_coderunner").then((function(s){alert(s)})),prototypeType.prop("disabled",!0),customise.prop("disabled",!0))),function(){let messagePara=null;""!==brokenQuestion.prop("value")&&(messagePara=$("

"+brokenQuestion.prop("value")+"

"),$("#id_qtype_coderunner_error_div").append(messagePara))}(),badQuestionLoad.prop("hidden"),currentQtype=typeCombo.children("option:selected").text(),setCustomisationVisibility(isCustomised),isCustomised?(setUis(),str.get_string("info_unavailable","qtype_coderunner").then((function(s){questiontypeHelpDiv.html("

"+s+"

")}))):loadCustomisationFields(),set_testtype_visibilities(),useace.prop("checked")&&(setUi("id_templateparams","ace"),setUi("id_uiparameters","ace")),loadUiParametersDescription(),customise.on("change",(function(){customise.prop("checked")?setCustomisationVisibility(!0):str.get_string("confirm_proceed","qtype_coderunner").then((function(s){window.confirm(s)?setCustomisationVisibility(!1):customise.prop("checked",!0)}))})),acelang.on("change",check_ace_lang),language.on("change",(function(){useace.prop("checked")&&setUi("id_template","ace"),check_ace_lang()})),typeCombo.on("change",(function(){customise.prop("checked")?str.get_string("question_type_changed","qtype_coderunner").then((function(s){window.confirm(s)&&loadCustomisationFields()})):loadCustomisationFields()})),useace.on("change",(function(){useace.prop("checked")?(setUi("id_template","ace"),setUi("id_templateparams","ace"),setUi("id_uiparameters","ace")):(setUi("id_template",""),setUi("id_templateparams",""),setUi("id_uiparameters",""))})),evaluatePerStudent.on("change",(function(){evaluatePerStudent.is(":checked")&&langStringAlert("templateparamsusingsandbox")})),uiplugin.on("change",(function(){setUis(),loadUiParametersDescription()})),precheck.on("change",set_testtype_visibilities),prototypeType.on("change",(function(){"0"==prototypeType.prop("value")?(testsection.css("display","block"),prototypeDisplay.attr("hidden","1")):(testsection.css("display","none"),prototypeDisplay.removeAttr("hidden"))})),new MutationObserver((function(){setUis()})).observe(preloadHdr.get(0),{attributes:!0,attributeFilter:["class"]}),$("button.replaceexpectedwithgot").click((function(){var gotPre=$(this).prev('pre[id^="id_got_"]'),testCaseId=gotPre.attr("id").replace("id_got_","");$("#id_expected_"+testCaseId).val(gotPre.text()),$("#id_fail_expected_"+testCaseId).html(gotPre.text()),$(".failrow_"+testCaseId).addClass("fixed"),$(this).prop("disabled",!0)})),$(".btn-primary").click((function(){typeCombo.prop("disabled",!1)}))}}})); //# sourceMappingURL=authorform.min.js.map \ No newline at end of file diff --git a/amd/build/authorform.min.js.map b/amd/build/authorform.min.js.map index c682f6622..dd8882c2a 100644 --- a/amd/build/authorform.min.js.map +++ b/amd/build/authorform.min.js.map @@ -1 +1 @@ -{"version":3,"file":"authorform.min.js","sources":["../src/authorform.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/* jshint esversion: 6 */\n\n/**\n * JavaScript for handling UI actions in the question authoring form.\n *\n * @module qtype_coderunner/authorform\n * @copyright Richard Lobb, 2015, The University of Canterbury\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery', 'qtype_coderunner/userinterfacewrapper', 'core/str'], function($, ui, str) {\n\n // We need this to keep track of the current question type.\n let currentQtype = \"\";\n\n // Define a mapping from the fields of the JSON object returned by an AJAX\n // 'get question type' request to the form elements. Only fields that\n // belong to the question type should appear here. Keys are JSON field\n // names, values are a 3- or 4-element array of: a jQuery form element selector;\n // the element property to be set; a default value if the JSON field is\n // empty and an optional filter function to apply to the field value before\n // setting the property with it.\n var JSON_TO_FORM_MAP = {\n template: ['#id_template', 'value', ''],\n iscombinatortemplate:['#id_iscombinatortemplate', 'checked', '',\n function (value) {\n return value === '1' ? true : false;\n }], // Need nice clean boolean for 'checked' attribute.\n cputimelimitsecs: ['#id_cputimelimitsecs', 'value', ''],\n memlimitmb: ['#id_memlimitmb', 'value', ''],\n sandbox: ['#id_sandbox', 'value', 'DEFAULT'],\n sandboxparams: ['#id_sandboxparams', 'value', ''],\n testsplitterre: ['#id_testsplitterre', 'value', '',\n function (splitter) {\n return splitter.replace('\\n', '\\\\n');\n }],\n allowmultiplestdins: ['#id_allowmultiplestdins', 'checked', '',\n function (value) {\n return value === '1' ? true : false;\n }],\n grader: ['#id_grader', 'value', 'EqualityGrader'],\n resultcolumns: ['#id_resultcolumns', 'value', ''],\n language: ['#id_language', 'value', ''],\n acelang: ['#id_acelang', 'value', ''],\n uiplugin: ['#id_uiplugin', 'value', 'ace']\n };\n\n /**\n * Set up the author edit form UI plugins and event handlers.\n * The template parameters and Ace language are passed to each\n * text area from PHP by setting its data-params and\n * data-lang attributes.\n */\n function initEditForm() {\n var typeCombo = $('#id_coderunnertype'),\n prototypeDisplay = $('#id_isprototype'),\n template = $('#id_template'),\n evaluatePerStudent = $('#id_templateparamsevalpertry'),\n globalextra = $('#id_globalextra'),\n prototypeextra = $('#id_prototypeextra'),\n useace = $('#id_useace'),\n language = $('#id_language'),\n acelang = $('#id_acelang'),\n customise = $('#id_customise'),\n isCombinator = $('#id_iscombinatortemplate'),\n testSplitterRe = $('#id_testsplitterre'),\n allowMultipleStdins = $('#id_allowmultiplestdins'),\n customisationFieldSet = $('#id_customisationheader'),\n advancedCustomisation = $('#id_advancedcustomisationheader'),\n isCustomised = customise.prop('checked'),\n prototypeType = $('#id_prototypetype'),\n preloadHdr = $('#id_answerpreloadhdr'),\n courseId = $('input[name=\"courseid\"]').prop('value'),\n questiontypeHelpDiv = $('#qtype-help'),\n precheck = $('select#id_precheck'),\n testtypedivs = $('div.testtype'),\n testsection = $('#id_testcasehdr'),\n brokenQuestion = $('#id_broken_question'),\n badQuestionLoad = $('#id_bad_question_load'),\n uiplugin = $('#id_uiplugin'),\n uiparameters = $('#id_uiparameters');\n\n /**\n * Set up the UI controller for a given textarea (one of template,\n * answer or answerpreload).\n * We don't attempt to process changes in template parameters,\n * as these need to be merged with those of the prototype. But we do handle\n * changes in the language.\n * @param {string} taId The ID of the textarea element.\n * @param {string} uiname The name of the UI controller (may be empty or none).\n */\n function setUi(taId, uiname) {\n var ta = $(document.getElementById(taId)), // The jquery text area element(s).\n lang,\n paramsJson = ta.attr('data-params'), // Ui params set by PHP.\n params = {},\n uiWrapper;\n\n // Set data attributes in the text area for UI components that need\n // global extra or testcase data (e.g. gapfiller UI).\n ta.attr('data-prototypeextra', prototypeextra.val());\n ta.attr('data-globalextra', globalextra.val());\n ta.attr('data-test0', $('#id_testcode_0').val());\n try {\n params = JSON.parse(paramsJson);\n } catch(err) {}\n uiname = uiname.toLowerCase();\n if (uiname === 'none') {\n uiname = '';\n }\n\n if (taId == 'id_templateparams' || taId == 'id_uiparameters') {\n lang = ''; // These fields may be twigged, so can't be parsed by Ace.\n } else {\n lang = language.prop('value');\n if (taId !== \"id_template\" && acelang.prop('value')) {\n lang = preferredAceLang(acelang.prop('value'));\n }\n }\n\n uiWrapper = ta[0].current_ui_wrapper; // Currently-active UI wrapper on this ta.\n\n ta.attr('data-lang', lang);\n\n if (!uiWrapper) {\n uiWrapper = new ui.InterfaceWrapper(uiname, taId);\n } else {\n // Wrapper has already been set up - just reload the reqd UI.\n params.lang = lang;\n uiWrapper.loadUi(uiname, params);\n }\n\n }\n\n /**\n * Set the correct Ui controller on both the sample answer and the answer preload.\n * The sample answer and answer preload have the data-params attribute which contains\n * the UI params in a JSON from the current question merged with the prototype.\n * Both of them are identical and are changed simultaneously; only checking\n * answer as state is identical.\n * As a special case, we don't turn on the Ui controller in the answer\n * and answer preload fields when using Html-Ui and the ui-parameter\n * enable_in_editor is false.\n *\n */\n function setUis() {\n let uiname = uiplugin.val();\n let answer = $('#id_answer');\n let enableUi = true;\n if (uiname === 'html' && answer.attr('data-params') !== '') {\n try {\n let answerparams = JSON.parse(answer.attr('data-params'));\n if (answerparams.enable_in_editor === false) {\n enableUi = false;\n }\n } catch (error) {\n alert(\"Invalid UI parameters.\");\n }\n }\n if (enableUi) {\n setUi('id_answer', uiname);\n setUi('id_answerpreload', uiname);\n }\n }\n\n /**\n * Display or Hide all customisation parts of the form.\n * @param {bool} isVisible True to show, false to hide.\n */\n function setCustomisationVisibility(isVisible) {\n var display = isVisible ? 'block' : 'none';\n customisationFieldSet.css('display', display);\n advancedCustomisation.css('display', display);\n if (isVisible && useace.prop('checked')) {\n setUi('id_template', 'ace');\n }\n }\n\n\n /**\n * Turn on or off the Ace editor in the template and uiparameters fields\n * so we can reload the textareas with JavaScript.\n * Ignore if UseAce is unchecked.\n * @param {bool} stateOn True to stop Ace, false to restart it.\n */\n function enableAceInCustomisedFields(stateOn) {\n var taIds = ['id_template', 'id_uiparameters'];\n var uiWrapper, ta;\n if (useace.prop('checked')) {\n for(var i = 0; i < taIds.length; i++) {\n ta = $(document.getElementById(taIds[i]));\n uiWrapper = ta.data('current-ui-wrapper');\n if (uiWrapper && stateOn) {\n uiWrapper.restart();\n } else if (uiWrapper && !stateOn) {\n uiWrapper.stop();\n }\n }\n }\n }\n\n\n /**\n * After loading the form with new question type data we have to\n * enable or disable both the testsplitterre and the allow multiple\n * stdins field. These are subsequently enabled/disabled via event handlers\n * set up by code in edit_coderunner_form.php (q.v.) but those event\n * handlers do not handle the freshly downloaded state.\n */\n function enableTemplateSupportFields() {\n var isCombinatorEnabled = isCombinator.prop('checked');\n\n testSplitterRe.prop('disabled', !isCombinatorEnabled);\n allowMultipleStdins.prop('disabled', !isCombinatorEnabled);\n }\n\n /**\n * Copy fields from the AJAX \"get question type\" response into the form.\n * @param {string} newType the newly selected question type.\n * @param {object} response The AJAX resopnse.\n */\n function copyFieldsFromQuestionType(newType, response) {\n var formspecifier, attrval, filter;\n\n enableAceInCustomisedFields(false);\n for (var key in JSON_TO_FORM_MAP) {\n formspecifier = JSON_TO_FORM_MAP[key];\n attrval = response[key] ? response[key] : formspecifier[2];\n if (formspecifier.length > 3) {\n filter = formspecifier[3];\n attrval = filter(attrval);\n }\n $(formspecifier[0]).prop(formspecifier[1], attrval);\n }\n\n customise.prop('checked', false);\n str.get_string('coderunner_question_type', 'qtype_coderunner').then(function (s) {\n questiontypeHelpDiv.html(detailsHtml(newType, s, response.questiontext));\n });\n\n setCustomisationVisibility(false);\n enableTemplateSupportFields();\n }\n\n /**\n * A JSON request for a question type returned a 'failure' response - probably a\n * missing question type. Report the error with an alert, and replace\n * the template contents with an error message in case the user\n * saves the question and later wonders why it breaks.\n * Returns the JSON error object for further use.\n * @param {string} questionType The CodeRunner (sub) question type.\n * @param {string} error The error message as JSON encoded error => langstring,\n * extra => components string.\n * @return {JSON object} The JSON error object for further parsing.\n */\n function reportError(questionType, error) {\n const errorObject = JSON.parse(error);\n str.get_string('prototype_error', 'qtype_coderunner').then(function(s) {\n str.get_string(errorObject.alert, 'qtype_coderunner', questionType).then(function(str) {\n langStringAlert('prototype_load_failure', str);\n let errorMessage = s + \"\\n\";\n errorMessage += str + '\\n';\n errorMessage += \"CourseId: \" + courseId + \", qtype: \" + questionType;\n template.prop('value', errorMessage);\n });\n });\n return errorObject;\n }\n\n /**\n * Local function to return the HTML to display in the\n * question type details section of the form.\n * @param {string} title The type of the question being described.\n * @param {string} coderunner_descr The language string to introduce\n * the detail.\n * @param {html} html The HTML description of the question type, namely\n * the question text from its prototype.\n * @return {html} The composite HTML describing the question type.\n */\n function detailsHtml(title, coderunner_descr, html) {\n\n var resultHtml = '

';\n resultHtml += coderunner_descr;\n resultHtml += title + '

\\n' + html;\n return resultHtml;\n\n }\n\n /**\n * Raise an alert with the given language string and possible additional\n * extra text.\n * @param {string} key The language string to put in the Alert.\n * @param {string} extra Extra text to append.\n */\n function langStringAlert(key, extra) {\n if (window.hasOwnProperty('behattesting') && window.behattesting) {\n return;\n }\n str.get_string(key, 'qtype_coderunner').then(function(s) {\n var message = s.replace(/\\n/g, \" \");\n if (extra) {\n message += '\\n' + extra;\n }\n alert(message);\n });\n }\n\n /**\n * Get the \"preferred language\" from the AceLang string supplied.\n * @param {string} acelang The AceLang string.\n * For multilanguage questions, this is either the default (i.e.,\n * the language with a '*' suffix), or the first language. Otherwise\n * it is simply the entire AceLang string.\n * @return {string} The language to pass to Ace for syntax highlighting.\n */\n function preferredAceLang(acelang) {\n var langs, i;\n if (acelang.indexOf(',') < 0) {\n return acelang;\n } else {\n langs = acelang.split(',');\n for (i = 0; i < langs.length; i++) {\n if (langs[i].endsWith('*')) {\n return langs[i].substr(0, langs[i].length - 1);\n }\n }\n return langs.length > 0 ? langs[0] : '';\n }\n }\n\n /**\n * Load the various customisation fields into the form from the\n * CodeRunner question type currently selected by the combobox.\n * Looks at the preexisting type of the selected field.\n */\n function loadCustomisationFields() {\n let newType = typeCombo.children('option:selected').text();\n\n if (newType !== '' && newType !== 'Undefined') {\n // Prevent 'Undefined' ever being reselected.\n typeCombo.children('option:first-child').prop('disabled', 'disabled');\n\n // Load question type with ajax.\n $.getJSON(M.cfg.wwwroot + '/question/type/coderunner/ajax.php',\n {\n qtype: newType,\n courseid: courseId,\n sesskey: M.cfg.sesskey\n },\n function (outcome) {\n // Clean all warnings regardless.\n $('#id_qtype_coderunner_warning_div').empty();\n if (outcome.success) {\n copyFieldsFromQuestionType(newType, outcome);\n setUis();\n loadUiParametersDescription();\n // Success, so remove the errors and change the current Qtype.\n currentQtype = newType;\n $('#id_qtype_coderunner_error_div').empty();\n }\n else {\n const errorObject = reportError(newType, outcome.error);\n // Checks to see if there has been a change in type from last saved.\n // If so, put up a load error and keep type unchanged.\n if (currentQtype !== newType && errorObject.error === 'duplicateprototype') {\n showLoadTypeError(currentQtype, errorObject, newType);\n $(\"#id_coderunnertype\").val(currentQtype);\n }\n }\n }\n ).fail(function () {\n // AJAX failed. We're dead, Fred. The attempt to get the\n // language translation for the error message will likely\n // fail too, so use English for a start.\n langStringAlert('error_loading_prototype');\n template.prop('value', '*** AJAX ERROR. DON\\'T SAVE THIS! ***');\n str.get_string('ajax_error', 'qtype_coderunner').then(function(s) {\n template.prop('value', s); // Translates into current language (if it works).\n });\n });\n }\n }\n\n /**\n * Build an HTML table describing all the UI parameters.\n * @param {object} uiParamInfo The object describing the parameters\n * for a particular UI.\n * @return {string} An HTML table describing each UI parameter.\n */\n function UiParameterDescriptionTable(uiParamInfo) {\n var html = '
\\n',\n hdrs = uiParamInfo.columnheaders, param, i;\n html += \"\\n\";\n for (i = 0; i < uiParamInfo.uiparamstable.length; i++) {\n param = uiParamInfo.uiparamstable[i];\n html += \"\\n\";\n }\n html += \"
\" + hdrs[0] + \"\" + hdrs[1] + \"\" + hdrs[2] + \"
\" + param[0] + \"\" + param[1] + \"\" + param[2] + \"
\\n\";\n return html;\n }\n\n\n\n /**\n * Plug the UI info received by getJSON into the author form.\n * @param {object} uiInfo The response data from the getJSON call\n * @returns {undefined}\n */\n function updateUiParamsDescription(uiInfo) {\n let currentuiparameters = uiparameters.val();\n let paramDescriptionDiv = $('.ui_parameters_descr');\n let hideUiParamsDescription = function() {\n uiparameters.val(''); // Remove stray white space.\n $('#fgroup_id_uiparametergroup').hide();\n };\n paramDescriptionDiv.empty();\n if (uiInfo === null || (uiInfo.uiparamstable.length == 0 && currentuiparameters.trim() === '')) {\n hideUiParamsDescription();\n } else {\n paramDescriptionDiv.append(uiInfo.header);\n let showhidebutton = $('');\n if (uiInfo.uiparamstable.length != 0) {\n paramDescriptionDiv.append(showhidebutton);\n let table = $(UiParameterDescriptionTable(uiInfo));\n paramDescriptionDiv.append(table);\n table.hide();\n showhidebutton.click(function () {\n if (showhidebutton.html() == uiInfo.showdetails) {\n table.show();\n showhidebutton.html(uiInfo.hidedetails);\n } else {\n table.hide();\n showhidebutton.html(uiInfo.showdetails);\n }\n });\n }\n $('#fgroup_id_uiparametergroup').show();\n if (useace.prop('checked')) {\n setUi('id_uiparameters', 'ace');\n }\n }\n }\n\n /**\n * Load the UI parameter description field by Ajax initially or\n * when the UI plugin is changed.\n */\n function loadUiParametersDescription() {\n let newUi = uiplugin.children('option:selected').text();\n if (newUi === '' || newUi === 'none') {\n updateUiParamsDescription(null);\n } else {\n $.getJSON(M.cfg.wwwroot + '/question/type/coderunner/ajax.php',\n {\n uiplugin: newUi,\n courseid: courseId,\n sesskey: M.cfg.sesskey\n },\n updateUiParamsDescription\n ).fail(function () {\n // AJAX failed.\n langStringAlert('error_loading_ui_descr', `UI: ${newUi}`);\n });\n }\n }\n\n /**\n * Show/hide all testtype divs in the testcases according to the\n * 'Precheck' selector.\n */\n function set_testtype_visibilities() {\n if (precheck.val() === '3') { // Show only for case of 'Selected'.\n testtypedivs.show();\n } else {\n testtypedivs.hide();\n }\n }\n\n /**\n * Check that the Ace language is correctly set for the answer and\n * answer preload fields.\n */\n function check_ace_lang() {\n if (uiplugin.val() === 'ace'){\n setUis();\n }\n }\n\n /**\n * Check that the Ace language is correctly set for the template,\n * if template_uses_ace is checked.\n */\n function check_template_lang() {\n if (useace.prop('checked')) {\n setUi('id_template', 'ace');\n }\n }\n\n /**\n * If the brokenquestionmessage hidden element is not empty, insert the\n * given message as an error at the top of the question.\n * itself to go back to the last valid value.\n */\n function checkForBrokenQuestion() {\n let brokenQuestionMessage = brokenQuestion.prop('value'),\n messagePara = null;\n if (brokenQuestionMessage !== '') {\n messagePara = $('

' + brokenQuestion.prop('value') + '

');\n $('#id_qtype_coderunner_error_div').append(messagePara);\n }\n }\n\n /**\n * Shows the load type error of the selected type if the selected type is\n * faulty.\n * @param {string} currentType The current type with its errors.\n * @param {JSON Object} errorObject The JSON object containing a list of all the errors.\n * @param {string} newType The new type string which it failed to load.\n */\n function showLoadTypeError(currentType, errorObject, newType) {\n str.get_string('loadprototypeerror', 'qtype_coderunner',\n { oldtype : currentType, crtype : newType, outputstring : errorObject.extras })\n .then(function(str) {\n $('#id_qtype_coderunner_warning_div').append($('

' + str + '

'));\n });\n }\n\n /*************************************************************\n *\n * Body of initEditFormWhenReady starts here.\n *\n *************************************************************/\n\n if (prototypeType.prop('value') != 0) {\n // Display the prototype warning if it's a prototype and hide testboxes.\n testsection.css('display', 'none');\n prototypeDisplay.removeAttr('hidden');\n if (prototypeType.prop('value') == 1) {\n // Editing a built-in question type: Dangerous!\n str.get_string('proceed_at_own_risk', 'qtype_coderunner').then(function(s) {\n alert(s);\n });\n prototypeType.prop('disabled', true);\n customise.prop('disabled', true);\n }\n }\n\n checkForBrokenQuestion();\n badQuestionLoad.prop('hidden'); // Until we check it once.\n // Keep track of the current prototype loaded.\n currentQtype = typeCombo.children('option:selected').text();\n\n setCustomisationVisibility(isCustomised);\n if (!isCustomised) {\n // Not customised so have to load fields from prototype.\n loadCustomisationFields(); // setUis is called when this completes.\n } else {\n setUis(); // Set up UI controllers on answer and answerpreload.\n str.get_string('info_unavailable', 'qtype_coderunner').then(function(s) {\n questiontypeHelpDiv.html(\"

\" + s + \"

\");\n });\n }\n\n set_testtype_visibilities();\n\n if (useace.prop('checked')) {\n setUi('id_templateparams', 'ace');\n setUi('id_uiparameters', 'ace');\n }\n\n loadUiParametersDescription();\n\n // Set up event Handlers.\n\n customise.on('change', function() {\n let isCustomised = customise.prop('checked');\n if (isCustomised) {\n // Customisation is being turned on.\n setCustomisationVisibility(true);\n } else { // Customisation being turned off.\n str.get_string('confirm_proceed', 'qtype_coderunner').then(function(s) {\n if (window.confirm(s)) {\n setCustomisationVisibility(false);\n } else {\n customise.prop('checked', true);\n }\n });\n }\n });\n\n acelang.on('change', check_ace_lang);\n language.on('change', function() {\n check_template_lang();\n check_ace_lang();\n });\n\n typeCombo.on('change', function() {\n if (customise.prop('checked')) {\n // Author has customised the question. Ask if they want to reload inherited stuff.\n str.get_string('question_type_changed', 'qtype_coderunner').then(function (s) {\n if (window.confirm(s)) {\n loadCustomisationFields();\n }\n });\n } else {\n loadCustomisationFields();\n }\n });\n\n useace.on('change', function() {\n var isTurningOn = useace.prop('checked');\n if (isTurningOn) {\n setUi('id_template', 'ace');\n setUi('id_templateparams', 'ace');\n setUi('id_uiparameters', 'ace');\n } else {\n setUi('id_template', '');\n setUi('id_templateparams', '');\n setUi('id_uiparameters', '');\n }\n });\n\n evaluatePerStudent.on('change', function() {\n if (evaluatePerStudent.is(':checked')) {\n langStringAlert('templateparamsusingsandbox');\n }\n });\n\n uiplugin.on('change', function () {\n setUis();\n loadUiParametersDescription();\n });\n\n precheck.on('change', set_testtype_visibilities);\n\n // Displays and hides the reason for the question type to be disabled.\n // Also hides/shows the test cases section if prototype/not prototype.\n prototypeType.on('change', function () {\n if (prototypeType.prop('value') == '0') {\n testsection.css('display', 'block');\n prototypeDisplay.attr('hidden', '1');\n } else {\n testsection.css('display', 'none');\n prototypeDisplay.removeAttr('hidden');\n }\n });\n\n // In order to initialise the Ui plugin when the answer preload section is\n // expanded, we monitor attribute mutations in the Answer Preload\n // header.\n var observer = new MutationObserver( function () {\n setUis();\n });\n observer.observe(preloadHdr.get(0), {'attributes': true, 'attributeFilter':['class']});\n\n // Setup click handler for the buttons that allow users to replace the\n // expected output with the output got from testing the answer program.\n $('button.replaceexpectedwithgot').click(function() {\n var gotPre = $(this).prev('pre[id^=\"id_got_\"]');\n var testCaseId = gotPre.attr('id').replace('id_got_', '');\n $('#id_expected_' + testCaseId).val(gotPre.text());\n $('#id_fail_expected_' + testCaseId).html(gotPre.text());\n $('.failrow_' + testCaseId).addClass('fixed'); // Fixed row.\n $(this).prop('disabled', true);\n });\n\n // On reloading the page, enable the typeCombo so that its value is POSTed.\n $('.btn-primary').click(function() {\n typeCombo.prop('disabled', false);\n });\n }\n\n return {initEditForm: initEditForm};\n});"],"names":["define","$","ui","str","currentQtype","JSON_TO_FORM_MAP","template","iscombinatortemplate","value","cputimelimitsecs","memlimitmb","sandbox","sandboxparams","testsplitterre","splitter","replace","allowmultiplestdins","grader","resultcolumns","language","acelang","uiplugin","initEditForm","typeCombo","prototypeDisplay","evaluatePerStudent","globalextra","prototypeextra","useace","customise","isCombinator","testSplitterRe","allowMultipleStdins","customisationFieldSet","advancedCustomisation","isCustomised","prop","prototypeType","preloadHdr","courseId","questiontypeHelpDiv","precheck","testtypedivs","testsection","brokenQuestion","badQuestionLoad","uiparameters","setUi","taId","uiname","lang","uiWrapper","ta","document","getElementById","paramsJson","attr","params","val","JSON","parse","err","toLowerCase","langs","i","indexOf","split","length","endsWith","substr","preferredAceLang","current_ui_wrapper","loadUi","InterfaceWrapper","setUis","answer","enableUi","enable_in_editor","error","alert","setCustomisationVisibility","isVisible","display","css","copyFieldsFromQuestionType","newType","response","formspecifier","attrval","isCombinatorEnabled","key","stateOn","taIds","data","restart","stop","enableAceInCustomisedFields","filter","get_string","then","s","title","coderunner_descr","html","resultHtml","questiontext","langStringAlert","extra","window","hasOwnProperty","behattesting","message","loadCustomisationFields","children","text","getJSON","M","cfg","wwwroot","qtype","courseid","sesskey","outcome","empty","success","loadUiParametersDescription","errorObject","questionType","errorMessage","reportError","currentType","oldtype","crtype","outputstring","extras","append","showLoadTypeError","fail","updateUiParamsDescription","uiInfo","currentuiparameters","paramDescriptionDiv","uiparamstable","trim","hide","header","showhidebutton","showdetails","table","uiParamInfo","param","hdrs","columnheaders","UiParameterDescriptionTable","click","show","hidedetails","newUi","set_testtype_visibilities","check_ace_lang","removeAttr","messagePara","checkForBrokenQuestion","on","confirm","is","MutationObserver","observe","get","gotPre","this","prev","testCaseId","addClass"],"mappings":";;;;;;;AAyBAA,qCAAO,CAAC,SAAU,wCAAyC,aAAa,SAASC,EAAGC,GAAIC,SAGhFC,aAAe,OASfC,iBAAmB,CACnBC,SAAqB,CAAC,eAAgB,QAAS,IAC/CC,qBAAqB,CAAC,2BAA4B,UAAW,GACrC,SAAUC,aACW,MAAVA,QAEnCC,iBAAqB,CAAC,uBAAwB,QAAS,IACvDC,WAAqB,CAAC,iBAAkB,QAAS,IACjDC,QAAqB,CAAC,cAAe,QAAS,WAC9CC,cAAqB,CAAC,oBAAqB,QAAS,IACpDC,eAAqB,CAAC,qBAAsB,QAAS,GAC7B,SAAUC,iBACCA,SAASC,QAAQ,KAAM,SAE1DC,oBAAqB,CAAC,0BAA2B,UAAW,GACpC,SAAUR,aACW,MAAVA,QAEnCS,OAAqB,CAAC,aAAc,QAAS,kBAC7CC,cAAqB,CAAC,oBAAqB,QAAS,IACpDC,SAAqB,CAAC,eAAgB,QAAS,IAC/CC,QAAqB,CAAC,cAAe,QAAS,IAC9CC,SAAqB,CAAC,eAAgB,QAAS,cAonB5C,CAACC,4BA1mBAC,UAAYtB,EAAE,sBACduB,iBAAmBvB,EAAE,mBACrBK,SAAWL,EAAE,gBACbwB,mBAAqBxB,EAAE,gCACvByB,YAAczB,EAAE,mBAChB0B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vD,QAC3CjH,EAAE,qBAAuB2K,YAAYrE,KAAKkE,OAAOvD,QACjDjH,EAAE,YAAc2K,YAAYC,SAAS,SACrC5K,EAAEyK,MAAMtI,KAAK,YAAY,MAI7BnC,EAAE,gBAAgByJ,OAAM,WACpBnI,UAAUa,KAAK,YAAY"} \ No newline at end of file +{"version":3,"file":"authorform.min.js","sources":["../src/authorform.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/* jshint esversion: 6 */\n\n/**\n * JavaScript for handling UI actions in the question authoring form.\n *\n * @module qtype_coderunner/authorform\n * @copyright Richard Lobb, 2015, The University of Canterbury\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery', 'qtype_coderunner/userinterfacewrapper', 'core/str'], function($, ui, str) {\n\n // We need this to keep track of the current question type.\n let currentQtype = \"\";\n\n // Define a mapping from the fields of the JSON object returned by an AJAX\n // 'get question type' request to the form elements. Only fields that\n // belong to the question type should appear here. Keys are JSON field\n // names, values are a 3- or 4-element array of: a jQuery form element selector;\n // the element property to be set; a default value if the JSON field is\n // empty and an optional filter function to apply to the field value before\n // setting the property with it.\n var JSON_TO_FORM_MAP = {\n template: ['#id_template', 'value', ''],\n iscombinatortemplate:['#id_iscombinatortemplate', 'checked', '',\n function (value) {\n return value === '1' ? true : false;\n }], // Need nice clean boolean for 'checked' attribute.\n cputimelimitsecs: ['#id_cputimelimitsecs', 'value', ''],\n memlimitmb: ['#id_memlimitmb', 'value', ''],\n sandbox: ['#id_sandbox', 'value', 'DEFAULT'],\n sandboxparams: ['#id_sandboxparams', 'value', ''],\n testsplitterre: ['#id_testsplitterre', 'value', '',\n function (splitter) {\n return splitter.replace('\\n', '\\\\n');\n }],\n allowmultiplestdins: ['#id_allowmultiplestdins', 'checked', '',\n function (value) {\n return value === '1' ? true : false;\n }],\n grader: ['#id_grader', 'value', 'EqualityGrader'],\n resultcolumns: ['#id_resultcolumns', 'value', ''],\n language: ['#id_language', 'value', ''],\n acelang: ['#id_acelang', 'value', ''],\n uiplugin: ['#id_uiplugin', 'value', 'ace']\n };\n\n /**\n * Set up the author edit form UI plugins and event handlers.\n * The template parameters and Ace language are passed to each\n * text area from PHP by setting its data-params and\n * data-lang attributes.\n */\n function initEditForm() {\n var typeCombo = $('#id_coderunnertype'),\n prototypeDisplay = $('#id_isprototype'),\n template = $('#id_template'),\n evaluatePerStudent = $('#id_templateparamsevalpertry'),\n globalextra = $('#id_globalextra'),\n prototypeextra = $('#id_prototypeextra'),\n useace = $('#id_useace'),\n language = $('#id_language'),\n acelang = $('#id_acelang'),\n customise = $('#id_customise'),\n isCombinator = $('#id_iscombinatortemplate'),\n testSplitterRe = $('#id_testsplitterre'),\n allowMultipleStdins = $('#id_allowmultiplestdins'),\n customisationFieldSet = $('#id_customisationheader'),\n advancedCustomisation = $('#id_advancedcustomisationheader'),\n isCustomised = customise.prop('checked'),\n prototypeType = $('#id_prototypetype'),\n preloadHdr = $('#id_answerpreloadhdr'),\n courseId = $('input[name=\"courseid\"]').prop('value'),\n questiontypeHelpDiv = $('#qtype-help'),\n precheck = $('select#id_precheck'),\n testtypedivs = $('div.testtype'),\n testsection = $('#id_testcasehdr'),\n brokenQuestion = $('#id_broken_question'),\n badQuestionLoad = $('#id_bad_question_load'),\n uiplugin = $('#id_uiplugin'),\n uiparameters = $('#id_uiparameters');\n\n /**\n * Set up the UI controller for a given textarea (one of template,\n * answer or answerpreload).\n * We don't attempt to process changes in template parameters,\n * as these need to be merged with those of the prototype. But we do handle\n * changes in the language.\n * @param {string} taId The ID of the textarea element.\n * @param {string} uiname The name of the UI controller (may be empty or none).\n */\n function setUi(taId, uiname) {\n var ta = $(document.getElementById(taId)), // The jquery text area element(s).\n lang,\n paramsJson = ta.attr('data-params'), // Ui params set by PHP.\n params = {},\n uiWrapper;\n\n // Set data attributes in the text area for UI components that need\n // global extra or testcase data (e.g. gapfiller UI).\n ta.attr('data-prototypeextra', prototypeextra.val());\n ta.attr('data-globalextra', globalextra.val());\n ta.attr('data-test0', $('#id_testcode_0').val());\n try {\n params = JSON.parse(paramsJson);\n } catch(err) {}\n uiname = uiname.toLowerCase();\n if (uiname === 'none') {\n uiname = '';\n }\n\n if (taId == 'id_templateparams' || taId == 'id_uiparameters') {\n lang = ''; // These fields may be twigged, so can't be parsed by Ace.\n } else {\n lang = language.prop('value');\n if (taId !== \"id_template\" && acelang.prop('value')) {\n lang = preferredAceLang(acelang.prop('value'));\n }\n }\n\n uiWrapper = ta[0].current_ui_wrapper; // Currently-active UI wrapper on this ta.\n\n ta.attr('data-lang', lang);\n\n if (!uiWrapper) {\n uiWrapper = new ui.InterfaceWrapper(uiname, taId);\n } else {\n // Wrapper has already been set up - just reload the reqd UI.\n params.lang = lang;\n uiWrapper.loadUi(uiname, params);\n }\n\n }\n\n /**\n * Set the correct Ui controller on both the sample answer and the answer preload.\n * The sample answer and answer preload have the data-params attribute which contains\n * the UI params in a JSON from the current question merged with the prototype.\n * Both of them are identical and are changed simultaneously; only checking\n * answer as state is identical.\n * As a special case, we don't turn on the Ui controller in the answer\n * and answer preload fields when using Html-Ui and the ui-parameter\n * enable_in_editor is false.\n *\n */\n function setUis() {\n let uiname = uiplugin.val();\n let answer = $('#id_answer');\n let enableUi = true;\n if (uiname === 'html' && answer.attr('data-params') !== '') {\n try {\n let answerparams = JSON.parse(answer.attr('data-params'));\n if (answerparams.enable_in_editor === false) {\n enableUi = false;\n }\n } catch (error) {\n alert(\"Invalid UI parameters.\");\n }\n }\n if (enableUi) {\n setUi('id_answer', uiname);\n setUi('id_answerpreload', uiname);\n }\n }\n\n /**\n * Display or Hide all customisation parts of the form.\n * @param {bool} isVisible True to show, false to hide.\n */\n function setCustomisationVisibility(isVisible) {\n var display = isVisible ? 'block' : 'none';\n customisationFieldSet.css('display', display);\n advancedCustomisation.css('display', display);\n if (isVisible && useace.prop('checked')) {\n setUi('id_template', 'ace');\n }\n }\n\n\n /**\n * Turn on or off the Ace editor in the template and uiparameters fields\n * so we can reload the textareas with JavaScript.\n * Ignore if UseAce is unchecked.\n * @param {bool} stateOn True to stop Ace, false to restart it.\n */\n function enableAceInCustomisedFields(stateOn) {\n var taIds = ['id_template', 'id_uiparameters'];\n var uiWrapper, ta;\n if (useace.prop('checked')) {\n for(var i = 0; i < taIds.length; i++) {\n ta = $(document.getElementById(taIds[i]));\n uiWrapper = ta.get(0).current_ui_wrapper;\n if (uiWrapper && stateOn) {\n uiWrapper.restart();\n } else if (uiWrapper && !stateOn) {\n uiWrapper.stop();\n }\n }\n }\n }\n\n\n /**\n * After loading the form with new question type data we have to\n * enable or disable both the testsplitterre and the allow multiple\n * stdins field. These are subsequently enabled/disabled via event handlers\n * set up by code in edit_coderunner_form.php (q.v.) but those event\n * handlers do not handle the freshly downloaded state.\n */\n function enableTemplateSupportFields() {\n var isCombinatorEnabled = isCombinator.prop('checked');\n\n testSplitterRe.prop('disabled', !isCombinatorEnabled);\n allowMultipleStdins.prop('disabled', !isCombinatorEnabled);\n }\n\n /**\n * Copy fields from the AJAX \"get question type\" response into the form.\n * @param {string} newType the newly selected question type.\n * @param {object} response The AJAX resopnse.\n */\n function copyFieldsFromQuestionType(newType, response) {\n var formspecifier, attrval, filter;\n\n enableAceInCustomisedFields(false);\n for (var key in JSON_TO_FORM_MAP) {\n formspecifier = JSON_TO_FORM_MAP[key];\n attrval = response[key] ? response[key] : formspecifier[2];\n if (formspecifier.length > 3) {\n filter = formspecifier[3];\n attrval = filter(attrval);\n }\n $(formspecifier[0]).prop(formspecifier[1], attrval);\n }\n\n customise.prop('checked', false);\n str.get_string('coderunner_question_type', 'qtype_coderunner').then(function (s) {\n questiontypeHelpDiv.html(detailsHtml(newType, s, response.questiontext));\n });\n\n setCustomisationVisibility(false);\n enableTemplateSupportFields();\n }\n\n /**\n * A JSON request for a question type returned a 'failure' response - probably a\n * missing question type. Report the error with an alert, and replace\n * the template contents with an error message in case the user\n * saves the question and later wonders why it breaks.\n * Returns the JSON error object for further use.\n * @param {string} questionType The CodeRunner (sub) question type.\n * @param {string} error The error message as JSON encoded error => langstring,\n * extra => components string.\n * @return {JSON object} The JSON error object for further parsing.\n */\n function reportError(questionType, error) {\n const errorObject = JSON.parse(error);\n str.get_string('prototype_error', 'qtype_coderunner').then(function(s) {\n str.get_string(errorObject.alert, 'qtype_coderunner', questionType).then(function(str) {\n langStringAlert('prototype_load_failure', str);\n let errorMessage = s + \"\\n\";\n errorMessage += str + '\\n';\n errorMessage += \"CourseId: \" + courseId + \", qtype: \" + questionType;\n template.prop('value', errorMessage);\n });\n });\n return errorObject;\n }\n\n /**\n * Local function to return the HTML to display in the\n * question type details section of the form.\n * @param {string} title The type of the question being described.\n * @param {string} coderunner_descr The language string to introduce\n * the detail.\n * @param {html} html The HTML description of the question type, namely\n * the question text from its prototype.\n * @return {html} The composite HTML describing the question type.\n */\n function detailsHtml(title, coderunner_descr, html) {\n\n var resultHtml = '

';\n resultHtml += coderunner_descr;\n resultHtml += title + '

\\n' + html;\n return resultHtml;\n\n }\n\n /**\n * Raise an alert with the given language string and possible additional\n * extra text.\n * @param {string} key The language string to put in the Alert.\n * @param {string} extra Extra text to append.\n */\n function langStringAlert(key, extra) {\n if (window.hasOwnProperty('behattesting') && window.behattesting) {\n return;\n }\n str.get_string(key, 'qtype_coderunner').then(function(s) {\n var message = s.replace(/\\n/g, \" \");\n if (extra) {\n message += '\\n' + extra;\n }\n alert(message);\n });\n }\n\n /**\n * Get the \"preferred language\" from the AceLang string supplied.\n * @param {string} acelang The AceLang string.\n * For multilanguage questions, this is either the default (i.e.,\n * the language with a '*' suffix), or the first language. Otherwise\n * it is simply the entire AceLang string.\n * @return {string} The language to pass to Ace for syntax highlighting.\n */\n function preferredAceLang(acelang) {\n var langs, i;\n if (acelang.indexOf(',') < 0) {\n return acelang;\n } else {\n langs = acelang.split(',');\n for (i = 0; i < langs.length; i++) {\n if (langs[i].endsWith('*')) {\n return langs[i].substr(0, langs[i].length - 1);\n }\n }\n return langs.length > 0 ? langs[0] : '';\n }\n }\n\n /**\n * Load the various customisation fields into the form from the\n * CodeRunner question type currently selected by the combobox.\n * Looks at the preexisting type of the selected field.\n */\n function loadCustomisationFields() {\n let newType = typeCombo.children('option:selected').text();\n\n if (newType !== '' && newType !== 'Undefined') {\n // Prevent 'Undefined' ever being reselected.\n typeCombo.children('option:first-child').prop('disabled', 'disabled');\n\n // Load question type with ajax.\n $.getJSON(M.cfg.wwwroot + '/question/type/coderunner/ajax.php',\n {\n qtype: newType,\n courseid: courseId,\n sesskey: M.cfg.sesskey\n },\n function (outcome) {\n // Clean all warnings regardless.\n $('#id_qtype_coderunner_warning_div').empty();\n if (outcome.success) {\n copyFieldsFromQuestionType(newType, outcome);\n setUis();\n loadUiParametersDescription();\n // Success, so remove the errors and change the current Qtype.\n currentQtype = newType;\n $('#id_qtype_coderunner_error_div').empty();\n }\n else {\n const errorObject = reportError(newType, outcome.error);\n // Checks to see if there has been a change in type from last saved.\n // If so, put up a load error and keep type unchanged.\n if (currentQtype !== newType && errorObject.error === 'duplicateprototype') {\n showLoadTypeError(currentQtype, errorObject, newType);\n $(\"#id_coderunnertype\").val(currentQtype);\n }\n }\n }\n ).fail(function () {\n // AJAX failed. We're dead, Fred. The attempt to get the\n // language translation for the error message will likely\n // fail too, so use English for a start.\n langStringAlert('error_loading_prototype');\n template.prop('value', '*** AJAX ERROR. DON\\'T SAVE THIS! ***');\n str.get_string('ajax_error', 'qtype_coderunner').then(function(s) {\n template.prop('value', s); // Translates into current language (if it works).\n });\n });\n }\n }\n\n /**\n * Build an HTML table describing all the UI parameters.\n * @param {object} uiParamInfo The object describing the parameters\n * for a particular UI.\n * @return {string} An HTML table describing each UI parameter.\n */\n function UiParameterDescriptionTable(uiParamInfo) {\n var html = '
\\n',\n hdrs = uiParamInfo.columnheaders, param, i;\n html += \"\\n\";\n for (i = 0; i < uiParamInfo.uiparamstable.length; i++) {\n param = uiParamInfo.uiparamstable[i];\n html += \"\\n\";\n }\n html += \"
\" + hdrs[0] + \"\" + hdrs[1] + \"\" + hdrs[2] + \"
\" + param[0] + \"\" + param[1] + \"\" + param[2] + \"
\\n\";\n return html;\n }\n\n\n\n /**\n * Plug the UI info received by getJSON into the author form.\n * @param {object} uiInfo The response data from the getJSON call\n * @returns {undefined}\n */\n function updateUiParamsDescription(uiInfo) {\n let currentuiparameters = uiparameters.val();\n let paramDescriptionDiv = $('.ui_parameters_descr');\n let hideUiParamsDescription = function() {\n uiparameters.val(''); // Remove stray white space.\n $('#fgroup_id_uiparametergroup').hide();\n };\n paramDescriptionDiv.empty();\n if (uiInfo === null || (uiInfo.uiparamstable.length == 0 && currentuiparameters.trim() === '')) {\n hideUiParamsDescription();\n } else {\n paramDescriptionDiv.append(uiInfo.header);\n let showhidebutton = $('');\n if (uiInfo.uiparamstable.length != 0) {\n paramDescriptionDiv.append(showhidebutton);\n let table = $(UiParameterDescriptionTable(uiInfo));\n paramDescriptionDiv.append(table);\n table.hide();\n showhidebutton.click(function () {\n if (showhidebutton.html() == uiInfo.showdetails) {\n table.show();\n showhidebutton.html(uiInfo.hidedetails);\n } else {\n table.hide();\n showhidebutton.html(uiInfo.showdetails);\n }\n });\n }\n $('#fgroup_id_uiparametergroup').show();\n if (useace.prop('checked')) {\n setUi('id_uiparameters', 'ace');\n }\n }\n }\n\n /**\n * Load the UI parameter description field by Ajax initially or\n * when the UI plugin is changed.\n */\n function loadUiParametersDescription() {\n let newUi = uiplugin.children('option:selected').text();\n if (newUi === '' || newUi === 'none') {\n updateUiParamsDescription(null);\n } else {\n $.getJSON(M.cfg.wwwroot + '/question/type/coderunner/ajax.php',\n {\n uiplugin: newUi,\n courseid: courseId,\n sesskey: M.cfg.sesskey\n },\n updateUiParamsDescription\n ).fail(function () {\n // AJAX failed.\n langStringAlert('error_loading_ui_descr', `UI: ${newUi}`);\n });\n }\n }\n\n /**\n * Show/hide all testtype divs in the testcases according to the\n * 'Precheck' selector.\n */\n function set_testtype_visibilities() {\n if (precheck.val() === '3') { // Show only for case of 'Selected'.\n testtypedivs.show();\n } else {\n testtypedivs.hide();\n }\n }\n\n /**\n * Check that the Ace language is correctly set for the answer and\n * answer preload fields.\n */\n function check_ace_lang() {\n if (uiplugin.val() === 'ace'){\n setUis();\n }\n }\n\n /**\n * Check that the Ace language is correctly set for the template,\n * if template_uses_ace is checked.\n */\n function check_template_lang() {\n if (useace.prop('checked')) {\n setUi('id_template', 'ace');\n }\n }\n\n /**\n * If the brokenquestionmessage hidden element is not empty, insert the\n * given message as an error at the top of the question.\n * itself to go back to the last valid value.\n */\n function checkForBrokenQuestion() {\n let brokenQuestionMessage = brokenQuestion.prop('value'),\n messagePara = null;\n if (brokenQuestionMessage !== '') {\n messagePara = $('

' + brokenQuestion.prop('value') + '

');\n $('#id_qtype_coderunner_error_div').append(messagePara);\n }\n }\n\n /**\n * Shows the load type error of the selected type if the selected type is\n * faulty.\n * @param {string} currentType The current type with its errors.\n * @param {JSON Object} errorObject The JSON object containing a list of all the errors.\n * @param {string} newType The new type string which it failed to load.\n */\n function showLoadTypeError(currentType, errorObject, newType) {\n str.get_string('loadprototypeerror', 'qtype_coderunner',\n { oldtype : currentType, crtype : newType, outputstring : errorObject.extras })\n .then(function(str) {\n $('#id_qtype_coderunner_warning_div').append($('

' + str + '

'));\n });\n }\n\n /*************************************************************\n *\n * Body of initEditFormWhenReady starts here.\n *\n *************************************************************/\n\n if (prototypeType.prop('value') != 0) {\n // Display the prototype warning if it's a prototype and hide testboxes.\n testsection.css('display', 'none');\n prototypeDisplay.removeAttr('hidden');\n if (prototypeType.prop('value') == 1) {\n // Editing a built-in question type: Dangerous!\n str.get_string('proceed_at_own_risk', 'qtype_coderunner').then(function(s) {\n alert(s);\n });\n prototypeType.prop('disabled', true);\n customise.prop('disabled', true);\n }\n }\n\n checkForBrokenQuestion();\n badQuestionLoad.prop('hidden'); // Until we check it once.\n // Keep track of the current prototype loaded.\n currentQtype = typeCombo.children('option:selected').text();\n\n setCustomisationVisibility(isCustomised);\n if (!isCustomised) {\n // Not customised so have to load fields from prototype.\n loadCustomisationFields(); // setUis is called when this completes.\n } else {\n setUis(); // Set up UI controllers on answer and answerpreload.\n str.get_string('info_unavailable', 'qtype_coderunner').then(function(s) {\n questiontypeHelpDiv.html(\"

\" + s + \"

\");\n });\n }\n\n set_testtype_visibilities();\n\n if (useace.prop('checked')) {\n setUi('id_templateparams', 'ace');\n setUi('id_uiparameters', 'ace');\n }\n\n loadUiParametersDescription();\n\n // Set up event Handlers.\n\n customise.on('change', function() {\n let isCustomised = customise.prop('checked');\n if (isCustomised) {\n // Customisation is being turned on.\n setCustomisationVisibility(true);\n } else { // Customisation being turned off.\n str.get_string('confirm_proceed', 'qtype_coderunner').then(function(s) {\n if (window.confirm(s)) {\n setCustomisationVisibility(false);\n } else {\n customise.prop('checked', true);\n }\n });\n }\n });\n\n acelang.on('change', check_ace_lang);\n language.on('change', function() {\n check_template_lang();\n check_ace_lang();\n });\n\n typeCombo.on('change', function() {\n if (customise.prop('checked')) {\n // Author has customised the question. Ask if they want to reload inherited stuff.\n str.get_string('question_type_changed', 'qtype_coderunner').then(function (s) {\n if (window.confirm(s)) {\n loadCustomisationFields();\n }\n });\n } else {\n loadCustomisationFields();\n }\n });\n\n useace.on('change', function() {\n var isTurningOn = useace.prop('checked');\n if (isTurningOn) {\n setUi('id_template', 'ace');\n setUi('id_templateparams', 'ace');\n setUi('id_uiparameters', 'ace');\n } else {\n setUi('id_template', '');\n setUi('id_templateparams', '');\n setUi('id_uiparameters', '');\n }\n });\n\n evaluatePerStudent.on('change', function() {\n if (evaluatePerStudent.is(':checked')) {\n langStringAlert('templateparamsusingsandbox');\n }\n });\n\n uiplugin.on('change', function () {\n setUis();\n loadUiParametersDescription();\n });\n\n precheck.on('change', set_testtype_visibilities);\n\n // Displays and hides the reason for the question type to be disabled.\n // Also hides/shows the test cases section if prototype/not prototype.\n prototypeType.on('change', function () {\n if (prototypeType.prop('value') == '0') {\n testsection.css('display', 'block');\n prototypeDisplay.attr('hidden', '1');\n } else {\n testsection.css('display', 'none');\n prototypeDisplay.removeAttr('hidden');\n }\n });\n\n // In order to initialise the Ui plugin when the answer preload section is\n // expanded, we monitor attribute mutations in the Answer Preload\n // header.\n var observer = new MutationObserver( function () {\n setUis();\n });\n observer.observe(preloadHdr.get(0), {'attributes': true, 'attributeFilter':['class']});\n\n // Setup click handler for the buttons that allow users to replace the\n // expected output with the output got from testing the answer program.\n $('button.replaceexpectedwithgot').click(function() {\n var gotPre = $(this).prev('pre[id^=\"id_got_\"]');\n var testCaseId = gotPre.attr('id').replace('id_got_', '');\n $('#id_expected_' + testCaseId).val(gotPre.text());\n $('#id_fail_expected_' + testCaseId).html(gotPre.text());\n $('.failrow_' + testCaseId).addClass('fixed'); // Fixed row.\n $(this).prop('disabled', true);\n });\n\n // On reloading the page, enable the typeCombo so that its value is POSTed.\n $('.btn-primary').click(function() {\n typeCombo.prop('disabled', false);\n });\n }\n\n return {initEditForm: initEditForm};\n});"],"names":["define","$","ui","str","currentQtype","JSON_TO_FORM_MAP","template","iscombinatortemplate","value","cputimelimitsecs","memlimitmb","sandbox","sandboxparams","testsplitterre","splitter","replace","allowmultiplestdins","grader","resultcolumns","language","acelang","uiplugin","initEditForm","typeCombo","prototypeDisplay","evaluatePerStudent","globalextra","prototypeextra","useace","customise","isCombinator","testSplitterRe","allowMultipleStdins","customisationFieldSet","advancedCustomisation","isCustomised","prop","prototypeType","preloadHdr","courseId","questiontypeHelpDiv","precheck","testtypedivs","testsection","brokenQuestion","badQuestionLoad","uiparameters","setUi","taId","uiname","lang","uiWrapper","ta","document","getElementById","paramsJson","attr","params","val","JSON","parse","err","toLowerCase","langs","i","indexOf","split","length","endsWith","substr","preferredAceLang","current_ui_wrapper","loadUi","InterfaceWrapper","setUis","answer","enableUi","enable_in_editor","error","alert","setCustomisationVisibility","isVisible","display","css","copyFieldsFromQuestionType","newType","response","formspecifier","attrval","isCombinatorEnabled","key","stateOn","taIds","get","restart","stop","enableAceInCustomisedFields","filter","get_string","then","s","title","coderunner_descr","html","resultHtml","questiontext","langStringAlert","extra","window","hasOwnProperty","behattesting","message","loadCustomisationFields","children","text","getJSON","M","cfg","wwwroot","qtype","courseid","sesskey","outcome","empty","success","loadUiParametersDescription","errorObject","questionType","errorMessage","reportError","currentType","oldtype","crtype","outputstring","extras","append","showLoadTypeError","fail","updateUiParamsDescription","uiInfo","currentuiparameters","paramDescriptionDiv","uiparamstable","trim","hide","header","showhidebutton","showdetails","table","uiParamInfo","param","hdrs","columnheaders","UiParameterDescriptionTable","click","show","hidedetails","newUi","set_testtype_visibilities","check_ace_lang","removeAttr","messagePara","checkForBrokenQuestion","on","confirm","is","MutationObserver","observe","gotPre","this","prev","testCaseId","addClass"],"mappings":";;;;;;;AAyBAA,qCAAO,CAAC,SAAU,wCAAyC,aAAa,SAASC,EAAGC,GAAIC,SAGhFC,aAAe,OASfC,iBAAmB,CACnBC,SAAqB,CAAC,eAAgB,QAAS,IAC/CC,qBAAqB,CAAC,2BAA4B,UAAW,GACrC,SAAUC,aACW,MAAVA,QAEnCC,iBAAqB,CAAC,uBAAwB,QAAS,IACvDC,WAAqB,CAAC,iBAAkB,QAAS,IACjDC,QAAqB,CAAC,cAAe,QAAS,WAC9CC,cAAqB,CAAC,oBAAqB,QAAS,IACpDC,eAAqB,CAAC,qBAAsB,QAAS,GAC7B,SAAUC,iBACCA,SAASC,QAAQ,KAAM,SAE1DC,oBAAqB,CAAC,0BAA2B,UAAW,GACpC,SAAUR,aACW,MAAVA,QAEnCS,OAAqB,CAAC,aAAc,QAAS,kBAC7CC,cAAqB,CAAC,oBAAqB,Q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,cAOrB,IAAIM,kBAAkB,WACjC5F,YAEK6F,QAAQjI,WAAWuD,IAAI,GAAI,aAAe,kBAAwB,CAAC,WAI5E5F,EAAE,iCAAiCyJ,OAAM,eACjCc,OAASvK,EAAEwK,MAAMC,KAAK,sBACtBC,WAAaH,OAAOhH,KAAK,MAAMzC,QAAQ,UAAW,IACtDd,EAAE,gBAAkB0K,YAAYjH,IAAI8G,OAAOtD,QAC3CjH,EAAE,qBAAuB0K,YAAYpE,KAAKiE,OAAOtD,QACjDjH,EAAE,YAAc0K,YAAYC,SAAS,SACrC3K,EAAEwK,MAAMrI,KAAK,YAAY,MAI7BnC,EAAE,gBAAgByJ,OAAM,WACpBnI,UAAUa,KAAK,YAAY"} \ No newline at end of file diff --git a/amd/build/resetbutton.min.js b/amd/build/resetbutton.min.js index 76c24554d..630ae5d6a 100644 --- a/amd/build/resetbutton.min.js +++ b/amd/build/resetbutton.min.js @@ -9,6 +9,6 @@ * @copyright Richard Lobb, 2016, The University of Canterbury * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("qtype_coderunner/resetbutton",["jquery"],(function($){return{initResetButton:function(buttonId,answerId,confirmText){var uiWrapper,resetButton=$('[id="'+buttonId+'"]'),studentAnswer=$('[id="'+answerId+'"]');resetButton.on("click",(function(){if(window.behattesting||window.confirm(confirmText)){var reloadText=resetButton.attr("data-reload-text");(uiWrapper=studentAnswer.data("current-ui-wrapper"))&&uiWrapper.uiInstance?(uiWrapper.stop(),studentAnswer.val(reloadText),uiWrapper.restart()):studentAnswer.val(reloadText)}}))}}})); +define("qtype_coderunner/resetbutton",["jquery"],(function($){return{initResetButton:function(buttonId,answerId,confirmText){var uiWrapper,resetButton=$('[id="'+buttonId+'"]'),studentAnswer=$('[id="'+answerId+'"]');resetButton.on("click",(function(){if(window.behattesting||window.confirm(confirmText)){var reloadText=resetButton.attr("data-reload-text");(uiWrapper=studentAnswer.get(0).current_ui_wrapper)&&uiWrapper.uiInstance?(uiWrapper.stop(),studentAnswer.val(reloadText),uiWrapper.restart()):studentAnswer.val(reloadText)}}))}}})); //# sourceMappingURL=resetbutton.min.js.map \ No newline at end of file diff --git a/amd/build/resetbutton.min.js.map b/amd/build/resetbutton.min.js.map index 6ca89e48d..32dcafcf8 100644 --- a/amd/build/resetbutton.min.js.map +++ b/amd/build/resetbutton.min.js.map @@ -1 +1 @@ -{"version":3,"file":"resetbutton.min.js","sources":["../src/resetbutton.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This AMD module provides the functionality for the \"Reset\"\n * button that is shown just below the student answer field if the question is\n * defined to have preloaded text.\n * If clicked, the button reloads the student answer field with the original\n * preloaded text (after a Confirm dialogue, of course).\n *\n * @module qtype_coderunner/resetbutton\n * @copyright Richard Lobb, 2016, The University of Canterbury\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\ndefine(['jquery'], function($) {\n\n /**\n * Initialise the Reset button.\n * @param {string} buttonId The ID of the button.\n * @param {string} answerId The ID of the answer box whose contents are to\n * be reset.\n * @param {string} confirmText The language string to display when asking\n * the user to confirm the reset.\n */\n function initResetButton(buttonId, answerId, confirmText) {\n var resetButton = $('[id=\"' + buttonId + '\"]'),\n studentAnswer = $('[id=\"' + answerId + '\"]'),\n uiWrapper;\n\n resetButton.on(\"click\", function() {\n if (window.behattesting || window.confirm(confirmText)) {\n var reloadText = resetButton.attr('data-reload-text');\n uiWrapper = studentAnswer.data('current-ui-wrapper');\n if (uiWrapper && uiWrapper.uiInstance) {\n // If the textarea has a UI wrapper, and it's active.\n uiWrapper.stop();\n studentAnswer.val(reloadText);\n uiWrapper.restart();\n } else {\n studentAnswer.val(reloadText);\n }\n }\n });\n }\n\n return { \"initResetButton\": initResetButton };\n});\n"],"names":["define","$","buttonId","answerId","confirmText","uiWrapper","resetButton","studentAnswer","on","window","behattesting","confirm","reloadText","attr","data","uiInstance","stop","val","restart"],"mappings":";;;;;;;;;;;AA4BAA,sCAAO,CAAC,WAAW,SAASC,SA+BjB,0BArBkBC,SAAUC,SAAUC,iBAGrCC,UAFAC,YAAcL,EAAE,QAAUC,SAAW,MACrCK,cAAgBN,EAAE,QAAUE,SAAW,MAG3CG,YAAYE,GAAG,SAAS,cAChBC,OAAOC,cAAgBD,OAAOE,QAAQP,aAAc,KAChDQ,WAAaN,YAAYO,KAAK,qBAClCR,UAAYE,cAAcO,KAAK,wBACdT,UAAUU,YAEvBV,UAAUW,OACVT,cAAcU,IAAIL,YAClBP,UAAUa,WAEVX,cAAcU,IAAIL"} \ No newline at end of file +{"version":3,"file":"resetbutton.min.js","sources":["../src/resetbutton.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This AMD module provides the functionality for the \"Reset\"\n * button that is shown just below the student answer field if the question is\n * defined to have preloaded text.\n * If clicked, the button reloads the student answer field with the original\n * preloaded text (after a Confirm dialogue, of course).\n *\n * @module qtype_coderunner/resetbutton\n * @copyright Richard Lobb, 2016, The University of Canterbury\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\ndefine(['jquery'], function($) {\n\n /**\n * Initialise the Reset button.\n * @param {string} buttonId The ID of the button.\n * @param {string} answerId The ID of the answer box whose contents are to\n * be reset.\n * @param {string} confirmText The language string to display when asking\n * the user to confirm the reset.\n */\n function initResetButton(buttonId, answerId, confirmText) {\n var resetButton = $('[id=\"' + buttonId + '\"]'),\n studentAnswer = $('[id=\"' + answerId + '\"]'),\n uiWrapper;\n\n resetButton.on(\"click\", function() {\n if (window.behattesting || window.confirm(confirmText)) {\n var reloadText = resetButton.attr('data-reload-text');\n uiWrapper = studentAnswer.get(0).current_ui_wrapper;\n if (uiWrapper && uiWrapper.uiInstance) {\n // If the textarea has a UI wrapper, and it's active.\n uiWrapper.stop();\n studentAnswer.val(reloadText);\n uiWrapper.restart();\n } else {\n studentAnswer.val(reloadText);\n }\n }\n });\n }\n\n return { \"initResetButton\": initResetButton };\n});\n"],"names":["define","$","buttonId","answerId","confirmText","uiWrapper","resetButton","studentAnswer","on","window","behattesting","confirm","reloadText","attr","get","current_ui_wrapper","uiInstance","stop","val","restart"],"mappings":";;;;;;;;;;;AA4BAA,sCAAO,CAAC,WAAW,SAASC,SA+BjB,0BArBkBC,SAAUC,SAAUC,iBAGrCC,UAFAC,YAAcL,EAAE,QAAUC,SAAW,MACrCK,cAAgBN,EAAE,QAAUE,SAAW,MAG3CG,YAAYE,GAAG,SAAS,cAChBC,OAAOC,cAAgBD,OAAOE,QAAQP,aAAc,KAChDQ,WAAaN,YAAYO,KAAK,qBAClCR,UAAYE,cAAcO,IAAI,GAAGC,qBAChBV,UAAUW,YAEvBX,UAAUY,OACVV,cAAcW,IAAIN,YAClBP,UAAUc,WAEVZ,cAAcW,IAAIN"} \ No newline at end of file diff --git a/amd/src/authorform.js b/amd/src/authorform.js index 71d01c01a..98a939ccb 100644 --- a/amd/src/authorform.js +++ b/amd/src/authorform.js @@ -204,7 +204,7 @@ define(['jquery', 'qtype_coderunner/userinterfacewrapper', 'core/str'], function if (useace.prop('checked')) { for(var i = 0; i < taIds.length; i++) { ta = $(document.getElementById(taIds[i])); - uiWrapper = ta.data('current-ui-wrapper'); + uiWrapper = ta.get(0).current_ui_wrapper; if (uiWrapper && stateOn) { uiWrapper.restart(); } else if (uiWrapper && !stateOn) { diff --git a/amd/src/resetbutton.js b/amd/src/resetbutton.js index 4d341b847..e5cc61537 100644 --- a/amd/src/resetbutton.js +++ b/amd/src/resetbutton.js @@ -44,7 +44,7 @@ define(['jquery'], function($) { resetButton.on("click", function() { if (window.behattesting || window.confirm(confirmText)) { var reloadText = resetButton.attr('data-reload-text'); - uiWrapper = studentAnswer.data('current-ui-wrapper'); + uiWrapper = studentAnswer.get(0).current_ui_wrapper; if (uiWrapper && uiWrapper.uiInstance) { // If the textarea has a UI wrapper, and it's active. uiWrapper.stop();