Skip to content

Commit

Permalink
MDL-59859 enrol_manual: Improve modal creation ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Aug 21, 2017
1 parent 17137d4 commit b05f2cd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion enrol/manual/amd/build/quickenrolment.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 33 additions & 25 deletions enrol/manual/amd/src/quickenrolment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down

0 comments on commit b05f2cd

Please sign in to comment.