Skip to content
Permalink
Browse files

[IMP]web: save advanced enabled columns i.e. show advanced column in …

…localstorage, where key will be 'model_name,field1:type,field2:type,...'

there less chances to have same key twice, to have same key twice there should two same views with same fields in same order on same model, even if there is such case where we have two same view for same model then it's ok to hide/show same fields for both views

get localstorage data in start of list renderer, reason is, init will not have list controller as a parent because renderer is instantiated from mvc and hence parent will be action manager, so get localstorage data using trigger_up in start method

two events are added get_advanced_columns and set_advanced_columns where get_advanced_columns fetches advanced columns which are enabled from localstorage and set_advanced_columns will store advanced columns enabled and this event is triggerred whenever user changes advance column from list view dropdown of advance column
also these two events are handled in relational x2m field to generate key for x2m and fetch and store data for advance columns enabled
  • Loading branch information...
msh-odoo committed Apr 16, 2019
1 parent 18236a0 commit 5301612157f0c33625d3e8f0eda1916fcea99d5a
@@ -815,7 +815,8 @@ var FieldX2Many = AbstractField.extend({
toggle_column_order: '_onToggleColumnOrder',
activate_next_widget: '_onActiveNextWidget',
navigation_move: '_onNavigationMove',
get_advanced_columns_storedkey: '_getAdvancedColumnsStoredkey',
get_advanced_columns: '_getAdvancedColumns',
set_advanced_columns: '_setAdvancedColumns',
}),

// We need to trigger the reset on every changes to be aware of the parent changes
@@ -979,8 +980,15 @@ var FieldX2Many = AbstractField.extend({
}).column_invisible;
});
},
_getAdvancedColumnsStoredkey: function (ev) {
ev.data.storageKey = _.str.sprintf('%s,%s', this.name, ev.data.storageKey);
_getAdvancedColumns: function (ev) {
ev.stopPropagation();
var fields = []
_.each(this.field.views['tree'].fields, function (field, name) {
fields.push(name + ":" + field.type);
});
var storageKey = this.field.relation + "," + fields.join(',');
var advancedColumnsEnabled = this.call('local_storage', 'getItem', storageKey);
ev.data.callback(advancedColumnsEnabled);
},
/**
* Computes the default renderer to use depending on the view type.
@@ -1163,6 +1171,14 @@ var FieldX2Many = AbstractField.extend({
}
});
},
_setAdvancedColumns: function (ev) {
var fields = []
_.each(this.field.views['tree'].fields, function (field, name) {
fields.push(name + ":" + field.type);
});
var storageKey = this.field.relation + "," + fields.join(',');
this.call('local_storage', 'setItem', storageKey, ev.data.advancedColumnsEnabled || '');
},
/**
* Parses the 'columnInvisibleFields' attribute to search for the domains
* containing the key 'parent'. If there are such domains, the string
@@ -136,7 +136,6 @@ var AbstractView = Factory.extend({
isMultiRecord: this.multi_record,
modelName: params.modelName,
viewType: this.viewType,
actionId: params.actionId,
};

var controllerState = params.controllerState || {};
@@ -643,7 +643,6 @@ var BasicModel = AbstractModel.extend({
limit: element.limit,
model: element.model,
offset: element.offset,
advancedColumnsEnabled: element.advancedColumnsEnabled,
orderedBy: element.orderedBy,
res_id: element.res_id,
res_ids: element.res_ids.slice(0),
@@ -1121,29 +1120,6 @@ var BasicModel = AbstractModel.extend({
setDirty: function (id) {
this.localData[id]._isDirty = true;
},
/**
* For list resources, this changes the advancedColumnsEnabled key.
* This method is called when advanced columns are enabled/disabled,
* most likely from x2many list view, we need to maintain state of
* advanced columns enabled so when x2many list view re-render
* we display advanced columns based advancedColumnsEnabled
*
*/
setAdvancedColumns: function (list_id, fieldName, enable) {
var list = this.localData[list_id];
if (list.type === 'record') {
return;
} else if (list._changes) {
_.each(list._changes, function (change) {
delete change.isNew;
});
}
if (enable) {
list.advancedColumnsEnabled.push(fieldName);
} else {
list.advancedColumnsEnabled.splice(list.advancedColumnsEnabled.indexOf(fieldName), 1);
}
},
/**
* For list resources, this changes the orderedBy key.
*
@@ -3708,7 +3684,6 @@ var BasicModel = AbstractModel.extend({
loadMoreOffset: 0,
model: params.modelName,
offset: params.offset || (type === 'record' ? _.indexOf(res_ids, res_id) : 0),
advancedColumnsEnabled: params.advancedColumnsEnabled || [],
openGroupByDefault: params.openGroupByDefault,
orderedBy: params.orderedBy || [],
orderedResIDs: params.orderedResIDs,
@@ -19,12 +19,10 @@ var FormController = BasicController.extend({
open_one2many_record: '_onOpenOne2ManyRecord',
open_record: '_onOpenRecord',
toggle_column_order: '_onToggleColumnOrder',
toggle_advanced_column: '_onToggleAdvancedColumn',
focus_control_button: '_onFocusControlButton',
form_dialog_discarded: '_onFormDialogDiscarded',
swipe_left: '_onSwipeLeft',
swipe_right: '_onSwipeRight',
get_advanced_columns_storedkey: '_getAdvancedColumnsStoredkey',
}),
/**
* @override
@@ -350,10 +348,6 @@ var FormController = BasicController.extend({
this._super.apply(this, arguments);
this.renderer.enableButtons();
},
_getAdvancedColumnsStoredkey: function (ev) {
ev.data.storageKey = _.str.sprintf('%s,%s,%s', this.actionId || '', this.viewType, ev.data.storageKey);
ev.data.callback(ev.data.storageKey);
},
/**
* Hook method, called when record(s) has been deleted.
*
@@ -715,15 +709,6 @@ var FormController = BasicController.extend({
self.renderer.confirmChange(state, state.id, [field]);
});
},
/**
* This method is called when someone enable/disable advanced column in
* x2many list view
*
* @private
*/
_onToggleAdvancedColumn: function (ev) {
this.model.setAdvancedColumns(ev.data.id, ev.data.name, ev.data.enable);
},
});

