MDL-59382 javascript: template context can be given to modal factory
authorRyan Wyllie <ryan@moodle.com>
Mon, 24 Jul 2017 06:54:17 +0000 (06:54 +0000)
committerRyan Wyllie <ryan@moodle.com>
Wed, 2 Aug 2017 04:47:42 +0000 (04:47 +0000)
lib/amd/build/modal_factory.min.js
lib/amd/src/modal_factory.js

index 715247b..06f8a5f 100644 (file)
Binary files a/lib/amd/build/modal_factory.min.js and b/lib/amd/build/modal_factory.min.js differ
index 68dedf2..52839b1 100644 (file)
@@ -101,10 +101,10 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
      * @param {object} triggerElement The trigger HTML jQuery object
      * @return {promise} Resolved with a Modal instance
      */
-    var createFromType = function(registryConf, triggerElement) {
+    var createFromType = function(registryConf, templateContext, triggerElement) {
         var templateName = registryConf.template;
 
-        return Templates.render(templateName, {})
+        return Templates.render(templateName, templateContext)
             .then(function(html) {
                 var modalElement = $(html);
                 return createFromElement(registryConf, modalElement, triggerElement);
@@ -124,6 +124,7 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
         var type = modalConfig.type || TYPES.DEFAULT;
         var isLarge = modalConfig.large ? true : false;
         var registryConf = null;
+        var templateContext = {};
 
         registryConf = ModalRegistry.get(type);
 
@@ -131,7 +132,11 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
             Notification.exception({message: 'Unable to find modal of type: ' + type});
         }
 
-        return createFromType(registryConf, triggerElement)
+        if (typeof modalConfig.templateContext != 'undefined') {
+            templateContext = modalConfig.templateContext;
+        }
+
+        return createFromType(registryConf, templateContext, triggerElement)
             .then(function(modal) {
                 if (typeof modalConfig.title != 'undefined') {
                     modal.setTitle(modalConfig.title);