[New] Always call callback on dialog close, passing confirmed value

This commit is contained in:
Robert von Burg 2021-08-30 17:18:13 +02:00
parent 63b96ea249
commit f3579ae0f9
2 changed files with 21 additions and 5 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "strolch-wc-information-dialog", "name": "strolch-wc-information-dialog",
"description": "Strolch WebComponent Information Dialog", "description": "Strolch WebComponent Information Dialog",
"version": "0.1.2", "version": "0.1.3",
"authors": [ "authors": [
"Robert von Burg" "Robert von Burg"
], ],

View File

@ -34,12 +34,12 @@
<div class="buttons"> <div class="buttons">
<template is="dom-if" if="[[confirmation]]"> <template is="dom-if" if="[[confirmation]]">
<template is="dom-if" if="[[cancelable]]"> <template is="dom-if" if="[[cancelable]]">
<paper-button dialog-dismiss>[[cancelLbl]]</paper-button> <paper-button on-tap="_onClose">[[cancelLbl]]</paper-button>
</template> </template>
<paper-button dialog-confirm autofocus on-tap="_onOk">[[okLbl]]</paper-button> <paper-button autofocus on-tap="_onOk">[[okLbl]]</paper-button>
</template> </template>
<template is="dom-if" if="[[!confirmation]]"> <template is="dom-if" if="[[!confirmation]]">
<paper-button dialog-confirm autofocus>[[closeLbl]]</paper-button> <paper-button autofocus on-tap="_onClose">[[closeLbl]]</paper-button>
</template> </template>
</div> </div>
</paper-dialog> </paper-dialog>
@ -99,7 +99,23 @@
observers: [], observers: [],
_onClose: function () {
if (this.confirmation) {
this._confirm(false);
} else {
this.close();
}
},
_onOk: function () { _onOk: function () {
if (this.confirmation) {
this._confirm(true);
} else {
this.close();
}
},
_confirm: function (confirmed) {
if (this.callback == null) { if (this.callback == null) {
console.log("Bad dlg config: no callback!"); console.log("Bad dlg config: no callback!");
alert("Bad dlg config: no callback!"); alert("Bad dlg config: no callback!");
@ -108,7 +124,7 @@
alert("Bad dlg config: callback is not a function, but is " + (typeof this.callback)); alert("Bad dlg config: callback is not a function, but is " + (typeof this.callback));
} else { } else {
try { try {
this.callback(true); this.callback(confirmed);
this.close(); this.close();
} catch (e) { } catch (e) {
console.log(e); console.log(e);