summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic
diff options
context:
space:
mode:
authorDavid Monjoie <dmo@odoo.com>2019-06-05 14:27:32 +0000
committerVincent Schippefilt <vsc@odoo.com>2019-07-30 06:37:23 +0000
commit307db300670e2c9c3cb8cfa11b2e5e63edd8aa69 (patch)
treecb459aeab47df2effc6f806215950b3b37709368 /addons/web/static/src/js/views/basic
parent321a3699ed634287010c4ab0701bf6f28704c250 (diff)
[FIX] web: add view id in optional fields local storage key
Since the renderer does not know the view id, we moved the local storage key computation up to the basic controller, which makes more sense since the renderer is supposed to be inert. The _processColumns function had to be moved in willStart however, since it now needs the controller to respond to the trigger_up and the controller is not present during the init of the renderer. closes odoo/odoo#34051 Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
Diffstat (limited to 'addons/web/static/src/js/views/basic')
-rw-r--r--addons/web/static/src/js/views/basic/basic_controller.js89
-rw-r--r--addons/web/static/src/js/views/basic/basic_view.js1
2 files changed, 90 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js
index e76aec046e8..fc9cd1c7f2f 100644
--- a/addons/web/static/src/js/views/basic/basic_controller.js
+++ b/addons/web/static/src/js/views/basic/basic_controller.js
@@ -21,6 +21,8 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
reload: '_onReload',
resequence_records: '_onResequenceRecords',
set_dirty: '_onSetDirty',
+ load_optional_fields: '_onLoadOptionalFields',
+ save_optional_fields: '_onSaveOptionalFields',
sidebar_data_asked: '_onSidebarDataAsked',
translate: '_onTranslate',
}),
@@ -43,6 +45,7 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
// operations to complete before checking if there are changes to
// discard when discardChanges is called
this.savingDef = Promise.resolve();
+ this.viewId = params.viewId;
},
/**
* @override
@@ -419,6 +422,49 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
});
},
/**
+ * Compute the optional fields local storage key using the given parts.
+ *
+ * @param {Object} keyParts
+ * @param {string} keyParts.viewType view type
+ * @param {string} [keyParts.relationalField] name of the field with subview
+ * @param {integer} [keyParts.subViewId] subview id
+ * @param {string} [keyParts.subViewType] type of the subview
+ * @param {Object} keyParts.fields fields
+ * @param {string} keyParts.fields.name field name
+ * @param {string} keyParts.fields.type field type
+ * @returns {string} local storage key for optional fields in this view
+ * @private
+ */
+ _getOptionalFieldsLocalStorageKey: function (keyParts) {
+ keyParts.model = this.modelName;
+ keyParts.viewType = this.viewType;
+ keyParts.viewId = this.viewId;
+
+ var parts = [
+ 'model',
+ 'viewType',
+ 'viewId',
+ 'relationalField',
+ 'subViewType',
+ 'subViewId',
+ ];
+
+ var viewIdentifier = parts.reduce(function (identifier, partName) {
+ if (partName in keyParts) {
+ return identifier + ',' + keyParts[partName];
+ }
+ return identifier;
+ }, 'optional_fields');
+
+ viewIdentifier =
+ keyParts.fields.sort(this._nameSortComparer)
+ .reduce(function (identifier, field) {
+ return identifier + ',' + field.name;
+ }, viewIdentifier);
+
+ return viewIdentifier;
+ },
+ /**
* Return the params (current_min, limit and size) to pass to the pager,
* according to the current state.
*
@@ -458,6 +504,16 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
return true;
},
/**
+ * Sort function used to sort the fields by names, to compute the optional fields keys
+ *
+ * @param {Object} left
+ * @param {Object} right
+ * @private
+ */
+ _nameSortComparer: function(left, right) {
+ return left.name < right.name ? -1 : 1;
+ },
+ /**
* Helper function to display a warning that some fields have an invalid
* value. This is used when a save operation cannot be completed.
*
@@ -676,6 +732,39 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
});
},
/**
+ * Load the optional columns settings in local storage for this view
+ *
+ * @param {OdooEvent} ev
+ * @param {Object} ev.data.keyParts see _getLocalStorageKey
+ * @param {function} ev.data.callback function to call with the result
+ * @private
+ */
+ _onLoadOptionalFields: function (ev) {
+ var res = this.call(
+ 'local_storage',
+ 'getItem',
+ this._getOptionalFieldsLocalStorageKey(ev.data.keyParts)
+ );
+ ev.data.callback(res);
+ },
+ /**
+ * Save the optional columns settings in local storage for this view
+ *
+ * @param {OdooEvent} ev
+ * @param {Object} ev.data.keyParts see _getLocalStorageKey
+ * @param {Array<string>} ev.data.optionalColumnsEnabled list of optional
+ * field names that have been enabled
+ * @private
+ */
+ _onSaveOptionalFields: function (ev) {
+ this.call(
+ 'local_storage',
+ 'setItem',
+ this._getOptionalFieldsLocalStorageKey(ev.data.keyParts),
+ ev.data.optionalColumnsEnabled
+ );
+ },
+ /**
* @private
* @param {OdooEvent} ev
*/
diff --git a/addons/web/static/src/js/views/basic/basic_view.js b/addons/web/static/src/js/views/basic/basic_view.js
index 008bbcf8775..428378d69ab 100644
--- a/addons/web/static/src/js/views/basic/basic_view.js
+++ b/addons/web/static/src/js/views/basic/basic_view.js
@@ -48,6 +48,7 @@ var BasicView = AbstractView.extend({
this.controllerParams.archiveEnabled = 'active' in this.fields;
this.controllerParams.hasButtons =
'action_buttons' in params ? params.action_buttons : true;
+ this.controllerParams.viewId = viewInfo.view_id;
this.loadParams.fieldsInfo = this.fieldsInfo;
this.loadParams.fields = this.fields;