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

(-)a/C4/Utils/DataTables/ColumnsSettings.pm (-27 / +53 lines)
Lines 6-13 use YAML; Link Here
6
use C4::Context;
6
use C4::Context;
7
use Koha::Database;
7
use Koha::Database;
8
use Koha::Caches;
8
use Koha::Caches;
9
use Koha::UsersColumnsSettings;
10
use Koha::UsersColumnsSetting;
11
use C4::Utils::DataTables::ColumnsSettings::Dynamic;
9
12
10
sub get_yaml {
13
sub get_yaml {
14
    my ( $module, $page, $tablename ) = @_;
15
11
    my $yml_path = C4::Context->config('intranetdir') . '/admin/columns_settings.yml';
16
    my $yml_path = C4::Context->config('intranetdir') . '/admin/columns_settings.yml';
12
    my $cache = Koha::Caches->get_instance();
17
    my $cache = Koha::Caches->get_instance();
13
    my $yaml  = $cache->get_from_cache('ColumnsSettingsYaml');
18
    my $yaml  = $cache->get_from_cache('ColumnsSettingsYaml');
Lines 19-60 sub get_yaml { Link Here
19
        $cache->set_in_cache( 'ColumnsSettingsYaml', $yaml, { expiry => 3600 } );
24
        $cache->set_in_cache( 'ColumnsSettingsYaml', $yaml, { expiry => 3600 } );
20
    }
25
    }
21
26
22
    return $yaml;
27
    unless ( $module || $page || $tablename ) {
28
        return $yaml;
29
    }
30
31
    if (my $list = $yaml->{modules}{$module}{$page}{$tablename}) {
32
        return $list;
33
    }
34
35
    return '';
23
}
36
}
24
37
25
sub get_columns {
38
sub get_columns {
26
    my ( $module, $page, $tablename ) = @_;
39
    my ( $module, $page, $tablename, $additional_param ) = @_;
27
40
28
    my $list = get_yaml;
41
    my $columns = get_yaml($module, $page, $tablename);
42
    # Fall back on a dynamic way to retrieve default columns.
43
    unless ($columns) {
44
        my $sub = $module . '_' . $page . '_' . $tablename;
45
        if (my $s = C4::Utils::DataTables::ColumnsSettings::Dynamic->can($sub)) {
46
            $columns = $s->($additional_param);
47
        }
48
    }
29
49
30
    my $schema = Koha::Database->new->schema;
50
    my $schema = Koha::Database->new->schema;
31
51
    my $borrowernumber = C4::Context::userenv->{number};
32
    my $rs = $schema->resultset('ColumnsSetting')->search(
52
33
        {
53
    foreach my $c (@$columns) {
34
            module    => $module,
54
        # User settings.
35
            page      => $page,
55
        my $user_column = Koha::UsersColumnsSettings->search({
36
            tablename => $tablename,
56
            borrowernumber   => $borrowernumber,
57
            module           => $module,
58
            page             => $page,
59
            tablename        => $tablename,
60
            columnname       => $c->{columnname},
61
            additional_param => $additional_param
62
        })->next();
63
64
        if ($user_column) {
65
            $c->{is_hidden} = $user_column->is_hidden || 0;
37
        }
66
        }
38
    );
39
40
    while ( my $c = $rs->next ) {
41
        my $column = first { $c->columnname eq $_->{columnname} }
42
        @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } };
43
        $column->{is_hidden}         = $c->is_hidden;
44
        $column->{cannot_be_toggled} = $c->cannot_be_toggled;
45
    }
46
67
47
    my $columns = $list->{modules}{$module}{$page}{$tablename} || [];
68
        # Admin settings.
69
        my $column = $schema->resultset('ColumnsSetting')->search({
70
            module     => $module,
71
            page       => $page,
72
            tablename  => $tablename,
73
            columnname => $c->{columnname},
74
        })->next();
48
75
49
    # Assign default value if does not exist
76
        if ($column) {
50
    $columns = [ map {
77
            $c->{cannot_be_toggled} = $column->cannot_be_toggled;
51
        {
52
            cannot_be_toggled => exists $_->{cannot_be_toggled} ? $_->{cannot_be_toggled} : 0,
53
            cannot_be_modified => exists $_->{cannot_be_modified} ? $_->{cannot_be_modified} : 0,
54
            is_hidden => exists $_->{is_hidden} ? $_->{is_hidden} : 0,
55
            columnname => $_->{columnname},
56
        }
78
        }
57
    } @$columns ];
79
80
        $c->{is_hidden} ||= 0;
81
        $c->{cannot_be_toggled} ||= 0;
82
        $c->{cannot_be_modified} ||= 0;
83
    }
