From 99d776f58e0fc99fa23adc58545346983bcbf218 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 23 Feb 2024 12:15:42 +0100 Subject: [PATCH] Bug 36084: svc - renew Material - The code that is supposed to replace the checkbox with a text was not at the correct place. It should be with checkin, not renewal. With the table refresh it does not make sense to keep it as we will never see it. Best is to replace the checkbox with the text directly. Signed-off-by: Jonathan Druart --- koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 113 ++++++++++-------- .../prog/js/fetch/circulation-api-client.js | 10 ++ 2 files changed, 71 insertions(+), 52 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js index c3584ea7fe..8833e66d8b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -362,7 +362,7 @@ function LoadIssuesTable() { } else if ( oObj.can_renew_error == "on_reserve" ) { return "" + __("On hold") + ""; } else if ( oObj.materials ) { - return ""; + return __("Confirm (%s)".format(oObj.materials.escapeHtml())); } else { return ""; } @@ -643,31 +643,19 @@ $(document).ready(function() { // Prevent form submit return false; }); - $("#RenewChecked").on("click",function(){ + $("#RenewChecked").on("click",function(e){ + e.preventDefault(); let refresh_table = true; - $(".confirm:checked:visible").each(function() { - itemnumber = $(this).val(); - id = "#checkin_" + itemnumber; - materials = $(this).data('materials'); - - $(this).replaceWith("" + __("Confirm") + " (" + materials + "): "); - $(id).parent().parent().addClass('warn'); - }); - - $(".renew:checked:visible").each(function() { + function renew(item_id){ var override_limit = $("#override_limit").is(':checked') ? 1 : 0; - var isOnReserve = $(this).data().hasOwnProperty('onReserve'); - - var itemnumber = $(this).val(); - - $(this).parent().parent().replaceWith(""); + $(this).parent().parent().replaceWith(""); var params = { - itemnumber: itemnumber, - borrowernumber: borrowernumber, - branchcode: branchcode, - override_limit: override_limit + item_id, + patron_id: borrowernumber, + library_id: branchcode, + override_limit: override_limit }; if (UnseenRenewals) { @@ -676,43 +664,39 @@ $(document).ready(function() { params.seen = renew_unseen === 1 ? 0 : 1; } - // Determine which due date we need to use - var dueDate = isOnReserve ? - $("#newonholdduedate input").val() : - $("#newduedate").val(); + var dueDate = $("#newduedate").val(); if (dueDate && dueDate.length > 0) { params.date_due = dueDate } - $.post({ - url: "/cgi-bin/koha/svc/renew", - data: params, - success: function( data ) { - var id = "#renew_" + data.itemnumber; + const client = APIClient.circulation; + return client.checkouts.renew(params).then( + success => { + var id = "#renew_" + success.itemnumber; var content = ""; - if ( data.renew_okay ) { - content = __("Renewed, due:") + " " + data.date_due; - $('#date_due_' + data.itemnumber).replaceWith( data.date_due ); + if ( success.renew_okay ) { + content = __("Renewed, due:") + " " + success.date_due; + $('#date_due_' + success.itemnumber).replaceWith( success.date_due ); } else { content = __("Renew failed:") + " "; - if ( data.error == "no_checkout" ) { + if ( success.error == "no_checkout" ) { content += __("not checked out"); - } else if ( data.error == "too_many" ) { + } else if ( success.error == "too_many" ) { content += __("too many renewals"); - } else if ( data.error == "too_unseen" ) { + } else if ( success.error == "too_unseen" ) { content += __("too many consecutive renewals without being seen by the library"); - } else if ( data.error == "on_reserve" ) { + } else if ( success.error == "on_reserve" ) { content += __("on hold"); - } else if ( data.error == "restriction" ) { + } else if ( success.error == "restriction" ) { content += __("Not allowed: patron restricted"); - } else if ( data.error == "overdue" ) { + } else if ( success.error == "overdue" ) { content += __("Not allowed: overdue"); - } else if ( data.error == 'no_open_days' ) { + } else if ( success.error == 'no_open_days' ) { content += __('Unable to find an open day'); - } else if ( data.error ) { - content += data.error; + } else if ( success.error ) { + content += success.error; } else { content += __("reason unknown"); } @@ -720,20 +704,45 @@ $(document).ready(function() { } $(id).replaceWith( content ); - }, - dataType: "json", - async: false, + }, + error => { + console.warn("Something wrong happened: %s".format(error)); + } + ); + } + + function renew_all(item_ids, fn){ + let i = 0; + function next(){ + if (i < item_ids.length) { + return fn(item_ids[i++]).then(function(id) { + return next(); + }); + } + } + + $(item_ids).each((i, id) => { + $("#renew_"+id).parent().append(""); + $("#renew_"+id).hide(); }); - }); - // Refocus on barcode field if it exists - if ( $("#barcode").length ) { - $("#barcode").focus(); + return next(); } - if ( refresh_table ) { - RefreshIssuesTable(); - } + let item_ids = $(".renew:checked:visible").map((i, c) => c.value); + + renew_all(item_ids, renew).then(() => { + // Refocus on barcode field if it exists + if ( $("#barcode").length ) { + $("#barcode").focus(); + } + + if ( refresh_table ) { + RefreshIssuesTable(); + } + $('#RenewChecked, #CheckinChecked').prop('disabled' , true ); + }); + // Prevent form submit return false; }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/fetch/circulation-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/fetch/circulation-api-client.js index dd3247b209..106c8e6614 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/fetch/circulation-api-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/fetch/circulation-api-client.js @@ -29,6 +29,16 @@ export class CirculationAPIClient extends HttpClient { get checkouts() { return { + renew: checkout => + this.post({ + endpoint: "renew", + body: "itemnumber=%s&borrowernumber=%s&branchcode=%s&override_limit=%s".format(checkout.item_id, checkout.patron_id, checkout.library_id, checkout.override_limit), + //+ ( checkout.seen !== undefined ? "&seen=%s".format(checkout.seen) : "" ) + (checkout.date_due !== undefined ? "&date_due=%s".format(checkout.date_due) : ""), + headers: { + "Content-Type": + "application/x-www-form-urlencoded;charset=utf-8", + }, + }), mark_as_seen: checkout_id => this.post({ endpoint: "checkout_notes", -- 2.39.5