View | Details | Raw Unified | Return to bug 10212
Collapse All | Expand All

(-)a/C4/Utils/DataTables/ColumnsSettings.pm (+106 lines)
Line 0 Link Here
1
package C4::Utils::DataTables::ColumnsSettings;
2
3
use Modern::Perl;
4
use List::Util qw( first );
5
use YAML;
6
use C4::Context;
7
use Koha::Database;
8
9
sub get_yaml {
10
    my $yml_path =
11
      C4::Context->config('intranetdir') . '/admin/columns_settings.yml';
12
    my $yaml = eval { YAML::LoadFile($yml_path) };
13
    warn
14
"ERROR: the yaml file for DT::ColumnsSettings is not correctly formated: $@"
15
      if $@;
16
    return $yaml;
17
}
18
19
sub get_columns {
20
    my ( $module, $page, $tablename ) = @_;
21
22
    my $list = get_yaml;
23
24
    my $schema = Koha::Database->new->schema;
25
26
    my $rs = $schema->resultset('ColumnsSetting')->search(
27
        {
28
            module    => $module,
29
            page      => $page,
30
            tablename => $tablename,
31
        }
32
    );
33
34
    while ( my $c = $rs->next ) {
35
        my $column = first { $c->columnname eq $_->{columnname} }
36
        @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } };
37
        $column->{is_hidden}         = $c->is_hidden;
38
        $column->{cannot_be_toggled} = $c->cannot_be_toggled;
39
    }
40
41
    return $list->{modules}{$module}{$page}{$tablename} || [];
42
}
43
44
sub get_modules {
45
    my $list = get_yaml;
46
47
    my $schema = Koha::Database->new->schema;
48
    my $rs     = $schema->resultset('ColumnsSetting')->search;
49
50
    while ( my $c = $rs->next ) {
51
        my $column = first { $c->columnname eq $_->{columnname} }
52
        @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } };
53
        $column->{is_hidden}         = $c->is_hidden;
54
        $column->{cannot_be_toggled} = $c->cannot_be_toggled;
55
    }
56
57
    return $list->{modules};
