1 $(document).ready(function() {
4 // Don't load holds table unless it is clicked on
5 $("#holds-tab").on( "click", function(){ load_holds_table() } );
7 // If the holds tab is preselected on load, we need to load the table
8 if ( $("#holds-tab").parent().hasClass('ui-state-active') ) { load_holds_table() }
10 function load_holds_table() {
11 var holds = new Array();
13 holdsTable = $("#holds-table").dataTable({
18 "data": { _: "reservedate_formatted", "sort": "reservedate" }
21 "mDataProp": function ( oObj ) {
22 title = "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber="
25 + oObj.title.escapeHtml();
27 $.each(oObj.subtitle, function( index, value ) {
28 title += " " + value.escapeHtml();
31 title += " " + oObj.part_number + " " + oObj.part_name;
33 if ( oObj.enumchron ) {
34 title += " (" + oObj.enumchron.escapeHtml() + ")";
40 title += " " + BY.replace( "_AUTHOR_", oObj.author.escapeHtml() );
43 if ( oObj.itemnotes ) {
45 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
46 span_class = "circ-hlt";
48 title += " - <span class='" + span_class + "'>" + oObj.itemnotes.escapeHtml() + "</span>"
55 "mDataProp": function( oObj ) {
56 return oObj.itemcallnumber && oObj.itemcallnumber.escapeHtml() || "";
60 "mDataProp": function( oObj ) {
63 data += " <a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
70 + oObj.barcode.escapeHtml()
77 "mDataProp": function( oObj ) {
78 if( oObj.branches.length > 1 && oObj.found !== 'W' && oObj.found !== 'T' ){
79 var branchSelect='<select priority='+oObj.priority+' class="hold_location_select" reserve_id="'+oObj.reserve_id+'" name="pick-location">';
80 for ( var i=0; i < oObj.branches.length; i++ ){
83 if( oObj.branches[i].selected ){
85 selectedbranch = " selected='selected' ";
87 } else if ( oObj.branches[i].pickup_location == 0 ) {
93 branchSelect += '<option value="'+ oObj.branches[i].branchcode.escapeHtml() +'"'+selectedbranch+'>'+oObj.branches[i].branchname.escapeHtml()+setbranch+'</option>';
95 branchSelect +='</select>';
98 else { return oObj.branchcode.escapeHtml() || ""; }
101 { "data": { _: "expirationdate_formatted", "sort": "expirationdate" } },
103 "mDataProp": function( oObj ) {
104 if ( oObj.priority && parseInt( oObj.priority ) && parseInt( oObj.priority ) > 0 ) {
105 return oObj.priority;
113 "mDataProp": function( oObj ) {
114 return "<select name='rank-request'>"
115 + "<option value='n'>" + NO + "</option>"
116 + "<option value='del'>" + YES + "</option>"
118 + "<input type='hidden' name='biblionumber' value='" + oObj.biblionumber + "'>"
119 + "<input type='hidden' name='borrowernumber' value='" + borrowernumber + "'>"
120 + "<input type='hidden' name='reserve_id' value='" + oObj.reserve_id + "'>";
125 "mDataProp": function( oObj ) {
126 holds[oObj.reserve_id] = oObj; //Store holds for later use
130 } else if ( oObj.suspend == 1 ) {
131 return "<a class='hold-resume btn btn-default btn-xs' id='resume" + oObj.reserve_id + "'>"
132 + "<i class='fa fa-play'></i> " + RESUME + "</a>";
134 return "<a class='hold-suspend btn btn-default btn-xs' id='suspend" + oObj.reserve_id + "'>"
135 + "<i class='fa fa-pause'></i> " + SUSPEND + "</a>";
140 "mDataProp": function( oObj ) {
143 if ( oObj.suspend == 1 ) {
144 data += "<p>" + HOLD_IS_SUSPENDED;
145 if ( oObj.suspend_until ) {
146 data += " " + UNTIL.format( oObj.suspend_until_formatted );
151 if ( oObj.itemtype_limit ) {
152 data += NEXT_AVAILABLE_ITYPE.format( oObj.itemtype_limit );
155 if ( oObj.barcode ) {
157 if ( oObj.found == "W" ) {
159 if ( oObj.waiting_here ) {
160 data += ITEM_IS_WAITING_HERE;
162 data += ITEM_IS_WAITING;
163 data += " " + AT.format( oObj.waiting_at );
166 } else if ( oObj.transferred ) {
167 data += ITEM_IS_IN_TRANSIT.format( oObj.from_branch, oObj.date_sent );
168 } else if ( oObj.not_transferred ) {
169 data += NOT_TRANSFERRED_YET.format( oObj.not_transferred_by );
179 "bServerSide": false,
181 "url": '/cgi-bin/koha/svc/holds',
182 "data": function ( d ) {
183 d.borrowernumber = borrowernumber;
188 $('#holds-table').on( 'draw.dt', function () {
189 $(".hold-suspend").on( "click", function() {
190 var id = $(this).attr("id").replace("suspend", "");
191 var hold = holds[id];
192 $("#suspend-modal-title").html( hold.title );
193 $("#suspend-modal-reserve_id").val( hold.reserve_id );
194 $('#suspend-modal').modal('show');
197 $(".hold-resume").on( "click", function() {
198 var id = $(this).attr("id").replace("resume", "");
199 var hold = holds[id];
200 $.post('/cgi-bin/koha/svc/hold/resume', { "reserve_id": hold.reserve_id }, function( data ){
201 if ( data.success ) {
202 holdsTable.api().ajax.reload();
204 if ( data.error == "HOLD_NOT_FOUND" ) {
205 alert ( RESUME_HOLD_ERROR_NOT_FOUND );
206 holdsTable.api().ajax.reload();
212 $(".hold_location_select").change(function(){
213 $(this).prop("disabled",true);
214 var cur_select = $(this);
215 var res_id = $(this).attr('reserve_id');
216 $(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>');
217 var api_url = '/api/v1/holds/'+res_id;
218 var update_info = JSON.stringify({ pickup_library_id: $(this).val(), priority: parseInt($(this).attr("priority"),10) });
223 success: function( data ){ holdsTable.api().ajax.reload(); },
224 error: function( jqXHR, textStatus, errorThrown) {
225 alert('There was an error:'+textStatus+" "+errorThrown);
226 cur_select.prop("disabled",false);
227 $("#updating_reserveno"+res_id).remove();
228 cur_select.val( cur_select.children('option[selected="selected"]').val() );
235 if ( $("#holds-table").length ) {
236 $("#holds-table_processing").position({
237 of: $( "#holds-table" ),
245 <div id='suspend-modal' class='modal fade' role='dialog' aria-hidden='true'>\
246 <div class='modal-dialog'>\
247 <div class='modal-content'>\
248 <form id='suspend-modal-form' class='form-inline'>\
249 <div class='modal-header'>\
250 <button type='button' class='closebtn' data-dismiss='modal' aria-hidden='true'>×</button>\
251 <h3 id='suspend-modal-label'>" + SUSPEND_HOLD_ON + " <i><span id='suspend-modal-title'></span></i></h3>\
254 <div class='modal-body'>\
255 <input type='hidden' id='suspend-modal-reserve_id' name='reserve_id' />\
257 <label for='suspend-modal-until'>" + SUSPEND_UNTIL + "</label>\
258 <input name='suspend_until' id='suspend-modal-until' class='suspend-until' size='10' />\
260 <p/><a class='btn btn-link' id='suspend-modal-clear-date' >" + CLEAR_DATE_TO_SUSPEND_INDEFINITELY + "</a></p>\
264 <div class='modal-footer'>\
265 <button id='suspend-modal-submit' class='btn btn-primary' type='submit' name='submit'>" + SUSPEND + "</button>\
266 <a href='#' data-dismiss='modal' aria-hidden='true' class='cancel'>" + CANCEL + "</a>\
274 $("#suspend-modal-until").datepicker({ minDate: 1 }); // Require that "until date" be in the future
275 $("#suspend-modal-clear-date").on( "click", function() { $("#suspend-modal-until").val(""); } );
277 $("#suspend-modal-submit").on( "click", function( e ) {
279 $.post('/cgi-bin/koha/svc/hold/suspend', $('#suspend-modal-form').serialize(), function( data ){
280 $('#suspend-modal').modal('hide');
281 if ( data.success ) {
282 holdsTable.api().ajax.reload();
284 if ( data.error == "INVALID_DATE" ) {
285 alert( SUSPEND_HOLD_ERROR_DATE );
287 else if ( data.error == "HOLD_NOT_FOUND" ) {
288 alert ( SUSPEND_HOLD_ERROR_NOT_FOUND );
289 holdsTable.api().ajax.reload();