From 343ed5ec9727e1ad55e3759bbc947f3658eb415b Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Thu, 6 Mar 2025 12:58:13 +0000
Subject: [PATCH] Bug 39262: Don't pass string literals to setTimeout

This patch updates a few places in our code where we pass string
literals to JavaScript's setTimeout() function. This is not recommended:
https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#passing_string_literals

To test, apply the patch and clear your browser cache if necessary.

- In the OPAC, perform a catalog search. From the search results page,
  test adding some items to the cart. The "Item has been added to your
  cart" message should appear and disappear correctly.
- In the staff interface, view the contents of a list. Click the "Print
  list" button in the toolbar. A new tab should load and trigger the
  browser's print window. Printing the page or cancelling should
  automatically close the tab.
- Go to Acquisitions -> Vendor -> Basket groups. In the "Open" tab,
  click the "Close and export as PDF" button. This should trigger
  a page reload and the creation of a PDF. The basket group should now
  appear under the "Closed" tab.

Sponsored-by: Athens County Public Libraries
Signed-off-by: David Cook <dcook@prosentient.com.au>
---
 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt  | 4 +++-
 .../intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt   | 4 +++-
 koha-tmpl/opac-tmpl/bootstrap/js/basket.js                    | 2 +-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt
index 153d0e8d90..ba83451cf2 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt
@@ -410,7 +410,9 @@
 
         function closeandprint(bg){
             if(document.location = '/cgi-bin/koha/acqui/basketgroup.pl?op=closeandprint&amp;basketgroupid=' + bg ){
-                setTimeout("window.location.reload();", 3000);
+                setTimeout(() => {
+                    window.location.reload();
+                }, 3000);
             } else {
                 alert( _("Error downloading the file") );
             }
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
index c7bb4d5f5d..b16b7005ec 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
@@ -640,7 +640,9 @@
                 window.onafterprint = function () {
                     window.close();
                 };
-                setTimeout("window.close()", 1000); // Hack for Chrome < 63
+                setTimeout(() => {
+                    window.close();
+                }, 1000); // Hack for Chrome < 63
             });
         </script>
     [% END #/print %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/basket.js b/koha-tmpl/opac-tmpl/bootstrap/js/basket.js
index 0f12addf84..e4a9c5f5ae 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/js/basket.js
+++ b/koha-tmpl/opac-tmpl/bootstrap/js/basket.js
@@ -209,7 +209,7 @@ function showCartUpdate(msg) {
     // set body of popup window
     $("#cartDetails").html(msg);
     showCart();
-    setTimeout("hideCart()", 2000);
+    setTimeout(hideCart, 2000);
 }
 
 function showListsUpdate(msg) {
-- 
2.39.5