Bug 9573: Lost items report - Move filters code to a separate js file
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / columns_settings.inc
1 [% USE ColumnsSettings %]
2
3 <script type="text/javascript">
4 function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
5     var id = 0;
6     var hidden_ids = [];
7     var included_ids = [];
8     $(columns_settings).each( function() {
9         var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( 'th' );
10         var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id;
11         if ( used_id == -1 ) return;
12
13         if ( this['is_hidden'] == "1" ) {
14             hidden_ids.push( used_id );
15         }
16         if ( this['cannot_be_toggled'] == "0" ) {
17             included_ids.push( used_id );
18         }
19         id++;
20     });
21     dt_parameters[ "buttons" ] = [
22         {
23             extend: 'colvis',
24             columns: included_ids,
25             text: _("Column visibility"),
26         }
27     ];
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));
39
40     $(hidden_ids).each(function(index, value) {
41         table.fnSetColumnVis( value, false );
42     });
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
53     return table;
54 }
55
56 </script>