MDL-59859 enrol_manual: Improve modal creation ordering
authorAndrew Nicols <andrew@nicols.co.uk>
Fri, 18 Aug 2017 02:02:00 +0000 (10:02 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Mon, 21 Aug 2017 05:00:00 +0000 (13:00 +0800)
enrol/manual/amd/build/quickenrolment.min.js
enrol/manual/amd/src/quickenrolment.js

index 583e136..698752c 100644 (file)
Binary files a/enrol/manual/amd/build/quickenrolment.min.js and b/enrol/manual/amd/build/quickenrolment.min.js differ
index eedda35..600a894 100644 (file)
@@ -59,33 +59,41 @@ define(['core/templates',
     QuickEnrolment.prototype.initModal = function() {
         var triggerButtons = $('.enrolusersbutton.enrol_manual_plugin [type="submit"]');
 
-        var strparams = [
+        var stringsPromise = Str.get_strings([
             {key: 'enroluserscohorts', component: 'enrol_manual'},
-            {key: 'enrolusers', component: 'enrol_manual'}
-        ];
-
-        $.when(Str.get_strings(strparams)).then(function(strlist) {
-            var modalSaveChanges = strlist[0],
-                modalTitle = strlist[1];
-
-            return ModalFactory.create({
-                type: ModalFactory.types.SAVE_CANCEL,
-                title: modalTitle,
-                body: this.getBody()
-            }, triggerButtons).then(function(modal) {
-                this.modal = modal;
-                this.modal.setLarge();
-                this.modal.setSaveButtonText(modalSaveChanges);
-
-                // We want the reset the form every time it is opened.
-                this.modal.getRoot().on(ModalEvents.hidden, function() {
-                    this.modal.setBody(this.getBody());
-                }.bind(this));
-
-                this.modal.getRoot().on(ModalEvents.save, this.submitForm.bind(this));
-                this.modal.getRoot().on('submit', 'form', this.submitFormAjax.bind(this));
+            {key: 'enrolusers', component: 'enrol_manual'},
+        ]);
+
+        var titlePromise = stringsPromise.then(function(strings) {
+            return strings[1];
+        });
+
+        var buttonPromise = stringsPromise.then(function(strings) {
+            return strings[0];
+        });
+
+        return ModalFactory.create({
+            type: ModalFactory.types.SAVE_CANCEL,
+            large: true,
+            title: titlePromise,
+            body: this.getBody()
+        }, triggerButtons)
+        .then(function(modal) {
+            this.modal = modal;
+
+            this.modal.setSaveButtonText(buttonPromise);
+
+            // We want the reset the form every time it is opened.
+            this.modal.getRoot().on(ModalEvents.hidden, function() {
+                this.modal.setBody(this.getBody());
             }.bind(this));
-        }.bind(this)).fail(Notification.exception);
+
+            this.modal.getRoot().on(ModalEvents.save, this.submitForm.bind(this));
+            this.modal.getRoot().on('submit', 'form', this.submitFormAjax.bind(this));
+
+            return modal;
+        }.bind(this))
+        .fail(Notification.exception);
     };
 
     /**