-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManageModal.vue
91 lines (84 loc) · 2.35 KB
/
ManageModal.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
<template>
<b-modal
id="manage-cookies"
modal-class="cc-manage-modal"
v-model="visible"
:title="title"
@ok="handleOkClicked"
@hide="handleHide"
>
<template v-slot:modal-title>
<slot name="title" />
</template>
<div class="cc-manage-modal__description mb-3">
<slot />
</div>
<ManageForm
:endpoint="endpoint"
:categories="categories"
:value="value"
:required-label="requiredLabel"
:anonymize-label="anonymizeLabel"
ref="form"
/>
<template v-slot:modal-footer="{ ok }">
<button type="submit" class="btn btn-primary" @click="ok">
<slot name="ok-button" />
</button>
</template>
</b-modal>
</template>
<script>
import ManageForm from './ManageForm';
import { BModal } from 'bootstrap-vue';
function resetLocationtHash() {
if(history && history.replaceState) {
history.replaceState(null, null, `${window.location.pathname}${window.location.search}`);
} else {
location.hash = '';
}
}
export default {
components: {
ManageForm,
BModal,
},
props: {
endpoint: String,
value: Object,
categories: Array,
title: String,
requiredLabel: String,
anonymizeLabel: String,
},
data() {
return {
visible: false,
}
},
methods: {
handleOkClicked() {
this.$refs.form.submit();
},
handleHide() {
if(location.hash === '#manage-cookies') {
resetLocationtHash();
}
},
init() {
if(location.hash === '#manage-cookies') {
this.visible = true;
}
},
},
created() {
this.init();
window.addEventListener('hashchange', this.init);
},
destroyed() {
document.removeEventListener('hashchange', this.init);
},
}
</script>
<!-- not scoped as not working with modal -->
<style src="../../scss/components/_manage-modal.scss" lang="scss"></style>