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('ui-state-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.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.barcode ) {
283 if ( oObj.found == "W" ) {
285 if ( oObj.waiting_here ) {
286 data += __("Item is <strong>waiting here</strong>");
287 if (oObj.desk_name) {
288 data += ", " + __("at %s").format(oObj.desk_name.escapeHtml());
291 data += __("Item is <strong>waiting</strong>");
292 data += " " + __("at %s").format(oObj.waiting_at);
293 if (oObj.desk_name) {
294 data += ", " + __("at %s").format(oObj.desk_name.escapeHtml());
299 } else if ( oObj.transferred ) {
300 data += __("Item is <strong>in transit</strong> from %s since %s").format(oObj.from_branch, oObj.date_sent);
301 } else if ( oObj.not_transferred ) {
302 data += __("Item hasn't been transferred yet from %s").format(oObj.not_transferred_by);
312 "bServerSide": false,
314 "url": '/cgi-bin/koha/svc/holds',
315 "data": function ( d ) {
316 d.borrowernumber = borrowernumber;
321 $('#holds-table').on( 'draw.dt', function () {
322 $(".hold-suspend").on( "click", function() {
323 var hold_id = $(this).data('hold-id');
324 var hold_title = $(this).data('hold-title');
325 $("#suspend-modal-title").html( hold_title );
326 $("#suspend-modal-submit").data( 'hold-id', hold_id );
327 $('#suspend-modal').modal('show');
330 $(".hold-resume").on("click", function () {
331 var hold_id = $(this).data('hold-id');
334 ).success(function () {
335 holdsTable.api().ajax.reload();
336 }).error(function (jqXHR, textStatus, errorThrown) {
337 if (jqXHR.status === 404) {
338 alert(__("Unable to resume, hold not found"));
341 alert(__("Your request could not be processed. Check the logs"));
343 holdsTable.api().ajax.reload();
347 $(".hold_location_select").each(function(){ $(this).pickup_locations_dropdown(); });
349 $(".hold_location_select").on("change", function(){
350 $(this).prop("disabled",true);
351 var cur_select = $(this);
352 var res_id = $(this).attr('reserve_id');
353 $(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>');
354 var api_url = '/api/v1/holds/' + encodeURIComponent(res_id) + '/pickup_location';
358 data: JSON.stringify({ "pickup_library_id": $(this).val() }),
359 headers: { "x-koha-override": "any" },
360 success: function( data ){ holdsTable.api().ajax.reload(); },
361 error: function( jqXHR, textStatus, errorThrown) {
362 alert('There was an error:'+textStatus+" "+errorThrown);
363 cur_select.prop("disabled",false);
364 $("#updating_reserveno"+res_id).remove();
365 cur_select.val( cur_select.children('option[selected="selected"]').val() );
372 if ( $("#holds-table").length ) {
373 $("#holds-table_processing").position({
374 of: $( "#holds-table" ),
382 <div id='suspend-modal' class='modal fade' role='dialog' aria-hidden='true'>\
383 <div class='modal-dialog'>\
384 <div class='modal-content'>\
385 <form id='suspend-modal-form' class='form-inline'>\
386 <div class='modal-header'>\
387 <button type='button' class='closebtn' data-dismiss='modal' aria-hidden='true'>×</button>\
388 <h3 id='suspend-modal-label'>" + __("Suspend hold on") + " <i><span id='suspend-modal-title'></span></i></h3>\
391 <div class='modal-body'>\
392 <input type='hidden' id='suspend-modal-reserve_id' name='reserve_id' />\
394 <label for='suspend-modal-until'>" + __("Suspend until:") + "</label>\
395 <input name='suspend_until' id='suspend-modal-until' class='suspend-until flatpickr' data-flatpickr-futuredate='true' size='10' />\
397 <p><a class='btn btn-link' id='suspend-modal-clear-date' >" + __("Clear date to suspend indefinitely") + "</a></p>\
401 <div class='modal-footer'>\
402 <button id='suspend-modal-submit' class='btn btn-primary' type='submit' name='submit'>" + __("Suspend") + "</button>\
403 <a href='#' data-dismiss='modal' aria-hidden='true' class='cancel'>" + __("Cancel") + "</a>\
411 $("#suspend-modal-clear-date").on( "click", function() { $("#suspend-modal-until").val(""); } );
413 $("#suspend-modal-submit").on( "click", function( e ) {
415 var suspend_until_date = $("#suspend-modal-until").val();
416 if ( suspend_until_date !== null ) suspend_until_date = $date(suspend_until_date, {dateformat:"rfc3339"});
418 $(this).data('hold-id'),
420 ).success(function () {
421 holdsTable.api().ajax.reload();
422 }).error(function (jqXHR, textStatus, errorThrown) {
423 if (jqXHR.status === 404) {
424 alert(__("Unable to suspend, hold not found"));
427 alert(__("Your request could not be processed. Check the logs"));
429 holdsTable.api().ajax.reload();
431 $("#suspend-modal-until").val(""); // clean the input
432 $('#suspend-modal').modal('hide');
436 $(".toggle-suspend").on('click', function(e) {
438 let reserve_id = $(this).data('reserve-id');
439 let biblionumber = $(this).data('biblionumber');
440 let suspend_until = $('#suspend_until_' + reserve_id).val();
441 window.location.href='request.pl?action=toggleSuspend&reserve_id=' + reserve_id + '&biblionumber=' + biblionumber + '&suspend_until=' + suspend_until;