From c706fc9e41583f593bda7a555764f61116e11fbb Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 27 Feb 2024 11:17:30 +0100 Subject: [PATCH] Bug 34478: Replace delete links with form - smart-rules We can certainly do better here (too many duplicated code in on click functions), but it's good enouh for now... Signed-off-by: Jonathan Druart --- admin/smart-rules.pl | 18 +-- .../prog/en/modules/admin/smart-rules.tt | 104 ++++++++++++++++-- 2 files changed, 101 insertions(+), 21 deletions(-) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index e1aea66aa8..f5f168f44f 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -121,7 +121,7 @@ if ($op eq 'cud-delete') { } ); } -elsif ($op eq 'delete-branch-cat') { +elsif ($op eq 'cud-delete-branch-cat') { my $categorycode = $input->param('categorycode'); if ($branch eq "*") { if ($categorycode eq "*") { @@ -197,7 +197,7 @@ elsif ($op eq 'delete-branch-cat') { ); } } -elsif ($op eq 'delete-branch-item') { +elsif ($op eq 'cud-delete-branch-item') { my $itemtype = $input->param('itemtype'); if ($branch eq "*") { if ($itemtype eq "*") { @@ -519,7 +519,7 @@ elsif ( $op eq "cud-add-open-article-requests-limit" ) { } ); } -} elsif ( $op eq 'del-open-article-requests-limit' ) { +} elsif ( $op eq 'cud-del-open-article-requests-limit' ) { my $categorycode = $input->param('categorycode'); if ( $branch eq "*" ) { if ( $categorycode eq "*" ) { @@ -555,7 +555,7 @@ elsif ( $op eq "cud-add-open-article-requests-limit" ) { } elsif ( $op eq "cud-set-article-request-fee" ) { - my $category = $input->param('article_request_fee_category'); + my $category = $input->param('categorycode'); my $fee = strip_non_numeric( scalar $input->param('article_request_fee') ); Koha::Exception->throw("No value passed for article request fee") @@ -569,9 +569,9 @@ elsif ( $op eq "cud-set-article-request-fee" ) { } ); -} elsif ( $op eq 'del-article-request-fee' ) { +} elsif ( $op eq 'cud-del-article-request-fee' ) { - my $category = $input->param('article_request_fee_category'); + my $category = $input->param('categorycode'); Koha::CirculationRules->set_rules( { categorycode => ( $category eq '*' ) ? undef : $category, @@ -709,10 +709,10 @@ elsif ( $op eq 'cud-mod-refund-lost-item-fee-rule' ) { } ); -} elsif ( $op eq 'del-waiting-hold-cancellation' ) { +} elsif ( $op eq 'cud-del-waiting-hold-cancellation' ) { - my $category = $input->param('waiting_hold_cancellation_category'); - my $itemtype = $input->param('waiting_hold_cancellation_itemtype'); + my $category = $input->param('categorycode'); + my $itemtype = $input->param('itemtype'); Koha::CirculationRules->set_rules( { categorycode => ( $category eq '*' ) ? undef : $category, 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 7dec803c08..bbaf7e78cc 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 @@ -243,7 +243,7 @@ Edit - Delete + Delete [% IF note.defined && note != '' %] @@ -410,7 +410,7 @@ [% END %] Edit - Delete + Delete [% END %] @@ -801,7 +801,7 @@ [% IF ( default_checkout_hold_and_return_policy ) %] - Unset + Unset [% END %] @@ -868,7 +868,7 @@ - Delete + Delete [% END %] @@ -940,7 +940,7 @@ [% END %] - Delete + Delete [% END %] @@ -1011,7 +1011,7 @@ - Delete + Delete [% END %] @@ -1070,7 +1070,7 @@ [% END %] - Delete + Delete [% END %] @@ -1360,7 +1360,7 @@ [% END %] - Delete + Delete [% END %] @@ -1416,6 +1416,15 @@ + +
+ [% INCLUDE 'csrf-token.inc' %] + + + + +
+ @@ -1471,10 +1480,6 @@ $(document).ready(function() { $('[data-toggle="popover"]').popover(); - $(".delete").on("click",function(){ - return confirmDelete(MSG_CONFIRM_DELETE); - }); - $("#clone_rules").on("click",function(){ var library_dropdown = document.getElementById("branch"); var selected_library = library_dropdown.options[library_dropdown.selectedIndex].value; @@ -1596,6 +1601,81 @@ } return true; }); + + $(".delete").on("click", function(e){ + e.preventDefault(); + if ( !confirmDelete(MSG_CONFIRM_DELETE) ) { + return false; + } + let f = $("#delete_form"); + f.find("[name='op']").val('cud-delete'); + f.find("[name='itemtype']").val($(this).data('itemtype')); + f.find("[name='categorycode']").val($(this).data('categorycode')); + f.find("[name='branch']").val($(this).data('branch')); + return f.submit(); + }); + + $(".delete-branch-cat").on("click", function(e){ + e.preventDefault(); + if ( !confirmDelete(MSG_CONFIRM_DELETE) ) { + return false; + } + let f = $("#delete_form"); + f.find("[name='op']").val('cud-delete-branch-cat'); + f.find("[name='categorycode']").val($(this).data('categorycode')); + f.find("[name='branch']").val($(this).data('branch')); + return f.submit(); + }); + + $(".del-waiting-hold-cancellation").on("click", function(e){ + e.preventDefault(); + if ( !confirmDelete(MSG_CONFIRM_DELETE) ) { + return false; + } + let f = $("#delete_form"); + f.find("[name='op']").val('cud-del-waiting-hold-cancellation'); + f.find("[name='itemtype']").val($(this).data('itemtype')); + f.find("[name='categorycode']").val($(this).data('categorycode')); + f.find("[name='branch']").val($(this).data('branch')); + return f.submit(); + }); + + $(".del-open-article-requests-limit").on("click", function(e){ + e.preventDefault(); + if ( !confirmDelete(MSG_CONFIRM_DELETE) ) { + return false; + } + let f = $("#delete_form"); + f.find("[name='op']").val('cud-del-open-article-requests-limit'); + f.find("[name='categorycode']").val($(this).data('categorycode')); + f.find("[name='branch']").val($(this).data('branch')); + return f.submit(); + }); + + $(".del-article-request-fee").on("click", function(e){ + e.preventDefault(); + if ( !confirmDelete(MSG_CONFIRM_DELETE) ) { + return false; + } + let f = $("#delete_form"); + f.find("[name='op']").val('cud-del-article-request-fee'); + f.find("[name='categorycode']").val($(this).data('categorycode')); + f.find("[name='branch']").val($(this).data('branch')); + return f.submit(); + }); + + $(".delete-branch-item").on("click", function(e){ + e.preventDefault(); + if ( !confirmDelete(MSG_CONFIRM_DELETE) ) { + return false; + } + let f = $("#delete_form"); + f.find("[name='op']").val('cud-delete-branch-item'); + f.find("[name='itemtype']").val($(this).data('itemtype')); + f.find("[name='branch']").val($(this).data('branch')); + return f.submit(); + }); + }); [% END %] -- 2.39.5