From e6228fd187b13e43da7f181bba676ea7c7c897b2 Mon Sep 17 00:00:00 2001 From: Jake Deery Date: Mon, 29 Sep 2025 12:51:35 +0000 Subject: [PATCH] Bug 40896: Disable run report buttons upon click This patch will disable the run report button found on both the list page, and the individual operation pages (e.g. run, edit, saved successfully). This will stop librarians from unintentionally crashing their Koha system, by pressing the run report button repeatedly when there is no need to re-request it. TO TEST: a) go to /cgi-bin/koha/reports/guided_reports.pl?op=list b) create three new sql test reports: *) Name: Test report #1, SQL: SELECT count(*) FROM biblio *) Name: Test report #2, SQL: SELECT count(*) FROM items *) Name: Test report #3, SQL: SELECT * FROM items WHERE items.dateaccessioned = <> c) run all of the above test reports, noticing how the run report button can be activated repeatedly APPLY PATCH d) redo step a e) run test report #1 from the table, notice how now the button can only be activated once before it is greyed out and the play button is replaced with a spinner f) return to the list, edit test report #2 from the table, click run report from the edit page, and notice how this run report button exhibits the same behaviour as the button in step e g) return to the list, run test report #3, select a date, click run report from this page, and notice again how the run report button exhibits the same behaviour as the buttons in steps e and f SIGN OFF --- .../modules/reports/guided_reports_start.tt | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index d8be142676a..7872a7652c5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -930,7 +930,7 @@ [% IF ( template_id ) %] [% END %] - + [% END # / IF ( auth_val_error ) %] @@ -2005,6 +2005,18 @@ } } + const toggleReportRunButton = (element => { + if ($(element).attr('disabled') === undefined) { + $(element).attr('disabled', 'disabled'); + $(element).addClass('disabled'); + $(element).find('i.fa-play').first().replaceWith(''); + } else { + $(element).removeAttr('disabled'); + $(element).removeClass('disabled'); + $(element).find('i.fa-spinner').first().replaceWith(''); + } + }); + $(document).ready(function(){ var activeTab = localStorage.getItem("sql_reports_activetab"); @@ -2480,6 +2492,41 @@ selectField.style.minWidth = '320px'; $(selectField).select2(); }); + + $('a[href*="/cgi-bin/koha/reports/guided_reports.pl"]').each((idx, element) => { + const params = new URLSearchParams($(element).attr('href')); + const op = params.get('op'); + + if (op !== 'run') { + return; + } + + $(element).on('click', event => { + event.preventDefault(); + const href = $(element).attr('href'); + + toggleReportRunButton(element); + setTimeout(() => { + toggleReportRunButton(element); + }, 120000); + + window.location.href = href; + return false; + }); + }); + + $('#report_param_form').on('submit', event => { + const button = $('button[type="submit"]'); + + if (button.length < 1) { + return; + } + + toggleReportRunButton(button); + setTimeout(() => { + toggleReportRunButton(button); + }, 120000); + }); }); $("#toggle_auto_links").on("click", function(e){ -- 2.43.0