Bug 22197: Add Mana KB link to administration sidebar menu
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / columns_settings.inc
1 [% USE ColumnsSettings %]
2
3 <script>
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
24     var exportColumns = ":visible";
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     dt_parameters[ "buttons" ] = [
31         {
32             extend: 'colvis',
33             columns: included_ids,
34             text: _("Column visibility"),
35             exportOptions: {
36                 columns: exportColumns
37             },
38         },
39         {
40             extend: 'excelHtml5',
41             text: _("Excel"),
42             exportOptions: {
43                 columns: exportColumns
44             },
45         },
46         {
47             extend: 'csvHtml5',
48             text: _("CSV"),
49             exportOptions: {
50                 columns: exportColumns
51             },
52         },
53         {
54             extend: 'copyHtml5',
55             text: _("Copy"),
56             exportOptions: {
57                 columns: exportColumns
58             },
59         },
60         {
61             extend: 'print',
62             text: _("Print"),
63             exportOptions: {
64                 columns: exportColumns
65             },
66         },
67     ];
68
69     var table = $(selector);
70     if ( add_filters ) {
71         // Duplicate the table header row for columnFilter
72         thead_row = table.find('thead tr');
73         clone = thead_row.clone().addClass('filters_row');
74         clone.find("th.NoSort").html('');
75         thead_row.before(clone);
76     }
77
78     table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
79
80     $(hidden_ids).each(function(index, value) {
81         table.fnSetColumnVis( value, false );
82     });
83
84     if ( add_filters ) {
85         // show a link to activate filtering
86         link = $('<a>')
87             .attr('href', '#')
88             .attr('id', id_selector + '_activate_filters');
89         $("." + id_selector  + "_table_controls").prepend(link);
90         deactivate_filters(id_selector);
91     }
92
93     return table;
94 }
95
96 </script>