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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc (-2 / +21 lines)
Lines 1-7 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
function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
5
    var id = 0;
5
    var id = 0;
6
    var hidden_ids = [];
6
    var hidden_ids = [];
7
    var included_ids = [];
7
    var included_ids = [];
Lines 25-36 function KohaTable(selector, dt_parameters, columns_settings) { Link Here
25
            text: _("Column visibility"),
25
            text: _("Column visibility"),
26
        }
26
        }
27
    ];
27
    ];
28
    var table = $(selector).dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
28
29
    var table = $('#' + id_selector + ' table');
30
    if ( add_filters ) {
31
        // Duplicate the table header row for columnFilter
32
        thead_row = table.find('thead tr');
33
        clone = thead_row.clone().addClass('filters_row');
34
        clone.find("th.NoSort").html('');
35
        thead_row.before(clone);
36
    }
37
38
    table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
29
39
30
    $(hidden_ids).each(function(index, value) {
40
    $(hidden_ids).each(function(index, value) {
31
        table.fnSetColumnVis( value, false );
41
        table.fnSetColumnVis( value, false );
32
    });
42
    });
33
43
44
    if ( add_filters ) {
45
        // show a link to activate filtering
46
        link = $('<a>')
47
            .attr('href', '#')
48
            .attr('id', id_selector + '_activate_filters');
49
        $("." + id_selector + "_table_controls").prepend(link);
50
        deactivate_filters(id_selector);
51
    }
52
34
    return table;
53
    return table;
35
}
54
}
36
55
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (-69 / +7 lines)
Lines 1041-1131 Link Here
1041
    [% INCLUDE 'datatables.inc' %]
1041
    [% INCLUDE 'datatables.inc' %]
1042
    <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.dataTables.columnFilter.js"></script>
1042
    <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.dataTables.columnFilter.js"></script>
1043
    [% INCLUDE 'browser-strings.inc' %]
1043
    [% INCLUDE 'browser-strings.inc' %]
1044
    [% INCLUDE 'columns_settings.inc' %]
1044
    <script type="text/javascript" src="[% interface %]/js/browser.js"></script>
1045
    <script type="text/javascript" src="[% interface %]/js/browser.js"></script>
1046
    <script type="text/javascript" src="[% interface %]/[% theme %]/js/table_filters.js"></script>
1045
    <script type="text/javascript">
1047
    <script type="text/javascript">
1046
        var browser = KOHA.browser('[% searchid %]', parseInt(biblionumber, 10));
1048
        var browser = KOHA.browser('[% searchid %]', parseInt(biblionumber, 10));
1047
        browser.show();
1049
        browser.show();
1048
1050
1049
        function activate_filters(id) {
1050
            var table = $("#" + id + " table");
1051
            if (table.length == 1) {
1052
                filters_row = table.find('thead tr.filters_row');
1053
1054
                var aoColumns = [];
1055
                filters_row.find('th').each(function() {
1056
                    if(this.className === "NoSort"){
1057
                        aoColumns.push(null);
1058
                    } else {
1059
                        aoColumns.push('text');
1060
                    }
1061
                });
1062
1063
                if (table.find('thead tr.columnFilter').length == 0) {
1064
                    table.dataTable().columnFilter({
1065
                        'sPlaceHolder': 'head:after'
1066
                        ,   'aoColumns': aoColumns
1067
                    });
1068
                    filters_row.addClass('columnFilter');
1069
                }
1070
                filters_row.show();
1071
            }
1072
1073
            $('#' + id + '_activate_filters')
1074
                .html('<i class="fa fa-filter"></i> ' + _("Deactivate filters") )
1075
                .unbind('click')
1076
                .click(function() {
1077
                    deactivate_filters(id);
1078
                    return false;
1079
                });
1080
        }
1081
1082
        function deactivate_filters(id) {
1083
            filters_row = $("#" + id + " table").find('thead tr.filters_row');
1084
1085
            filters_row.find('input[type="text"]')
1086
                .val('')            // Empty filter text boxes
1087
                .trigger('keyup')   // Filter (display all rows)
1088
                .trigger('blur');   // Reset value to the column name
1089
            filters_row.hide();
1090
1091
            $('#' + id + '_activate_filters')
1092
                .html('<i class="fa fa-filter"></i> ' + _("Activate filters") )
1093
                .unbind('click')
1094
                .click(function() {
1095
                    activate_filters(id);
1096
                    return false;
1097
                });
1098
        }
1099
1100
        $(document).ready(function() {
1051
        $(document).ready(function() {
1101
            var ids = ['holdings', 'otherholdings'];
1052
            var ids = ['holdings', 'otherholdings'];
1053
1102
            for (var i in ids) {
1054
            for (var i in ids) {
1103
                var id = ids[i];
1055
                var id = ids[i];
1104
                var table = $('#' + id + ' table');
1056
                var dt_parameters = {
1105
1106
                // Duplicate the table header row for columnFilter
1107
                thead_row = table.find('thead tr');
1108
                clone = thead_row.clone().addClass('filters_row');
1109
                clone.find("th.NoSort").html('');
1110
                thead_row.before(clone);
1111
1112
                // Enable sorting
1113
                table.dataTable($.extend(true, {}, dataTablesDefaults, {
1114
                    'sDom': 't',
1057
                    'sDom': 't',
1115
                    'bPaginate': false,
1058
                    'bPaginate': false,
1116
                    'bAutoWidth': false,
1059
                    'bAutoWidth': false,
1117
                    "aoColumnDefs": [
1060
                    "aoColumnDefs": [
1118
                        { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] }
1061
                        { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] }
1119
                    ]
1062
                    ]
1120
                }));
1063
                };
1121
1064
                var table = KohaTable(id, dt_parameters, null, 'with_filters');
1122
                // Show a link to activate filtering
1123
                link = $('<a>')
1124
                    .attr('href', '#')
1125
                    .attr('id', id + '_activate_filters');
1126
                $("." + id + "_table_controls").prepend(link);
1127
                deactivate_filters(id);
1128
            }
1065
            }
1066
1129
            [% IF Koha.Preference('AcquisitionDetails') %]
1067
            [% IF Koha.Preference('AcquisitionDetails') %]
1130
                $("#orders").dataTable($.extend(true, {}, dataTablesDefaults, {
1068
                $("#orders").dataTable($.extend(true, {}, dataTablesDefaults, {
1131
                    'sDom': 't',
1069
                    'sDom': 't',
(-)a/koha-tmpl/intranet-tmpl/prog/js/table_filters.js (-1 / +50 lines)
Line 0 Link Here
0
- 
1
function activate_filters(id) {
2
    var table = $("#" + id + " table");
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 + " table").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
}

Return to bug 9573