diff --git a/mod/data/amd/build/resetalltemplates.min.js b/mod/data/amd/build/resetalltemplates.min.js new file mode 100644 index 00000000000..5727092bbaf --- /dev/null +++ b/mod/data/amd/build/resetalltemplates.min.js @@ -0,0 +1,10 @@ +define("mod_data/resetalltemplates",["exports","core/notification","core/prefetch","core/str"],(function(_exports,_notification,_prefetch,_str){var obj; +/** + * Javascript module for reseting all templates. + * + * @module mod_data/resetalltemplates + * @copyright 2022 Ferran Recio + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_notification=(obj=_notification)&&obj.__esModule?obj:{default:obj};const selectors_resetAllTemplatesAction='[data-action="resetalltemplates"]';_exports.init=()=>{(0,_prefetch.prefetchStrings)("mod_data",["resetalltemplatesconfirmtitle","resetalltemplatesconfirm"]),(0,_prefetch.prefetchStrings)("core",["reset"]),registerEventListeners()};const registerEventListeners=()=>{document.addEventListener("click",(event=>{const actionLink=event.target.closest(selectors_resetAllTemplatesAction);actionLink&&(event.preventDefault(),resetAllTemplatesConfirm(actionLink))}))},resetAllTemplatesConfirm=async actionLink=>{try{await _notification.default.saveCancelPromise((0,_str.get_string)("resetalltemplatesconfirmtitle","mod_data"),(0,_str.get_string)("resetalltemplatesconfirm","mod_data"),(0,_str.get_string)("reset","core")),window.location=actionLink.href}catch(error){return}}})); + +//# sourceMappingURL=resetalltemplates.min.js.map \ No newline at end of file diff --git a/mod/data/amd/build/resetalltemplates.min.js.map b/mod/data/amd/build/resetalltemplates.min.js.map new file mode 100644 index 00000000000..dc98ab5c36f --- /dev/null +++ b/mod/data/amd/build/resetalltemplates.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"resetalltemplates.min.js","sources":["../src/resetalltemplates.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 * Javascript module for reseting all templates.\n *\n * @module mod_data/resetalltemplates\n * @copyright 2022 Ferran Recio \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Notification from 'core/notification';\nimport {prefetchStrings} from 'core/prefetch';\nimport {get_string as getString} from 'core/str';\n\nconst selectors = {\n resetAllTemplatesAction: '[data-action=\"resetalltemplates\"]',\n};\n\n/**\n * Initialize module\n */\nexport const init = () => {\n prefetchStrings('mod_data', [\n 'resetalltemplatesconfirmtitle',\n 'resetalltemplatesconfirm',\n ]);\n prefetchStrings('core', [\n 'reset',\n ]);\n registerEventListeners();\n};\n\n/**\n * Register events for option in action menu.\n */\nconst registerEventListeners = () => {\n document.addEventListener('click', (event) => {\n const actionLink = event.target.closest(selectors.resetAllTemplatesAction);\n if (actionLink) {\n event.preventDefault();\n resetAllTemplatesConfirm(actionLink);\n }\n });\n};\n\n/**\n * Show the confirmation modal to reset all the templates.\n *\n * @param {HTMLElement} actionLink the element that triggers the action.\n */\nconst resetAllTemplatesConfirm = async(actionLink) => {\n try {\n await Notification.saveCancelPromise(\n getString('resetalltemplatesconfirmtitle', 'mod_data'),\n getString('resetalltemplatesconfirm', 'mod_data'),\n getString('reset', 'core'),\n );\n window.location = actionLink.href;\n } catch (error) {\n return;\n }\n};\n"],"names":["selectors","registerEventListeners","document","addEventListener","event","actionLink","target","closest","preventDefault","resetAllTemplatesConfirm","async","Notification","saveCancelPromise","window","location","href","error"],"mappings":";;;;;;;4JA2BMA,kCACuB,kDAMT,mCACA,WAAY,CACxB,gCACA,2DAEY,OAAQ,CACpB,UAEJC,gCAMEA,uBAAyB,KAC3BC,SAASC,iBAAiB,SAAUC,cAC1BC,WAAaD,MAAME,OAAOC,QAAQP,mCACpCK,aACAD,MAAMI,iBACNC,yBAAyBJ,iBAU/BI,yBAA2BC,MAAAA,uBAEnBC,sBAAaC,mBACf,mBAAU,gCAAiC,aAC3C,mBAAU,2BAA4B,aACtC,mBAAU,QAAS,SAEvBC,OAAOC,SAAWT,WAAWU,KAC/B,MAAOC"} \ No newline at end of file diff --git a/mod/data/amd/build/templateseditor.min.js b/mod/data/amd/build/templateseditor.min.js index 9491f41b9e6..d5be75a660c 100644 --- a/mod/data/amd/build/templateseditor.min.js +++ b/mod/data/amd/build/templateseditor.min.js @@ -1,11 +1,10 @@ -define("mod_data/templateseditor",["exports","core/str","core/prefetch","core/url","core/notification"],(function(_exports,_str,_prefetch,_url,_notification){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0, +define("mod_data/templateseditor",["exports","core/str","core/prefetch","core/url","core/notification","core/templates"],(function(_exports,_str,_prefetch,_url,_notification,_templates){var obj; /** * Javascript module to control the template editor. * * @module mod_data/templateseditor * @copyright 2021 Mihail Geshoski * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -(0,_prefetch.prefetchStrings)("admin",["confirmation"]),(0,_prefetch.prefetchStrings)("mod_data",["resettemplateconfirmtitle","resettemplateconfirm","resettemplate","enabletemplateeditorcheck","editorenable"]);const selectors_toggleTemplateEditor='input[name="useeditor"]',selectors_resetTemplate='input[name="defaultform"]',selectors_resetButton='input[name="resetbutton"]',selectors_editForm="#edittemplateform",registerResetButton=()=>{const editForm=document.querySelector(selectors_editForm),resetButton=document.querySelector(selectors_resetButton),resetTemplate=document.querySelector(selectors_resetTemplate);resetButton&&resetTemplate&&editForm&&resetButton.addEventListener("click",(async event=>{event.preventDefault(),(0,_notification.saveCancel)((0,_str.get_string)("resettemplateconfirmtitle","mod_data"),(0,_str.get_string)("resettemplateconfirm","mod_data"),(0,_str.get_string)("resettemplate","mod_data"),(()=>{resetTemplate.value="true",editForm.submit()}),null,{triggerElement:event.target})}))},registerEditorToggler=(instanceId,mode)=>{const toggleTemplateEditor=document.querySelector(selectors_toggleTemplateEditor);toggleTemplateEditor&&toggleTemplateEditor.addEventListener("click",(async event=>{event.preventDefault();event.target.checked?(0,_notification.saveCancel)((0,_str.get_string)("confirmation","admin"),(0,_str.get_string)("enabletemplateeditorcheck","mod_data"),(0,_str.get_string)("editorenable","mod_data"),(()=>{window.location=(0,_url.relativeUrl)("/mod/data/templates.php",{d:instanceId,mode:mode,useeditor:!0})}),null,{triggerElement:event.target}):window.location=(0,_url.relativeUrl)("/mod/data/templates.php",{d:instanceId,mode:mode,useeditor:!1})}))};_exports.init=(instanceId,mode)=>{((instanceId,mode)=>{registerResetButton(),registerEditorToggler(instanceId,mode)})(instanceId,mode)}})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_templates=(obj=_templates)&&obj.__esModule?obj:{default:obj},(0,_prefetch.prefetchStrings)("admin",["confirmation"]),(0,_prefetch.prefetchStrings)("mod_data",["resettemplateconfirmtitle","resettemplateconfirm","enabletemplateeditorcheck","editorenable"]),(0,_prefetch.prefetchStrings)("core",["reset"]);const selectors_toggleTemplateEditor='input[name="useeditor"]',selectors_resetTemplate='input[name="defaultform"]',selectors_resetAllTemplates='input[name="resetall"]',selectors_resetButton='input[name="resetbutton"]',selectors_resetAllCheck='input[name="resetallcheck"]',selectors_editForm="#edittemplateform",registerResetButton=()=>{const editForm=document.querySelector(selectors_editForm),resetButton=document.querySelector(selectors_resetButton),resetTemplate=document.querySelector(selectors_resetTemplate),resetAllTemplates=document.querySelector(selectors_resetAllTemplates);resetButton&&resetTemplate&&editForm&&(resetButton.addEventListener("click",(async event=>{event.preventDefault(),(0,_notification.saveCancel)((0,_str.get_string)("resettemplateconfirmtitle","mod_data"),_templates.default.render("mod_data/template_editor_resetmodal",{resetallname:"resetallcheck"}),(0,_str.get_string)("reset","core"),(()=>{resetTemplate.value="true",editForm.submit()}),null,{triggerElement:event.target})})),resetAllTemplates&&document.addEventListener("change",(event=>{event.target.matches(selectors_resetAllCheck)&&(resetAllTemplates.value=event.target.checked?"true":"")})))},registerEditorToggler=(instanceId,mode)=>{const toggleTemplateEditor=document.querySelector(selectors_toggleTemplateEditor);toggleTemplateEditor&&toggleTemplateEditor.addEventListener("click",(async event=>{event.preventDefault();event.target.checked?(0,_notification.saveCancel)((0,_str.get_string)("confirmation","admin"),(0,_str.get_string)("enabletemplateeditorcheck","mod_data"),(0,_str.get_string)("editorenable","mod_data"),(()=>{window.location=(0,_url.relativeUrl)("/mod/data/templates.php",{d:instanceId,mode:mode,useeditor:!0})}),null,{triggerElement:event.target}):window.location=(0,_url.relativeUrl)("/mod/data/templates.php",{d:instanceId,mode:mode,useeditor:!1})}))};_exports.init=(instanceId,mode)=>{((instanceId,mode)=>{registerResetButton(),registerEditorToggler(instanceId,mode)})(instanceId,mode)}})); //# sourceMappingURL=templateseditor.min.js.map \ No newline at end of file diff --git a/mod/data/amd/build/templateseditor.min.js.map b/mod/data/amd/build/templateseditor.min.js.map index 07698917b6c..df9f8ba54d1 100644 --- a/mod/data/amd/build/templateseditor.min.js.map +++ b/mod/data/amd/build/templateseditor.min.js.map @@ -1 +1 @@ -{"version":3,"file":"templateseditor.min.js","sources":["../src/templateseditor.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 * Javascript module to control the template editor.\n *\n * @module mod_data/templateseditor\n * @copyright 2021 Mihail Geshoski \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 {prefetchStrings} from 'core/prefetch';\nimport {relativeUrl} from 'core/url';\nimport {saveCancel} from 'core/notification';\n\nprefetchStrings('admin', ['confirmation']);\nprefetchStrings('mod_data', [\n 'resettemplateconfirmtitle',\n 'resettemplateconfirm',\n 'resettemplate',\n 'enabletemplateeditorcheck',\n 'editorenable'\n]);\n\n/**\n * Template editor constants.\n */\nconst selectors = {\n toggleTemplateEditor: 'input[name=\"useeditor\"]',\n resetTemplate: 'input[name=\"defaultform\"]',\n resetButton: 'input[name=\"resetbutton\"]',\n editForm: '#edittemplateform',\n};\n\n/**\n * Register event listeners for the module.\n *\n * @param {Number} instanceId The database ID\n * @param {string} mode The template mode\n */\nconst registerEventListeners = (instanceId, mode) => {\n registerResetButton();\n registerEditorToggler(instanceId, mode);\n};\n\nconst registerResetButton = () => {\n const editForm = document.querySelector(selectors.editForm);\n const resetButton = document.querySelector(selectors.resetButton);\n const resetTemplate = document.querySelector(selectors.resetTemplate);\n\n if (!resetButton || !resetTemplate || !editForm) {\n return;\n }\n\n resetButton.addEventListener('click', async(event) => {\n event.preventDefault();\n saveCancel(\n getString('resettemplateconfirmtitle', 'mod_data'),\n getString('resettemplateconfirm', 'mod_data'),\n getString('resettemplate', 'mod_data'),\n () => {\n resetTemplate.value = \"true\";\n editForm.submit();\n },\n null,\n {triggerElement: event.target}\n );\n });\n};\n\nconst registerEditorToggler = (instanceId, mode) => {\n const toggleTemplateEditor = document.querySelector(selectors.toggleTemplateEditor);\n\n if (!toggleTemplateEditor) {\n return;\n }\n\n toggleTemplateEditor.addEventListener('click', async(event) => {\n event.preventDefault();\n // Whether the event action attempts to enable or disable the template editor.\n const enableTemplateEditor = event.target.checked;\n\n if (enableTemplateEditor) {\n // Display a confirmation dialog before enabling the template editor.\n saveCancel(\n getString('confirmation', 'admin'),\n getString('enabletemplateeditorcheck', 'mod_data'),\n getString('editorenable', 'mod_data'),\n () => {\n window.location = relativeUrl('/mod/data/templates.php', {d: instanceId, mode: mode, useeditor: true});\n },\n null,\n {triggerElement: event.target}\n );\n } else {\n window.location = relativeUrl('/mod/data/templates.php', {d: instanceId, mode: mode, useeditor: false});\n }\n });\n};\n\n/**\n * Initialize the module.\n *\n * @param {int} instanceId The database ID\n * @param {string} mode The template mode\n */\nexport const init = (instanceId, mode) => {\n registerEventListeners(instanceId, mode);\n};\n"],"names":["selectors","registerResetButton","editForm","document","querySelector","resetButton","resetTemplate","addEventListener","async","event","preventDefault","value","submit","triggerElement","target","registerEditorToggler","instanceId","mode","toggleTemplateEditor","checked","window","location","d","useeditor","registerEventListeners"],"mappings":";;;;;;;;8BA4BgB,QAAS,CAAC,+CACV,WAAY,CACxB,4BACA,uBACA,gBACA,4BACA,uBAMEA,+BACoB,0BADpBA,wBAEa,4BAFbA,sBAGW,4BAHXA,mBAIQ,oBAcRC,oBAAsB,WAClBC,SAAWC,SAASC,cAAcJ,oBAClCK,YAAcF,SAASC,cAAcJ,uBACrCM,cAAgBH,SAASC,cAAcJ,yBAExCK,aAAgBC,eAAkBJ,UAIvCG,YAAYE,iBAAiB,SAASC,MAAAA,QAClCC,MAAMC,+CAEF,mBAAU,4BAA6B,aACvC,mBAAU,uBAAwB,aAClC,mBAAU,gBAAiB,aAC3B,KACIJ,cAAcK,MAAQ,OACtBT,SAASU,WAEb,KACA,CAACC,eAAgBJ,MAAMK,aAK7BC,sBAAwB,CAACC,WAAYC,cACjCC,qBAAuBf,SAASC,cAAcJ,gCAE/CkB,sBAILA,qBAAqBX,iBAAiB,SAASC,MAAAA,QAC3CC,MAAMC,iBAEuBD,MAAMK,OAAOK,sCAKlC,mBAAU,eAAgB,UAC1B,mBAAU,4BAA6B,aACvC,mBAAU,eAAgB,aAC1B,KACIC,OAAOC,UAAW,oBAAY,0BAA2B,CAACC,EAAGN,WAAYC,KAAMA,KAAMM,WAAW,MAEpG,KACA,CAACV,eAAgBJ,MAAMK,SAG3BM,OAAOC,UAAW,oBAAY,0BAA2B,CAACC,EAAGN,WAAYC,KAAMA,KAAMM,WAAW,sBAWxF,CAACP,WAAYC,QAlEF,EAACD,WAAYC,QACxChB,sBACAc,sBAAsBC,WAAYC,OAiElCO,CAAuBR,WAAYC"} \ No newline at end of file +{"version":3,"file":"templateseditor.min.js","sources":["../src/templateseditor.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 * Javascript module to control the template editor.\n *\n * @module mod_data/templateseditor\n * @copyright 2021 Mihail Geshoski \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 {prefetchStrings} from 'core/prefetch';\nimport {relativeUrl} from 'core/url';\nimport {saveCancel} from 'core/notification';\nimport Templates from 'core/templates';\n\nprefetchStrings('admin', ['confirmation']);\nprefetchStrings('mod_data', [\n 'resettemplateconfirmtitle',\n 'resettemplateconfirm',\n 'enabletemplateeditorcheck',\n 'editorenable'\n]);\nprefetchStrings('core', [\n 'reset',\n]);\n\n/**\n * Template editor constants.\n */\nconst selectors = {\n toggleTemplateEditor: 'input[name=\"useeditor\"]',\n resetTemplate: 'input[name=\"defaultform\"]',\n resetAllTemplates: 'input[name=\"resetall\"]',\n resetButton: 'input[name=\"resetbutton\"]',\n resetAllCheck: 'input[name=\"resetallcheck\"]',\n editForm: '#edittemplateform',\n};\n\n/**\n * Register event listeners for the module.\n *\n * @param {Number} instanceId The database ID\n * @param {string} mode The template mode\n */\nconst registerEventListeners = (instanceId, mode) => {\n registerResetButton();\n registerEditorToggler(instanceId, mode);\n};\n\nconst registerResetButton = () => {\n const editForm = document.querySelector(selectors.editForm);\n const resetButton = document.querySelector(selectors.resetButton);\n const resetTemplate = document.querySelector(selectors.resetTemplate);\n const resetAllTemplates = document.querySelector(selectors.resetAllTemplates);\n\n if (!resetButton || !resetTemplate || !editForm) {\n return;\n }\n\n resetButton.addEventListener('click', async(event) => {\n event.preventDefault();\n saveCancel(\n getString('resettemplateconfirmtitle', 'mod_data'),\n Templates.render('mod_data/template_editor_resetmodal', {resetallname: \"resetallcheck\"}),\n getString('reset', 'core'),\n () => {\n resetTemplate.value = \"true\";\n editForm.submit();\n },\n null,\n {triggerElement: event.target}\n );\n });\n\n // The reset all checkbox is inside a modal so we need to capture at document level.\n if (!resetAllTemplates) {\n return;\n }\n document.addEventListener('change', (event) => {\n if (event.target.matches(selectors.resetAllCheck)) {\n resetAllTemplates.value = (event.target.checked) ? \"true\" : \"\";\n }\n });\n};\n\nconst registerEditorToggler = (instanceId, mode) => {\n const toggleTemplateEditor = document.querySelector(selectors.toggleTemplateEditor);\n\n if (!toggleTemplateEditor) {\n return;\n }\n\n toggleTemplateEditor.addEventListener('click', async(event) => {\n event.preventDefault();\n // Whether the event action attempts to enable or disable the template editor.\n const enableTemplateEditor = event.target.checked;\n\n if (enableTemplateEditor) {\n // Display a confirmation dialog before enabling the template editor.\n saveCancel(\n getString('confirmation', 'admin'),\n getString('enabletemplateeditorcheck', 'mod_data'),\n getString('editorenable', 'mod_data'),\n () => {\n window.location = relativeUrl('/mod/data/templates.php', {d: instanceId, mode: mode, useeditor: true});\n },\n null,\n {triggerElement: event.target}\n );\n } else {\n window.location = relativeUrl('/mod/data/templates.php', {d: instanceId, mode: mode, useeditor: false});\n }\n });\n};\n\n/**\n * Initialize the module.\n *\n * @param {int} instanceId The database ID\n * @param {string} mode The template mode\n */\nexport const init = (instanceId, mode) => {\n registerEventListeners(instanceId, mode);\n};\n"],"names":["selectors","registerResetButton","editForm","document","querySelector","resetButton","resetTemplate","resetAllTemplates","addEventListener","async","event","preventDefault","Templates","render","resetallname","value","submit","triggerElement","target","matches","checked","registerEditorToggler","instanceId","mode","toggleTemplateEditor","window","location","d","useeditor","registerEventListeners"],"mappings":";;;;;;;8KA6BgB,QAAS,CAAC,+CACV,WAAY,CACxB,4BACA,uBACA,4BACA,+CAEY,OAAQ,CACpB,gBAMEA,+BACoB,0BADpBA,wBAEa,4BAFbA,4BAGiB,yBAHjBA,sBAIW,4BAJXA,wBAKa,8BALbA,mBAMQ,oBAcRC,oBAAsB,WAClBC,SAAWC,SAASC,cAAcJ,oBAClCK,YAAcF,SAASC,cAAcJ,uBACrCM,cAAgBH,SAASC,cAAcJ,yBACvCO,kBAAoBJ,SAASC,cAAcJ,6BAE5CK,aAAgBC,eAAkBJ,WAIvCG,YAAYG,iBAAiB,SAASC,MAAAA,QAClCC,MAAMC,+CAEF,mBAAU,4BAA6B,YACvCC,mBAAUC,OAAO,sCAAuC,CAACC,aAAc,mBACvE,mBAAU,QAAS,SACnB,KACIR,cAAcS,MAAQ,OACtBb,SAASc,WAEb,KACA,CAACC,eAAgBP,MAAMQ,YAK1BX,mBAGLJ,SAASK,iBAAiB,UAAWE,QAC7BA,MAAMQ,OAAOC,QAAQnB,2BACrBO,kBAAkBQ,MAASL,MAAMQ,OAAOE,QAAW,OAAS,SAKlEC,sBAAwB,CAACC,WAAYC,cACjCC,qBAAuBrB,SAASC,cAAcJ,gCAE/CwB,sBAILA,qBAAqBhB,iBAAiB,SAASC,MAAAA,QAC3CC,MAAMC,iBAEuBD,MAAMQ,OAAOE,sCAKlC,mBAAU,eAAgB,UAC1B,mBAAU,4BAA6B,aACvC,mBAAU,eAAgB,aAC1B,KACIK,OAAOC,UAAW,oBAAY,0BAA2B,CAACC,EAAGL,WAAYC,KAAMA,KAAMK,WAAW,MAEpG,KACA,CAACX,eAAgBP,MAAMQ,SAG3BO,OAAOC,UAAW,oBAAY,0BAA2B,CAACC,EAAGL,WAAYC,KAAMA,KAAMK,WAAW,sBAWxF,CAACN,WAAYC,QA7EF,EAACD,WAAYC,QACxCtB,sBACAoB,sBAAsBC,WAAYC,OA4ElCM,CAAuBP,WAAYC"} \ No newline at end of file diff --git a/mod/data/amd/src/resetalltemplates.js b/mod/data/amd/src/resetalltemplates.js new file mode 100644 index 00000000000..8b3c5daabc7 --- /dev/null +++ b/mod/data/amd/src/resetalltemplates.js @@ -0,0 +1,75 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Javascript module for reseting all templates. + * + * @module mod_data/resetalltemplates + * @copyright 2022 Ferran Recio + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import Notification from 'core/notification'; +import {prefetchStrings} from 'core/prefetch'; +import {get_string as getString} from 'core/str'; + +const selectors = { + resetAllTemplatesAction: '[data-action="resetalltemplates"]', +}; + +/** + * Initialize module + */ +export const init = () => { + prefetchStrings('mod_data', [ + 'resetalltemplatesconfirmtitle', + 'resetalltemplatesconfirm', + ]); + prefetchStrings('core', [ + 'reset', + ]); + registerEventListeners(); +}; + +/** + * Register events for option in action menu. + */ +const registerEventListeners = () => { + document.addEventListener('click', (event) => { + const actionLink = event.target.closest(selectors.resetAllTemplatesAction); + if (actionLink) { + event.preventDefault(); + resetAllTemplatesConfirm(actionLink); + } + }); +}; + +/** + * Show the confirmation modal to reset all the templates. + * + * @param {HTMLElement} actionLink the element that triggers the action. + */ +const resetAllTemplatesConfirm = async(actionLink) => { + try { + await Notification.saveCancelPromise( + getString('resetalltemplatesconfirmtitle', 'mod_data'), + getString('resetalltemplatesconfirm', 'mod_data'), + getString('reset', 'core'), + ); + window.location = actionLink.href; + } catch (error) { + return; + } +}; diff --git a/mod/data/amd/src/templateseditor.js b/mod/data/amd/src/templateseditor.js index 5c5bf8505de..69bfd4aaec7 100644 --- a/mod/data/amd/src/templateseditor.js +++ b/mod/data/amd/src/templateseditor.js @@ -25,15 +25,18 @@ import {get_string as getString} from 'core/str'; import {prefetchStrings} from 'core/prefetch'; import {relativeUrl} from 'core/url'; import {saveCancel} from 'core/notification'; +import Templates from 'core/templates'; prefetchStrings('admin', ['confirmation']); prefetchStrings('mod_data', [ 'resettemplateconfirmtitle', 'resettemplateconfirm', - 'resettemplate', 'enabletemplateeditorcheck', 'editorenable' ]); +prefetchStrings('core', [ + 'reset', +]); /** * Template editor constants. @@ -41,7 +44,9 @@ prefetchStrings('mod_data', [ const selectors = { toggleTemplateEditor: 'input[name="useeditor"]', resetTemplate: 'input[name="defaultform"]', + resetAllTemplates: 'input[name="resetall"]', resetButton: 'input[name="resetbutton"]', + resetAllCheck: 'input[name="resetallcheck"]', editForm: '#edittemplateform', }; @@ -60,6 +65,7 @@ const registerResetButton = () => { const editForm = document.querySelector(selectors.editForm); const resetButton = document.querySelector(selectors.resetButton); const resetTemplate = document.querySelector(selectors.resetTemplate); + const resetAllTemplates = document.querySelector(selectors.resetAllTemplates); if (!resetButton || !resetTemplate || !editForm) { return; @@ -69,8 +75,8 @@ const registerResetButton = () => { event.preventDefault(); saveCancel( getString('resettemplateconfirmtitle', 'mod_data'), - getString('resettemplateconfirm', 'mod_data'), - getString('resettemplate', 'mod_data'), + Templates.render('mod_data/template_editor_resetmodal', {resetallname: "resetallcheck"}), + getString('reset', 'core'), () => { resetTemplate.value = "true"; editForm.submit(); @@ -79,6 +85,16 @@ const registerResetButton = () => { {triggerElement: event.target} ); }); + + // The reset all checkbox is inside a modal so we need to capture at document level. + if (!resetAllTemplates) { + return; + } + document.addEventListener('change', (event) => { + if (event.target.matches(selectors.resetAllCheck)) { + resetAllTemplates.value = (event.target.checked) ? "true" : ""; + } + }); }; const registerEditorToggler = (instanceId, mode) => { diff --git a/mod/data/classes/manager.php b/mod/data/classes/manager.php index ab866db0049..022ace17be8 100644 --- a/mod/data/classes/manager.php +++ b/mod/data/classes/manager.php @@ -372,6 +372,39 @@ class manager { return true; } + /** + * Reset all templates. + * + * @return bool if the reset is done or not + */ + public function reset_all_templates(): bool { + $newtemplates = new stdClass(); + foreach (self::TEMPLATES_LIST as $templatename => $templatefile) { + $newtemplates->{$templatename} = ''; + } + return $this->update_templates($newtemplates); + } + + /** + * Reset all templates related to a specific template. + * + * @param string $templatename the template name + * @return bool if the reset is done or not + */ + public function reset_template(string $templatename): bool { + $newtemplates = new stdClass(); + // Reset the template to default. + $newtemplates->{$templatename} = ''; + if ($templatename == 'listtemplate') { + $newtemplates->listtemplateheader = ''; + $newtemplates->listtemplatefooter = ''; + } + if ($templatename == 'rsstemplate') { + $newtemplates->rsstitletemplate = ''; + } + return $this->update_templates($newtemplates); + } + /** Check if the user can view a specific preset. * * @param preset $preset the preset instance. diff --git a/mod/data/classes/output/action_bar.php b/mod/data/classes/output/action_bar.php index 25eb41fc634..7db843fb6a1 100644 --- a/mod/data/classes/output/action_bar.php +++ b/mod/data/classes/output/action_bar.php @@ -178,7 +178,20 @@ class action_bar { $selectmenu->set_label(get_string('templatesnavigation', 'mod_data'), ['class' => 'sr-only']); $renderer = $PAGE->get_renderer('mod_data'); + $presetsactions = $this->get_presets_actions_select(false); + + // Reset all templates action. + $resetallurl = new moodle_url($this->currenturl); + $resetallurl->param('action', 'resetalltemplates'); + $presetsactions->add(new \action_menu_link( + $resetallurl, + null, + get_string('resetalltemplates', 'mod_data'), + false, + ['data-action' => 'resetalltemplates', 'data-dataid' => $this->id] + )); + $templatesactionbar = new templates_action_bar($this->id, $selectmenu, null, null, $presetsactions); return $renderer->render_templates_action_bar($templatesactionbar); diff --git a/mod/data/lang/en/data.php b/mod/data/lang/en/data.php index 9c1cd55f452..331768a8a8e 100644 --- a/mod/data/lang/en/data.php +++ b/mod/data/lang/en/data.php @@ -383,6 +383,9 @@ $string['requiredentriestoview_help'] = 'The number of entries a student is requ Note: If entries are required before viewing, the database auto-linking filter should be disabled. This is because the database auto-linking filter can\'t determine whether a user has submitted the required number of entries.'; $string['requiredfield'] = 'Required field'; +$string['resetalltemplates'] = 'Reset all templates'; +$string['resetalltemplatesconfirmtitle'] = 'Reset all templates?'; +$string['resetalltemplatesconfirm'] = 'You\'re about to remove all templates for your current preset. If you want to restore the templates later, you need to choose the preset again in the \'Presets\' tab.'; $string['resetsettings'] = 'Reset filters'; $string['resettemplate'] = 'Reset template'; $string['resettemplateconfirmtitle'] = 'Reset template?'; @@ -424,6 +427,7 @@ $string['tagsdeleted'] = 'Database tags have been deleted'; $string['teachersandstudents'] = '{$a->teachers} and {$a->students}'; $string['templates'] = 'Templates'; $string['templatereset'] = 'Template reset'; +$string['templateresetall'] = 'All templates reset'; $string['templatesnavigation'] = 'Templates tertiary navigation'; $string['templatesaved'] = 'Template saved'; $string['text'] = 'Text'; diff --git a/mod/data/templates.php b/mod/data/templates.php index d936d226af1..e0b216b600d 100644 --- a/mod/data/templates.php +++ b/mod/data/templates.php @@ -31,6 +31,7 @@ require_once('lib.php'); $id = optional_param('id', 0, PARAM_INT); // course module id $d = optional_param('d', 0, PARAM_INT); // database id $mode = optional_param('mode', 'addtemplate', PARAM_ALPHA); +$action = optional_param('action', '', PARAM_ALPHA); $useeditor = optional_param('useeditor', null, PARAM_BOOL); $url = new moodle_url('/mod/data/templates.php'); @@ -85,27 +86,31 @@ if (!$manager->has_fields()) { $actionbar = new \mod_data\output\action_bar($instance->id, $url); echo $actionbar->get_templates_action_bar(); +if ($action == 'resetalltemplates') { + $manager->reset_all_templates(); + $notificationstr = get_string('templateresetall', 'mod_data'); +} + if (($formdata = data_submitted()) && confirm_sesskey()) { - $notificationstr = get_string('templatesaved', 'data'); if (!empty($formdata->defaultform)) { // Reset the template to default. - $formdata->{$mode} = ''; - if ($mode == 'listtemplate') { - $formdata->listtemplateheader = ''; - $formdata->listtemplatefooter = ''; + if (!empty($formdata->resetall)) { + $manager->reset_all_templates(); + $notificationstr = get_string('templateresetall', 'mod_data'); + } else { + $manager->reset_template($mode); + $notificationstr = get_string('templatereset', 'data'); } - if ($mode == 'rsstemplate') { - $formdata->rsstitletemplate = ''; - } - $notificationstr = get_string('templatereset', 'data'); - } - if ($manager->update_templates($formdata)) { - // Reload instance. - $instance = $manager->get_instance(); - echo $OUTPUT->notification($notificationstr, 'notifysuccess'); + } else { + $manager->update_templates($formdata); + $notificationstr = get_string('templatesaved', 'data'); } } +if (!empty($notificationstr)) { + echo $OUTPUT->notification($notificationstr, 'notifysuccess'); +} + $templateeditor = new \mod_data\output\template_editor($manager, $mode); echo $renderer->render($templateeditor); diff --git a/mod/data/templates/template_editor.mustache b/mod/data/templates/template_editor.mustache index e272a08ec1a..a92429bd0d8 100644 --- a/mod/data/templates/template_editor.mustache +++ b/mod/data/templates/template_editor.mustache @@ -69,6 +69,7 @@
+
{{#toolbar}} {{> mod_data/template_editor_tools }} diff --git a/mod/data/templates/template_editor_resetmodal.mustache b/mod/data/templates/template_editor_resetmodal.mustache new file mode 100644 index 00000000000..495d64a34f4 --- /dev/null +++ b/mod/data/templates/template_editor_resetmodal.mustache @@ -0,0 +1,28 @@ +{{! + This file is part of Moodle - http://moodle.org/ + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template mod_data/template_editor_resetmodal + + Reset template modal content. + + Example context (json): + { + "resetallname": "resetallcheck" + } +}} +

{{#str}} resetalltemplatesconfirm, mod_data {{/str}}

+
+ + +
diff --git a/mod/data/templates/templates_action_bar.mustache b/mod/data/templates/templates_action_bar.mustache index b9ee5d73519..53d0e086bba 100644 --- a/mod/data/templates/templates_action_bar.mustache +++ b/mod/data/templates/templates_action_bar.mustache @@ -98,7 +98,8 @@

{{#js}} - require(['mod_data/saveaspreset'], function(saveAsPreset) { + require(['mod_data/saveaspreset', 'mod_data/resetalltemplates'], function(saveAsPreset, resetAll) { saveAsPreset.init(); + resetAll.init(); }); {{/js}} diff --git a/mod/data/tests/behat/default_templates.feature b/mod/data/tests/behat/default_templates.feature index 32f84bca396..cf342675c37 100644 --- a/mod/data/tests/behat/default_templates.feature +++ b/mod/data/tests/behat/default_templates.feature @@ -143,7 +143,7 @@ Feature: Users can use mod_data without editing the templates When I navigate to "Templates" in current page administration And I set the field "Templates tertiary navigation" to "List view template" And I click on "Reset" "button" in the "sticky-footer" "region" - And I click on "Reset template" "button" in the "Reset template?" "dialogue" + And I click on "Reset" "button" in the "Reset template?" "dialogue" And I should see "Template reset" And I navigate to "Database" in current page administration And I should not see "New header!" diff --git a/mod/data/tests/behat/edit_templates.feature b/mod/data/tests/behat/edit_templates.feature index 100ae8c8cca..3a4d85ec907 100644 --- a/mod/data/tests/behat/edit_templates.feature +++ b/mod/data/tests/behat/edit_templates.feature @@ -124,7 +124,7 @@ Feature: Users can edit the database templates When I navigate to "Templates" in current page administration And I set the field "Templates tertiary navigation" to "List view template" And I click on "Reset" "button" in the "sticky-footer" "region" - And I click on "Reset template" "button" in the "Reset template?" "dialogue" + And I click on "Reset" "button" in the "Reset template?" "dialogue" Then I should see "Template reset" And I navigate to "Database" in current page administration And I should not see "New header!" @@ -132,3 +132,79 @@ Feature: Users can edit the database templates And I should not see "New footer!" And I should see "Student entry 1" And I should see "Some content 1" + + @javascript + Scenario: Reset all database templates using the action menu + Given the following "mod_data > templates" exist: + | database | name | content | + | data1 | singletemplate | Initial single | + | data1 | listtemplate | Initial list | + | data1 | addtemplate | Initial add | + | data1 | asearchtemplate | Initial search | + And I navigate to "Database" in current page administration + And I should see "Initial list" + And I should not see "Student entry 1" + And I should not see "Some content 1" + And I click on "Advanced search" "checkbox" + And I should see "Initial search" + And I set the field "View mode tertiary navigation" to "Single view" + And I should see "Initial single" + And I should not see "Student entry 1" + And I should not see "Some content 1" + And I click on "Add entry" "button" + And I should see "Initial add" + When I navigate to "Templates" in current page administration + And I click on "Actions" "button" + And I choose "Reset all templates" in the open action menu + And I click on "Reset" "button" in the "Reset all templates?" "dialogue" + Then I should see "All templates reset" + And I navigate to "Database" in current page administration + And I should not see "Initial list" + And I should see "Student entry 1" + And I should see "Some content 1" + And I click on "Advanced search" "checkbox" + And I should not see "Initial search" + And I set the field "View mode tertiary navigation" to "Single view" + And I should not see "Initial single" + And I should see "Student entry 1" + And I should see "Some content 1" + And I click on "Add entry" "button" + And I should not see "Initial add" + + @javascript + Scenario: Reset all database templates using the reset template button + Given the following "mod_data > templates" exist: + | database | name | content | + | data1 | singletemplate | Initial single | + | data1 | listtemplate | Initial list | + | data1 | addtemplate | Initial add | + | data1 | asearchtemplate | Initial search | + And I navigate to "Database" in current page administration + And I should see "Initial list" + And I should not see "Student entry 1" + And I should not see "Some content 1" + And I click on "Advanced search" "checkbox" + And I should see "Initial search" + And I set the field "View mode tertiary navigation" to "Single view" + And I should see "Initial single" + And I should not see "Student entry 1" + And I should not see "Some content 1" + And I click on "Add entry" "button" + And I should see "Initial add" + When I navigate to "Templates" in current page administration + And I click on "Reset" "button" in the "sticky-footer" "region" + And I click on "Reset all templates" "checkbox" + And I click on "Reset" "button" in the "Reset template?" "dialogue" + Then I should see "All templates reset" + And I navigate to "Database" in current page administration + And I should not see "Initial list" + And I should see "Student entry 1" + And I should see "Some content 1" + And I click on "Advanced search" "checkbox" + And I should not see "Initial search" + And I set the field "View mode tertiary navigation" to "Single view" + And I should not see "Initial single" + And I should see "Student entry 1" + And I should see "Some content 1" + And I click on "Add entry" "button" + And I should not see "Initial add" diff --git a/mod/data/tests/manager_test.php b/mod/data/tests/manager_test.php index 7d51e91b499..8828cb47345 100644 --- a/mod/data/tests/manager_test.php +++ b/mod/data/tests/manager_test.php @@ -19,6 +19,7 @@ namespace mod_data; use context_module; use moodle_url; use core_component; +use stdClass; /** * Manager tests class for mod_data. @@ -609,4 +610,137 @@ class manager_test extends \advanced_testcase { $result = $manager->can_export_entries(); $this->assertEquals(true, $result); } + + /* + * Test reset_all_templates. + * + * @covers ::reset_all_templates + */ + public function test_reset_all_templates() { + global $DB; + + $this->resetAfterTest(); + $this->setAdminUser(); + + // Setup test data. + $course = $this->getDataGenerator()->create_course(); + $instance = $this->getDataGenerator()->create_module( + 'data', + ['course' => $course->id] + ); + $manager = manager::create_from_instance($instance); + + // Create some initial templates. + $initialtemplates = new stdClass(); + foreach (manager::TEMPLATES_LIST as $templatename => $unused) { + $initialtemplates->$templatename = "Initial $templatename"; + } + $manager->update_templates($initialtemplates); + $instance = $manager->get_instance(); + $record = $DB->get_record('data', ['id' => $instance->id]); + foreach (manager::TEMPLATES_LIST as $templatename => $unused) { + $this->assertEquals($initialtemplates->$templatename, $instance->$templatename); + $this->assertEquals($initialtemplates->$templatename, $record->$templatename); + } + + // Reset all templates. + $result = $manager->reset_all_templates(); + $this->assertTrue($result); + $instance = $manager->get_instance(); + $record = $DB->get_record('data', ['id' => $instance->id]); + foreach (manager::TEMPLATES_LIST as $templatename => $unused) { + $this->assertEquals('', $instance->$templatename); + $this->assertEquals('', $record->$templatename); + } + } + + /** + * Test reset_template. + * + * @covers ::reset_template + * @dataProvider reset_template_provider + * @param string $templatetoreset the template to reset + * @param string[] $expected the expected templates to be reset + */ + public function test_reset_template(string $templatetoreset, array $expected) { + global $DB; + + $this->resetAfterTest(); + $this->setAdminUser(); + + // Setup test data. + $course = $this->getDataGenerator()->create_course(); + $instance = $this->getDataGenerator()->create_module( + 'data', + ['course' => $course->id] + ); + $manager = manager::create_from_instance($instance); + + // Create some initial templates. + $initialtemplates = new stdClass(); + foreach (manager::TEMPLATES_LIST as $templatename => $unused) { + $initialtemplates->$templatename = "Initial $templatename"; + } + $manager->update_templates($initialtemplates); + $instance = $manager->get_instance(); + $record = $DB->get_record('data', ['id' => $instance->id]); + foreach (manager::TEMPLATES_LIST as $templatename => $unused) { + $this->assertEquals($initialtemplates->$templatename, $instance->$templatename); + $this->assertEquals($initialtemplates->$templatename, $record->$templatename); + } + + // Reset template. + $result = $manager->reset_template($templatetoreset); + $this->assertTrue($result); + $instance = $manager->get_instance(); + $record = $DB->get_record('data', ['id' => $instance->id]); + foreach (manager::TEMPLATES_LIST as $templatename => $unused) { + if (in_array($templatename, $expected)) { + $this->assertEquals('', $instance->$templatename); + $this->assertEquals('', $record->$templatename); + } else { + $this->assertEquals($initialtemplates->$templatename, $instance->$templatename); + $this->assertEquals($initialtemplates->$templatename, $record->$templatename); + } + } + } + + /** + * Data provider for test_reset_templatet. + * + * @return array + */ + public function reset_template_provider(): array { + return [ + // User presets. + 'listtemplate' => [ + 'templatename' => 'listtemplate', + 'expected' => ['listtemplate', 'listtemplateheader', 'listtemplatefooter'], + ], + 'singletemplate' => [ + 'templatename' => 'singletemplate', + 'expected' => ['singletemplate'], + ], + 'asearchtemplate' => [ + 'templatename' => 'asearchtemplate', + 'expected' => ['asearchtemplate'], + ], + 'addtemplate' => [ + 'templatename' => 'addtemplate', + 'expected' => ['addtemplate'], + ], + 'rsstemplate' => [ + 'templatename' => 'rsstemplate', + 'expected' => ['rsstemplate', 'rsstitletemplate'], + ], + 'csstemplate' => [ + 'templatename' => 'csstemplate', + 'expected' => ['csstemplate'], + ], + 'jstemplate' => [ + 'templatename' => 'jstemplate', + 'expected' => ['jstemplate'], + ], + ]; + } }