|
Lines 11-16
Link Here
|
| 11 |
document |
11 |
document |
| 12 |
.getElementById("deleteForm") |
12 |
.getElementById("deleteForm") |
| 13 |
?.addEventListener("submit", handleDeleteSubmit); |
13 |
?.addEventListener("submit", handleDeleteSubmit); |
|
|
14 |
document |
| 15 |
.getElementById("quotaUsageModal") |
| 16 |
?.addEventListener("show.bs.modal", handleShowQuotaUsageModal); |
| 14 |
|
17 |
|
| 15 |
async function handleQuotaSubmit(e) { |
18 |
async function handleQuotaSubmit(e) { |
| 16 |
e.preventDefault(); |
19 |
e.preventDefault(); |
|
Lines 28-34
Link Here
|
| 28 |
const endDate = formData.get("end_date"); |
31 |
const endDate = formData.get("end_date"); |
| 29 |
const allocation = formData.get("allocation"); |
32 |
const allocation = formData.get("allocation"); |
| 30 |
|
33 |
|
| 31 |
const quotaUrl = quotaId ? `/api/v1/patrons/${patronId}/quotas/${quotaId}` : `/api/v1/patrons/${patronId}/quotas`; |
34 |
const quotaUrl = quotaId |
|
|
35 |
? `/api/v1/patrons/${patronId}/quotas/${quotaId}` |
| 36 |
: `/api/v1/patrons/${patronId}/quotas`; |
| 32 |
let [error, response] = await catchError( |
37 |
let [error, response] = await catchError( |
| 33 |
fetch(quotaUrl, { |
38 |
fetch(quotaUrl, { |
| 34 |
method: quotaId ? "PUT" : "POST", |
39 |
method: quotaId ? "PUT" : "POST", |
|
Lines 37-43
Link Here
|
| 37 |
description: description, |
42 |
description: description, |
| 38 |
start_date: startDate, |
43 |
start_date: startDate, |
| 39 |
end_date: endDate, |
44 |
end_date: endDate, |
| 40 |
allocation: allocation |
45 |
allocation: allocation, |
| 41 |
}), |
46 |
}), |
| 42 |
headers: { |
47 |
headers: { |
| 43 |
"Content-Type": "application/json", |
48 |
"Content-Type": "application/json", |
|
Lines 45-53
Link Here
|
| 45 |
}) |
50 |
}) |
| 46 |
); |
51 |
); |
| 47 |
if (error || !response.ok) { |
52 |
if (error || !response.ok) { |
| 48 |
const alertContainer = document.getElementById( |
53 |
const alertContainer = document.getElementById("quota_result"); |
| 49 |
"quota_result" |
|
|
| 50 |
); |
| 51 |
alertContainer.outerHTML = ` |
54 |
alertContainer.outerHTML = ` |
| 52 |
<div id="quota_result" class="alert alert-danger"> |
55 |
<div id="quota_result" class="alert alert-danger"> |
| 53 |
${__("Failure")} |
56 |
${__("Failure")} |
|
Lines 75-98
Link Here
|
| 75 |
|
78 |
|
| 76 |
const quotaIdInput = document.getElementById("quota_id"); |
79 |
const quotaIdInput = document.getElementById("quota_id"); |
| 77 |
const quotaPatronInput = document.getElementById("patron_id"); |
80 |
const quotaPatronInput = document.getElementById("patron_id"); |
| 78 |
const quotaDescriptionInput = document.getElementById("quota_description"); |
81 |
const quotaDescriptionInput = |
|
|
82 |
document.getElementById("quota_description"); |
| 79 |
const quotaStartDateInput = document.getElementById("quota_from"); |
83 |
const quotaStartDateInput = document.getElementById("quota_from"); |
| 80 |
const quotaEndDateInput = document.getElementById("quota_to"); |
84 |
const quotaEndDateInput = document.getElementById("quota_to"); |
| 81 |
const quotaAllocationInput = document.getElementById("quota_allocation"); |
85 |
const quotaAllocationInput = |
|
|
86 |
document.getElementById("quota_allocation"); |
| 82 |
|
87 |
|
| 83 |
const quota = button.dataset.quota; |
88 |
const quota = button.dataset.quota; |
| 84 |
if (quota) { |
89 |
if (quota) { |
| 85 |
quotaIdInput.value = quota; |
90 |
quotaIdInput.value = quota; |
| 86 |
quotaModalLabel.textContent = _("Edit quota"); |
91 |
quotaModalLabel.textContent = __("Edit quota"); |
| 87 |
quotaModalSubmit.innerHTML = "<i class=\"fa fa-check\"></i> " + _("Update"); |
92 |
quotaModalSubmit.innerHTML = |
|
|
93 |
'<i class="fa fa-check"></i> ' + __("Update"); |
| 88 |
quotaDescriptionInput.value = button.dataset.description; |
94 |
quotaDescriptionInput.value = button.dataset.description; |
| 89 |
quotaStartDateInput._flatpickr.setDate(button.dataset.start_date, 1); |
95 |
quotaStartDateInput._flatpickr.setDate( |
|
|
96 |
button.dataset.start_date, |
| 97 |
1 |
| 98 |
); |
| 90 |
quotaEndDateInput._flatpickr.setDate(button.dataset.end_date, 1); |
99 |
quotaEndDateInput._flatpickr.setDate(button.dataset.end_date, 1); |
| 91 |
quotaAllocationInput.value = button.dataset.allocation; |
100 |
quotaAllocationInput.value = button.dataset.allocation; |
| 92 |
} else { |
101 |
} else { |
| 93 |
quotaIdInput.value = null; |
102 |
quotaIdInput.value = null; |
| 94 |
quotaModalLabel.textContent = _("Add quota"); |
103 |
quotaModalLabel.textContent = __("Add quota"); |
| 95 |
quotaModalSubmit.innerHTML = "<i class=\"fa fa-fw fa-plus\"></i> " + _("Add"); |
104 |
quotaModalSubmit.innerHTML = |
|
|
105 |
'<i class="fa fa-fw fa-plus"></i> ' + __("Add"); |
| 96 |
quotaDescriptionInput.value = null; |
106 |
quotaDescriptionInput.value = null; |
| 97 |
quotaStartDateInput.value = null; |
107 |
quotaStartDateInput.value = null; |
| 98 |
quotaEndDateInput.value = null; |
108 |
quotaEndDateInput.value = null; |
|
Lines 127-135
Link Here
|
| 127 |
}) |
137 |
}) |
| 128 |
); |
138 |
); |
| 129 |
if (error || !response.ok) { |
139 |
if (error || !response.ok) { |
| 130 |
const alertContainer = document.getElementById( |
140 |
const alertContainer = document.getElementById("quota_result"); |
| 131 |
"quota_result" |
|
|
| 132 |
); |
| 133 |
alertContainer.outerHTML = ` |
141 |
alertContainer.outerHTML = ` |
| 134 |
<div id="quota_result" class="alert alert-danger"> |
142 |
<div id="quota_result" class="alert alert-danger"> |
| 135 |
${__("Failure")} |
143 |
${__("Failure")} |
|
Lines 162-167
Link Here
|
| 162 |
return; |
170 |
return; |
| 163 |
} |
171 |
} |
| 164 |
|
172 |
|
|
|
173 |
function handleShowQuotaUsageModal(e) { |
| 174 |
const button = e.relatedTarget; |
| 175 |
if (!button) { |
| 176 |
return; |
| 177 |
} |
| 178 |
|
| 179 |
const quota = button.dataset.quota; |
| 180 |
const patron = button.dataset.patron; |
| 181 |
|
| 182 |
// Destroy any existing DataTable instance to prevent duplication |
| 183 |
if ($.fn.DataTable.isDataTable("#usage_detail")) { |
| 184 |
$("#usage_detail").DataTable().destroy(); |
| 185 |
} |
| 186 |
|
| 187 |
// Initialize DataTable |
| 188 |
let usage_url = "/api/v1/patrons/%s/quotas/%s/usages".format( |
| 189 |
patron, |
| 190 |
quota |
| 191 |
); |
| 192 |
$("#usage_detail").kohaTable({ |
| 193 |
ajax: { |
| 194 |
url: usage_url, |
| 195 |
}, |
| 196 |
embed: ["patron", "checkout.item.biblio"], |
| 197 |
columns: [ |
| 198 |
{ |
| 199 |
title: __("Date"), |
| 200 |
data: "creation_date", |
| 201 |
searchable: true, |
| 202 |
orderable: true, |
| 203 |
render: function (data, type, row, meta) { |
| 204 |
return $date(row.creation_date); |
| 205 |
}, |
| 206 |
}, |
| 207 |
{ |
| 208 |
title: __("Patron"), |
| 209 |
data: "patron", |
| 210 |
render: function (data, type, row, meta) { |
| 211 |
return $patron_to_html(row.patron, { |
| 212 |
display_cardnumber: false, |
| 213 |
url: true, |
| 214 |
}); |
| 215 |
}, |
| 216 |
}, |
| 217 |
{ |
| 218 |
title: __("Item"), |
| 219 |
data: "checkout.item.biblio.title", |
| 220 |
render: function (data, type, row, meta) { |
| 221 |
if (row.checkout) { |
| 222 |
return $biblio_to_html(row.checkout.item.biblio, { |
| 223 |
link: 1, |
| 224 |
}); |
| 225 |
} else { |
| 226 |
return __("Circulation history removed"); |
| 227 |
} |
| 228 |
}, |
| 229 |
}, |
| 230 |
{ |
| 231 |
title: __("Usage Type"), |
| 232 |
data: "type", |
| 233 |
searchable: true, |
| 234 |
orderable: true, |
| 235 |
render: function (data, type, row, meta) { |
| 236 |
return row.type; |
| 237 |
}, |
| 238 |
}, |
| 239 |
], |
| 240 |
paging: true, |
| 241 |
searching: true, |
| 242 |
lengthChange: false, |
| 243 |
}); |
| 244 |
return; |
| 245 |
} |
| 246 |
|
| 165 |
function catchError(promise) { |
247 |
function catchError(promise) { |
| 166 |
return promise.then(data => [undefined, data]).catch(error => [error]); |
248 |
return promise.then(data => [undefined, data]).catch(error => [error]); |
| 167 |
} |
249 |
} |
| 168 |
- |
|
|