From d14177b8aed8671b1da1362569742e3f9e16d3c4 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 - 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 1c534730fc2..70fbda32d1e 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`; @@ -49,10 +61,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}
`; @@ -72,6 +95,12 @@ return; } + const alertContainer = document.getElementById("quota_result"); + if (alertContainer) { + alertContainer.className = ""; + alertContainer.innerHTML = ""; + } + const quotaModalLabel = document.getElementById("quotaLabel"); const quotaModalSubmit = document.getElementById("quotaFormSubmit"); @@ -114,6 +143,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(); @@ -136,10 +177,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