Bug 32991: Don't remove all messages when confirm box is closed
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / vue / stores / main.js
1 import { defineStore } from "pinia";
2
3 export const useMainStore = defineStore("main", {
4     state: () => ({
5         _message: null,
6         _error: null,
7         _warning: null,
8         _confirmation: null,
9         _accept_callback: null,
10         previousMessage: null,
11         previousError: null,
12         displayed_already: false,
13         _is_submitting: false,
14         _is_loading: false,
15     }),
16     actions: {
17         setMessage(message, displayed = false) {
18             this._error = null;
19             this._warning = null;
20             this._message = message;
21             this._confirmation = null;
22             this.displayed_already = displayed; /* Will be displayed on the next view */
23         },
24         setError(error, displayed = true) {
25             this._error = error;
26             this._warning = null;
27             this._message = null;
28             this._confirmation = null;
29             this.displayed_already = displayed; /* Is displayed on the current view */
30         },
31         setWarning(warning, displayed = true) {
32             this._error = null;
33             this._warning = warning;
34             this._message = null;
35             this._confirmation = null;
36             this.displayed_already = displayed; /* Is displayed on the current view */
37         },
38         setConfirmationDialog(confirmation, accept_callback, displayed = true){
39             if(accept_callback) {
40                 this._accept_callback = async () => {
41                     await accept_callback()
42                     this.removeConfirmationMessages()
43                 }
44             }
45             this._confirmation = confirmation;
46             this.displayed_already = displayed; /* Is displayed on the current view */
47         },
48         removeMessages() {
49             if (this.displayed_already) {
50                 this._error = null;
51                 this._warning = null;
52                 this._message = null;
53                 this._confirmation = null;
54                 this._accept_callback = null;
55             }
56             this.displayed_already = true;
57         },
58         removeConfirmationMessages(){
59             this._confirmation = null;
60             this._accept_callback = null;
61         },
62         submitting(){
63             this._is_submitting = true;
64         },
65         submitted(){
66             this._is_submitting = false;
67         },
68         loading(){
69             this._is_loading = true;
70         },
71         loaded(){
72             this._is_loading = false;
73         },
74     },
75     getters: {
76         error() {
77             return this._error
78         },
79         warning() {
80             return this._warning
81         },
82         message() {
83             return this._message
84         },
85         confirmation() {
86             return this._confirmation
87         },
88         accept_callback() {
89             return this._accept_callback
90         },
91         is_submitting(){
92             return this._is_submitting
93         },
94         is_loading(){
95             return this._is_loading
96         },
97     },
98 });