Lines 1-61
Link Here
|
1 |
[% USE TablesSettings %] |
1 |
/* global dataTablesDefaults columnsInit __ */ |
|
|
2 |
/* exported KohaTable */ |
2 |
|
3 |
|
3 |
<script> |
|
|
4 |
function KohaTable(selector, dt_parameters, columns_settings) { |
4 |
function KohaTable(selector, dt_parameters, columns_settings) { |
5 |
var id = 0; |
5 |
var id = 0; |
6 |
var hidden_ids = []; |
6 |
var hidden_ids = []; |
7 |
var included_ids = []; |
7 |
var included_ids = []; |
8 |
$(columns_settings).each( function() { |
8 |
$(columns_settings).each(function () { |
9 |
var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector+' th' ); |
9 |
var named_id = $('thead th[data-colname="' + this.columnname + '"]', selector).index(selector + ' th'); |
10 |
|
10 |
|
11 |
var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id; |
11 |
var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id; |
12 |
if ( used_id == -1 ) return; |
12 |
if (used_id == -1) return; |
13 |
|
13 |
|
14 |
if ( this['is_hidden'] == "1" ) { |
14 |
if (this['is_hidden'] == "1") { |
15 |
hidden_ids.push( used_id ); |
15 |
hidden_ids.push(used_id); |
16 |
} |
16 |
} |
17 |
if ( this['cannot_be_toggled'] == "0" ) { |
17 |
if (this['cannot_be_toggled'] == "0") { |
18 |
included_ids.push( used_id ); |
18 |
included_ids.push(used_id); |
19 |
} |
19 |
} |
20 |
id++; |
20 |
id++; |
21 |
}); |
21 |
}); |
22 |
|
22 |
|
23 |
// By default we include all visible columns in exports and print unless they have the "noExport" class |
23 |
// By default we include all visible columns in exports and print unless they have the "noExport" class |
24 |
var exportColumns = ":visible:not(.noExport)"; |
24 |
var exportColumns = ":visible:not(.noExport)"; |
25 |
if( dt_parameters.hasOwnProperty("exportColumns") ){ |
25 |
if (dt_parameters.hasOwnProperty("exportColumns")) { |
26 |
// A custom buttons configuration has been passed from the page |
26 |
// A custom buttons configuration has been passed from the page |
27 |
exportColumns = dt_parameters["exportColumns"]; |
27 |
exportColumns = dt_parameters["exportColumns"]; |
28 |
} |
28 |
} |
29 |
// Data which has the "noExport" class should not appear in print or export |
29 |
// Data which has the "noExport" class should not appear in print or export |
30 |
var export_format = { |
30 |
var export_format = { |
31 |
body: function ( data, row, column, node ) { |
31 |
body: function (data, row, column, node) { |
32 |
var newnode = $(node); |
32 |
var newnode = $(node); |
33 |
|
33 |
|
34 |
if ( newnode.find(".noExport").length > 0 ) { |
34 |
if (newnode.find(".noExport").length > 0) { |
35 |
newnode = newnode.clone(); |
35 |
newnode = newnode.clone(); |
36 |
newnode.find(".noExport").remove(); |
36 |
newnode.find(".noExport").remove(); |
37 |
} |
37 |
} |
38 |
|
38 |
|
39 |
return newnode.text().replace( /\n/g, ' ' ).trim(); |
39 |
return newnode.text().replace(/\n/g, ' ').trim(); |
40 |
} |
40 |
} |
41 |
} |
41 |
}; |
42 |
|
42 |
|
43 |
// Add a "Clear filter" button to table filter form field |
43 |
// Add a "Clear filter" button to table filter form field |
44 |
dt_parameters[ "buttons" ] = [ |
44 |
dt_parameters["buttons"] = [ |
45 |
{ |
45 |
{ |
46 |
fade: 100, |
46 |
fade: 100, |
47 |
className: "dt_button_clear_filter", |
47 |
className: "dt_button_clear_filter", |
48 |
titleAttr: _("Clear filter"), |
48 |
titleAttr: __("Clear filter"), |
49 |
enabled: false, |
49 |
enabled: false, |
50 |
text: '<i class="fa fa-lg fa-remove" aria-hidden="true"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>', |
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 ) { |
51 |
action: function (e, dt, node) { |
52 |
dt.search( "" ).draw("page"); |
52 |
dt.search("").draw("page"); |
53 |
node.addClass("disabled"); |
53 |
node.addClass("disabled"); |
54 |
} |
54 |
} |
55 |
}, |
55 |
}, |
56 |
{ |
56 |
{ |
57 |
extend: 'csvHtml5', |
57 |
extend: 'csvHtml5', |
58 |
text: _("CSV"), |
58 |
text: __("CSV"), |
59 |
exportOptions: { |
59 |
exportOptions: { |
60 |
columns: exportColumns, |
60 |
columns: exportColumns, |
61 |
format: export_format |
61 |
format: export_format |
Lines 63-69
function KohaTable(selector, dt_parameters, columns_settings) {
Link Here
|
63 |
}, |
63 |
}, |
64 |
{ |
64 |
{ |
65 |
extend: 'copyHtml5', |
65 |
extend: 'copyHtml5', |
66 |
text: _("Copy"), |
66 |
text: __("Copy"), |
67 |
exportOptions: { |
67 |
exportOptions: { |
68 |
columns: exportColumns, |
68 |
columns: exportColumns, |
69 |
format: export_format |
69 |
format: export_format |
Lines 71-77
function KohaTable(selector, dt_parameters, columns_settings) {
Link Here
|
71 |
}, |
71 |
}, |
72 |
{ |
72 |
{ |
73 |
extend: 'print', |
73 |
extend: 'print', |
74 |
text: _("Print"), |
74 |
text: __("Print"), |
75 |
exportOptions: { |
75 |
exportOptions: { |
76 |
columns: exportColumns, |
76 |
columns: exportColumns, |
77 |
format: export_format |
77 |
format: export_format |
Lines 79-93
function KohaTable(selector, dt_parameters, columns_settings) {
Link Here
|
79 |
} |
79 |
} |
80 |
]; |
80 |
]; |
81 |
|
81 |
|
82 |
if( included_ids.length > 0 ){ |
82 |
if (included_ids.length > 0) { |
83 |
dt_parameters[ "buttons" ].push( |
83 |
dt_parameters["buttons"].push( |
84 |
{ |
84 |
{ |
85 |
extend: 'colvis', |
85 |
extend: 'colvis', |
86 |
fade: 100, |
86 |
fade: 100, |
87 |
columns: included_ids, |
87 |
columns: included_ids, |
88 |
className: "columns_controls", |
88 |
className: "columns_controls", |
89 |
titleAttr: _("Columns settings"), |
89 |
titleAttr: __("Columns settings"), |
90 |
text: '<i class="fa fa-lg fa-gear" aria-hidden="true"></i> <span class="dt-button-text">' + _("Columns") + '</span>', |
90 |
text: '<i class="fa fa-lg fa-gear" aria-hidden="true"></i> <span class="dt-button-text">' + __("Columns") + '</span>', |
91 |
exportOptions: { |
91 |
exportOptions: { |
92 |
columns: exportColumns |
92 |
columns: exportColumns |
93 |
} |
93 |
} |
Lines 96-102
function KohaTable(selector, dt_parameters, columns_settings) {
Link Here
|
96 |
} |
96 |
} |
97 |
|
97 |
|
98 |
var table = $(selector); |
98 |
var table = $(selector); |
99 |
var new_parameters = {} |
99 |
var new_parameters = {}; |
100 |
$.extend(true, new_parameters, dataTablesDefaults, dt_parameters); |
100 |
$.extend(true, new_parameters, dataTablesDefaults, dt_parameters); |
101 |
var default_column_defs = [ |
101 |
var default_column_defs = [ |
102 |
{ "aTargets": ["string-sort"], "sType": "string" }, |
102 |
{ "aTargets": ["string-sort"], "sType": "string" }, |
Lines 123-127
function KohaTable(selector, dt_parameters, columns_settings) {
Link Here
|
123 |
|
123 |
|
124 |
return table; |
124 |
return table; |
125 |
} |
125 |
} |
126 |
|
|
|
127 |
</script> |
128 |
- |