diff --git a/amd/build/calculatescales.min.js b/amd/build/calculatescales.min.js index e8aa47cc8..26c3160eb 100644 --- a/amd/build/calculatescales.min.js +++ b/amd/build/calculatescales.min.js @@ -3,6 +3,6 @@ define("local_catquiz/calculatescales",["exports","core/str","core/ajax","core/n * @package local_catquiz * @copyright Wunderbyte GmbH * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_ajax=_interopRequireDefault(_ajax),_notification=_interopRequireDefault(_notification);const SELECTORS_CALCULATEBUTTON="#model_button";_exports.init=()=>{const calculateButton=document.querySelector(SELECTORS_CALCULATEBUTTON),contextId=parseInt(calculateButton.dataset.contextid);calculateButton.onclick=()=>{updateParameters(contextId)};const updateParameters=async contextid=>{const catscaleid=new URLSearchParams(window.location.search).get("scaleid");let errorMessage="Something went wrong";try{errorMessage=await(0,_str.get_string)("somethingwentwrong","local_catquiz")}catch(error){}_ajax.default.call([{methodname:"local_catquiz_update_parameters",args:{contextid:contextid,catscaleid:catscaleid},done:async function(res){if(res.success){disableButton();let successMessage="Recalculation was scheduled";try{successMessage=await(0,_str.get_string)("recalculationscheduled","local_catquiz")}catch(error){}_notification.default.addNotification({message:successMessage,type:"success"})}else disableButton(),_notification.default.addNotification({message:errorMessage,type:"danger"})},fail:()=>{disableButton(),_notification.default.addNotification({message:errorMessage,type:"danger"})}}])},disableButton=()=>{document.querySelector(SELECTORS_CALCULATEBUTTON).setAttribute("disabled",!0)}}})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_ajax=_interopRequireDefault(_ajax),_notification=_interopRequireDefault(_notification);const SELECTORS_CALCULATEBUTTON="#model_button";_exports.init=()=>{const calculateButton=document.querySelector(SELECTORS_CALCULATEBUTTON);if(!calculateButton)return;const contextId=parseInt(calculateButton.dataset.contextid);calculateButton.onclick=()=>{updateParameters(contextId)};const updateParameters=async contextid=>{const catscaleid=new URLSearchParams(window.location.search).get("scaleid");let errorMessage="Something went wrong";try{errorMessage=await(0,_str.get_string)("somethingwentwrong","local_catquiz")}catch(error){}_ajax.default.call([{methodname:"local_catquiz_update_parameters",args:{contextid:contextid,catscaleid:catscaleid},done:async function(res){if(res.success){disableButton();let successMessage="Recalculation was scheduled";try{successMessage=await(0,_str.get_string)("recalculationscheduled","local_catquiz")}catch(error){}_notification.default.addNotification({message:successMessage,type:"success"})}else disableButton(),_notification.default.addNotification({message:errorMessage,type:"danger"})},fail:()=>{disableButton(),_notification.default.addNotification({message:errorMessage,type:"danger"})}}])},disableButton=()=>{document.querySelector(SELECTORS_CALCULATEBUTTON).setAttribute("disabled",!0)}}})); //# sourceMappingURL=calculatescales.min.js.map \ No newline at end of file diff --git a/amd/build/calculatescales.min.js.map b/amd/build/calculatescales.min.js.map index 2531ca2fc..d4cacba54 100644 --- a/amd/build/calculatescales.min.js.map +++ b/amd/build/calculatescales.min.js.map @@ -1 +1 @@ -{"version":3,"file":"calculatescales.min.js","sources":["../src/calculatescales.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 * @package local_catquiz\n * @copyright Wunderbyte GmbH \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {get_string as getString} from 'core/str';\nimport Ajax from 'core/ajax';\nimport Notification from 'core/notification';\n\nconst SELECTORS = {\n FORMCONTAINER: '#lcq_select_context_form',\n CALCULATEBUTTON: '#model_button'\n};\n/**\n * Add event listener to buttons.\n */\nexport const init = () => {\n\n const calculateButton = document.querySelector(SELECTORS.CALCULATEBUTTON);\n const contextId = parseInt(calculateButton.dataset.contextid);\n calculateButton.onclick = () => {\n updateParameters(contextId);\n };\n\n const updateParameters = async(contextid) => {\n const urlParams = new URLSearchParams(window.location.search);\n const catscaleid = urlParams.get('scaleid');\n\n // Fallback if the translation can not be loaded\n let errorMessage = 'Something went wrong';\n try {\n errorMessage = await getString('somethingwentwrong', 'local_catquiz');\n } catch (error) {\n // We already have a fallback message, nothing to do here.\n }\n Ajax.call([{\n methodname: 'local_catquiz_update_parameters',\n args: {contextid, catscaleid},\n done: async function(res) {\n if (res.success) {\n disableButton();\n // Fallback if the translation can not be loaded\n let successMessage = 'Recalculation was scheduled';\n try {\n successMessage = await getString('recalculationscheduled', 'local_catquiz');\n } catch (error) {\n // We already have a fallback message, nothing to do here.\n }\n\n Notification.addNotification({\n message: successMessage,\n type: 'success'\n });\n } else {\n disableButton();\n Notification.addNotification({\n message: errorMessage,\n type: 'danger'\n });\n }\n },\n fail: () => {\n disableButton();\n Notification.addNotification({\n message: errorMessage,\n type: 'danger'\n });\n },\n }]);\n };\n\n const disableButton = () => {\n document.querySelector(SELECTORS.CALCULATEBUTTON).setAttribute('disabled', true);\n };\n};"],"names":["SELECTORS","calculateButton","document","querySelector","contextId","parseInt","dataset","contextid","onclick","updateParameters","async","catscaleid","URLSearchParams","window","location","search","get","errorMessage","error","call","methodname","args","done","res","success","disableButton","successMessage","addNotification","message","type","fail","setAttribute"],"mappings":";;;;;gLAyBMA,0BAEe,8BAKD,WAEVC,gBAAkBC,SAASC,cAAcH,2BACzCI,UAAYC,SAASJ,gBAAgBK,QAAQC,WACnDN,gBAAgBO,QAAU,KACtBC,iBAAiBL,kBAGfK,iBAAmBC,MAAAA,kBAEfC,WADY,IAAIC,gBAAgBC,OAAOC,SAASC,QACzBC,IAAI,eAG7BC,aAAe,2BAEfA,mBAAqB,mBAAU,qBAAsB,iBACvD,MAAOC,sBAGJC,KAAK,CAAC,CACPC,WAAY,kCACZC,KAAM,CAACd,UAAAA,UAAWI,WAAAA,YAClBW,KAAMZ,eAAea,QACbA,IAAIC,QAAS,CACbC,oBAEIC,eAAiB,kCAEjBA,qBAAuB,mBAAU,yBAA0B,iBAC7D,MAAOR,8BAIIS,gBAAgB,CACzBC,QAASF,eACTG,KAAM,iBAGVJ,sCACaE,gBAAgB,CACzBC,QAASX,aACTY,KAAM,YAIlBC,KAAM,KACEL,sCACaE,gBAAgB,CACzBC,QAASX,aACTY,KAAM,gBAMpBJ,cAAgB,KAClBvB,SAASC,cAAcH,2BAA2B+B,aAAa,YAAY"} \ No newline at end of file +{"version":3,"file":"calculatescales.min.js","sources":["../src/calculatescales.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 * @package local_catquiz\n * @copyright Wunderbyte GmbH \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {get_string as getString} from 'core/str';\nimport Ajax from 'core/ajax';\nimport Notification from 'core/notification';\n\nconst SELECTORS = {\n FORMCONTAINER: '#lcq_select_context_form',\n CALCULATEBUTTON: '#model_button'\n};\n/**\n * Add event listener to buttons.\n */\nexport const init = () => {\n\n const calculateButton = document.querySelector(SELECTORS.CALCULATEBUTTON);\n if (!calculateButton) {\n return;\n }\n const contextId = parseInt(calculateButton.dataset.contextid);\n calculateButton.onclick = () => {\n updateParameters(contextId);\n };\n\n const updateParameters = async(contextid) => {\n const urlParams = new URLSearchParams(window.location.search);\n const catscaleid = urlParams.get('scaleid');\n\n // Fallback if the translation can not be loaded\n let errorMessage = 'Something went wrong';\n try {\n errorMessage = await getString('somethingwentwrong', 'local_catquiz');\n } catch (error) {\n // We already have a fallback message, nothing to do here.\n }\n Ajax.call([{\n methodname: 'local_catquiz_update_parameters',\n args: {contextid, catscaleid},\n done: async function(res) {\n if (res.success) {\n disableButton();\n // Fallback if the translation can not be loaded\n let successMessage = 'Recalculation was scheduled';\n try {\n successMessage = await getString('recalculationscheduled', 'local_catquiz');\n } catch (error) {\n // We already have a fallback message, nothing to do here.\n }\n\n Notification.addNotification({\n message: successMessage,\n type: 'success'\n });\n } else {\n disableButton();\n Notification.addNotification({\n message: errorMessage,\n type: 'danger'\n });\n }\n },\n fail: () => {\n disableButton();\n Notification.addNotification({\n message: errorMessage,\n type: 'danger'\n });\n },\n }]);\n };\n\n const disableButton = () => {\n document.querySelector(SELECTORS.CALCULATEBUTTON).setAttribute('disabled', true);\n };\n};\n"],"names":["SELECTORS","calculateButton","document","querySelector","contextId","parseInt","dataset","contextid","onclick","updateParameters","async","catscaleid","URLSearchParams","window","location","search","get","errorMessage","error","call","methodname","args","done","res","success","disableButton","successMessage","addNotification","message","type","fail","setAttribute"],"mappings":";;;;;gLAyBMA,0BAEe,8BAKD,WAEVC,gBAAkBC,SAASC,cAAcH,+BAC1CC,6BAGCG,UAAYC,SAASJ,gBAAgBK,QAAQC,WACnDN,gBAAgBO,QAAU,KACtBC,iBAAiBL,kBAGfK,iBAAmBC,MAAAA,kBAEfC,WADY,IAAIC,gBAAgBC,OAAOC,SAASC,QACzBC,IAAI,eAG7BC,aAAe,2BAEfA,mBAAqB,mBAAU,qBAAsB,iBACvD,MAAOC,sBAGJC,KAAK,CAAC,CACPC,WAAY,kCACZC,KAAM,CAACd,UAAAA,UAAWI,WAAAA,YAClBW,KAAMZ,eAAea,QACbA,IAAIC,QAAS,CACbC,oBAEIC,eAAiB,kCAEjBA,qBAAuB,mBAAU,yBAA0B,iBAC7D,MAAOR,8BAIIS,gBAAgB,CACzBC,QAASF,eACTG,KAAM,iBAGVJ,sCACaE,gBAAgB,CACzBC,QAASX,aACTY,KAAM,YAIlBC,KAAM,KACEL,sCACaE,gBAAgB,CACzBC,QAASX,aACTY,KAAM,gBAMpBJ,cAAgB,KAClBvB,SAASC,cAAcH,2BAA2B+B,aAAa,YAAY"} \ No newline at end of file diff --git a/amd/src/calculatescales.js b/amd/src/calculatescales.js index f7c962253..4d40b4c37 100644 --- a/amd/src/calculatescales.js +++ b/amd/src/calculatescales.js @@ -33,6 +33,9 @@ const SELECTORS = { export const init = () => { const calculateButton = document.querySelector(SELECTORS.CALCULATEBUTTON); + if (!calculateButton) { + return; + } const contextId = parseInt(calculateButton.dataset.contextid); calculateButton.onclick = () => { updateParameters(contextId); @@ -88,4 +91,4 @@ export const init = () => { const disableButton = () => { document.querySelector(SELECTORS.CALCULATEBUTTON).setAttribute('disabled', true); }; -}; \ No newline at end of file +};