From 090e518082696f6857e2edb7fec5f24b3b91edda Mon Sep 17 00:00:00 2001 From: Jacob O'Mara Date: Fri, 7 Nov 2025 11:50:36 +0000 Subject: [PATCH] Bug 38924: (follow-up) Minor QOL quota modal fixes This patch: - Makes sure that the quotas modal displays the error message for why the submit failed, instead of a generic message - Clears the modal data on modal close to remove persistent data - Get dates directly from flatpickr selectedDates for API requests to ensure sync. --- .../intranet-tmpl/prog/js/modals/quota.js | 60 +++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/modals/quota.js b/koha-tmpl/intranet-tmpl/prog/js/modals/quota.js index b6a795217d4..a83acc6d3f1 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/modals/quota.js +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/quota.js @@ -2,6 +2,9 @@ document .getElementById("quotaModal") ?.addEventListener("show.bs.modal", handleShowQuotaModal); + document + .getElementById("quotaModal") + ?.addEventListener("hidden.bs.modal", handleHideQuotaModal); document .getElementById("quotaForm") ?.addEventListener("submit", handleQuotaSubmit); @@ -27,10 +30,19 @@ const quotaId = formData.get("quota_id"); const patronId = formData.get("patron_id"); const description = formData.get("description"); - const startDate = formData.get("start_date"); - const endDate = formData.get("end_date"); const allocation = formData.get("allocation"); + const quotaStartPicker = + document.getElementById("quota_from")._flatpickr; + const quotaEndPicker = document.getElementById("quota_to")._flatpickr; + + const startDate = quotaStartPicker.selectedDates[0] + ? flatpickr.formatDate(quotaStartPicker.selectedDates[0], "Y-m-d") + : null; + const endDate = quotaEndPicker.selectedDates[0] + ? flatpickr.formatDate(quotaEndPicker.selectedDates[0], "Y-m-d") + : null; + const quotaUrl = quotaId ? `/api/v1/patrons/${patronId}/quotas/${quotaId}` : `/api/v1/patrons/${patronId}/quotas`; @@ -50,10 +62,21 @@ }) ); if (error || !response.ok) { + let errorMessage = __("Failure"); + + try { + const errorData = await response.json(); + if (errorData.error) { + errorMessage = errorData.error; + } + } catch (e) { + // If parsing fails, use default message + } + const alertContainer = document.getElementById("quota_result"); alertContainer.outerHTML = `
- ${__("Failure")} + ${errorMessage}
`; @@ -73,6 +96,12 @@ return; } + const alertContainer = document.getElementById("quota_result"); + if (alertContainer) { + alertContainer.className = ""; + alertContainer.innerHTML = ""; + } + const quotaModalLabel = document.getElementById("quotaLabel"); const quotaModalSubmit = document.getElementById("quotaFormSubmit"); @@ -115,6 +144,18 @@ return; } + function handleHideQuotaModal() { + document.getElementById("quota_description").value = ""; + document.getElementById("quota_from")._flatpickr.clear(); + document.getElementById("quota_to")._flatpickr.clear(); + document.getElementById("quota_allocation").value = ""; + document.getElementById("quota_id").value = ""; + const alertContainer = document.getElementById("quota_result"); + if (alertContainer) { + alertContainer.innerHTML = ""; + } + } + async function handleDeleteSubmit(e) { e.preventDefault(); @@ -137,10 +178,21 @@ }) ); if (error || !response.ok) { + let errorMessage = __("Failure"); + + try { + const errorData = await response.json(); + if (errorData.error) { + errorMessage = errorData.error; + } + } catch (e) { + // If parsing fails, use default message + } + const alertContainer = document.getElementById("quota_result"); alertContainer.outerHTML = `
- ${__("Failure")} + ${errorMessage}
`; -- 2.39.5