58
84
59
    return $columns;
85
    return $columns;
60
}
86
}
(-)a/C4/Utils/DataTables/ColumnsSettings/Dynamic.pm (+74 lines)
Line 0 Link Here
1
package C4::Utils::DataTables::ColumnsSettings::Dynamic;
2
3
# Copyright 2017 BibLibre
4
#
5
# This file is part of Koha.
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
require Exporter;
22
23
use vars qw(@ISA @EXPORT);
24
25
use C4::Biblio;
26
use Koha::Database;
27
28
BEGIN {
29
30
    @ISA        = qw(Exporter);
31
    @EXPORT     = qw(dt_build_orderby dt_build_having dt_get_params dt_build_query);
32
}
33
34
=head1 NAME
35
36
C4::Utils::DataTables::ColumnsSettings::Dynamic - Subs providing dynamic columns for jquery datatables.
37
38
=head1 SYNOPSIS
39
40
use C4::Utils::DataTables::ColumnsSettings::Dynamic;
41
42
=head1 DESCRIPTION
43
44
This modules is intented to contain subs that return columns for KohaTable with columns setting plugin.
45
46
=head1 FUNCTIONS
47
48
=head2 catalogue_marcdetail_itemst
49
50
    my $columns = catalogue_marcdetail_itemst($frameworkcode);
51
    This function returns items columns depending on the framework.
52
53
=cut
54
55
sub catalogue_marcdetail_itemst {
56
    my ($frameworkcode) = @_;
57
58
    my $columns;
59
    my $tagslib = C4::Biblio::GetMarcStructure( 1, $frameworkcode );
60
    my ($itemfield) = C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', $frameworkcode );
61
    foreach my $subfield ( keys %{ $tagslib->{$itemfield} } ) {
62
        next unless $subfield =~ /^\w$/;
63
        next if ( $tagslib->{$itemfield}->{$subfield}->{tab} ne 10 );
64
        next if ( $tagslib->{$itemfield}->{$subfield}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/ );
65
66
        push @$columns, {
67
            columnname         => $subfield,
68
            is_hidden          => 0,
69
        }
70
    }
71
    return $columns;
72
}
73
74
1;
(-)a/Koha/REST/V1/UserColumnsSettings.pm (+62 lines)
Line 0 Link Here
1
package Koha::REST::V1::UserColumnsSettings;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use C4::Auth qw( haspermission );
23
use Koha::UsersColumnsSetting;
24
use Koha::UsersColumnsSettings;
25
26
use Try::Tiny;
27
28
sub add {
29
    my ( $c, $args, $cb ) = @_;
30
31
    my $added;
32
    my $body = $args->{body};
33
    foreach my $column (@{ $body->{columns} }) {
34
        my $params = {
35
            borrowernumber => $body->{'borrowernumber'},
36
            module => $body->{module},
37
            page => $body->{page},
38
            tablename => $body->{tablename},
39
            additional_param => $body->{additional_param},
40
            columnname => $column->{name},
41
        };
42
43
        my $user_column;
44
        unless ( $user_column = Koha::UsersColumnsSettings->search($params)->next ) {
45
            $user_column = Koha::UsersColumnsSetting->new($params);
46
        }
47
        $user_column->is_hidden($column->{is_hidden});
48
49
        try {
50
            $user_column->store;
51
            push @$added, $user_column->unblessed;
52
        }
53
        catch {
54
            warn $_;
55
            return $c->$cb( $_, 500);
56
        };
57
    }
58
59
    return $c->$cb( { added => $added }, 200);
60
}
61
62
1;
(-)a/Koha/Template/Plugin/ColumnsSettings.pm (-2 / +3 lines)
Lines 27-32 use JSON qw( to_json ); Link Here
27
27
28
use C4::Context qw( config );
28
use C4::Context qw( config );
29
use C4::Utils::DataTables::ColumnsSettings;
29
use C4::Utils::DataTables::ColumnsSettings;
30
use C4::Utils::DataTables::ColumnsSettings::Dynamic;
30
31
31
=pod
32
=pod
32
33
Lines 42-51 For example: [% ColumnsSettings.GetColumns( 'circ', 'circulation', 'holdst' ) %] Link Here
42
=cut
43
=cut
43
44
44
sub GetColumns {
45
sub GetColumns {
45
    my ( $self, $module, $page, $table, $format ) = @_;
46
    my ( $self, $module, $page, $table, $format, $additional_params ) = @_;
46
    $format //= q{};
47
    $format //= q{};
47
48
48
    my $columns = C4::Utils::DataTables::ColumnsSettings::get_columns( $module, $page, $table );
49
    my $columns = C4::Utils::DataTables::ColumnsSettings::get_columns( $module, $page, $table, $additional_params );
49
50
50
    return $format eq 'json'
51
    return $format eq 'json'
51
        ? to_json( $columns )
52
        ? to_json( $columns )
(-)a/Koha/UsersColumnsSetting.pm (+50 lines)
Line 0 Link Here
1
package Koha::UsersColumnsSetting;
2
3
# Copyright Biblibre 2017
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::UsersColumnsSetting - Koha UsersColumnsSetting Object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'UsersColumnsSetting';
42
}
43
44
=head1 AUTHOR
45
46
Alex Arnaud <alex.arnaud@biblibre.com>
47
48
=cut
49
50
1;
(-)a/Koha/UsersColumnsSettings.pm (+54 lines)
Line 0 Link Here
1
package Koha::UsersColumnsSettings;
2
3
# Copyright Biblibre 2017
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw(Koha::Objects);
25
26
=head1 NAME
27
28
Koha::UsersColumnsSettings - Koha UsersColumnsSettings Object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'UsersColumnsSetting';
42
}
43
44
sub object_class {
45
    return 'Koha::UsersColumnsSetting';
46
}
47
48
=head1 AUTHOR
49
50
Alex Arnaud <alex.arnaud@biblibre.com>
51
52
=cut
53
54
1;
(-)a/api/v1/swagger/definitions.json (+6 lines)
Lines 13-17 Link Here
13
  },
