3 $(document).ready(function() {
4 $.ajaxSetup ({ cache: false });
6 var barcodefield = $("#barcode");
8 var onHoldDueDateSet = false;
10 var onHoldChecked = function() {
11 var isChecked = false;
12 $('input[data-on-reserve]').each(function() {
13 if ($(this).is(':checked')) {
20 var showHideOnHoldRenewal = function() {
21 // Display the date input
22 if (onHoldChecked()) {
23 $('#newonholdduedate').show()
25 $('#newonholdduedate').hide();
29 // Handle the select all/none links for checkouts table columns
30 $("#CheckAllRenewals").on("click",function(){
31 $("#UncheckAllCheckins").click();
32 $(".renew:visible").prop("checked", true);
33 showHideOnHoldRenewal();
36 $("#UncheckAllRenewals").on("click",function(){
37 $(".renew:visible").prop("checked", false);
38 showHideOnHoldRenewal();
42 $("#CheckAllCheckins").on("click",function(){
43 $("#UncheckAllRenewals").click();
44 $(".checkin:visible").prop("checked", true);
47 $("#UncheckAllCheckins").on("click",function(){
48 $(".checkin:visible").prop("checked", false);
52 $("#newduedate").on("change", function() {
53 if (!onHoldDueDateSet) {
54 $('#newonholdduedate input').val($('#newduedate').val());
58 $("#newonholdduedate").on("change", function() {
59 onHoldDueDateSet = true;
62 // Don't allow both return and renew checkboxes to be checked
63 $(document).on("change", '.renew', function(){
64 if ( $(this).is(":checked") ) {
65 $( "#checkin_" + $(this).val() ).prop("checked", false);
68 $(document).on("change", '.checkin', function(){
69 if ( $(this).is(":checked") ) {
70 $( "#renew_" + $(this).val() ).prop("checked", false);
74 // Display on hold due dates input when an on hold item is
76 $(document).on('change', '.renew', function(){
77 showHideOnHoldRenewal();
80 $("#output_format > option:first-child").attr("selected", "selected");
81 $("select[name='csv_profile_id']").hide();
82 $(document).on("change", '#issues-table-output-format', function(){
83 if ( $(this).val() == 'csv' ) {
84 $("select[name='csv_profile_id']").show();
86 $("select[name='csv_profile_id']").hide();
90 // Clicking the table cell checks the checkbox inside it
91 $(document).on("click", 'td', function(e){
92 if(e.target.tagName.toLowerCase() == 'td'){
93 $(this).find("input:checkbox:visible").each( function() {
99 // Handle renewals and returns
100 $("#RenewCheckinChecked").on("click",function(){
101 $(".checkin:checked:visible").each(function() {
102 itemnumber = $(this).val();
104 $(this).replaceWith("<img id='checkin_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
107 itemnumber: itemnumber,
108 borrowernumber: borrowernumber,
109 branchcode: branchcode,
110 exempt_fine: $("#exemptfine").is(':checked')
114 url: "/cgi-bin/koha/svc/checkin",
116 success: function( data ) {
117 id = "#checkin_" + data.itemnumber;
120 if ( data.returned ) {
121 content = __("Checked in");
122 $(id).parent().parent().addClass('ok');
123 $('#date_due_' + data.itemnumber).html( __("Checked in") );
124 if ( data.patronnote != null ) {
125 $('.patron_note_' + data.itemnumber).html( __("Patron note") + ": " + data.patronnote);
128 content = __("Unable to check in");
129 $(id).parent().parent().addClass('warn');
132 $(id).replaceWith( content );
139 $(".confirm:checked:visible").each(function() {
140 itemnumber = $(this).val();
141 id = "#checkin_" + itemnumber;
142 materials = $(this).data('materials');
144 $(this).replaceWith("<span class='confirm' id='checkin_" + itemnumber + "'>" + __("Confirm") + " (<span>" + materials + "</span>): <input type='checkbox' class='checkin' name='checkin' value='" + itemnumber +"'></input></span>");
145 $(id).parent().parent().addClass('warn');
148 $(".renew:checked:visible").each(function() {
149 var override_limit = $("#override_limit").is(':checked') ? 1 : 0;
151 var isOnReserve = $(this).data().hasOwnProperty('onReserve');
153 var itemnumber = $(this).val();
155 $(this).parent().parent().replaceWith("<img id='renew_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
158 itemnumber: itemnumber,
159 borrowernumber: borrowernumber,
160 branchcode: branchcode,
161 override_limit: override_limit
164 if (UnseenRenewals) {
165 var ren = $("#renew_as_unseen_checkbox");
166 var renew_unseen = ren.length > 0 && ren.is(':checked') ? 1 : 0;
167 params.seen = renew_unseen === 1 ? 0 : 1;
170 // Determine which due date we need to use
171 var dueDate = isOnReserve ?
172 $("#newonholdduedate input").val() :
173 $("#newduedate").val();
175 if (dueDate && dueDate.length > 0) {
176 params.date_due = dueDate
180 url: "/cgi-bin/koha/svc/renew",
182 success: function( data ) {
183 var id = "#renew_" + data.itemnumber;
186 if ( data.renew_okay ) {
187 content = __("Renewed, due:") + " " + data.date_due;
188 $('#date_due_' + data.itemnumber).replaceWith( data.date_due );
190 content = __("Renew failed:") + " ";
191 if ( data.error == "no_checkout" ) {
192 content += __("not checked out");
193 } else if ( data.error == "too_many" ) {
194 content += __("too many renewals");
195 } else if ( data.error == "too_unseen" ) {
196 content += __("too many consecutive renewals without being seen by the library");
197 } else if ( data.error == "on_reserve" ) {
198 content += __("on hold");
199 } else if ( data.error == "restriction" ) {
200 content += __("Not allowed: patron restricted");
201 } else if ( data.error == "overdue" ) {
202 content += __("Not allowed: overdue");
203 } else if ( data.error ) {
204 content += data.error;
206 content += __("reason unknown");
210 $(id).replaceWith( content );
217 // Refocus on barcode field if it exists
218 if ( $("#barcode").length ) {
219 $("#barcode").focus();
222 // Prevent form submit
226 $("#RenewAll").on("click",function(){
227 $("#CheckAllRenewals").click();
228 $("#UncheckAllCheckins").click();
229 showHideOnHoldRenewal();
230 $("#RenewCheckinChecked").click();
232 // Prevent form submit
236 var ymd = flatpickr.formatDate(new Date(), "Y-m-d");
238 $('#issues-table').hide();
239 $('#issues-table-actions').hide();
240 $('#issues-table-load-immediately').change(function(){
241 if ( this.checked && typeof issuesTable === 'undefined') {
242 $('#issues-table-load-now-button').click();
244 barcodefield.focus();
246 $('#issues-table-load-now-button').click(function(){
248 barcodefield.focus();
252 $('#RenewCheckinChecked').on('click', function(){
253 RefreshIssuesTable();
256 if ( Cookies.get("issues-table-load-immediately-" + script) == "true" ) {
258 $('#issues-table-load-immediately').prop('checked', true);
260 $('#issues-table-load-immediately').on( "change", function(){
261 Cookies.set("issues-table-load-immediately-" + script, $(this).is(':checked'), { expires: 365 });
264 function RefreshIssuesTable() {
265 var table = $('#issues-table').DataTable();
269 function LoadIssuesTable() {
270 $('#issues-table-loading-message').hide();
271 $('#issues-table').show();
272 $('#issues-table-actions').show();
274 var msg_loading = __('Loading... you may continue scanning.');
275 issuesTable = KohaTable("issues-table", {
277 "sEmptyTable" : msg_loading,
278 "sProcessing": msg_loading,
281 "dom": 'B<"clearfix">rt',
284 "mDataProp": function( oObj ) {
285 return oObj.sort_order;
289 "mDataProp": function( oObj ) {
290 if ( oObj.issued_today ) {
291 return "<strong>" + __("Today's checkouts") + "</strong>";
293 return "<strong>" + __("Previous checkouts") + "</strong>";
298 "mDataProp": "date_due",
302 "iDataSort": 2, // Sort on hidden unformatted date due column
303 "mDataProp": function( oObj ) {
304 var due = oObj.date_due_formatted;
305 if ( oObj.date_due_overdue ) {
306 due = "<span class='overdue'>" + due + "</span>";
309 due = "<span id='date_due_" + oObj.itemnumber + "' class='date_due'>" + due + "</span>";
311 if ( oObj.lost && oObj.claims_returned ) {
312 due += "<span class='lost claims_returned'>" + oObj.lost.escapeHtml() + "</span>";
313 } else if ( oObj.lost ) {
314 due += "<span class='lost'>" + oObj.lost.escapeHtml() + "</span>";
317 if ( oObj.damaged ) {
318 due += "<span class='dmg'>" + oObj.damaged.escapeHtml() + "</span>";
321 var patron_note = " <span class='patron_note_" + oObj.itemnumber + "'></span>";
322 due +="<br>" + patron_note;
328 "mDataProp": function ( oObj ) {
329 let title = "<span id='title_" + oObj.itemnumber + "' class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
332 + (oObj.title ? oObj.title.escapeHtml() : '' );
334 $.each(oObj.subtitle, function( index, value ) {
335 title += " " + value.escapeHtml();
338 title += " " + oObj.part_number + " " + oObj.part_name;
340 if ( oObj.enumchron ) {
341 title += " (" + oObj.enumchron.escapeHtml() + ")";
344 title += "</a></span>";
347 title += " " + __("by _AUTHOR_").replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
350 if ( oObj.itemnotes ) {
351 var span_class = "text-muted";
352 if ( flatpickr.formatDate( new Date(oObj.issuedate), "Y-m-d" ) == ymd ){
353 span_class = "circ-hlt";
355 title += " - <span class='" + span_class + " item-note-public'>" + oObj.itemnotes.escapeHtml() + "</span>";
358 if ( oObj.itemnotes_nonpublic ) {
359 var span_class = "text-danger";
360 if ( flatpickr.formatDate( new Date(oObj.issuedate), "Y-m-d" ) == ymd ){
361 span_class = "circ-hlt";
363 title += " - <span class='" + span_class + " item-note-nonpublic'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>";
366 var onsite_checkout = '';
367 if ( oObj.onsite_checkout == 1 ) {
368 onsite_checkout += " <span class='onsite_checkout'>(" + __("On-site checkout") + ")</span>";
372 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
379 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
388 "mDataProp": function ( oObj ) {
389 return oObj.recordtype_description.escapeHtml();
393 "mDataProp": function ( oObj ) {
394 return oObj.itemtype_description.escapeHtml();
398 "mDataProp": function ( oObj ) {
399 return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
403 "mDataProp": function ( oObj ) {
404 return ( oObj.location ? oObj.location.escapeHtml() : '' );
408 "mDataProp": function ( oObj ) {
409 return (oObj.homebranch ? oObj.homebranch.escapeHtml() : '' );
413 "mDataProp": "issuedate",
417 "iDataSort": 10, // Sort on hidden unformatted issuedate column
418 "mDataProp": "issuedate_formatted",
421 "mDataProp": function ( oObj ) {
422 return (oObj.branchname ? oObj.branchname.escapeHtml() : '' );
426 "mDataProp": function ( oObj ) {
427 return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
431 "mDataProp": function ( oObj ) {
432 return ( oObj.copynumber ? oObj.copynumber.escapeHtml() : '' );
436 "mDataProp": function ( oObj ) {
437 if ( ! oObj.charge ) oObj.charge = 0;
438 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.charge).toFixed(2) + '<span>';
442 "mDataProp": function ( oObj ) {
443 if ( ! oObj.fine ) oObj.fine = 0;
444 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.fine).toFixed(2) + '<span>';
448 "mDataProp": function ( oObj ) {
449 if ( ! oObj.price ) oObj.price = 0;
450 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.price).toFixed(2) + '<span>';
455 "bVisible": AllowCirculate ? true : false,
456 "mDataProp": function ( oObj ) {
462 if ( oObj.can_renew ) {
464 } else if ( oObj.can_renew_error == "on_reserve" ) {
466 +"<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + __("On hold") + "</a>"
469 span_style = "display: none";
470 span_class = "renewals-allowed-on_reserve";
471 } else if ( oObj.can_renew_error == "too_many" ) {
472 msg += "<span class='renewals-disabled'>"
473 + __("Not renewable")
476 span_style = "display: none";
477 span_class = "renewals-allowed";
478 } else if ( oObj.can_renew_error == "too_unseen" ) {
480 + __("Must be renewed at the library")
482 span_class = "renewals-allowed";
483 } else if ( oObj.can_renew_error == "restriction" ) {
484 msg += "<span class='renewals-disabled'>"
485 + __("Not allowed: patron restricted")
488 span_style = "display: none";
489 span_class = "renewals-allowed";
490 } else if ( oObj.can_renew_error == "overdue" ) {
491 msg += "<span class='renewals-disabled'>"
492 + __("Not allowed: overdue")
495 span_style = "display: none";
496 span_class = "renewals-allowed";
497 } else if ( oObj.can_renew_error == "too_soon" ) {
498 msg += "<span class='renewals-disabled'>"
499 + __("No renewal before %s").format(oObj.can_renew_date)
502 span_style = "display: none";
503 span_class = "renewals-allowed";
504 } else if ( oObj.can_renew_error == "auto_too_soon" ) {
505 msg += "<span class='renewals-disabled'>"
506 + __("Scheduled for automatic renewal")
509 span_style = "display: none";
510 span_class = "renewals-allowed";
511 } else if ( oObj.can_renew_error == "auto_too_late" ) {
512 msg += "<span class='renewals-disabled'>"
513 + __("Can no longer be auto-renewed - number of checkout days exceeded")
516 span_style = "display: none";
517 span_class = "renewals-allowed";
518 } else if ( oObj.can_renew_error == "auto_too_much_oweing" ) {
519 msg += "<span class='renewals-disabled'>"
520 + __("Automatic renewal failed, patron has unpaid fines")
523 span_style = "display: none";
524 span_class = "renewals-allowed";
525 } else if ( oObj.can_renew_error == "auto_account_expired" ) {
526 msg += "<span class='renewals-disabled'>"
527 + __("Automatic renewal failed, account expired")
530 span_style = "display: none";
531 span_class = "renewals-allowed";
532 } else if ( oObj.can_renew_error == "auto_renew" ) {
533 msg += "<span class='renewals-disabled'>"
534 + __("Scheduled for automatic renewal")
537 span_style = "display: none";
538 span_class = "renewals-allowed";
539 } else if ( oObj.can_renew_error == "onsite_checkout" ) {
540 // Don't display something if it's an onsite checkout
541 } else if ( oObj.can_renew_error == "item_denied_renewal" ) {
542 content += "<span class='renewals-disabled'>"
543 + __("Renewal denied by syspref")
546 span_style = "display: none";
547 span_class = "renewals-allowed";
549 msg += "<span class='renewals-disabled'>"
550 + oObj.can_renew_error
553 span_style = "display: none";
554 span_class = "renewals-allowed";
557 var can_force_renew = ( oObj.onsite_checkout == 0 ) &&
558 ( oObj.can_renew_error != "on_reserve" || (oObj.can_renew_error == "on_reserve" && AllowRenewalOnHoldOverride))
560 var can_renew = ( oObj.renewals_remaining > 0 && ( !oObj.can_renew_error || oObj.can_renew_error == "too_unseen" ));
562 if ( can_renew || can_force_renew ) {
563 content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
564 content += "<span class='" + span_class + "' style='" + span_style + "'>"
565 + "<input type='checkbox' ";
566 if ( oObj.date_due_overdue && can_renew ) {
567 content += "checked='checked' ";
569 if (oObj.can_renew_error == "on_reserve") {
570 content += "data-on-reserve ";
572 content += "class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
576 if ( can_renew || can_force_renew ) {
577 content += "<span class='renewals'>(";
578 content += __("%s of %s renewals remaining").format(oObj.renewals_remaining, oObj.renewals_allowed);
579 if (UnseenRenewals && oObj.unseen_allowed) {
580 content += __(" and %s of %s unseen renewals remaining").format(oObj.unseen_remaining, oObj.unseen_allowed);
582 content += ")</span>";
590 "bVisible": AllowCirculate ? true : false,
591 "mDataProp": function ( oObj ) {
592 if ( oObj.can_renew_error == "on_reserve" ) {
593 return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + __("On hold") + "</a>";
594 } else if ( oObj.materials ) {
595 return "<input type='checkbox' class='confirm' id='confirm_" + oObj.itemnumber + "' name='confirm' value='" + oObj.itemnumber + "' data-materials='" + oObj.materials.escapeHtml() + "'></input>";
597 return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
602 "bVisible": ClaimReturnedLostValue ? true : false,
604 "mDataProp": function ( oObj ) {
607 if ( oObj.return_claim_id ) {
608 content = '<span class="badge">' + oObj.return_claim_created_on_formatted + '</span>';
609 } else if ( ClaimReturnedLostValue ) {
610 content = '<a class="btn btn-default btn-xs claim-returned-btn" data-itemnumber="' + oObj.itemnumber + '"><i class="fa fa-exclamation-circle"></i> ' + __("Claim returned") + '</a>';
612 content = '<a class="btn btn-default btn-xs" disabled="disabled" title="ClaimReturnedLostValue is not set, this feature is disabled"><i class="fa fa-exclamation-circle"></i> ' + __("Claim returned") + '</a>';
618 "bVisible": exports_enabled == 1 ? true : false,
620 "mDataProp": function ( oObj ) {
621 var s = "<input type='checkbox' name='itemnumbers' value='" + oObj.itemnumber + "' style='visibility:hidden;' />";
623 s += "<input type='checkbox' class='export' id='export_" + oObj.biblionumber + "' name='biblionumbers' value='" + oObj.biblionumber + "' />";
628 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
629 var total_charge = 0;
632 for ( var i=0; i < aaData.length; i++ ) {
633 total_charge += aaData[i]['charge'] * 1;
634 total_fine += aaData[i]['fine'] * 1;
635 total_price += aaData[i]['price'] * 1;
637 $("#totaldue").html(total_charge.toFixed(2));
638 $("#totalfine").html(total_fine.toFixed(2));
639 $("#totalprice").html(total_price.toFixed(2));
643 "bServerSide": false,
644 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
645 "fnServerData": function ( sSource, aoData, fnCallback ) {
646 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
648 $.getJSON( sSource, aoData, function (json) {
653 "dataSrc": "issued_today",
654 "startRender": function ( rows, group ) {
656 return __("Today's checkouts");
658 return __("Previous checkouts");
662 "fnInitComplete": function(oSettings, json) {
663 // Build a summary of checkouts grouped by itemtype
664 var checkoutsByItype = json.aaData.reduce(function (obj, row) {
665 obj[row.type_for_stat] = (obj[row.type_for_stat] || 0) + 1;
669 Object.keys(checkoutsByItype).sort().forEach(function (itype) {
671 .append($('<strong>').html(itype || __("No itemtype")))
672 .append(': ' + checkoutsByItype[itype]);
676 .addClass('checkouts-by-itemtype')
677 .append($('<summary>').html( __("Number of checkouts by item type") ))
679 .insertBefore(oSettings.nTableWrapper)
681 }, columns_settings_issues_table);
683 if ( $("#issues-table").length ) {
684 $("#issues-table_processing").position({
685 of: $( "#issues-table" ),
691 // Don't load relatives' issues table unless it is clicked on
692 var relativesIssuesTable;
693 $("#relatives-issues-tab").click( function() {
694 if ( ! relativesIssuesTable ) {
695 relativesIssuesTable = $("#relatives-issues-table").dataTable($.extend(true, {}, dataTablesDefaults, {
701 "mDataProp": "date_due",
705 "iDataSort": 0, // Sort on hidden unformatted date due column
706 "mDataProp": function( oObj ) {
707 var today = new Date();
708 var due = new Date( oObj.date_due );
710 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
712 return oObj.date_due_formatted;
717 "mDataProp": function ( oObj ) {
718 let title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
721 + (oObj.title ? oObj.title.escapeHtml() : '' );
723 $.each(oObj.subtitle, function( index, value ) {
724 title += " " + value.escapeHtml();
727 title += " " + oObj.part_number + " " + oObj.part_name;
729 if ( oObj.enumchron ) {
730 title += " (" + oObj.enumchron.escapeHtml() + ")";
733 title += "</a></span>";
736 title += " " + __("by _AUTHOR_").replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
739 if ( oObj.itemnotes ) {
741 if ( flatpickr.formatDate( new Date(oObj.issuedate), "Y-m-d" ) == ymd ){
742 span_class = "circ-hlt";
744 title += " - <span class='" + span_class + "'>" + oObj.itemnotes.escapeHtml() + "</span>"
747 if ( oObj.itemnotes_nonpublic ) {
749 if ( flatpickr.formatDate( new Date(oObj.issuedate), "Y-m-d" ) == ymd ){
750 span_class = "circ-hlt";
752 title += " - <span class='" + span_class + "'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>"
755 var onsite_checkout = '';
756 if ( oObj.onsite_checkout == 1 ) {
757 onsite_checkout += " <span class='onsite_checkout'>(" + __("On-site checkout") + ")</span>";
761 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
768 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
777 "mDataProp": function ( oObj ) {
778 return oObj.recordtype_description.escapeHtml();
782 "mDataProp": function ( oObj ) {
783 return oObj.itemtype_description.escapeHtml();
787 "mDataProp": function ( oObj ) {
788 return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
792 "mDataProp": function ( oObj ) {
793 return ( oObj.location ? oObj.location.escapeHtml() : '' );
797 "mDataProp": "issuedate",
801 "iDataSort": 7, // Sort on hidden unformatted issuedate column
802 "mDataProp": "issuedate_formatted",
805 "mDataProp": function ( oObj ) {
806 return ( oObj.branchname ? oObj.branchname.escapeHtml() : '' );
810 "mDataProp": function ( oObj ) {
811 return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
815 "mDataProp": function ( oObj ) {
816 return ( oObj.copynumber ? oObj.copynumber.escapeHtml() : '' );
820 "mDataProp": function ( oObj ) {
821 if ( ! oObj.charge ) oObj.charge = 0;
822 return parseFloat(oObj.charge).toFixed(2);
826 "mDataProp": function ( oObj ) {
827 if ( ! oObj.fine ) oObj.fine = 0;
828 return parseFloat(oObj.fine).toFixed(2);
832 "mDataProp": function ( oObj ) {
833 if ( ! oObj.price ) oObj.price = 0;
834 return parseFloat(oObj.price).toFixed(2);
838 "mDataProp": function( oObj ) {
839 return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
840 + ( oObj.borrower.firstname ? oObj.borrower.firstname.escapeHtml() : "" )
842 ( oObj.borrower.surname ? oObj.borrower.surname.escapeHtml() : "" )
843 + " (" + ( oObj.borrower.cardnumber ? oObj.borrower.cardnumber.escapeHtml() : "" ) + ")</a>"
849 "bServerSide": false,
850 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
851 "fnServerData": function ( sSource, aoData, fnCallback ) {
852 $.each(relatives_borrowernumbers, function( index, value ) {
853 aoData.push( { "name": "borrowernumber", "value": value } );
856 $.getJSON( sSource, aoData, function (json) {
864 if ( $("#relatives-issues-table").length ) {
865 $("#relatives-issues-table_processing").position({
866 of: $( "#relatives-issues-table" ),
871 if ( AllowRenewalLimitOverride || AllowRenewalOnHoldOverride ) {
872 $( '#override_limit' ).click( function () {
873 if ( this.checked ) {
874 if ( AllowRenewalLimitOverride ) {
875 $( '.renewals-allowed' ).show();
876 $( '.renewals-disabled' ).hide();
878 if ( AllowRenewalOnHoldOverride ) {
879 $( '.renewals-allowed-on_reserve' ).show();
882 $( '.renewals-allowed' ).hide();
883 $( '.renewals-allowed-on_reserve' ).hide();
884 $( '.renewals-disabled' ).show();
886 } ).prop('checked', false);
889 // Handle return claims
890 $(document).on("click", '.claim-returned-btn', function(e){
892 itemnumber = $(this).data('itemnumber');
894 $('#claims-returned-itemnumber').val(itemnumber);
895 $('#claims-returned-notes').val("");
896 $('#claims-returned-charge-lost-fee').attr('checked', false)
897 $('#claims-returned-modal').modal()
899 $(document).on("click", '#claims-returned-modal-btn-submit', function(e){
900 let itemnumber = $('#claims-returned-itemnumber').val();
901 let notes = $('#claims-returned-notes').val();
902 let fee = $('#claims-returned-charge-lost-fee').attr('checked') ? true : false;
904 $('#claims-returned-modal').modal('hide')
906 $('.claim-returned-btn[data-itemnumber="' + itemnumber + '"]').replaceWith('<img id="return_claim_spinner_' + itemnumber + ' src=' + interface + '/' + theme + '/img/spinner-small.gif />');
911 charge_lost_fee: fee,
912 created_by: logged_in_user_borrowernumber,
915 $.post( '/api/v1/return_claims', JSON.stringify(params), function( data ) {
917 id = "#return_claim_spinner_" + data.item_id;
919 let created_on = new Date(data.created_on);
922 if ( data.claim_id ) {
923 content = '<span class="badge">' + created_on.toLocaleDateString() + '</span>';
924 $(id).parent().parent().addClass('ok');
926 content = __("Unable to claim as returned");
927 $(id).parent().parent().addClass('warn');
930 $(id).replaceWith( content );
932 refreshReturnClaimsTable();
933 issuesTable.api().ajax.reload();
939 // Don't load return claims table unless it is clicked on
940 var returnClaimsTable;
941 $("#return-claims-tab").click( function() {
942 refreshReturnClaimsTable();
945 function refreshReturnClaimsTable(){
946 loadReturnClaimsTable();
947 $("#return-claims-table").DataTable().ajax.reload();
949 function loadReturnClaimsTable() {
950 if ( ! returnClaimsTable ) {
951 returnClaimsTable = $("#return-claims-table").dataTable({
956 { "bSortable": false, "bSearchable": false, 'aTargets': ['NoSort'] },
957 { "sType": "anti-the", "aTargets": ["anti-the"] },
965 "mDataProp": function (oObj) {
966 if (oObj.resolution) {
967 return "is_resolved";
969 return "is_unresolved";
975 "mDataProp": function ( oObj ) {
976 let title = '<a class="return-claim-title strong" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + oObj.biblionumber + '">'
978 + ( oObj.subtitle ? " " + oObj.subtitle : "" )
979 + ( oObj.enumchron || "" )
982 title += ' by ' + oObj.author;
984 title += ' <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber='
989 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
996 "sClass": "return-claim-notes-td",
997 "mDataProp": function ( oObj ) {
998 let notes = '<span id="return-claim-notes-static-' + oObj.id + '" class="return-claim-notes" data-return-claim-id="' + oObj.id + '">';
1000 notes += oObj.notes;
1003 notes += '<i style="float:right" class="fa fa-pencil-square-o" title="' + __("Double click to edit") + '"></i>';
1008 "mDataProp": function ( oObj ) {
1009 let created_on = new Date( oObj.created_on );
1010 return created_on.toLocaleDateString();
1014 "mDataProp": function ( oObj ) {
1015 if ( oObj.updated_on ) {
1016 let updated_on = new Date( oObj.updated_on );
1017 return updated_on.toLocaleDateString();
1024 "mDataProp": function ( oObj ) {
1025 if ( ! oObj.resolution ) return "";
1027 let desc = '<strong>' + oObj.resolution_data.lib + '</strong> <i>(';
1028 if (oObj.resolved_by_data) desc += '<a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=' + oObj.resolved_by_data.borrowernumber + '">' + ( oObj.resolved_by_data.firstname || "" ) + " " + ( oObj.resolved_by_data.surname || "" ) + '</a>';
1029 desc += ', ' + oObj.resolved_on + ')</i>';
1034 "mDataProp": function ( oObj ) {
1035 let delete_html = oObj.resolved_on
1036 ? '<li><a href="#" class="return-claim-tools-delete" data-return-claim-id="' + oObj.id + '"><i class="fa fa-trash"></i> ' + __("Delete") + '</a></li>'
1038 let resolve_html = ! oObj.resolution
1039 ? '<li><a href="#" class="return-claim-tools-resolve" data-return-claim-id="' + oObj.id + '" data-current-lost-status="' + escape_str(oObj.itemlost) + '"><i class="fa fa-check-square"></i> ' + __("Resolve") + '</a></li>'
1042 return '<div class="btn-group">'
1043 + ' <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
1044 + __("Actions") + ' <span class="caret"></span>'
1046 + ' <ul class="dropdown-menu">'
1047 + ' <li><a href="#" class="return-claim-tools-editnotes" data-return-claim-id="' + oObj.id + '"><i class="fa fa-edit"></i> ' + __("Edit notes") + '</a></li>'
1056 "bProcessing": true,
1057 "bServerSide": false,
1058 "sAjaxSource": '/cgi-bin/koha/svc/return_claims',
1059 "fnServerData": function ( sSource, aoData, fnCallback ) {
1060 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
1062 $.getJSON( sSource, aoData, function (json) {
1063 let resolved = json.resolved;
1064 let unresolved = json.unresolved;
1066 if ( resolved > 0 ) {
1067 $('#return-claims-count-resolved').text(resolved)
1068 .removeClass('label-default')
1069 .addClass('label-success');
1071 $('#return-claims-count-resolved').text(resolved)
1072 .removeClass('label-success')
1073 .addClass('label-default');
1075 if ( unresolved > 0 ) {
1076 $('#return-claims-count-unresolved').text(unresolved)
1077 .removeClass('label-default')
1078 .addClass('label-warning');
1080 $('#return-claims-count-unresolved').text(unresolved)
1081 .removeClass('label-warning')
1082 .addClass('label-default');
1088 "search": { "search": "is_unresolved" },
1089 "footerCallback": function (row, data, start, end, display) {
1090 var api = this.api();
1091 // Total over all pages
1092 var colData = api.column(1).data();
1093 var is_unresolved = 0;
1094 var is_resolved = 0;
1095 colData.each(function( index, value ){
1096 if( index == "is_unresolved" ){ is_unresolved++; }
1097 if (index == "is_resolved") { is_resolved++; }
1100 $("#return-claims-controls").html( showClaimFilter( is_unresolved, is_resolved ) )
1106 function showClaimFilter( is_unresolved, is_resolved ){
1107 var showAll, showUnresolved;
1108 var total = Number( is_unresolved ) + Number( is_resolved );
1110 showAll = __nx("Show 1 claim", "Show all {count} claims", total, { count: total });
1114 if( is_unresolved > 0 ){
1115 showUnresolved = __nx("Show 1 unresolved claim", "Show {count} unresolved claims", is_unresolved, { count: is_unresolved })
1117 showUnresolved = "";
1119 $("#show_all_claims").html( showAll );
1120 $("#show_unresolved_claims").html( showUnresolved );
1123 $('body').on('click', '.return-claim-tools-editnotes', function() {
1124 let id = $(this).data('return-claim-id');
1125 $('#return-claim-notes-static-' + id).parent().dblclick();
1127 $('body').on('dblclick', '.return-claim-notes-td', function() {
1128 let elt = $(this).children('.return-claim-notes');
1129 let id = elt.data('return-claim-id');
1130 if ( $('#return-claim-notes-editor-textarea-' + id).length == 0 ) {
1131 let note = elt.text();
1133 ' <span id="return-claim-notes-editor-' + id + '">'
1134 + ' <textarea id="return-claim-notes-editor-textarea-' + id + '">' + note + '</textarea>'
1136 + ' <a class="btn btn-default btn-xs claim-returned-notes-editor-submit" data-return-claim-id="' + id + '"><i class="fa fa-save"></i> ' + __("Update") + '</a>'
1137 + ' <a class="claim-returned-notes-editor-cancel" data-return-claim-id="' + id + '" href="#">' + __("Cancel") + '</a>'
1140 $(editor).insertAfter( elt );
1144 $('body').on('click', '.claim-returned-notes-editor-submit', function(){
1145 let id = $(this).data('return-claim-id');
1146 let notes = $('#return-claim-notes-editor-textarea-' + id).val();
1150 updated_by: logged_in_user_borrowernumber
1153 $(this).parent().remove();
1156 url: '/api/v1/return_claims/' + id + '/notes',
1158 data: JSON.stringify(params),
1159 success: function( data ) {
1160 let notes = $('#return-claim-notes-static-' + id);
1161 notes.text(data.notes);
1168 $('body').on('click', '.claim-returned-notes-editor-cancel', function(){
1169 let id = $(this).data('return-claim-id');
1170 $(this).parent().remove();
1171 $('#return-claim-notes-static-' + id).show();
1174 // Hanld return claim deletion
1175 $('body').on('click', '.return-claim-tools-delete', function() {
1176 let confirmed = confirm(__("Are you sure you want to delete this return claim?"));
1178 let id = $(this).data('return-claim-id');
1181 url: '/api/v1/return_claims/' + id,
1183 success: function( data ) {
1184 refreshReturnClaimsTable();
1185 issuesTable.api().ajax.reload();
1191 $("#show_all_claims").on("click", function(e){
1193 $(".ctrl_link").removeClass("disabled");
1194 $(this).addClass("disabled");
1195 $("#return-claims-table").DataTable().search("").draw();
1198 $("#show_unresolved_claims").on("click", function (e) {
1200 $(".ctrl_link").removeClass("disabled");
1201 $(this).addClass("disabled");
1202 $("#return-claims-table").DataTable().search("is_unresolved").draw();