-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathConfirmDialog.vue
107 lines (106 loc) · 3.6 KB
/
ConfirmDialog.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<template>
<CDialog :visible="visible" :modal="true" :header="header" :blockScroll="blockScroll" :position="position" class="p-confirm-dialog" @click="closeDialog($event)">
<i :class="iconClass" />
<span class="p-confirm-dialog-message">{{message}}</span>
<template #footer>
<CDButton :label="rejectLabel" :icon="rejectIcon" :class="rejectClass" @click="reject()"/>
<CDButton :label="acceptLabel" :icon="acceptIcon" :class="acceptClass" @click="accept()" autofocus />
</template>
</CDialog>
</template>
<script>
import ConfirmationEventBus from '../confirmationservice/ConfirmationEventBus';
import Dialog from '../dialog/Dialog';
import Button from '../button/Button';
import DomHandler from '../utils/DomHandler';
export default {
props: {
group: String
},
data() {
return {
visible: false,
confirmation: null,
}
},
mounted() {
ConfirmationEventBus.on('confirm', (options) => {
if (!options) {
return;
}
if (options.group === this.group) {
this.confirmation = options;
this.visible = true;
}
});
ConfirmationEventBus.on('close', () => {
this.visible = false;
this.confirmation = null;
});
},
beforeDestroy() {
ConfirmationEventBus.off('confirm');
ConfirmationEventBus.off('close');
},
methods: {
accept() {
if (this.confirmation.accept) {
this.confirmation.accept();
}
this.visible = false;
},
reject() {
if (this.confirmation.reject) {
this.confirmation.reject();
}
this.visible = false;
},
closeDialog($event) {
if(DomHandler.hasClass($event.target, 'p-dialog-header-close') || DomHandler.hasClass($event.target, 'p-dialog-header-close-icon')) {
ConfirmationEventBus.off('confirm');
ConfirmationEventBus.off('close');
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() {
return this.confirmation ? (this.confirmation.acceptLabel || this.$primevue.config.locale.accept) : null;
},
rejectLabel() {
return this.confirmation ? (this.confirmation.rejectLabel || this.$primevue.config.locale.reject) : null;
},
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() {
return ['p-confirm-dialog-reject', this.confirmation ? (this.confirmation.rejectClass || 'p-button-text') : null];
}
},
components: {
'CDialog': Dialog,
'CDButton': Button
}
}
</script>