diff --git a/mod/quiz/accessrule/seb/amd/build/view.min.js b/mod/quiz/accessrule/seb/amd/build/view.min.js index 725150f612e..86019da438c 100644 --- a/mod/quiz/accessrule/seb/amd/build/view.min.js +++ b/mod/quiz/accessrule/seb/amd/build/view.min.js @@ -1,4 +1,4 @@ -define("quizaccess_seb/view",["exports","core/notification","core/templates","core/str","core/modal_factory"],(function(_exports,_notification,Templates,Str,ModalFactory){var obj; +define("quizaccess_seb/view",["exports","core/notification","core/templates","core/str","core/local/modal/alert"],(function(_exports,_notification,Templates,Str,_alert){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} /** * Manage the quiz views. * @@ -6,6 +6,6 @@ define("quizaccess_seb/view",["exports","core/notification","core/templates","co * @author Andrew Madden * @copyright 2021 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.showValidationFailedModal=_exports.clearLoadingAlert=_exports.allowAccess=_exports.addLoadingAlert=void 0,_notification=(obj=_notification)&&obj.__esModule?obj:{default:obj},Templates=_interopRequireWildcard(Templates),Str=_interopRequireWildcard(Str),ModalFactory=_interopRequireWildcard(ModalFactory);const SELECTOR_MAIN="#region-main",SELECTOR_LOADING=".seb-loading",TEMPLATE_LOADING="quizaccess_seb/loading";_exports.allowAccess=()=>{window.location.reload()};_exports.addLoadingAlert=()=>Templates.render(TEMPLATE_LOADING,{}).then(((html,js)=>{const alertRegion=window.document.querySelector(SELECTOR_MAIN);return Templates.prependNodeContents(alertRegion,html,js)})).catch(_notification.default.exception);_exports.clearLoadingAlert=()=>{const alert=window.document.querySelector(SELECTOR_LOADING);alert&&Templates.replaceNode(alert,"","")};_exports.showValidationFailedModal=()=>{ModalFactory.create({type:ModalFactory.types.ALERT,title:Str.get_string("sebkeysvalidationfailed","quizaccess_seb"),body:Str.get_string("invalidkeys","quizaccess_seb"),large:!1}).then((modal=>{modal.show()})).fail(_notification.default.exception)}})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.showValidationFailedModal=_exports.clearLoadingAlert=_exports.allowAccess=_exports.addLoadingAlert=void 0,_notification=_interopRequireDefault(_notification),Templates=_interopRequireWildcard(Templates),Str=_interopRequireWildcard(Str),_alert=_interopRequireDefault(_alert);const SELECTOR_MAIN="#region-main",SELECTOR_LOADING=".seb-loading",TEMPLATE_LOADING="quizaccess_seb/loading";_exports.allowAccess=()=>{window.location.reload()};_exports.addLoadingAlert=()=>Templates.render(TEMPLATE_LOADING,{}).then(((html,js)=>{const alertRegion=window.document.querySelector(SELECTOR_MAIN);return Templates.prependNodeContents(alertRegion,html,js)})).catch(_notification.default.exception);_exports.clearLoadingAlert=()=>{const alert=window.document.querySelector(SELECTOR_LOADING);alert&&Templates.replaceNode(alert,"","")};_exports.showValidationFailedModal=()=>{_alert.default.create({title:Str.get_string("sebkeysvalidationfailed","quizaccess_seb"),body:Str.get_string("invalidkeys","quizaccess_seb"),large:!1,show:!0}).catch(_notification.default.exception)}})); //# sourceMappingURL=view.min.js.map \ No newline at end of file diff --git a/mod/quiz/accessrule/seb/amd/build/view.min.js.map b/mod/quiz/accessrule/seb/amd/build/view.min.js.map index a3f1510252a..431ac9b306f 100644 --- a/mod/quiz/accessrule/seb/amd/build/view.min.js.map +++ b/mod/quiz/accessrule/seb/amd/build/view.min.js.map @@ -1 +1 @@ -{"version":3,"file":"view.min.js","sources":["../src/view.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 * Manage the quiz views.\n *\n * @module quizaccess_seb/view\n * @author Andrew Madden \n * @copyright 2021 Catalyst IT\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Notification from \"core/notification\";\nimport * as Templates from \"core/templates\";\nimport * as Str from \"core/str\";\nimport * as ModalFactory from \"core/modal_factory\";\n\n/** @var SELECTOR List of CSS selectors. */\nconst SELECTOR = {\n MAIN: '#region-main',\n LOADING: '.seb-loading',\n};\n\n/** @var Template List of mustache templates. */\nconst TEMPLATE = {\n LOADING: 'quizaccess_seb/loading',\n};\n\n/**\n * Manages view when access has been granted.\n */\nexport const allowAccess = () => {\n window.location.reload();\n};\n\n/**\n * Add an alert to page to inform that Safe Exam Browser access is being checked.\n *\n * @return {Promise}\n */\nexport const addLoadingAlert = () => {\n return Templates.render(TEMPLATE.LOADING, {}).then((html, js) => {\n const alertRegion = window.document.querySelector(SELECTOR.MAIN);\n return Templates.prependNodeContents(alertRegion, html, js);\n }).catch(Notification.exception);\n};\n\n/**\n * Remove the Safe Exam Browser access check alert from the page.\n */\nexport const clearLoadingAlert = () => {\n const alert = window.document.querySelector(SELECTOR.LOADING);\n if (alert) {\n Templates.replaceNode(alert, '', '');\n }\n};\n\n/**\n * Display validation failed modal.\n */\nexport const showValidationFailedModal = () => {\n ModalFactory.create({\n type: ModalFactory.types.ALERT,\n title: Str.get_string('sebkeysvalidationfailed', 'quizaccess_seb'),\n body: Str.get_string('invalidkeys', 'quizaccess_seb'),\n large: false,\n }).then((modal) => {\n modal.show();\n }).fail(Notification.exception);\n};\n"],"names":["SELECTOR","TEMPLATE","window","location","reload","Templates","render","then","html","js","alertRegion","document","querySelector","prependNodeContents","catch","Notification","exception","alert","replaceNode","ModalFactory","create","type","types","ALERT","title","Str","get_string","body","large","modal","show","fail"],"mappings":";;;;;;;;kzCA8BMA,cACI,eADJA,iBAEO,eAIPC,iBACO,8CAMc,KACvBC,OAAOC,SAASC,mCAQW,IACpBC,UAAUC,OAAOL,iBAAkB,IAAIM,MAAK,CAACC,KAAMC,YAChDC,YAAcR,OAAOS,SAASC,cAAcZ,sBAC3CK,UAAUQ,oBAAoBH,YAAaF,KAAMC,OACzDK,MAAMC,sBAAaC,sCAMO,WACvBC,MAAQf,OAAOS,SAASC,cAAcZ,kBACxCiB,OACAZ,UAAUa,YAAYD,MAAO,GAAI,wCAOA,KACrCE,aAAaC,OAAO,CAChBC,KAAMF,aAAaG,MAAMC,MACzBC,MAAOC,IAAIC,WAAW,0BAA2B,kBACjDC,KAAMF,IAAIC,WAAW,cAAe,kBACpCE,OAAO,IACRrB,MAAMsB,QACLA,MAAMC,UACPC,KAAKhB,sBAAaC"} \ No newline at end of file +{"version":3,"file":"view.min.js","sources":["../src/view.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 * Manage the quiz views.\n *\n * @module quizaccess_seb/view\n * @author Andrew Madden \n * @copyright 2021 Catalyst IT\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Notification from \"core/notification\";\nimport * as Templates from \"core/templates\";\nimport * as Str from \"core/str\";\nimport ModalAlert from \"core/local/modal/alert\";\n\n/** @var SELECTOR List of CSS selectors. */\nconst SELECTOR = {\n MAIN: '#region-main',\n LOADING: '.seb-loading',\n};\n\n/** @var Template List of mustache templates. */\nconst TEMPLATE = {\n LOADING: 'quizaccess_seb/loading',\n};\n\n/**\n * Manages view when access has been granted.\n */\nexport const allowAccess = () => {\n window.location.reload();\n};\n\n/**\n * Add an alert to page to inform that Safe Exam Browser access is being checked.\n *\n * @return {Promise}\n */\nexport const addLoadingAlert = () => {\n return Templates.render(TEMPLATE.LOADING, {}).then((html, js) => {\n const alertRegion = window.document.querySelector(SELECTOR.MAIN);\n return Templates.prependNodeContents(alertRegion, html, js);\n }).catch(Notification.exception);\n};\n\n/**\n * Remove the Safe Exam Browser access check alert from the page.\n */\nexport const clearLoadingAlert = () => {\n const alert = window.document.querySelector(SELECTOR.LOADING);\n if (alert) {\n Templates.replaceNode(alert, '', '');\n }\n};\n\n/**\n * Display validation failed modal.\n */\nexport const showValidationFailedModal = () => {\n ModalAlert.create({\n title: Str.get_string('sebkeysvalidationfailed', 'quizaccess_seb'),\n body: Str.get_string('invalidkeys', 'quizaccess_seb'),\n large: false,\n show: true,\n }).catch(Notification.exception);\n};\n"],"names":["SELECTOR","TEMPLATE","window","location","reload","Templates","render","then","html","js","alertRegion","document","querySelector","prependNodeContents","catch","Notification","exception","alert","replaceNode","create","title","Str","get_string","body","large","show"],"mappings":";;;;;;;;8VA8BMA,cACI,eADJA,iBAEO,eAIPC,iBACO,8CAMc,KACvBC,OAAOC,SAASC,mCAQW,IACpBC,UAAUC,OAAOL,iBAAkB,IAAIM,MAAK,CAACC,KAAMC,YAChDC,YAAcR,OAAOS,SAASC,cAAcZ,sBAC3CK,UAAUQ,oBAAoBH,YAAaF,KAAMC,OACzDK,MAAMC,sBAAaC,sCAMO,WACvBC,MAAQf,OAAOS,SAASC,cAAcZ,kBACxCiB,OACAZ,UAAUa,YAAYD,MAAO,GAAI,wCAOA,oBAC1BE,OAAO,CACdC,MAAOC,IAAIC,WAAW,0BAA2B,kBACjDC,KAAMF,IAAIC,WAAW,cAAe,kBACpCE,OAAO,EACPC,MAAM,IACPX,MAAMC,sBAAaC"} \ No newline at end of file diff --git a/mod/quiz/accessrule/seb/amd/src/view.js b/mod/quiz/accessrule/seb/amd/src/view.js index 20d84826b99..e345ca35640 100644 --- a/mod/quiz/accessrule/seb/amd/src/view.js +++ b/mod/quiz/accessrule/seb/amd/src/view.js @@ -25,7 +25,7 @@ import Notification from "core/notification"; import * as Templates from "core/templates"; import * as Str from "core/str"; -import * as ModalFactory from "core/modal_factory"; +import ModalAlert from "core/local/modal/alert"; /** @var SELECTOR List of CSS selectors. */ const SELECTOR = { @@ -71,12 +71,10 @@ export const clearLoadingAlert = () => { * Display validation failed modal. */ export const showValidationFailedModal = () => { - ModalFactory.create({ - type: ModalFactory.types.ALERT, + ModalAlert.create({ title: Str.get_string('sebkeysvalidationfailed', 'quizaccess_seb'), body: Str.get_string('invalidkeys', 'quizaccess_seb'), large: false, - }).then((modal) => { - modal.show(); - }).fail(Notification.exception); + show: true, + }).catch(Notification.exception); }; diff --git a/mod/quiz/amd/build/add_question_modal.min.js b/mod/quiz/amd/build/add_question_modal.min.js new file mode 100644 index 00000000000..57e67301cd2 --- /dev/null +++ b/mod/quiz/amd/build/add_question_modal.min.js @@ -0,0 +1,10 @@ +define("mod_quiz/add_question_modal",["exports","core/modal"],(function(_exports,_modal){var obj; +/** + * Contain the logic for the add random question modal. + * + * @module mod_quiz/add_question_modal + * @copyright 2023 Andrew Lyons + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_modal=(obj=_modal)&&obj.__esModule?obj:{default:obj};class AddQuestionModal extends _modal.default{configure(modalConfig){modalConfig.large=!0,modalConfig.show=!0,this.setContextId(modalConfig.contextId),this.setAddOnPageId(modalConfig.addOnPage),super.configure(modalConfig)}constructor(root){super(root),this.contextId=null,this.addOnPageId=null}setContextId(id){this.contextId=id}getContextId(){return this.contextId}setAddOnPageId(id){this.addOnPageId=id}getAddOnPageId(){return this.addOnPageId}}return _exports.default=AddQuestionModal,_exports.default})); + +//# sourceMappingURL=add_question_modal.min.js.map \ No newline at end of file diff --git a/mod/quiz/amd/build/add_question_modal.min.js.map b/mod/quiz/amd/build/add_question_modal.min.js.map new file mode 100644 index 00000000000..8f2082971fd --- /dev/null +++ b/mod/quiz/amd/build/add_question_modal.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"add_question_modal.min.js","sources":["../src/add_question_modal.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 * Contain the logic for the add random question modal.\n *\n * @module mod_quiz/add_question_modal\n * @copyright 2023 Andrew Lyons \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Modal from 'core/modal';\n\nexport default class AddQuestionModal extends Modal {\n configure(modalConfig) {\n // Add question modals are always large.\n modalConfig.large = true;\n\n // Always show on creation.\n modalConfig.show = true;\n\n // Apply question modal configuration.\n this.setContextId(modalConfig.contextId);\n this.setAddOnPageId(modalConfig.addOnPage);\n\n // Apply standard configuration.\n super.configure(modalConfig);\n }\n\n constructor(root) {\n super(root);\n\n this.contextId = null;\n this.addOnPageId = null;\n }\n\n /**\n * Save the Moodle context id that the question bank is being\n * rendered in.\n *\n * @method setContextId\n * @param {Number} id\n */\n setContextId(id) {\n this.contextId = id;\n }\n\n /**\n * Retrieve the saved Moodle context id.\n *\n * @method getContextId\n * @return {Number}\n */\n getContextId() {\n return this.contextId;\n }\n\n /**\n * Set the id of the page that the question should be added to\n * when the user clicks the add to quiz link.\n *\n * @method setAddOnPageId\n * @param {Number} id\n */\n setAddOnPageId(id) {\n this.addOnPageId = id;\n }\n\n /**\n * Returns the saved page id for the question to be added to.\n *\n * @method getAddOnPageId\n * @return {Number}\n */\n getAddOnPageId() {\n return this.addOnPageId;\n }\n\n}\n"],"names":["AddQuestionModal","Modal","configure","modalConfig","large","show","setContextId","contextId","setAddOnPageId","addOnPage","constructor","root","addOnPageId","id","getContextId","this","getAddOnPageId"],"mappings":";;;;;;;iJAyBqBA,yBAAyBC,eAC1CC,UAAUC,aAENA,YAAYC,OAAQ,EAGpBD,YAAYE,MAAO,OAGdC,aAAaH,YAAYI,gBACzBC,eAAeL,YAAYM,iBAG1BP,UAAUC,aAGpBO,YAAYC,YACFA,WAEDJ,UAAY,UACZK,YAAc,KAUvBN,aAAaO,SACJN,UAAYM,GASrBC,sBACWC,KAAKR,UAUhBC,eAAeK,SACND,YAAcC,GASvBG,wBACWD,KAAKH"} \ No newline at end of file diff --git a/mod/quiz/amd/build/add_question_modal_launcher.min.js b/mod/quiz/amd/build/add_question_modal_launcher.min.js deleted file mode 100644 index 12c1163c6ed..00000000000 --- a/mod/quiz/amd/build/add_question_modal_launcher.min.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Initialise the an add question modal on the quiz page. - * - * @module mod_quiz/add_question_modal_launcher - * @copyright 2018 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -define("mod_quiz/add_question_modal_launcher",["jquery","core/notification","core/modal_factory"],(function($,Notification,ModalFactory){return{init:function(modalType,selector,contextId,preShowCallback){let showNewCategory=!(arguments.length>4&&void 0!==arguments[4])||arguments[4];var body=$("body");let templateContext={hidden:showNewCategory};return ModalFactory.create({type:modalType,large:!0,templateContext:templateContext,preShowCallback:function(triggerElement,modal){triggerElement=$(triggerElement),modal.setContextId(contextId),modal.setAddOnPageId(triggerElement.attr("data-addonpage")),modal.setTitle(triggerElement.attr("data-header")),preShowCallback&&preShowCallback(triggerElement,modal)}},[body,selector]).fail(Notification.exception)}}})); - -//# sourceMappingURL=add_question_modal_launcher.min.js.map \ No newline at end of file diff --git a/mod/quiz/amd/build/add_question_modal_launcher.min.js.map b/mod/quiz/amd/build/add_question_modal_launcher.min.js.map deleted file mode 100644 index 4098c9b2e75..00000000000 --- a/mod/quiz/amd/build/add_question_modal_launcher.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"add_question_modal_launcher.min.js","sources":["../src/add_question_modal_launcher.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 * Initialise the an add question modal on the quiz page.\n *\n * @module mod_quiz/add_question_modal_launcher\n * @copyright 2018 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n [\n 'jquery',\n 'core/notification',\n 'core/modal_factory',\n ],\n function(\n $,\n Notification,\n ModalFactory\n ) {\n\n return {\n /**\n * Create a modal using the modal factory and add listeners to launch the\n * modal when clicked.\n *\n * @param {string} modalType Which modal to create\n * @param {string} selector The selectors for the elements that trigger the modal\n * @param {int} contextId The current context id\n * @param {function} preShowCallback A callback to execute before the modal is shown\n * @param {boolean} showNewCategory Display the New category tab when selecting random questions.\n * @return {promise} Resolved with the modal\n */\n init: function(modalType, selector, contextId, preShowCallback, showNewCategory = true) {\n var body = $('body');\n let templateContext = {\n hidden: showNewCategory,\n };\n\n // Create a question bank modal using the factory.\n // The same modal will be used by all of the add question\n // links that match \"selector\" on the page. The content\n // of the modal will be changed depending on which link is\n // clicked.\n return ModalFactory.create(\n {\n type: modalType,\n large: true,\n templateContext: templateContext,\n // This callback executes before the modal is shown when the\n // trigger element is clicked.\n preShowCallback: function(triggerElement, modal) {\n triggerElement = $(triggerElement);\n modal.setContextId(contextId);\n modal.setAddOnPageId(triggerElement.attr('data-addonpage'));\n modal.setTitle(triggerElement.attr('data-header'));\n\n if (preShowCallback) {\n preShowCallback(triggerElement, modal);\n }\n }\n },\n // Created a deligated listener rather than a single\n // trigger element.\n [body, selector]\n ).fail(Notification.exception);\n }\n };\n});\n"],"names":["define","$","Notification","ModalFactory","init","modalType","selector","contextId","preShowCallback","showNewCategory","body","templateContext","hidden","create","type","large","triggerElement","modal","setContextId","setAddOnPageId","attr","setTitle","fail","exception"],"mappings":";;;;;;;AAsBAA,8CACI,CACI,SACA,oBACA,uBAEJ,SACIC,EACAC,aACAC,oBAGG,CAYHC,KAAM,SAASC,UAAWC,SAAUC,UAAWC,qBAAiBC,+EACxDC,KAAOT,EAAE,YACTU,gBAAkB,CAClBC,OAAQH,wBAQLN,aAAaU,OAChB,CACIC,KAAMT,UACNU,OAAO,EACPJ,gBAAiBA,gBAGjBH,gBAAiB,SAASQ,eAAgBC,OACtCD,eAAiBf,EAAEe,gBACnBC,MAAMC,aAAaX,WACnBU,MAAME,eAAeH,eAAeI,KAAK,mBACzCH,MAAMI,SAASL,eAAeI,KAAK,gBAE/BZ,iBACAA,gBAAgBQ,eAAgBC,SAM5C,CAACP,KAAMJ,WACTgB,KAAKpB,aAAaqB"} \ No newline at end of file diff --git a/mod/quiz/amd/build/add_random_question.min.js b/mod/quiz/amd/build/add_random_question.min.js deleted file mode 100644 index 6b687e87df3..00000000000 --- a/mod/quiz/amd/build/add_random_question.min.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Initialise the add random question modal on the quiz page. - * - * @module mod_quiz/add_random_question - * @copyright 2018 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -define("mod_quiz/add_random_question",["mod_quiz/add_question_modal_launcher","mod_quiz/modal_add_random_question"],(function(AddQuestionModalLauncher,ModalAddRandomQuestion){return{init:function(contextId,category,returnUrl,cmid){let showNewCategory=!(arguments.length>4&&void 0!==arguments[4])||arguments[4];AddQuestionModalLauncher.init(ModalAddRandomQuestion.TYPE,'.menu [data-action="addarandomquestion"]',contextId,(function(triggerElement,modal){modal.setCategory(category),modal.setReturnUrl(returnUrl),modal.setCMID(cmid)}),showNewCategory)}}})); - -//# sourceMappingURL=add_random_question.min.js.map \ No newline at end of file diff --git a/mod/quiz/amd/build/add_random_question.min.js.map b/mod/quiz/amd/build/add_random_question.min.js.map deleted file mode 100644 index a58c0e54d4d..00000000000 --- a/mod/quiz/amd/build/add_random_question.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"add_random_question.min.js","sources":["../src/add_random_question.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 * Initialise the add random question modal on the quiz page.\n *\n * @module mod_quiz/add_random_question\n * @copyright 2018 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n [\n 'mod_quiz/add_question_modal_launcher',\n 'mod_quiz/modal_add_random_question'\n ],\n function(\n AddQuestionModalLauncher,\n ModalAddRandomQuestion\n ) {\n\n return {\n /**\n * Create the add random question modal.\n *\n * @param {int} contextId Current context id.\n * @param {string} category Category id and category context id comma separated.\n * @param {string} returnUrl URL to return to after form submission.\n * @param {int} cmid Current course module id.\n * @param {boolean} showNewCategory Display the New category tab when selecting random questions.\n */\n init: function(contextId, category, returnUrl, cmid, showNewCategory = true) {\n AddQuestionModalLauncher.init(\n ModalAddRandomQuestion.TYPE,\n '.menu [data-action=\"addarandomquestion\"]',\n contextId,\n // Additional values that should be set before the modal is shown.\n function(triggerElement, modal) {\n modal.setCategory(category);\n modal.setReturnUrl(returnUrl);\n modal.setCMID(cmid);\n },\n showNewCategory\n );\n }\n };\n});\n"],"names":["define","AddQuestionModalLauncher","ModalAddRandomQuestion","init","contextId","category","returnUrl","cmid","showNewCategory","TYPE","triggerElement","modal","setCategory","setReturnUrl","setCMID"],"mappings":";;;;;;;AAsBAA,sCACI,CACI,uCACA,uCAEJ,SACIC,yBACAC,8BAGG,CAUHC,KAAM,SAASC,UAAWC,SAAUC,UAAWC,UAAMC,2EACjDP,yBAAyBE,KACrBD,uBAAuBO,KACvB,2CACAL,WAEA,SAASM,eAAgBC,OACrBA,MAAMC,YAAYP,UAClBM,MAAME,aAAaP,WACnBK,MAAMG,QAAQP,QAElBC"} \ No newline at end of file diff --git a/mod/quiz/amd/build/modal_add_random_question.min.js b/mod/quiz/amd/build/modal_add_random_question.min.js index 0a1ac4c4c16..276b86a32da 100644 --- a/mod/quiz/amd/build/modal_add_random_question.min.js +++ b/mod/quiz/amd/build/modal_add_random_question.min.js @@ -1,3 +1,3 @@ -define("mod_quiz/modal_add_random_question",["exports","jquery","core/modal","core/notification","core/fragment","core/templates","core_form/changechecker","core/ajax","core/pending"],(function(_exports,_jquery,_modal,Notification,Fragment,Templates,FormChangeChecker,_ajax,_pending){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_jquery=_interopRequireDefault(_jquery),_modal=_interopRequireDefault(_modal),Notification=_interopRequireWildcard(Notification),Fragment=_interopRequireWildcard(Fragment),Templates=_interopRequireWildcard(Templates),FormChangeChecker=_interopRequireWildcard(FormChangeChecker),_pending=_interopRequireDefault(_pending);const SELECTORS={EXISTING_CATEGORY_CONTAINER:'[data-region="existing-category-container"]',EXISTING_CATEGORY_TAB:"#id_existingcategoryheader",NEW_CATEGORY_CONTAINER:'[data-region="new-category-container"]',NEW_CATEGORY_TAB:"#id_newcategoryheader",TAB_CONTENT:'[data-region="tab-content"]',ADD_ON_PAGE_FORM_ELEMENT:'[name="addonpage"]',ADD_RANDOM_BUTTON:'input[type="submit"][name="addrandom"]',ADD_NEW_CATEGORY_BUTTON:'input[type="submit"][name="newcategory"]',SUBMIT_BUTTON_ELEMENT:'input[type="submit"][name="addrandom"], input[type="submit"][name="newcategory"]',FORM_HEADER:"legend",SELECT_NUMBER_TO_ADD:"#menurandomcount",NEW_CATEGORY_ELEMENT:"#categoryname",PARENT_CATEGORY_ELEMENT:"#parentcategory",FILTER_CONDITION_ELEMENT:"[data-filtercondition]",FORM_ELEMENT:"#add_random_question_form",MESSAGE_INPUT:'[name="message"]'};class ModalAddRandomQuestion extends _modal.default{constructor(root){super(root),this.contextId=null,this.addOnPageId=null,this.category=null,this.returnUrl=null,this.cmid=null,this.loadedForm=!1}setContextId(id){this.contextId=id}getContextId(){return this.contextId}setAddOnPageId(id){this.addOnPageId=id,this.getBody().find(SELECTORS.ADD_ON_PAGE_FORM_ELEMENT).val(id)}getAddOnPageId(){return this.addOnPageId}setCategory(category){this.category=category}getCategory(){return this.category}setReturnUrl(url){this.returnUrl=url}getReturnUrl(){return this.returnUrl}setCMID(id){this.cmid=id}getCMID(){return this.cmid}moveContentIntoTab(tabContent,tabElement){tabContent.find(SELECTORS.FORM_HEADER).addClass("hidden"),tabContent.wrap(tabElement)}moveTabsIntoTabContent(form){const tabContent=this.getBody().find(SELECTORS.TAB_CONTENT).empty();form.find('[role="tabpanel"]').wrapAll(tabContent)}moveCancelButtonToTabs(form){const cancelButton=form.find(SELECTORS.CANCEL_BUTTON_ELEMENT).addClass("ml-1"),tabFooters=form.find('[data-region="footer"]');cancelButton.closest(SELECTORS.BUTTON_CONTAINER).remove(),cancelButton.clone().appendTo(tabFooters)}loadForm(){const cmid=this.getCMID(),cat=this.getCategory(),addonpage=this.getAddOnPageId(),returnurl=this.getReturnUrl();return Fragment.loadFragment("mod_quiz","add_random_question_form",this.getContextId(),{addonpage:addonpage,cat:cat,returnurl:returnurl,cmid:cmid}).then(((html,js)=>{const form=(0,_jquery.default)(html),existingCategoryTabContent=form.find(SELECTORS.EXISTING_CATEGORY_TAB),existingCategoryTab=this.getBody().find(SELECTORS.EXISTING_CATEGORY_CONTAINER),newCategoryTabContent=form.find(SELECTORS.NEW_CATEGORY_TAB),newCategoryTab=this.getBody().find(SELECTORS.NEW_CATEGORY_CONTAINER);this.moveContentIntoTab(existingCategoryTabContent,existingCategoryTab),this.moveContentIntoTab(newCategoryTabContent,newCategoryTab),this.moveTabsIntoTabContent(form),Templates.replaceNode(this.getBody().find(SELECTORS.TAB_CONTENT),form,js)})).then((()=>{FormChangeChecker.disableAllChecks(),this.getBody()[0].addEventListener("click",(e=>{var _document$querySelect;if(!e.target.closest(SELECTORS.SUBMIT_BUTTON_ELEMENT))return;e.preventDefault();const randomcount=document.querySelector(SELECTORS.SELECT_NUMBER_TO_ADD).value,filtercondition=null===(_document$querySelect=document.querySelector(SELECTORS.FILTER_CONDITION_ELEMENT).dataset)||void 0===_document$querySelect?void 0:_document$querySelect.filtercondition;if(e.target.closest(SELECTORS.ADD_RANDOM_BUTTON))return void this.addQuestions(cmid,addonpage,randomcount,filtercondition,"","");e.target.closest(SELECTORS.ADD_NEW_CATEGORY_BUTTON)&&this.addQuestions(cmid,addonpage,randomcount,filtercondition,document.querySelector(SELECTORS.NEW_CATEGORY_ELEMENT).value,document.querySelector(SELECTORS.PARENT_CATEGORY_ELEMENT).value)}))})).catch(Notification.exception)}async addQuestions(cmid,addonpage,randomcount,filtercondition,newcategory,parentcategory){new _pending.default("mod-quiz/modal_add_random_questions");const call={methodname:"mod_quiz_add_random_questions",args:{cmid:cmid,addonpage:addonpage,randomcount:randomcount,filtercondition:filtercondition,newcategory:newcategory,parentcategory:parentcategory}};try{const response=await(0,_ajax.call)([call])[0],form=document.querySelector(SELECTORS.FORM_ELEMENT);form.querySelector(SELECTORS.MESSAGE_INPUT).value=response.message,form.submit()}catch(e){Notification.exception(e)}}show(){super.show(this),this.loadedForm||(this.loadForm(window.location.search),this.loadedForm=!0)}}return _exports.default=ModalAddRandomQuestion,_defineProperty(ModalAddRandomQuestion,"TYPE","mod_quiz-quiz-add-random-question"),_defineProperty(ModalAddRandomQuestion,"TEMPLATE","mod_quiz/modal_add_random_question"),ModalAddRandomQuestion.registerModalType(),_exports.default})); +define("mod_quiz/modal_add_random_question",["exports","jquery","./add_question_modal","core/notification","core/fragment","core/templates","core_form/changechecker","core/ajax","core/pending"],(function(_exports,_jquery,_add_question_modal,Notification,Fragment,Templates,FormChangeChecker,_ajax,_pending){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_jquery=_interopRequireDefault(_jquery),_add_question_modal=_interopRequireDefault(_add_question_modal),Notification=_interopRequireWildcard(Notification),Fragment=_interopRequireWildcard(Fragment),Templates=_interopRequireWildcard(Templates),FormChangeChecker=_interopRequireWildcard(FormChangeChecker),_pending=_interopRequireDefault(_pending);const SELECTORS={EXISTING_CATEGORY_CONTAINER:'[data-region="existing-category-container"]',EXISTING_CATEGORY_TAB:"#id_existingcategoryheader",NEW_CATEGORY_CONTAINER:'[data-region="new-category-container"]',NEW_CATEGORY_TAB:"#id_newcategoryheader",TAB_CONTENT:'[data-region="tab-content"]',ADD_ON_PAGE_FORM_ELEMENT:'[name="addonpage"]',ADD_RANDOM_BUTTON:'input[type="submit"][name="addrandom"]',ADD_NEW_CATEGORY_BUTTON:'input[type="submit"][name="newcategory"]',SUBMIT_BUTTON_ELEMENT:'input[type="submit"][name="addrandom"], input[type="submit"][name="newcategory"]',FORM_HEADER:"legend",SELECT_NUMBER_TO_ADD:"#menurandomcount",NEW_CATEGORY_ELEMENT:"#categoryname",PARENT_CATEGORY_ELEMENT:"#parentcategory",FILTER_CONDITION_ELEMENT:"[data-filtercondition]",FORM_ELEMENT:"#add_random_question_form",MESSAGE_INPUT:'[name="message"]'};class ModalAddRandomQuestion extends _add_question_modal.default{static init(contextId,category,returnUrl,cmid){let showNewCategory=!(arguments.length>4&&void 0!==arguments[4])||arguments[4];document.addEventListener("click",(e=>{const trigger=e.target.closest('.menu [data-action="addarandomquestion"]');trigger&&(e.preventDefault(),ModalAddRandomQuestion.create({contextId:contextId,category:category,returnUrl:returnUrl,cmid:cmid,title:trigger.dataset.header,addOnPage:trigger.dataset.addonpage,templateContext:{hidden:showNewCategory}}))}))}constructor(root){super(root),this.category=null,this.returnUrl=null,this.cmid=null,this.loadedForm=!1}configure(modalConfig){this.setCategory(modalConfig.category),this.setReturnUrl(modalConfig.returnUrl),this.setCMID(modalConfig.cmid),super.configure(modalConfig)}setAddOnPageId(id){super.setAddOnPageId(id),this.getBody().find(SELECTORS.ADD_ON_PAGE_FORM_ELEMENT).val(id)}setCategory(category){this.category=category}getCategory(){return this.category}setReturnUrl(url){this.returnUrl=url}getReturnUrl(){return this.returnUrl}setCMID(id){this.cmid=id}getCMID(){return this.cmid}moveContentIntoTab(tabContent,tabElement){tabContent.find(SELECTORS.FORM_HEADER).addClass("hidden"),tabContent.wrap(tabElement)}moveTabsIntoTabContent(form){const tabContent=this.getBody().find(SELECTORS.TAB_CONTENT).empty();form.find('[role="tabpanel"]').wrapAll(tabContent)}moveCancelButtonToTabs(form){const cancelButton=form.find(SELECTORS.CANCEL_BUTTON_ELEMENT).addClass("ml-1"),tabFooters=form.find('[data-region="footer"]');cancelButton.closest(SELECTORS.BUTTON_CONTAINER).remove(),cancelButton.clone().appendTo(tabFooters)}loadForm(){const cmid=this.getCMID(),cat=this.getCategory(),addonpage=this.getAddOnPageId(),returnurl=this.getReturnUrl();return Fragment.loadFragment("mod_quiz","add_random_question_form",this.getContextId(),{addonpage:addonpage,cat:cat,returnurl:returnurl,cmid:cmid}).then(((html,js)=>{const form=(0,_jquery.default)(html),existingCategoryTabContent=form.find(SELECTORS.EXISTING_CATEGORY_TAB),existingCategoryTab=this.getBody().find(SELECTORS.EXISTING_CATEGORY_CONTAINER),newCategoryTabContent=form.find(SELECTORS.NEW_CATEGORY_TAB),newCategoryTab=this.getBody().find(SELECTORS.NEW_CATEGORY_CONTAINER);this.moveContentIntoTab(existingCategoryTabContent,existingCategoryTab),this.moveContentIntoTab(newCategoryTabContent,newCategoryTab),this.moveTabsIntoTabContent(form),Templates.replaceNode(this.getBody().find(SELECTORS.TAB_CONTENT),form,js)})).then((()=>{FormChangeChecker.disableAllChecks(),this.getBody()[0].addEventListener("click",(e=>{var _document$querySelect;if(!e.target.closest(SELECTORS.SUBMIT_BUTTON_ELEMENT))return;e.preventDefault();const randomcount=document.querySelector(SELECTORS.SELECT_NUMBER_TO_ADD).value,filtercondition=null===(_document$querySelect=document.querySelector(SELECTORS.FILTER_CONDITION_ELEMENT).dataset)||void 0===_document$querySelect?void 0:_document$querySelect.filtercondition;if(e.target.closest(SELECTORS.ADD_RANDOM_BUTTON))return void this.addQuestions(cmid,addonpage,randomcount,filtercondition,"","");e.target.closest(SELECTORS.ADD_NEW_CATEGORY_BUTTON)&&this.addQuestions(cmid,addonpage,randomcount,filtercondition,document.querySelector(SELECTORS.NEW_CATEGORY_ELEMENT).value,document.querySelector(SELECTORS.PARENT_CATEGORY_ELEMENT).value)}))})).catch(Notification.exception)}async addQuestions(cmid,addonpage,randomcount,filtercondition,newcategory,parentcategory){new _pending.default("mod-quiz/modal_add_random_questions");const call={methodname:"mod_quiz_add_random_questions",args:{cmid:cmid,addonpage:addonpage,randomcount:randomcount,filtercondition:filtercondition,newcategory:newcategory,parentcategory:parentcategory}};try{const response=await(0,_ajax.call)([call])[0],form=document.querySelector(SELECTORS.FORM_ELEMENT);form.querySelector(SELECTORS.MESSAGE_INPUT).value=response.message,form.submit()}catch(e){Notification.exception(e)}}show(){super.show(this),this.loadedForm||(this.loadForm(window.location.search),this.loadedForm=!0)}}return _exports.default=ModalAddRandomQuestion,_defineProperty(ModalAddRandomQuestion,"TYPE","mod_quiz-quiz-add-random-question"),_defineProperty(ModalAddRandomQuestion,"TEMPLATE","mod_quiz/modal_add_random_question"),ModalAddRandomQuestion.registerModalType(),_exports.default})); //# sourceMappingURL=modal_add_random_question.min.js.map \ No newline at end of file diff --git a/mod/quiz/amd/build/modal_add_random_question.min.js.map b/mod/quiz/amd/build/modal_add_random_question.min.js.map index f8588682a52..3c07c771bd7 100644 --- a/mod/quiz/amd/build/modal_add_random_question.min.js.map +++ b/mod/quiz/amd/build/modal_add_random_question.min.js.map @@ -1 +1 @@ -{"version":3,"file":"modal_add_random_question.min.js","sources":["../src/modal_add_random_question.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 * Contain the logic for the add random question modal.\n *\n * @module mod_quiz/modal_add_random_question\n * @copyright 2018 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport Modal from 'core/modal';\nimport * as Notification from 'core/notification';\nimport * as Fragment from 'core/fragment';\nimport * as Templates from 'core/templates';\nimport * as FormChangeChecker from 'core_form/changechecker';\nimport {call as fetchMany} from 'core/ajax';\nimport Pending from 'core/pending';\n\nconst SELECTORS = {\n EXISTING_CATEGORY_CONTAINER: '[data-region=\"existing-category-container\"]',\n EXISTING_CATEGORY_TAB: '#id_existingcategoryheader',\n NEW_CATEGORY_CONTAINER: '[data-region=\"new-category-container\"]',\n NEW_CATEGORY_TAB: '#id_newcategoryheader',\n TAB_CONTENT: '[data-region=\"tab-content\"]',\n ADD_ON_PAGE_FORM_ELEMENT: '[name=\"addonpage\"]',\n ADD_RANDOM_BUTTON: 'input[type=\"submit\"][name=\"addrandom\"]',\n ADD_NEW_CATEGORY_BUTTON: 'input[type=\"submit\"][name=\"newcategory\"]',\n SUBMIT_BUTTON_ELEMENT: 'input[type=\"submit\"][name=\"addrandom\"], input[type=\"submit\"][name=\"newcategory\"]',\n FORM_HEADER: 'legend',\n SELECT_NUMBER_TO_ADD: '#menurandomcount',\n NEW_CATEGORY_ELEMENT: '#categoryname',\n PARENT_CATEGORY_ELEMENT: '#parentcategory',\n FILTER_CONDITION_ELEMENT: '[data-filtercondition]',\n FORM_ELEMENT: '#add_random_question_form',\n MESSAGE_INPUT: '[name=\"message\"]',\n};\n\nexport default class ModalAddRandomQuestion extends Modal {\n static TYPE = 'mod_quiz-quiz-add-random-question';\n static TEMPLATE = 'mod_quiz/modal_add_random_question';\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n constructor(root) {\n super(root);\n this.contextId = null;\n this.addOnPageId = null;\n this.category = null;\n this.returnUrl = null;\n this.cmid = null;\n this.loadedForm = false;\n }\n\n /**\n * Save the Moodle context id that the question bank is being\n * rendered in.\n *\n * @method setContextId\n * @param {int} id\n */\n setContextId(id) {\n this.contextId = id;\n }\n\n /**\n * Retrieve the saved Moodle context id.\n *\n * @method getContextId\n * @return {int}\n */\n getContextId() {\n return this.contextId;\n }\n\n /**\n * Set the id of the page that the question should be added to\n * when the user clicks the add to quiz link.\n *\n * @method setAddOnPageId\n * @param {int} id\n */\n setAddOnPageId(id) {\n this.addOnPageId = id;\n this.getBody().find(SELECTORS.ADD_ON_PAGE_FORM_ELEMENT).val(id);\n }\n\n /**\n * Returns the saved page id for the question to be added to.\n *\n * @method getAddOnPageId\n * @return {int}\n */\n getAddOnPageId() {\n return this.addOnPageId;\n }\n\n /**\n * Set the category for this form. The category is a comma separated\n * category id and category context id.\n *\n * @method setCategory\n * @param {string} category\n */\n setCategory(category) {\n this.category = category;\n }\n\n /**\n * Returns the saved category.\n *\n * @method getCategory\n * @return {string}\n */\n getCategory() {\n return this.category;\n }\n\n /**\n * Set the return URL for the form.\n *\n * @method setReturnUrl\n * @param {string} url\n */\n setReturnUrl(url) {\n this.returnUrl = url;\n }\n\n /**\n * Returns the return URL for the form.\n *\n * @method getReturnUrl\n * @return {string}\n */\n getReturnUrl() {\n return this.returnUrl;\n }\n\n /**\n * Set the course module id for the form.\n *\n * @method setCMID\n * @param {int} id\n */\n setCMID(id) {\n this.cmid = id;\n }\n\n /**\n * Returns the course module id for the form.\n *\n * @method getCMID\n * @return {int}\n */\n getCMID() {\n return this.cmid;\n }\n\n /**\n * Moves a given form element inside (a child of) a given tab element.\n *\n * Hides the 'legend' (e.g. header) element of the form element because the\n * tab has the name.\n *\n * Moves the submit button into a footer element at the bottom of the form\n * element for styling purposes.\n *\n * @method moveContentIntoTab\n * @param {jquery} tabContent The form element to move into the tab.\n * @param {jquey} tabElement The tab element for the form element to move into.\n */\n moveContentIntoTab(tabContent, tabElement) {\n // Hide the header because the tabs show us which part of the form we're\n // looking at.\n tabContent.find(SELECTORS.FORM_HEADER).addClass('hidden');\n // Move the element inside a tab.\n tabContent.wrap(tabElement);\n }\n\n /**\n * Empty the tab content container and move all tabs from the form into the\n * tab container element.\n *\n * @method moveTabsIntoTabContent\n * @param {jquery} form The form element.\n */\n moveTabsIntoTabContent(form) {\n // Empty it to remove the loading icon.\n const tabContent = this.getBody().find(SELECTORS.TAB_CONTENT).empty();\n // Make sure all tabs are inside the tab content element.\n form.find('[role=\"tabpanel\"]').wrapAll(tabContent);\n }\n\n /**\n * Make sure all of the tabs have a cancel button in their fotter to sit along\n * side the submit button.\n *\n * @method moveCancelButtonToTabs\n * @param {jquey} form The form element.\n */\n moveCancelButtonToTabs(form) {\n const cancelButton = form.find(SELECTORS.CANCEL_BUTTON_ELEMENT).addClass('ml-1');\n const tabFooters = form.find('[data-region=\"footer\"]');\n // Remove the buttons container element.\n cancelButton.closest(SELECTORS.BUTTON_CONTAINER).remove();\n cancelButton.clone().appendTo(tabFooters);\n }\n\n /**\n * Load the add random question form in a fragement and perform some transformation\n * on the HTML to convert it into tabs for rendering in the modal.\n *\n * @method loadForm\n * @return {promise} Resolved with form HTML and JS.\n */\n loadForm() {\n const cmid = this.getCMID();\n const cat = this.getCategory();\n const addonpage = this.getAddOnPageId();\n const returnurl = this.getReturnUrl();\n\n return Fragment.loadFragment(\n 'mod_quiz',\n 'add_random_question_form',\n this.getContextId(),\n {\n addonpage,\n cat,\n returnurl,\n cmid,\n }\n )\n .then((html, js) =>{\n const form = $(html);\n const existingCategoryTabContent = form.find(SELECTORS.EXISTING_CATEGORY_TAB);\n const existingCategoryTab = this.getBody().find(SELECTORS.EXISTING_CATEGORY_CONTAINER);\n const newCategoryTabContent = form.find(SELECTORS.NEW_CATEGORY_TAB);\n const newCategoryTab = this.getBody().find(SELECTORS.NEW_CATEGORY_CONTAINER);\n\n // Transform the form into tabs for better rendering in the modal.\n this.moveContentIntoTab(existingCategoryTabContent, existingCategoryTab);\n this.moveContentIntoTab(newCategoryTabContent, newCategoryTab);\n this.moveTabsIntoTabContent(form);\n\n Templates.replaceNode(this.getBody().find(SELECTORS.TAB_CONTENT), form, js);\n return;\n })\n .then(() => {\n // Make sure the form change checker is disabled otherwise it'll stop the user from navigating away from the\n // page once the modal is hidden.\n FormChangeChecker.disableAllChecks();\n\n // Add question to quiz.\n this.getBody()[0].addEventListener('click', (e) => {\n const button = e.target.closest(SELECTORS.SUBMIT_BUTTON_ELEMENT);\n if (!button) {\n return;\n }\n e.preventDefault();\n\n const randomcount = document.querySelector(SELECTORS.SELECT_NUMBER_TO_ADD).value;\n const filtercondition = document.querySelector(SELECTORS.FILTER_CONDITION_ELEMENT).dataset?.filtercondition;\n\n // Add Random questions if the add random button was clicked.\n const addRandomButton = e.target.closest(SELECTORS.ADD_RANDOM_BUTTON);\n if (addRandomButton) {\n this.addQuestions(cmid, addonpage, randomcount, filtercondition, '', '');\n return;\n }\n // Add new category if the add category button was clicked.\n const addCategoryButton = e.target.closest(SELECTORS.ADD_NEW_CATEGORY_BUTTON);\n if (addCategoryButton) {\n this.addQuestions(\n cmid,\n addonpage,\n randomcount,\n filtercondition,\n document.querySelector(SELECTORS.NEW_CATEGORY_ELEMENT).value,\n document.querySelector(SELECTORS.PARENT_CATEGORY_ELEMENT).value\n );\n return;\n }\n });\n })\n .catch(Notification.exception);\n }\n\n /**\n * Call web service function to add random questions\n *\n * @param {number} cmid course module id\n * @param {number} addonpage the page where random questions will be added to\n * @param {number} randomcount Number of random questions\n * @param {string} filtercondition Filter condition\n * @param {string} newcategory add new category\n * @param {string} parentcategory parent category of new category\n */\n async addQuestions(\n cmid,\n addonpage,\n randomcount,\n filtercondition,\n newcategory,\n parentcategory\n ) {\n // We do not need to resolve this Pending because the form submission will result in a page redirect.\n new Pending('mod-quiz/modal_add_random_questions');\n const call = {\n methodname: 'mod_quiz_add_random_questions',\n args: {\n cmid,\n addonpage,\n randomcount,\n filtercondition,\n newcategory,\n parentcategory,\n }\n };\n try {\n const response = await fetchMany([call])[0];\n const form = document.querySelector(SELECTORS.FORM_ELEMENT);\n const messageInput = form.querySelector(SELECTORS.MESSAGE_INPUT);\n messageInput.value = response.message;\n form.submit();\n } catch (e) {\n Notification.exception(e);\n }\n }\n\n /**\n * Override the modal show function to load the form when this modal is first\n * shown.\n *\n * @method show\n */\n show() {\n super.show(this);\n\n if (!this.loadedForm) {\n this.loadForm(window.location.search);\n this.loadedForm = true;\n }\n }\n}\n\nModalAddRandomQuestion.registerModalType();\n"],"names":["SELECTORS","EXISTING_CATEGORY_CONTAINER","EXISTING_CATEGORY_TAB","NEW_CATEGORY_CONTAINER","NEW_CATEGORY_TAB","TAB_CONTENT","ADD_ON_PAGE_FORM_ELEMENT","ADD_RANDOM_BUTTON","ADD_NEW_CATEGORY_BUTTON","SUBMIT_BUTTON_ELEMENT","FORM_HEADER","SELECT_NUMBER_TO_ADD","NEW_CATEGORY_ELEMENT","PARENT_CATEGORY_ELEMENT","FILTER_CONDITION_ELEMENT","FORM_ELEMENT","MESSAGE_INPUT","ModalAddRandomQuestion","Modal","constructor","root","contextId","addOnPageId","category","returnUrl","cmid","loadedForm","setContextId","id","getContextId","this","setAddOnPageId","getBody","find","val","getAddOnPageId","setCategory","getCategory","setReturnUrl","url","getReturnUrl","setCMID","getCMID","moveContentIntoTab","tabContent","tabElement","addClass","wrap","moveTabsIntoTabContent","form","empty","wrapAll","moveCancelButtonToTabs","cancelButton","CANCEL_BUTTON_ELEMENT","tabFooters","closest","BUTTON_CONTAINER","remove","clone","appendTo","loadForm","cat","addonpage","returnurl","Fragment","loadFragment","then","html","js","existingCategoryTabContent","existingCategoryTab","newCategoryTabContent","newCategoryTab","Templates","replaceNode","FormChangeChecker","disableAllChecks","addEventListener","e","target","preventDefault","randomcount","document","querySelector","value","filtercondition","dataset","_document$querySelect","addQuestions","catch","Notification","exception","newcategory","parentcategory","Pending","call","methodname","args","response","message","submit","show","window","location","search","registerModalType"],"mappings":"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"} \ No newline at end of file +{"version":3,"file":"modal_add_random_question.min.js","sources":["../src/modal_add_random_question.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 * Contain the logic for the add random question modal.\n *\n * @module mod_quiz/modal_add_random_question\n * @copyright 2018 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport Modal from './add_question_modal';\nimport * as Notification from 'core/notification';\nimport * as Fragment from 'core/fragment';\nimport * as Templates from 'core/templates';\nimport * as FormChangeChecker from 'core_form/changechecker';\nimport {call as fetchMany} from 'core/ajax';\nimport Pending from 'core/pending';\n\nconst SELECTORS = {\n EXISTING_CATEGORY_CONTAINER: '[data-region=\"existing-category-container\"]',\n EXISTING_CATEGORY_TAB: '#id_existingcategoryheader',\n NEW_CATEGORY_CONTAINER: '[data-region=\"new-category-container\"]',\n NEW_CATEGORY_TAB: '#id_newcategoryheader',\n TAB_CONTENT: '[data-region=\"tab-content\"]',\n ADD_ON_PAGE_FORM_ELEMENT: '[name=\"addonpage\"]',\n ADD_RANDOM_BUTTON: 'input[type=\"submit\"][name=\"addrandom\"]',\n ADD_NEW_CATEGORY_BUTTON: 'input[type=\"submit\"][name=\"newcategory\"]',\n SUBMIT_BUTTON_ELEMENT: 'input[type=\"submit\"][name=\"addrandom\"], input[type=\"submit\"][name=\"newcategory\"]',\n FORM_HEADER: 'legend',\n SELECT_NUMBER_TO_ADD: '#menurandomcount',\n NEW_CATEGORY_ELEMENT: '#categoryname',\n PARENT_CATEGORY_ELEMENT: '#parentcategory',\n FILTER_CONDITION_ELEMENT: '[data-filtercondition]',\n FORM_ELEMENT: '#add_random_question_form',\n MESSAGE_INPUT: '[name=\"message\"]',\n};\n\nexport default class ModalAddRandomQuestion extends Modal {\n static TYPE = 'mod_quiz-quiz-add-random-question';\n static TEMPLATE = 'mod_quiz/modal_add_random_question';\n\n /**\n * Create the add random question modal.\n *\n * @param {Number} contextId Current context id.\n * @param {string} category Category id and category context id comma separated.\n * @param {string} returnUrl URL to return to after form submission.\n * @param {Number} cmid Current course module id.\n * @param {boolean} showNewCategory Display the New category tab when selecting random questions.\n */\n static init(contextId, category, returnUrl, cmid, showNewCategory = true) {\n const selector = '.menu [data-action=\"addarandomquestion\"]';\n document.addEventListener('click', (e) => {\n const trigger = e.target.closest(selector);\n if (!trigger) {\n return;\n }\n e.preventDefault();\n\n ModalAddRandomQuestion.create({\n contextId,\n category,\n returnUrl,\n cmid,\n\n title: trigger.dataset.header,\n addOnPage: trigger.dataset.addonpage,\n\n templateContext: {\n hidden: showNewCategory,\n },\n });\n });\n }\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n constructor(root) {\n super(root);\n this.category = null;\n this.returnUrl = null;\n this.cmid = null;\n this.loadedForm = false;\n }\n\n configure(modalConfig) {\n this.setCategory(modalConfig.category);\n this.setReturnUrl(modalConfig.returnUrl);\n this.setCMID(modalConfig.cmid);\n\n super.configure(modalConfig);\n }\n\n /**\n * Set the id of the page that the question should be added to\n * when the user clicks the add to quiz link.\n *\n * @method setAddOnPageId\n * @param {int} id\n */\n setAddOnPageId(id) {\n super.setAddOnPageId(id);\n this.getBody().find(SELECTORS.ADD_ON_PAGE_FORM_ELEMENT).val(id);\n }\n\n /**\n * Set the category for this form. The category is a comma separated\n * category id and category context id.\n *\n * @method setCategory\n * @param {string} category\n */\n setCategory(category) {\n this.category = category;\n }\n\n /**\n * Returns the saved category.\n *\n * @method getCategory\n * @return {string}\n */\n getCategory() {\n return this.category;\n }\n\n /**\n * Set the return URL for the form.\n *\n * @method setReturnUrl\n * @param {string} url\n */\n setReturnUrl(url) {\n this.returnUrl = url;\n }\n\n /**\n * Returns the return URL for the form.\n *\n * @method getReturnUrl\n * @return {string}\n */\n getReturnUrl() {\n return this.returnUrl;\n }\n\n /**\n * Set the course module id for the form.\n *\n * @method setCMID\n * @param {Number} id\n */\n setCMID(id) {\n this.cmid = id;\n }\n\n /**\n * Returns the course module id for the form.\n *\n * @method getCMID\n * @return {Number}\n */\n getCMID() {\n return this.cmid;\n }\n\n /**\n * Moves a given form element inside (a child of) a given tab element.\n *\n * Hides the 'legend' (e.g. header) element of the form element because the\n * tab has the name.\n *\n * Moves the submit button into a footer element at the bottom of the form\n * element for styling purposes.\n *\n * @method moveContentIntoTab\n * @param {jquery} tabContent The form element to move into the tab.\n * @param {jquey} tabElement The tab element for the form element to move into.\n */\n moveContentIntoTab(tabContent, tabElement) {\n // Hide the header because the tabs show us which part of the form we're\n // looking at.\n tabContent.find(SELECTORS.FORM_HEADER).addClass('hidden');\n // Move the element inside a tab.\n tabContent.wrap(tabElement);\n }\n\n /**\n * Empty the tab content container and move all tabs from the form into the\n * tab container element.\n *\n * @method moveTabsIntoTabContent\n * @param {jquery} form The form element.\n */\n moveTabsIntoTabContent(form) {\n // Empty it to remove the loading icon.\n const tabContent = this.getBody().find(SELECTORS.TAB_CONTENT).empty();\n // Make sure all tabs are inside the tab content element.\n form.find('[role=\"tabpanel\"]').wrapAll(tabContent);\n }\n\n /**\n * Make sure all of the tabs have a cancel button in their fotter to sit along\n * side the submit button.\n *\n * @method moveCancelButtonToTabs\n * @param {jquey} form The form element.\n */\n moveCancelButtonToTabs(form) {\n const cancelButton = form.find(SELECTORS.CANCEL_BUTTON_ELEMENT).addClass('ml-1');\n const tabFooters = form.find('[data-region=\"footer\"]');\n // Remove the buttons container element.\n cancelButton.closest(SELECTORS.BUTTON_CONTAINER).remove();\n cancelButton.clone().appendTo(tabFooters);\n }\n\n /**\n * Load the add random question form in a fragement and perform some transformation\n * on the HTML to convert it into tabs for rendering in the modal.\n *\n * @method loadForm\n * @return {promise} Resolved with form HTML and JS.\n */\n loadForm() {\n const cmid = this.getCMID();\n const cat = this.getCategory();\n const addonpage = this.getAddOnPageId();\n const returnurl = this.getReturnUrl();\n\n return Fragment.loadFragment(\n 'mod_quiz',\n 'add_random_question_form',\n this.getContextId(),\n {\n addonpage,\n cat,\n returnurl,\n cmid,\n }\n )\n .then((html, js) =>{\n const form = $(html);\n const existingCategoryTabContent = form.find(SELECTORS.EXISTING_CATEGORY_TAB);\n const existingCategoryTab = this.getBody().find(SELECTORS.EXISTING_CATEGORY_CONTAINER);\n const newCategoryTabContent = form.find(SELECTORS.NEW_CATEGORY_TAB);\n const newCategoryTab = this.getBody().find(SELECTORS.NEW_CATEGORY_CONTAINER);\n\n // Transform the form into tabs for better rendering in the modal.\n this.moveContentIntoTab(existingCategoryTabContent, existingCategoryTab);\n this.moveContentIntoTab(newCategoryTabContent, newCategoryTab);\n this.moveTabsIntoTabContent(form);\n\n Templates.replaceNode(this.getBody().find(SELECTORS.TAB_CONTENT), form, js);\n return;\n })\n .then(() => {\n // Make sure the form change checker is disabled otherwise it'll stop the user from navigating away from the\n // page once the modal is hidden.\n FormChangeChecker.disableAllChecks();\n\n // Add question to quiz.\n this.getBody()[0].addEventListener('click', (e) => {\n const button = e.target.closest(SELECTORS.SUBMIT_BUTTON_ELEMENT);\n if (!button) {\n return;\n }\n e.preventDefault();\n\n const randomcount = document.querySelector(SELECTORS.SELECT_NUMBER_TO_ADD).value;\n const filtercondition = document.querySelector(SELECTORS.FILTER_CONDITION_ELEMENT).dataset?.filtercondition;\n\n // Add Random questions if the add random button was clicked.\n const addRandomButton = e.target.closest(SELECTORS.ADD_RANDOM_BUTTON);\n if (addRandomButton) {\n this.addQuestions(cmid, addonpage, randomcount, filtercondition, '', '');\n return;\n }\n // Add new category if the add category button was clicked.\n const addCategoryButton = e.target.closest(SELECTORS.ADD_NEW_CATEGORY_BUTTON);\n if (addCategoryButton) {\n this.addQuestions(\n cmid,\n addonpage,\n randomcount,\n filtercondition,\n document.querySelector(SELECTORS.NEW_CATEGORY_ELEMENT).value,\n document.querySelector(SELECTORS.PARENT_CATEGORY_ELEMENT).value\n );\n return;\n }\n });\n })\n .catch(Notification.exception);\n }\n\n /**\n * Call web service function to add random questions\n *\n * @param {number} cmid course module id\n * @param {number} addonpage the page where random questions will be added to\n * @param {number} randomcount Number of random questions\n * @param {string} filtercondition Filter condition\n * @param {string} newcategory add new category\n * @param {string} parentcategory parent category of new category\n */\n async addQuestions(\n cmid,\n addonpage,\n randomcount,\n filtercondition,\n newcategory,\n parentcategory\n ) {\n // We do not need to resolve this Pending because the form submission will result in a page redirect.\n new Pending('mod-quiz/modal_add_random_questions');\n const call = {\n methodname: 'mod_quiz_add_random_questions',\n args: {\n cmid,\n addonpage,\n randomcount,\n filtercondition,\n newcategory,\n parentcategory,\n }\n };\n try {\n const response = await fetchMany([call])[0];\n const form = document.querySelector(SELECTORS.FORM_ELEMENT);\n const messageInput = form.querySelector(SELECTORS.MESSAGE_INPUT);\n messageInput.value = response.message;\n form.submit();\n } catch (e) {\n Notification.exception(e);\n }\n }\n\n /**\n * Override the modal show function to load the form when this modal is first\n * shown.\n *\n * @method show\n */\n show() {\n super.show(this);\n\n if (!this.loadedForm) {\n this.loadForm(window.location.search);\n this.loadedForm = true;\n }\n }\n}\n\nModalAddRandomQuestion.registerModalType();\n"],"names":["SELECTORS","EXISTING_CATEGORY_CONTAINER","EXISTING_CATEGORY_TAB","NEW_CATEGORY_CONTAINER","NEW_CATEGORY_TAB","TAB_CONTENT","ADD_ON_PAGE_FORM_ELEMENT","ADD_RANDOM_BUTTON","ADD_NEW_CATEGORY_BUTTON","SUBMIT_BUTTON_ELEMENT","FORM_HEADER","SELECT_NUMBER_TO_ADD","NEW_CATEGORY_ELEMENT","PARENT_CATEGORY_ELEMENT","FILTER_CONDITION_ELEMENT","FORM_ELEMENT","MESSAGE_INPUT","ModalAddRandomQuestion","Modal","contextId","category","returnUrl","cmid","showNewCategory","document","addEventListener","e","trigger","target","closest","preventDefault","create","title","dataset","header","addOnPage","addonpage","templateContext","hidden","constructor","root","loadedForm","configure","modalConfig","setCategory","setReturnUrl","setCMID","setAddOnPageId","id","getBody","find","val","getCategory","this","url","getReturnUrl","getCMID","moveContentIntoTab","tabContent","tabElement","addClass","wrap","moveTabsIntoTabContent","form","empty","wrapAll","moveCancelButtonToTabs","cancelButton","CANCEL_BUTTON_ELEMENT","tabFooters","BUTTON_CONTAINER","remove","clone","appendTo","loadForm","cat","getAddOnPageId","returnurl","Fragment","loadFragment","getContextId","then","html","js","existingCategoryTabContent","existingCategoryTab","newCategoryTabContent","newCategoryTab","Templates","replaceNode","FormChangeChecker","disableAllChecks","randomcount","querySelector","value","filtercondition","_document$querySelect","addQuestions","catch","Notification","exception","newcategory","parentcategory","Pending","call","methodname","args","response","message","submit","show","window","location","search","registerModalType"],"mappings":"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"} \ No newline at end of file diff --git a/mod/quiz/amd/build/modal_quiz_question_bank.min.js b/mod/quiz/amd/build/modal_quiz_question_bank.min.js index d9285224524..041d386e60e 100644 --- a/mod/quiz/amd/build/modal_quiz_question_bank.min.js +++ b/mod/quiz/amd/build/modal_quiz_question_bank.min.js @@ -1,3 +1,3 @@ -define("mod_quiz/modal_quiz_question_bank",["exports","jquery","core/modal","core/fragment","core_form/changechecker","core/modal_events"],(function(_exports,_jquery,_modal,Fragment,FormChangeChecker,ModalEvents){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_jquery=_interopRequireDefault(_jquery),_modal=_interopRequireDefault(_modal),Fragment=_interopRequireWildcard(Fragment),FormChangeChecker=_interopRequireWildcard(FormChangeChecker),ModalEvents=_interopRequireWildcard(ModalEvents);const SELECTORS_ADD_TO_QUIZ_CONTAINER="td.addtoquizaction",SELECTORS_ANCHOR="a[href]",SELECTORS_PREVIEW_CONTAINER="td.previewaction",SELECTORS_ADD_QUESTIONS_FORM="form#questionsubmit",SELECTORS_SORTERS=".sorters";class ModalQuizQuestionBank extends _modal.default{constructor(root){super(root),this.contextId=null,this.addOnPageId=null}setContextId(id){this.contextId=id}getContextId(){return this.contextId}setAddOnPageId(id){this.addOnPageId=id}getAddOnPageId(){return this.addOnPageId}show(){return this.reloadBodyContent(window.location.search),super.show(this)}reloadBodyContent(querystring){this.setBody(Fragment.loadFragment("mod_quiz","quiz_question_bank",this.getContextId(),{querystring:querystring}))}handleAddToQuizEvent(e,anchorElement){const href=new URL(anchorElement.attr("href"));href.searchParams.set("addonpage",this.getAddOnPageId()),anchorElement.attr("href",href)}handlePreviewContainerEvent(e,anchorElement){window.openpopup(e,{url:anchorElement.attr("href"),name:"questionpreview",options:["height=600","width=800","top=0","left=0","menubar=0","location=0","scrollbars","resizable","toolbar","status","directories=0","fullscreen=0","dependent"].join(",")})}registerEventListeners(){super.registerEventListeners(this),this.getModal().on("submit",SELECTORS_ADD_QUESTIONS_FORM,(e=>{const formElement=(0,_jquery.default)(e.currentTarget);(0,_jquery.default)("").attr("type","hidden").attr("name","addonpage").attr("value",this.getAddOnPageId()).appendTo(formElement)})),this.getModal().on("click",SELECTORS_ANCHOR,(e=>{const anchorElement=(0,_jquery.default)(e.currentTarget);anchorElement.closest(SELECTORS_ADD_TO_QUIZ_CONTAINER).length?this.handleAddToQuizEvent(e,anchorElement):anchorElement.closest(SELECTORS_PREVIEW_CONTAINER).length?this.handlePreviewContainerEvent(e,anchorElement):anchorElement.closest(SELECTORS_SORTERS).length||(e.preventDefault(),this.reloadBodyContent(anchorElement.prop("search")))})),this.getRoot().on(ModalEvents.bodyRendered,(()=>{FormChangeChecker.disableAllChecks()}))}}var obj,key,value;return _exports.default=ModalQuizQuestionBank,value="mod_quiz-quiz-question-bank",(key="TYPE")in(obj=ModalQuizQuestionBank)?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,ModalQuizQuestionBank.registerModalType(),_exports.default})); +define("mod_quiz/modal_quiz_question_bank",["exports","jquery","./add_question_modal","core/fragment","core_form/changechecker","core/modal_events"],(function(_exports,_jquery,_add_question_modal,Fragment,FormChangeChecker,ModalEvents){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_jquery=_interopRequireDefault(_jquery),_add_question_modal=_interopRequireDefault(_add_question_modal),Fragment=_interopRequireWildcard(Fragment),FormChangeChecker=_interopRequireWildcard(FormChangeChecker),ModalEvents=_interopRequireWildcard(ModalEvents);const SELECTORS_ADD_TO_QUIZ_CONTAINER="td.addtoquizaction",SELECTORS_ANCHOR="a[href]",SELECTORS_PREVIEW_CONTAINER="td.previewaction",SELECTORS_ADD_QUESTIONS_FORM="form#questionsubmit",SELECTORS_SORTERS=".sorters";class ModalQuizQuestionBank extends _add_question_modal.default{static init(contextId){document.addEventListener("click",(e=>{const trigger=e.target.closest('.menu [data-action="questionbank"]');trigger&&(e.preventDefault(),ModalQuizQuestionBank.create({contextId:contextId,title:trigger.dataset.header,addOnPage:trigger.dataset.addonpage,templateContext:{hidden:!0},large:!0}))}))}show(){return this.reloadBodyContent(window.location.search),super.show(this)}reloadBodyContent(querystring){this.setBody(Fragment.loadFragment("mod_quiz","quiz_question_bank",this.getContextId(),{querystring:querystring}))}handleAddToQuizEvent(e,anchorElement){const href=new URL(anchorElement.attr("href"));href.searchParams.set("addonpage",this.getAddOnPageId()),anchorElement.attr("href",href)}handlePreviewContainerEvent(e,anchorElement){window.openpopup(e,{url:anchorElement.attr("href"),name:"questionpreview",options:["height=600","width=800","top=0","left=0","menubar=0","location=0","scrollbars","resizable","toolbar","status","directories=0","fullscreen=0","dependent"].join(",")})}registerEventListeners(){super.registerEventListeners(this),this.getModal().on("submit",SELECTORS_ADD_QUESTIONS_FORM,(e=>{const formElement=(0,_jquery.default)(e.currentTarget);(0,_jquery.default)("").attr("type","hidden").attr("name","addonpage").attr("value",this.getAddOnPageId()).appendTo(formElement)})),this.getModal().on("click",SELECTORS_ANCHOR,(e=>{const anchorElement=(0,_jquery.default)(e.currentTarget);anchorElement.closest(SELECTORS_ADD_TO_QUIZ_CONTAINER).length?this.handleAddToQuizEvent(e,anchorElement):anchorElement.closest(SELECTORS_PREVIEW_CONTAINER).length?this.handlePreviewContainerEvent(e,anchorElement):anchorElement.closest(SELECTORS_SORTERS).length||(e.preventDefault(),this.reloadBodyContent(anchorElement.prop("search")))})),this.getRoot().on(ModalEvents.bodyRendered,(()=>{FormChangeChecker.disableAllChecks()}))}}var obj,key,value;return _exports.default=ModalQuizQuestionBank,value="mod_quiz-quiz-question-bank",(key="TYPE")in(obj=ModalQuizQuestionBank)?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,ModalQuizQuestionBank.registerModalType(),_exports.default})); //# sourceMappingURL=modal_quiz_question_bank.min.js.map \ No newline at end of file diff --git a/mod/quiz/amd/build/modal_quiz_question_bank.min.js.map b/mod/quiz/amd/build/modal_quiz_question_bank.min.js.map index 9eb5605e017..ba9479e613a 100644 --- a/mod/quiz/amd/build/modal_quiz_question_bank.min.js.map +++ b/mod/quiz/amd/build/modal_quiz_question_bank.min.js.map @@ -1 +1 @@ -{"version":3,"file":"modal_quiz_question_bank.min.js","sources":["../src/modal_quiz_question_bank.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 * Contain the logic for the question bank modal.\n *\n * @module mod_quiz/modal_quiz_question_bank\n * @copyright 2018 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport Modal from 'core/modal';\nimport * as Fragment from 'core/fragment';\nimport * as FormChangeChecker from 'core_form/changechecker';\nimport * as ModalEvents from 'core/modal_events';\n\nconst SELECTORS = {\n ADD_TO_QUIZ_CONTAINER: 'td.addtoquizaction',\n ANCHOR: 'a[href]',\n PREVIEW_CONTAINER: 'td.previewaction',\n ADD_QUESTIONS_FORM: 'form#questionsubmit',\n SORTERS: '.sorters',\n};\n\nexport default class ModalQuizQuestionBank extends Modal {\n static TYPE = 'mod_quiz-quiz-question-bank';\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n constructor(root) {\n super(root);\n\n this.contextId = null;\n this.addOnPageId = null;\n }\n\n /**\n * Save the Moodle context id that the question bank is being\n * rendered in.\n *\n * @method setContextId\n * @param {int} id\n */\n setContextId(id) {\n this.contextId = id;\n }\n\n /**\n * Retrieve the saved Moodle context id.\n *\n * @method getContextId\n * @return {int}\n */\n getContextId() {\n return this.contextId;\n }\n\n /**\n * Set the id of the page that the question should be added to\n * when the user clicks the add to quiz link.\n *\n * @method setAddOnPageId\n * @param {int} id\n */\n setAddOnPageId(id) {\n this.addOnPageId = id;\n }\n\n /**\n * Returns the saved page id for the question to be added it.\n *\n * @method getAddOnPageId\n * @return {int}\n */\n getAddOnPageId() {\n return this.addOnPageId;\n }\n\n /**\n * Override the parent show function.\n *\n * Reload the body contents when the modal is shown. The current\n * window URL is used to inform the new content that should be\n * displayed.\n *\n * @method show\n * @return {void}\n */\n show() {\n this.reloadBodyContent(window.location.search);\n return super.show(this);\n }\n\n /**\n * Replaces the current body contents with a new version of the question\n * bank.\n *\n * The contents of the question bank are generated using the provided\n * query string.\n *\n * @method reloadBodyContent\n * @param {string} querystring URL encoded string.\n */\n reloadBodyContent(querystring) {\n // Load the question bank fragment to be displayed in the modal.\n this.setBody(Fragment.loadFragment(\n 'mod_quiz',\n 'quiz_question_bank',\n this.getContextId(),\n {\n querystring,\n }\n ));\n }\n\n /**\n * Update the URL of the anchor element that the user clicked on to make\n * sure that the question is added to the correct page.\n *\n * @method handleAddToQuizEvent\n * @param {event} e A JavaScript event\n * @param {object} anchorElement The anchor element that was triggered\n */\n handleAddToQuizEvent(e, anchorElement) {\n // If the user clicks the plus icon to add the question to the page\n // directly then we need to intercept the click in order to adjust the\n // href and include the correct add on page id before the page is\n // redirected.\n const href = new URL(anchorElement.attr('href'));\n href.searchParams.set('addonpage', this.getAddOnPageId());\n anchorElement.attr('href', href);\n }\n\n /**\n * Open a popup window to show the preview of the question.\n *\n * @method handlePreviewContainerEvent\n * @param {event} e A JavaScript event\n * @param {object} anchorElement The anchor element that was triggered\n */\n handlePreviewContainerEvent(e, anchorElement) {\n const popupOptions = [\n 'height=600',\n 'width=800',\n 'top=0',\n 'left=0',\n 'menubar=0',\n 'location=0',\n 'scrollbars',\n 'resizable',\n 'toolbar',\n 'status',\n 'directories=0',\n 'fullscreen=0',\n 'dependent',\n ];\n window.openpopup(e, {\n url: anchorElement.attr('href'),\n name: 'questionpreview',\n options: popupOptions.join(',')\n });\n }\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n registerEventListeners() {\n // Apply parent event listeners.\n super.registerEventListeners(this);\n\n this.getModal().on('submit', SELECTORS.ADD_QUESTIONS_FORM, (e) => {\n // If the user clicks on the \"Add selected questions to the quiz\" button to add some questions to the page\n // then we need to intercept the submit in order to include the correct \"add on page id\" before the form is\n // submitted.\n const formElement = $(e.currentTarget);\n\n $('').attr('type', 'hidden')\n .attr('name', \"addonpage\")\n .attr('value', this.getAddOnPageId())\n .appendTo(formElement);\n });\n\n this.getModal().on('click', SELECTORS.ANCHOR, (e) => {\n const anchorElement = $(e.currentTarget);\n\n // If the anchor element was the add to quiz link.\n if (anchorElement.closest(SELECTORS.ADD_TO_QUIZ_CONTAINER).length) {\n this.handleAddToQuizEvent(e, anchorElement);\n return;\n }\n\n // If the anchor element was a preview question link.\n if (anchorElement.closest(SELECTORS.PREVIEW_CONTAINER).length) {\n this.handlePreviewContainerEvent(e, anchorElement);\n return;\n }\n\n // Sorting links have their own handler.\n if (anchorElement.closest(SELECTORS.SORTERS).length) {\n return;\n }\n\n // Anything else means reload the pop-up contents.\n e.preventDefault();\n this.reloadBodyContent(anchorElement.prop('search'));\n });\n\n // Disable the form change checker when the body is rendered.\n this.getRoot().on(ModalEvents.bodyRendered, () => {\n // Make sure the form change checker is disabled otherwise it'll stop the user from navigating away from the\n // page once the modal is hidden.\n FormChangeChecker.disableAllChecks();\n });\n }\n}\n\nModalQuizQuestionBank.registerModalType();\n"],"names":["SELECTORS","ModalQuizQuestionBank","Modal","constructor","root","contextId","addOnPageId","setContextId","id","getContextId","this","setAddOnPageId","getAddOnPageId","show","reloadBodyContent","window","location","search","super","querystring","setBody","Fragment","loadFragment","handleAddToQuizEvent","e","anchorElement","href","URL","attr","searchParams","set","handlePreviewContainerEvent","openpopup","url","name","options","join","registerEventListeners","getModal","on","formElement","currentTarget","appendTo","closest","length","preventDefault","prop","getRoot","ModalEvents","bodyRendered","FormChangeChecker","disableAllChecks","registerModalType"],"mappings":"2hDA6BMA,gCACqB,qBADrBA,iBAEM,UAFNA,4BAGiB,mBAHjBA,6BAIkB,sBAJlBA,kBAKO,iBAGQC,8BAA8BC,eAQ/CC,YAAYC,YACFA,WAEDC,UAAY,UACZC,YAAc,KAUvBC,aAAaC,SACJH,UAAYG,GASrBC,sBACWC,KAAKL,UAUhBM,eAAeH,SACNF,YAAcE,GASvBI,wBACWF,KAAKJ,YAahBO,mBACSC,kBAAkBC,OAAOC,SAASC,QAChCC,MAAML,KAAKH,MAatBI,kBAAkBK,kBAETC,QAAQC,SAASC,aAClB,WACA,qBACAZ,KAAKD,eACL,CACIU,YAAAA,eAaZI,qBAAqBC,EAAGC,qBAKdC,KAAO,IAAIC,IAAIF,cAAcG,KAAK,SACxCF,KAAKG,aAAaC,IAAI,YAAapB,KAAKE,kBACxCa,cAAcG,KAAK,OAAQF,MAU/BK,4BAA4BP,EAAGC,eAgB3BV,OAAOiB,UAAUR,EAAG,CAChBS,IAAKR,cAAcG,KAAK,QACxBM,KAAM,kBACNC,QAlBiB,CACjB,aACA,YACA,QACA,SACA,YACA,aACA,aACA,YACA,UACA,SACA,gBACA,eACA,aAKsBC,KAAK,OASnCC,+BAEUA,uBAAuB3B,WAExB4B,WAAWC,GAAG,SAAUvC,8BAA+BwB,UAIlDgB,aAAc,mBAAEhB,EAAEiB,mCAEtB,aAAab,KAAK,OAAQ,UACvBA,KAAK,OAAQ,aACbA,KAAK,QAASlB,KAAKE,kBACnB8B,SAASF,qBAGbF,WAAWC,GAAG,QAASvC,kBAAmBwB,UACrCC,eAAgB,mBAAED,EAAEiB,eAGtBhB,cAAckB,QAAQ3C,iCAAiC4C,YAClDrB,qBAAqBC,EAAGC,eAK7BA,cAAckB,QAAQ3C,6BAA6B4C,YAC9Cb,4BAA4BP,EAAGC,eAKpCA,cAAckB,QAAQ3C,mBAAmB4C,SAK7CpB,EAAEqB,sBACG/B,kBAAkBW,cAAcqB,KAAK,oBAIzCC,UAAUR,GAAGS,YAAYC,cAAc,KAGxCC,kBAAkBC,6FA/LZ,iDADGlD,6HAqMrBA,sBAAsBmD"} \ No newline at end of file +{"version":3,"file":"modal_quiz_question_bank.min.js","sources":["../src/modal_quiz_question_bank.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 * Contain the logic for the question bank modal.\n *\n * @module mod_quiz/modal_quiz_question_bank\n * @copyright 2018 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport Modal from './add_question_modal';\nimport * as Fragment from 'core/fragment';\nimport * as FormChangeChecker from 'core_form/changechecker';\nimport * as ModalEvents from 'core/modal_events';\n\nconst SELECTORS = {\n ADD_TO_QUIZ_CONTAINER: 'td.addtoquizaction',\n ANCHOR: 'a[href]',\n PREVIEW_CONTAINER: 'td.previewaction',\n ADD_QUESTIONS_FORM: 'form#questionsubmit',\n SORTERS: '.sorters',\n};\n\nexport default class ModalQuizQuestionBank extends Modal {\n static TYPE = 'mod_quiz-quiz-question-bank';\n\n /**\n * Create the question bank modal.\n *\n * @param {Number} contextId Current context id.\n */\n static init(contextId) {\n const selector = '.menu [data-action=\"questionbank\"]';\n document.addEventListener('click', (e) => {\n const trigger = e.target.closest(selector);\n if (!trigger) {\n return;\n }\n e.preventDefault();\n\n ModalQuizQuestionBank.create({\n contextId,\n title: trigger.dataset.header,\n addOnPage: trigger.dataset.addonpage,\n templateContext: {\n hidden: true,\n },\n large: true,\n });\n });\n }\n\n /**\n * Override the parent show function.\n *\n * Reload the body contents when the modal is shown. The current\n * window URL is used to inform the new content that should be\n * displayed.\n *\n * @method show\n * @return {void}\n */\n show() {\n this.reloadBodyContent(window.location.search);\n return super.show(this);\n }\n\n /**\n * Replaces the current body contents with a new version of the question\n * bank.\n *\n * The contents of the question bank are generated using the provided\n * query string.\n *\n * @method reloadBodyContent\n * @param {string} querystring URL encoded string.\n */\n reloadBodyContent(querystring) {\n // Load the question bank fragment to be displayed in the modal.\n this.setBody(Fragment.loadFragment(\n 'mod_quiz',\n 'quiz_question_bank',\n this.getContextId(),\n {\n querystring,\n }\n ));\n }\n\n /**\n * Update the URL of the anchor element that the user clicked on to make\n * sure that the question is added to the correct page.\n *\n * @method handleAddToQuizEvent\n * @param {event} e A JavaScript event\n * @param {object} anchorElement The anchor element that was triggered\n */\n handleAddToQuizEvent(e, anchorElement) {\n // If the user clicks the plus icon to add the question to the page\n // directly then we need to intercept the click in order to adjust the\n // href and include the correct add on page id before the page is\n // redirected.\n const href = new URL(anchorElement.attr('href'));\n href.searchParams.set('addonpage', this.getAddOnPageId());\n anchorElement.attr('href', href);\n }\n\n /**\n * Open a popup window to show the preview of the question.\n *\n * @method handlePreviewContainerEvent\n * @param {event} e A JavaScript event\n * @param {object} anchorElement The anchor element that was triggered\n */\n handlePreviewContainerEvent(e, anchorElement) {\n const popupOptions = [\n 'height=600',\n 'width=800',\n 'top=0',\n 'left=0',\n 'menubar=0',\n 'location=0',\n 'scrollbars',\n 'resizable',\n 'toolbar',\n 'status',\n 'directories=0',\n 'fullscreen=0',\n 'dependent',\n ];\n window.openpopup(e, {\n url: anchorElement.attr('href'),\n name: 'questionpreview',\n options: popupOptions.join(',')\n });\n }\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n registerEventListeners() {\n // Apply parent event listeners.\n super.registerEventListeners(this);\n\n this.getModal().on('submit', SELECTORS.ADD_QUESTIONS_FORM, (e) => {\n // If the user clicks on the \"Add selected questions to the quiz\" button to add some questions to the page\n // then we need to intercept the submit in order to include the correct \"add on page id\" before the form is\n // submitted.\n const formElement = $(e.currentTarget);\n\n $('').attr('type', 'hidden')\n .attr('name', \"addonpage\")\n .attr('value', this.getAddOnPageId())\n .appendTo(formElement);\n });\n\n this.getModal().on('click', SELECTORS.ANCHOR, (e) => {\n const anchorElement = $(e.currentTarget);\n\n // If the anchor element was the add to quiz link.\n if (anchorElement.closest(SELECTORS.ADD_TO_QUIZ_CONTAINER).length) {\n this.handleAddToQuizEvent(e, anchorElement);\n return;\n }\n\n // If the anchor element was a preview question link.\n if (anchorElement.closest(SELECTORS.PREVIEW_CONTAINER).length) {\n this.handlePreviewContainerEvent(e, anchorElement);\n return;\n }\n\n // Sorting links have their own handler.\n if (anchorElement.closest(SELECTORS.SORTERS).length) {\n return;\n }\n\n // Anything else means reload the pop-up contents.\n e.preventDefault();\n this.reloadBodyContent(anchorElement.prop('search'));\n });\n\n // Disable the form change checker when the body is rendered.\n this.getRoot().on(ModalEvents.bodyRendered, () => {\n // Make sure the form change checker is disabled otherwise it'll stop the user from navigating away from the\n // page once the modal is hidden.\n FormChangeChecker.disableAllChecks();\n });\n }\n}\n\nModalQuizQuestionBank.registerModalType();\n"],"names":["SELECTORS","ModalQuizQuestionBank","Modal","contextId","document","addEventListener","e","trigger","target","closest","preventDefault","create","title","dataset","header","addOnPage","addonpage","templateContext","hidden","large","show","reloadBodyContent","window","location","search","super","this","querystring","setBody","Fragment","loadFragment","getContextId","handleAddToQuizEvent","anchorElement","href","URL","attr","searchParams","set","getAddOnPageId","handlePreviewContainerEvent","openpopup","url","name","options","join","registerEventListeners","getModal","on","formElement","currentTarget","appendTo","length","prop","getRoot","ModalEvents","bodyRendered","FormChangeChecker","disableAllChecks","registerModalType"],"mappings":"4kDA6BMA,gCACqB,qBADrBA,iBAEM,UAFNA,4BAGiB,mBAHjBA,6BAIkB,sBAJlBA,kBAKO,iBAGQC,8BAA8BC,wCAQnCC,WAERC,SAASC,iBAAiB,SAAUC,UAC1BC,QAAUD,EAAEE,OAAOC,QAFZ,sCAGRF,UAGLD,EAAEI,iBAEFT,sBAAsBU,OAAO,CACzBR,UAAAA,UACAS,MAAOL,QAAQM,QAAQC,OACvBC,UAAWR,QAAQM,QAAQG,UAC3BC,gBAAiB,CACbC,QAAQ,GAEZC,OAAO,QAenBC,mBACSC,kBAAkBC,OAAOC,SAASC,QAChCC,MAAML,KAAKM,MAatBL,kBAAkBM,kBAETC,QAAQC,SAASC,aAClB,WACA,qBACAJ,KAAKK,eACL,CACIJ,YAAAA,eAaZK,qBAAqB1B,EAAG2B,qBAKdC,KAAO,IAAIC,IAAIF,cAAcG,KAAK,SACxCF,KAAKG,aAAaC,IAAI,YAAaZ,KAAKa,kBACxCN,cAAcG,KAAK,OAAQF,MAU/BM,4BAA4BlC,EAAG2B,eAgB3BX,OAAOmB,UAAUnC,EAAG,CAChBoC,IAAKT,cAAcG,KAAK,QACxBO,KAAM,kBACNC,QAlBiB,CACjB,aACA,YACA,QACA,SACA,YACA,aACA,aACA,YACA,UACA,SACA,gBACA,eACA,aAKsBC,KAAK,OASnCC,+BAEUA,uBAAuBpB,WAExBqB,WAAWC,GAAG,SAAUhD,8BAA+BM,UAIlD2C,aAAc,mBAAE3C,EAAE4C,mCAEtB,aAAad,KAAK,OAAQ,UACvBA,KAAK,OAAQ,aACbA,KAAK,QAASV,KAAKa,kBACnBY,SAASF,qBAGbF,WAAWC,GAAG,QAAShD,kBAAmBM,UACrC2B,eAAgB,mBAAE3B,EAAE4C,eAGtBjB,cAAcxB,QAAQT,iCAAiCoD,YAClDpB,qBAAqB1B,EAAG2B,eAK7BA,cAAcxB,QAAQT,6BAA6BoD,YAC9CZ,4BAA4BlC,EAAG2B,eAKpCA,cAAcxB,QAAQT,mBAAmBoD,SAK7C9C,EAAEI,sBACGW,kBAAkBY,cAAcoB,KAAK,oBAIzCC,UAAUN,GAAGO,YAAYC,cAAc,KAGxCC,kBAAkBC,6FAnKZ,iDADGzD,6HAyKrBA,sBAAsB0D"} \ No newline at end of file diff --git a/mod/quiz/amd/build/quizquestionbank.min.js b/mod/quiz/amd/build/quizquestionbank.min.js deleted file mode 100644 index c82294e38f7..00000000000 --- a/mod/quiz/amd/build/quizquestionbank.min.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Initialise the question bank modal on the quiz page. - * - * @module mod_quiz/quizquestionbank - * @copyright 2018 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -define("mod_quiz/quizquestionbank",["mod_quiz/add_question_modal_launcher","mod_quiz/modal_quiz_question_bank"],(function(AddQuestionModalLauncher,ModalQuizQuestionBank){return{init:function(contextId){AddQuestionModalLauncher.init(ModalQuizQuestionBank.TYPE,'.menu [data-action="questionbank"]',contextId)}}})); - -//# sourceMappingURL=quizquestionbank.min.js.map \ No newline at end of file diff --git a/mod/quiz/amd/build/quizquestionbank.min.js.map b/mod/quiz/amd/build/quizquestionbank.min.js.map deleted file mode 100644 index 01c5107fbc3..00000000000 --- a/mod/quiz/amd/build/quizquestionbank.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"quizquestionbank.min.js","sources":["../src/quizquestionbank.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 * Initialise the question bank modal on the quiz page.\n *\n * @module mod_quiz/quizquestionbank\n * @copyright 2018 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n [\n 'mod_quiz/add_question_modal_launcher',\n 'mod_quiz/modal_quiz_question_bank'\n ],\n function(\n AddQuestionModalLauncher,\n ModalQuizQuestionBank\n ) {\n\n return {\n /**\n * Create the question bank modal.\n *\n * @param {int} contextId Current context id.\n */\n init: function(contextId) {\n AddQuestionModalLauncher.init(\n ModalQuizQuestionBank.TYPE,\n '.menu [data-action=\"questionbank\"]',\n contextId\n );\n }\n };\n});\n"],"names":["define","AddQuestionModalLauncher","ModalQuizQuestionBank","init","contextId","TYPE"],"mappings":";;;;;;;AAsBAA,mCACI,CACI,uCACA,sCAEJ,SACIC,yBACAC,6BAGG,CAMHC,KAAM,SAASC,WACXH,yBAAyBE,KACrBD,sBAAsBG,KACtB,qCACAD"} \ No newline at end of file diff --git a/mod/quiz/amd/build/repaginate.min.js b/mod/quiz/amd/build/repaginate.min.js index 21ecca0071d..d25a7df36d6 100644 --- a/mod/quiz/amd/build/repaginate.min.js +++ b/mod/quiz/amd/build/repaginate.min.js @@ -1,10 +1,10 @@ +define("mod_quiz/repaginate",["exports","core/modal"],(function(_exports,_modal){var obj; /** - * Initialise the repaginate dialogue on quiz editing page. - * - * @module mod_quiz/repaginate - * @copyright 2019 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -define("mod_quiz/repaginate",["jquery","core/modal_factory"],(function($,ModalFactory){var SELECTORS_REPAGINATECOMMAND="#repaginatecommand",SELECTORS_HEADER="header",SELECTORS_BODY="form";return{init:function(){ModalFactory.create({title:$(SELECTORS_REPAGINATECOMMAND).data(SELECTORS_HEADER),body:$(SELECTORS_REPAGINATECOMMAND).data(SELECTORS_BODY),large:!1},$(SELECTORS_REPAGINATECOMMAND))}}})); + * Initialise the repaginate dialogue on quiz editing page. + * + * @module mod_quiz/repaginate + * @copyright 2019 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_modal=(obj=_modal)&&obj.__esModule?obj:{default:obj};_exports.init=()=>{document.addEventListener("click",(event=>{const repaginateCommand=event.target.closest("#repaginatecommand");repaginateCommand&&(event.preventDefault(),_modal.default.create({title:repaginateCommand.dataset.header,body:repaginateCommand.dataset.form,large:!1,show:!0}))}))}})); //# sourceMappingURL=repaginate.min.js.map \ No newline at end of file diff --git a/mod/quiz/amd/build/repaginate.min.js.map b/mod/quiz/amd/build/repaginate.min.js.map index 760920733d0..0ca7c95691a 100644 --- a/mod/quiz/amd/build/repaginate.min.js.map +++ b/mod/quiz/amd/build/repaginate.min.js.map @@ -1 +1 @@ -{"version":3,"file":"repaginate.min.js","sources":["../src/repaginate.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 * Initialise the repaginate dialogue on quiz editing page.\n *\n * @module mod_quiz/repaginate\n * @copyright 2019 The Open University\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/modal_factory'], function($, ModalFactory) {\n\n var SELECTORS = {\n REPAGINATECOMMAND: '#repaginatecommand',\n HEADER: 'header',\n BODY: 'form'\n };\n\n /**\n * Initialise the repaginate button and add the event listener.\n */\n var init = function() {\n ModalFactory.create(\n {\n title: $(SELECTORS.REPAGINATECOMMAND).data(SELECTORS.HEADER),\n body: $(SELECTORS.REPAGINATECOMMAND).data(SELECTORS.BODY),\n large: false,\n },\n $(SELECTORS.REPAGINATECOMMAND)\n );\n };\n return {\n init: init\n };\n});\n"],"names":["define","$","ModalFactory","SELECTORS","init","create","title","data","body","large"],"mappings":";;;;;;;AAsBAA,6BAAO,CAAC,SAAU,uBAAuB,SAASC,EAAGC,kBAE7CC,4BACmB,qBADnBA,iBAEQ,SAFRA,eAGM,aAgBH,CACHC,KAXO,WACPF,aAAaG,OACT,CACIC,MAAOL,EAAEE,6BAA6BI,KAAKJ,kBAC3CK,KAAMP,EAAEE,6BAA6BI,KAAKJ,gBAC1CM,OAAO,GAEXR,EAAEE"} \ No newline at end of file +{"version":3,"file":"repaginate.min.js","sources":["../src/repaginate.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 * Initialise the repaginate dialogue on quiz editing page.\n *\n * @module mod_quiz/repaginate\n * @copyright 2019 The Open University\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport Modal from 'core/modal';\n\nexport const init = () => {\n document.addEventListener('click', (event) => {\n const repaginateCommand = event.target.closest('#repaginatecommand');\n if (!repaginateCommand) {\n return;\n }\n\n event.preventDefault();\n Modal.create({\n title: repaginateCommand.dataset.header,\n body: repaginateCommand.dataset.form,\n large: false,\n show: true,\n });\n });\n};\n"],"names":["document","addEventListener","event","repaginateCommand","target","closest","preventDefault","create","title","dataset","header","body","form","large","show"],"mappings":";;;;;;;sJAwBoB,KAChBA,SAASC,iBAAiB,SAAUC,cAC1BC,kBAAoBD,MAAME,OAAOC,QAAQ,sBAC1CF,oBAILD,MAAMI,gCACAC,OAAO,CACTC,MAAOL,kBAAkBM,QAAQC,OACjCC,KAAMR,kBAAkBM,QAAQG,KAChCC,OAAO,EACPC,MAAM"} \ No newline at end of file diff --git a/mod/quiz/amd/src/add_question_modal.js b/mod/quiz/amd/src/add_question_modal.js new file mode 100644 index 00000000000..2947d7cf9dd --- /dev/null +++ b/mod/quiz/amd/src/add_question_modal.js @@ -0,0 +1,91 @@ +// 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 . + +/** + * Contain the logic for the add random question modal. + * + * @module mod_quiz/add_question_modal + * @copyright 2023 Andrew Lyons + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import Modal from 'core/modal'; + +export default class AddQuestionModal extends Modal { + configure(modalConfig) { + // Add question modals are always large. + modalConfig.large = true; + + // Always show on creation. + modalConfig.show = true; + + // Apply question modal configuration. + this.setContextId(modalConfig.contextId); + this.setAddOnPageId(modalConfig.addOnPage); + + // Apply standard configuration. + super.configure(modalConfig); + } + + constructor(root) { + super(root); + + this.contextId = null; + this.addOnPageId = null; + } + + /** + * Save the Moodle context id that the question bank is being + * rendered in. + * + * @method setContextId + * @param {Number} id + */ + setContextId(id) { + this.contextId = id; + } + + /** + * Retrieve the saved Moodle context id. + * + * @method getContextId + * @return {Number} + */ + getContextId() { + return this.contextId; + } + + /** + * Set the id of the page that the question should be added to + * when the user clicks the add to quiz link. + * + * @method setAddOnPageId + * @param {Number} id + */ + setAddOnPageId(id) { + this.addOnPageId = id; + } + + /** + * Returns the saved page id for the question to be added to. + * + * @method getAddOnPageId + * @return {Number} + */ + getAddOnPageId() { + return this.addOnPageId; + } + +} diff --git a/mod/quiz/amd/src/add_question_modal_launcher.js b/mod/quiz/amd/src/add_question_modal_launcher.js deleted file mode 100644 index 96151acef81..00000000000 --- a/mod/quiz/amd/src/add_question_modal_launcher.js +++ /dev/null @@ -1,82 +0,0 @@ -// 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 . - -/** - * Initialise the an add question modal on the quiz page. - * - * @module mod_quiz/add_question_modal_launcher - * @copyright 2018 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -define( - [ - 'jquery', - 'core/notification', - 'core/modal_factory', - ], - function( - $, - Notification, - ModalFactory - ) { - - return { - /** - * Create a modal using the modal factory and add listeners to launch the - * modal when clicked. - * - * @param {string} modalType Which modal to create - * @param {string} selector The selectors for the elements that trigger the modal - * @param {int} contextId The current context id - * @param {function} preShowCallback A callback to execute before the modal is shown - * @param {boolean} showNewCategory Display the New category tab when selecting random questions. - * @return {promise} Resolved with the modal - */ - init: function(modalType, selector, contextId, preShowCallback, showNewCategory = true) { - var body = $('body'); - let templateContext = { - hidden: showNewCategory, - }; - - // Create a question bank modal using the factory. - // The same modal will be used by all of the add question - // links that match "selector" on the page. The content - // of the modal will be changed depending on which link is - // clicked. - return ModalFactory.create( - { - type: modalType, - large: true, - templateContext: templateContext, - // This callback executes before the modal is shown when the - // trigger element is clicked. - preShowCallback: function(triggerElement, modal) { - triggerElement = $(triggerElement); - modal.setContextId(contextId); - modal.setAddOnPageId(triggerElement.attr('data-addonpage')); - modal.setTitle(triggerElement.attr('data-header')); - - if (preShowCallback) { - preShowCallback(triggerElement, modal); - } - } - }, - // Created a deligated listener rather than a single - // trigger element. - [body, selector] - ).fail(Notification.exception); - } - }; -}); diff --git a/mod/quiz/amd/src/add_random_question.js b/mod/quiz/amd/src/add_random_question.js deleted file mode 100644 index f87181cd829..00000000000 --- a/mod/quiz/amd/src/add_random_question.js +++ /dev/null @@ -1,58 +0,0 @@ -// 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 . - -/** - * Initialise the add random question modal on the quiz page. - * - * @module mod_quiz/add_random_question - * @copyright 2018 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -define( - [ - 'mod_quiz/add_question_modal_launcher', - 'mod_quiz/modal_add_random_question' - ], - function( - AddQuestionModalLauncher, - ModalAddRandomQuestion - ) { - - return { - /** - * Create the add random question modal. - * - * @param {int} contextId Current context id. - * @param {string} category Category id and category context id comma separated. - * @param {string} returnUrl URL to return to after form submission. - * @param {int} cmid Current course module id. - * @param {boolean} showNewCategory Display the New category tab when selecting random questions. - */ - init: function(contextId, category, returnUrl, cmid, showNewCategory = true) { - AddQuestionModalLauncher.init( - ModalAddRandomQuestion.TYPE, - '.menu [data-action="addarandomquestion"]', - contextId, - // Additional values that should be set before the modal is shown. - function(triggerElement, modal) { - modal.setCategory(category); - modal.setReturnUrl(returnUrl); - modal.setCMID(cmid); - }, - showNewCategory - ); - } - }; -}); diff --git a/mod/quiz/amd/src/modal_add_random_question.js b/mod/quiz/amd/src/modal_add_random_question.js index cd723490893..ec8b3cf40d2 100644 --- a/mod/quiz/amd/src/modal_add_random_question.js +++ b/mod/quiz/amd/src/modal_add_random_question.js @@ -22,7 +22,7 @@ */ import $ from 'jquery'; -import Modal from 'core/modal'; +import Modal from './add_question_modal'; import * as Notification from 'core/notification'; import * as Fragment from 'core/fragment'; import * as Templates from 'core/templates'; @@ -53,6 +53,40 @@ export default class ModalAddRandomQuestion extends Modal { static TYPE = 'mod_quiz-quiz-add-random-question'; static TEMPLATE = 'mod_quiz/modal_add_random_question'; + /** + * Create the add random question modal. + * + * @param {Number} contextId Current context id. + * @param {string} category Category id and category context id comma separated. + * @param {string} returnUrl URL to return to after form submission. + * @param {Number} cmid Current course module id. + * @param {boolean} showNewCategory Display the New category tab when selecting random questions. + */ + static init(contextId, category, returnUrl, cmid, showNewCategory = true) { + const selector = '.menu [data-action="addarandomquestion"]'; + document.addEventListener('click', (e) => { + const trigger = e.target.closest(selector); + if (!trigger) { + return; + } + e.preventDefault(); + + ModalAddRandomQuestion.create({ + contextId, + category, + returnUrl, + cmid, + + title: trigger.dataset.header, + addOnPage: trigger.dataset.addonpage, + + templateContext: { + hidden: showNewCategory, + }, + }); + }); + } + /** * Constructor for the Modal. * @@ -60,33 +94,18 @@ export default class ModalAddRandomQuestion extends Modal { */ constructor(root) { super(root); - this.contextId = null; - this.addOnPageId = null; this.category = null; this.returnUrl = null; this.cmid = null; this.loadedForm = false; } - /** - * Save the Moodle context id that the question bank is being - * rendered in. - * - * @method setContextId - * @param {int} id - */ - setContextId(id) { - this.contextId = id; - } + configure(modalConfig) { + this.setCategory(modalConfig.category); + this.setReturnUrl(modalConfig.returnUrl); + this.setCMID(modalConfig.cmid); - /** - * Retrieve the saved Moodle context id. - * - * @method getContextId - * @return {int} - */ - getContextId() { - return this.contextId; + super.configure(modalConfig); } /** @@ -97,20 +116,10 @@ export default class ModalAddRandomQuestion extends Modal { * @param {int} id */ setAddOnPageId(id) { - this.addOnPageId = id; + super.setAddOnPageId(id); this.getBody().find(SELECTORS.ADD_ON_PAGE_FORM_ELEMENT).val(id); } - /** - * Returns the saved page id for the question to be added to. - * - * @method getAddOnPageId - * @return {int} - */ - getAddOnPageId() { - return this.addOnPageId; - } - /** * Set the category for this form. The category is a comma separated * category id and category context id. @@ -156,7 +165,7 @@ export default class ModalAddRandomQuestion extends Modal { * Set the course module id for the form. * * @method setCMID - * @param {int} id + * @param {Number} id */ setCMID(id) { this.cmid = id; @@ -166,7 +175,7 @@ export default class ModalAddRandomQuestion extends Modal { * Returns the course module id for the form. * * @method getCMID - * @return {int} + * @return {Number} */ getCMID() { return this.cmid; diff --git a/mod/quiz/amd/src/modal_quiz_question_bank.js b/mod/quiz/amd/src/modal_quiz_question_bank.js index 5ebd4661d42..769e4a6a4b1 100644 --- a/mod/quiz/amd/src/modal_quiz_question_bank.js +++ b/mod/quiz/amd/src/modal_quiz_question_bank.js @@ -22,7 +22,7 @@ */ import $ from 'jquery'; -import Modal from 'core/modal'; +import Modal from './add_question_modal'; import * as Fragment from 'core/fragment'; import * as FormChangeChecker from 'core_form/changechecker'; import * as ModalEvents from 'core/modal_events'; @@ -39,57 +39,29 @@ export default class ModalQuizQuestionBank extends Modal { static TYPE = 'mod_quiz-quiz-question-bank'; /** - * Constructor for the Modal. + * Create the question bank modal. * - * @param {object} root The root jQuery element for the modal + * @param {Number} contextId Current context id. */ - constructor(root) { - super(root); + static init(contextId) { + const selector = '.menu [data-action="questionbank"]'; + document.addEventListener('click', (e) => { + const trigger = e.target.closest(selector); + if (!trigger) { + return; + } + e.preventDefault(); - this.contextId = null; - this.addOnPageId = null; - } - - /** - * Save the Moodle context id that the question bank is being - * rendered in. - * - * @method setContextId - * @param {int} id - */ - setContextId(id) { - this.contextId = id; - } - - /** - * Retrieve the saved Moodle context id. - * - * @method getContextId - * @return {int} - */ - getContextId() { - return this.contextId; - } - - /** - * Set the id of the page that the question should be added to - * when the user clicks the add to quiz link. - * - * @method setAddOnPageId - * @param {int} id - */ - setAddOnPageId(id) { - this.addOnPageId = id; - } - - /** - * Returns the saved page id for the question to be added it. - * - * @method getAddOnPageId - * @return {int} - */ - getAddOnPageId() { - return this.addOnPageId; + ModalQuizQuestionBank.create({ + contextId, + title: trigger.dataset.header, + addOnPage: trigger.dataset.addonpage, + templateContext: { + hidden: true, + }, + large: true, + }); + }); } /** diff --git a/mod/quiz/amd/src/quizquestionbank.js b/mod/quiz/amd/src/quizquestionbank.js deleted file mode 100644 index 1481485f070..00000000000 --- a/mod/quiz/amd/src/quizquestionbank.js +++ /dev/null @@ -1,47 +0,0 @@ -// 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 . - -/** - * Initialise the question bank modal on the quiz page. - * - * @module mod_quiz/quizquestionbank - * @copyright 2018 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -define( - [ - 'mod_quiz/add_question_modal_launcher', - 'mod_quiz/modal_quiz_question_bank' - ], - function( - AddQuestionModalLauncher, - ModalQuizQuestionBank - ) { - - return { - /** - * Create the question bank modal. - * - * @param {int} contextId Current context id. - */ - init: function(contextId) { - AddQuestionModalLauncher.init( - ModalQuizQuestionBank.TYPE, - '.menu [data-action="questionbank"]', - contextId - ); - } - }; -}); diff --git a/mod/quiz/amd/src/repaginate.js b/mod/quiz/amd/src/repaginate.js index 8d2ab4ca7cc..dbe9913c2f9 100644 --- a/mod/quiz/amd/src/repaginate.js +++ b/mod/quiz/amd/src/repaginate.js @@ -20,28 +20,21 @@ * @copyright 2019 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['jquery', 'core/modal_factory'], function($, ModalFactory) { +import Modal from 'core/modal'; - var SELECTORS = { - REPAGINATECOMMAND: '#repaginatecommand', - HEADER: 'header', - BODY: 'form' - }; +export const init = () => { + document.addEventListener('click', (event) => { + const repaginateCommand = event.target.closest('#repaginatecommand'); + if (!repaginateCommand) { + return; + } - /** - * Initialise the repaginate button and add the event listener. - */ - var init = function() { - ModalFactory.create( - { - title: $(SELECTORS.REPAGINATECOMMAND).data(SELECTORS.HEADER), - body: $(SELECTORS.REPAGINATECOMMAND).data(SELECTORS.BODY), - large: false, - }, - $(SELECTORS.REPAGINATECOMMAND) - ); - }; - return { - init: init - }; -}); + event.preventDefault(); + Modal.create({ + title: repaginateCommand.dataset.header, + body: repaginateCommand.dataset.form, + large: false, + show: true, + }); + }); +}; diff --git a/mod/quiz/classes/output/edit_renderer.php b/mod/quiz/classes/output/edit_renderer.php index 498813f73b6..4cb9a3f7d52 100644 --- a/mod/quiz/classes/output/edit_renderer.php +++ b/mod/quiz/classes/output/edit_renderer.php @@ -111,11 +111,11 @@ class edit_renderer extends \plugin_renderer_base { // Include the contents of any other popups required. if ($structure->can_be_edited()) { $thiscontext = $contexts->lowest(); - $this->page->requires->js_call_amd('mod_quiz/quizquestionbank', 'init', [ + $this->page->requires->js_call_amd('mod_quiz/modal_quiz_question_bank', 'init', [ $thiscontext->id ]); - $this->page->requires->js_call_amd('mod_quiz/add_random_question', 'init', [ + $this->page->requires->js_call_amd('mod_quiz/modal_add_random_question', 'init', [ $thiscontext->id, $pagevars['cat'], $pageurl->out_as_local_url(true),