|
Lines 1-40
Link Here
|
| 1 |
import { defineStore } from "pinia"; |
1 |
import { defineStore } from "pinia"; |
|
|
2 |
import { reactive, toRefs } from "vue"; |
| 2 |
|
3 |
|
| 3 |
export const useMainStore = defineStore("main", { |
4 |
export const useMainStore = defineStore("main", () => { |
| 4 |
state: () => ({ |
5 |
const store = reactive({ |
| 5 |
_message: null, |
6 |
message: null, |
| 6 |
_error: null, |
7 |
error: null, |
| 7 |
_warning: null, |
8 |
warning: null, |
| 8 |
_confirmation: null, |
9 |
confirmation: null, |
| 9 |
_accept_callback: null, |
10 |
accept_callback: null, |
| 10 |
previousMessage: null, |
11 |
previousMessage: null, |
| 11 |
previousError: null, |
12 |
previousError: null, |
| 12 |
displayed_already: false, |
13 |
displayed_already: false, |
| 13 |
_is_submitting: false, |
14 |
is_submitting: false, |
| 14 |
_is_loading: false, |
15 |
is_loading: false, |
| 15 |
}), |
16 |
}); |
| 16 |
actions: { |
17 |
|
|
|
18 |
const actions = { |
| 17 |
setMessage(message, displayed = false) { |
19 |
setMessage(message, displayed = false) { |
| 18 |
this._error = null; |
20 |
this.error = null; |
| 19 |
this._warning = null; |
21 |
this.warning = null; |
| 20 |
this._message = message; |
22 |
this.message = message; |
| 21 |
this._confirmation = null; |
23 |
this.confirmation = null; |
| 22 |
this.displayed_already = |
24 |
this.displayed_already = |
| 23 |
displayed; /* Will be displayed on the next view */ |
25 |
displayed; /* Will be displayed on the next view */ |
| 24 |
}, |
26 |
}, |
| 25 |
setError(error, displayed = true) { |
27 |
setError(error, displayed = true) { |
| 26 |
this._error = error; |
28 |
this.error = error; |
| 27 |
this._warning = null; |
29 |
this.warning = null; |
| 28 |
this._message = null; |
30 |
this.message = null; |
| 29 |
this._confirmation = null; |
31 |
this.confirmation = null; |
| 30 |
this.displayed_already = |
32 |
this.displayed_already = |
| 31 |
displayed; /* Is displayed on the current view */ |
33 |
displayed; /* Is displayed on the current view */ |
| 32 |
}, |
34 |
}, |
| 33 |
setWarning(warning, displayed = true) { |
35 |
setWarning(warning, displayed = true) { |
| 34 |
this._error = null; |
36 |
this.error = null; |
| 35 |
this._warning = warning; |
37 |
this.warning = warning; |
| 36 |
this._message = null; |
38 |
this.message = null; |
| 37 |
this._confirmation = null; |
39 |
this.confirmation = null; |
| 38 |
this.displayed_already = |
40 |
this.displayed_already = |
| 39 |
displayed; /* Is displayed on the current view */ |
41 |
displayed; /* Is displayed on the current view */ |
| 40 |
}, |
42 |
}, |
|
Lines 55-117
export const useMainStore = defineStore("main", {
Link Here
|
| 55 |
*/ |
57 |
*/ |
| 56 |
setConfirmationDialog(confirmation, accept_callback, displayed = true) { |
58 |
setConfirmationDialog(confirmation, accept_callback, displayed = true) { |
| 57 |
if (accept_callback) { |
59 |
if (accept_callback) { |
| 58 |
this._accept_callback = async () => { |
60 |
this.accept_callback = async () => { |
| 59 |
await accept_callback(confirmation); |
61 |
await accept_callback(confirmation); |
| 60 |
this.removeConfirmationMessages(); |
62 |
this.removeConfirmationMessages(); |
| 61 |
}; |
63 |
}; |
| 62 |
} |
64 |
} |
| 63 |
this._confirmation = confirmation; |
65 |
this.confirmation = confirmation; |
| 64 |
this.displayed_already = |
66 |
this.displayed_already = |
| 65 |
displayed; /* Is displayed on the current view */ |
67 |
displayed; /* Is displayed on the current view */ |
| 66 |
}, |
68 |
}, |
| 67 |
removeMessages() { |
69 |
removeMessages() { |
| 68 |
if (this.displayed_already) { |
70 |
if (this.displayed_already) { |
| 69 |
this._error = null; |
71 |
this.error = null; |
| 70 |
this._warning = null; |
72 |
this.warning = null; |
| 71 |
this._message = null; |
73 |
this.message = null; |
| 72 |
this._confirmation = null; |
74 |
this.confirmation = null; |
| 73 |
this._accept_callback = null; |
75 |
this.accept_callback = null; |
| 74 |
} |
76 |
} |
| 75 |
this.displayed_already = true; |
77 |
this.displayed_already = true; |
| 76 |
}, |
78 |
}, |
| 77 |
removeConfirmationMessages() { |
79 |
removeConfirmationMessages() { |
| 78 |
this._confirmation = null; |
80 |
this.confirmation = null; |
| 79 |
this._accept_callback = null; |
81 |
this.accept_callback = null; |
| 80 |
}, |
82 |
}, |
| 81 |
submitting() { |
83 |
submitting() { |
| 82 |
this._is_submitting = true; |
84 |
this.is_submitting = true; |
| 83 |
}, |
85 |
}, |
| 84 |
submitted() { |
86 |
submitted() { |
| 85 |
this._is_submitting = false; |
87 |
this.is_submitting = false; |
| 86 |
}, |
88 |
}, |
| 87 |
loading() { |
89 |
loading() { |
| 88 |
this._is_loading = true; |
90 |
this.is_loading = true; |
| 89 |
}, |
91 |
}, |
| 90 |
loaded() { |
92 |
loaded() { |
| 91 |
this._is_loading = false; |
93 |
this.is_loading = false; |
| 92 |
}, |
|
|
| 93 |
}, |
| 94 |
getters: { |
| 95 |
error() { |
| 96 |
return this._error; |
| 97 |
}, |
| 98 |
warning() { |
| 99 |
return this._warning; |
| 100 |
}, |
| 101 |
message() { |
| 102 |
return this._message; |
| 103 |
}, |
| 104 |
confirmation() { |
| 105 |
return this._confirmation; |
| 106 |
}, |
94 |
}, |
| 107 |
accept_callback() { |
95 |
}; |
| 108 |
return this._accept_callback; |
96 |
|
| 109 |
}, |
97 |
return { |
| 110 |
is_submitting() { |
98 |
...toRefs(store), |
| 111 |
return this._is_submitting; |
99 |
...actions, |
| 112 |
}, |
100 |
}; |
| 113 |
is_loading() { |
|
|
| 114 |
return this._is_loading; |
| 115 |
}, |
| 116 |
}, |
| 117 |
}); |
101 |
}); |