Lines 26-36
function KohaTable(id_selector, dt_parameters, table_settings, add_filters) {
Link Here
|
26 |
dt_parameters.stateSaveCallback = function( settings, data ) { |
26 |
dt_parameters.stateSaveCallback = function( settings, data ) { |
27 |
localStorage.setItem( table_key, JSON.stringify(data) ) |
27 |
localStorage.setItem( table_key, JSON.stringify(data) ) |
28 |
} |
28 |
} |
|
|
29 |
|
30 |
function set_default(table_settings, settings){ |
31 |
let columns = new Array(table_settings.columns.length).fill({visible: true}); |
32 |
let hidden_ids, included_ids; |
33 |
[hidden_ids, included_ids] = _dt_visibility(table_settings, settings, $("#"+settings.nTable.id)); |
34 |
hidden_ids.forEach((id, i) => { columns[id] = { visible: false } } ); |
35 |
// State is not loaded if time is not passed |
36 |
return { columns, time: new Date() }; |
37 |
} |
29 |
dt_parameters.stateLoadCallback = function(settings) { |
38 |
dt_parameters.stateLoadCallback = function(settings) { |
30 |
if (!default_save_state) return {}; |
39 |
|
|
|
40 |
// Load state from URL |
41 |
const url = new URL(window.location.href); |
42 |
let state_from_url = url.searchParams.get( settings.nTable.id + '_state'); |
43 |
if ( state_from_url ) { |
44 |
settings.loaded_from_state = true; |
45 |
return JSON.parse(atob(state_from_url)); |
46 |
} |
47 |
|
48 |
if (!default_save_state) return set_default(table_settings, settings); |
31 |
|
49 |
|
32 |
let state = localStorage.getItem(table_key); |
50 |
let state = localStorage.getItem(table_key); |
33 |
if (!state) return {}; |
51 |
if (!state) return set_default(table_settings, settings); |
34 |
|
52 |
|
35 |
state = JSON.parse(state); |
53 |
state = JSON.parse(state); |
36 |
|
54 |
|
Lines 38-43
function KohaTable(id_selector, dt_parameters, table_settings, add_filters) {
Link Here
|
38 |
delete state.search; |
56 |
delete state.search; |
39 |
state.columns.forEach(c => delete c.search ); |
57 |
state.columns.forEach(c => delete c.search ); |
40 |
} |
58 |
} |
|
|
59 |
settings.loaded_from_state = true; |
41 |
return state; |
60 |
return state; |
42 |
} |
61 |
} |
43 |
|
62 |
|
Lines 193-198
function KohaTable(id_selector, dt_parameters, table_settings, add_filters) {
Link Here
|
193 |
} |
212 |
} |
194 |
); |
213 |
); |
195 |
|
214 |
|
|
|
215 |
if ( table_settings ) { |
216 |
dt_parameters["buttons"].push( |
217 |
{ |
218 |
autoClose: true, |
219 |
fade: 100, |
220 |
className: "copyConditions_controls", |
221 |
titleAttr: __("Copy conditions"), |
222 |
text: '<i class="fa fa-lg fa-copy"></i> <span class="dt-button-text">' + __("Copy conditions") + '</span>', |
223 |
action: function (e, dt, node, config) { |
224 |
let state = JSON.stringify(dt.state()); |
225 |
delete state.time; |
226 |
let searchParams = new URLSearchParams(window.location.search); |
227 |
let table_id = dt.table().node().id; |
228 |
searchParams.set(table_id + '_state', btoa(state)); |
229 |
let url = window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash; |
230 |
if( navigator.clipboard && navigator.clipboard.writeText){ |
231 |
navigator.clipboard.writeText( url ); |
232 |
// TODO Add tooltip "State copied to the clipboard" |
233 |
} |
234 |
}, |
235 |
} |
236 |
); |
237 |
} |
238 |
|
196 |
if ( table_settings && CAN_user_parameters_manage_column_config ) { |
239 |
if ( table_settings && CAN_user_parameters_manage_column_config ) { |
197 |
dt_parameters[ "buttons" ].push( |
240 |
dt_parameters[ "buttons" ].push( |
198 |
{ |
241 |
{ |
Lines 233-238
function KohaTable(id_selector, dt_parameters, table_settings, add_filters) {
Link Here
|
233 |
}); |
276 |
}); |
234 |
} |
277 |
} |
235 |
|
278 |
|
|
|
279 |
new_parameters["loaded_from_state"] = false; |
280 |
|
236 |
if ( table_settings ) { |
281 |
if ( table_settings ) { |
237 |
if ( table_settings.hasOwnProperty('default_display_length') && table_settings['default_display_length'] != null ) { |
282 |
if ( table_settings.hasOwnProperty('default_display_length') && table_settings['default_display_length'] != null ) { |
238 |
// pageLength needs to be a number, not a string, or it can cause issues with DataTable's next button. |
283 |
// pageLength needs to be a number, not a string, or it can cause issues with DataTable's next button. |