MDL-78324 mod_quiz: Update modals to stop using factory

This commit includes some simplifications to the way in which some of
the modals are launched and allows us to remove several modules entirely
as they are no longer required following the simplification of the Modal
instantiation.
This commit is contained in:
Andrew Nicols 2023-08-17 23:26:20 +08:00
parent a54ba682a4
commit 854da2dd70
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
25 changed files with 203 additions and 349 deletions

View File

@ -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 <andrewmadden@catalyst-au.net>
* @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

View File

@ -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 <http://www.gnu.org/licenses/>.\n\n/**\n * Manage the quiz views.\n *\n * @module quizaccess_seb/view\n * @author Andrew Madden <andrewmadden@catalyst-au.net>\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"}
{"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 <http://www.gnu.org/licenses/>.\n\n/**\n * Manage the quiz views.\n *\n * @module quizaccess_seb/view\n * @author Andrew Madden <andrewmadden@catalyst-au.net>\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"}

View File

@ -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);
};

View File

@ -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 <andrew@nicols.co.uk>
* @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

View File

@ -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 <http://www.gnu.org/licenses/>.\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 <andrew@nicols.co.uk>\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"}

View File

@ -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 <ryan@moodle.com>
* @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

View File

@ -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 <http://www.gnu.org/licenses/>.\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 <ryan@moodle.com>\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"}

View File

@ -1,10 +0,0 @@
/**
* Initialise the add random question modal on the quiz page.
*
* @module mod_quiz/add_random_question
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
* @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

View File

@ -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 <http://www.gnu.org/licenses/>.\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 <ryan@moodle.com>\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"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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)("<input />").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)("<input />").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

File diff suppressed because one or more lines are too long

View File

@ -1,10 +0,0 @@
/**
* Initialise the question bank modal on the quiz page.
*
* @module mod_quiz/quizquestionbank
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
* @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

View File

@ -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 <http://www.gnu.org/licenses/>.\n\n/**\n * Initialise the question bank modal on the quiz page.\n *\n * @module mod_quiz/quizquestionbank\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\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"}

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.\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"}
{"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 <http://www.gnu.org/licenses/>.\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"}

View File

@ -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 <http://www.gnu.org/licenses/>.
/**
* Contain the logic for the add random question modal.
*
* @module mod_quiz/add_question_modal
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
* @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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
/**
* Initialise the an add question modal on the quiz page.
*
* @module mod_quiz/add_question_modal_launcher
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
* @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);
}
};
});

View File

@ -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 <http://www.gnu.org/licenses/>.
/**
* Initialise the add random question modal on the quiz page.
*
* @module mod_quiz/add_random_question
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
* @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
);
}
};
});

View File

@ -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;

View File

@ -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,
});
});
}
/**

View File

@ -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 <http://www.gnu.org/licenses/>.
/**
* Initialise the question bank modal on the quiz page.
*
* @module mod_quiz/quizquestionbank
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
* @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
);
}
};
});

View File

@ -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,
});
});
};

View File

@ -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),