|
Lines 15-45
function KohaTable(id_selector, dt_parameters, table_settings, add_filters) {
Link Here
|
| 15 |
let columns_settings = table_settings["columns"]; |
15 |
let columns_settings = table_settings["columns"]; |
| 16 |
|
16 |
|
| 17 |
let table_key = 'DataTables_%s_%s_%s'.format( |
17 |
let table_key = 'DataTables_%s_%s_%s'.format( |
| 18 |
table_settings["module"], |
18 |
table_settings.module, |
| 19 |
table_settings["page"], |
19 |
table_settings.page, |
| 20 |
table_settings["table"]); |
20 |
table_settings.table); |
| 21 |
|
21 |
|
| 22 |
let default_save_state = table_settings.default_save_state; |
22 |
let default_save_state = table_settings.default_save_state; |
| 23 |
let default_save_state_search = table_settings.default_save_state_search; |
23 |
let default_save_state_search = table_settings.default_save_state_search; |
| 24 |
|
24 |
|
| 25 |
if ( default_save_state ) { |
25 |
dt_parameters.stateSave = true; |
| 26 |
dt_parameters["stateSave"] = true; |
26 |
dt_parameters.stateSaveCallback = function( settings, data ) { |
| 27 |
dt_parameters["stateSaveCallback"] = function( settings, data ) { |
27 |
localStorage.setItem( table_key, JSON.stringify(data) ) |
| 28 |
if (!default_save_state_search ) { |
|
|
| 29 |
delete data.search; |
| 30 |
data.columns.forEach(c => delete c.search ); |
| 31 |
} |
| 32 |
localStorage.setItem( table_key, JSON.stringify(data) ) |
| 33 |
} |
| 34 |
dt_parameters["stateLoadCallback"] = function(settings) { |
| 35 |
return JSON.parse( localStorage.getItem(table_key) ) |
| 36 |
} |
| 37 |
let local_settings = localStorage.getItem(table_key); |
| 38 |
columns_settings = get_columns_saved_state(local_settings, columns_settings); |
| 39 |
} else { |
| 40 |
localStorage.removeItem(table_key); |
| 41 |
} |
28 |
} |
|
|
29 |
dt_parameters.stateLoadCallback = function(settings) { |
| 30 |
if (!default_save_state) return {}; |
| 31 |
|
| 32 |
let state = localStorage.getItem(table_key); |
| 33 |
if (!state) return {}; |
| 42 |
|
34 |
|
|
|
35 |
state = JSON.parse(state); |
| 36 |
|
| 37 |
if (!default_save_state_search ) { |
| 38 |
delete state.search; |
| 39 |
state.columns.forEach(c => delete c.search ); |
| 40 |
} |
| 41 |
return state; |
| 42 |
} |
| 43 |
|
43 |
|
| 44 |
$(columns_settings).each( function() { |
44 |
$(columns_settings).each( function() { |
| 45 |
var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector + ' th' ); |
45 |
var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector + ' th' ); |
|
Lines 264-308
function KohaTable(id_selector, dt_parameters, table_settings, add_filters) {
Link Here
|
| 264 |
|
264 |
|
| 265 |
return table; |
265 |
return table; |
| 266 |
} |
266 |
} |
| 267 |
|
|
|
| 268 |
|
| 269 |
/* get_columns_saved_state checks for a DataTables configuration saved |
| 270 |
* in the browser's local storage. If it is present, the columns |
| 271 |
* configuration supplied by Koha is overwritten |
| 272 |
* |
| 273 |
* It takes two parameters: |
| 274 |
* - localstorage_config, the DataTables saved state object from local storage |
| 275 |
* - columns_settings, the columns settings object supplied by the template |
| 276 |
* |
| 277 |
* An example: |
| 278 |
* |
| 279 |
* var columns_settings = [% ColumnsSettings.GetColumns( 'module', 'page', 'table', 'json' ) | $raw %]; |
| 280 |
* var saved_table = localStorage.getItem("DataTables_TABLE_ID_/cgi-bin/koha/PATH/TO/SCRIPT.pl"); |
| 281 |
* var updated_settings = get_columns_saved_state( saved_table, columns_settings ); |
| 282 |
* |
| 283 |
* KohaTable("TABLE_ID", { |
| 284 |
* "stateSave": true |
| 285 |
* }, updated_settings); |
| 286 |
*/ |
| 287 |
|
| 288 |
function get_columns_saved_state( localstorage_config, columns_settings ){ |
| 289 |
var tables = JSON.parse( localstorage_config ); |
| 290 |
// if a table configuration was found in local storage, parse it |
| 291 |
if( tables ){ |
| 292 |
var stateSave_column_visibility = []; |
| 293 |
$(tables.columns).each(function(){ |
| 294 |
stateSave_column_visibility.push( this.visible === true ? 0 : 1 ); |
| 295 |
}); |
| 296 |
$.each( columns_settings, function( index, key ){ |
| 297 |
if( stateSave_column_visibility[ index ] !== columns_settings[key] ){ |
| 298 |
columns_settings[ index ].is_hidden = stateSave_column_visibility[ index ]; |
| 299 |
} |
| 300 |
}); |
| 301 |
return columns_settings; |
| 302 |
} else { |
| 303 |
return columns_settings; |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
</script> |
267 |
</script> |
| 308 |
<!-- / columns_settings.inc --> |
268 |
<!-- / columns_settings.inc --> |