From 9ca7881157bcc0f09bc5bf394d050f6375cabf53 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Tue, 29 Oct 2024 10:42:22 +0100
Subject: [PATCH] Bug 33484: checkouts - Move visibility handling to
 table_settings

We need to set is_hidden for the column we want to force hide (depending
on system config)

This patch fixes t/db_dependent/selenium/regressions.t

Obviously there will be incorrect behaviours if we restore from a state
and that the settings have been modified in the meanwhile.
Not sure we can deal with that properly.
---
 .../prog/en/modules/circ/circulation.tt       |  2 +-
 koha-tmpl/intranet-tmpl/prog/js/checkouts.js  | 22 +++++++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
index e96fa9f1488..bd2fce08fbf 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
@@ -1007,7 +1007,7 @@
         var theme = "[% theme | html %]";
         var borrowernumber = "[% patron.borrowernumber | html %]";
         var branchcode = "[% branch | html %]";
-        var exports_enabled = "[% Koha.Preference('ExportCircHistory') | html %]";
+        var exports_enabled = [% Koha.Preference('ExportCircHistory') ? 1 : 0 | html %];
         var AllowRenewalLimitOverride = [% (CAN_user_circulate_override_renewals && Koha.Preference('AllowRenewalLimitOverride') )? 1: 0 | html %];
         var AllowRenewalOnHoldOverride = [% (CAN_user_circulate_override_renewals && Koha.Preference('AllowRenewalOnHoldOverride') )? 1: 0 | html %];
         var AllowCirculate = [% (CAN_user_circulate_circulate_remaining_permissions)? 1 : 0 | html %];
diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
index a27fd722cfb..19b16d33311 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
@@ -32,6 +32,24 @@ function LoadIssuesTable() {
     $('#issues-table').show();
     $('#issues-table-actions').show();
     var msg_loading = __('Loading... you may continue scanning.');
+    if (!AllowCirculate) {
+        table_settings_issues_table.columns.find(
+            c => c.columnname == "renew"
+        ).is_hidden = 42;
+        table_settings_issues_table.columns.find(
+            c => c.columnname == "checkin"
+        ).is_hidden = 1;
+    }
+    if (!ClaimReturnedLostValue) {
+        table_settings_issues_table.columns.find(
+            c => c.columnname == "claims_returned"
+        ).is_hidden = 1;
+    }
+    if (!exports_enabled) {
+        table_settings_issues_table.columns.find(
+            c => c.columnname == "export"
+        ).is_hidden = 1;
+    }
     issuesTable = KohaTable("issues-table", {
         "language":  {
             "emptyTable":  msg_loading,
@@ -224,7 +242,6 @@ function LoadIssuesTable() {
             },
             {
                 "orderable":  false,
-                "visible":  AllowCirculate ? true : false,
                 "data": function ( oObj ) {
                     var content = "";
                     var msg = "";
@@ -363,7 +380,6 @@ function LoadIssuesTable() {
             },
             {
                 "orderable":  false,
-                "visible":  AllowCirculate ? true : false,
                 "data": function ( oObj ) {
                     if ( oObj.can_renew_error == "recalled" ) {
                         return "<a href='/cgi-bin/koha/recalls/request.pl?biblionumber=" + oObj.biblionumber + "'>" + __("Recalled") + "</a>";
@@ -377,7 +393,6 @@ function LoadIssuesTable() {
                 }
             },
             {
-                "visible":  ClaimReturnedLostValue ? true : false,
                 "orderable":  false,
                 "data": function ( oObj ) {
                     let content = "";
@@ -393,7 +408,6 @@ function LoadIssuesTable() {
                 }
             },
             {
-                "visible":  exports_enabled == 1 ? true : false,
                 "orderable":  false,
                 "data": function ( oObj ) {
                     var s = "<input type='checkbox' name='itemnumbers' value='" + oObj.itemnumber + "' style='visibility:hidden;' />";
-- 
2.34.1