1 function display_pickup_location (state) {
3 if ( state.needs_override === true ) {
5 '<span>' + state.text + '</span> <span style="float:right;" title="' +
6 __("This pickup location is not allowed according to circulation rules") +
7 '"><i class="fa fa-exclamation-circle" aria-hidden="true"></i></span>'
11 $text = $('<span>'+state.text+'</span>');
20 * Generate a Select2 dropdown for pickup locations
22 * It expects the select object to contain several data-* attributes
23 * - data-pickup-location-source: 'biblio', 'item' or 'hold' (default)
24 * - data-patron-id: required for 'biblio' and 'item'
25 * - data-biblio-id: required for 'biblio' only
26 * - data-item-id: required for 'item' only
28 * @return {Object} The Select2 instance
31 $.fn.pickup_locations_dropdown = function () {
33 var pickup_location_source = $(this).data('pickup-location-source');
34 var patron_id = $(this).data('patron-id');
35 var biblio_id = $(this).data('biblio-id');
36 var item_id = $(this).data('item-id');
37 var hold_id = $(this).data('hold-id');
41 if ( pickup_location_source === 'biblio' ) {
42 url = '/api/v1/biblios/' + encodeURIComponent(biblio_id) + '/pickup_locations';
44 else if ( pickup_location_source === 'item' ) {
45 url = '/api/v1/items/' + encodeURIComponent(item_id) + '/pickup_locations';
48 url = '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations';
56 delay: 300, // wait 300 milliseconds before triggering the request
59 data: function (params) {
60 var search_term = (params.term === undefined) ? '' : params.term;
62 "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}),
67 if ( pickup_location_source !== 'hold' ) {
68 query["patron_id"] = patron_id;
73 processResults: function (data) {
75 data.results.forEach( function ( pickup_location ) {
78 "id": pickup_location.library_id.escapeHtml(),
79 "text": pickup_location.name.escapeHtml(),
80 "needs_override": pickup_location.needs_override
84 return { "results": results, "pagination": { "more": data.pagination.more } };
87 templateResult: display_pickup_location
94 /* global __ dataTablesDefaults borrowernumber SuspendHoldsIntranet */
95 $(document).ready(function() {
97 function suspend_hold(hold_id, end_date) {
100 if ( end_date !== null && end_date !== '' ) params = JSON.stringify({ "end_date": end_date });
104 url: '/api/v1/holds/'+encodeURIComponent(hold_id)+'/suspension',
105 contentType: 'application/json',
110 function resume_hold(hold_id) {
113 url: '/api/v1/holds/'+encodeURIComponent(hold_id)+'/suspension'
119 // Don't load holds table unless it is clicked on
120 $("#holds-tab").on( "click", function(){ load_holds_table() } );
122 // If the holds tab is preselected on load, we need to load the table
123 if ( $("#holds-tab").parent().hasClass('active') ) { load_holds_table() }
125 function load_holds_table() {
126 var holds = new Array();
127 if ( ! holdsTable ) {
129 holdsTable = $("#holds-table").dataTable($.extend(true, {}, dataTablesDefaults, {
134 "data": { _: "reservedate_formatted", "sort": "reservedate" }
137 "mDataProp": function ( oObj ) {
138 title = "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber="
141 + (oObj.title ? oObj.title.escapeHtml() : '');
143 $.each(oObj.subtitle, function( index, value ) {
144 title += " " + value.escapeHtml();
147 title += " " + oObj.part_number + " " + oObj.part_name;
149 if ( oObj.enumchron ) {
150 title += " (" + oObj.enumchron.escapeHtml() + ")";
156 title += " " + __("by _AUTHOR_").replace("_AUTHOR_", oObj.author.escapeHtml());
159 if ( oObj.itemnotes ) {
161 if ( flatpickr.formatDate( new Date(oObj.issuedate), "Y-m-d" ) == ymd ){
162 span_class = "circ-hlt";
164 title += " - <span class='" + span_class + "'>" + oObj.itemnotes.escapeHtml() + "</span>"
171 "mDataProp": function( oObj ) {
172 return oObj.itemcallnumber && oObj.itemcallnumber.escapeHtml() || "";
176 "mDataProp": function( oObj ) {
178 if ( oObj.itemtype ) {
179 data += oObj.itemtype_description;
185 "mDataProp": function( oObj ) {
187 if ( oObj.barcode ) {
188 data += " <a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
195 + oObj.barcode.escapeHtml()
202 "mDataProp": function( oObj ) {
203 if( oObj.branches.length > 1 && oObj.found !== 'W' && oObj.found !== 'T' ){
204 var branchSelect='<select priority='+oObj.priority+' class="hold_location_select" data-hold-id="'+oObj.reserve_id+'" reserve_id="'+oObj.reserve_id+'" name="pick-location" data-pickup-location-source="hold">';
205 for ( var i=0; i < oObj.branches.length; i++ ){
208 if( oObj.branches[i].selected ){
210 selectedbranch = " selected='selected' ";
211 setbranch = __(" (current) ");
212 } else if ( oObj.branches[i].pickup_location == 0 ) {
218 branchSelect += '<option value="'+ oObj.branches[i].branchcode.escapeHtml() +'"'+selectedbranch+'>'+oObj.branches[i].branchname.escapeHtml()+setbranch+'</option>';
220 branchSelect +='</select>';
223 else { return oObj.branchcode.escapeHtml() || ""; }
226 { "data": { _: "expirationdate_formatted", "sort": "expirationdate" } },
228 "mDataProp": function( oObj ) {
229 if ( oObj.priority && parseInt( oObj.priority ) && parseInt( oObj.priority ) > 0 ) {
230 return oObj.priority;
238 "mDataProp": function( oObj ) {
239 return "<select name='rank-request'>"
240 +"<option value='n'>" + __("No") + "</option>"
241 +"<option value='del'>" + __("Yes") + "</option>"
243 + "<input type='hidden' name='biblionumber' value='" + oObj.biblionumber + "'>"
244 + "<input type='hidden' name='borrowernumber' value='" + borrowernumber + "'>"
245 + "<input type='hidden' name='reserve_id' value='" + oObj.reserve_id + "'>";
250 "visible": SuspendHoldsIntranet,
251 "mDataProp": function( oObj ) {
252 holds[oObj.reserve_id] = oObj; //Store holds for later use
256 } else if ( oObj.suspend == 1 ) {
257 return "<a class='hold-resume btn btn-default btn-xs' data-hold-id='" + oObj.reserve_id + "'>"
258 +"<i class='fa fa-play'></i> " + __("Resume") + "</a>";
260 return "<a class='hold-suspend btn btn-default btn-xs' data-hold-id='" + oObj.reserve_id + "' data-hold-title='"+ oObj.title +"'>"
261 +"<i class='fa fa-pause'></i> " + __("Suspend") + "</a>";
266 "mDataProp": function( oObj ) {
269 if ( oObj.suspend == 1 ) {
270 data += "<p>" + __("Hold is <strong>suspended</strong>");
271 if ( oObj.suspend_until ) {
272 data += " " + __("until %s").format(oObj.suspend_until_formatted);
277 if ( oObj.itemtype_limit ) {
278 data += __("Next available %s item").format(oObj.itemtype_limit);
281 if ( oObj.item_group_id ) {
282 data += _("Next available item group <strong>%s</strong> item").format( oObj.item_group_description );
285 if ( oObj.barcode ) {
287 if ( oObj.found == "W" ) {
289 if ( oObj.waiting_here ) {
290 data += __("Item is <strong>waiting here</strong>");
291 if (oObj.desk_name) {
292 data += ", " + __("at %s").format(oObj.desk_name.escapeHtml());
295 data += __("Item is <strong>waiting</strong>");
296 data += " " + __("at %s").format(oObj.waiting_at);
297 if (oObj.desk_name) {
298 data += ", " + __("at %s").format(oObj.desk_name.escapeHtml());
303 } else if ( oObj.transferred ) {
304 data += __("Item is <strong>in transit</strong> from %s since %s").format(oObj.from_branch, oObj.date_sent);
305 } else if ( oObj.not_transferred ) {
306 data += __("Item hasn't been transferred yet from %s").format(oObj.not_transferred_by);
316 "bServerSide": false,
318 "url": '/cgi-bin/koha/svc/holds',
319 "data": function ( d ) {
320 d.borrowernumber = borrowernumber;
325 $('#holds-table').on( 'draw.dt', function () {
326 $(".hold-suspend").on( "click", function() {
327 var hold_id = $(this).data('hold-id');
328 var hold_title = $(this).data('hold-title');
329 $("#suspend-modal-title").html( hold_title );
330 $("#suspend-modal-submit").data( 'hold-id', hold_id );
331 $('#suspend-modal').modal('show');
334 $(".hold-resume").on("click", function () {
335 var hold_id = $(this).data('hold-id');
338 ).success(function () {
339 holdsTable.api().ajax.reload();
340 }).error(function (jqXHR, textStatus, errorThrown) {
341 if (jqXHR.status === 404) {
342 alert(__("Unable to resume, hold not found"));
345 alert(__("Your request could not be processed. Check the logs"));
347 holdsTable.api().ajax.reload();
351 $(".hold_location_select").each(function(){ $(this).pickup_locations_dropdown(); });
353 $(".hold_location_select").on("change", function(){
354 $(this).prop("disabled",true);
355 var cur_select = $(this);
356 var res_id = $(this).attr('reserve_id');
357 $(this).after('<div id="updating_reserveno'+res_id+'" class="waiting"><img src="/intranet-tmpl/prog/img/spinner-small.gif" alt="" /><span class="waiting_msg"></span></div>');
358 var api_url = '/api/v1/holds/' + encodeURIComponent(res_id) + '/pickup_location';
362 data: JSON.stringify({ "pickup_library_id": $(this).val() }),
363 headers: { "x-koha-override": "any" },
364 success: function( data ){ holdsTable.api().ajax.reload(); },
365 error: function( jqXHR, textStatus, errorThrown) {
366 alert('There was an error:'+textStatus+" "+errorThrown);
367 cur_select.prop("disabled",false);
368 $("#updating_reserveno"+res_id).remove();
369 cur_select.val( cur_select.children('option[selected="selected"]').val() );
376 if ( $("#holds-table").length ) {
377 $("#holds-table_processing").position({
378 of: $( "#holds-table" ),
386 <div id='suspend-modal' class='modal fade' role='dialog' aria-hidden='true'>\
387 <div class='modal-dialog'>\
388 <div class='modal-content'>\
389 <form id='suspend-modal-form' class='form-inline'>\
390 <div class='modal-header'>\
391 <button type='button' class='closebtn' data-dismiss='modal' aria-hidden='true'>×</button>\
392 <h3 id='suspend-modal-label'>" + __("Suspend hold on") + " <i><span id='suspend-modal-title'></span></i></h3>\
395 <div class='modal-body'>\
396 <input type='hidden' id='suspend-modal-reserve_id' name='reserve_id' />\
398 <label for='suspend-modal-until'>" + __("Suspend until:") + "</label>\
399 <input name='suspend_until' id='suspend-modal-until' class='suspend-until flatpickr' data-flatpickr-futuredate='true' size='10' />\
401 <p><a class='btn btn-link' id='suspend-modal-clear-date' >" + __("Clear date to suspend indefinitely") + "</a></p>\
405 <div class='modal-footer'>\
406 <button id='suspend-modal-submit' class='btn btn-primary' type='submit' name='submit'>" + __("Suspend") + "</button>\
407 <a href='#' data-dismiss='modal' aria-hidden='true' class='cancel'>" + __("Cancel") + "</a>\
415 $("#suspend-modal-clear-date").on( "click", function() { $("#suspend-modal-until").val(""); } );
417 $("#suspend-modal-submit").on( "click", function( e ) {
419 var suspend_until_date = $("#suspend-modal-until").val();
420 if ( suspend_until_date !== null ) suspend_until_date = $date(suspend_until_date, {dateformat:"rfc3339"});
422 $(this).data('hold-id'),
424 ).success(function () {
425 holdsTable.api().ajax.reload();
426 }).error(function (jqXHR, textStatus, errorThrown) {
427 if (jqXHR.status === 404) {
428 alert(__("Unable to suspend, hold not found"));
431 alert(__("Your request could not be processed. Check the logs"));
433 holdsTable.api().ajax.reload();
435 $("#suspend-modal-until").val(""); // clean the input
436 $('#suspend-modal').modal('hide');
440 $(".toggle-suspend").on('click', function(e) {
442 let reserve_id = $(this).data('reserve-id');
443 let biblionumber = $(this).data('biblionumber');
444 let suspend_until = $('#suspend_until_' + reserve_id).val();
445 window.location.href='request.pl?action=toggleSuspend&reserve_id=' + reserve_id + '&biblionumber=' + biblionumber + '&suspend_until=' + suspend_until;