13
  },
14
  "error": {
14
  "error": {
15
    "$ref": "definitions/error.json"
15
    "$ref": "definitions/error.json"
16
  },
17
  "user_columns_settings": {
18
    "$ref": "definitions/user_columns_settings.json"
19
  },
20
  "column": {
21
    "$ref": "definitions/column.json"
16
  }
22
  }
17
}
23
}
(-)a/api/v1/swagger/definitions/column.json (+13 lines)
Line 0 Link Here
1
{
2
    "type": "object",
3
    "properties": {
4
        "name": {
5
            "description": "Column name",
6
            "type": "string"
7
        },
8
        "is_hidden": {
9
            "description": "Column is hidden or not",
10
            "type": "boolean"
11
        }
12
    }
13
}
(-)a/api/v1/swagger/definitions/user_columns_settings.json (+31 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "borrowernumber": {
5
      "$ref": "../x-primitives.json#/borrowernumber"
6
    },
7
    "module": {
8
      "description": "Module name",
9
      "type": "string"
10
    },
11
    "page": {
12
      "description": "Page name",
13
      "type": "string"
14
    },
15
    "tablename": {
16
      "description": "Table name",
17
      "type": "string"
18
    },
19
    "additional_param": {
20
      "description": "Additional parameter",
21
      "type": "string"
22
    },
23
    "columns": {
24
      "description": "Columns list",
25
      "type": "array",
26
      "items": {
27
        "$ref": "column.json"
28
      }
29
    }
30
  }
31
}
(-)a/api/v1/swagger/paths.json (+3 lines)
Lines 16-20 Link Here
16
  },
16
  },
17
  "/patrons/{borrowernumber}": {
17
  "/patrons/{borrowernumber}": {
18
    "$ref": "paths/patrons.json#/~1patrons~1{borrowernumber}"
18
    "$ref": "paths/patrons.json#/~1patrons~1{borrowernumber}"
19
  },
20
  "/user_columns_settings": {
21
    "$ref": "paths/user_columns_settings.json#/~1user_columns_settings"
19
  }
22
  }
