From 66ccc6503d3b02653f4631d08bc55d875a35501d Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Mon, 28 May 2018 18:26:22 +0200 Subject: [IMP] web: correctly handle attributes on non inline view Before this rev. the `column_invisible` and `default_order` attribute, set in a x2m list view were only taken into account for inline views. The technical reason behind is because non inline views are fetched after the main view processing. Non inline x2m list views now correctly handle these two attributes. --- addons/web/static/src/js/views/basic/basic_view.js | 65 +++++++++++++--------- 1 file changed, 38 insertions(+), 27 deletions(-) (limited to 'addons/web/static/src/js/views/basic') 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 ad15931c6c6..22900e12d6b 100644 --- a/addons/web/static/src/js/views/basic/basic_view.js +++ b/addons/web/static/src/js/views/basic/basic_view.js @@ -276,33 +276,7 @@ var BasicView = AbstractView.extend({ attrs.mode = mode; if (mode in attrs.views) { var view = attrs.views[mode]; - var defaultOrder = view.arch.attrs.default_order; - if (defaultOrder) { - // process the default_order, which is like 'name,id desc' - // but we need it like [{name: 'name', asc: true}, {name: 'id', asc: false}] - attrs.orderedBy = _.map(defaultOrder.split(','), function (order) { - order = order.trim().split(' '); - return {name: order[0], asc: order[1] !== 'desc'}; - }); - } else { - // if there is a field with widget `handle`, the x2many - // needs to be ordered by this field to correctly display - // the records - var handleField = _.find(view.arch.children, function (child) { - return child.attrs && child.attrs.widget === 'handle'; - }); - if (handleField) { - attrs.orderedBy = [{name: handleField.attrs.name, asc: true}]; - } - } - - attrs.columnInvisibleFields = {}; - _.each(view.arch.children, function (child) { - if (child.attrs && child.attrs.modifiers) { - attrs.columnInvisibleFields[child.attrs.name] = - child.attrs.modifiers.column_invisible || false; - } - }); + this._processSubViewAttrs(view, attrs); } } if (attrs.Widget.prototype.fieldsToFetch) { @@ -398,6 +372,43 @@ var BasicView = AbstractView.extend({ } return node.tag !== 'arch'; }, + /** + * Processes in place the subview attributes (in particular, + * `default_order``and `column_invisible`). + * + * @private + * @param {Object} view - the field subview + * @param {Object} attrs - the field attributes (from the xml) + */ + _processSubViewAttrs: function (view, attrs) { + var defaultOrder = view.arch.attrs.default_order; + if (defaultOrder) { + // process the default_order, which is like 'name,id desc' + // but we need it like [{name: 'name', asc: true}, {name: 'id', asc: false}] + attrs.orderedBy = _.map(defaultOrder.split(','), function (order) { + order = order.trim().split(' '); + return {name: order[0], asc: order[1] !== 'desc'}; + }); + } else { + // if there is a field with widget `handle`, the x2many + // needs to be ordered by this field to correctly display + // the records + var handleField = _.find(view.arch.children, function (child) { + return child.attrs && child.attrs.widget === 'handle'; + }); + if (handleField) { + attrs.orderedBy = [{name: handleField.attrs.name, asc: true}]; + } + } + + attrs.columnInvisibleFields = {}; + _.each(view.arch.children, function (child) { + if (child.attrs && child.attrs.modifiers) { + attrs.columnInvisibleFields[child.attrs.name] = + child.attrs.modifiers.column_invisible || false; + } + }); + }, }); return BasicView; -- cgit v1.2.3