From 64e685bba3e0af5a4d64dc1f4674e20b089ecad8 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Tue, 21 Jul 2020 13:37:16 +0100
Subject: [PATCH] Bug 24786: Allow selection of cash register at login

---
 koha-tmpl/intranet-tmpl/prog/css/login.css    |  4 +++
 .../intranet-tmpl/prog/en/modules/auth.tt     | 12 +++++++
 .../prog/en/modules/circ/set-library.tt       | 31 +------------------
 .../prog/js/register_selection.js             | 27 ++++++++++++++++
 4 files changed, 44 insertions(+), 30 deletions(-)
 create mode 100644 koha-tmpl/intranet-tmpl/prog/js/register_selection.js

diff --git a/koha-tmpl/intranet-tmpl/prog/css/login.css b/koha-tmpl/intranet-tmpl/prog/css/login.css
index 5d1f9ef219..f4d0fb166b 100644
--- a/koha-tmpl/intranet-tmpl/prog/css/login.css
+++ b/koha-tmpl/intranet-tmpl/prog/css/login.css
@@ -96,6 +96,10 @@ label {
 	padding: 3px;
 }
 
+#login select {
+    width: 98%;
+}
+
 #login ul {
 	list-style: none;
 	margin: 0;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt
index 699dd10eaf..5d6e208208 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt
@@ -4,6 +4,7 @@
 [% USE Branches %]
 [% USE Desks %]
 [% USE Categories %]
+[% USE Registers %]
 [% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; 
@@ -95,6 +96,16 @@
             </select>
         </p>
     [% END %]
+
+    [% IF Koha.Preference('UseCashRegisters') %]
+    <p>
+        <label for="register_id">Cash register:</label>
+        <select name="register_id" id="register_id" class="input" tabindex="4">
+            [% PROCESS options_for_registers registers => Registers.all() %]
+        </select>
+    </p>
+    [% END %]
+
 </fieldset>
 [% END %]
 
@@ -137,6 +148,7 @@
 
 [% MACRO jsinclude BLOCK %]
     [% Asset.js("js/desk_selection.js") | $raw %]
+    [% Asset.js("js/register_selection.js") | $raw %]
     <script type="text/javascript">
         $(document).ready( function() {
             if ( document.location.hash ) {
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt
index 7751122436..49db4c3da7 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt
@@ -143,36 +143,7 @@ Updated:<ul>
 
 [% MACRO jsinclude BLOCK %]
   [% Asset.js("js/desk_selection.js") | $raw %]
-  <script>
-    $(document).ready(function() {
-        $("#branch").on("change", function() {
-            var selectedBranch = $("#branch").children(
-                    "option:selected").val();
-
-            $("#register_id").children().each(function() {
-                // default to no-register
-                if ($(this).is("#noregister")) {
-                    $(this).prop("selected", true)
-                }
-                // display branch registers
-                else if ($(this).hasClass(selectedBranch)) {
-                    $(this).prop("disabled", false);
-                    $(this).show();
-                    // default to branch default if there is one
-                    if ($(this).hasClass("default")) {
-                        $(this).prop("selected", true)
-                    }
-                }
-                // hide non-branch registers
-                else
-                {
-                    $(this).hide();
-                    $(this).prop("disabled", true);
-                }
-            });
-        });
-    });
-  </script>
+  [% Asset.js("js/register_selection.js") | $raw %]
 [% END %]
 
 [% INCLUDE 'intranet-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/js/register_selection.js b/koha-tmpl/intranet-tmpl/prog/js/register_selection.js
new file mode 100644
index 0000000000..b4d68590c6
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/js/register_selection.js
@@ -0,0 +1,27 @@
+$(document).ready(function() {
+    $("#branch").on("change", function() {
+        var selectedBranch = $("#branch").children(
+            "option:selected").val();
+
+        $("#register_id").children().each(function() {
+            // default to no-register
+            if ($(this).is("#noregister")) {
+                $(this).prop("selected", true)
+            }
+            // display branch registers
+            else if ($(this).hasClass(selectedBranch)) {
+                $(this).prop("disabled", false);
+                $(this).show();
+                // default to branch default if there is one
+                if ($(this).hasClass("default")) {
+                    $(this).prop("selected", true)
+                }
+            }
+            // hide non-branch registers
+            else {
+                $(this).hide();
+                $(this).prop("disabled", true);
+            }
+        });
+    });
+});
-- 
2.20.1