2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2022-12-08 11:04:25 +00:00
|
|
|
<CDialog v-model:visible="visible" role="alertdialog" class="p-confirm-dialog" :modal="true" :header="header" :blockScroll="blockScroll" :position="position" :breakpoints="breakpoints" :closeOnEscape="closeOnEscape" @update:visible="onHide">
|
2022-09-06 12:03:37 +00:00
|
|
|
<template v-if="!$slots.message">
|
2022-12-30 08:23:05 +00:00
|
|
|
<i v-if="confirmation.icon" :class="iconClass" />
|
2023-01-10 10:29:51 +00:00
|
|
|
<span class="p-confirm-dialog-message">{{ message }}</span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
<component v-else :is="$slots.message" :message="confirmation"></component>
|
|
|
|
<template #footer>
|
2022-09-14 11:26:01 +00:00
|
|
|
<CDButton :label="rejectLabel" :icon="rejectIcon" :class="rejectClass" @click="reject()" :autofocus="autoFocusReject" />
|
2022-09-06 12:03:37 +00:00
|
|
|
<CDButton :label="acceptLabel" :icon="acceptIcon" :class="acceptClass" @click="accept()" :autofocus="autoFocusAccept" />
|
|
|
|
</template>
|
|
|
|
</CDialog>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-09-14 11:26:01 +00:00
|
|
|
import Button from 'primevue/button';
|
2022-09-06 12:03:37 +00:00
|
|
|
import ConfirmationEventBus from 'primevue/confirmationeventbus';
|
|
|
|
import Dialog from 'primevue/dialog';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ConfirmDialog',
|
|
|
|
props: {
|
|
|
|
group: String,
|
|
|
|
breakpoints: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
confirmListener: null,
|
|
|
|
closeListener: null,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
visible: false,
|
2022-09-14 11:26:01 +00:00
|
|
|
confirmation: null
|
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.confirmListener = (options) => {
|
|
|
|
if (!options) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.group === this.group) {
|
|
|
|
this.confirmation = options;
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
if (this.confirmation.onShow) {
|
|
|
|
this.confirmation.onShow();
|
|
|
|
}
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.visible = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.closeListener = () => {
|
|
|
|
this.visible = false;
|
|
|
|
this.confirmation = null;
|
|
|
|
};
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
ConfirmationEventBus.on('confirm', this.confirmListener);
|
|
|
|
ConfirmationEventBus.on('close', this.closeListener);
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
ConfirmationEventBus.off('confirm', this.confirmListener);
|
|
|
|
ConfirmationEventBus.off('close', this.closeListener);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
accept() {
|
|
|
|
if (this.confirmation.accept) {
|
|
|
|
this.confirmation.accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.visible = false;
|
|
|
|
},
|
|
|
|
reject() {
|
|
|
|
if (this.confirmation.reject) {
|
|
|
|
this.confirmation.reject();
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
this.visible = false;
|
|
|
|
},
|
|
|
|
onHide() {
|
|
|
|
if (this.confirmation.onHide) {
|
|
|
|
this.confirmation.onHide();
|
|
|
|
}
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.visible = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
header() {
|
|
|
|
return this.confirmation ? this.confirmation.header : null;
|
|
|
|
},
|
|
|
|
message() {
|
|
|
|
return this.confirmation ? this.confirmation.message : null;
|
|
|
|
},
|
|
|
|
blockScroll() {
|
|
|
|
return this.confirmation ? this.confirmation.blockScroll : true;
|
|
|
|
},
|
|
|
|
position() {
|
|
|
|
return this.confirmation ? this.confirmation.position : null;
|
|
|
|
},
|
|
|
|
iconClass() {
|
|
|
|
return ['p-confirm-dialog-icon', this.confirmation ? this.confirmation.icon : null];
|
|
|
|
},
|
|
|
|
acceptLabel() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.confirmation ? this.confirmation.acceptLabel || this.$primevue.config.locale.accept : null;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
rejectLabel() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.confirmation ? this.confirmation.rejectLabel || this.$primevue.config.locale.reject : null;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
acceptIcon() {
|
|
|
|
return this.confirmation ? this.confirmation.acceptIcon : null;
|
|
|
|
},
|
|
|
|
rejectIcon() {
|
|
|
|
return this.confirmation ? this.confirmation.rejectIcon : null;
|
|
|
|
},
|
|
|
|
acceptClass() {
|
|
|
|
return ['p-confirm-dialog-accept', this.confirmation ? this.confirmation.acceptClass : null];
|
|
|
|
},
|
|
|
|
rejectClass() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return ['p-confirm-dialog-reject', this.confirmation ? this.confirmation.rejectClass || 'p-button-text' : null];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
autoFocusAccept() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.confirmation.defaultFocus === undefined || this.confirmation.defaultFocus === 'accept' ? true : false;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
autoFocusReject() {
|
|
|
|
return this.confirmation.defaultFocus === 'reject' ? true : false;
|
|
|
|
},
|
|
|
|
closeOnEscape() {
|
|
|
|
return this.confirmation ? this.confirmation.closeOnEscape : true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2022-09-14 11:26:01 +00:00
|
|
|
CDialog: Dialog,
|
|
|
|
CDButton: Button
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|