As of Totara 12 (Evergreen TBC), there has been the inheritance of a modal registry library. This can allow for additional modal types to use the basic Modal templates.
To create a new Modal type, both a mustache template file and a JavaScript AMD module need to be created.
Template file
This needs to reference the template core/modal and have the following variables set:
- title: This should be relatively short and is the heading for the modal.
- body: The main content of the modal.
- footer: The footer for the modal. This should contain any action buttons required.
An example mustache template can be found below:
AMD module
The AMD module needs core/modal and core/modal_registry. To add event listeners, the library core/custom_interaction_events must also be included. As the modal library uses jQuery extensively it may also be beneficial to include it.
The object returned from the AMD module needs to have all the functionality of core/modal (it would make sense to inherit it) with Type specified (mod_module-type recommended), and it must be registered with the modal registry (using ModalRegistry.register(modal.TYPE, template) ). Any events that the modal requires needs to listen to (e.g. from buttons in the footer) will need to be placed in a "registerEventListeners" function (on the activate event provided by core/custom_interaction_events).
An example of AMD module is below
Using a modal
Once a modal type has been registered with the modal registry, it can be used through the modal factory using the type that was defined e.g.: