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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc (-166 / +3 lines)
Lines 1-169 Link Here
1
[% USE raw %]
2
[% USE Asset %]
1
[% USE TablesSettings %]
3
[% USE TablesSettings %]
2
<!-- columns_settings.inc -->
4
<!-- columns_settings.inc -->
3
5
[% Asset.js("js/tablesettings.js") | $raw %]
4
<script>
5
function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
6
    var counter = 0;
7
    var hidden_ids = [];
8
    var included_ids = [];
9
    var selector = '#' + id_selector;
10
11
    $(columns_settings).each( function() {
12
        var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector + ' th' );
13
        var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : counter;
14
        if ( used_id == -1 ) return;
15
16
        if ( this['is_hidden'] == "1" ) {
17
            hidden_ids.push( used_id );
18
        }
19
        if ( this['cannot_be_toggled'] == "0" ) {
20
            included_ids.push( used_id );
21
        }
22
        counter++;
23
    });
24
25
    var exportColumns = ":visible:not(.noExport)";
26
    if( dt_parameters.hasOwnProperty("exportColumns") ){
27
        // A custom buttons configuration has been passed from the page
28
        exportColumns = dt_parameters["exportColumns"];
29
    }
30
31
    var export_format = {
32
        body: function ( data, row, column, node ) {
33
            var newnode = $(node);
34
35
            if ( newnode.find(".noExport").length > 0 ) {
36
                newnode = newnode.clone();
37
                newnode.find(".noExport").remove();
38
            }
39
40
            return newnode.text().replace( /\n/g, ' ' ).trim();
41
        }
42
    }
43
44
    var export_buttons = [
45
        {
46
            extend: 'excelHtml5',
47
            text: _("Excel"),
48
            exportOptions: {
49
                columns: exportColumns,
50
                format:  export_format
51
            },
52
        },
53
        {
54
            extend: 'csvHtml5',
55
            text: _("CSV"),
56
            exportOptions: {
57
                columns: exportColumns,
58
                format:  export_format
59
            },
60
        },
61
        {
62
            extend: 'copyHtml5',
63
            text: _("Copy"),
64
            exportOptions: {
65
                columns: exportColumns,
66
                format:  export_format
67
            },
68
        },
69
        {
70
            extend: 'print',
71
            text: _("Print"),
72
            exportOptions: {
73
                columns: exportColumns,
74
                format:  export_format
75
            },
76
        }
77
    ];
78
79
    dt_parameters[ "buttons" ] = [
80
        {
81
            fade: 100,
82
            className: "dt_button_clear_filter",
83
            titleAttr: _("Clear filter"),
84
            enabled: false,
85
            text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>',
86
            action: function ( e, dt, node, config ) {
87
                dt.search( "" ).draw("page");
88
                node.addClass("disabled");
89
            }
90
        }
91
    ];
92
93
    if( included_ids.length > 0 ){
94
        dt_parameters[ "buttons" ].push(
95
            {
96
                extend: 'colvis',
97
                fade: 100,
98
                columns: included_ids,
99
                className: "columns_controls",
100
                titleAttr: _("Columns settings"),
101
                text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + _("Columns") + '</span>',
102
                exportOptions: {
103
                    columns: exportColumns
104
                }
105
            }
106
        );
107
    }
108
109
    dt_parameters[ "buttons" ].push(
110
        {
111
            extend: 'collection',
112
            autoClose: true,
113
            fade: 100,
114
            className: "export_controls",
115
            titleAttr: _("Export or print"),
116
            text: '<i class="fa fa-lg fa-download"></i> <span class="dt-button-text">' + _("Export") + '</span>',
117
            buttons: export_buttons
118
        }
119
    );
120
121
    var table = $(selector);
122
    if ( add_filters ) {
123
        // Duplicate the table header row for columnFilter
124
        thead_row = table.find('thead tr');
125
        clone = thead_row.clone().addClass('filters_row');
126
        clone.find("th.NoSort").html('');
127
        thead_row.before(clone);
128
    }
