|
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_location").prop("disabled", false); |
| 112 |
}); |
| 113 |
|
| 114 |
// Pickup location select2 |
| 115 |
let pickup_url = '/api/v1/biblios/' + biblionumber + '/pickup_locations'; |
| 116 |
$("#pickup_location").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_location').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) { |
| 316 |
- |
|
|