Lines 73-78
Link Here
|
73 |
<script> |
73 |
<script> |
74 |
dayjs.extend(window.dayjs_plugin_isSameOrBefore); |
74 |
dayjs.extend(window.dayjs_plugin_isSameOrBefore); |
75 |
</script> |
75 |
</script> |
|
|
76 |
[% Asset.js("js/additional-fields.js") | $raw %] |
76 |
[% Asset.js("js/modals/place_booking.js") | $raw %] |
77 |
[% Asset.js("js/modals/place_booking.js") | $raw %] |
77 |
[% Asset.js("js/cancel_booking_modal.js") | $raw %] |
78 |
[% Asset.js("js/cancel_booking_modal.js") | $raw %] |
78 |
[% Asset.js("js/combobox.js") | $raw %] |
79 |
[% Asset.js("js/combobox.js") | $raw %] |
Lines 91-101
Link Here
|
91 |
}); |
92 |
}); |
92 |
var bookings = $.ajax({ |
93 |
var bookings = $.ajax({ |
93 |
url: '/api/v1/biblios/%s/bookings?_per_page=-1'.format(biblionumber), |
94 |
url: '/api/v1/biblios/%s/bookings?_per_page=-1'.format(biblionumber), |
94 |
headers: { 'x-koha-embed': 'patron' }, |
95 |
headers: { 'x-koha-embed': ['patron', 'extended_attributes'] }, |
95 |
dataType: 'json', |
96 |
dataType: 'json', |
96 |
type: 'GET', |
97 |
type: 'GET', |
97 |
}); |
98 |
}); |
98 |
|
99 |
var extended_attribute_types; |
|
|
100 |
var authorised_values; |
101 |
AdditionalFields.fetchAndProcessExtendedAttributes("booking") |
102 |
.then(types => { |
103 |
extended_attribute_types = types; |
104 |
const catArray = Object.values(types) |
105 |
.map(attr => attr.authorised_value_category_name) |
106 |
.filter(Boolean); |
107 |
return AdditionalFields.fetchAndProcessAuthorizedValues(catArray); |
108 |
}) |
109 |
.then(values => { |
110 |
authorised_values = values; |
111 |
}); |
99 |
$.when(items, bookings).then( |
112 |
$.when(items, bookings).then( |
100 |
function(items, bookings){ |
113 |
function(items, bookings){ |
101 |
var itemsSet = new vis.DataSet([{ |
114 |
var itemsSet = new vis.DataSet([{ |
Lines 123-128
Link Here
|
123 |
pickup_library: booking.pickup_library_id, |
136 |
pickup_library: booking.pickup_library_id, |
124 |
start: dayjs(booking.start_date).toDate(), |
137 |
start: dayjs(booking.start_date).toDate(), |
125 |
end: dayjs(booking.end_date).toDate(), |
138 |
end: dayjs(booking.end_date).toDate(), |
|
|
139 |
extended_attributes: booking.extended_attributes, |
126 |
content: !isActive ? `<s>${patronContent}</s>` : patronContent, |
140 |
content: !isActive ? `<s>${patronContent}</s>` : patronContent, |
127 |
[% IF CAN_user_circulate_manage_bookings %] |
141 |
[% IF CAN_user_circulate_manage_bookings %] |
128 |
editable: booking.status !== "cancelled" ? { remove: true, updateTime: true } : false, |
142 |
editable: booking.status !== "cancelled" ? { remove: true, updateTime: true } : false, |
Lines 190-196
Link Here
|
190 |
// set end datetime hours and minutes to the end of the day |
204 |
// set end datetime hours and minutes to the end of the day |
191 |
let endDate = dayjs(data.end).endOf('day'); |
205 |
let endDate = dayjs(data.end).endOf('day'); |
192 |
|
206 |
|
193 |
$('#placeBookingModal').modal('show', $('<button data-booking="'+data.id+'" data-biblionumber="[% biblionumber | uri %]" data-itemnumber="'+data.group+'" data-patron="'+data.patron+'" data-pickup_library="'+data.pickup_library+'" data-start_date="'+startDate.toISOString()+'" data-end_date="'+endDate.toISOString()+'">')); |
207 |
// Get the current booking to preserve extended attributes |
|
|
208 |
let currentBooking = bookingsSet.get(data.id); |
209 |
let extendedAttributes = currentBooking.extended_attributes || []; |
210 |
|
211 |
$('#placeBookingModal').modal('show', $(`<button |
212 |
data-booking="${data.id}" |
213 |
data-biblionumber="[% biblionumber | uri %]" |
214 |
data-itemnumber="${data.group}" |
215 |
data-patron="${data.patron}" |
216 |
data-pickup_library="${data.pickup_library}" |
217 |
data-start_date="${startDate.toISOString()}" |
218 |
data-end_date="${endDate.toISOString()}" |
219 |
data-extended_attributes='${JSON.stringify(extendedAttributes.map(attribute => ({ |
220 |
field_id: attribute.field_id, |
221 |
value: attribute.value |
222 |
})))}' |
223 |
>`)); |
194 |
$('#placeBookingModal').on('hide.bs.modal', function(e) { |
224 |
$('#placeBookingModal').on('hide.bs.modal', function(e) { |
195 |
if (update_success) { |
225 |
if (update_success) { |
196 |
update_success = 0; |
226 |
update_success = 0; |
Lines 246-252
Link Here
|
246 |
"embed": [ |
276 |
"embed": [ |
247 |
"item", |
277 |
"item", |
248 |
"patron", |
278 |
"patron", |
249 |
"pickup_library" |
279 |
"pickup_library", |
|
|
280 |
"extended_attributes", |
250 |
], |
281 |
], |
251 |
"columns": [{ |
282 |
"columns": [{ |
252 |
"data": "booking_id", |
283 |
"data": "booking_id", |
Lines 366-371
Link Here
|
366 |
return $date(row.end_date); |
397 |
return $date(row.end_date); |
367 |
} |
398 |
} |
368 |
}, |
399 |
}, |
|
|
400 |
{ |
401 |
data: "extended_attributes", |
402 |
title: _("Additional fields"), |
403 |
searchable: false, |
404 |
orderable: false, |
405 |
render: function (data, type, row, meta) { |
406 |
return AdditionalFields.renderExtendedAttributesValues( |
407 |
data, |
408 |
extended_attribute_types, |
409 |
authorised_values, |
410 |
row.booking_id |
411 |
).join("<br>"); |
412 |
}, |
413 |
}, |
369 |
{ |
414 |
{ |
370 |
"data": "", |
415 |
"data": "", |
371 |
"title": _("Actions"), |
416 |
"title": _("Actions"), |
Lines 377-384
Link Here
|
377 |
let is_cancelled = row.status === "cancelled"; |
422 |
let is_cancelled = row.status === "cancelled"; |
378 |
[% IF CAN_user_circulate_manage_bookings %] |
423 |
[% IF CAN_user_circulate_manage_bookings %] |
379 |
if (!is_cancelled) { |
424 |
if (!is_cancelled) { |
380 |
result += '<button type="button" class="btn btn-default btn-xs edit-action" data-bs-toggle="modal" data-bs-target="#placeBookingModal" data-booking="%s" data-biblionumber="%s" data-itemnumber="%s" data-patron="%s" data-pickup_library="%s" data-start_date="%s" data-end_date="%s"><i class="fa fa-pencil" aria-hidden="true"></i> %s</button>'.format(row.booking_id, biblionumber, row.item_id, row.patron_id, row.pickup_library_id, row.start_date, row.end_date, _("Edit")); |
425 |
result += ` |
381 |
result += '<button type="button" class="btn btn-default btn-xs cancel-action" data-bs-toggle="modal" data-bs-target="#cancelBookingModal" data-booking="%s"><i class="fa fa-trash" aria-hidden="true"></i> %s</button>'.format(row.booking_id, _("Cancel")); |
426 |
<button type="button" class="btn btn-default btn-xs edit-action" |
|
|
427 |
data-bs-toggle="modal" |
428 |
data-bs-target="#placeBookingModal" |
429 |
data-booking="${row.booking_id}" |
430 |
data-biblionumber="${biblionumber}" |
431 |
data-itemnumber="${row.item_id}" |
432 |
data-patron="${row.patron_id}" |
433 |
data-pickup_library="${row.pickup_library_id}" |
434 |
data-start_date="${row.start_date}" |
435 |
data-end_date="${row.end_date}" |
436 |
data-extended_attributes='${JSON.stringify(row.extended_attributes |
437 |
.filter(attribute => attribute.record_id == row.booking_id) |
438 |
.map(attribute => ({ |
439 |
field_id: attribute.field_id, |
440 |
value: attribute.value |
441 |
}) |
442 |
))}' |
443 |
> |
444 |
<i class="fa fa-pencil" aria-hidden="true"></i> ${_("Edit")} |
445 |
</button>`; |
446 |
result += ` |
447 |
<button type="button" class="btn btn-default btn-xs cancel-action" |
448 |
data-bs-toggle="modal" |
449 |
data-bs-target="#cancelBookingModal" |
450 |
data-booking="${row.booking_id}"> |
451 |
<i class="fa fa-trash" aria-hidden="true"></i> ${_("Cancel")} |
452 |
</button>`; |
382 |
} |
453 |
} |
383 |
[% END %] |
454 |
[% END %] |
384 |
return result; |
455 |
return result; |