Bug 29407: Make the pickup locations dropdown JS reusable
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / table_filters.js
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 }