hedera-web/js/htk/dialog/index.js

162 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-06-06 08:53:59 +00:00
require('./style.scss');
var Popup = require('../popup');
/**
* Class to show message dialogs with buttons.
2022-05-26 06:08:31 +00:00
*/
2020-05-04 20:47:02 +00:00
var Dialog = new Class();
module.exports = Dialog;
var Button =
{
OK : 1 << 1
,ACCEPT : 1 << 2
,CANCEL : 1 << 3
,RETRY : 1 << 4
,YES : 1 << 5
,NO : 1 << 6
};
var labels =
[{
response: Button.NO
,label: 'No'
},{
response: Button.CANCEL
,label: 'Cancel'
},{
response: Button.RETRY
,label: 'Retry'
},{
response: Button.ACCEPT
,label: 'Accept'
},{
response: Button.OK
,label: 'Ok'
},{
response: Button.YES
,label: 'Yes'
}];
Button.CANCEL_ACCEPT = Button.CANCEL | Button.ACCEPT;
2020-05-04 21:05:52 +00:00
Button.RETRY_CANCEL = Button.RETRY | Button.CANCEL;
Button.YES_NO = Button.YES | Button.NO;
2020-05-04 20:47:02 +00:00
Dialog.extend({
Button: Button
});
2020-05-04 20:47:02 +00:00
Dialog.implement({
Extends: Popup
,Tag: 'htk-dialog'
,Properties:
{
/**
* The message displayed to the user.
2022-05-26 06:08:31 +00:00
*/
message:
{
type: String
2020-05-04 20:47:02 +00:00
,set: function(x) {
this._message = x;
}
2020-05-04 20:47:02 +00:00
,get: function() {
return this._message;
}
}
/**
* The dialog icon.
2022-05-26 06:08:31 +00:00
*/
,icon:
{
type: String
2020-05-04 20:47:02 +00:00
,set: function(x) {
this._icon = x;
}
2020-05-04 20:47:02 +00:00
,get: function() {
return this._icon;
}
}
/**
* The dialog buttons.
2022-05-26 06:08:31 +00:00
*/
,buttons:
{
enumType: Button
2020-05-04 20:47:02 +00:00
,set: function(x) {
this._buttons = x;
}
2020-05-04 20:47:02 +00:00
,get: function() {
return this._buttons;
}
}
}
,_modal: true
,_icon: 'info'
,_buttons: Button.ACCEPT
2020-05-04 20:47:02 +00:00
,open: function() {
this.parent();
// Dialog body
2020-05-04 20:47:02 +00:00
var root = this.createElement('div');
root.className = 'htk-dialog';
2020-05-04 20:47:02 +00:00
var body = this.createElement('div');
root.appendChild(body);
2020-05-04 20:47:02 +00:00
if (this._icon) {
var icon = new Htk.Icon({
doc: this.doc,
icon: this._icon
});
2020-05-04 20:47:02 +00:00
body.appendChild(icon.node);
}
2020-05-04 20:47:02 +00:00
var p = this.createElement('p');
body.appendChild(p);
if (this._message)
2020-05-04 20:47:02 +00:00
p.appendChild(this.createTextNode(this._message));
2020-05-04 20:47:02 +00:00
var clear = this.createElement('div');
clear.style.clear = 'both';
2020-05-04 20:47:02 +00:00
body.appendChild(clear);
// Button bar
2020-05-04 20:47:02 +00:00
var buttonBar = this._buttonBar = this.createElement('div');
buttonBar.className = 'button-bar';
2020-05-04 20:47:02 +00:00
root.appendChild(buttonBar);
var i = labels.length;
while (i--)
if (this._buttons & labels[i].response)
2020-05-04 20:47:02 +00:00
this.createButton(_(labels[i].label), labels[i].response);
2020-05-04 20:47:02 +00:00
var clear = this.createElement('div');
clear.style.clear = 'both';
2020-05-04 20:47:02 +00:00
root.appendChild(clear);
this.childNode = root;
}
2020-05-04 20:47:02 +00:00
,hide(response) {
if (!this._isOpen) return;
this.parent();
2022-05-30 01:30:33 +00:00
this.emit('response', response);
}
2020-05-04 20:47:02 +00:00
,createButton: function(label, response) {
var button = this.createElement('button');
button.className = 'thin';
button.appendChild(this.createTextNode(label));
button.addEventListener('click',
this.hide.bind(this, response));
this._buttonBar.appendChild(button);
}
});