|
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 50-59
Link Here
|
| 50 |
}) |
62 |
}) |
| 51 |
); |
63 |
); |
| 52 |
if (error || !response.ok) { |
64 |
if (error || !response.ok) { |
|
|
65 |
let errorMessage = __("Failure"); |
| 66 |
|
| 67 |
try { |
| 68 |
const errorData = await response.json(); |
| 69 |
if (errorData.error) { |
| 70 |
errorMessage = errorData.error; |
| 71 |
} |
| 72 |
} catch (e) { |
| 73 |
// If parsing fails, use default message |
| 74 |
} |
| 75 |
|
| 53 |
const alertContainer = document.getElementById("quota_result"); |
76 |
const alertContainer = document.getElementById("quota_result"); |
| 54 |
alertContainer.outerHTML = ` |
77 |
alertContainer.outerHTML = ` |
| 55 |
<div id="quota_result" class="alert alert-danger"> |
78 |
<div id="quota_result" class="alert alert-danger"> |
| 56 |
${__("Failure")} |
79 |
${errorMessage} |
| 57 |
</div> |
80 |
</div> |
| 58 |
`; |
81 |
`; |
| 59 |
|
82 |
|
|
Lines 73-78
Link Here
|
| 73 |
return; |
96 |
return; |
| 74 |
} |
97 |
} |
| 75 |
|
98 |
|
|
|
99 |
const alertContainer = document.getElementById("quota_result"); |
| 100 |
if (alertContainer) { |
| 101 |
alertContainer.className = ""; |
| 102 |
alertContainer.innerHTML = ""; |
| 103 |
} |
| 104 |
|
| 76 |
const quotaModalLabel = document.getElementById("quotaLabel"); |
105 |
const quotaModalLabel = document.getElementById("quotaLabel"); |
| 77 |
const quotaModalSubmit = document.getElementById("quotaFormSubmit"); |
106 |
const quotaModalSubmit = document.getElementById("quotaFormSubmit"); |
| 78 |
|
107 |
|
|
Lines 115-120
Link Here
|
| 115 |
return; |
144 |
return; |
| 116 |
} |
145 |
} |
| 117 |
|
146 |
|
|
|
147 |
function handleHideQuotaModal() { |
| 148 |
document.getElementById("quota_description").value = ""; |
| 149 |
document.getElementById("quota_from")._flatpickr.clear(); |
| 150 |
document.getElementById("quota_to")._flatpickr.clear(); |
| 151 |
document.getElementById("quota_allocation").value = ""; |
| 152 |
document.getElementById("quota_id").value = ""; |
| 153 |
const alertContainer = document.getElementById("quota_result"); |
| 154 |
if (alertContainer) { |
| 155 |
alertContainer.innerHTML = ""; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 118 |
async function handleDeleteSubmit(e) { |
159 |
async function handleDeleteSubmit(e) { |
| 119 |
e.preventDefault(); |
160 |
e.preventDefault(); |
| 120 |
|
161 |
|
|
Lines 137-146
Link Here
|
| 137 |
}) |
178 |
}) |
| 138 |
); |
179 |
); |
| 139 |
if (error || !response.ok) { |
180 |
if (error || !response.ok) { |
|
|
181 |
let errorMessage = __("Failure"); |
| 182 |
|
| 183 |
try { |
| 184 |
const errorData = await response.json(); |
| 185 |
if (errorData.error) { |
| 186 |
errorMessage = errorData.error; |
| 187 |
} |
| 188 |
} catch (e) { |
| 189 |
// If parsing fails, use default message |
| 190 |
} |
| 191 |
|
| 140 |
const alertContainer = document.getElementById("quota_result"); |
192 |
const alertContainer = document.getElementById("quota_result"); |
| 141 |
alertContainer.outerHTML = ` |
193 |
alertContainer.outerHTML = ` |
| 142 |
<div id="quota_result" class="alert alert-danger"> |
194 |
<div id="quota_result" class="alert alert-danger"> |
| 143 |
${__("Failure")} |
195 |
${errorMessage} |
| 144 |
</div> |
196 |
</div> |
| 145 |
`; |
197 |
`; |
| 146 |
|
198 |
|
| 147 |
- |
|
|