1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 * A registry for the different types of modal.
19 * @module core/modal_registry
20 * @class modal_registry
22 * @copyright 2016 Ryan Wyllie <ryan@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 define(['core/notification'], function(Notification) {
27 // A singleton registry for all modules to access. Allows types to be
32 * Get a registered type of modal.
35 * @param {string} type The type of modal to get
36 * @return {object} The registered config for the modal
38 var get = function(type) {
39 return registry[type];
43 * Register a modal with the registry.
46 * @param {string} type The type of modal (must be unique)
47 * @param {function} module The modal module (must be a constructor function of type core/modal)
48 * @param {string} template The template name of the modal
50 var register = function(type, module, template) {
52 Notification.exception({message: "Modal of type '" + type + "' is already registered"});
55 if (!module || typeof module !== 'function') {
56 Notification.exception({message: "You must provide a modal module"});
60 Notification.exception({message: "You must provide a modal template"});