Lines 1-5
Link Here
|
1 |
/* global __ dataTablesDefaults borrowernumber SuspendHoldsIntranet */ |
1 |
/* global __ dataTablesDefaults borrowernumber SuspendHoldsIntranet */ |
2 |
$(document).ready(function() { |
2 |
$(document).ready(function() { |
|
|
3 |
|
4 |
function suspend_hold(hold_id, end_date) { |
5 |
return $.ajax({ |
6 |
method: 'POST', |
7 |
url: '/api/v1/holds/'+encodeURIComponent(hold_id)+'/suspension', |
8 |
data: function () { |
9 |
if ( end_date !== null ) return JSON.stringify({ "end_date": end_date }) |
10 |
} |
11 |
}); |
12 |
} |
13 |
|
14 |
function resume_hold(hold_id) { |
15 |
return $.ajax({ |
16 |
method: 'DELETE', |
17 |
url: '/api/v1/holds/'+encodeURIComponent(hold_id)+'/suspension' |
18 |
}); |
19 |
} |
20 |
|
3 |
var holdsTable; |
21 |
var holdsTable; |
4 |
|
22 |
|
5 |
// Don't load holds table unless it is clicked on |
23 |
// Don't load holds table unless it is clicked on |
Lines 131-140
$(document).ready(function() {
Link Here
|
131 |
if ( oObj.found ) { |
149 |
if ( oObj.found ) { |
132 |
return ""; |
150 |
return ""; |
133 |
} else if ( oObj.suspend == 1 ) { |
151 |
} else if ( oObj.suspend == 1 ) { |
134 |
return "<a class='hold-resume btn btn-default btn-xs' id='resume" + oObj.reserve_id + "'>" |
152 |
return "<a class='hold-resume btn btn-default btn-xs' data-hold-id='" + oObj.reserve_id + "'>" |
135 |
+"<i class='fa fa-play'></i> " + __("Resume") + "</a>"; |
153 |
+"<i class='fa fa-play'></i> " + __("Resume") + "</a>"; |
136 |
} else { |
154 |
} else { |
137 |
return "<a class='hold-suspend btn btn-default btn-xs' id='suspend" + oObj.reserve_id + "'>" |
155 |
return "<a class='hold-suspend btn btn-default btn-xs' data-hold-id='" + oObj.reserve_id + "' data-hold-title='"+ oObj.title +"'>" |
138 |
+"<i class='fa fa-pause'></i> " + __("Suspend") + "</a>"; |
156 |
+"<i class='fa fa-pause'></i> " + __("Suspend") + "</a>"; |
139 |
} |
157 |
} |
140 |
} |
158 |
} |
Lines 197-221
$(document).ready(function() {
Link Here
|
197 |
|
215 |
|
198 |
$('#holds-table').on( 'draw.dt', function () { |
216 |
$('#holds-table').on( 'draw.dt', function () { |
199 |
$(".hold-suspend").on( "click", function() { |
217 |
$(".hold-suspend").on( "click", function() { |
200 |
var id = $(this).attr("id").replace("suspend", ""); |
218 |
var hold_id = $(this).data('hold-id'); |
201 |
var hold = holds[id]; |
219 |
var hold_title = $(this).data('hold-title'); |
202 |
$("#suspend-modal-title").html( hold.title ); |
220 |
$("#suspend-modal-title").html( hold_title ); |
203 |
$("#suspend-modal-reserve_id").val( hold.reserve_id ); |
221 |
$("#suspend-modal-submit").data( 'hold-id', hold_id ); |
204 |
$('#suspend-modal').modal('show'); |
222 |
$('#suspend-modal').modal('show'); |
205 |
}); |
223 |
}); |
206 |
|
224 |
|
207 |
$(".hold-resume").on( "click", function() { |
225 |
$(".hold-resume").on("click", function () { |
208 |
var id = $(this).attr("id").replace("resume", ""); |
226 |
var hold_id = $(this).data('hold-id'); |
209 |
var hold = holds[id]; |
227 |
resume_hold( |
210 |
$.post('/cgi-bin/koha/svc/hold/resume', { "reserve_id": hold.reserve_id }, function( data ){ |
228 |
hold_id |
211 |
if ( data.success ) { |
229 |
).success(function () { |
212 |
holdsTable.api().ajax.reload(); |
230 |
holdsTable.api().ajax.reload(); |
213 |
} else { |
231 |
}).error(function (jqXHR, textStatus, errorThrown) { |
214 |
if ( data.error == "HOLD_NOT_FOUND" ) { |
232 |
if (jqXHR.status === 404) { |
215 |
alert( __("Unable to resume, hold not found") ); |
233 |
alert(__("Unable to resume, hold not found")); |
216 |
holdsTable.api().ajax.reload(); |
234 |
holdsTable.api().ajax.reload(); |
217 |
} |
235 |
} |
218 |
} |
|
|
219 |
}); |
236 |
}); |
220 |
}); |
237 |
}); |
221 |
|
238 |
|
Lines 340-358
$(document).ready(function() {
Link Here
|
340 |
|
357 |
|
341 |
$("#suspend-modal-submit").on( "click", function( e ) { |
358 |
$("#suspend-modal-submit").on( "click", function( e ) { |
342 |
e.preventDefault(); |
359 |
e.preventDefault(); |
343 |
$.post('/cgi-bin/koha/svc/hold/suspend', $('#suspend-modal-form').serialize(), function( data ){ |
360 |
var suspend_until_date = $("#suspend-modal-until").datepicker("getDate"); |
344 |
$('#suspend-modal').modal('hide'); |
361 |
if ( suspend_until_date !== null ) suspend_until_date = $date(suspend_until_date, {dateformat:"rfc3339"}); |
345 |
if ( data.success ) { |
362 |
suspend_hold( |
346 |
holdsTable.api().ajax.reload(); |
363 |
$(this).data('hold-id'), |
347 |
} else { |
364 |
suspend_until_date |
348 |
if ( data.error == "INVALID_DATE" ) { |
365 |
).success(function () { |
349 |
alert( __("Unable to suspend hold, invalid date") ); |
366 |
holdsTable.api().ajax.reload(); |
350 |
} |
367 |
}).error(function (jqXHR, textStatus, errorThrown) { |
351 |
else if ( data.error == "HOLD_NOT_FOUND" ) { |
368 |
if (jqXHR.status === 404) { |
352 |
alert( __("Unable to suspend hold, hold not found") ); |
369 |
alert(__("Unable to resume, hold not found")); |
353 |
holdsTable.api().ajax.reload(); |
370 |
holdsTable.api().ajax.reload(); |
354 |
} |
371 |
} |
355 |
} |
372 |
}).done(function() { |
|
|
373 |
$("#suspend-modal-until").val(""); // clean the input |
374 |
$('#suspend-modal').modal('hide'); |
356 |
}); |
375 |
}); |
357 |
}); |
376 |
}); |
358 |
}); |
377 |
}); |
359 |
- |
|
|