2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-03-27 13:22:02 +00:00
|
|
|
<Dialog
|
2023-03-16 14:37:09 +00:00
|
|
|
v-model:visible="visible"
|
|
|
|
role="alertdialog"
|
2023-05-29 20:18:28 +00:00
|
|
|
:class="cx('root')"
|
2023-03-16 14:37:09 +00:00
|
|
|
:modal="true"
|
|
|
|
:header="header"
|
|
|
|
:blockScroll="blockScroll"
|
|
|
|
:position="position"
|
|
|
|
:breakpoints="breakpoints"
|
|
|
|
:closeOnEscape="closeOnEscape"
|
|
|
|
:draggable="draggable"
|
|
|
|
@update:visible="onHide"
|
2023-04-25 11:21:19 +00:00
|
|
|
:pt="pt"
|
2023-05-29 17:44:31 +00:00
|
|
|
:unstyled="unstyled"
|
2023-03-16 14:37:09 +00:00
|
|
|
>
|
2023-09-19 10:51:23 +00:00
|
|
|
<template v-if="$slots.container" #container="slotProps">
|
2023-10-31 12:52:10 +00:00
|
|
|
<slot name="container" :message="confirmation" :onClose="slotProps.onClose" :onAccept="accept" :onReject="reject" :closeCallback="slotProps.onclose" :acceptCallback="accept" :rejectCallback="reject" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
2023-09-19 10:51:23 +00:00
|
|
|
<template v-if="!$slots.container">
|
|
|
|
<template v-if="!$slots.message">
|
|
|
|
<slot name="icon">
|
|
|
|
<component v-if="$slots.icon" :is="$slots.icon" :class="cx('icon')" />
|
2024-01-04 08:24:27 +00:00
|
|
|
<span v-else-if="confirmation.icon" :class="[confirmation.icon, cx('icon')]" v-bind="ptm('icon')" />
|
2023-09-19 10:51:23 +00:00
|
|
|
</slot>
|
|
|
|
<span :class="cx('message')" v-bind="ptm('message')">{{ message }}</span>
|
|
|
|
</template>
|
|
|
|
<component v-else :is="$slots.message" :message="confirmation"></component>
|
|
|
|
</template>
|
|
|
|
<template v-if="!$slots.container" #footer>
|
2024-03-27 15:45:05 +00:00
|
|
|
<Button
|
|
|
|
:class="[cx('rejectButton'), confirmation.rejectClass]"
|
|
|
|
:autofocus="autoFocusReject"
|
|
|
|
:unstyled="unstyled"
|
|
|
|
:text="confirmation.rejectProps?.text || false"
|
|
|
|
@click="reject()"
|
|
|
|
v-bind="confirmation.rejectProps"
|
|
|
|
:label="rejectLabel"
|
|
|
|
:pt="ptm('rejectButton')"
|
|
|
|
>
|
2023-06-09 12:09:21 +00:00
|
|
|
<template v-if="rejectIcon || $slots.rejecticon" #icon="iconProps">
|
2023-04-18 11:50:19 +00:00
|
|
|
<slot name="rejecticon">
|
2024-01-30 14:35:32 +00:00
|
|
|
<span :class="[rejectIcon, iconProps.class]" v-bind="ptm('rejectButton')['icon']" data-pc-section="rejectbuttonicon" />
|
2023-04-18 11:50:19 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2024-03-27 13:22:02 +00:00
|
|
|
</Button>
|
2024-03-27 15:45:05 +00:00
|
|
|
<Button :label="acceptLabel" :class="[cx('acceptButton'), confirmation.acceptClass]" :autofocus="autoFocusAccept" :unstyled="unstyled" @click="accept()" v-bind="confirmation.acceptProps" :pt="ptm('acceptButton')">
|
2023-06-09 12:09:21 +00:00
|
|
|
<template v-if="acceptIcon || $slots.accepticon" #icon="iconProps">
|
2023-04-18 11:50:19 +00:00
|
|
|
<slot name="accepticon">
|
2024-01-30 14:35:32 +00:00
|
|
|
<span :class="[acceptIcon, iconProps.class]" v-bind="ptm('acceptButton')['icon']" data-pc-section="acceptbuttonicon" />
|
2023-04-18 11:50:19 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2024-03-27 13:22:02 +00:00
|
|
|
</Button>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
2024-03-27 13:22:02 +00:00
|
|
|
</Dialog>
|
2022-09-06 12:03:37 +00:00
|
|
|
</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';
|
2023-06-09 12:09:21 +00:00
|
|
|
import BaseConfirmDialog from './BaseConfirmDialog.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ConfirmDialog',
|
2023-05-29 17:44:31 +00:00
|
|
|
extends: BaseConfirmDialog,
|
2022-09-06 12:03:37 +00:00
|
|
|
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;
|
2023-05-29 17:44:31 +00:00
|
|
|
},
|
|
|
|
getCXOptions(icon, iconProps) {
|
|
|
|
return { contenxt: { icon, iconClass: iconProps.class } };
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
acceptLabel() {
|
2024-03-27 15:45:05 +00:00
|
|
|
if (this.confirmation) {
|
|
|
|
const confirmation = this.confirmation;
|
|
|
|
|
|
|
|
return confirmation.acceptLabel ? confirmation.acceptLabel : confirmation.acceptProps ? confirmation.acceptProps.label || this.$primevue.config.locale.accept : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
rejectLabel() {
|
2024-03-27 15:45:05 +00:00
|
|
|
if (this.confirmation) {
|
|
|
|
const confirmation = this.confirmation;
|
|
|
|
|
|
|
|
return confirmation.rejectLabel ? confirmation.rejectLabel : confirmation.rejectProps ? confirmation.rejectProps.label || this.$primevue.config.locale.reject : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
acceptIcon() {
|
2024-03-27 15:45:05 +00:00
|
|
|
return this.confirmation ? this.confirmation.acceptIcon : this.confirmation?.acceptProps ? this.confirmation.acceptProps.icon : null;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
rejectIcon() {
|
2024-03-27 15:45:05 +00:00
|
|
|
return this.confirmation ? this.confirmation.rejectIcon : this.confirmation?.rejectProps ? this.confirmation.rejectProps.icon : 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: {
|
2024-03-27 13:22:02 +00:00
|
|
|
Dialog,
|
|
|
|
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>
|