View | Details | Raw Unified | Return to bug 38924
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/modals/quota.js (-5 / +56 lines)
Lines 2-7 Link Here
2
    document
2
    document
3
        .getElementById("quotaModal")
3
        .getElementById("quotaModal")
4
        ?.addEventListener("show.bs.modal", handleShowQuotaModal);
4
        ?.addEventListener("show.bs.modal", handleShowQuotaModal);
5
    document
6
        .getElementById("quotaModal")
7
        ?.addEventListener("hidden.bs.modal", handleHideQuotaModal);
5
    document
8
    document
6
        .getElementById("quotaForm")
9
        .getElementById("quotaForm")
7
        ?.addEventListener("submit", handleQuotaSubmit);
10
        ?.addEventListener("submit", handleQuotaSubmit);
Lines 27-36 Link Here
27
        const quotaId = formData.get("quota_id");
30
        const quotaId = formData.get("quota_id");
28
        const patronId = formData.get("patron_id");
31
        const patronId = formData.get("patron_id");
29
        const description = formData.get("description");
32
        const description = formData.get("description");
30
        const startDate = formData.get("start_date");
31
        const endDate = formData.get("end_date");
32
        const allocation = formData.get("allocation");
33
        const allocation = formData.get("allocation");
33
34
35
        const quotaStartPicker =
36
            document.getElementById("quota_from")._flatpickr;
37
        const quotaEndPicker = document.getElementById("quota_to")._flatpickr;
38
39
        const startDate = quotaStartPicker.selectedDates[0]
40
            ? flatpickr.formatDate(quotaStartPicker.selectedDates[0], "Y-m-d")
41
            : null;
42
        const endDate = quotaEndPicker.selectedDates[0]
43
            ? flatpickr.formatDate(quotaEndPicker.selectedDates[0], "Y-m-d")
44
            : null;
45
34
        const quotaUrl = quotaId
46
        const quotaUrl = quotaId
35
            ? `/api/v1/patrons/${patronId}/quotas/${quotaId}`
47
            ? `/api/v1/patrons/${patronId}/quotas/${quotaId}`
36
            : `/api/v1/patrons/${patronId}/quotas`;
48
            : `/api/v1/patrons/${patronId}/quotas`;
Lines 49-58 Link Here
49
            })
61
            })
50
        );
62
        );
51
        if (error || !response.ok) {
63
        if (error || !response.ok) {
64
            let errorMessage = __("Failure");
65
66
            try {
67
                const errorData = await response.json();
68
                if (errorData.error) {
69
                    errorMessage = errorData.error;
70
                }
71
            } catch (e) {
72
                // If parsing fails, use default message
73
            }
74
52
            const alertContainer = document.getElementById("quota_result");
75
            const alertContainer = document.getElementById("quota_result");
53
            alertContainer.outerHTML = `
76
            alertContainer.outerHTML = `
54
                <div id="quota_result" class="alert alert-danger">
77
                <div id="quota_result" class="alert alert-danger">
55
                    ${__("Failure")}
78
                    ${errorMessage}
56
                </div>
79
                </div>
57
            `;
80
            `;
58
81
Lines 72-77 Link Here
72
            return;
95
            return;
73
        }
96
        }
74
97
98
        const alertContainer = document.getElementById("quota_result");
99
        if (alertContainer) {
100
            alertContainer.className = "";
101
            alertContainer.innerHTML = "";
102
        }
103
75
        const quotaModalLabel = document.getElementById("quotaLabel");
104
        const quotaModalLabel = document.getElementById("quotaLabel");
76
        const quotaModalSubmit = document.getElementById("quotaFormSubmit");
105
        const quotaModalSubmit = document.getElementById("quotaFormSubmit");
77
106
Lines 114-119 Link Here
114
        return;
143
        return;
115
    }
144
    }
116
145
146
    function handleHideQuotaModal() {
147
        document.getElementById("quota_description").value = "";
148
        document.getElementById("quota_from")._flatpickr.clear();
149
        document.getElementById("quota_to")._flatpickr.clear();
150
        document.getElementById("quota_allocation").value = "";
151
        document.getElementById("quota_id").value = "";
152
        const alertContainer = document.getElementById("quota_result");
153
        if (alertContainer) {
154
            alertContainer.innerHTML = "";
155
        }
156
    }
157
117
    async function handleDeleteSubmit(e) {
158
    async function handleDeleteSubmit(e) {
118
        e.preventDefault();
159
        e.preventDefault();
119
160
Lines 136-145 Link Here
136
            })
177
            })
137
        );
178
        );
138
        if (error || !response.ok) {
179
        if (error || !response.ok) {
180
            let errorMessage = __("Failure");
181
182
            try {
183
                const errorData = await response.json();
184
                if (errorData.error) {
185
                    errorMessage = errorData.error;
186
                }
187
            } catch (e) {
188
                // If parsing fails, use default message
189
            }
190
139
            const alertContainer = document.getElementById("quota_result");
191
            const alertContainer = document.getElementById("quota_result");
140
            alertContainer.outerHTML = `
192
            alertContainer.outerHTML = `
141
                <div id="quota_result" class="alert alert-danger">
193
                <div id="quota_result" class="alert alert-danger">
142
                    ${__("Failure")}
194
                    ${errorMessage}
143
                </div>
195
                </div>
144
            `;
196
            `;
145
197
146
- 

Return to bug 38924