2016-10-20 08:37:08 +00:00
|
|
|
|
2020-05-04 20:47:02 +00:00
|
|
|
var Popup = require('./popup');
|
2016-10-20 08:37:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
2016-10-20 08:37:08 +00:00
|
|
|
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;
|
2016-10-20 08:37:08 +00:00
|
|
|
Button.YES_NO = Button.YES | Button.NO;
|
|
|
|
|
2020-05-04 20:47:02 +00:00
|
|
|
Dialog.extend({
|
2016-10-20 08:37:08 +00:00
|
|
|
Button: Button
|
|
|
|
});
|
|
|
|
|
2020-05-04 20:47:02 +00:00
|
|
|
Dialog.implement({
|
2016-10-20 08:37:08 +00:00
|
|
|
Extends: Popup
|
|
|
|
,Tag: 'htk-dialog'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The message displayed to the user.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2016-10-20 08:37:08 +00:00
|
|
|
message:
|
|
|
|
{
|
|
|
|
type: String
|
2020-05-04 20:47:02 +00:00
|
|
|
,set: function(x) {
|
2016-10-20 08:37:08 +00:00
|
|
|
this._message = x;
|
|
|
|
}
|
2020-05-04 20:47:02 +00:00
|
|
|
,get: function() {
|
2016-10-20 08:37:08 +00:00
|
|
|
return this._message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* The dialog icon.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2016-10-20 08:37:08 +00:00
|
|
|
,icon:
|
|
|
|
{
|
|
|
|
type: String
|
2020-05-04 20:47:02 +00:00
|
|
|
,set: function(x) {
|
2016-10-20 08:37:08 +00:00
|
|
|
this._icon = x;
|
|
|
|
}
|
2020-05-04 20:47:02 +00:00
|
|
|
,get: function() {
|
2016-10-20 08:37:08 +00:00
|
|
|
return this._icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* The dialog buttons.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2016-10-20 08:37:08 +00:00
|
|
|
,buttons:
|
|
|
|
{
|
|
|
|
enumType: Button
|
2020-05-04 20:47:02 +00:00
|
|
|
,set: function(x) {
|
2016-10-20 08:37:08 +00:00
|
|
|
this._buttons = x;
|
|
|
|
}
|
2020-05-04 20:47:02 +00:00
|
|
|
,get: function() {
|
2016-10-20 08:37:08 +00:00
|
|
|
return this._buttons;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,_modal: true
|
|
|
|
,_icon: 'info'
|
|
|
|
,_buttons: Button.ACCEPT
|
|
|
|
|
2020-05-04 20:47:02 +00:00
|
|
|
,open: function() {
|
|
|
|
this.parent();
|
2016-10-20 08:37:08 +00:00
|
|
|
|
|
|
|
// Dialog body
|
|
|
|
|
2020-05-04 20:47:02 +00:00
|
|
|
var root = this.createElement('div');
|
2016-10-20 08:37:08 +00:00
|
|
|
root.className = 'htk-dialog';
|
|
|
|
|
2020-05-04 20:47:02 +00:00
|
|
|
var body = this.createElement('div');
|
|
|
|
root.appendChild(body);
|
2016-10-20 08:37:08 +00:00
|
|
|
|
2020-05-04 20:47:02 +00:00
|
|
|
if (this._icon) {
|
|
|
|
var icon = new Htk.Icon({
|
2016-10-20 08:37:08 +00:00
|
|
|
doc: this.doc,
|
|
|
|
icon: this._icon
|
|
|
|
});
|
2020-05-04 20:47:02 +00:00
|
|
|
body.appendChild(icon.node);
|
2016-10-20 08:37:08 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 20:47:02 +00:00
|
|
|
var p = this.createElement('p');
|
|
|
|
body.appendChild(p);
|
2016-10-20 08:37:08 +00:00
|
|
|
|
|
|
|
if (this._message)
|
2020-05-04 20:47:02 +00:00
|
|
|
p.appendChild(this.createTextNode(this._message));
|
2016-10-20 08:37:08 +00:00
|
|
|
|
2020-05-04 20:47:02 +00:00
|
|
|
var clear = this.createElement('div');
|
2016-10-20 08:37:08 +00:00
|
|
|
clear.style.clear = 'both';
|
2020-05-04 20:47:02 +00:00
|
|
|
body.appendChild(clear);
|
2016-10-20 08:37:08 +00:00
|
|
|
|
|
|
|
// Button bar
|
|
|
|
|
2020-05-04 20:47:02 +00:00
|
|
|
var buttonBar = this._buttonBar = this.createElement('div');
|
2016-10-20 08:37:08 +00:00
|
|
|
buttonBar.className = 'button-bar';
|
2020-05-04 20:47:02 +00:00
|
|
|
root.appendChild(buttonBar);
|
2016-10-20 08:37:08 +00:00
|
|
|
|
|
|
|
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);
|
2016-10-20 08:37:08 +00:00
|
|
|
|
2020-05-04 20:47:02 +00:00
|
|
|
var clear = this.createElement('div');
|
2016-10-20 08:37:08 +00:00
|
|
|
clear.style.clear = 'both';
|
2020-05-04 20:47:02 +00:00
|
|
|
root.appendChild(clear);
|
2016-10-20 08:37:08 +00:00
|
|
|
|
|
|
|
this.childNode = root;
|
|
|
|
}
|
2020-05-04 20:47:02 +00:00
|
|
|
|
|
|
|
,hide(response) {
|
|
|
|
if (!this._isOpen) return;
|
|
|
|
this.parent();
|
|
|
|
this.signalEmit('response', response);
|
2016-10-20 08:37:08 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2016-10-20 08:37:08 +00:00
|
|
|
}
|
|
|
|
});
|