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 = KohaTable("#issues-table", {
169 "sEmptyTable" : MSG_DT_LOADING_RECORDS,
170 "sProcessing": MSG_DT_LOADING_RECORDS,
173 "sDom": 'C<"clearfix">rt',
176 "mDataProp": function( oObj ) {
177 return oObj.sort_order;
181 "mDataProp": function( oObj ) {
182 if ( oObj.issued_today ) {
183 return "<strong>" + TODAYS_CHECKOUTS + "</strong>";
185 return "<strong>" + PREVIOUS_CHECKOUTS + "</strong>";
190 "mDataProp": "date_due",
194 "iDataSort": 2, // Sort on hidden unformatted date due column
195 "mDataProp": function( oObj ) {
196 var due = oObj.date_due_formatted;
198 if ( oObj.date_due_overdue ) {
199 due = "<span class='overdue'>" + due + "</span>";
203 due += "<span class='lost'>" + oObj.lost + "</span>";
206 if ( oObj.damaged ) {
207 due += "<span class='dmg'>" + oObj.damaged + "</span>";
210 due = "<span id='date_due_" + oObj.itemnumber + "' class='date_due'>" + due + "</span>";
216 "mDataProp": function ( oObj ) {
217 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
222 $.each(oObj.subtitle, function( index, value ) {
223 title += " " + value.subfield;
226 title += "</a></span>";
229 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author );
232 if ( oObj.itemnotes ) {
234 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
235 span_class = "circ-hlt";
237 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
240 var onsite_checkout = '';
241 if ( oObj.onsite_checkout == 1 ) {
242 onsite_checkout += " <span class='onsite_checkout'>(" + INHOUSE_USE + ")</span>";
246 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
261 { "mDataProp": "itemtype_description" },
262 { "mDataProp": "location" },
263 { "mDataProp": "issuedate_formatted" },
264 { "mDataProp": "branchname" },
265 { "mDataProp": "itemcallnumber" },
267 "mDataProp": function ( oObj ) {
268 if ( ! oObj.charge ) oObj.charge = 0;
269 return parseFloat(oObj.charge).toFixed(2);
273 "mDataProp": function ( oObj ) {
274 if ( ! oObj.fine ) oObj.fine = 0;
275 return parseFloat(oObj.fine).toFixed(2);
279 "mDataProp": function ( oObj ) {
280 if ( ! oObj.price ) oObj.price = 0;
281 return parseFloat(oObj.price).toFixed(2);
286 "mDataProp": function ( oObj ) {
292 content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
294 if ( oObj.can_renew ) {
296 } else if ( oObj.can_renew_error == "on_reserve" ) {
297 content += "<span class='renewals-disabled-no-override'>"
298 + "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>"
301 span_style = "display: none";
302 span_class = "renewals-allowed";
303 } else if ( oObj.can_renew_error == "too_many" ) {
304 content += "<span class='renewals-disabled'>"
308 span_style = "display: none";
309 span_class = "renewals-allowed";
310 } else if ( oObj.can_renew_error == "too_soon" ) {
311 content += "<span class='renewals-disabled'>"
312 + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date )
315 span_style = "display: none";
316 span_class = "renewals-allowed";
317 } else if ( oObj.can_renew_error == "auto_too_soon" ) {
318 content += "<span class='renewals-disabled'>"
319 + NOT_RENEWABLE_AUTO_TOO_SOON
322 span_style = "display: none";
323 span_class = "renewals-allowed";
324 } else if ( oObj.can_renew_error == "auto_renew" ) {
325 content += "<span class='renewals-disabled'>"
326 + NOT_RENEWABLE_AUTO_RENEW
329 span_style = "display: none";
330 span_class = "renewals-allowed";
331 } else if ( oObj.can_renew_error == "onsite_checkout" ) {
332 // Don't display something if it's an onsite checkout
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 ( can_renew || can_force_renew ) {
345 content += "<span class='" + span_class + "' style='" + span_style + "'>"
346 + "<input type='checkbox' ";
347 if ( oObj.date_due_overdue && can_renew ) {
348 content += "checked='checked' ";
350 content += "class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
353 content += "<span class='renewals'>("
354 + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed )
358 content += "</span>";
365 "mDataProp": function ( oObj ) {
366 if ( oObj.can_renew_error == "on_reserve" ) {
367 return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>";
369 return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
374 "bVisible": exports_enabled ? true : false,
376 "mDataProp": function ( oObj ) {
377 return "<input type='checkbox' class='export' id='export_" + oObj.biblionumber + "' name='biblionumbers' value='" + oObj.biblionumber + "' />";
381 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
382 var total_charge = 0;
385 for ( var i=0; i < aaData.length; i++ ) {
386 total_charge += aaData[i]['charge'] * 1;
387 total_fine += aaData[i]['fine'] * 1;
388 total_price += aaData[i]['price'] * 1;
390 $("#totaldue").html(total_charge.toFixed(2));
391 $("#totalfine").html(total_fine.toFixed(2));
392 $("#totalprice").html(total_price.toFixed(2));
396 "bServerSide": false,
397 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
398 "fnServerData": function ( sSource, aoData, fnCallback ) {
399 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
401 $.getJSON( sSource, aoData, function (json) {
405 "fnInitComplete": function(oSettings) {
406 // Disable rowGrouping plugin after first use
407 // so any sorting on the table doesn't use it
408 var oSettings = issuesTable.fnSettings();
410 for (f = 0; f < oSettings.aoDrawCallback.length; f++) {
411 if (oSettings.aoDrawCallback[f].sName == 'fnRowGrouping') {
412 oSettings.aoDrawCallback.splice(f, 1);
417 oSettings.aaSortingFixed = null;
419 }, columns_settings).rowGrouping(
421 iGroupingColumnIndex: 1,
422 iGroupingOrderByColumnIndex: 0,
423 sGroupingColumnSortDirection: "asc"
427 if ( $("#issues-table").length ) {
428 $("#issues-table_processing").position({
429 of: $( "#issues-table" ),
435 // Don't load relatives' issues table unless it is clicked on
436 var relativesIssuesTable;
437 $("#relatives-issues-tab").click( function() {
438 if ( ! relativesIssuesTable ) {
439 relativesIssuesTable = $("#relatives-issues-table").dataTable({
445 "mDataProp": "date_due",
449 "iDataSort": 1, // Sort on hidden unformatted date due column
450 "mDataProp": function( oObj ) {
451 var today = new Date();
452 var due = new Date( oObj.date_due );
454 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
456 return oObj.date_due_formatted;
461 "mDataProp": function ( oObj ) {
462 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
467 $.each(oObj.subtitle, function( index, value ) {
468 title += " " + value.subfield;
471 title += "</a></span>";
474 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author );
477 if ( oObj.itemnotes ) {
479 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
480 span_class = "circ-hlt";
482 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
485 var onsite_checkout = '';
486 if ( oObj.onsite_checkout == 1 ) {
487 onsite_checkout += " <span class='onsite_checkout'>(" + INHOUSE_USE + ")</span>";
491 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
506 { "mDataProp": "itemtype" },
507 { "mDataProp": "location" },
508 { "mDataProp": "issuedate_formatted" },
509 { "mDataProp": "branchname" },
510 { "mDataProp": "itemcallnumber" },
512 "mDataProp": function ( oObj ) {
513 if ( ! oObj.charge ) oObj.charge = 0;
514 return parseFloat(oObj.charge).toFixed(2);
518 "mDataProp": function ( oObj ) {
519 if ( ! oObj.fine ) oObj.fine = 0;
520 return parseFloat(oObj.fine).toFixed(2);
524 "mDataProp": function ( oObj ) {
525 if ( ! oObj.price ) oObj.price = 0;
526 return parseFloat(oObj.price).toFixed(2);
530 "mDataProp": function( oObj ) {
531 return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
532 + oObj.borrower.firstname + " " + oObj.borrower.surname + " (" + oObj.borrower.cardnumber + ")</a>"
538 "bServerSide": false,
539 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
540 "fnServerData": function ( sSource, aoData, fnCallback ) {
541 $.each(relatives_borrowernumbers, function( index, value ) {
542 aoData.push( { "name": "borrowernumber", "value": value } );
545 $.getJSON( sSource, aoData, function (json) {
553 if ( $("#relatives-issues-table").length ) {
554 $("#relatives-issues-table_processing").position({
555 of: $( "#relatives-issues-table" ),
560 if ( AllowRenewalLimitOverride ) {
561 $( '#override_limit' ).click( function () {
562 if ( this.checked ) {
563 $( '.renewals-allowed' ).show(); $( '.renewals-disabled' ).hide();
565 $( '.renewals-allowed' ).hide(); $( '.renewals-disabled' ).show();
567 } ).attr( 'checked', false );