58
}
59
60
sub update_columns {
61
    my ($params) = @_;
62
    my $columns = $params->{columns};
63
64
    my $schema = Koha::Database->new->schema;
65
66
    for my $c (@$columns) {
67
        $c->{is_hidden}         //= 0;
68
        $c->{cannot_be_toggled} //= 0;
69
70
        my $column = $schema->resultset('ColumnsSetting')->search(
71
            {
72
                module     => $c->{module},
73
                page       => $c->{page},
74
                tablename  => $c->{tablename},
75
                columnname => $c->{columnname},
76
            }
77
        );
78
        if ( $column->count ) {
79
            $column = $column->first;
80
            $column->update(
81
                {
82
                    module            => $c->{module},
83
                    page              => $c->{page},
84
                    tablename         => $c->{tablename},
85
                    columnname        => $c->{columnname},
86
                    is_hidden         => $c->{is_hidden},
87
                    cannot_be_toggled => $c->{cannot_be_toggled},
88
                }
89
            );
90
        }
91
        else {
92
            $schema->resultset('ColumnsSetting')->create(
93
                {
94
                    module            => $c->{module},
95
                    page              => $c->{page},
96
                    tablename         => $c->{tablename},
97
                    columnname        => $c->{columnname},
98
                    is_hidden         => $c->{is_hidden},
99
                    cannot_be_toggled => $c->{cannot_be_toggled},
100
                }
101
            );
102
        }
103
    }
104
}
105
106
1;
(-)a/Koha/Template/Plugin/ColumnsSettings.pm (+55 lines)
Line 0 Link Here
1
package Koha::Template::Plugin::ColumnsSettings;
2
3
# This file is part of Koha.
4
#
5
# Copyright BibLibre 2014
6
#
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.
11
#
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.
16
#
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>.
19
20
use Modern::Perl;
21
22
use Template::Plugin;
23
use base qw( Template::Plugin );
24
25
use YAML qw( LoadFile );
26
use JSON qw( to_json );
27
28
use C4::Context qw( config );
29
use C4::Utils::DataTables::ColumnsSettings;
30
31
=pod
32
33
This plugin allows to get the column configuration for a table.
34
35
First, include the line '[% USE Tables %]' at the top
36
of the template to enable the plugin.
37
38
To use, call ColumnsSettings.GetColumns with the module, the page and the table where the template is called.
39
40
For example: [% ColumnsSettings.GetColumns( 'circ', 'circulation', 'holdst' ) %]
41
42
=cut
43
44
sub GetColumns {
45
    my ( $self, $module, $page, $table, $format ) = @_;
46
    $format //= q{};
47
48
    my $columns = C4::Utils::DataTables::ColumnsSettings::get_columns( $module, $page, $table );
49
50
    return $format eq 'json'
51
        ? to_json( $columns )
52
        : $columns
53
}
54
55
1;
(-)a/admin/columns_settings.pl (+62 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use CGI;
5
use YAML qw( LoadFile );
6
use C4::Auth;
7
use C4::Context;
8
use C4::Output;
9
use C4::Utils::DataTables::ColumnsSettings qw( get_modules );
10
my $input = new CGI;
11
12
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
13
    {
14
        template_name   => "admin/columns_settings.tt",
15
        query           => $input,
16
        type            => "intranet",
17
        authnotrequired => 0,
18
        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
19
        debug           => 1,
20
    }
21
);
22
23
my $action = $input->param('action') // 'list';
24
25
if ( $action eq 'save' ) {
26
    my $module = $input->param('module');
27
    my @columnids = $input->param("columnid");
28
    my @columns;
29
    for my $columnid (@columnids) {
30
        next unless $columnid =~ m|^([^_]*)_([^_]*)_(.*)$|;
31
        my $is_hidden = $input->param( $columnid . '_hidden' ) // 0;
32
        my $cannot_be_toggled =
33
          $input->param( $columnid . '_cannot_be_toggled' ) // 0;
34
        push @columns,
35
          {
36
            module            => $module,
37
            page              => $1,
38
            tablename         => $2,
39
            columnname        => $3,
40
            is_hidden         => $is_hidden,
41
            cannot_be_toggled => $cannot_be_toggled,
42
          };
43
    }
44
45
    C4::Utils::DataTables::ColumnsSettings::update_columns(
46
        {
47
            columns => \@columns,
48
        }
49
    );
50
51
    $action = 'list';
52
}
53
54
if ( $action eq 'list' ) {
55
    my $modules = C4::Utils::DataTables::ColumnsSettings::get_modules;
56
    $template->param(
57
        panel   => ( $input->param('panel') || 0 ),
58
        modules => $modules,
59
    );
60
}
61
62
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/admin/columns_settings.yml (+10 lines)
Line 0 Link Here
1
modules:
2
  module_name:
3
    page_name:
4
      table_id:
5
        -
6
          columnname: my_column_name
7
        -
8
          columnname: my_other_column_name
9
          cannot_be_toggled: 1
10
          cannot_be_modified: 1
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (+1 lines)
Lines 62-67 Link Here
62
	<!-- <li><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></li> -->
62
	<!-- <li><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></li> -->
63
    <li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 client targets</a></li>
63
    <li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 client targets</a></li>
64
    <li><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></li>
64
    <li><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></li>
65
    <li><a href="/cgi-bin/koha/admin/columns_settings.pl">Columns settings</a></li>
65
</ul>
66
</ul>
66
</div>
67
</div>
67
</div>
68
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc (+27 lines)
Line 0 Link Here
1
[% USE ColumnsSettings %]
2
3
<script type="text/javascript">
4
function KohaTable(selector, dt_parameters, columns_settings) {
5
    var id = 0;
6
    var hidden_ids = [];
7
    var excluded_ids = [];
8
    $(columns_settings).each( function() {
9
        if ( this['is_hidden'] == "1" ) {
10
            hidden_ids.push( id );
11
        }
12
        if ( this['cannot_be_toggled'] == "1" ) {
13
            excluded_ids.push( id );
14
        }
15
        id++;
16
    });
17
    dt_parameters[ "oColVis" ] = { "aiExclude": excluded_ids };
18
    var table = $(selector).dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
19
20
    $(hidden_ids).each(function(index, value) {
21
        table.fnSetColumnVis( value, false );
22
    });
23
24
    return table;
25
}
26
27
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js (-1 / +1 lines)
Lines 23-29 var dataTablesDefaults = { Link Here
23
        "sSearch"           : window.MSG_DT_SEARCH || "Search:",
23
        "sSearch"           : window.MSG_DT_SEARCH || "Search:",
24
        "sZeroRecords"      : window.MSG_DT_ZERO_RECORDS || "No matching records found"
24
        "sZeroRecords"      : window.MSG_DT_ZERO_RECORDS || "No matching records found"
25
    },
