ConfirmationDialogView: Make showCancel an explicit option

Also, don't call resolve/reject callbacks if they weren't provided.

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-07-12 17:14:22 -07:00
parent 14765599f3
commit aa80cdd74d
2 changed files with 10 additions and 5 deletions

View file

@ -10,6 +10,7 @@
templateName: 'confirmation-dialog', templateName: 'confirmation-dialog',
initialize: function(options) { initialize: function(options) {
this.message = options.message; this.message = options.message;
this.hideCancel = options.hideCancel;
this.resolve = options.resolve; this.resolve = options.resolve;
this.okText = options.okText || i18n('ok'); this.okText = options.okText || i18n('ok');
@ -27,18 +28,22 @@
render_attributes: function() { render_attributes: function() {
return { return {
message: this.message, message: this.message,
showCancel: Boolean(this.reject), showCancel: !this.hideCancel,
cancel: this.cancelText, cancel: this.cancelText,
ok: this.okText ok: this.okText
}; };
}, },
ok: function() { ok: function() {
this.remove(); this.remove();
this.resolve(); if (this.resolve) {
this.resolve();
}
}, },
cancel: function() { cancel: function() {
this.remove(); this.remove();
this.reject(); if (this.reject) {
this.reject();
}
}, },
onKeyup: function(event) { onKeyup: function(event) {
if (event.key === 'Escape' || event.key === 'Esc') { if (event.key === 'Escape' || event.key === 'Esc') {

View file

@ -96,11 +96,11 @@
var dialog = new Whisper.ConfirmationDialogView({ var dialog = new Whisper.ConfirmationDialogView({
message: i18n('deleteWarning'), message: i18n('deleteWarning'),
okText: i18n('delete'), okText: i18n('delete'),
hideCancel: true,
resolve: function() { resolve: function() {
this.model.destroy(); this.model.destroy();
this.resetPanel(); this.resetPanel();
}.bind(this), }.bind(this)
reject: function() {}
}); });
this.$el.prepend(dialog.el); this.$el.prepend(dialog.el);