Files
P42_UI/app/views/templates/dialogs/ConfirmDialog.js
T
2025-10-14 16:31:07 +00:00

69 lines
2.1 KiB
JavaScript

/**
* @category MyEic
* @subcategory Views
*
* @extends WindozDialogContent
*/
class ConfirmDialog extends WindozDialogContent {
actions = [
{
label: 'Cancel',
onclick: this.cancel.bind(this),
severity: 'secondary',
role: 'cancel'
}
]
constructor(options) {
super(options);
this.options = options;
if(this.options.cancelLabel) this.actions[0].label = this.options.cancelLabel
if(this.options.cancelSeverity) this.actions[0].severity = this.options.cancelSeverity
if(this.options.okLabel != '') {
this.actions.push({
label: this.options.okLabel || 'OK',
onclick: this.comply.bind(this),
severity: options.okSeverity||options.severity,
role: 'comply'
});
}
}
DOMContentLoaded() {
ui.eicfy(this.el);
if(typeof(this.options.contentLoaded)=='function') this.options.contentLoaded(this.el)
if(this.options.promptsClass) this.form = new Form(this.find('.'+this.options.promptsClass))
}
comply() {
let data = true
if(this.options.promptsClass){
if(!this.form.validate()) return
data = this.form.value
}
this.actions.find(o => o.role == 'comply').button.loading = true;
this.actions.find(o => o.role == 'cancel').button.disabled = true;
if(this.options.okPromise){
this.options.okPromise(data).then( this.onSuccess.bind(this,data), this.onFailed.bind(this) )
} else {
this.onSuccess(data)
}
}
onSuccess(data) {
this.actions.find(o => o.role == 'comply').button.loading = false;
this.actions.find(o => o.role == 'cancel').button.disabled = false;
this.commit(data);
}
onFailed() {
this.actions.find(o => o.role == 'comply').button.loading = false;
this.actions.find(o => o.role == 'cancel').button.disabled = false;
this.abort();
}
}
app.registerClass('ConfirmDialog',ConfirmDialog);