25
    },
26
    "sDom": '<"top pager"ilpf>tr<"bottom pager"ip>',
26
    "sDom": 'C<"top pager"ilpf>tr<"bottom pager"ip>',
27
    "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, window.MSG_DT_ALL || "All"]],
27
    "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, window.MSG_DT_ALL || "All"]],
28
    "iDisplayLength": 20
28
    "iDisplayLength": 20
29
};
29
};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+2 lines)
Lines 104-109 Link Here
104
	<dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
104
	<dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
105
    <dt><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></dt>
105
    <dt><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></dt>
106
    <dd>Choose which plugins to use to suggest searches to patrons and staff.</dd>
106
    <dd>Choose which plugins to use to suggest searches to patrons and staff.</dd>
107
    <dt><a href="/cgi-bin/koha/admin/columns_settings.pl">Configure columns</a></dt>
108
    <dd>Hide or show columns for tables.</dd>
107
</dl>
109
</dl>
108
</div>
110
</div>
109
111
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/columns_settings.tt (-1 / +144 lines)
Line 0 Link Here
0
- 
1
[% SET panel_id = 0 %]
2
[% BLOCK pagelist %]
3
<div class="pagelist">
4
  <form method="post" action="/cgi-bin/koha/admin/columns_settings.pl">
5
    <input type="hidden" name="action" value="save" />
6
    <input type="hidden" name="module" value="[% modulename %]" />
7
    <input type="hidden" name="panel" value="[% panel_id %]" />
8
    [% SET panel_id = panel_id + 1 %]
9
    [% IF module.keys and module.keys.size > 0 %]
10
      [% FOR pagename IN module.keys %]
11
        <h5>[% pagename %]</h5>
12
        [% SET tables = module %]
13
        [% IF tables.$pagename.keys and tables.$pagename.keys.size > 0 %]
14
          [% FOR tablename IN tables.$pagename.keys.sort %]
15
            <table>
16
              <caption>[% tablename %]</caption>
17
              <thead><tr><th>Column name</th><th>Is Hidden by default</th><th>Cannot be toggled</th></tr></thead>
18
              <tbody>
19
              [% FOR column IN tables.$pagename.$tablename %]
20
                <tr>
21
                  <td>
22
                    [% column.columnname %]
23
                    <input type="hidden" name="columnid" value="[% pagename %]_[% tablename %]_[% column.columnname %]" />
24
                  </td>
25
                  <td>
26
                    [% IF column.is_hidden %]
27
                      [% IF column.cannot_be_modified %]
28
                        <input type="checkbox" name="[% pagename %]_[% tablename %]_[% column.columnname %]_hidden" value="1" checked="checked" disabled="disabled" />
29
                        <input type="hidden" name="[% pagename %]_[% tablename %]_[% column.columnname %]_hidden" value="1" />
30
                      [% ELSE %]
31
                        <input type="checkbox" name="[% pagename %]_[% tablename %]_[% column.columnname %]_hidden" value="1" checked="checked" />
32
                      [% END %]
33
                    [% ELSE %]
34
                      [% IF column.cannot_be_modified %]
35
                        <input type="checkbox" name="[% pagename %]_[% tablename %]_[% column.columnname %]_hidden" value="1" disabled="disabled" />
36
                        <input type="hidden" name="[% pagename %]_[% tablename %]_[% column.columnname %]_hidden" value="0" />
37
                      [% ELSE %]
38
                        <input type="checkbox" name="[% pagename %]_[% tablename %]_[% column.columnname %]_hidden" value="1" />
39
                      [% END %]
40
                    [% END %]
41
                  </td>
42
                  <td>
43
                    [% IF column.cannot_be_toggled %]
44
                      [% IF column.cannot_be_modified %]
