1 $(document).ready(function() {
2 $.ajaxSetup ({ cache: false });
4 var barcodefield = $("#barcode");
6 var onHoldDueDateSet = false;
8 var onHoldChecked = function() {
10 $('input[data-on-reserve]').each(function() {
11 if ($(this).is(':checked')) {
18 var showHideOnHoldRenewal = function() {
19 // Display the date input
20 if (onHoldChecked()) {
21 $('#newonholdduedate').show()
23 $('#newonholdduedate').hide();
27 // Handle the select all/none links for checkouts table columns
28 $("#CheckAllRenewals").on("click",function(){
29 $("#UncheckAllCheckins").click();
30 $(".renew:visible").prop("checked", true);
31 showHideOnHoldRenewal();
34 $("#UncheckAllRenewals").on("click",function(){
35 $(".renew:visible").prop("checked", false);
36 showHideOnHoldRenewal();
40 $("#CheckAllCheckins").on("click",function(){
41 $("#UncheckAllRenewals").click();
42 $(".checkin:visible").prop("checked", true);
45 $("#UncheckAllCheckins").on("click",function(){
46 $(".checkin:visible").prop("checked", false);
50 $("#newduedate").on("change", function() {
51 if (!onHoldDueDateSet) {
52 $('#newonholdduedate input').val($('#newduedate').val());
56 $("#newonholdduedate").on("change", function() {
57 onHoldDueDateSet = true;
60 // Don't allow both return and renew checkboxes to be checked
61 $(document).on("change", '.renew', function(){
62 if ( $(this).is(":checked") ) {
63 $( "#checkin_" + $(this).val() ).prop("checked", false);
66 $(document).on("change", '.checkin', function(){
67 if ( $(this).is(":checked") ) {
68 $( "#renew_" + $(this).val() ).prop("checked", false);
72 // Display on hold due dates input when an on hold item is
74 $(document).on('change', '.renew', function(){
75 showHideOnHoldRenewal();
78 $("#output_format > option:first-child").attr("selected", "selected");
79 $("select[name='csv_profile_id']").hide();
80 $(document).on("change", '#issues-table-output-format', function(){
81 if ( $(this).val() == 'csv' ) {
82 $("select[name='csv_profile_id']").show();
84 $("select[name='csv_profile_id']").hide();
88 // Clicking the table cell checks the checkbox inside it
89 $(document).on("click", 'td', function(e){
90 if(e.target.tagName.toLowerCase() == 'td'){
91 $(this).find("input:checkbox:visible").each( function() {
97 // Handle renewals and returns
98 $("#RenewCheckinChecked").on("click",function(){
99 $(".checkin:checked:visible").each(function() {
100 itemnumber = $(this).val();
102 $(this).replaceWith("<img id='checkin_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
105 itemnumber: itemnumber,
106 borrowernumber: borrowernumber,
107 branchcode: branchcode,
108 exempt_fine: $("#exemptfine").is(':checked')
111 $.post( "/cgi-bin/koha/svc/checkin", params, function( data ) {
112 id = "#checkin_" + data.itemnumber;
115 if ( data.returned ) {
116 content = CIRCULATION_RETURNED;
117 $(id).parent().parent().addClass('ok');
118 $('#date_due_' + data.itemnumber).html(CIRCULATION_RETURNED);
119 if ( data.patronnote != null ) {
120 $('.patron_note_' + data.itemnumber).html("Patron note: " + data.patronnote);
123 content = CIRCULATION_NOT_RETURNED;
124 $(id).parent().parent().addClass('warn');
127 $(id).replaceWith( content );
131 $(".renew:checked:visible").each(function() {
132 var override_limit = $("#override_limit").is(':checked') ? 1 : 0;
134 var isOnReserve = $(this).data().hasOwnProperty('onReserve');
136 var itemnumber = $(this).val();
138 $(this).parent().parent().replaceWith("<img id='renew_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
141 itemnumber: itemnumber,
142 borrowernumber: borrowernumber,
143 branchcode: branchcode,
144 override_limit: override_limit,
147 // Determine which due date we need to use
148 var dueDate = isOnReserve ?
149 $("#newonholdduedate input").val() :
150 $("#newduedate").val();
152 if (dueDate && dueDate.length > 0) {
153 params.date_due = dueDate
156 $.post( "/cgi-bin/koha/svc/renew", params, function( data ) {
157 var id = "#renew_" + data.itemnumber;
160 if ( data.renew_okay ) {
161 content = CIRCULATION_RENEWED_DUE + " " + data.date_due;
162 $('#date_due_' + data.itemnumber).replaceWith( data.date_due );
164 content = CIRCULATION_RENEW_FAILED + " ";
165 if ( data.error == "no_checkout" ) {
166 content += NOT_CHECKED_OUT;
167 } else if ( data.error == "too_many" ) {
168 content += TOO_MANY_RENEWALS;
169 } else if ( data.error == "on_reserve" ) {
170 content += ON_RESERVE;
171 } else if ( data.error == "restriction" ) {
172 content += NOT_RENEWABLE_RESTRICTION;
173 } else if ( data.error == "overdue" ) {
174 content += NOT_RENEWABLE_OVERDUE;
175 } else if ( data.error ) {
176 content += data.error;
178 content += REASON_UNKNOWN;
182 $(id).replaceWith( content );
186 // Refocus on barcode field if it exists
187 if ( $("#barcode").length ) {
188 $("#barcode").focus();
191 // Prevent form submit
195 $("#RenewAll").on("click",function(){
196 $("#CheckAllRenewals").click();
197 $("#UncheckAllCheckins").click();
198 showHideOnHoldRenewal();
199 $("#RenewCheckinChecked").click();
201 // Prevent form submit
205 var ymd = $.datepicker.formatDate('yy-mm-dd', new Date());
207 $('#issues-table').hide();
208 $('#issues-table-actions').hide();
209 $('#issues-table-load-immediately').change(function(){
210 if ( this.checked && typeof issuesTable === 'undefined') {
211 $('#issues-table-load-now-button').click();
213 barcodefield.focus();
215 $('#issues-table-load-now-button').click(function(){
217 barcodefield.focus();
221 if ( $.cookie("issues-table-load-immediately-" + script) == "true" ) {
223 $('#issues-table-load-immediately').prop('checked', true);
225 $('#issues-table-load-immediately').on( "change", function(){
226 $.cookie("issues-table-load-immediately-" + script, $(this).is(':checked'), { expires: 365 });
229 function LoadIssuesTable() {
230 $('#issues-table-loading-message').hide();
231 $('#issues-table').show();
232 $('#issues-table-actions').show();
234 issuesTable = KohaTable("issues-table", {
236 "sEmptyTable" : MSG_DT_LOADING_RECORDS,
237 "sProcessing": MSG_DT_LOADING_RECORDS,
240 "dom": 'B<"clearfix">rt',
243 "mDataProp": function( oObj ) {
244 return oObj.sort_order;
248 "mDataProp": function( oObj ) {
249 if ( oObj.issued_today ) {
250 return "<strong>" + TODAYS_CHECKOUTS + "</strong>";
252 return "<strong>" + PREVIOUS_CHECKOUTS + "</strong>";
257 "mDataProp": "date_due",
261 "iDataSort": 2, // Sort on hidden unformatted date due column
262 "mDataProp": function( oObj ) {
263 var due = oObj.date_due_formatted;
265 if ( oObj.date_due_overdue ) {
266 due = "<span class='overdue'>" + due + "</span>";
269 due = "<span id='date_due_" + oObj.itemnumber + "' class='date_due'>" + due + "</span>";
272 due += "<span class='lost'>" + oObj.lost.escapeHtml() + "</span>";
275 if ( oObj.damaged ) {
276 due += "<span class='dmg'>" + oObj.damaged.escapeHtml() + "</span>";
279 var patron_note = " <span class='patron_note_" + oObj.itemnumber + "'></span>";
280 due +="<br>" + patron_note;
286 "mDataProp": function ( oObj ) {
287 title = "<span id='title_" + oObj.itemnumber + "' class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
290 + oObj.title.escapeHtml();
292 $.each(oObj.subtitle, function( index, value ) {
293 title += " " + value.subfield.escapeHtml();
296 if ( oObj.enumchron ) {
297 title += " (" + oObj.enumchron.escapeHtml() + ")";
300 title += "</a></span>";
303 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
306 if ( oObj.itemnotes ) {
307 var span_class = "text-muted";
308 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
309 span_class = "circ-hlt";
311 title += " - <span class='" + span_class + " item-note-public'>" + oObj.itemnotes.escapeHtml() + "</span>";
314 if ( oObj.itemnotes_nonpublic ) {
315 var span_class = "text-danger";
316 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
317 span_class = "circ-hlt";
319 title += " - <span class='" + span_class + " item-note-nonpublic'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>";
322 var onsite_checkout = '';
323 if ( oObj.onsite_checkout == 1 ) {
324 onsite_checkout += " <span class='onsite_checkout'>(" + INHOUSE_USE + ")</span>";
328 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
335 + oObj.barcode.escapeHtml()
344 "mDataProp": function ( oObj ) {
345 return oObj.itemtype_description.escapeHtml();
349 "mDataProp": function ( oObj ) {
350 return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
354 "mDataProp": function ( oObj ) {
355 return ( oObj.location ? oObj.location.escapeHtml() : '' );
359 "mDataProp": function ( oObj ) {
360 return oObj.homebranch.escapeHtml();
364 "mDataProp": "issuedate",
368 "iDataSort": 9, // Sort on hidden unformatted issuedate column
369 "mDataProp": "issuedate_formatted",
372 "mDataProp": function ( oObj ) {
373 return oObj.branchname.escapeHtml();
377 "mDataProp": function ( oObj ) {
378 return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
382 "mDataProp": function ( oObj ) {
383 if ( ! oObj.charge ) oObj.charge = 0;
384 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.charge).toFixed(2) + '<span>';
388 "mDataProp": function ( oObj ) {
389 if ( ! oObj.fine ) oObj.fine = 0;
390 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.fine).toFixed(2) + '<span>';
394 "mDataProp": function ( oObj ) {
395 if ( ! oObj.price ) oObj.price = 0;
396 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.price).toFixed(2) + '<span>';
401 "bVisible": AllowCirculate ? true : false,
402 "mDataProp": function ( oObj ) {
408 if ( oObj.can_renew ) {
410 } else if ( oObj.can_renew_error == "on_reserve" ) {
412 + "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>"
415 span_style = "display: none";
416 span_class = "renewals-allowed";
417 } else if ( oObj.can_renew_error == "too_many" ) {
418 msg += "<span class='renewals-disabled'>"
422 span_style = "display: none";
423 span_class = "renewals-allowed";
424 } else if ( oObj.can_renew_error == "restriction" ) {
425 msg += "<span class='renewals-disabled'>"
426 + NOT_RENEWABLE_RESTRICTION
429 span_style = "display: none";
430 span_class = "renewals-allowed";
431 } else if ( oObj.can_renew_error == "overdue" ) {
432 msg += "<span class='renewals-disabled'>"
433 + NOT_RENEWABLE_OVERDUE
436 span_style = "display: none";
437 span_class = "renewals-allowed";
438 } else if ( oObj.can_renew_error == "too_soon" ) {
439 msg += "<span class='renewals-disabled'>"
440 + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date )
443 span_style = "display: none";
444 span_class = "renewals-allowed";
445 } else if ( oObj.can_renew_error == "auto_too_soon" ) {
446 msg += "<span class='renewals-disabled'>"
447 + NOT_RENEWABLE_AUTO_TOO_SOON
450 span_style = "display: none";
451 span_class = "renewals-allowed";
452 } else if ( oObj.can_renew_error == "auto_too_late" ) {
453 msg += "<span class='renewals-disabled'>"
454 + NOT_RENEWABLE_AUTO_TOO_LATE
457 span_style = "display: none";
458 span_class = "renewals-allowed";
459 } else if ( oObj.can_renew_error == "auto_too_much_oweing" ) {
460 msg += "<span class='renewals-disabled'>"
461 + NOT_RENEWABLE_AUTO_TOO_MUCH_OWEING
464 span_style = "display: none";
465 span_class = "renewals-allowed";
466 } else if ( oObj.can_renew_error == "auto_account_expired" ) {
467 msg += "<span class='renewals-disabled'>"
468 + NOT_RENEWABLE_AUTO_ACCOUNT_EXPIRED
471 span_style = "display: none";
472 span_class = "renewals-allowed";
473 } else if ( oObj.can_renew_error == "auto_renew" ) {
474 msg += "<span class='renewals-disabled'>"
475 + NOT_RENEWABLE_AUTO_RENEW
478 span_style = "display: none";
479 span_class = "renewals-allowed";
480 } else if ( oObj.can_renew_error == "onsite_checkout" ) {
481 // Don't display something if it's an onsite checkout
482 } else if ( oObj.can_renew_error == "item_denied_renewal" ) {
483 content += "<span class='renewals-disabled'>"
484 + NOT_RENEWABLE_DENIED
487 span_style = "display: none";
488 span_class = "renewals-allowed";
490 msg += "<span class='renewals-disabled'>"
491 + oObj.can_renew_error
494 span_style = "display: none";
495 span_class = "renewals-allowed";
498 var can_force_renew = ( oObj.onsite_checkout == 0 ) &&
499 ( oObj.can_renew_error != "on_reserve" || (oObj.can_renew_error == "on_reserve" && AllowRenewalOnHoldOverride))
501 var can_renew = ( oObj.renewals_remaining > 0 && !oObj.can_renew_error );
503 if ( can_renew || can_force_renew ) {
504 content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
505 content += "<span class='" + span_class + "' style='" + span_style + "'>"
506 + "<input type='checkbox' ";
507 if ( oObj.date_due_overdue && can_renew ) {
508 content += "checked='checked' ";
510 if (oObj.can_renew_error == "on_reserve") {
511 content += "data-on-reserve ";
513 content += "class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
517 if ( can_renew || can_force_renew ) {
518 content += "<span class='renewals'>("
519 + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed )
523 content += "</span>";
530 "bVisible": AllowCirculate ? true : false,
531 "mDataProp": function ( oObj ) {
532 if ( oObj.can_renew_error == "on_reserve" ) {
533 return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>";
535 return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
540 "bVisible": exports_enabled == 1 ? true : false,
542 "mDataProp": function ( oObj ) {
543 var s = "<input type='checkbox' name='itemnumbers' value='" + oObj.itemnumber + "' style='visibility:hidden;' />";
545 s += "<input type='checkbox' class='export' id='export_" + oObj.biblionumber + "' name='biblionumbers' value='" + oObj.biblionumber + "' />";
550 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
551 var total_charge = 0;
554 for ( var i=0; i < aaData.length; i++ ) {
555 total_charge += aaData[i]['charge'] * 1;
556 total_fine += aaData[i]['fine'] * 1;
557 total_price += aaData[i]['price'] * 1;
559 $("#totaldue").html(total_charge.toFixed(2));
560 $("#totalfine").html(total_fine.toFixed(2));
561 $("#totalprice").html(total_price.toFixed(2));
565 "bServerSide": false,
566 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
567 "fnServerData": function ( sSource, aoData, fnCallback ) {
568 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
570 $.getJSON( sSource, aoData, function (json) {
574 "fnInitComplete": function(oSettings, json) {
575 // Disable rowGrouping plugin after first use
576 // so any sorting on the table doesn't use it
577 var oSettings = issuesTable.fnSettings();
579 for (f = 0; f < oSettings.aoDrawCallback.length; f++) {
580 if (oSettings.aoDrawCallback[f].sName == 'fnRowGrouping') {
581 oSettings.aoDrawCallback.splice(f, 1);
586 oSettings.aaSortingFixed = null;
588 // Build a summary of checkouts grouped by itemtype
589 var checkoutsByItype = json.aaData.reduce(function (obj, row) {
590 obj[row.itemtype_description] = (obj[row.itemtype_description] || 0) + 1;
594 Object.keys(checkoutsByItype).sort().forEach(function (itype) {
596 .append($('<strong>').html(itype || MSG_NO_ITEMTYPE))
597 .append(': ' + checkoutsByItype[itype]);
601 .addClass('checkouts-by-itemtype')
602 .append($('<summary>').html(MSG_CHECKOUTS_BY_ITEMTYPE))
604 .insertBefore(oSettings.nTableWrapper)
606 }, columns_settings_issues_table).rowGrouping(
608 iGroupingColumnIndex: 1,
609 iGroupingOrderByColumnIndex: 0,
610 sGroupingColumnSortDirection: "asc"
614 if ( $("#issues-table").length ) {
615 $("#issues-table_processing").position({
616 of: $( "#issues-table" ),
622 // Don't load relatives' issues table unless it is clicked on
623 var relativesIssuesTable;
624 $("#relatives-issues-tab").click( function() {
625 if ( ! relativesIssuesTable ) {
626 relativesIssuesTable = $("#relatives-issues-table").dataTable({
632 "mDataProp": "date_due",
636 "iDataSort": 0, // Sort on hidden unformatted date due column
637 "mDataProp": function( oObj ) {
638 var today = new Date();
639 var due = new Date( oObj.date_due );
641 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
643 return oObj.date_due_formatted;
648 "mDataProp": function ( oObj ) {
649 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
652 + oObj.title.escapeHtml();
654 $.each(oObj.subtitle, function( index, value ) {
655 title += " " + value.subfield.escapeHtml();
658 if ( oObj.enumchron ) {
659 title += " (" + oObj.enumchron.escapeHtml() + ")";
662 title += "</a></span>";
665 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
668 if ( oObj.itemnotes ) {
670 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
671 span_class = "circ-hlt";
673 title += " - <span class='" + span_class + "'>" + oObj.itemnotes.escapeHtml() + "</span>"
676 if ( oObj.itemnotes_nonpublic ) {
678 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
679 span_class = "circ-hlt";
681 title += " - <span class='" + span_class + "'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>"
684 var onsite_checkout = '';
685 if ( oObj.onsite_checkout == 1 ) {
686 onsite_checkout += " <span class='onsite_checkout'>(" + INHOUSE_USE + ")</span>";
690 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
697 + oObj.barcode.escapeHtml()
706 "mDataProp": function ( oObj ) {
707 return oObj.itemtype_description.escapeHtml();
711 "mDataProp": function ( oObj ) {
712 return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
716 "mDataProp": function ( oObj ) {
717 return ( oObj.location ? oObj.location.escapeHtml() : '' );
721 "mDataProp": "issuedate",
725 "iDataSort": 7, // Sort on hidden unformatted issuedate column
726 "mDataProp": "issuedate_formatted",
729 "mDataProp": function ( oObj ) {
730 return oObj.branchname.escapeHtml();
734 "mDataProp": function ( oObj ) {
735 return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
739 "mDataProp": function ( oObj ) {
740 if ( ! oObj.charge ) oObj.charge = 0;
741 return parseFloat(oObj.charge).toFixed(2);
745 "mDataProp": function ( oObj ) {
746 if ( ! oObj.fine ) oObj.fine = 0;
747 return parseFloat(oObj.fine).toFixed(2);
751 "mDataProp": function ( oObj ) {
752 if ( ! oObj.price ) oObj.price = 0;
753 return parseFloat(oObj.price).toFixed(2);
757 "mDataProp": function( oObj ) {
758 return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
759 + oObj.borrower.firstname.escapeHtml()
761 oObj.borrower.surname.escapeHtml()
762 + " (" + oObj.borrower.cardnumber.escapeHtml() + ")</a>"
768 "bServerSide": false,
769 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
770 "fnServerData": function ( sSource, aoData, fnCallback ) {
771 $.each(relatives_borrowernumbers, function( index, value ) {
772 aoData.push( { "name": "borrowernumber", "value": value } );
775 $.getJSON( sSource, aoData, function (json) {
783 if ( $("#relatives-issues-table").length ) {
784 $("#relatives-issues-table_processing").position({
785 of: $( "#relatives-issues-table" ),
790 if ( AllowRenewalLimitOverride ) {
791 $( '#override_limit' ).click( function () {
792 if ( this.checked ) {
793 $( '.renewals-allowed' ).show(); $( '.renewals-disabled' ).hide();
795 $( '.renewals-allowed' ).hide(); $( '.renewals-disabled' ).show();
797 } ).prop('checked', false);