20
}
23
}
(-)a/api/v1/swagger/paths/user_columns_settings.json (+46 lines)
Line 0 Link Here
1
{
2
  "/user_columns_settings": {
3
    "post": {
4
      "x-mojo-controller": "Koha::REST::V1::UserColumnsSettings",
5
      "operationId": "add",
6
      "tags": ["user_columns_settings"],
7
      "parameters": [{
8
        "name": "body",
9
        "in": "body",
10
        "description": "A JSON object containing informations about the columns settings",
11
        "required": true,
12
        "schema": {
13
          "$ref": "../definitions.json#/user_columns_settings"
14
        }
15
      }],
16
      "produces": [
17
        "application/json"
18
      ],
19
      "responses": {
20
        "200": {
21
          "description": "Columns settings added",
22
          "schema": {
23
            "$ref": "../definitions.json#/user_columns_settings"
24
          }
25
        },
26
        "403": {
27
          "description": "Access forbidden",
28
          "schema": {
29
            "$ref": "../definitions.json#/error"
30
          }
31
        },
32
        "500": {
33
          "description": "Internal error",
34
          "schema": {
35
            "$ref": "../definitions.json#/error"
36
          }
37
        }
38
      },
39
      "x-koha-authorization": {
40
        "permissions": {
41
          "catalogue": "1"
42
        }
43
      }
44
    }
45
  }
46
}
(-)a/catalogue/MARCdetail.pl (-1 / +4 lines)
Lines 85-90 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
85
        debug           => 1,
85
        debug           => 1,
86
    }
86
    }
