]> git.koha-community.org Git - koha.git/blob - koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc
Bug 11873: (QA follow-up) Add missing TT filters
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / includes / columns_settings.inc
1 [% USE TablesSettings %]
2
3 <script>
4 function KohaTable(selector, dt_parameters, columns_settings) {
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( selector+' th' );
10
11         var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id;
12         if ( used_id == -1 ) return;
13
14         if ( this['is_hidden'] == "1" ) {
15             hidden_ids.push( used_id );
16         }
17         if ( this['cannot_be_toggled'] == "0" ) {
18             included_ids.push( used_id );
19         }
20         id++;
21     });
22
23     // By default we include all visible columns in exports and print unless they have the "noExport" class
24     var exportColumns = ":visible:not(.noExport)";
25     if( dt_parameters.hasOwnProperty("exportColumns") ){
26         // A custom buttons configuration has been passed from the page
27         exportColumns = dt_parameters["exportColumns"];
28     }
29     // Data which has the "noExport" class should not appear in print or export
30     var export_format = {
31         body: function ( data, row, column, node ) {
32             var newnode = $(node);
33
34             if ( newnode.find(".noExport").length > 0 ) {
35                 newnode = newnode.clone();
36                 newnode.find(".noExport").remove();
37             }
38
39             return newnode.text().replace( /\n/g, ' ' ).trim();
40         }
41     }
42
43     // Add a "Clear filter" button to table filter form field
44     dt_parameters[ "buttons" ] = [
45         {
46             fade: 100,
47             className: "dt_button_clear_filter",
48             titleAttr: _("Clear filter"),
49             enabled: false,
50             text: '<i class="fa fa-lg fa-remove" aria-hidden="true"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>',
51             action: function ( e, dt, node, config ) {
52                 dt.search( "" ).draw("page");
53                 node.addClass("disabled");
54             }
55         },
56         {
57             extend: 'csvHtml5',
58             text: _("CSV"),
59             exportOptions: {
60                 columns: exportColumns,
61                 format: export_format
62             },
63         },
64         {
65             extend: 'copyHtml5',
66             text: _("Copy"),
67             exportOptions: {
68                 columns: exportColumns,
69                 format: export_format
70             },
71         },
72         {
73             extend: 'print',
74             text: _("Print"),
75             exportOptions: {
76                 columns: exportColumns,
77                 format: export_format
78             },
79         }
80     ];
81
82     if( included_ids.length > 0 ){
83         dt_parameters[ "buttons" ].push(
84             {
85                 extend: 'colvis',
86                 fade: 100,
87                 columns: included_ids,
88                 className: "columns_controls",
89                 titleAttr: _("Columns settings"),
90                 text: '<i class="fa fa-lg fa-gear" aria-hidden="true"></i> <span class="dt-button-text">' + _("Columns") + '</span>',
91                 exportOptions: {
92                     columns: exportColumns
93                 }
94             }
95         );
96     }
97
98     var table = $(selector);
99     var new_parameters = {}
100     $.extend(true, new_parameters, dataTablesDefaults, dt_parameters);
101     var default_column_defs = [
102         { "aTargets": ["string-sort"], "sType": "string" },
103         { "aTargets": ["anti-the"], "sType": "anti-the" },
104         { "aTargets": ["NoSort"], "bSortable": false, "bSearchable": false }
105     ];
106     if (new_parameters["aoColumnDefs"] === undefined) {
107         new_parameters["aoColumnDefs"] = default_column_defs;
108     } else {
109         $.extend(true, new_parameters, default_column_defs);
110     }
111
112     table.dataTable(new_parameters);
113     table.DataTable().on("column-visibility.dt", function () {
114         if (typeof columnsInit == 'function') {
115             // This function can be created separately and used to trigger
116             // an event after the DataTable has loaded AND column visibility
117             // has been updated according to the table's configuration
118             columnsInit();
119         }
120     }).columns(hidden_ids).visible(false);
121
122     $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
123
124     return table;
125 }
126
127 </script>