1 package Koha::Template::Plugin::TablesSettings;
3 # This file is part of Koha.
5 # Copyright BibLibre 2014
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 Koha::Template::Plugin::TablesSettings
26 [% USE TablesSettings %]
30 [% UNLESS TablesSettings.is_hidden( 'module', 'page', 'table', 'column') %]
31 <th id="column" data-colname="column">Column title</th>
36 [% UNLESS TablesSettings.is_hidden( 'module', 'page', 'table', 'column') %]
37 <td>[% row.column %]</td>
43 var columns_settings = [% TablesSettings.GetColumns( 'module', 'page', 'table', 'json' ) | $raw %];
44 var table = KohaTable("id", { "autoWidth": false }, columns_settings );
47 This plugin allows to get the column configuration for a table. It should be used both in table markup
48 and as the input for datatables visibility settings to take full effect.
55 use base qw( Template::Plugin );
57 use JSON qw( to_json );
60 use C4::Utils::DataTables::TablesSettings;
67 var tables_settings = [% TablesSettings.GetColumns( 'module', 'page', 'table', 'json' ) | $raw %];
68 var table = KohaTable("id", { "autoWidth": false }, tables_settings );
71 Used to get the full column settings configuration for datatables, usually requires a format of 'json' to pass into
72 datatables instantiator.
78 var columns_settings = [% TablesSettings.GetColumns( module, page, table 'json' ) | $raw%]
80 This method is usually be used to retrieve the columns settings for a DataTable init.
82 So the 'json' format will be provided and the columns_settings JS var will be
83 passed as argument of the constructor.
88 my ( $self, $module, $page, $table, $format ) = @_;
91 my $columns = C4::Utils::DataTables::TablesSettings::get_columns( $module, $page, $table );
93 return $format eq 'json'
100 [% UNLESS TablesSettings.is_hidden( 'module', 'page', 'table', 'column') %]
101 <th id="column" data-colname="column">Column title</th>
104 Used to fetch an individual columns display status so we can fully hide a column in the markup for cases where
105 it may contain confidential information and should be fully hidden rather than just hidden from display.
110 my ( $self, $module, $page, $table, $column_name ) = @_;
111 my $columns = C4::Utils::DataTables::TablesSettings::get_columns( $module, $page, $table );
112 foreach my $keys(@$columns){
113 if($keys->{'columnname'} eq $column_name){
114 return $keys->{'is_hidden'};
120 =head3 GetTableSettings
122 [% SET table_settings = GetTableSettings( module, page, table ) %]
124 This method is used to retrieve the tables settings (like table_settings.default_display_length and
125 table_settings.default_sort_order).
126 They can be passed to the DataTable constructor (for iDisplayLength and order parameters)
130 sub GetTableSettings {
131 my ( $self, $module, $page, $table, $format ) = @_;
134 my $settings = C4::Utils::DataTables::TablesSettings::get_table_settings( $module, $page, $table );
135 my $columns = C4::Utils::DataTables::TablesSettings::get_columns( $module, $page, $table );
145 return $format eq 'json'
146 ? to_json( $settings || {} )