From 1227126e321ad906c21f61b4aab28c7c11929163 Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Thu, 28 Sep 2023 12:48:36 +0000
Subject: [PATCH] Bug 34946: Remove the use of event attributes from self
 checkout and check-in

This patch removes the use of event attributes from the self checkout
and self check-in templates. These events are defined now along with the
other in-page JS.

To test you must have SelfCheckInModule and WebBasedSelfCheck
preferences enabled.

- Navigate to the self checkout interface
  (/cgi-bin/koha/sco/sco-main.pl).
- When the page loads, cursor focus should be automatically placed in
  the barcode field.
- Test the "munge history" feature from Bug 10016:
  [1] Start a web-based self-check session.
  [2] Enter a patron barcode.
  [3] Allow the self-check session to time out.
  [4] Use the back button.  You should get the patron barcode
      entry form; you should not be prompted to resubmit form input.
  [5] Enter a patron barcode, perform some transactions, then
      use the finish button.
  [6] Next, use the back button.  You should get the patron barcode
      entry form.
- Test the updated checkout_confirm function by submitting the "magic"
  barcode for checkout: __KOHA_NEW_CIRC__. The user's session should be
  ended.

- Navigate to the self check-in interface
  (/cgi-bin/koha/sco/sci-main.pl).
- Test the cursor focus and "munge history" feature on this page too.
---
 .../bootstrap/en/modules/sci/sci-main.tt          | 10 +++++++++-
 .../bootstrap/en/modules/sco/sco-main.tt          | 15 +++++++++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt
index cc044a6845..87ecf9b346 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt
@@ -51,7 +51,7 @@
 [% Asset.js('js/Gettext.js') | $raw %]
 [% Asset.js('js/i18n.js') | $raw %]
 </head>
-<body id="sci_main" class="sci" onload="dofocus();" onunload="mungeHistory();">
+<body id="sci_main" class="sci">
     [% INCLUDE 'masthead-sci.inc' %]
 
     <div class="main">
@@ -209,6 +209,14 @@
 
         var barcodes = [];
 
+        $( window ).on( "load", function() {
+            dofocus();
+        });
+
+        $( window ).on( "unload", function() {
+            mungeHistory();
+        });
+
         $(document).ready(function() {
             // Barcodes scanning table initially hidden
             $("#sci_barcodes_table").hide();
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt
index 003c792402..cf175343fc 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt
@@ -32,7 +32,7 @@
 [% Asset.js('js/Gettext.js') | $raw %]
 [% Asset.js('js/i18n.js') | $raw %]
 </head>
-<body id="sco_main" class="sco" onload="dofocus();" onunload="mungeHistory();">
+<body id="sco_main" class="sco">
     [% INCLUDE 'masthead-sco.inc' %]
 
     <div class="main">
@@ -241,7 +241,7 @@
 
                         [% IF ( validuser ) %]
                             <div id="newcheckout" class="sco_entry">
-                                <form id="scan_form" name="scan_form" method="post" action="/cgi-bin/koha/sco/sco-main.pl" onsubmit="return checkout_confirm('[% patronid | html %]');">
+                                <form id="scan_form" name="scan_form" method="post" action="/cgi-bin/koha/sco/sco-main.pl">
                                     <legend><h2>
                                         [% IF ( Koha.Preference('SCOAllowCheckin') ) %]
                                             <span>Check out, return, or renew an item:</span>
@@ -499,6 +499,13 @@
             }
         [% END %]
 
+        $( window ).on( "load", function() {
+            dofocus();
+        });
+
+        $( window ).on( "unload", function() {
+            mungeHistory();
+        });
 
         $(document).ready(function() {
             dofocus();
@@ -533,6 +540,10 @@
 
                 return true;
             });
+
+            $("#scan_form").on("submit", function(){
+                return checkout_confirm('[% patronid | html %]');
+            });
     });
 
     </script>
-- 
2.30.2