Lines 108-113
$('#placeBookingModal').on('show.bs.modal', function(e) {
Link Here
|
108 |
|
108 |
|
109 |
$('#booking_patron_id').on('select2:select', function (e) { |
109 |
$('#booking_patron_id').on('select2:select', function (e) { |
110 |
booking_patron = e.params.data; |
110 |
booking_patron = e.params.data; |
|
|
111 |
$("#pickup_library_id").prop("disabled", false); |
112 |
}); |
113 |
|
114 |
// Pickup location select2 |
115 |
let pickup_url = '/api/v1/biblios/' + biblionumber + '/pickup_locations'; |
116 |
$("#pickup_library_id").kohaSelect({ |
117 |
dropdownParent: $(".modal-content", "#placeBookingModal"), |
118 |
width: '50%', |
119 |
dropdownAutoWidth: true, |
120 |
allowClear: false, |
121 |
ajax: { |
122 |
url: pickup_url, |
123 |
delay: 300, // wait 300 milliseconds before triggering the request |
124 |
cache: true, |
125 |
dataType: 'json', |
126 |
data: function (params) { |
127 |
var search_term = (params.term === undefined) ? '' : params.term; |
128 |
var query = { |
129 |
"q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}), |
130 |
"_order_by": "name", |
131 |
"_page": params.page |
132 |
}; |
133 |
query["patron_id"] = booking_patron.patron_id; |
134 |
return query; |
135 |
}, |
136 |
processResults: function (data) { |
137 |
var results = []; |
138 |
data.results.forEach( function ( pickup_location ) { |
139 |
results.push( |
140 |
{ |
141 |
"id": pickup_location.library_id.escapeHtml(), |
142 |
"text": pickup_location.name.escapeHtml(), |
143 |
"needs_override": pickup_location.needs_override, |
144 |
"pickup_items": pickup_location.pickup_items, |
145 |
} |
146 |
); |
147 |
}); |
148 |
return { "results": results, "pagination": { "more": data.pagination.more } }; |
149 |
} |
150 |
}, |
151 |
templateResult: function (state) { |
152 |
var $text; |
153 |
if ( state.needs_override === true ) { |
154 |
$text = $( |
155 |
'<span>' + state.text + '</span> <span style="float:right;" title="' + |
156 |
__("This pickup location is not allowed according to circulation rules") + |
157 |
'"><i class="fa fa-exclamation-circle" aria-hidden="true"></i></span>' |
158 |
); |
159 |
} |
160 |
else { |
161 |
$text = $('<span>'+state.text+'</span>'); |
162 |
} |
163 |
return $text; |
164 |
}, |
111 |
}); |
165 |
}); |
112 |
|
166 |
|
113 |
// Adopt periodPicker |
167 |
// Adopt periodPicker |
Lines 310-315
$('#placeBookingModal').on('show.bs.modal', function(e) {
Link Here
|
310 |
periodPicker.redraw(); |
364 |
periodPicker.redraw(); |
311 |
}); |
365 |
}); |
312 |
|
366 |
|
|
|
367 |
// Setup listener for pickup location select2 |
368 |
$('#pickup_library_id').on('select2:select', function(e) { |
369 |
let valid_items = e.params.data.pickup_items; |
370 |
|
371 |
// Disable items not available at the pickup location |
372 |
$("#booking_item_id > option").each(function() { |
373 |
let option = $(this); |
374 |
let item_id = option.val(); |
375 |
if (valid_items.includes(parseInt(item_id))) { |
376 |
option.prop('disabled',false); |
377 |
} else { |
378 |
option.prop('disabled',true); |
379 |
} |
380 |
}); |
381 |
$('#booking_item_id').trigger('change.select2'); |
382 |
}); |
383 |
|
313 |
// Set onChange for flatpickr |
384 |
// Set onChange for flatpickr |
314 |
let changeExists = periodPicker.config.onChange.filter(f => f.name ==='periodChange'); |
385 |
let changeExists = periodPicker.config.onChange.filter(f => f.name ==='periodChange'); |
315 |
if(changeExists.length === 0) { |
386 |
if(changeExists.length === 0) { |
Lines 446-451
$("#placeBookingForm").on('submit', function(e) {
Link Here
|
446 |
|
517 |
|
447 |
let start_date = $('#booking_start_date').val(); |
518 |
let start_date = $('#booking_start_date').val(); |
448 |
let end_date = $('#booking_end_date').val(); |
519 |
let end_date = $('#booking_end_date').val(); |
|
|
520 |
let pickup_library_id = $('#pickup_library_id').val(); |
521 |
let biblio_id = $('#booking_biblio_id').val(); |
449 |
let item_id = $('#booking_item_id').val(); |
522 |
let item_id = $('#booking_item_id').val(); |
450 |
|
523 |
|
451 |
if (!booking_id) { |
524 |
if (!booking_id) { |
Lines 454-460
$("#placeBookingForm").on('submit', function(e) {
Link Here
|
454 |
JSON.stringify({ |
527 |
JSON.stringify({ |
455 |
"start_date": start_date, |
528 |
"start_date": start_date, |
456 |
"end_date": end_date, |
529 |
"end_date": end_date, |
457 |
"biblio_id": $('#booking_biblio_id').val(), |
530 |
"pickup_library_id": pickup_library_id, |
|
|
531 |
"biblio_id": biblio_id, |
458 |
"item_id": item_id != 0 ? item_id : null, |
532 |
"item_id": item_id != 0 ? item_id : null, |
459 |
"patron_id": $('#booking_patron_id').find(':selected').val() |
533 |
"patron_id": $('#booking_patron_id').find(':selected').val() |
460 |
}) |
534 |
}) |
Lines 505-511
$("#placeBookingForm").on('submit', function(e) {
Link Here
|
505 |
"booking_id": booking_id, |
579 |
"booking_id": booking_id, |
506 |
"start_date": start_date, |
580 |
"start_date": start_date, |
507 |
"end_date": end_date, |
581 |
"end_date": end_date, |
508 |
"biblio_id": $('#booking_biblio_id').val(), |
582 |
"pickup_library_id": pickup_library_id, |
|
|
583 |
"biblio_id": biblio_id, |
509 |
"item_id": item_id != 0 ? item_id : null, |
584 |
"item_id": item_id != 0 ? item_id : null, |
510 |
"patron_id": $('#booking_patron_id').find(':selected').val() |
585 |
"patron_id": $('#booking_patron_id').find(':selected').val() |
511 |
}) |
586 |
}) |
Lines 554-559
$('#placeBookingModal').on('hidden.bs.modal', function (e) {
Link Here
|
554 |
$('#booking_patron_id').val(null).trigger('change'); |
629 |
$('#booking_patron_id').val(null).trigger('change'); |
555 |
$('#booking_patron_id').empty(); |
630 |
$('#booking_patron_id').empty(); |
556 |
$('#booking_item_id').val(0).trigger('change'); |
631 |
$('#booking_item_id').val(0).trigger('change'); |
|
|
632 |
$('#pickup_library_id').val(null).trigger('change'); |
633 |
$('#pickup_library_id').empty(); |
557 |
$('#period').get(0)._flatpickr.clear(); |
634 |
$('#period').get(0)._flatpickr.clear(); |
558 |
$('#booking_start_date').val(''); |
635 |
$('#booking_start_date').val(''); |
559 |
$('#booking_end_date').val(''); |
636 |
$('#booking_end_date').val(''); |
560 |
- |
|
|