45
                        <input type="checkbox" name="[% pagename %]_[% tablename %]_[% column.columnname %]_cannot_be_toggled" value="1" checked="checked" disabled="disabled" />
46
                        <input type="hidden" name="[% pagename %]_[% tablename %]_[% column.columnname %]_cannot_be_toggled" value="1" />
47
                      [% ELSE %]
48
                        <input type="checkbox" name="[% pagename %]_[% tablename %]_[% column.columnname %]_cannot_be_toggled" value="1" checked="checked" />
49
                      [% END %]
50
                    [% ELSE %]
51
                      [% IF column.cannot_be_modified %]
52
                        <input type="checkbox" name="[% pagename %]_[% tablename %]_[% column.columnname %]_cannot_be_toggled" value="1" disabled="disabled" />
53
                        <input type="hidden" name="[% pagename %]_[% tablename %]_[% column.columnname %]_cannot_be_toggled" value="0" />
54
                      [% ELSE %]
55
                        <input type="checkbox" name="[% pagename %]_[% tablename %]_[% column.columnname %]_cannot_be_toggled" value="1" />
56
                      [% END %]
57
                    [% END %]
58
                  </td>
59
                </tr>
60
              [% END %]
61
              </tbody>
62
            </table>
63
          [% END %]
64
          <input type="submit" value="Save" />
65
        [% ELSE %]
66
          There is no table to configure for this module.
67
        [% END %]
68
      [% END %]
69
    [% ELSE %]
70
        There is no page using the table configuration in this module.
71
    [% END %]
72
  </form>
73
</div>
74
[% END %]
75
76
[% INCLUDE 'doc-head-open.inc' %]
77
<title>Koha &rsaquo; Administration &rsaquo; Columns settings</title>
78
[% INCLUDE 'doc-head-close.inc' %]
79
<script type="text/javascript">
80
    $(document).ready( function() {
81
        var accordion = $( "#modules" ).accordion({
82
            collapsible: true,
83
            autoHeight: false,
84
            header: "h3",
85
            active: [% panel %]
86
        });
87
    });
88
</script>
89
</head>
90
<body id="admin_tables" class="admin">
91
[% INCLUDE 'header.inc' %]
92
[% INCLUDE 'cat-search.inc' %]
93
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Columns settings</div>
94
95
<div id="doc3" class="yui-t2">
96
  <div id="bd">
97
    <div id="yui-main">
98
      <div class="yui-b">
99
        <h2>Columns settings</h2>
100
        <div id="modules">
101
          <h3><a href="#acqui">Acquisition</a></h3>
102
          <div id="acqui">
103
            <h4>Acquisition tables</h4>
104
            [% PROCESS pagelist module=modules.acqui modulename="acqui" %]
105
          </div>
106
107
          <h3><a href="#admin">Administration</a></h3>
108
          <div id="admin">
109
            <h4>Administration tables</h4>
110
            [% PROCESS pagelist module=modules.admin modulename="admin" %]
111
          </div>
112
113
          <h3><a href="#authorities">Authorities</a></h3>
114
          <div id="authorities">
115
            <h4>Authorities tables</h4>
116
            [% PROCESS pagelist module=modules.authorities modulename="authorities" %]
117
          </div>
118
119
          <h3><a href="#catalog">Catalog</a></h3>
120
          <div id="catalogue">
121
            <h4>Catalogue tables</h4>
122
            [% PROCESS pagelist module=modules.catalogue modulename="catalogue" %]
123
          </div>
124
125
          <h3><a href="#cataloguing">Cataloging</a></h3>
126
          <div id="cataloguing">
127
            <h4>Cataloguing tables</h4>
128
            [% PROCESS pagelist module=modules.cataloguing modulename="cataloguing" %]
129
          </div>
130
131
          <h3><a href="#circulation">Circulation</a></h3>
132
          <div id="circulation">
133
            <h4>Circulation tables</h4>
134
            [% PROCESS pagelist module=modules.circ modulename="circ" %]
135
          </div>
136
        </div>
137
      </div>
138
    </div>
139
140
    <div class="yui-b">
141
      [% INCLUDE 'admin-menu.inc' %]
142
    </div>
143
  </div>
144
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 10212