From 72fec430d7658a7317975ac8bbad8edf35488cde Mon Sep 17 00:00:00 2001
From: Lucas Gass <lucas@bywatersolutions.com>
Date: Fri, 4 Feb 2022 22:14:58 +0000
Subject: [PATCH] Bug 30031: Add table settings to staff lists (op=view)

To test:
1. Apply patch and restart_all
2. Create a list
3. GO to Administration > Table settings
4. In Table settings look under Catalog for lists.
6. The search results table should be listed, with the ability to hide the author, date_added, or call_number
5. Go to the view of your list ( /cgi-bin/koha/virtualshelves/shelves.pl?op=view&shelfnumber=1 )
7. Make sure you can hide the columns properly. ( The checkbox and Title columns should not be hidable )

Signed-off-by: David Nind <david@davidnind.com>
---
 admin/columns_settings.yml                     | 18 ++++++++++++++++++
 .../prog/en/modules/virtualshelves/shelves.tt  | 13 ++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml
index 9b0982d264..93003a8835 100644
--- a/admin/columns_settings.yml
+++ b/admin/columns_settings.yml
@@ -299,6 +299,24 @@ modules:
               cannot_be_modified: 1
 
   catalogue:
+    lists:
+      searchresults:
+        columns:
+            -
+              columnname: checkbox
+              cannot_be_toggled: 1
+              cannot_be_modified: 1
+            -
+              columnname: title
+              cannot_be_toggled: 1
+              cannot_be_modified: 1
+            -
+              columnname: author
+            -
+              columnname: date_added
+            -
+              columnname: call_number
+
     detail:
       holdings_table:
         columns:
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 09550fe2b4..8e31a2cb30 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
@@ -2,6 +2,7 @@
 [% USE Asset %]
 [% USE Koha %]
 [% USE KohaDates %]
+[% USE TablesSettings %]
 [% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>
@@ -500,12 +501,12 @@
 
     [% IF op == 'view' %]
         [% Asset.js("lib/hc-sticky.js") | $raw %]
+        [% INCLUDE 'columns_settings.inc' %]
     [% END %]
     <script>
         var MSG_NO_ITEM_SELECTED = _("Nothing is selected.");
         var MSG_REMOVE_FROM_LIST = _("Are you sure you want to remove these items from the list?");
         var MSG_CONFIRM_DELETE_LIST = _("Are you sure you want to remove this list?");
-
         [% IF op == 'list' %]
             $(document).ready(function(){
                 var public = [% public | html %];
@@ -608,6 +609,16 @@
         [% IF shelf AND op == 'view' %]
             var Sticky;
             $(document).ready(function(){
+                var column_settings = [% TablesSettings.GetColumns( 'catalogue', 'lists', 'searchresults', 'json' ) | $raw %];
+                KohaTable("searchresults", {
+                    "dom": 'lrt',
+                    "sorting": [[ 1, "asc" ]],
+                    "autoWidth": false,
+                    "asColumnDefs": [
+                        { "aTargets": [ 1 ], "sType": "nsb-nse" },
+                    ]
+                }, column_settings );
+
                 Sticky = $("#searchheader");
                 Sticky.hcSticky({
                     stickTo: "#listform",
-- 
2.30.2