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