Bug 18791: (follow-up) Make buttons translatable
[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 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( '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     dt_parameters[ "buttons" ] = [
24         {
25             extend: 'colvis',
26             columns: included_ids,
27             text: _("Column visibility"),
28         },
29         {
30             extend: 'excelHtml5',
31             text: _("Excel"),
32         },
33         {
34             extend: 'csvHtml5',
35             text: _("CSV"),
36         },
37         {
38             extend: 'copyHtml5',
39             text: _("Copy"),
40         },
41         {
42             extend: 'print',
43             text: _("Print"),
44         },
45     ];
46
47     var table = $(selector);
48     if ( add_filters ) {
49         // Duplicate the table header row for columnFilter
50         thead_row = table.find('thead tr');
51         clone = thead_row.clone().addClass('filters_row');
52         clone.find("th.NoSort").html('');
53         thead_row.before(clone);
54     }
55
56     table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
57
58     $(hidden_ids).each(function(index, value) {
59         table.fnSetColumnVis( value, false );
60     });
61
62     if ( add_filters ) {
63         // show a link to activate filtering
64         link = $('<a>')
65             .attr('href', '#')
66             .attr('id', id_selector + '_activate_filters');
67         $("." + id_selector  + "_table_controls").prepend(link);
68         deactivate_filters(id_selector);
69     }
70
71     return table;
72 }
73
74 </script>