2018-04-27 21:25:04 +00:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
window.Whisper = window.Whisper || {};
|
2015-05-26 23:54:21 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
Whisper.ConfirmationDialogView = Whisper.View.extend({
|
|
|
|
className: 'confirmation-dialog modal',
|
|
|
|
templateName: 'confirmation-dialog',
|
|
|
|
initialize: function(options) {
|
|
|
|
this.message = options.message;
|
|
|
|
this.hideCancel = options.hideCancel;
|
2017-06-14 00:36:32 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.resolve = options.resolve;
|
|
|
|
this.okText = options.okText || i18n('ok');
|
2017-06-14 00:36:32 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.reject = options.reject;
|
|
|
|
this.cancelText = options.cancelText || i18n('cancel');
|
2017-06-14 00:36:32 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
keyup: 'onKeyup',
|
|
|
|
'click .ok': 'ok',
|
|
|
|
'click .cancel': 'cancel',
|
|
|
|
},
|
|
|
|
render_attributes: function() {
|
|
|
|
return {
|
|
|
|
message: this.message,
|
|
|
|
showCancel: !this.hideCancel,
|
|
|
|
cancel: this.cancelText,
|
|
|
|
ok: this.okText,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
ok: function() {
|
|
|
|
this.remove();
|
|
|
|
if (this.resolve) {
|
|
|
|
this.resolve();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cancel: function() {
|
|
|
|
this.remove();
|
|
|
|
if (this.reject) {
|
|
|
|
this.reject();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onKeyup: function(event) {
|
|
|
|
if (event.key === 'Escape' || event.key === 'Esc') {
|
|
|
|
this.cancel();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
focusCancel: function() {
|
|
|
|
this.$('.cancel').focus();
|
|
|
|
},
|
|
|
|
});
|
2015-05-26 23:54:21 +00:00
|
|
|
})();
|