MDL-59859 core: Accept Promise for save button

Accept either a promise, or a string for the content of the save button
in the save / cancel modal.
This commit is contained in:
Andrew Nicols 2017-08-18 10:53:28 +08:00
parent 3e0df465db
commit 17137d471d
2 changed files with 9 additions and 4 deletions

View File

@ -1 +1 @@
define(["jquery","core/notification","core/custom_interaction_events","core/modal","core/modal_events"],function(a,b,c,d,e){var f={SAVE_BUTTON:'[data-action="save"]',CANCEL_BUTTON:'[data-action="cancel"]'},g=function(a){d.call(this,a),this.getFooter().find(f.SAVE_BUTTON).length||b.exception({message:"No save button found"}),this.getFooter().find(f.CANCEL_BUTTON).length||b.exception({message:"No cancel button found"})};return g.prototype=Object.create(d.prototype),g.prototype.constructor=g,g.prototype.setFooter=function(){b.exception({message:"Can not change the footer of a save cancel modal"})},g.prototype.registerEventListeners=function(){d.prototype.registerEventListeners.call(this),this.getModal().on(c.events.activate,f.SAVE_BUTTON,function(b,c){var d=a.Event(e.save);this.getRoot().trigger(d,this),d.isDefaultPrevented()||(this.hide(),c.originalEvent.preventDefault())}.bind(this)),this.getModal().on(c.events.activate,f.CANCEL_BUTTON,function(b,c){var d=a.Event(e.cancel);this.getRoot().trigger(d,this),d.isDefaultPrevented()||(this.hide(),c.originalEvent.preventDefault())}.bind(this))},g.prototype.setSaveButtonText=function(a){this.getFooter().find(f.SAVE_BUTTON).text(a)},g});
define(["jquery","core/notification","core/custom_interaction_events","core/modal","core/modal_events"],function(a,b,c,d,e){var f={SAVE_BUTTON:'[data-action="save"]',CANCEL_BUTTON:'[data-action="cancel"]'},g=function(a){d.call(this,a),this.getFooter().find(f.SAVE_BUTTON).length||b.exception({message:"No save button found"}),this.getFooter().find(f.CANCEL_BUTTON).length||b.exception({message:"No cancel button found"})};return g.prototype=Object.create(d.prototype),g.prototype.constructor=g,g.prototype.setFooter=function(){b.exception({message:"Can not change the footer of a save cancel modal"})},g.prototype.registerEventListeners=function(){d.prototype.registerEventListeners.call(this),this.getModal().on(c.events.activate,f.SAVE_BUTTON,function(b,c){var d=a.Event(e.save);this.getRoot().trigger(d,this),d.isDefaultPrevented()||(this.hide(),c.originalEvent.preventDefault())}.bind(this)),this.getModal().on(c.events.activate,f.CANCEL_BUTTON,function(b,c){var d=a.Event(e.cancel);this.getRoot().trigger(d,this),d.isDefaultPrevented()||(this.hide(),c.originalEvent.preventDefault())}.bind(this))},g.prototype.setSaveButtonText=function(a){var b=this.getFooter().find(f.SAVE_BUTTON);this.asyncSet(a,b.text.bind(b))},g});

View File

@ -91,10 +91,15 @@ define(['jquery', 'core/notification', 'core/custom_interaction_events', 'core/m
/**
* Allows to overwrite the text of "Save changes" button.
*
* @param {String} text
* This method is overloaded to take either a string value for the button title or a jQuery promise that is resolved with
* text most commonly from a Str.get_string call.
*
* @param {(String|object)} value The button text, or a jQuery promise which will resolve it
*/
ModalSaveCancel.prototype.setSaveButtonText = function(text) {
this.getFooter().find(SELECTORS.SAVE_BUTTON).text(text);
ModalSaveCancel.prototype.setSaveButtonText = function(value) {
var button = this.getFooter().find(SELECTORS.SAVE_BUTTON);
this.asyncSet(value, button.text.bind(button));
};
return ModalSaveCancel;