diff --git a/lnbits/static/js/components/lnbits-dialog.js b/lnbits/static/js/components/lnbits-dialog.js index 12fab0b95..dcb701553 100644 --- a/lnbits/static/js/components/lnbits-dialog.js +++ b/lnbits/static/js/components/lnbits-dialog.js @@ -33,15 +33,22 @@ window.app.component('lnbits-dialog', { action: { type: Object, default: null + }, + secondaryAction: { + type: Object, + default: null } }, - emits: ['update:show', 'hide', 'cancel', 'action'], + emits: ['update:show', 'hide', 'cancel', 'action', 'secondary-action'], computed: { hasAction() { return !!(this.action && this.action.label) }, + hasSecondaryAction() { + return !!(this.secondaryAction && this.secondaryAction.label) + }, actionProps() { const action = this.action || {} @@ -50,7 +57,19 @@ window.app.component('lnbits-dialog', { label: action.label || 'Action', color: action.color || 'primary', loading: !!action.loading, - disable: !!action.disable + disable: !!action.disable, + closePopup: !!action.closePopup + } + }, + secondaryActionProps() { + const action = this.secondaryAction || {} + return { + icon: action.icon || null, + label: action.label || 'Secondary', + color: action.color || 'secondary', + loading: !!action.loading, + disable: !!action.disable, + closePopup: !!action.closePopup } } }, @@ -83,6 +102,22 @@ window.app.component('lnbits-dialog', { } catch (error) { console.error('lnbits-dialog action handler failed', error) } + }, + async handleSecondaryAction() { + try { + if ( + this.secondaryAction && + typeof this.secondaryAction.handler === 'function' + ) { + await this.secondaryAction.handler() + } + this.$emit('secondary-action') + if (this.secondaryAction && this.secondaryAction.closeOnClick) { + this.handleModelUpdate(false) + } + } catch (error) { + console.error('lnbits-dialog secondary action handler failed', error) + } } } }) diff --git a/lnbits/templates/components/lnbits-dialog.vue b/lnbits/templates/components/lnbits-dialog.vue index 0e6a2b33b..38db41a37 100644 --- a/lnbits/templates/components/lnbits-dialog.vue +++ b/lnbits/templates/components/lnbits-dialog.vue @@ -18,7 +18,7 @@ @@ -32,6 +32,18 @@ + +