129
130
    var new_parameters = {}
131
    $.extend(true, new_parameters, dataTablesDefaults, dt_parameters);
132
    var default_column_defs = [
133
        { "targets": [ "title-string" ], "type": "title-string" },
134
        { "targets": [ "string-sort" ],  "type": "string" },
135
        { "targets": [ "anti-the" ],     "type": "anti-the" },
136
        { "targets": [ "NoSort" ],       "orderable": false, "searchable": false },
137
    ];
138
    if ( new_parameters["columnDefs"] === undefined ) {
139
        new_parameters["columnDefs"] = default_column_defs;
140
    } else {
141
        $.extend(true, new_parameters, default_column_defs);
142
    }
143
144
    table.dataTable(new_parameters);
145
    table.DataTable().on("column-visibility.dt", function(){
146
        if( typeof columnsInit == 'function' ){
147
            // This function can be created separately and used to trigger
148
            // an event after the DataTable has loaded AND column visibility
149
            // has been updated according to the table's configuration
150
            columnsInit();
151
        }
152
    }).columns( hidden_ids ).visible( false );
153
154
    if ( add_filters ) {
155
        // show a link to activate filtering
156
        link = $('<a>')
157
            .attr('href', '#')
158
            .attr('id', id_selector + '_activate_filters');
159
        $("." + id_selector  + "_table_controls").prepend(link);
160
        deactivate_filters(id_selector);
161
    }
162
163
    $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
164
165
    return table;
166
}
167
168
</script>
169
<!-- / columns_settings.inc -->
6
<!-- / columns_settings.inc -->
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (-1 lines)
Lines 1286-1292 Note that permanent location is a code, and location may be an authval. Link Here
1286
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
1286
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
1287
    [% INCLUDE 'columns_settings.inc' %]
1287
    [% INCLUDE 'columns_settings.inc' %]
1288
    [% Asset.js("js/browser.js") | $raw %]
1288
    [% Asset.js("js/browser.js") | $raw %]
1289
    [% Asset.js("js/table_filters.js") | $raw %]
1290
    <script>
1289
    <script>
1291
        var browser;
1290
        var browser;
1292
        browser = KOHA.browser('[% searchid | html %]', parseInt(biblionumber, 10));
1291
        browser = KOHA.browser('[% searchid | html %]', parseInt(biblionumber, 10));
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt (-1 lines)
Lines 208-214 Link Here
208
    [% INCLUDE 'datatables.inc' %]
208
    [% INCLUDE 'datatables.inc' %]
209
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
209
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
210
    [% INCLUDE 'columns_settings.inc' %]
210
    [% INCLUDE 'columns_settings.inc' %]
211
    [% Asset.js("js/table_filters.js") | $raw %]
212
    <script>
211
    <script>
