1 $(document).ready(function() {
2 $.ajaxSetup ({ cache: false });
4 var barcodefield = $("#barcode");
6 // Handle the select all/none links for checkouts table columns
7 $("#CheckAllRenewals").on("click",function(){
8 $("#UncheckAllCheckins").click();
9 $(".renew:visible").attr("checked", "checked" );
12 $("#UncheckAllRenewals").on("click",function(){
13 $(".renew:visible").removeAttr("checked");
17 $("#CheckAllCheckins").on("click",function(){
18 $("#UncheckAllRenewals").click();
19 $(".checkin:visible").attr("checked", "checked" );
22 $("#UncheckAllCheckins").on("click",function(){
23 $(".checkin:visible").removeAttr("checked");
27 // Don't allow both return and renew checkboxes to be checked
28 $(document).on("change", '.renew', function(){
29 if ( $(this).is(":checked") ) {
30 $( "#checkin_" + $(this).val() ).removeAttr("checked");
33 $(document).on("change", '.checkin', function(){
34 if ( $(this).is(":checked") ) {
35 $( "#renew_" + $(this).val() ).removeAttr("checked");
39 // Clicking the table cell checks the checkbox inside it
40 $(document).on("click", 'td', function(e){
41 if(e.target.tagName.toLowerCase() == 'td'){
42 $(this).find("input:checkbox:visible").each( function() {
48 // Handle renewals and returns
49 $("#RenewCheckinChecked").on("click",function(){
50 $(".checkin:checked:visible").each(function() {
51 itemnumber = $(this).val();
53 $(this).replaceWith("<img id='checkin_" + itemnumber + "' src='" + interface + "/" + theme + "/img/loading-small.gif' />");
56 itemnumber: itemnumber,
57 borrowernumber: borrowernumber,
58 branchcode: branchcode,
59 exempt_fine: $("#exemptfine").is(':checked')
62 $.post( "/cgi-bin/koha/svc/checkin", params, function( data ) {
63 id = "#checkin_" + data.itemnumber;
66 if ( data.returned ) {
67 content = CIRCULATION_RETURNED;
68 $(id).parent().parent().addClass('ok');
69 $('#date_due_' + data.itemnumber).html(CIRCULATION_RETURNED);
71 content = CIRCULATION_NOT_RETURNED;
72 $(id).parent().parent().addClass('warn');
75 $(id).replaceWith( content );
79 $(".renew:checked:visible").each(function() {
80 var override_limit = $("#override_limit").is(':checked') ? 1 : 0;
82 var itemnumber = $(this).val();
84 $(this).parent().parent().replaceWith("<img id='renew_" + itemnumber + "' src='" + interface + "/" + theme + "/img/loading-small.gif' />");
87 itemnumber: itemnumber,
88 borrowernumber: borrowernumber,
89 branchcode: branchcode,
90 override_limit: override_limit,
91 date_due: $("#newduedate").val()
94 $.post( "/cgi-bin/koha/svc/renew", params, function( data ) {
95 var id = "#renew_" + data.itemnumber;
98 if ( data.renew_okay ) {
99 content = CIRCULATION_RENEWED_DUE + " " + data.date_due;
100 $('#date_due_' + data.itemnumber).replaceWith( data.date_due );
102 content = CIRCULATION_RENEW_FAILED + " ";
103 if ( data.error == "no_checkout" ) {
104 content += NOT_CHECKED_OUT;
105 } else if ( data.error == "too_many" ) {
106 content += TOO_MANY_RENEWALS;
107 } else if ( data.error == "on_reserve" ) {
108 content += ON_RESERVE;
109 } else if ( data.error ) {
110 content += data.error;
112 content += REASON_UNKNOWN;
116 $(id).replaceWith( content );
120 // Refocus on barcode field if it exists
121 if ( $("#barcode").length ) {
122 $("#barcode").focus();
125 // Prevent form submit
129 $("#RenewAll").on("click",function(){
130 $("#CheckAllRenewals").click();
131 $("#UncheckAllCheckins").click();
132 $("#RenewCheckinChecked").click();
134 // Prevent form submit
138 var ymd = $.datepicker.formatDate('yy-mm-dd', new Date());
140 $('#issues-table').hide();
141 $('#issues-table-actions').hide();
142 $('#issues-table-load-immediately').change(function(){
143 if ( this.checked && typeof issuesTable === 'undefined') {
144 $('#issues-table-load-now-button').click();
146 barcodefield.focus();
148 $('#issues-table-load-now-button').click(function(){
150 barcodefield.focus();
154 if ( $.cookie("issues-table-load-immediately-" + script) == "true" ) {
156 $('#issues-table-load-immediately').prop('checked', true);
158 $('#issues-table-load-immediately').on( "change", function(){
159 $.cookie("issues-table-load-immediately-" + script, $(this).is(':checked'), { expires: 365 });
162 function LoadIssuesTable() {
163 $('#issues-table-loading-message').hide();
164 $('#issues-table').show();
165 $('#issues-table-actions').show();
167 issuesTable = $("#issues-table").dataTable({
169 "sEmptyTable" : MSG_DT_LOADING_RECORDS,
170 "sProcessing": MSG_DT_LOADING_RECORDS,
176 "mDataProp": function( oObj ) {
177 if ( oObj.issued_today ) {
178 return "1" + oObj.timestamp;
180 return "0" + oObj.date_due;
185 "mDataProp": function( oObj ) {
186 if ( oObj.issued_today ) {
187 return "<strong>" + TODAYS_CHECKOUTS + "</strong>";
189 return "<strong>" + PREVIOUS_CHECKOUTS + "</strong>";
194 "mDataProp": "date_due",
198 "iDataSort": 1, // Sort on hidden unformatted date due column
199 "mDataProp": function( oObj ) {
200 var due = oObj.date_due_formatted;
202 if ( oObj.date_due_overdue ) {
203 due = "<span class='overdue'>" + due + "</span>";
207 due += "<span class='lost'>" + oObj.lost + "</span>";
210 if ( oObj.damaged ) {
211 due += "<span class='dmg'>" + oObj.damaged + "</span>";
214 due = "<span id='date_due_" + oObj.itemnumber + "' class='date_due'>" + due + "</span>";
220 "mDataProp": function ( oObj ) {
221 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
226 $.each(oObj.subtitle, function( index, value ) {
227 title += " " + value.subfield;
230 title += "</a></span>";
233 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author );
236 if ( oObj.itemnotes ) {
238 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
239 span_class = "circ-hlt";
241 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
244 var onsite_checkout = '';
245 if ( oObj.onsite_checkout == 1 ) {
246 onsite_checkout += " <span class='onsite_checkout'>(" + INHOUSE_USE + ")</span>";
250 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
264 { "mDataProp": "itemtype_description" },
265 { "mDataProp": "issuedate_formatted" },
266 { "mDataProp": "branchname" },
267 { "mDataProp": "itemcallnumber" },
269 "mDataProp": function ( oObj ) {
270 if ( ! oObj.charge ) oObj.charge = 0;
271 return parseFloat(oObj.charge).toFixed(2);
275 "mDataProp": function ( oObj ) {
276 if ( ! oObj.fine ) oObj.fine = 0;
277 return parseFloat(oObj.fine).toFixed(2);
281 "mDataProp": function ( oObj ) {
282 if ( ! oObj.price ) oObj.price = 0;
283 return parseFloat(oObj.price).toFixed(2);
288 "mDataProp": function ( oObj ) {
294 content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
296 if ( oObj.can_renew ) {
298 } else if ( oObj.can_renew_error == "on_reserve" ) {
299 content += "<span class='renewals-disabled-no-override'>"
300 + "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>"
303 span_style = "display: none";
304 span_class = "renewals-allowed";
305 } else if ( oObj.can_renew_error == "too_many" ) {
306 content += "<span class='renewals-disabled'>"
310 span_style = "display: none";
311 span_class = "renewals-allowed";
312 } else if ( oObj.can_renew_error == "too_soon" ) {
313 content += "<span class='renewals-disabled'>"
314 + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date )
317 span_style = "display: none";
318 span_class = "renewals-allowed";
319 } else if ( oObj.can_renew_error == "auto_too_soon" ) {
320 content += "<span class='renewals-disabled'>"
321 + NOT_RENEWABLE_AUTO_TOO_SOON
324 span_style = "display: none";
325 span_class = "renewals-allowed";
326 } else if ( oObj.can_renew_error == "auto_renew" ) {
327 content += "<span class='renewals-disabled'>"
328 + NOT_RENEWABLE_AUTO_RENEW
331 span_style = "display: none";
332 span_class = "renewals-allowed";
334 content += "<span class='renewals-disabled'>"
335 + oObj.can_renew_error
338 span_style = "display: none";
339 span_class = "renewals-allowed";
342 var can_force_renew = ( oObj.onsite_checkout == 0 ) && ( oObj.can_renew_error != "on_reserve" );
343 var can_renew = ( oObj.renewals_remaining > 0 && !oObj.can_renew_error );
344 if ( oObj.onsite_checkout == 0 ) {
345 if ( can_renew || can_force_renew ) {
346 content += "<span class='" + span_class + "' style='" + span_style + "'>"
347 + "<input type='checkbox' ";
348 if ( oObj.date_due_overdue && can_renew ) {
349 content += "checked='checked' ";
351 content += "class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
354 content += "<span class='renewals'>("
355 + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed )
360 content += "</span>";
367 "mDataProp": function ( oObj ) {
368 if ( oObj.can_renew_error == "on_reserve" ) {
369 return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>";
371 return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
376 "bVisible": exports_enabled ? true : false,
378 "mDataProp": function ( oObj ) {
379 return "<input type='checkbox' class='export' id='export_" + oObj.biblionumber + "' name='biblionumbers' value='" + oObj.biblionumber + "' />";
383 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
384 var total_charge = 0;
387 for ( var i=0; i < aaData.length; i++ ) {
388 total_charge += aaData[i]['charge'] * 1;
389 total_fine += aaData[i]['fine'] * 1;
390 total_price += aaData[i]['price'] * 1;
392 var nCells = nRow.getElementsByTagName('td');
393 nCells[1].innerHTML = total_charge.toFixed(2);
394 nCells[2].innerHTML = total_fine.toFixed(2);
395 nCells[3].innerHTML = total_price.toFixed(2);
399 "bServerSide": false,
400 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
401 "fnServerData": function ( sSource, aoData, fnCallback ) {
402 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
404 $.getJSON( sSource, aoData, function (json) {
408 "fnInitComplete": function(oSettings) {
409 // Disable rowGrouping plugin after first use
410 // so any sorting on the table doesn't use it
411 var oSettings = issuesTable.fnSettings();
413 for (f = 0; f < oSettings.aoDrawCallback.length; f++) {
414 if (oSettings.aoDrawCallback[f].sName == 'fnRowGrouping') {
415 oSettings.aoDrawCallback.splice(f, 1);
420 oSettings.aaSortingFixed = null;
424 iGroupingColumnIndex: 1,
425 iGroupingOrderByColumnIndex: 0,
426 sGroupingColumnSortDirection: "desc"
430 if ( $("#issues-table").length ) {
431 $("#issues-table_processing").position({
432 of: $( "#issues-table" ),
438 // Don't load relatives' issues table unless it is clicked on
439 var relativesIssuesTable;
440 $("#relatives-issues-tab").click( function() {
441 if ( ! relativesIssuesTable ) {
442 relativesIssuesTable = $("#relatives-issues-table").dataTable({
448 "mDataProp": "date_due",
452 "iDataSort": 1, // Sort on hidden unformatted date due column
453 "mDataProp": function( oObj ) {
454 var today = new Date();
455 var due = new Date( oObj.date_due );
457 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
459 return oObj.date_due_formatted;
464 "mDataProp": function ( oObj ) {
465 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
470 $.each(oObj.subtitle, function( index, value ) {
471 title += " " + value.subfield;
474 title += "</a></span>";
477 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author );
480 if ( oObj.itemnotes ) {
482 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
483 span_class = "circ-hlt";
485 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
488 var onsite_checkout = '';
489 if ( oObj.onsite_checkout == 1 ) {
490 onsite_checkout += " <span class='onsite_checkout'>(" + INHOUSE_USE + ")</span>";
494 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
508 { "mDataProp": "itemtype" },
509 { "mDataProp": "issuedate_formatted" },
510 { "mDataProp": "branchname" },
511 { "mDataProp": "itemcallnumber" },
513 "mDataProp": function ( oObj ) {
514 if ( ! oObj.charge ) oObj.charge = 0;
515 return parseFloat(oObj.charge).toFixed(2);
519 "mDataProp": function ( oObj ) {
520 if ( ! oObj.fine ) oObj.fine = 0;
521 return parseFloat(oObj.fine).toFixed(2);
525 "mDataProp": function ( oObj ) {
526 if ( ! oObj.price ) oObj.price = 0;
527 return parseFloat(oObj.price).toFixed(2);
531 "mDataProp": function( oObj ) {
532 return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
533 + oObj.borrower.firstname + " " + oObj.borrower.surname + " (" + oObj.borrower.cardnumber + ")</a>"
539 "bServerSide": false,
540 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
541 "fnServerData": function ( sSource, aoData, fnCallback ) {
542 $.each(relatives_borrowernumbers, function( index, value ) {
543 aoData.push( { "name": "borrowernumber", "value": value } );
546 $.getJSON( sSource, aoData, function (json) {
554 if ( $("#relatives-issues-table").length ) {
555 $("#relatives-issues-table_processing").position({
556 of: $( "#relatives-issues-table" ),
561 if ( AllowRenewalLimitOverride ) {
562 $( '#override_limit' ).click( function () {
563 if ( this.checked ) {
564 $( '.renewals-allowed' ).show(); $( '.renewals-disabled' ).hide();
566 $( '.renewals-allowed' ).hide(); $( '.renewals-disabled' ).show();
568 } ).attr( 'checked', false );