Extract WebUI localStorage access into class

This commit is contained in:
Thomas Piccirello 2019-08-06 00:28:15 -07:00
parent f339f629ae
commit 7047974132
9 changed files with 100 additions and 70 deletions

View file

@ -50,8 +50,8 @@ const DynamicTable = new Class({
this.selectedRows = [];
this.columns = [];
this.contextMenu = contextMenu;
this.sortedColumn = getLocalStorageItem('sorted_column_' + this.dynamicTableDivId, 0);
this.reverseSort = getLocalStorageItem('reverse_sort_' + this.dynamicTableDivId, '0');
this.sortedColumn = LocalPreferences.get('sorted_column_' + this.dynamicTableDivId, 0);
this.reverseSort = LocalPreferences.get('reverse_sort_' + this.dynamicTableDivId, '0');
this.initColumns();
this.loadColumnsOrder();
this.updateTableHeaders();
@ -214,15 +214,15 @@ const DynamicTable = new Class({
resetElementBorderStyle(this.lastHoverTh);
el.setStyle('background-color', '');
if (this.currentHeaderAction === 'resize')
localStorage.setItem('column_' + this.resizeTh.columnName + '_width_' + this.dynamicTableDivId, this.columns[this.resizeTh.columnName].width);
LocalPreferences.set('column_' + this.resizeTh.columnName + '_width_' + this.dynamicTableDivId, this.columns[this.resizeTh.columnName].width);
if ((this.currentHeaderAction === 'drag') && (el !== this.lastHoverTh)) {
this.saveColumnsOrder();
const val = localStorage.getItem('columns_order_' + this.dynamicTableDivId).split(',');
const val = LocalPreferences.get('columns_order_' + this.dynamicTableDivId).split(',');
val.erase(el.columnName);
let pos = val.indexOf(this.lastHoverTh.columnName);
if (this.dropSide === 'right') ++pos;
val.splice(pos, 0, el.columnName);
localStorage.setItem('columns_order_' + this.dynamicTableDivId, val.join(','));
LocalPreferences.set('columns_order_' + this.dynamicTableDivId, val.join(','));
this.loadColumnsOrder();
this.updateTableHeaders();
while (this.tableBody.firstChild)
@ -283,7 +283,7 @@ const DynamicTable = new Class({
showColumn: function(columnName, show) {
this.columns[columnName].visible = show ? '1' : '0';
localStorage.setItem('column_' + columnName + '_visible_' + this.dynamicTableDivId, show ? '1' : '0');
LocalPreferences.set('column_' + columnName + '_visible_' + this.dynamicTableDivId, show ? '1' : '0');
this.updateColumn(columnName);
},
@ -339,11 +339,11 @@ const DynamicTable = new Class({
const column = {};
column['name'] = name;
column['title'] = name;
column['visible'] = getLocalStorageItem('column_' + name + '_visible_' + this.dynamicTableDivId, defaultVisible ? '1' : '0');
column['visible'] = LocalPreferences.get('column_' + name + '_visible_' + this.dynamicTableDivId, defaultVisible ? '1' : '0');
column['force_hide'] = false;
column['caption'] = caption;
column['style'] = style;
column['width'] = getLocalStorageItem('column_' + name + '_width_' + this.dynamicTableDivId, defaultWidth);
column['width'] = LocalPreferences.get('column_' + name + '_width_' + this.dynamicTableDivId, defaultWidth);
column['dataProperties'] = [name];
column['getRowValue'] = function(row, pos) {
if (pos === undefined)
@ -372,7 +372,7 @@ const DynamicTable = new Class({
loadColumnsOrder: function() {
const columnsOrder = [];
const val = localStorage.getItem('columns_order_' + this.dynamicTableDivId);
const val = LocalPreferences.get('columns_order_' + this.dynamicTableDivId);
if (val === null || val === undefined) return;
val.split(',').forEach(function(v) {
if ((v in this.columns) && (!columnsOrder.contains(v)))
@ -394,7 +394,7 @@ const DynamicTable = new Class({
val += ',';
val += this.columns[i].name;
}
localStorage.setItem('columns_order_' + this.dynamicTableDivId, val);
LocalPreferences.set('columns_order_' + this.dynamicTableDivId, val);
},
updateTableHeaders: function() {
@ -456,7 +456,7 @@ const DynamicTable = new Class({
},
getSortedColumn: function() {
return localStorage.getItem('sorted_column_' + this.dynamicTableDivId);
return LocalPreferences.get('sorted_column_' + this.dynamicTableDivId);
},
setSortedColumn: function(column) {
@ -471,8 +471,8 @@ const DynamicTable = new Class({
this.reverseSort = this.reverseSort === '0' ? '1' : '0';
this.setSortedColumnIcon(column, null, (this.reverseSort === '1'));
}
localStorage.setItem('sorted_column_' + this.dynamicTableDivId, column);
localStorage.setItem('reverse_sort_' + this.dynamicTableDivId, this.reverseSort);
LocalPreferences.set('sorted_column_' + this.dynamicTableDivId, column);
LocalPreferences.set('reverse_sort_' + this.dynamicTableDivId, this.reverseSort);
this.updateTable(false);
},