1 /* global __ dataTablesDefaults borrowernumber SuspendHoldsIntranet */
2 $(document).ready(function() {
5 // Don't load holds table unless it is clicked on
6 $("#holds-tab").on( "click", function(){ load_holds_table() } );
8 // If the holds tab is preselected on load, we need to load the table
9 if ( $("#holds-tab").parent().hasClass('ui-state-active') ) { load_holds_table() }
11 function load_holds_table() {
12 var holds = new Array();
15 holdsTable = $("#holds-table").dataTable($.extend(true, {}, dataTablesDefaults, {
20 "data": { _: "reservedate_formatted", "sort": "reservedate" }
23 "mDataProp": function ( oObj ) {
24 title = "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber="
27 + oObj.title.escapeHtml();
29 $.each(oObj.subtitle, function( index, value ) {
30 title += " " + value.escapeHtml();
33 title += " " + oObj.part_number + " " + oObj.part_name;
35 if ( oObj.enumchron ) {
36 title += " (" + oObj.enumchron.escapeHtml() + ")";
42 title += " " + __("by _AUTHOR_").replace("_AUTHOR_", oObj.author.escapeHtml());
45 if ( oObj.itemnotes ) {
47 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
48 span_class = "circ-hlt";
50 title += " - <span class='" + span_class + "'>" + oObj.itemnotes.escapeHtml() + "</span>"
57 "mDataProp": function( oObj ) {
58 return oObj.itemcallnumber && oObj.itemcallnumber.escapeHtml() || "";
62 "mDataProp": function( oObj ) {
65 data += " <a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
72 + oObj.barcode.escapeHtml()
79 "mDataProp": function( oObj ) {
80 if( oObj.branches.length > 1 && oObj.found !== 'W' && oObj.found !== 'T' ){
81 var branchSelect='<select priority='+oObj.priority+' class="hold_location_select" reserve_id="'+oObj.reserve_id+'" name="pick-location">';
82 for ( var i=0; i < oObj.branches.length; i++ ){
85 if( oObj.branches[i].selected ){
87 selectedbranch = " selected='selected' ";
88 setbranch = __(" (current) ");
89 } else if ( oObj.branches[i].pickup_location == 0 ) {
95 branchSelect += '<option value="'+ oObj.branches[i].branchcode.escapeHtml() +'"'+selectedbranch+'>'+oObj.branches[i].branchname.escapeHtml()+setbranch+'</option>';
97 branchSelect +='</select>';
100 else { return oObj.branchcode.escapeHtml() || ""; }
103 { "data": { _: "expirationdate_formatted", "sort": "expirationdate" } },
105 "mDataProp": function( oObj ) {
106 if ( oObj.priority && parseInt( oObj.priority ) && parseInt( oObj.priority ) > 0 ) {
107 return oObj.priority;
115 "mDataProp": function( oObj ) {
116 return "<select name='rank-request'>"
117 +"<option value='n'>" + __("No") + "</option>"
118 +"<option value='del'>" + __("Yes") + "</option>"
120 + "<input type='hidden' name='biblionumber' value='" + oObj.biblionumber + "'>"
121 + "<input type='hidden' name='borrowernumber' value='" + borrowernumber + "'>"
122 + "<input type='hidden' name='reserve_id' value='" + oObj.reserve_id + "'>";
127 "visible": SuspendHoldsIntranet,
128 "mDataProp": function( oObj ) {
129 holds[oObj.reserve_id] = oObj; //Store holds for later use
133 } else if ( oObj.suspend == 1 ) {
134 return "<a class='hold-resume btn btn-default btn-xs' id='resume" + oObj.reserve_id + "'>"
135 +"<i class='fa fa-play'></i> " + __("Resume") + "</a>";
137 return "<a class='hold-suspend btn btn-default btn-xs' id='suspend" + oObj.reserve_id + "'>"
138 +"<i class='fa fa-pause'></i> " + __("Suspend") + "</a>";
143 "mDataProp": function( oObj ) {
146 if ( oObj.suspend == 1 ) {
147 data += "<p>" + __("Hold is <strong>suspended</strong>");
148 if ( oObj.suspend_until ) {
149 data += " " + __("until %s").format(oObj.suspend_until_formatted);
154 if ( oObj.itemtype_limit ) {
155 data += __("Next available %s item").format(oObj.itemtype_limit);
158 if ( oObj.barcode ) {
160 if ( oObj.found == "W" ) {
162 if ( oObj.waiting_here ) {
163 data += __("Item is <strong>waiting here</strong>");
164 if (oObj.desk_name) {
165 data += ", " + __("at %s").format( oObj.desk_name );
168 data += __("Item is <strong>waiting</strong>");
169 data += " " + __("at %s").format(oObj.waiting_at);
170 if (oObj.desk_name) {
171 data += ", " + __("at %s").format( oObj.desk_name );
176 } else if ( oObj.transferred ) {
177 data += __("Item is <strong>in transit</strong> from %s since %s").format(oObj.from_branch, oObj.date_sent);
178 } else if ( oObj.not_transferred ) {
179 data += __("Item hasn't been transferred yet from %s").format(oObj.not_transferred_by);
189 "bServerSide": false,
191 "url": '/cgi-bin/koha/svc/holds',
192 "data": function ( d ) {
193 d.borrowernumber = borrowernumber;
198 $('#holds-table').on( 'draw.dt', function () {
199 $(".hold-suspend").on( "click", function() {
200 var id = $(this).attr("id").replace("suspend", "");
201 var hold = holds[id];
202 $("#suspend-modal-title").html( hold.title );
203 $("#suspend-modal-reserve_id").val( hold.reserve_id );
204 $('#suspend-modal').modal('show');
207 $(".hold-resume").on( "click", function() {
208 var id = $(this).attr("id").replace("resume", "");
209 var hold = holds[id];
210 $.post('/cgi-bin/koha/svc/hold/resume', { "reserve_id": hold.reserve_id }, function( data ){
211 if ( data.success ) {
212 holdsTable.api().ajax.reload();
214 if ( data.error == "HOLD_NOT_FOUND" ) {
215 alert( __("Unable to resume, hold not found") );
216 holdsTable.api().ajax.reload();
222 $(".hold_location_select").change(function(){
223 $(this).prop("disabled",true);
224 var cur_select = $(this);
225 var res_id = $(this).attr('reserve_id');
226 $(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>');
227 var api_url = '/api/v1/holds/'+res_id;
228 var update_info = JSON.stringify({ pickup_library_id: $(this).val(), priority: parseInt($(this).attr("priority"),10) });
233 success: function( data ){ holdsTable.api().ajax.reload(); },
234 error: function( jqXHR, textStatus, errorThrown) {
235 alert('There was an error:'+textStatus+" "+errorThrown);
236 cur_select.prop("disabled",false);
237 $("#updating_reserveno"+res_id).remove();
238 cur_select.val( cur_select.children('option[selected="selected"]').val() );
245 if ( $("#holds-table").length ) {
246 $("#holds-table_processing").position({
247 of: $( "#holds-table" ),
255 <div id='suspend-modal' class='modal fade' role='dialog' aria-hidden='true'>\
256 <div class='modal-dialog'>\
257 <div class='modal-content'>\
258 <form id='suspend-modal-form' class='form-inline'>\
259 <div class='modal-header'>\
260 <button type='button' class='closebtn' data-dismiss='modal' aria-hidden='true'>×</button>\
261 <h3 id='suspend-modal-label'>" + __("Suspend hold on") + " <i><span id='suspend-modal-title'></span></i></h3>\
264 <div class='modal-body'>\
265 <input type='hidden' id='suspend-modal-reserve_id' name='reserve_id' />\
267 <label for='suspend-modal-until'>" + __("Suspend until:") + "</label>\
268 <input name='suspend_until' id='suspend-modal-until' class='suspend-until' size='10' />\
270 <p><a class='btn btn-link' id='suspend-modal-clear-date' >" + __("Clear date to suspend indefinitely") + "</a></p>\
274 <div class='modal-footer'>\
275 <button id='suspend-modal-submit' class='btn btn-primary' type='submit' name='submit'>" + __("Suspend") + "</button>\
276 <a href='#' data-dismiss='modal' aria-hidden='true' class='cancel'>" + __("Cancel") + "</a>\
284 $("#suspend-modal-until").datepicker({ minDate: 1 }); // Require that "until date" be in the future
285 $("#suspend-modal-clear-date").on( "click", function() { $("#suspend-modal-until").val(""); } );
287 $("#suspend-modal-submit").on( "click", function( e ) {
289 $.post('/cgi-bin/koha/svc/hold/suspend', $('#suspend-modal-form').serialize(), function( data ){
290 $('#suspend-modal').modal('hide');
291 if ( data.success ) {
292 holdsTable.api().ajax.reload();
294 if ( data.error == "INVALID_DATE" ) {
295 alert( __("Unable to suspend hold, invalid date") );
297 else if ( data.error == "HOLD_NOT_FOUND" ) {
298 alert( __("Unable to suspend hold, hold not found") );
299 holdsTable.api().ajax.reload();