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>");
165 data += __("Item is <strong>waiting</strong>");
166 data += " " + __("at %s").format(oObj.waiting_at);
169 } else if ( oObj.transferred ) {
170 data += __("Item is <strong>in transit</strong> from %s since %s").format(oObj.from_branch, oObj.date_sent);
171 } else if ( oObj.not_transferred ) {
172 data += __("Item hasn't been transferred yet from %s").format(oObj.not_transferred_by);
182 "bServerSide": false,
184 "url": '/cgi-bin/koha/svc/holds',
185 "data": function ( d ) {
186 d.borrowernumber = borrowernumber;
191 $('#holds-table').on( 'draw.dt', function () {
192 $(".hold-suspend").on( "click", function() {
193 var id = $(this).attr("id").replace("suspend", "");
194 var hold = holds[id];
195 $("#suspend-modal-title").html( hold.title );
196 $("#suspend-modal-reserve_id").val( hold.reserve_id );
197 $('#suspend-modal').modal('show');
200 $(".hold-resume").on( "click", function() {
201 var id = $(this).attr("id").replace("resume", "");
202 var hold = holds[id];
203 $.post('/cgi-bin/koha/svc/hold/resume', { "reserve_id": hold.reserve_id }, function( data ){
204 if ( data.success ) {
205 holdsTable.api().ajax.reload();
207 if ( data.error == "HOLD_NOT_FOUND" ) {
208 alert( __("Unable to resume, hold not found") );
209 holdsTable.api().ajax.reload();
215 $(".hold_location_select").change(function(){
216 $(this).prop("disabled",true);
217 var cur_select = $(this);
218 var res_id = $(this).attr('reserve_id');
219 $(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>');
220 var api_url = '/api/v1/holds/'+res_id;
221 var update_info = JSON.stringify({ pickup_library_id: $(this).val(), priority: parseInt($(this).attr("priority"),10) });
226 success: function( data ){ holdsTable.api().ajax.reload(); },
227 error: function( jqXHR, textStatus, errorThrown) {
228 alert('There was an error:'+textStatus+" "+errorThrown);
229 cur_select.prop("disabled",false);
230 $("#updating_reserveno"+res_id).remove();
231 cur_select.val( cur_select.children('option[selected="selected"]').val() );
238 if ( $("#holds-table").length ) {
239 $("#holds-table_processing").position({
240 of: $( "#holds-table" ),
248 <div id='suspend-modal' class='modal fade' role='dialog' aria-hidden='true'>\
249 <div class='modal-dialog'>\
250 <div class='modal-content'>\
251 <form id='suspend-modal-form' class='form-inline'>\
252 <div class='modal-header'>\
253 <button type='button' class='closebtn' data-dismiss='modal' aria-hidden='true'>×</button>\
254 <h3 id='suspend-modal-label'>" + __("Suspend hold on") + " <i><span id='suspend-modal-title'></span></i></h3>\
257 <div class='modal-body'>\
258 <input type='hidden' id='suspend-modal-reserve_id' name='reserve_id' />\
260 <label for='suspend-modal-until'>" + __("Suspend until:") + "</label>\
261 <input name='suspend_until' id='suspend-modal-until' class='suspend-until' size='10' />\
263 <p><a class='btn btn-link' id='suspend-modal-clear-date' >" + __("Clear date to suspend indefinitely") + "</a></p>\
267 <div class='modal-footer'>\
268 <button id='suspend-modal-submit' class='btn btn-primary' type='submit' name='submit'>" + __("Suspend") + "</button>\
269 <a href='#' data-dismiss='modal' aria-hidden='true' class='cancel'>" + __("Cancel") + "</a>\
277 $("#suspend-modal-until").datepicker({ minDate: 1 }); // Require that "until date" be in the future
278 $("#suspend-modal-clear-date").on( "click", function() { $("#suspend-modal-until").val(""); } );
280 $("#suspend-modal-submit").on( "click", function( e ) {
282 $.post('/cgi-bin/koha/svc/hold/suspend', $('#suspend-modal-form').serialize(), function( data ){
283 $('#suspend-modal').modal('hide');
284 if ( data.success ) {
285 holdsTable.api().ajax.reload();
287 if ( data.error == "INVALID_DATE" ) {
288 alert( __("Unable to suspend hold, invalid date") );
290 else if ( data.error == "HOLD_NOT_FOUND" ) {
291 alert( __("Unable to suspend hold, hold not found") );
292 holdsTable.api().ajax.reload();