summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-03-24 08:39:35 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit348a44855d65ea780e5bbfcf536df49753cf6dd7 (patch)
treef963817f5e2a99c7cab31cec25eef95961b984df /addons/web/static/src
parentc8fd0e4507a3a1f677ae69bb877fa62766e397d6 (diff)
[IMP] web: data_manager: make field description self-contained
The fields are represented as an Object whose keys are the field names and values their description. By adding the name inside the description, this commit makes it fully self-contained. This commit also moves the processing of fields_views s.t. they are stored processed in the cache, instead of processing them each time they were requested.
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/services/data_manager.js47
1 files changed, 34 insertions, 13 deletions
diff --git a/addons/web/static/src/js/services/data_manager.js b/addons/web/static/src/js/services/data_manager.js
index 5d5b71ece17..abcf10a2e6d 100644
--- a/addons/web/static/src/js/services/data_manager.js
+++ b/addons/web/static/src/js/services/data_manager.js
@@ -96,9 +96,7 @@ return core.Class.extend({
}).then(function (result) {
// Postprocess fields_views and insert them into the fields_views cache
result.fields_views = _.mapObject(result.fields_views, self._postprocess_fvg.bind(self));
- _.each(result.fields_views, function (fields_view) {
- _.defaults(fields_view.fields, result.fields);
- });
+ self.processViews(result.fields_views, result.fields);
_.each(views_descr, function (view_descr) {
var toolbar = options.toolbar && view_descr[1] !== 'search';
var fv_key = self._gen_key(model, view_descr[0], view_descr[1], toolbar, context);
@@ -114,15 +112,7 @@ return core.Class.extend({
}, this._invalidate.bind(this, this._cache.views, key));
}
- return this._cache.views[key].then(function (views) {
- return _.mapObject(views, function (view, viewType) {
- return _.extend(view, self._processFieldsView({
- type: viewType,
- arch: view.arch,
- fields: view.fields,
- }));
- });
- });
+ return this._cache.views[key];
},
/**
@@ -189,6 +179,37 @@ return core.Class.extend({
},
/**
+ * Processes fields and fields_views. For each field, writes its name inside
+ * the field description to make it self-contained. For each fields_view,
+ * completes its fields with the missing ones.
+ *
+ * @param {Object} fieldsViews object of fields_views (keys are view types)
+ * @param {Object} fields all the fields of the model
+ */
+ processViews: function (fieldsViews, fields) {
+ var fieldName, fieldsView, viewType;
+ // write the field name inside the description for all fields
+ for (fieldName in fields) {
+ fields[fieldName].name = fieldName;
+ }
+ for (viewType in fieldsViews) {
+ fieldsView = fieldsViews[viewType];
+ // write the field name inside the description for fields in view
+ for (fieldName in fieldsView.fields) {
+ fieldsView.fields[fieldName].name = fieldName;
+ }
+ // complete fields (in view) with missing ones
+ _.defaults(fieldsView.fields, fields);
+ // process the fields_view
+ _.extend(fieldsView, this._processFieldsView({
+ type: viewType,
+ arch: fieldsView.arch,
+ fields: fieldsView.fields,
+ }));
+ }
+ },
+
+ /**
* Private function that postprocesses fields_view (mainly parses the arch attribute)
*/
_postprocess_fvg: function (fields_view) {
@@ -205,7 +226,7 @@ return core.Class.extend({
id_field.type = 'id';
}
- // Process inner views (one2manys)
+ // Process inner views (x2manys)
_.each(fields_view.fields, function(field) {
_.each(field.views || {}, function(view) {
self._postprocess_fvg(view);