87
);
87
);
88
$template->param(
89
    frameworkcode   => $frameworkcode
90
);
88
91
89
my $record = GetMarcBiblio($biblionumber, 1);
92
my $record = GetMarcBiblio($biblionumber, 1);
90
$template->param( ocoins => GetCOinSBiblio($record) );
93
$template->param( ocoins => GetCOinSBiblio($record) );
Lines 281-287 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbran Link Here
281
# fill item info
284
# fill item info
282
my @item_header_loop;
285
my @item_header_loop;
283
for my $subfield_code ( @item_subfield_codes ) {
286
for my $subfield_code ( @item_subfield_codes ) {
284
    push @item_header_loop, $witness{$subfield_code};
287
    push @item_header_loop, { colname => $subfield_code, label => $witness{$subfield_code} };
285
    for my $item_data ( @item_loop ) {
288
    for my $item_data ( @item_loop ) {
286
        $item_data->{$subfield_code} ||= "&nbsp;"
289
        $item_data->{$subfield_code} ||= "&nbsp;"
287
    }
290
    }
(-)a/installer/data/mysql/atomicupdate/add-table-users_columns_settings.sql (+13 lines)
Line 0 Link Here
1
CREATE TABLE IF NOT EXISTS users_columns_settings (
2
    id int(11) NOT NULL auto_increment,
3
    borrowernumber int(11) NOT NULL,
4
    module varchar(50) NOT NULL,
5
    page varchar(50) NOT NULL,
6
    tablename varchar(50) NOT NULL,
7
    additional_param varchar(255) NOT NULL,
8
    columnname varchar(50) NOT NULL,
9
    is_hidden int(1) NOT NULL DEFAULT 0,
10
    PRIMARY KEY(id),
11
    UNIQUE KEY user_column_elements (borrowernumber, module, page, tablename, columnname, additional_param),
12
    CONSTRAINT borrower_columns_settings_ibfk1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
13
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(-)a/installer/data/mysql/kohastructure.sql (+18 lines)
Lines 3592-3597 CREATE TABLE IF NOT EXISTS columns_settings ( Link Here
3592
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3592
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3593
3593
3594
--
3594
--
3595
-- Table structure for table `users_columns_settings`
3596
--
3597
3598
CREATE TABLE IF NOT EXISTS users_columns_settings (
3599
    id int(11) NOT NULL auto_increment,
3600
    borrowernumber int(11) NOT NULL,
3601
    module varchar(50) NOT NULL,
3602
    page varchar(50) NOT NULL,
3603
    tablename varchar(50) NOT NULL,
3604
    additional_param varchar(255) NOT NULL,
3605
    columnname varchar(50) NOT NULL,
3606
    is_hidden int(1) NOT NULL DEFAULT 0,
3607
    PRIMARY KEY(id),
3608
    UNIQUE KEY user_column_elements (borrowernumber, module, page, tablename, columnname, additional_param),
3609
    CONSTRAINT borrower_columns_settings_ibfk1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3610
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3611
3612
--
3595
-- Table structure for table 'items_search_fields'
3613
-- Table structure for table 'items_search_fields'
3596
--
3614
--
3597
3615
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc (-2 / +31 lines)
Lines 1-12 Link Here
1
[% USE ColumnsSettings %]
1
[% USE ColumnsSettings %]
2
2
3
<script type="text/javascript">
3
<script type="text/javascript">
4
function KohaTable(selector, dt_parameters, columns_settings) {
4
var loaded = false;
5
function KohaTable(selector, dt_parameters, columns_settings, script_params) {
5
    var id = 0;
6
    var id = 0;
6
    var hidden_ids = [];
7
    var hidden_ids = [];
7
    var included_ids = [];
8
    var included_ids = [];
8
    $(columns_settings).each( function() {
9
    $(columns_settings).each( function() {
9
        var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( 'th' );
10
        var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index();
10
        var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id;
11
        var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id;
11
        if ( used_id == -1 ) return;
12
        if ( used_id == -1 ) return;
12
13
Lines 25-37 function KohaTable(selector, dt_parameters, columns_settings) { Link Here
25
            text: _("Column visibility"),
26
            text: _("Column visibility"),
26
        }
27
        }
27
    ];
28
    ];
29
    if ($(columns_settings).length) {
30
        dt_parameters[ "stateSave" ] =  true;
31
        dt_parameters[ "stateSaveCallback" ] = function(settings, data) {
32
            KohaStateSaveCallback(settings, data, script_params);
33
        };
34
    }
28
    var table = $(selector).dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
35
    var table = $(selector).dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
29
36
30
    $(hidden_ids).each(function(index, value) {
37
    $(hidden_ids).each(function(index, value) {
31
        table.fnSetColumnVis( value, false );
38
        table.fnSetColumnVis( value, false );
32
    });
39
    });
33
40
41
    loaded = true;
34
    return table;
42
    return table;
35
}
43
}
36
44
45
function KohaStateSaveCallback(settings, data, script_params) {
46
    if (loaded && typeof settings['aoColumns'] !== 'undefined') {
47
        var columns = [];
48
        $.each( settings['aoColumns'], function( index, value ){
49
            columns.push({name: value.colname, is_hidden: value.bVisible ? false : true});
50
        });
51
        $.ajax({
52
            url: "/api/v1/user_columns_settings",
53
            data: JSON.stringify({
54
                borrowernumber: "[% loggedinusernumber %]",
55
                module: script_params['module'],
56
                page: script_params['page'],
57
                tablename: script_params['tablename'],
58
                additional_param: script_params['additional_param'],
59
                columns: columns
60
            }),
61
            type: "POST",
62
        });
63
    }
64
}
65
37
</script>
66
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt (-7 / +33 lines)
Lines 1-3 Link Here
1
[% USE ColumnsSettings %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Catalog &rsaquo;
3
<title>Koha &rsaquo; Catalog &rsaquo;
3
  [% IF ( unknownbiblionumber ) %]
4
  [% IF ( unknownbiblionumber ) %]
Lines 6-13 Link Here
6
    MARC details for [% bibliotitle | html %]
7
    MARC details for [% bibliotitle | html %]
7
  [% END %]
8
  [% END %]
8
</title>
9
</title>
10
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
9
[% INCLUDE 'doc-head-close.inc' %]
11
[% INCLUDE 'doc-head-close.inc' %]
10
[% INCLUDE 'browser-strings.inc' %]
12
[% INCLUDE 'browser-strings.inc' %]
13
[% INCLUDE 'datatables.inc' %]
14
[% INCLUDE 'columns_settings.inc' %]
11
<!--[if lt IE 9]>
15
<!--[if lt IE 9]>
12
<script type="text/javascript" src="[% interface %]/lib/shims/json2.min.js"></script>
16
<script type="text/javascript" src="[% interface %]/lib/shims/json2.min.js"></script>
13
<![endif]-->
17
<![endif]-->
Lines 17-28 Link Here
17
    var browser = KOHA.browser('[% searchid %]', parseInt('[% biblionumber %]', 10));
21
    var browser = KOHA.browser('[% searchid %]', parseInt('[% biblionumber %]', 10));
18
    browser.show();
22
    browser.show();
19
23
20
	 $(document).ready(function() {
24
$(document).ready(function() {
21
        $('#bibliotabs').tabs();
25
    $('#bibliotabs').tabs();
22
        $("#Frameworks").on("change",function(){
26
    $("#Frameworks").on("change",function(){
23
            Changefwk(this);
27
        Changefwk(this);
24
        });
28
    });
25
	 });
29
30
    var columns_settings = [% ColumnsSettings.GetColumns( 'catalogue', 'marcdetail', 'itemst', 'json', frameworkcode ) %];
31
    var script_params = {
32
        module: 'catalogue',
33
        page: 'marcdetail',
34
        tablename: 'itemst',
35
        additional_param: '[% frameworkcode %]',
36
    }
37
    var itemst = KohaTable("#tab10XX table", {
38
        'module': 'catalogue',
39
        'bPaginate': false,
40
        'bInfo': false,
41
        "bAutoWidth": false,
42
        "bKohaColumnsUseNames": true,
43
        "aoColumnDefs": [
44
            { "bSortable": false, "bSearchable": false, "aTargets": [ "NoSort" ] }
45
        ]
46
    }, columns_settings, script_params);
47
});
26
48
27
function Changefwk(FwkList) {
49
function Changefwk(FwkList) {
28
	var fwk = FwkList.options[FwkList.selectedIndex].value;
50
	var fwk = FwkList.options[FwkList.selectedIndex].value;
Lines 173-183 function Changefwk(FwkList) { Link Here
173
     [% IF ( tab10XX ) %]
195
     [% IF ( tab10XX ) %]
174
    <div id="tab10XX">
196
    <div id="tab10XX">
175
        <table>
197
        <table>
198
            <thead>
176
                <tr>
199
                <tr>
177
                    [% FOREACH header IN item_header_loop %]
200
                    [% FOREACH header IN item_header_loop %]
178
                        <th>[% header %]</th>
201
                        <th data-colname="[% header.colname %]">[% header.label %]</th>
179
                    [% END %]
202
                    [% END %]
180
                </tr>
203
                </tr>
204
            </thead>
205
            <tbody>
181
                [% FOREACH item IN item_loop %]
206
                [% FOREACH item IN item_loop %]
182
                    <tr>
207
                    <tr>
183
                        [% FOREACH sf_code IN item_subfield_codes %]
208
                        [% FOREACH sf_code IN item_subfield_codes %]
Lines 185-190 function Changefwk(FwkList) { Link Here
185
                        [% END %]
210
                        [% END %]
186
                    </tr>
211
                    </tr>
187
                [% END %]
212
                [% END %]
213
            </tbody>
188
        </table>
214
        </table>
189
    </div>
215
    </div>
190
    [% END %]
216
    [% END %]
(-)a/t/db_dependent/ColumnsSettings.t (+1 lines)
Lines 6-11 use Test::MockModule; Link Here
6
6
7
use C4::Context;
7
use C4::Context;
8
use C4::Utils::DataTables::ColumnsSettings;
8
use C4::Utils::DataTables::ColumnsSettings;
9
9
my $dbh = C4::Context->dbh;
10
my $dbh = C4::Context->dbh;
10
$dbh->{AutoCommit} = 0;
11
$dbh->{AutoCommit} = 0;
11
$dbh->{RaiseError} = 1;
12
$dbh->{RaiseError} = 1;
(-)a/t/db_dependent/api/v1/user_columns_settings.t (-1 / +148 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Test::More tests => 9;
21
use Test::Mojo;
22
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
25
26
use C4::Auth;
27
use Koha::UsersColumnsSetting;
28
use Koha::UsersColumnsSettings;
29
use Koha::Database;
30
31
my $schema  = Koha::Database->new->schema;
32
$schema->storage->txn_begin;
33
my $builder = t::lib::TestBuilder->new;
34
35
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
36
37
my $remote_address = '127.0.0.1';
38
my $t              = Test::Mojo->new('Koha::REST::V1');
39
40
my ( $unauthorized_borrowernumber, $unauthorized_session_id ) =
41
  create_user_and_session( { authorized => 0 } );
42
my ( $authorized_borrowernumber, $authorized_session_id ) =
43
  create_user_and_session( { authorized => 1 } );
44
45
my $user_columns_settings = {
46
    borrowernumber => $authorized_borrowernumber,
47
    module => 'catalgue',
48
    page => 'marcdetail',
49
    tablename => 'itemst',
50
    additional_param => 'ACQ',
51
    columns => [
52
        {name => 'foo', is_hidden => \0},
53
        {name => 'bar', is_hidden => \1}
54
    ]
55
};
56
57
my $tx = $t->ua->build_tx( POST => "/api/v1/user_columns_settings/" => json => $user_columns_settings );
58
$tx->req->cookies(
59
    { name => 'CGISESSID', value => $unauthorized_session_id } );
60
$tx->req->env( { REMOTE_ADDR => $remote_address } );
61
$t->request_ok($tx)->status_is(403);
62
63
$tx = $t->ua->build_tx( POST => "/api/v1/user_columns_settings/" => json => $user_columns_settings );
64
$tx->req->cookies(
65
    { name => 'CGISESSID', value => $authorized_session_id } );
66
$tx->req->env( { REMOTE_ADDR => $remote_address } );
67
$t->request_ok($tx)->status_is(200);
68
69
my $col_foo = Koha::UsersColumnsSettings->search({
70
    borrowernumber => $authorized_borrowernumber,
71
    module => 'catalgue',
72
    page => 'marcdetail',
73
    tablename => 'itemst',
74
    additional_param => 'ACQ',
75
    columnname => 'foo'
76
77
})->next;
78
79
is($col_foo->is_hidden, 0, 'Column foo added');
80
81
my $col_bar = Koha::UsersColumnsSettings->search({
82
    borrowernumber => $authorized_borrowernumber,
83
    module => 'catalgue',
84
    page => 'marcdetail',
85
    tablename => 'itemst',
86
    additional_param => 'ACQ',
87
    columnname => 'bar'
88
})->next;
89
90
is($col_bar->is_hidden, 1, 'Column bar added');
91
92
# Update user columns
93
$user_columns_settings->{columns}->[0]->{is_hidden} = \1;
94
95
$tx = $t->ua->build_tx( POST => "/api/v1/user_columns_settings/" => json => $user_columns_settings );
96
$tx->req->cookies(
97
    { name => 'CGISESSID', value => $authorized_session_id } );
98
$tx->req->env( { REMOTE_ADDR => $remote_address } );
99
$t->request_ok($tx)->status_is(200);
100
101
$col_foo = Koha::UsersColumnsSettings->search({
102
    borrowernumber => $authorized_borrowernumber,
103
    module => 'catalgue',
104
    page => 'marcdetail',
105
    tablename => 'itemst',
106
    additional_param => 'ACQ',
107
    columnname => 'foo'
108
109
})->next;
110
111
is($col_foo->is_hidden, 1, 'Column foo updated');
112
113
sub create_user_and_session {
114
115
    my $args  = shift;
116
    my $flags = ( $args->{authorized} ) ? $args->{authorized} : 0;
117
    my $dbh   = C4::Context->dbh;
118
119
    my $user = $builder->build(
120
        {
121
            source => 'Borrower',
122
            value  => {
123
                flags => $flags
124
            }
125
        }
126
    );
127
128
    # Create a session for the authorized user
129
    my $session = C4::Auth::get_session('');
130
    $session->param( 'number',   $user->{borrowernumber} );
131
    $session->param( 'id',       $user->{userid} );
132
    $session->param( 'ip',       '127.0.0.1' );
133
    $session->param( 'lasttime', time() );
134
    $session->flush;
135
136
    if ( $args->{authorized} ) {
137
        $dbh->do( "
138
            INSERT INTO user_permissions (borrowernumber,module_bit,code)
139
            VALUES (?,3,'parameters_remaining_permissions')", undef,
140
            $user->{borrowernumber} );
141
    }
142
143
    return ( $user->{borrowernumber}, $session->id );
144
}
145
146
$schema->storage->txn_rollback;
147
148
1;

Return to bug 16881