Bug 22195: (follow-up) Add tooltip to buttons
[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     var export_buttons = [
31         {
32             extend: 'excelHtml5',
33             text: _("Excel"),
34             exportOptions: {
35                 columns: exportColumns
36             },
37         },
38         {
39             extend: 'csvHtml5',
40             text: _("CSV"),
41             exportOptions: {
42                 columns: exportColumns
43             },
44         },
45         {
46             extend: 'copyHtml5',
47             text: _("Copy"),
48             exportOptions: {
49                 columns: exportColumns
50             },
51         },
52         {
53             extend: 'print',
54             text: _("Print"),
55             exportOptions: {
56                 columns: exportColumns
57             },
58         }
59     ];
60
61     dt_parameters[ "buttons" ] = [
62         {
63             extend: 'colvis',
64             fade: 100,
65             columns: included_ids,
66             className: "columns_controls",
67             titleAttr: _("Columns settings"),
68             text: '<i class="fa fa-lg fa-gear"></i>',
69             exportOptions: {
70                 columns: exportColumns
71             },
72         },
73         {
74             extend: 'collection',
75             fade: 100,
76             className: "export_controls",
77             titleAttr: _("Export or print"),
78             text: '<i class="fa fa-lg fa-download"></i>',
79             buttons: export_buttons
80         }
81
82     ];
83
84     var table = $(selector);
85     if ( add_filters ) {
86         // Duplicate the table header row for columnFilter
87         thead_row = table.find('thead tr');
88         clone = thead_row.clone().addClass('filters_row');
89         clone.find("th.NoSort").html('');
90         thead_row.before(clone);
91     }
92
93     table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
94
95     $(hidden_ids).each(function(index, value) {
96         table.fnSetColumnVis( value, false );
97     });
98
99     if ( add_filters ) {
100         // show a link to activate filtering
101         link = $('<a>')
102             .attr('href', '#')
103             .attr('id', id_selector + '_activate_filters');
104         $("." + id_selector  + "_table_controls").prepend(link);
105         deactivate_filters(id_selector);
106     }
107
108     $(".columns_controls,.export_controls").tooltip();
109
110     return table;
111 }
112
113 </script>