213
        $(document).ready(function() {
212
        $(document).ready(function() {
214
            var columns_settings = [% TablesSettings.GetColumns( 'reports', 'lostitems', 'lostitems-table', 'json' ) | $raw %];
213
            var columns_settings = [% TablesSettings.GetColumns( 'reports', 'lostitems', 'lostitems-table', 'json' ) | $raw %];
(-)a/koha-tmpl/intranet-tmpl/prog/js/table_filters.js (-50 lines)
Lines 1-50 Link Here
1
function activate_filters(id) {
2
    var table = $("#" + id );
3
    if (table.length == 1) {
4
        filters_row = table.find('thead tr.filters_row');
5
6
        var aoColumns = [];
7
        filters_row.find('th').each(function() {
8
            if(this.className === "NoSort"){
9
                aoColumns.push(null);
10
            } else {
11
                aoColumns.push('text');
12
            }
13
        });
14
15
        if (table.find('thead tr.columnFilter').length == 0) {
16
            table.dataTable().columnFilter({
17
                'sPlaceHolder': 'head:after'
18
                ,   'aoColumns': aoColumns
19
            });
20
            filters_row.addClass('columnFilter');
21
        }
22
        filters_row.show();
23
    }
24
25
    $('#' + id + '_activate_filters')
26
        .html('<i class="fa fa-filter"></i> ' + __('Deactivate filters') )
27
        .unbind('click')
28
        .click(function() {
29
            deactivate_filters(id);
30
            return false;
31
        });
32
}
33
34
function deactivate_filters(id) {
35
    filters_row = $("#" + id ).find('thead tr.filters_row');
36
37
    filters_row.find('input[type="text"]')
38
        .val('')            // Empty filter text boxes
39
        .trigger('keyup')   // Filter (display all rows)
40
        .trigger('blur');   // Reset value to the column name
41
    filters_row.hide();
42
43
    $('#' + id + '_activate_filters')
44
        .html('<i class="fa fa-filter"></i> ' + __('Activate filters') )
45
        .unbind('click')
46
        .click(function() {
47
            activate_filters(id);
48
            return false;
49
        });
50
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/tablesettings.js (-1 / +216 lines)
Line 0 Link Here
0
- 
1
/* global dataTablesDefaults columnsInit __ */
2
/* exported KohaTable */
3
4
function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
5
    var counter = 0;
6
    var hidden_ids = [];
7
    var included_ids = [];
8
    var selector = '#' + id_selector;
9
10
    $(columns_settings).each(function () {
11
        var named_id = $('thead th[data-colname="' + this.columnname + '"]', selector).index(selector + ' th');
12
        var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : counter;
13
        if (used_id == -1) return;
14
15
        if (this['is_hidden'] == "1") {
16
            hidden_ids.push(used_id);
17
        }
18
        if (this['cannot_be_toggled'] == "0") {
19
            included_ids.push(used_id);
20
        }
21
        counter++;
22
    });
23
24
    var exportColumns = ":visible:not(.noExport)";
25
    if (dt_parameters.hasOwnProperty("exportColumns")) {
26
        // A custom buttons configuration has been passed from the page
27
        exportColumns = dt_parameters["exportColumns"];
28
    }
29
30
    var export_format = {
31
        body: function (data, row, column, node) {
32
            var newnode = $(node);
33
34
            if (newnode.find(".noExport").length > 0) {
35
                newnode = newnode.clone();
36
                newnode.find(".noExport").remove();
37
            }
38
39
            return newnode.text().replace(/\n/g, ' ').trim();
40
        }
41
    };
42
43
    var export_buttons = [
44
        {
45
            extend: 'excelHtml5',
46
            text: __("Excel"),
47
            exportOptions: {
48
                columns: exportColumns,
49
                format: export_format
50
            },
51
        },
52
        {
53
            extend: 'csvHtml5',
54
            text: __("CSV"),
55
            exportOptions: {
56
                columns: exportColumns,
57
                format: export_format
58
            },
59
        },
60
        {
61
            extend: 'copyHtml5',
62
            text: __("Copy"),
63
            exportOptions: {
64
                columns: exportColumns,
65
                format: export_format
66
            },
67
        },
68
        {
69
            extend: 'print',
70
            text: __("Print"),
71
            exportOptions: {
72
                columns: exportColumns,
73
                format: export_format
74
            },
75
        }
76
    ];
77
78
    dt_parameters["buttons"] = [
79
        {
80
            fade: 100,
81
            className: "dt_button_clear_filter",
82
            titleAttr: __("Clear filter"),
83
            enabled: false,
84
            text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + __("Clear filter") + '</span>',
85
            action: function (e, dt, node) {
86
                dt.search("").draw("page");
87
                node.addClass("disabled");
88
            }
89
        }
90
    ];
91
92
    if (included_ids.length > 0) {
93
        dt_parameters["buttons"].push(
94
            {
95
                extend: 'colvis',
96
                fade: 100,
97
                columns: included_ids,
98
                className: "columns_controls",
99
                titleAttr: __("Columns settings"),
100
                text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + __("Columns") + '</span>',
101
                exportOptions: {
102
                    columns: exportColumns
103
                }
104
            }
105
        );
106
    }
107
108
    dt_parameters["buttons"].push(
109
        {
110
            extend: 'collection',
111
            autoClose: true,
112
            fade: 100,
113
            className: "export_controls",
114
            titleAttr: __("Export or print"),
115
            text: '<i class="fa fa-lg fa-download"></i> <span class="dt-button-text">' + __("Export") + '</span>',
116
            buttons: export_buttons
117
        }
118
    );
119
120
    var table = $(selector);
121
    if (add_filters) {
122
        // Duplicate the table header row for columnFilter
123
        var thead_row = table.find('thead tr');
124
        var clone = thead_row.clone().addClass('filters_row');
125
        clone.find("th.NoSort").html('');
126
        thead_row.before(clone);
127
    }
128
129
    var new_parameters = {};
130
    $.extend(true, new_parameters, dataTablesDefaults, dt_parameters);
131
    var default_column_defs = [
132
        { "targets": ["title-string"], "type": "title-string" },
133
        { "targets": ["string-sort"], "type": "string" },
134
        { "targets": ["anti-the"], "type": "anti-the" },
135
        { "targets": ["NoSort"], "orderable": false, "searchable": false },
136
    ];
137
    if (new_parameters["columnDefs"] === undefined) {
138
        new_parameters["columnDefs"] = default_column_defs;
139
    } else {
140
        $.extend(true, new_parameters, default_column_defs);
141
    }
142
143
    table.dataTable(new_parameters);
144
    table.DataTable().on("column-visibility.dt", function () {
145
        if (typeof columnsInit == 'function') {
146
            // This function can be created separately and used to trigger
147
            // an event after the DataTable has loaded AND column visibility
148
            // has been updated according to the table's configuration
149
            columnsInit();
150
        }
151
    }).columns(hidden_ids).visible(false);
152
153
    if (add_filters) {
154
        // show a link to activate filtering
155
        var link = $('<a>')
156
            .attr('href', '#')
157
            .attr('id', id_selector + '_activate_filters');
158
        $("." + id_selector + "_table_controls").prepend(link);
159
        deactivate_filters(id_selector);
160
    }
161
162
    $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
163
164
    return table;
165
}
166
167
function activate_filters(id) {
168
    var table = $("#" + id);
169
    if (table.length == 1) {
170
        var filters_row = table.find('thead tr.filters_row');
171
172
        var aoColumns = [];
173
        filters_row.find('th').each(function () {
174
            if (this.className === "NoSort") {
175
                aoColumns.push(null);
176
            } else {
177
                aoColumns.push('text');
178
            }
179
        });
180
181
        if (table.find('thead tr.columnFilter').length == 0) {
182
            table.dataTable().columnFilter({
183
                'sPlaceHolder': 'head:after'
184
                , 'aoColumns': aoColumns
185
            });
186
            filters_row.addClass('columnFilter');
187
        }
188
        filters_row.show();
189
    }
190
191
    $('#' + id + '_activate_filters')
192
        .html('<i class="fa fa-filter"></i> ' + __('Deactivate filters'))
193
        .unbind('click')
194
        .click(function () {
195
            deactivate_filters(id);
196
            return false;
197
        });
198
}
199
200
function deactivate_filters(id) {
201
    var filters_row = $("#" + id).find('thead tr.filters_row');
202
203
    filters_row.find('input[type="text"]')
204
        .val('')            // Empty filter text boxes
205
        .trigger('keyup')   // Filter (display all rows)
206
        .trigger('blur');   // Reset value to the column name
207
    filters_row.hide();
208
209
    $('#' + id + '_activate_filters')
210
        .html('<i class="fa fa-filter"></i> ' + __('Activate filters'))
211
        .unbind('click')
212
        .click(function () {
213
            activate_filters(id);
214
            return false;
215
        });
216
}

Return to bug 28058