return FormController;
@@ -33,7 +33,8 @@ var ListController = BasicController.extend({
toggle_column_order: '_onToggleColumnOrder',
toggle_group: '_onToggleGroup',
navigation_move: '_onNavigationMove',
get_advanced_columns_storedkey: '_getAdvancedColumnsStoredkey',
get_advanced_columns: '_getAdvancedColumns',
set_advanced_columns: '_setAdvancedColumns',
}),
/**
* @constructor
@@ -46,7 +47,6 @@ var ListController = BasicController.extend({
*/
init: function (parent, model, renderer, params) {
this._super.apply(this, arguments);
this.actionId = params.actionId;
this.hasSidebar = params.hasSidebar;
this.toolbarActions = params.toolbarActions || {};
this.editable = params.editable;
@@ -332,9 +332,15 @@ var ListController = BasicController.extend({
self._updateButtons('readonly');
});
},
_getAdvancedColumnsStoredkey: function (ev) {
ev.data.storedKey = _.str.sprintf('%s,%s,%s', this.actionId, this.viewType, ev.data.storedKey);
ev.data.callback(ev.data.storedKey);
_getAdvancedColumns: function (ev) {
var state = this.model.get(this.handle);
var fields = []
_.each(state.fieldsInfo[this.viewType], function (field, name) {
fields.push(name + ":" + state.fields[name].type);
});
var storageKey = this.modelName + "," + fields.join(',');
var advancedColumnsEnabled = this.call('local_storage', 'getItem', storageKey);
ev.data.callback(advancedColumnsEnabled);
},
/**
* @override
@@ -345,6 +351,15 @@ var ListController = BasicController.extend({
var record = this.model.get(this.handle);
return _.extend(env, {domain: record.getDomain()});
},
_setAdvancedColumns: function (ev) {
var state = this.model.get(this.handle);
var fields = []
_.each(state.fieldsInfo[this.viewType], function (field, name) {
fields.push(name + ":" + state.fields[name].type);
});
var storageKey = this.modelName + "," + fields.join(',');
this.call('local_storage', 'setItem', storageKey, ev.data.advancedColumnsEnabled || '');
},
/**
* Allows to change the mode of a single row.
*
@@ -75,14 +75,12 @@ var ListRenderer = BasicRenderer.extend({
// Need to override start and call _processColumns from here as we want to trigger_up to get storedKey
// in init parent will be action manager for renderer,
// controller as a parent is set later once instance of renderer is created
var advancedColumnsFromStorage = [];
var storageKey = '';
this.trigger_up('get_advanced_columns_storedkey', {
storageKey: storageKey,
callback: function (key) { storageKey = key;}
var advancedColumnsEnabled = [];
this.trigger_up('get_advanced_columns', {
callback: function (columns) { advancedColumnsEnabled = columns;}
});
var advancedColumnsFromStorage = this.call('local_storage', 'getItem', storageKey);
this.advancedColumnsEnabled = advancedColumnsFromStorage || [];
// var advancedColumnsFromStorage = this.call('local_storage', 'getItem', storageKey);
this.advancedColumnsEnabled = advancedColumnsEnabled || [];
this._processColumns(this.columnInvisibleFields || {});
return this._super.apply(this, arguments);
},
@@ -884,20 +882,13 @@ var ListRenderer = BasicRenderer.extend({
_onAddColumn: function (ev) {
var currentElement = ev.currentTarget;
if (!currentElement.checked) {
this.trigger_up('toggle_advanced_column', {id: this.state.id, name: currentElement.name});
this.advancedColumnsEnabled.splice(this.advancedColumnsEnabled.indexOf(currentElement.name), 1);
this.columns = this._computeColumns();
} else {
this.trigger_up('toggle_advanced_column', {id: this.state.id, name: currentElement.name, enable: true});
this.advancedColumnsEnabled.push(currentElement.name);
this.columns = this._computeColumns();
}
var storageKey = '';
this.trigger_up('get_advanced_columns_storedkey', {
storageKey: storageKey,
callback: function (key) { storageKey = key;}
});
this.call('local_storage', 'setItem', storageKey, this.advancedColumnsEnabled);
this.trigger_up('set_advanced_columns', {advancedColumnsEnabled: this.advancedColumnsEnabled});
this._renderView();
},
/**

0 comments on commit 5301612

Please sign in to comment.
You can’t perform that action at this time.