From 409e7c18c3186ffdac78c109b762edd040bb1805 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 28 Mar 2018 11:37:48 +0200 Subject: [PATCH] [REF] FormRenderer: renderOuterGroup This rev. extracts the part of the rendering that renders outer groups (i.e. groups that contain groups) in its own function. This allows extentions of the FormRenderer to use it (for instance, the renderer of the new Dashboard view). --- .../static/src/js/views/form/form_renderer.js | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/addons/web/static/src/js/views/form/form_renderer.js b/addons/web/static/src/js/views/form/form_renderer.js index f6430d4a251..61576832ff5 100644 --- a/addons/web/static/src/js/views/form/form_renderer.js +++ b/addons/web/static/src/js/views/form/form_renderer.js @@ -502,6 +502,32 @@ var FormRenderer = BasicRenderer.extend({ } return this._renderGenericTag(node); }, + /** + * Renders a 'group' node, which contains 'group' nodes in its children. + * + * @param {Object} node] + * @returns {JQueryElement} + */ + _renderOuterGroup: function (node) { + var self = this; + var $result = $('
', {class: 'o_group'}); + var colSize = Math.max(1, Math.round(12 / (parseInt(node.attrs.col, 10) || 2))); + if (node.attrs.string) { + var $sep = $('
', {class: 'o_horizontal_separator'}).text(node.attrs.string); + $result.append($sep); + } + $result.append(_.map(node.children, function (child) { + if (child.tag === 'newline') { + return $('
'); + } + var $child = self._renderNode(child); + $child.addClass('o_group_col_' + (colSize * (parseInt(child.attrs.colspan, 10) || 1))); + return $child; + })); + this._handleAttributes($result, node); + this._registerModifiers(node, this.state, $result); + return $result; + }, /** * @private * @param {Object} node @@ -603,31 +629,13 @@ var FormRenderer = BasicRenderer.extend({ * @returns {jQueryElement} */ _renderTagGroup: function (node) { - var self = this; var isOuterGroup = _.some(node.children, function (child) { return child.tag === 'group'; }); if (!isOuterGroup) { return this._renderInnerGroup(node); } - - var $result = $('
', {class: 'o_group'}); - var colSize = Math.max(1, Math.round(12 / (parseInt(node.attrs.col, 10) || 2))); - if (node.attrs.string) { - var $sep = $('
', {class: 'o_horizontal_separator'}).text(node.attrs.string); - $result.append($sep); - } - $result.append(_.map(node.children, function (child) { - if (child.tag === 'newline') { - return $('
'); - } - var $child = self._renderNode(child); - $child.addClass('o_group_col_' + (colSize * (parseInt(child.attrs.colspan, 10) || 1))); - return $child; - })); - this._handleAttributes($result, node); - this._registerModifiers(node, this.state, $result); - return $result; + return this._renderOuterGroup(node); }, /** * @private