signal-desktop/js/views/confirmation_dialog_view.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

/* global Whisper, i18n */
// eslint-disable-next-line func-names
2018-04-27 21:25:04 +00:00
(function() {
'use strict';
2018-04-27 21:25:04 +00:00
window.Whisper = window.Whisper || {};
2018-04-27 21:25:04 +00:00
Whisper.ConfirmationDialogView = Whisper.View.extend({
className: 'confirmation-dialog modal',
templateName: 'confirmation-dialog',
initialize(options) {
2018-04-27 21:25:04 +00:00
this.message = options.message;
this.hideCancel = options.hideCancel;
2018-04-27 21:25:04 +00:00
this.resolve = options.resolve;
this.okText = options.okText || i18n('ok');
2018-04-27 21:25:04 +00:00
this.reject = options.reject;
this.cancelText = options.cancelText || i18n('cancel');
2018-04-27 21:25:04 +00:00
this.render();
},
events: {
keyup: 'onKeyup',
'click .ok': 'ok',
'click .cancel': 'cancel',
},
render_attributes() {
2018-04-27 21:25:04 +00:00
return {
message: this.message,
showCancel: !this.hideCancel,
cancel: this.cancelText,
ok: this.okText,
};
},
ok() {
2018-04-27 21:25:04 +00:00
this.remove();
if (this.resolve) {
this.resolve();
}
},
cancel() {
2018-04-27 21:25:04 +00:00
this.remove();
if (this.reject) {
this.reject();
}
},
onKeyup(event) {
2018-04-27 21:25:04 +00:00
if (event.key === 'Escape' || event.key === 'Esc') {
this.cancel();
}
},
focusCancel() {
2018-04-27 21:25:04 +00:00
this.$('.cancel').focus();
},
});
})();