MDL-79182 core_modal: Removed core/modal_registry and core/modal_factory for final deprecation
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
issueNumber: MDL-79182
|
||||
notes:
|
||||
core:
|
||||
- message:
|
||||
- Removed core/modal_registry for the final deprecation due to no longer being required.
|
||||
- Removed core/modal_factory for the final deprecation due to no longer being required.
|
||||
type: removed
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
-12
@@ -1,12 +0,0 @@
|
||||
define("core/modal_factory",["exports","jquery","core/modal_events","core/modal_registry","core/modal","core/modal_save_cancel","core/modal_delete_cancel","core/modal_cancel","core/local/modal/alert","core/notification","core/custom_interaction_events","core/pending"],(function(_exports,_jquery,_modal_events,ModalRegistry,_modal,_modal_save_cancel,_modal_delete_cancel,_modal_cancel,_alert,Notification,CustomEvents,_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}}
|
||||
/**
|
||||
* Create a modal.
|
||||
*
|
||||
* @module core/modal_factory
|
||||
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @deprecated since Moodle 4.3
|
||||
* @todo Final deprecation in Moodle 4.7/5.2. See MDL-79128/
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.types=_exports.default=_exports.create=void 0,_jquery=_interopRequireDefault(_jquery),_modal_events=_interopRequireDefault(_modal_events),ModalRegistry=_interopRequireWildcard(ModalRegistry),_modal=_interopRequireDefault(_modal),_modal_save_cancel=_interopRequireDefault(_modal_save_cancel),_modal_delete_cancel=_interopRequireDefault(_modal_delete_cancel),_modal_cancel=_interopRequireDefault(_modal_cancel),_alert=_interopRequireDefault(_alert),Notification=_interopRequireWildcard(Notification),CustomEvents=_interopRequireWildcard(CustomEvents),_pending=_interopRequireDefault(_pending);const types={DEFAULT:"DEFAULT",SAVE_CANCEL:_modal_save_cancel.default.TYPE,DELETE_CANCEL:_modal_delete_cancel.default.TYPE,CANCEL:_modal_cancel.default.TYPE,ALERT:_alert.default.TYPE};_exports.types=types,ModalRegistry.register(types.DEFAULT,_modal.default,_modal.default.TEMPLATE);const create=(modalConfig,triggerElement)=>{window.console.warn("The modal_factory has been deprecated since Moodle 4.3. Please use the create method on your target modal type instead.");const type=modalConfig.type||types.DEFAULT,registryConf=ModalRegistry.get(type);registryConf||Notification.exception({message:"Unable to find modal of type: ".concat(type)});const modal=registryConf.module.create(modalConfig);return triggerElement&&(window.console.warn("The triggerElement feature of the modal_factory has been deprecated. Please use event listeners instead."),((modalPromise,triggerElement,modalConfig)=>{let actualTriggerElement=null;const hasPreShowCallback="function"==typeof modalConfig.preShowCallback,triggeredCallback=(e,data)=>{const pendingPromise=new _pending.default("core/modal_factory:setUpTrigger:triggeredCallback");actualTriggerElement=(0,_jquery.default)(e.currentTarget),modalPromise.then((function(modal){return hasPreShowCallback&&modalConfig.preShowCallback(actualTriggerElement,modal),modal.show(),modal})).then(pendingPromise.resolve),data.originalEvent.preventDefault()};if(Array.isArray(triggerElement)){const selector=triggerElement[1];triggerElement=triggerElement[0],CustomEvents.define(triggerElement,[CustomEvents.events.activate]),triggerElement.on(CustomEvents.events.activate,selector,triggeredCallback)}else CustomEvents.define(triggerElement,[CustomEvents.events.activate]),triggerElement.on(CustomEvents.events.activate,triggeredCallback);modalPromise.then((function(modal){return modal.getRoot().on(_modal_events.default.hidden,(function(){null!==actualTriggerElement&&actualTriggerElement.focus()})),modal}))})(modal,triggerElement,modalConfig)),_jquery.default.when(new Promise(((resolve,reject)=>{modal.then(resolve).catch(reject)})))};_exports.create=create;var _default={create:create,types:types};return _exports.default=_default,_exports.default}));
|
||||
|
||||
//# sourceMappingURL=modal_factory.min.js.map
|
||||
File diff suppressed because one or more lines are too long
-11
@@ -1,11 +0,0 @@
|
||||
define("core/modal_registry",["exports","core/notification","core/prefetch"],(function(_exports,Notification,Prefetch){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}
|
||||
/**
|
||||
* A registry for the different types of modal.
|
||||
*
|
||||
* @module core/modal_registry
|
||||
* @class modal_registry
|
||||
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.register=_exports.get=_exports.default=void 0,Notification=_interopRequireWildcard(Notification),Prefetch=_interopRequireWildcard(Prefetch);const registry=new Map,get=type=>registry.get(type);_exports.get=get;const register=(type,module,template)=>{const existing=get(type);existing&&existing.module!==module&&Notification.exception({message:"Modal of type '".concat(type,"' is already registered")}),module&&"function"==typeof module||Notification.exception({message:"You must provide a modal module"}),template||Notification.exception({message:"You must provide a modal template"}),registry.set(type,{module:module,template:template}),Prefetch.prefetchTemplate(template)};_exports.register=register;var _default={register:register,get:get};return _exports.default=_default,_exports.default}));
|
||||
|
||||
//# sourceMappingURL=modal_registry.min.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"modal_registry.min.js","sources":["../src/modal_registry.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 * A registry for the different types of modal.\n *\n * @module core/modal_registry\n * @class modal_registry\n * @copyright 2016 Ryan Wyllie <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport * as Notification from 'core/notification';\nimport * as Prefetch from 'core/prefetch';\n\n// A singleton registry for all modules to access. Allows types to be\n// added at runtime.\nconst registry = new Map();\n\n/**\n * Get a registered type of modal.\n *\n * @method get\n * @param {string} type The type of modal to get\n * @return {object} The registered config for the modal\n */\nexport const get = (type) => registry.get(type);\n\n/**\n * Register a modal with the registry.\n *\n * @method register\n * @param {string} type The type of modal (must be unique)\n * @param {function} module The modal module (must be a constructor function of type core/modal)\n * @param {string} template The template name of the modal\n */\nexport const register = (type, module, template) => {\n const existing = get(type);\n if (existing && existing.module !== module) {\n Notification.exception({\n message: `Modal of type '${type}' is already registered`,\n });\n }\n\n if (!module || typeof module !== 'function') {\n Notification.exception({message: \"You must provide a modal module\"});\n }\n\n if (!template) {\n Notification.exception({message: \"You must provide a modal template\"});\n }\n\n registry.set(type, {module, template});\n\n // Prefetch the template.\n Prefetch.prefetchTemplate(template);\n};\n\nexport default {\n register,\n get,\n};\n"],"names":["registry","Map","get","type","register","module","template","existing","Notification","exception","message","set","Prefetch","prefetchTemplate"],"mappings":";;;;;;;;wNA4BMA,SAAW,IAAIC,IASRC,IAAOC,MAASH,SAASE,IAAIC,6BAU7BC,SAAW,CAACD,KAAME,OAAQC,kBAC7BC,SAAWL,IAAIC,MACjBI,UAAYA,SAASF,SAAWA,QAChCG,aAAaC,UAAU,CACnBC,kCAA4BP,kCAI/BE,QAA4B,mBAAXA,QAClBG,aAAaC,UAAU,CAACC,QAAS,oCAGhCJ,UACDE,aAAaC,UAAU,CAACC,QAAS,sCAGrCV,SAASW,IAAIR,KAAM,CAACE,OAAAA,OAAQC,SAAAA,WAG5BM,SAASC,iBAAiBP,mDAGf,CACXF,SAAAA,SACAF,IAAAA"}
|
||||
+41
-10
@@ -27,7 +27,6 @@ import * as Notification from 'core/notification';
|
||||
import * as KeyCodes from 'core/key_codes';
|
||||
import ModalBackdrop from 'core/modal_backdrop';
|
||||
import ModalEvents from 'core/modal_events';
|
||||
import * as ModalRegistry from 'core/modal_registry';
|
||||
import Pending from 'core/pending';
|
||||
import * as CustomEvents from 'core/custom_interaction_events';
|
||||
import * as FilterEvents from 'core_filters/events';
|
||||
@@ -36,6 +35,7 @@ import * as Aria from 'core/aria';
|
||||
import * as Fullscreen from 'core/fullscreen';
|
||||
import {removeToastRegion} from './toast';
|
||||
import {dispatchEvent} from 'core/event_dispatcher';
|
||||
import * as Prefetch from 'core/prefetch';
|
||||
|
||||
/**
|
||||
* A configuration to provide to the modal.
|
||||
@@ -91,6 +91,12 @@ export default class Modal {
|
||||
*/
|
||||
static modalCounter = 0;
|
||||
|
||||
/**
|
||||
* @var {Number} A singleton registry for all modules to access. Allows types to be
|
||||
* added at runtime.
|
||||
*/
|
||||
static registry = new Map();
|
||||
|
||||
/**
|
||||
* Getter method for .root element.
|
||||
* @return {object} jQuery object
|
||||
@@ -175,13 +181,43 @@ export default class Modal {
|
||||
if (!this.TEMPLATE) {
|
||||
throw new Error(`Unknown modal template`, this);
|
||||
}
|
||||
ModalRegistry.register(
|
||||
|
||||
this.register(
|
||||
this.TYPE,
|
||||
this,
|
||||
this.TEMPLATE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a modal.
|
||||
*
|
||||
* @param {string} type The type of modal (must be unique)
|
||||
* @param {function} module The modal module (must be a constructor function of type core/modal)
|
||||
* @param {string} template The template name of the modal
|
||||
*/
|
||||
static register = (type, module, template) => {
|
||||
const existing = this.registry.get(type);
|
||||
if (existing && existing.module !== module) {
|
||||
Notification.exception({
|
||||
message: `Modal of type '${type}' is already registered`,
|
||||
});
|
||||
}
|
||||
|
||||
if (!module || typeof module !== 'function') {
|
||||
Notification.exception({message: "You must provide a modal module"});
|
||||
}
|
||||
|
||||
if (!template) {
|
||||
Notification.exception({message: "You must provide a modal template"});
|
||||
}
|
||||
|
||||
this.registry.set(type, {module, template});
|
||||
|
||||
// Prefetch the template.
|
||||
Prefetch.prefetchTemplate(template);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new modal using the ModalFactory.
|
||||
* This is a shortcut to creating the modal.
|
||||
@@ -191,7 +227,7 @@ export default class Modal {
|
||||
* @returns {Promise<Modal>}
|
||||
*/
|
||||
static async create(modalConfig = {}) {
|
||||
const pendingModalPromise = new Pending('core/modal_factory:create');
|
||||
const pendingModalPromise = new Pending('core/modal:create');
|
||||
modalConfig.type = this.TYPE;
|
||||
|
||||
const templateName = this._getTemplateName(modalConfig);
|
||||
@@ -225,13 +261,8 @@ export default class Modal {
|
||||
return this.TEMPLATE;
|
||||
}
|
||||
|
||||
if (ModalRegistry.has(this.TYPE)) {
|
||||
// Note: This is provided as an interim backwards-compatability layer and will be removed four releases after 4.3.
|
||||
window.console.warning(
|
||||
'Use of core/modal_registry is deprecated. ' +
|
||||
'Please define your modal template in a new static TEMPLATE property on your modal class.',
|
||||
);
|
||||
const config = ModalRegistry.get(this.TYPE);
|
||||
if (this.registry.has(this.TYPE)) {
|
||||
const config = this.registry.get(this.TYPE);
|
||||
return config.template;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,163 +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/>.
|
||||
|
||||
/**
|
||||
* Create a modal.
|
||||
*
|
||||
* @module core/modal_factory
|
||||
* @copyright 2016 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @deprecated since Moodle 4.3
|
||||
* @todo Final deprecation in Moodle 4.7/5.2. See MDL-79128/
|
||||
*/
|
||||
|
||||
import $ from 'jquery';
|
||||
import ModalEvents from 'core/modal_events';
|
||||
import * as ModalRegistry from 'core/modal_registry';
|
||||
import Modal from 'core/modal';
|
||||
import ModalSaveCancel from 'core/modal_save_cancel';
|
||||
import ModalDeleteCancel from 'core/modal_delete_cancel';
|
||||
import ModalCancel from 'core/modal_cancel';
|
||||
import ModalAlert from 'core/local/modal/alert';
|
||||
import * as Notification from 'core/notification';
|
||||
import * as CustomEvents from 'core/custom_interaction_events';
|
||||
import Pending from 'core/pending';
|
||||
|
||||
/**
|
||||
* The available standard modals.
|
||||
*
|
||||
* @property {String} DEFAULT The default modal
|
||||
* @property {String} SAVE_CANCEL A modal which can be used to either save, or cancel.
|
||||
* @property {String} DELETE_CANCEL A modal which can be used to either delete, or cancel.
|
||||
* @property {String} CANCEL A modal which displayed a cancel button
|
||||
* @property {String} ALERT An information modal which only displays information.
|
||||
*/
|
||||
export const types = {
|
||||
DEFAULT: 'DEFAULT',
|
||||
SAVE_CANCEL: ModalSaveCancel.TYPE,
|
||||
DELETE_CANCEL: ModalDeleteCancel.TYPE,
|
||||
CANCEL: ModalCancel.TYPE,
|
||||
ALERT: ModalAlert.TYPE,
|
||||
};
|
||||
|
||||
// Most modals are self-registering.
|
||||
// We do not self-register the base Modal because we do not want to define a default TYPE
|
||||
// on the class that every other modal extends.
|
||||
ModalRegistry.register(types.DEFAULT, Modal, Modal.TEMPLATE);
|
||||
|
||||
/**
|
||||
* Set up the events required to show the modal and return focus when the modal
|
||||
* is closed.
|
||||
*
|
||||
* @method setUpTrigger
|
||||
* @private
|
||||
* @param {Promise} modalPromise The modal instance
|
||||
* @param {object} triggerElement The jQuery element to open the modal
|
||||
* @param {object} modalConfig The modal configuration given to the factory
|
||||
*/
|
||||
const setUpTrigger = (modalPromise, triggerElement, modalConfig) => {
|
||||
// The element that actually shows the modal.
|
||||
let actualTriggerElement = null;
|
||||
// Check if the client has provided a callback function to be called
|
||||
// before the modal is displayed.
|
||||
const hasPreShowCallback = (typeof modalConfig.preShowCallback == 'function');
|
||||
// Function to handle the trigger element being activated.
|
||||
const triggeredCallback = (e, data) => {
|
||||
const pendingPromise = new Pending('core/modal_factory:setUpTrigger:triggeredCallback');
|
||||
actualTriggerElement = $(e.currentTarget);
|
||||
|
||||
// eslint-disable-next-line promise/catch-or-return
|
||||
modalPromise.then(function(modal) {
|
||||
if (hasPreShowCallback) {
|
||||
// If the client provided a pre-show callback then execute
|
||||
// it now before showing the modal.
|
||||
modalConfig.preShowCallback(actualTriggerElement, modal);
|
||||
}
|
||||
|
||||
modal.show();
|
||||
|
||||
return modal;
|
||||
})
|
||||
.then(pendingPromise.resolve);
|
||||
data.originalEvent.preventDefault();
|
||||
};
|
||||
|
||||
// The trigger element can either be a single element or it can be an
|
||||
// element + selector pair to create a delegated event handler to trigger
|
||||
// the modal.
|
||||
if (Array.isArray(triggerElement)) {
|
||||
const selector = triggerElement[1];
|
||||
triggerElement = triggerElement[0];
|
||||
|
||||
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
|
||||
triggerElement.on(CustomEvents.events.activate, selector, triggeredCallback);
|
||||
} else {
|
||||
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
|
||||
triggerElement.on(CustomEvents.events.activate, triggeredCallback);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line promise/catch-or-return
|
||||
modalPromise.then(function(modal) {
|
||||
modal.getRoot().on(ModalEvents.hidden, function() {
|
||||
// Focus on the trigger element that actually launched the modal.
|
||||
if (actualTriggerElement !== null) {
|
||||
actualTriggerElement.focus();
|
||||
}
|
||||
});
|
||||
|
||||
return modal;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a Modal instance.
|
||||
*
|
||||
* @method create
|
||||
* @param {object} modalConfig The configuration to create the modal instance
|
||||
* @param {object} triggerElement The trigger HTML jQuery object
|
||||
* @return {promise} Resolved with a Modal instance
|
||||
*/
|
||||
export const create = (modalConfig, triggerElement) => {
|
||||
window.console.warn(
|
||||
'The modal_factory has been deprecated since Moodle 4.3. Please use the create method on your target modal type instead.',
|
||||
);
|
||||
// Use of the triggerElement has been deprecated.
|
||||
const type = modalConfig.type || types.DEFAULT;
|
||||
|
||||
const registryConf = ModalRegistry.get(type);
|
||||
if (!registryConf) {
|
||||
Notification.exception({message: `Unable to find modal of type: ${type}`});
|
||||
}
|
||||
|
||||
const modal = registryConf.module.create(modalConfig);
|
||||
|
||||
if (triggerElement) {
|
||||
window.console.warn(
|
||||
'The triggerElement feature of the modal_factory has been deprecated. Please use event listeners instead.',
|
||||
);
|
||||
setUpTrigger(modal, triggerElement, modalConfig);
|
||||
}
|
||||
|
||||
return $.when(new Promise((resolve, reject) => {
|
||||
modal
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
}));
|
||||
};
|
||||
|
||||
export default {
|
||||
create,
|
||||
types,
|
||||
};
|
||||
@@ -1,73 +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/>.
|
||||
|
||||
/**
|
||||
* A registry for the different types of modal.
|
||||
*
|
||||
* @module core/modal_registry
|
||||
* @class modal_registry
|
||||
* @copyright 2016 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
import * as Notification from 'core/notification';
|
||||
import * as Prefetch from 'core/prefetch';
|
||||
|
||||
// A singleton registry for all modules to access. Allows types to be
|
||||
// added at runtime.
|
||||
const registry = new Map();
|
||||
|
||||
/**
|
||||
* Get a registered type of modal.
|
||||
*
|
||||
* @method get
|
||||
* @param {string} type The type of modal to get
|
||||
* @return {object} The registered config for the modal
|
||||
*/
|
||||
export const get = (type) => registry.get(type);
|
||||
|
||||
/**
|
||||
* Register a modal with the registry.
|
||||
*
|
||||
* @method register
|
||||
* @param {string} type The type of modal (must be unique)
|
||||
* @param {function} module The modal module (must be a constructor function of type core/modal)
|
||||
* @param {string} template The template name of the modal
|
||||
*/
|
||||
export const register = (type, module, template) => {
|
||||
const existing = get(type);
|
||||
if (existing && existing.module !== module) {
|
||||
Notification.exception({
|
||||
message: `Modal of type '${type}' is already registered`,
|
||||
});
|
||||
}
|
||||
|
||||
if (!module || typeof module !== 'function') {
|
||||
Notification.exception({message: "You must provide a modal module"});
|
||||
}
|
||||
|
||||
if (!template) {
|
||||
Notification.exception({message: "You must provide a modal template"});
|
||||
}
|
||||
|
||||
registry.set(type, {module, template});
|
||||
|
||||
// Prefetch the template.
|
||||
Prefetch.prefetchTemplate(template);
|
||||
};
|
||||
|
||||
export default {
|
||||
register,
|
||||
get,
|
||||
};
|
||||
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -120,8 +120,8 @@ export default class ModalForm {
|
||||
'Passing config.modalConfig.type to ModalForm has been deprecated since Moodle 4.3. ' +
|
||||
'Please pass config.modalName instead with the full module name.',
|
||||
);
|
||||
return import('core/modal_factory')
|
||||
.then((ModalFactory) => ModalFactory.create(this.config.modalConfig));
|
||||
return import('core/modal')
|
||||
.then((Modal) => Modal.create(this.config.modalConfig));
|
||||
} else {
|
||||
// New loader for Moodle 4.3 and above.
|
||||
const moduleName = this.config.moduleName ?? 'core/modal_save_cancel';
|
||||
|
||||
Reference in New Issue
Block a user