From 3d03790ec999c7c981a33f2659ab614e4a6323db Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Mon, 3 Feb 2025 08:55:11 +0000 Subject: [PATCH] Bug 8137: (follow-up) fix behavior with edit and clear actions --- .../prog/en/modules/admin/smart-rules.tt | 94 +++++++++++++++---- 1 file changed, 74 insertions(+), 20 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index 1ecd8fbc1ec..45cac33744f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -918,7 +918,7 @@
[% INCLUDE 'csrf-token.inc' %] - +
@@ -953,7 +953,7 @@ [% END %] + - - + +
Patron category - Edit + Edit Delete @@ -974,9 +974,9 @@ [% END %] [% END %] [% END %] -
- [% FOREACH patron_category IN patron_categories%] @@ -984,7 +984,7 @@ - [% FOREACH itemtypeloo IN itemtypeloop %] [% NEXT IF itemtypeloo.parent_type %] @@ -1004,10 +1004,10 @@ - +
@@ -1595,25 +1595,25 @@ }); }); - function clear_edit(){ + function clear_edit_form(editRowSelector, tableSelector) { var cancel = confirm(_("Are you sure you want to cancel your changes?")); - if ( !cancel ) return; - $('#default-circulation-rules td').removeClass('highlighted-row'); - var edit_row = $("#edit_row"); - $(edit_row).find("input").each(function(){ + if (!cancel) return; + $(tableSelector + ' td').removeClass('highlighted-row'); + var edit_row = $(editRowSelector); + $(edit_row).find("input").each(function() { var type = $(this).attr("type"); - if (type != "button" && type != "submit" ) { + if (type !== "button" && type !== "submit") { $(this).val(""); $(this).prop('disabled', false); } - if ( type == "checkbox" ) { + if (type === "checkbox") { $(this).prop('checked', false); } }); - $(edit_row).find("select").prop('disabled', false); - $(edit_row).find("select option:selected").removeAttr('selected'); - $(edit_row).find("select option:first-child").attr("selected", "selected"); - $(edit_row).find("td:last input[name='clear']").remove(); + edit_row.find("select").prop('disabled', false); + edit_row.find("select option:selected").prop('selected', false); + edit_row.find("select option:first-child").prop("selected", true); + edit_row.find("td:last input[name='clear']").remove(); } var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this rule? This cannot be undone."); @@ -1732,9 +1732,63 @@ $("#default-circulation-rules tr:last td:eq(1) select").prop('disabled', true); return false; }); + $(".editrule-global-checkout-limits").click(function(){ + if ( $("#global_checkout_limits_edit_row").find("input[type='text']").filter(function(){return this.value.length > 0 }).length > 0 ) { + var edit = confirm(_("Are you sure you want to edit another rule?")); + if (!edit) return false; + } + $('#global-checkout-limits-rules td').removeClass('highlighted-row'); + $(this).parent().parent().find("td").each(function (i) { + + $(this).addClass('highlighted-row'); + itm_code = $(this).data('code'); + itm_text = $(this).text(); + itm_text = itm_text.replace(/^\s*|\s*$/g,''); + var current_column = $("#global_checkout_limits_edit_row td:eq("+i+")"); + var current_input_id = $(current_column).children('input').first().attr('id'); + $(current_column).find("input[type='text']").val(itm_text); + // select the corresponding option + $(current_column).find("select option").each(function(){ + // Reset selection status for all options + $(this).prop('selected', false); + // Declare opt here to ensure it is scoped correctly within the loop + let opt = $(this).val(); + // Select the matching option + if (opt == itm_code) { + $(this).prop('selected', true); + } + }); + // After setting the correct option, update the select to reflect the change + $(current_column).find('select').trigger('change'); + if ( i == 0 || i == 1 ) { + // Disable the 2 first columns, we cannot update them. + var val = $(current_column).find("select option:selected").val(); + var name = "categorycode"; + if ( i == 1 ) { + name="itemtype"; + } + // Remove potential previous input added + $(current_column).find("input").remove(); + $(current_column).append(""); + } else if ( current_input_id === "global_checkout_limits_maxissueqty" || current_input_id === "global_checkout_limits_maxonsiteissueqty" ) { + // If the value is not an integer for + // - "Global current checkouts allowed" + // - "Global current on-site checkouts allowed" + // The value will be "Not defined" + if( !((parseFloat(itm_text) == parseInt(itm_text)) && !isNaN(itm_text)) ) { + $(current_column).find("input[type='text']").val(""); + } + } + }); + return false; + }); $(".clear_edit").on("click",function(e){ e.preventDefault(); - clear_edit(); + clear_edit_form("#edit_row", "#default-circulation-rules"); + }); + $(".clear_edit_global_checkouts_limit").on("click",function(e){ + e.preventDefault(); + clear_edit_form("#global_checkout_limits_edit_row", "#global-checkout-limits-rules"); }); $("#set-article-requests-daily-limit").on("submit", function(){ -- 2.39.5