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')
113 $.post( "/cgi-bin/koha/svc/checkin", params, function( data ) {
114 id = "#checkin_" + data.itemnumber;
117 if ( data.returned ) {
118 content = __("Checked in");
119 $(id).parent().parent().addClass('ok');
120 $('#date_due_' + data.itemnumber).html( __("Checked in") );
121 if ( data.patronnote != null ) {
122 $('.patron_note_' + data.itemnumber).html( __("Patron note") + ": " + data.patronnote);
125 content = __("Unable to check in");
126 $(id).parent().parent().addClass('warn');
129 $(id).replaceWith( content );
133 $(".confirm:checked:visible").each(function() {
134 itemnumber = $(this).val();
135 id = "#checkin_" + itemnumber;
136 materials = $(this).data('materials');
138 $(this).replaceWith("<span class='confirm' id='checkin_" + itemnumber + "'>" + __("Confirm") + " (<span>" + materials + "</span>): <input type='checkbox' class='checkin' name='checkin' value='" + itemnumber +"'></input></span>");
139 $(id).parent().parent().addClass('warn');
142 $(".renew:checked:visible").each(function() {
143 var override_limit = $("#override_limit").is(':checked') ? 1 : 0;
145 var isOnReserve = $(this).data().hasOwnProperty('onReserve');
147 var itemnumber = $(this).val();
149 $(this).parent().parent().replaceWith("<img id='renew_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
152 itemnumber: itemnumber,
153 borrowernumber: borrowernumber,
154 branchcode: branchcode,
155 override_limit: override_limit
158 if (UnseenRenewals) {
159 var ren = $("#renew_as_unseen_checkbox");
160 var renew_unseen = ren.length > 0 && ren.is(':checked') ? 1 : 0;
161 params.seen = renew_unseen === 1 ? 0 : 1;
164 // Determine which due date we need to use
165 var dueDate = isOnReserve ?
166 $("#newonholdduedate input").val() :
167 $("#newduedate").val();
169 if (dueDate && dueDate.length > 0) {
170 params.date_due = dueDate
173 $.post( "/cgi-bin/koha/svc/renew", params, function( data ) {
174 var id = "#renew_" + data.itemnumber;
177 if ( data.renew_okay ) {
178 content = __("Renewed, due:") + " " + data.date_due;
179 $('#date_due_' + data.itemnumber).replaceWith( data.date_due );
181 content = __("Renew failed:") + " ";
182 if ( data.error == "no_checkout" ) {
183 content += __("not checked out");
184 } else if ( data.error == "too_many" ) {
185 content += __("too many renewals");
186 } else if ( data.error == "too_unseen" ) {
187 content += __("too many consecutive renewals without being seen by the library");
188 } else if ( data.error == "on_reserve" ) {
189 content += __("on hold");
190 } else if ( data.error == "restriction" ) {
191 content += __("Not allowed: patron restricted");
192 } else if ( data.error == "overdue" ) {
193 content += __("Not allowed: overdue");
194 } else if ( data.error ) {
195 content += data.error;
197 content += __("reason unknown");
201 $(id).replaceWith( content );
205 // Refocus on barcode field if it exists
206 if ( $("#barcode").length ) {
207 $("#barcode").focus();
210 // Prevent form submit
214 $("#RenewAll").on("click",function(){
215 $("#CheckAllRenewals").click();
216 $("#UncheckAllCheckins").click();
217 showHideOnHoldRenewal();
218 $("#RenewCheckinChecked").click();
220 // Prevent form submit
224 var ymd = $.datepicker.formatDate('yy-mm-dd', new Date());
226 $('#issues-table').hide();
227 $('#issues-table-actions').hide();
228 $('#issues-table-load-immediately').change(function(){
229 if ( this.checked && typeof issuesTable === 'undefined') {
230 $('#issues-table-load-now-button').click();
232 barcodefield.focus();
234 $('#issues-table-load-now-button').click(function(){
236 barcodefield.focus();
240 if ( Cookies.get("issues-table-load-immediately-" + script) == "true" ) {
242 $('#issues-table-load-immediately').prop('checked', true);
244 $('#issues-table-load-immediately').on( "change", function(){
245 Cookies.set("issues-table-load-immediately-" + script, $(this).is(':checked'), { expires: 365 });
248 function LoadIssuesTable() {
249 $('#issues-table-loading-message').hide();
250 $('#issues-table').show();
251 $('#issues-table-actions').show();
253 var msg_loading = __('Loading... you may continue scanning.');
254 issuesTable = KohaTable("issues-table", {
256 "sEmptyTable" : msg_loading,
257 "sProcessing": msg_loading,
260 "dom": 'B<"clearfix">rt',
263 "mDataProp": function( oObj ) {
264 return oObj.sort_order;
268 "mDataProp": function( oObj ) {
269 if ( oObj.issued_today ) {
270 return "<strong>" + __("Today's checkouts") + "</strong>";
272 return "<strong>" + __("Previous checkouts") + "</strong>";
277 "mDataProp": "date_due",
281 "iDataSort": 2, // Sort on hidden unformatted date due column
282 "mDataProp": function( oObj ) {
283 var due = oObj.date_due_formatted;
285 if ( oObj.date_due_overdue ) {
286 due = "<span class='overdue'>" + due + "</span>";
289 due = "<span id='date_due_" + oObj.itemnumber + "' class='date_due'>" + due + "</span>";
291 if ( oObj.lost && oObj.claims_returned ) {
292 due += "<span class='lost claims_returned'>" + oObj.lost.escapeHtml() + "</span>";
293 } else if ( oObj.lost ) {
294 due += "<span class='lost'>" + oObj.lost.escapeHtml() + "</span>";
297 if ( oObj.damaged ) {
298 due += "<span class='dmg'>" + oObj.damaged.escapeHtml() + "</span>";
301 var patron_note = " <span class='patron_note_" + oObj.itemnumber + "'></span>";
302 due +="<br>" + patron_note;
308 "mDataProp": function ( oObj ) {
309 let title = "<span id='title_" + oObj.itemnumber + "' class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
312 + (oObj.title ? oObj.title.escapeHtml() : '' );
314 $.each(oObj.subtitle, function( index, value ) {
315 title += " " + value.escapeHtml();
318 title += " " + oObj.part_number + " " + oObj.part_name;
320 if ( oObj.enumchron ) {
321 title += " (" + oObj.enumchron.escapeHtml() + ")";
324 title += "</a></span>";
327 title += " " + __("by _AUTHOR_").replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
330 if ( oObj.itemnotes ) {
331 var span_class = "text-muted";
332 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
333 span_class = "circ-hlt";
335 title += " - <span class='" + span_class + " item-note-public'>" + oObj.itemnotes.escapeHtml() + "</span>";
338 if ( oObj.itemnotes_nonpublic ) {
339 var span_class = "text-danger";
340 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
341 span_class = "circ-hlt";
343 title += " - <span class='" + span_class + " item-note-nonpublic'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>";
346 var onsite_checkout = '';
347 if ( oObj.onsite_checkout == 1 ) {
348 onsite_checkout += " <span class='onsite_checkout'>(" + __("On-site checkout") + ")</span>";
352 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
359 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
368 "mDataProp": function ( oObj ) {
369 return oObj.recordtype_description.escapeHtml();
373 "mDataProp": function ( oObj ) {
374 return oObj.itemtype_description.escapeHtml();
378 "mDataProp": function ( oObj ) {
379 return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
383 "mDataProp": function ( oObj ) {
384 return ( oObj.location ? oObj.location.escapeHtml() : '' );
388 "mDataProp": function ( oObj ) {
389 return (oObj.homebranch ? oObj.homebranch.escapeHtml() : '' );
393 "mDataProp": "issuedate",
397 "iDataSort": 10, // Sort on hidden unformatted issuedate column
398 "mDataProp": "issuedate_formatted",
401 "mDataProp": function ( oObj ) {
402 return (oObj.branchname ? oObj.branchname.escapeHtml() : '' );
406 "mDataProp": function ( oObj ) {
407 return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
411 "mDataProp": function ( oObj ) {
412 return ( oObj.copynumber ? oObj.copynumber.escapeHtml() : '' );
416 "mDataProp": function ( oObj ) {
417 if ( ! oObj.charge ) oObj.charge = 0;
418 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.charge).toFixed(2) + '<span>';
422 "mDataProp": function ( oObj ) {
423 if ( ! oObj.fine ) oObj.fine = 0;
424 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.fine).toFixed(2) + '<span>';
428 "mDataProp": function ( oObj ) {
429 if ( ! oObj.price ) oObj.price = 0;
430 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.price).toFixed(2) + '<span>';
435 "bVisible": AllowCirculate ? true : false,
436 "mDataProp": function ( oObj ) {
442 if ( oObj.can_renew ) {
444 } else if ( oObj.can_renew_error == "on_reserve" ) {
446 +"<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + __("On hold") + "</a>"
449 span_style = "display: none";
450 span_class = "renewals-allowed-on_reserve";
451 } else if ( oObj.can_renew_error == "too_many" ) {
452 msg += "<span class='renewals-disabled'>"
453 + __("Not renewable")
456 span_style = "display: none";
457 span_class = "renewals-allowed";
458 } else if ( oObj.can_renew_error == "too_unseen" ) {
459 msg += "<span class='renewals-disabled'>"
460 + __("Must be renewed at the library")
463 span_style = "display: none";
464 span_class = "renewals-allowed";
465 } else if ( oObj.can_renew_error == "restriction" ) {
466 msg += "<span class='renewals-disabled'>"
467 + __("Not allowed: patron restricted")
470 span_style = "display: none";
471 span_class = "renewals-allowed";
472 } else if ( oObj.can_renew_error == "overdue" ) {
473 msg += "<span class='renewals-disabled'>"
474 + __("Not allowed: overdue")
477 span_style = "display: none";
478 span_class = "renewals-allowed";
479 } else if ( oObj.can_renew_error == "too_soon" ) {
480 msg += "<span class='renewals-disabled'>"
481 + __("No renewal before %s").format(oObj.can_renew_date)
484 span_style = "display: none";
485 span_class = "renewals-allowed";
486 } else if ( oObj.can_renew_error == "auto_too_soon" ) {
487 msg += "<span class='renewals-disabled'>"
488 + __("Scheduled for automatic renewal")
491 span_style = "display: none";
492 span_class = "renewals-allowed";
493 } else if ( oObj.can_renew_error == "auto_too_late" ) {
494 msg += "<span class='renewals-disabled'>"
495 + __("Can no longer be auto-renewed - number of checkout days exceeded")
498 span_style = "display: none";
499 span_class = "renewals-allowed";
500 } else if ( oObj.can_renew_error == "auto_too_much_oweing" ) {
501 msg += "<span class='renewals-disabled'>"
502 + __("Automatic renewal failed, patron has unpaid fines")
505 span_style = "display: none";
506 span_class = "renewals-allowed";
507 } else if ( oObj.can_renew_error == "auto_account_expired" ) {
508 msg += "<span class='renewals-disabled'>"
509 + __("Automatic renewal failed, account expired")
512 span_style = "display: none";
513 span_class = "renewals-allowed";
514 } else if ( oObj.can_renew_error == "auto_renew" ) {
515 msg += "<span class='renewals-disabled'>"
516 + __("Scheduled for automatic renewal")
519 span_style = "display: none";
520 span_class = "renewals-allowed";
521 } else if ( oObj.can_renew_error == "onsite_checkout" ) {
522 // Don't display something if it's an onsite checkout
523 } else if ( oObj.can_renew_error == "item_denied_renewal" ) {
524 content += "<span class='renewals-disabled'>"
525 + __("Renewal denied by syspref")
528 span_style = "display: none";
529 span_class = "renewals-allowed";
531 msg += "<span class='renewals-disabled'>"
532 + oObj.can_renew_error
535 span_style = "display: none";
536 span_class = "renewals-allowed";
539 var can_force_renew = ( oObj.onsite_checkout == 0 ) &&
540 ( oObj.can_renew_error != "on_reserve" || (oObj.can_renew_error == "on_reserve" && AllowRenewalOnHoldOverride))
542 var can_renew = ( oObj.renewals_remaining > 0 && !oObj.can_renew_error );
544 if ( can_renew || can_force_renew ) {
545 content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
546 content += "<span class='" + span_class + "' style='" + span_style + "'>"
547 + "<input type='checkbox' ";
548 if ( oObj.date_due_overdue && can_renew ) {
549 content += "checked='checked' ";
551 if (oObj.can_renew_error == "on_reserve") {
552 content += "data-on-reserve ";
554 content += "class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
558 if ( can_renew || can_force_renew ) {
559 content += "<span class='renewals'>(";
560 content + __("%s of %s renewals remaining").format(oObj.renewals_remaining, oObj.renewals_allowed);
561 if (UnseenRenewals && oObj.unseen_allowed) {
562 content += __("%s of %s unseen renewals remaining").format(oObj.unseen_remaining, oObj.unseen_allowed);
564 content += ")</span>";
572 "bVisible": AllowCirculate ? true : false,
573 "mDataProp": function ( oObj ) {
574 if ( oObj.can_renew_error == "on_reserve" ) {
575 return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + __("On hold") + "</a>";
576 } else if ( oObj.materials ) {
577 return "<input type='checkbox' class='confirm' id='confirm_" + oObj.itemnumber + "' name='confirm' value='" + oObj.itemnumber + "' data-materials='" + oObj.materials.escapeHtml() + "'></input>";
579 return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
584 "bVisible": ClaimReturnedLostValue ? true : false,
586 "mDataProp": function ( oObj ) {
589 if ( oObj.return_claim_id ) {
590 content = '<span class="badge">' + oObj.return_claim_created_on_formatted + '</span>';
592 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>';
598 "bVisible": exports_enabled == 1 ? true : false,
600 "mDataProp": function ( oObj ) {
601 var s = "<input type='checkbox' name='itemnumbers' value='" + oObj.itemnumber + "' style='visibility:hidden;' />";
603 s += "<input type='checkbox' class='export' id='export_" + oObj.biblionumber + "' name='biblionumbers' value='" + oObj.biblionumber + "' />";
608 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
609 var total_charge = 0;
612 for ( var i=0; i < aaData.length; i++ ) {
613 total_charge += aaData[i]['charge'] * 1;
614 total_fine += aaData[i]['fine'] * 1;
615 total_price += aaData[i]['price'] * 1;
617 $("#totaldue").html(total_charge.toFixed(2));
618 $("#totalfine").html(total_fine.toFixed(2));
619 $("#totalprice").html(total_price.toFixed(2));
623 "bServerSide": false,
624 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
625 "fnServerData": function ( sSource, aoData, fnCallback ) {
626 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
628 $.getJSON( sSource, aoData, function (json) {
633 "dataSrc": "issued_today",
634 "startRender": function ( rows, group ) {
636 return __("Today's checkouts");
638 return __("Previous checkouts");
642 "fnInitComplete": function(oSettings, json) {
643 // Build a summary of checkouts grouped by itemtype
644 var checkoutsByItype = json.aaData.reduce(function (obj, row) {
645 obj[row.type_for_stat] = (obj[row.type_for_stat] || 0) + 1;
649 Object.keys(checkoutsByItype).sort().forEach(function (itype) {
651 .append($('<strong>').html(itype || __("No itemtype")))
652 .append(': ' + checkoutsByItype[itype]);
656 .addClass('checkouts-by-itemtype')
657 .append($('<summary>').html( __("Number of checkouts by item type") ))
659 .insertBefore(oSettings.nTableWrapper)
661 }, columns_settings_issues_table);
663 if ( $("#issues-table").length ) {
664 $("#issues-table_processing").position({
665 of: $( "#issues-table" ),
671 // Don't load relatives' issues table unless it is clicked on
672 var relativesIssuesTable;
673 $("#relatives-issues-tab").click( function() {
674 if ( ! relativesIssuesTable ) {
675 relativesIssuesTable = $("#relatives-issues-table").dataTable($.extend(true, {}, dataTablesDefaults, {
681 "mDataProp": "date_due",
685 "iDataSort": 0, // Sort on hidden unformatted date due column
686 "mDataProp": function( oObj ) {
687 var today = new Date();
688 var due = new Date( oObj.date_due );
690 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
692 return oObj.date_due_formatted;
697 "mDataProp": function ( oObj ) {
698 let title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
701 + (oObj.title ? oObj.title.escapeHtml() : '' );
703 $.each(oObj.subtitle, function( index, value ) {
704 title += " " + value.escapeHtml();
707 title += " " + oObj.part_number + " " + oObj.part_name;
709 if ( oObj.enumchron ) {
710 title += " (" + oObj.enumchron.escapeHtml() + ")";
713 title += "</a></span>";
716 title += " " + __("by _AUTHOR_").replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
719 if ( oObj.itemnotes ) {
721 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
722 span_class = "circ-hlt";
724 title += " - <span class='" + span_class + "'>" + oObj.itemnotes.escapeHtml() + "</span>"
727 if ( oObj.itemnotes_nonpublic ) {
729 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
730 span_class = "circ-hlt";
732 title += " - <span class='" + span_class + "'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>"
735 var onsite_checkout = '';
736 if ( oObj.onsite_checkout == 1 ) {
737 onsite_checkout += " <span class='onsite_checkout'>(" + __("On-site checkout") + ")</span>";
741 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
748 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
757 "mDataProp": function ( oObj ) {
758 return oObj.recordtype_description.escapeHtml();
762 "mDataProp": function ( oObj ) {
763 return oObj.itemtype_description.escapeHtml();
767 "mDataProp": function ( oObj ) {
768 return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
772 "mDataProp": function ( oObj ) {
773 return ( oObj.location ? oObj.location.escapeHtml() : '' );
777 "mDataProp": "issuedate",
781 "iDataSort": 7, // Sort on hidden unformatted issuedate column
782 "mDataProp": "issuedate_formatted",
785 "mDataProp": function ( oObj ) {
786 return ( oObj.branchname ? oObj.branchname.escapeHtml() : '' );
790 "mDataProp": function ( oObj ) {
791 return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
795 "mDataProp": function ( oObj ) {
796 return ( oObj.copynumber ? oObj.copynumber.escapeHtml() : '' );
800 "mDataProp": function ( oObj ) {
801 if ( ! oObj.charge ) oObj.charge = 0;
802 return parseFloat(oObj.charge).toFixed(2);
806 "mDataProp": function ( oObj ) {
807 if ( ! oObj.fine ) oObj.fine = 0;
808 return parseFloat(oObj.fine).toFixed(2);
812 "mDataProp": function ( oObj ) {
813 if ( ! oObj.price ) oObj.price = 0;
814 return parseFloat(oObj.price).toFixed(2);
818 "mDataProp": function( oObj ) {
819 return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
820 + oObj.borrower.firstname.escapeHtml()
822 oObj.borrower.surname.escapeHtml()
823 + " (" + oObj.borrower.cardnumber.escapeHtml() + ")</a>"
829 "bServerSide": false,
830 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
831 "fnServerData": function ( sSource, aoData, fnCallback ) {
832 $.each(relatives_borrowernumbers, function( index, value ) {
833 aoData.push( { "name": "borrowernumber", "value": value } );
836 $.getJSON( sSource, aoData, function (json) {
844 if ( $("#relatives-issues-table").length ) {
845 $("#relatives-issues-table_processing").position({
846 of: $( "#relatives-issues-table" ),
851 if ( AllowRenewalLimitOverride || AllowRenewalOnHoldOverride ) {
852 $( '#override_limit' ).click( function () {
853 if ( this.checked ) {
854 if ( AllowRenewalLimitOverride ) {
855 $( '.renewals-allowed' ).show();
856 $( '.renewals-disabled' ).hide();
858 if ( AllowRenewalOnHoldOverride ) {
859 $( '.renewals-allowed-on_reserve' ).show();
862 $( '.renewals-allowed' ).hide();
863 $( '.renewals-allowed-on_reserve' ).hide();
864 $( '.renewals-disabled' ).show();
866 } ).prop('checked', false);
869 // Handle return claims
870 $(document).on("click", '.claim-returned-btn', function(e){
872 itemnumber = $(this).data('itemnumber');
874 $('#claims-returned-itemnumber').val(itemnumber);
875 $('#claims-returned-notes').val("");
876 $('#claims-returned-charge-lost-fee').attr('checked', false)
877 $('#claims-returned-modal').modal()
879 $(document).on("click", '#claims-returned-modal-btn-submit', function(e){
880 let itemnumber = $('#claims-returned-itemnumber').val();
881 let notes = $('#claims-returned-notes').val();
882 let fee = $('#claims-returned-charge-lost-fee').attr('checked') ? true : false;
884 $('#claims-returned-modal').modal('hide')
886 $('.claim-returned-btn[data-itemnumber="' + itemnumber + '"]').replaceWith('<img id="return_claim_spinner_' + itemnumber + ' src=' + interface + '/' + theme + '/img/spinner-small.gif />');
891 charge_lost_fee: fee,
892 created_by: logged_in_user_borrowernumber,
895 $.post( '/api/v1/return_claims', JSON.stringify(params), function( data ) {
897 id = "#return_claim_spinner_" + data.item_id;
899 let created_on = new Date(data.created_on);
902 if ( data.claim_id ) {
903 content = '<span class="badge">' + created_on.toLocaleDateString() + '</span>';
904 $(id).parent().parent().addClass('ok');
906 content = __("Unable to claim as returned");
907 $(id).parent().parent().addClass('warn');
910 $(id).replaceWith( content );
912 refreshReturnClaimsTable();
913 issuesTable.api().ajax.reload();
919 // Don't load return claims table unless it is clicked on
920 var returnClaimsTable;
921 $("#return-claims-tab").click( function() {
922 refreshReturnClaimsTable();
925 function refreshReturnClaimsTable(){
926 loadReturnClaimsTable();
927 $("#return-claims-table").DataTable().ajax.reload();
929 function loadReturnClaimsTable() {
930 if ( ! returnClaimsTable ) {
931 returnClaimsTable = $("#return-claims-table").dataTable({
941 "mDataProp": function ( oObj ) {
942 let title = '<a class="return-claim-title strong" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + oObj.biblionumber + '">'
944 + ( oObj.enumchron || "" )
947 title += ' by ' + oObj.author;
949 title += ' <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber='
954 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
961 "sClass": "return-claim-notes-td",
962 "mDataProp": function ( oObj ) {
963 return '<span id="return-claim-notes-static-' + oObj.id + '" class="return-claim-notes" data-return-claim-id="' + oObj.id + '">' + oObj.notes + '</span>'
964 + '<i style="float:right" class="fa fa-pencil-square-o" title="' + __("Double click to edit") + '"></i>';
968 "mDataProp": function ( oObj ) {
969 let created_on = new Date( oObj.created_on );
970 return created_on.toLocaleDateString();
974 "mDataProp": function ( oObj ) {
975 if ( oObj.updated_on ) {
976 let updated_on = new Date( oObj.updated_on );
977 return updated_on.toLocaleDateString();
984 "mDataProp": function ( oObj ) {
985 if ( ! oObj.resolution ) return "";
987 let desc = '<strong>' + oObj.resolution_data.lib + '</strong> <i>(';
988 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>';
989 desc += ', ' + oObj.resolved_on + ')</i>';
994 "mDataProp": function ( oObj ) {
995 let delete_html = oObj.resolved_on
996 ? '<li><a href="#" class="return-claim-tools-delete" data-return-claim-id="' + oObj.id + '"><i class="fa fa-trash"></i> ' + __("Delete") + '</a></li>'
998 let resolve_html = ! oObj.resolution
999 ? '<li><a href="#" class="return-claim-tools-resolve" data-return-claim-id="' + oObj.id + '"><i class="fa fa-check-square"></i> ' + __("Resolve") + '</a></li>'
1002 return '<div class="btn-group">'
1003 + ' <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
1004 + __("Actions") + ' <span class="caret"></span>'
1006 + ' <ul class="dropdown-menu">'
1007 + ' <li><a href="#" class="return-claim-tools-editnotes" data-return-claim-id="' + oObj.id + '"><i class="fa fa-edit"></i> ' + __("Edit notes") + '</a></li>'
1016 "bProcessing": true,
1017 "bServerSide": false,
1018 "sAjaxSource": '/cgi-bin/koha/svc/return_claims',
1019 "fnServerData": function ( sSource, aoData, fnCallback ) {
1020 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
1022 $.getJSON( sSource, aoData, function (json) {
1023 let resolved = json.resolved;
1024 let unresolved = json.unresolved;
1026 if ( resolved > 0 ) {
1027 $('#return-claims-count-resolved').text(resolved)
1028 .removeClass('label-default')
1029 .addClass('label-success');
1031 $('#return-claims-count-resolved').text(resolved)
1032 .removeClass('label-success')
1033 .addClass('label-default');
1035 if ( unresolved > 0 ) {
1036 $('#return-claims-count-unresolved').text(unresolved)
1037 .removeClass('label-default')
1038 .addClass('label-warning');
1040 $('#return-claims-count-unresolved').text(unresolved)
1041 .removeClass('label-warning')
1042 .addClass('label-default');
1052 $('body').on('click', '.return-claim-tools-editnotes', function() {
1053 let id = $(this).data('return-claim-id');
1054 $('#return-claim-notes-static-' + id).parent().dblclick();
1056 $('body').on('dblclick', '.return-claim-notes-td', function() {
1057 let elt = $(this).children('.return-claim-notes');
1058 let id = elt.data('return-claim-id');
1059 if ( $('#return-claim-notes-editor-textarea-' + id).length == 0 ) {
1060 let note = elt.text();
1062 ' <span id="return-claim-notes-editor-' + id + '">'
1063 + ' <textarea id="return-claim-notes-editor-textarea-' + id + '">' + note + '</textarea>'
1065 + ' <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>'
1066 + ' <a class="claim-returned-notes-editor-cancel" data-return-claim-id="' + id + '" href="#">' + __("Cancel") + '</a>'
1069 $(editor).insertAfter( elt );
1073 $('body').on('click', '.claim-returned-notes-editor-submit', function(){
1074 let id = $(this).data('return-claim-id');
1075 let notes = $('#return-claim-notes-editor-textarea-' + id).val();
1079 updated_by: logged_in_user_borrowernumber
1082 $(this).parent().remove();
1085 url: '/api/v1/return_claims/' + id + '/notes',
1087 data: JSON.stringify(params),
1088 success: function( data ) {
1089 let notes = $('#return-claim-notes-static-' + id);
1090 notes.text(data.notes);
1097 $('body').on('click', '.claim-returned-notes-editor-cancel', function(){
1098 let id = $(this).data('return-claim-id');
1099 $(this).parent().remove();
1100 $('#return-claim-notes-static-' + id).show();
1103 // Hanld return claim deletion
1104 $('body').on('click', '.return-claim-tools-delete', function() {
1105 let confirmed = confirm(__("Are you sure you want to delete this return claim?"));
1107 let id = $(this).data('return-claim-id');
1110 url: '/api/v1/return_claims/' + id,
1112 success: function( data ) {
1113 refreshReturnClaimsTable();
1114 issuesTable.api().ajax.reload();
1120 // Handle return claim resolution
1121 $('body').on('click', '.return-claim-tools-resolve', function() {
1122 let id = $(this).data('return-claim-id');
1124 $('#claims-returned-resolved-modal-id').val(id);
1125 $('#claims-returned-resolved-modal').modal()
1128 $(document).on('click', '#claims-returned-resolved-modal-btn-submit', function(e) {
1129 let resolution = $('#claims-returned-resolved-modal-resolved-code').val();
1130 let id = $('#claims-returned-resolved-modal-id').val();
1132 $('#claims-returned-resolved-modal-btn-submit-spinner').show();
1133 $('#claims-returned-resolved-modal-btn-submit-icon').hide();
1136 resolution: resolution,
1137 updated_by: logged_in_user_borrowernumber
1141 url: '/api/v1/return_claims/' + id + '/resolve',
1143 data: JSON.stringify(params),
1144 success: function( data ) {
1145 $('#claims-returned-resolved-modal-btn-submit-spinner').hide();
1146 $('#claims-returned-resolved-modal-btn-submit-icon').show();
1147 $('#claims-returned-resolved-modal').modal('hide')
1149 refreshReturnClaimsTable();