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 "mDataProp": "reservedate_formatted"
21 "mDataProp": function ( oObj ) {
22 title = "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber="
27 $.each(oObj.subtitle, function( index, value ) {
28 title += " " + value.subfield;
34 title += " " + BY.replace( "_AUTHOR_", oObj.author );
37 if ( oObj.itemnotes ) {
39 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
40 span_class = "circ-hlt";
42 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
49 "mDataProp": function( oObj ) {
50 return oObj.itemcallnumber || "";
54 "mDataProp": function( oObj ) {
57 if ( oObj.suspend == 1 ) {
58 data += "<p>" + HOLD_IS_SUSPENDED;
59 if ( oObj.suspend_until ) {
60 data += " " + UNTIL.format( oObj.suspend_until_formatted );
65 if ( oObj.itemtype_limit ) {
66 data += NEXT_AVAILABLE_ITYPE.format( oObj.itemtype_limit );
71 if ( oObj.found == "W" ) {
73 if ( oObj.waiting_here ) {
74 data += ITEM_IS_WAITING_HERE;
76 data += ITEM_IS_WAITING;
77 data += " " + AT.format( oObj.waiting_at );
80 } else if ( oObj.transferred ) {
81 data += ITEM_IS_IN_TRANSIT.format( oObj.from_branch, oObj.date_sent );
82 } else if ( oObj.not_transferred ) {
83 data += NOT_TRANSFERRED_YET.format( oObj.not_transferred_by );
87 data += " <a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
102 "mDataProp": function( oObj ) {
103 if( oObj.branches.length > 1 && oObj.found !== 'W' && oObj.found !== 'T' ){
104 var branchSelect='<select class="hold_location_select" reserve_id="'+oObj.reserve_id+'" name="pick-location">';
105 for ( var i=0; i < oObj.branches.length; i++ ){
107 if( oObj.branches[i].selected ){selectedbranch=" selected='selected' "}else{selectedbranch=''}
108 branchSelect += '<option value="'+ oObj.branches[i].value +'"'+selectedbranch+'>'+oObj.branches[i].branchname+'</option>';
110 branchSelect +='</select>';
113 else { return oObj.branchcode || ""; }
116 { "mDataProp": "expirationdate_formatted" },
118 "mDataProp": function( oObj ) {
119 if ( oObj.priority && parseInt( oObj.priority ) && parseInt( oObj.priority ) > 0 ) {
120 return oObj.priority;
128 "mDataProp": function( oObj ) {
129 return "<select name='rank-request'>"
130 + "<option value='n'>" + NO + "</option>"
131 + "<option value='del'>" + YES + "</option>"
133 + "<input type='hidden' name='biblionumber' value='" + oObj.biblionumber + "'>"
134 + "<input type='hidden' name='borrowernumber' value='" + borrowernumber + "'>"
135 + "<input type='hidden' name='reserve_id' value='" + oObj.reserve_id + "'>";
140 "mDataProp": function( oObj ) {
141 holds[oObj.reserve_id] = oObj; //Store holds for later use
145 } else if ( oObj.suspend == 1 ) {
146 return "<a class='hold-resume btn btn-mini' id='resume" + oObj.reserve_id + "'>"
147 + "<i class='fa fa-play'></i> " + RESUME + "</a>";
149 return "<a class='hold-suspend btn btn-mini' id='suspend" + oObj.reserve_id + "'>"
150 + "<i class='fa fa-pause'></i> " + SUSPEND + "</a>";
157 "bServerSide": false,
159 "url": '/cgi-bin/koha/svc/holds',
160 "data": function ( d ) {
161 d.borrowernumber = borrowernumber;
166 $('#holds-table').on( 'draw.dt', function () {
167 $(".hold-suspend").on( "click", function() {
168 var id = $(this).attr("id").replace("suspend", "");
169 var hold = holds[id];
170 $("#suspend-modal-title").html( hold.title );
171 $("#suspend-modal-reserve_id").val( hold.reserve_id );
172 $('#suspend-modal').modal('show');
175 $(".hold-resume").on( "click", function() {
176 var id = $(this).attr("id").replace("resume", "");
177 var hold = holds[id];
178 $.post('/cgi-bin/koha/svc/hold/resume', { "reserve_id": hold.reserve_id }, function( data ){
179 if ( data.success ) {
180 holdsTable.api().ajax.reload();
182 if ( data.error == "HOLD_NOT_FOUND" ) {
183 alert ( RESUME_HOLD_ERROR_NOT_FOUND );
184 holdsTable.api().ajax.reload();
190 $(".hold_location_select").change(function(){
191 if( confirm( _("Do you want to change the pickup location?") ) ){
192 $.post('/cgi-bin/koha/svc/hold/update_location', { "reserve_id": $(this).attr('reserve_id'), "updated_branch": $(this).val() }, function( data ){
193 if ( data.success ) {
194 holdsTable.api().ajax.reload();
197 if ( data.error == "HOLD_NOT_FOUND" ) {
198 alert ( RESUME_HOLD_ERROR_NOT_FOUND );
199 holdsTable.api().ajax.reload();
208 if ( $("#holds-table").length ) {
209 $("#holds-table_processing").position({
210 of: $( "#holds-table" ),
218 <div id='suspend-modal' class='modal hide fade' tabindex='-1' role='dialog' aria-hidden='true'>\
219 <form id='suspend-modal-form' class='form-inline'>\
220 <div class='modal-header'>\
221 <button type='button' class='closebtn' data-dismiss='modal' aria-hidden='true'>×</button>\
222 <h3 id='suspend-modal-label'>" + SUSPEND_HOLD_ON + " <i><span id='suspend-modal-title'></span></i></h3>\
225 <div class='modal-body'>\
226 <input type='hidden' id='suspend-modal-reserve_id' name='reserve_id' />\
228 <label for='suspend-modal-until'>Suspend until:</label>\
229 <input name='suspend_until' id='suspend-modal-until' class='suspend-until' size='10' />\
231 <p/><a class='btn btn-link' id='suspend-modal-clear-date' >" + CLEAR_DATE_TO_SUSPEND_INDEFINITELY + "</a></p>\
235 <div class='modal-footer'>\
236 <button id='suspend-modal-submit' class='btn btn-primary' type='submit' name='submit'>" + SUSPEND + "</button>\
237 <a href='#' data-dismiss='modal' aria-hidden='true' class='cancel'>" + CANCEL + "</a>\
243 $("#suspend-modal-until").datepicker({ minDate: 1 }); // Require that "until date" be in the future
244 $("#suspend-modal-clear-date").on( "click", function() { $("#suspend-modal-until").val(""); } );
246 $("#suspend-modal-submit").on( "click", function( e ) {
248 $.post('/cgi-bin/koha/svc/hold/suspend', $('#suspend-modal-form').serialize(), function( data ){
249 $('#suspend-modal').modal('hide');
250 if ( data.success ) {
251 holdsTable.api().ajax.reload();
253 if ( data.error == "INVALID_DATE" ) {
254 alert( SUSPEND_HOLD_ERROR_DATE );
256 else if ( data.error == "HOLD_NOT_FOUND" ) {
257 alert ( SUSPEND_HOLD_ERROR_NOT_FOUND );
258 holdsTable.api().ajax.reload();