1 /* global PATRON_NOTE */
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 = CIRCULATION_RETURNED;
119 $(id).parent().parent().addClass('ok');
120 $('#date_due_' + data.itemnumber).html(CIRCULATION_RETURNED);
121 if ( data.patronnote != null ) {
122 $('.patron_note_' + data.itemnumber).html( PATRON_NOTE + ": " + data.patronnote);
125 content = CIRCULATION_NOT_RETURNED;
126 $(id).parent().parent().addClass('warn');
129 $(id).replaceWith( content );
133 $(".renew:checked:visible").each(function() {
134 var override_limit = $("#override_limit").is(':checked') ? 1 : 0;
136 var isOnReserve = $(this).data().hasOwnProperty('onReserve');
138 var itemnumber = $(this).val();
140 $(this).parent().parent().replaceWith("<img id='renew_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
143 itemnumber: itemnumber,
144 borrowernumber: borrowernumber,
145 branchcode: branchcode,
146 override_limit: override_limit,
149 // Determine which due date we need to use
150 var dueDate = isOnReserve ?
151 $("#newonholdduedate input").val() :
152 $("#newduedate").val();
154 if (dueDate && dueDate.length > 0) {
155 params.date_due = dueDate
158 $.post( "/cgi-bin/koha/svc/renew", params, function( data ) {
159 var id = "#renew_" + data.itemnumber;
162 if ( data.renew_okay ) {
163 content = CIRCULATION_RENEWED_DUE + " " + data.date_due;
164 $('#date_due_' + data.itemnumber).replaceWith( data.date_due );
166 content = CIRCULATION_RENEW_FAILED + " ";
167 if ( data.error == "no_checkout" ) {
168 content += NOT_CHECKED_OUT;
169 } else if ( data.error == "too_many" ) {
170 content += TOO_MANY_RENEWALS;
171 } else if ( data.error == "on_reserve" ) {
172 content += ON_RESERVE;
173 } else if ( data.error == "restriction" ) {
174 content += NOT_RENEWABLE_RESTRICTION;
175 } else if ( data.error == "overdue" ) {
176 content += NOT_RENEWABLE_OVERDUE;
177 } else if ( data.error ) {
178 content += data.error;
180 content += REASON_UNKNOWN;
184 $(id).replaceWith( content );
188 // Refocus on barcode field if it exists
189 if ( $("#barcode").length ) {
190 $("#barcode").focus();
193 // Prevent form submit
197 $("#RenewAll").on("click",function(){
198 $("#CheckAllRenewals").click();
199 $("#UncheckAllCheckins").click();
200 showHideOnHoldRenewal();
201 $("#RenewCheckinChecked").click();
203 // Prevent form submit
207 var ymd = $.datepicker.formatDate('yy-mm-dd', new Date());
209 $('#issues-table').hide();
210 $('#issues-table-actions').hide();
211 $('#issues-table-load-immediately').change(function(){
212 if ( this.checked && typeof issuesTable === 'undefined') {
213 $('#issues-table-load-now-button').click();
215 barcodefield.focus();
217 $('#issues-table-load-now-button').click(function(){
219 barcodefield.focus();
223 if ( Cookies.get("issues-table-load-immediately-" + script) == "true" ) {
225 $('#issues-table-load-immediately').prop('checked', true);
227 $('#issues-table-load-immediately').on( "change", function(){
228 Cookies.set("issues-table-load-immediately-" + script, $(this).is(':checked'), { expires: 365 });
231 function LoadIssuesTable() {
232 $('#issues-table-loading-message').hide();
233 $('#issues-table').show();
234 $('#issues-table-actions').show();
236 var msg_loading = __('Loading... you may continue scanning.');
237 issuesTable = KohaTable("issues-table", {
239 "sEmptyTable" : msg_loading,
240 "sProcessing": msg_loading,
243 "dom": 'B<"clearfix">rt',
246 "mDataProp": function( oObj ) {
247 return oObj.sort_order;
251 "mDataProp": function( oObj ) {
252 if ( oObj.issued_today ) {
253 return "<strong>" + TODAYS_CHECKOUTS + "</strong>";
255 return "<strong>" + PREVIOUS_CHECKOUTS + "</strong>";
260 "mDataProp": "date_due",
264 "iDataSort": 2, // Sort on hidden unformatted date due column
265 "mDataProp": function( oObj ) {
266 var due = oObj.date_due_formatted;
268 if ( oObj.date_due_overdue ) {
269 due = "<span class='overdue'>" + due + "</span>";
272 due = "<span id='date_due_" + oObj.itemnumber + "' class='date_due'>" + due + "</span>";
274 if ( oObj.lost && oObj.claims_returned ) {
275 due += "<span class='lost claims_returned'>" + oObj.lost.escapeHtml() + "</span>";
276 } else if ( oObj.lost ) {
277 due += "<span class='lost'>" + oObj.lost.escapeHtml() + "</span>";
280 if ( oObj.damaged ) {
281 due += "<span class='dmg'>" + oObj.damaged.escapeHtml() + "</span>";
284 var patron_note = " <span class='patron_note_" + oObj.itemnumber + "'></span>";
285 due +="<br>" + patron_note;
291 "mDataProp": function ( oObj ) {
292 let title = "<span id='title_" + oObj.itemnumber + "' class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
295 + (oObj.title ? oObj.title.escapeHtml() : '' );
297 $.each(oObj.subtitle, function( index, value ) {
298 title += " " + value.escapeHtml();
301 title += " " + oObj.part_number + " " + oObj.part_name;
303 if ( oObj.enumchron ) {
304 title += " (" + oObj.enumchron.escapeHtml() + ")";
307 title += "</a></span>";
310 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
313 if ( oObj.itemnotes ) {
314 var span_class = "text-muted";
315 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
316 span_class = "circ-hlt";
318 title += " - <span class='" + span_class + " item-note-public'>" + oObj.itemnotes.escapeHtml() + "</span>";
321 if ( oObj.itemnotes_nonpublic ) {
322 var span_class = "text-danger";
323 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
324 span_class = "circ-hlt";
326 title += " - <span class='" + span_class + " item-note-nonpublic'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>";
329 var onsite_checkout = '';
330 if ( oObj.onsite_checkout == 1 ) {
331 onsite_checkout += " <span class='onsite_checkout'>(" + INHOUSE_USE + ")</span>";
335 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
342 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
351 "mDataProp": function ( oObj ) {
352 return oObj.recordtype_description.escapeHtml();
356 "mDataProp": function ( oObj ) {
357 return oObj.itemtype_description.escapeHtml();
361 "mDataProp": function ( oObj ) {
362 return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
366 "mDataProp": function ( oObj ) {
367 return ( oObj.location ? oObj.location.escapeHtml() : '' );
371 "mDataProp": function ( oObj ) {
372 return (oObj.homebranch ? oObj.homebranch.escapeHtml() : '' );
376 "mDataProp": "issuedate",
380 "iDataSort": 10, // Sort on hidden unformatted issuedate column
381 "mDataProp": "issuedate_formatted",
384 "mDataProp": function ( oObj ) {
385 return (oObj.branchname ? oObj.branchname.escapeHtml() : '' );
389 "mDataProp": function ( oObj ) {
390 return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
394 "mDataProp": function ( oObj ) {
395 if ( ! oObj.charge ) oObj.charge = 0;
396 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.charge).toFixed(2) + '<span>';
400 "mDataProp": function ( oObj ) {
401 if ( ! oObj.fine ) oObj.fine = 0;
402 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.fine).toFixed(2) + '<span>';
406 "mDataProp": function ( oObj ) {
407 if ( ! oObj.price ) oObj.price = 0;
408 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.price).toFixed(2) + '<span>';
413 "bVisible": AllowCirculate ? true : false,
414 "mDataProp": function ( oObj ) {
420 if ( oObj.can_renew ) {
422 } else if ( oObj.can_renew_error == "on_reserve" ) {
424 + "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>"
427 span_style = "display: none";
428 span_class = "renewals-allowed-on_reserve";
429 } else if ( oObj.can_renew_error == "too_many" ) {
430 msg += "<span class='renewals-disabled'>"
434 span_style = "display: none";
435 span_class = "renewals-allowed";
436 } else if ( oObj.can_renew_error == "restriction" ) {
437 msg += "<span class='renewals-disabled'>"
438 + NOT_RENEWABLE_RESTRICTION
441 span_style = "display: none";
442 span_class = "renewals-allowed";
443 } else if ( oObj.can_renew_error == "overdue" ) {
444 msg += "<span class='renewals-disabled'>"
445 + NOT_RENEWABLE_OVERDUE
448 span_style = "display: none";
449 span_class = "renewals-allowed";
450 } else if ( oObj.can_renew_error == "too_soon" ) {
451 msg += "<span class='renewals-disabled'>"
452 + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date )
455 span_style = "display: none";
456 span_class = "renewals-allowed";
457 } else if ( oObj.can_renew_error == "auto_too_soon" ) {
458 msg += "<span class='renewals-disabled'>"
459 + NOT_RENEWABLE_AUTO_TOO_SOON
462 span_style = "display: none";
463 span_class = "renewals-allowed";
464 } else if ( oObj.can_renew_error == "auto_too_late" ) {
465 msg += "<span class='renewals-disabled'>"
466 + NOT_RENEWABLE_AUTO_TOO_LATE
469 span_style = "display: none";
470 span_class = "renewals-allowed";
471 } else if ( oObj.can_renew_error == "auto_too_much_oweing" ) {
472 msg += "<span class='renewals-disabled'>"
473 + NOT_RENEWABLE_AUTO_TOO_MUCH_OWEING
476 span_style = "display: none";
477 span_class = "renewals-allowed";
478 } else if ( oObj.can_renew_error == "auto_account_expired" ) {
479 msg += "<span class='renewals-disabled'>"
480 + NOT_RENEWABLE_AUTO_ACCOUNT_EXPIRED
483 span_style = "display: none";
484 span_class = "renewals-allowed";
485 } else if ( oObj.can_renew_error == "auto_renew" ) {
486 msg += "<span class='renewals-disabled'>"
487 + NOT_RENEWABLE_AUTO_RENEW
490 span_style = "display: none";
491 span_class = "renewals-allowed";
492 } else if ( oObj.can_renew_error == "onsite_checkout" ) {
493 // Don't display something if it's an onsite checkout
494 } else if ( oObj.can_renew_error == "item_denied_renewal" ) {
495 content += "<span class='renewals-disabled'>"
496 + NOT_RENEWABLE_DENIED
499 span_style = "display: none";
500 span_class = "renewals-allowed";
502 msg += "<span class='renewals-disabled'>"
503 + oObj.can_renew_error
506 span_style = "display: none";
507 span_class = "renewals-allowed";
510 var can_force_renew = ( oObj.onsite_checkout == 0 ) &&
511 ( oObj.can_renew_error != "on_reserve" || (oObj.can_renew_error == "on_reserve" && AllowRenewalOnHoldOverride))
513 var can_renew = ( oObj.renewals_remaining > 0 && !oObj.can_renew_error );
515 if ( can_renew || can_force_renew ) {
516 content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
517 content += "<span class='" + span_class + "' style='" + span_style + "'>"
518 + "<input type='checkbox' ";
519 if ( oObj.date_due_overdue && can_renew ) {
520 content += "checked='checked' ";
522 if (oObj.can_renew_error == "on_reserve") {
523 content += "data-on-reserve ";
525 content += "class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
529 if ( can_renew || can_force_renew ) {
530 content += "<span class='renewals'>("
531 + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed )
535 content += "</span>";
542 "bVisible": AllowCirculate ? true : false,
543 "mDataProp": function ( oObj ) {
544 if ( oObj.can_renew_error == "on_reserve" ) {
545 return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>";
547 return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
552 "bVisible": ClaimReturnedLostValue ? true : false,
554 "mDataProp": function ( oObj ) {
557 if ( oObj.return_claim_id ) {
558 content = '<span class="badge">' + oObj.return_claim_created_on_formatted + '</span>';
560 content = '<a class="btn btn-default btn-xs claim-returned-btn" data-itemnumber="' + oObj.itemnumber + '"><i class="fa fa-exclamation-circle"></i> ' + RETURN_CLAIMED_MAKE + '</a>';
566 "bVisible": exports_enabled == 1 ? true : false,
568 "mDataProp": function ( oObj ) {
569 var s = "<input type='checkbox' name='itemnumbers' value='" + oObj.itemnumber + "' style='visibility:hidden;' />";
571 s += "<input type='checkbox' class='export' id='export_" + oObj.biblionumber + "' name='biblionumbers' value='" + oObj.biblionumber + "' />";
576 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
577 var total_charge = 0;
580 for ( var i=0; i < aaData.length; i++ ) {
581 total_charge += aaData[i]['charge'] * 1;
582 total_fine += aaData[i]['fine'] * 1;
583 total_price += aaData[i]['price'] * 1;
585 $("#totaldue").html(total_charge.toFixed(2));
586 $("#totalfine").html(total_fine.toFixed(2));
587 $("#totalprice").html(total_price.toFixed(2));
591 "bServerSide": false,
592 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
593 "fnServerData": function ( sSource, aoData, fnCallback ) {
594 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
596 $.getJSON( sSource, aoData, function (json) {
601 "dataSrc": "issued_today",
602 "startRender": function ( rows, group ) {
604 return TODAYS_CHECKOUTS;
606 return PREVIOUS_CHECKOUTS;
610 "fnInitComplete": function(oSettings, json) {
611 // Build a summary of checkouts grouped by itemtype
612 var checkoutsByItype = json.aaData.reduce(function (obj, row) {
613 obj[row.type_for_stat] = (obj[row.type_for_stat] || 0) + 1;
617 Object.keys(checkoutsByItype).sort().forEach(function (itype) {
619 .append($('<strong>').html(itype || MSG_NO_ITEMTYPE))
620 .append(': ' + checkoutsByItype[itype]);
624 .addClass('checkouts-by-itemtype')
625 .append($('<summary>').html(MSG_CHECKOUTS_BY_ITEMTYPE))
627 .insertBefore(oSettings.nTableWrapper)
629 }, columns_settings_issues_table);
631 if ( $("#issues-table").length ) {
632 $("#issues-table_processing").position({
633 of: $( "#issues-table" ),
639 // Don't load relatives' issues table unless it is clicked on
640 var relativesIssuesTable;
641 $("#relatives-issues-tab").click( function() {
642 if ( ! relativesIssuesTable ) {
643 relativesIssuesTable = $("#relatives-issues-table").dataTable($.extend(true, {}, dataTablesDefaults, {
649 "mDataProp": "date_due",
653 "iDataSort": 0, // Sort on hidden unformatted date due column
654 "mDataProp": function( oObj ) {
655 var today = new Date();
656 var due = new Date( oObj.date_due );
658 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
660 return oObj.date_due_formatted;
665 "mDataProp": function ( oObj ) {
666 let title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
669 + (oObj.title ? oObj.title.escapeHtml() : '' );
671 $.each(oObj.subtitle, function( index, value ) {
672 title += " " + value.escapeHtml();
675 title += " " + oObj.part_number + " " + oObj.part_name;
677 if ( oObj.enumchron ) {
678 title += " (" + oObj.enumchron.escapeHtml() + ")";
681 title += "</a></span>";
684 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
687 if ( oObj.itemnotes ) {
689 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
690 span_class = "circ-hlt";
692 title += " - <span class='" + span_class + "'>" + oObj.itemnotes.escapeHtml() + "</span>"
695 if ( oObj.itemnotes_nonpublic ) {
697 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
698 span_class = "circ-hlt";
700 title += " - <span class='" + span_class + "'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>"
703 var onsite_checkout = '';
704 if ( oObj.onsite_checkout == 1 ) {
705 onsite_checkout += " <span class='onsite_checkout'>(" + INHOUSE_USE + ")</span>";
709 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
716 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
725 "mDataProp": function ( oObj ) {
726 return oObj.recordtype_description.escapeHtml();
730 "mDataProp": function ( oObj ) {
731 return oObj.itemtype_description.escapeHtml();
735 "mDataProp": function ( oObj ) {
736 return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
740 "mDataProp": function ( oObj ) {
741 return ( oObj.location ? oObj.location.escapeHtml() : '' );
745 "mDataProp": "issuedate",
749 "iDataSort": 7, // Sort on hidden unformatted issuedate column
750 "mDataProp": "issuedate_formatted",
753 "mDataProp": function ( oObj ) {
754 return ( oObj.branchname ? oObj.branchname.escapeHtml() : '' );
758 "mDataProp": function ( oObj ) {
759 return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
763 "mDataProp": function ( oObj ) {
764 if ( ! oObj.charge ) oObj.charge = 0;
765 return parseFloat(oObj.charge).toFixed(2);
769 "mDataProp": function ( oObj ) {
770 if ( ! oObj.fine ) oObj.fine = 0;
771 return parseFloat(oObj.fine).toFixed(2);
775 "mDataProp": function ( oObj ) {
776 if ( ! oObj.price ) oObj.price = 0;
777 return parseFloat(oObj.price).toFixed(2);
781 "mDataProp": function( oObj ) {
782 return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
783 + oObj.borrower.firstname.escapeHtml()
785 oObj.borrower.surname.escapeHtml()
786 + " (" + oObj.borrower.cardnumber.escapeHtml() + ")</a>"
792 "bServerSide": false,
793 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
794 "fnServerData": function ( sSource, aoData, fnCallback ) {
795 $.each(relatives_borrowernumbers, function( index, value ) {
796 aoData.push( { "name": "borrowernumber", "value": value } );
799 $.getJSON( sSource, aoData, function (json) {
807 if ( $("#relatives-issues-table").length ) {
808 $("#relatives-issues-table_processing").position({
809 of: $( "#relatives-issues-table" ),
814 if ( AllowRenewalLimitOverride || AllowRenewalOnHoldOverride ) {
815 $( '#override_limit' ).click( function () {
816 if ( this.checked ) {
817 if ( AllowRenewalLimitOverride ) {
818 $( '.renewals-allowed' ).show();
819 $( '.renewals-disabled' ).hide();
821 if ( AllowRenewalOnHoldOverride ) {
822 $( '.renewals-allowed-on_reserve' ).show();
825 $( '.renewals-allowed' ).hide();
826 $( '.renewals-allowed-on_reserve' ).hide();
827 $( '.renewals-disabled' ).show();
829 } ).prop('checked', false);
832 // Handle return claims
833 $(document).on("click", '.claim-returned-btn', function(e){
835 itemnumber = $(this).data('itemnumber');
837 $('#claims-returned-itemnumber').val(itemnumber);
838 $('#claims-returned-notes').val("");
839 $('#claims-returned-charge-lost-fee').attr('checked', false)
840 $('#claims-returned-modal').modal()
842 $(document).on("click", '#claims-returned-modal-btn-submit', function(e){
843 let itemnumber = $('#claims-returned-itemnumber').val();
844 let notes = $('#claims-returned-notes').val();
845 let fee = $('#claims-returned-charge-lost-fee').attr('checked') ? true : false;
847 $('#claims-returned-modal').modal('hide')
849 $('.claim-returned-btn[data-itemnumber="' + itemnumber + '"]').replaceWith('<img id="return_claim_spinner_' + itemnumber + ' src=' + interface + '/' + theme + '/img/spinner-small.gif />');
854 charge_lost_fee: fee,
855 created_by: logged_in_user_borrowernumber,
858 $.post( '/api/v1/return_claims', JSON.stringify(params), function( data ) {
860 id = "#return_claim_spinner_" + data.item_id;
862 let created_on = new Date(data.created_on);
865 if ( data.claim_id ) {
866 content = '<span class="badge">' + created_on.toLocaleDateString() + '</span>';
867 $(id).parent().parent().addClass('ok');
869 content = RETURN_CLAIMED_FAILURE;
870 $(id).parent().parent().addClass('warn');
873 $(id).replaceWith( content );
875 refreshReturnClaimsTable();
876 issuesTable.api().ajax.reload();
882 // Don't load return claims table unless it is clicked on
883 var returnClaimsTable;
884 $("#return-claims-tab").click( function() {
885 refreshReturnClaimsTable();
888 function refreshReturnClaimsTable(){
889 loadReturnClaimsTable();
890 $("#return-claims-table").DataTable().ajax.reload();
892 function loadReturnClaimsTable() {
893 if ( ! returnClaimsTable ) {
894 returnClaimsTable = $("#return-claims-table").dataTable({
904 "mDataProp": function ( oObj ) {
905 let title = '<a class="return-claim-title strong" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + oObj.biblionumber + '">'
907 + ( oObj.enumchron || "" )
910 title += ' by ' + oObj.author;
912 title += ' <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber='
917 + (oObj.barcode ? oObj.barcode.escapeHtml() : "")
924 "sClass": "return-claim-notes-td",
925 "mDataProp": function ( oObj ) {
926 return '<span id="return-claim-notes-static-' + oObj.id + '" class="return-claim-notes" data-return-claim-id="' + oObj.id + '">' + oObj.notes + '</span>'
927 + '<i style="float:right" class="fa fa-pencil-square-o" title="' + __("Double click to edit") + '"></i>';
931 "mDataProp": function ( oObj ) {
932 let created_on = new Date( oObj.created_on );
933 return created_on.toLocaleDateString();
937 "mDataProp": function ( oObj ) {
938 if ( oObj.updated_on ) {
939 let updated_on = new Date( oObj.updated_on );
940 return updated_on.toLocaleDateString();
947 "mDataProp": function ( oObj ) {
948 if ( ! oObj.resolution ) return "";
950 let desc = '<strong>' + oObj.resolution_data.lib + '</strong> <i>(';
951 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>';
952 desc += ', ' + oObj.resolved_on + ')</i>';
957 "mDataProp": function ( oObj ) {
958 let delete_html = oObj.resolved_on
959 ? '<li><a href="#" class="return-claim-tools-delete" data-return-claim-id="' + oObj.id + '"><i class="fa fa-trash"></i> ' + __("Delete") + '</a></li>'
961 let resolve_html = ! oObj.resolution
962 ? '<li><a href="#" class="return-claim-tools-resolve" data-return-claim-id="' + oObj.id + '"><i class="fa fa-check-square"></i> ' + __("Resolve") + '</a></li>'
965 return '<div class="btn-group">'
966 + ' <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
967 + __("Actions") + ' <span class="caret"></span>'
969 + ' <ul class="dropdown-menu">'
970 + ' <li><a href="#" class="return-claim-tools-editnotes" data-return-claim-id="' + oObj.id + '"><i class="fa fa-edit"></i> ' + __("Edit notes") + '</a></li>'
980 "bServerSide": false,
981 "sAjaxSource": '/cgi-bin/koha/svc/return_claims',
982 "fnServerData": function ( sSource, aoData, fnCallback ) {
983 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
985 $.getJSON( sSource, aoData, function (json) {
986 let resolved = json.resolved;
987 let unresolved = json.unresolved;
989 $('#return-claims-count-resolved').text(resolved);
990 $('#return-claims-count-unresolved').text(unresolved);
999 $('body').on('click', '.return-claim-tools-editnotes', function() {
1000 let id = $(this).data('return-claim-id');
1001 $('#return-claim-notes-static-' + id).parent().dblclick();
1003 $('body').on('dblclick', '.return-claim-notes-td', function() {
1004 let elt = $(this).children('.return-claim-notes');
1005 let id = elt.data('return-claim-id');
1006 if ( $('#return-claim-notes-editor-textarea-' + id).length == 0 ) {
1007 let note = elt.text();
1009 ' <span id="return-claim-notes-editor-' + id + '">'
1010 + ' <textarea id="return-claim-notes-editor-textarea-' + id + '">' + note + '</textarea>'
1012 + ' <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>'
1013 + ' <a class="claim-returned-notes-editor-cancel" data-return-claim-id="' + id + '" href="#">' + __("Cancel") + '</a>'
1016 $(editor).insertAfter( elt );
1020 $('body').on('click', '.claim-returned-notes-editor-submit', function(){
1021 let id = $(this).data('return-claim-id');
1022 let notes = $('#return-claim-notes-editor-textarea-' + id).val();
1026 updated_by: logged_in_user_borrowernumber
1029 $(this).parent().remove();
1032 url: '/api/v1/return_claims/' + id + '/notes',
1034 data: JSON.stringify(params),
1035 success: function( data ) {
1036 let notes = $('#return-claim-notes-static-' + id);
1037 notes.text(data.notes);
1044 $('body').on('click', '.claim-returned-notes-editor-cancel', function(){
1045 let id = $(this).data('return-claim-id');
1046 $(this).parent().remove();
1047 $('#return-claim-notes-static-' + id).show();
1050 // Hanld return claim deletion
1051 $('body').on('click', '.return-claim-tools-delete', function() {
1052 let confirmed = confirm(CONFIRM_DELETE_RETURN_CLAIM);
1054 let id = $(this).data('return-claim-id');
1057 url: '/api/v1/return_claims/' + id,
1059 success: function( data ) {
1060 refreshReturnClaimsTable();
1061 issuesTable.api().ajax.reload();
1067 // Handle return claim resolution
1068 $('body').on('click', '.return-claim-tools-resolve', function() {
1069 let id = $(this).data('return-claim-id');
1071 $('#claims-returned-resolved-modal-id').val(id);
1072 $('#claims-returned-resolved-modal').modal()
1075 $(document).on('click', '#claims-returned-resolved-modal-btn-submit', function(e) {
1076 let resolution = $('#claims-returned-resolved-modal-resolved-code').val();
1077 let id = $('#claims-returned-resolved-modal-id').val();
1079 $('#claims-returned-resolved-modal-btn-submit-spinner').show();
1080 $('#claims-returned-resolved-modal-btn-submit-icon').hide();
1083 resolution: resolution,
1084 updated_by: logged_in_user_borrowernumber
1088 url: '/api/v1/return_claims/' + id + '/resolve',
1090 data: JSON.stringify(params),
1091 success: function( data ) {
1092 $('#claims-returned-resolved-modal-btn-submit-spinner').hide();
1093 $('#claims-returned-resolved-modal-btn-submit-icon').show();
1094 $('#claims-returned-resolved-modal').modal('hide')
1096 refreshReturnClaimsTable();