From 0f83b0fe20a80b52060106dd2882fbf2f711fc62 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 16 Dec 2021 11:34:02 +0100 Subject: [PATCH] Bug 29648: Improve existing code We already have 2 tables that are configurable, on acqui/basket and reports/orders_by_budget. This patch is modifying a bit the existing code to transfer the responsability/logic to the KohaTable constructor instead of the template that is creating the object. Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers --- C4/Utils/DataTables/TablesSettings.pm | 8 +++++++- Koha/Template/Plugin/TablesSettings.pm | 3 +++ .../prog/en/includes/columns_settings.inc | 11 ++++++++++- .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 13 +++++-------- .../prog/en/modules/reports/orders_by_budget.tt | 7 ++----- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/C4/Utils/DataTables/TablesSettings.pm b/C4/Utils/DataTables/TablesSettings.pm index 79c9417569..13157a71a3 100644 --- a/C4/Utils/DataTables/TablesSettings.pm +++ b/C4/Utils/DataTables/TablesSettings.pm @@ -88,7 +88,13 @@ sub get_table_settings { tablename => $tablename, } )->next; - return $rs ? $rs : $list->{modules}{$module}{$page}{$tablename}; + + return { + default_display_length => $rs ? $rs->default_display_length + : $list->{modules}{$module}{$page}{$tablename}{default_display_length}, + default_sort_order => $rs ? $rs->default_sort_order + : $list->{modules}{$module}{$page}{$tablename}{default_sort_order} + }; } sub get_modules { diff --git a/Koha/Template/Plugin/TablesSettings.pm b/Koha/Template/Plugin/TablesSettings.pm index 25df84e0ae..720b67445a 100644 --- a/Koha/Template/Plugin/TablesSettings.pm +++ b/Koha/Template/Plugin/TablesSettings.pm @@ -132,6 +132,9 @@ sub GetTableSettings { $format //= q{}; my $settings = C4::Utils::DataTables::TablesSettings::get_table_settings( $module, $page, $table ); + my $columns = C4::Utils::DataTables::TablesSettings::get_columns( $module, $page, $table ); + + $settings->{columns} = $columns; return $format eq 'json' ? to_json( $settings || {} ) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc index 42d4fb09bc..4d61b10534 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc @@ -3,12 +3,14 @@