From d92393198866b14bf0d77176c28aa032626daa98 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 6 Dec 2018 14:25:47 +0200 Subject: [PATCH] [FIX] web_widget_x2many_2d_matrix: _renderBodyCell --- web_widget_x2many_2d_matrix/README.rst | 18 +++++- web_widget_x2many_2d_matrix/__manifest__.py | 3 +- .../readme/DESCRIPTION.rst | 2 +- .../readme/HISTORY.rst | 11 ++++ .../static/description/index.html | 57 +++++++++++++------ .../static/src/js/2d_matrix_renderer.js | 44 ++++++++++---- 6 files changed, 104 insertions(+), 31 deletions(-) create mode 100644 web_widget_x2many_2d_matrix/readme/HISTORY.rst diff --git a/web_widget_x2many_2d_matrix/README.rst b/web_widget_x2many_2d_matrix/README.rst index 1372c625ae4a..c0693fcf41c4 100644 --- a/web_widget_x2many_2d_matrix/README.rst +++ b/web_widget_x2many_2d_matrix/README.rst @@ -42,7 +42,7 @@ An example use case would be: Select some projects and some employees so that a manager can easily fill in the planned_hours for one task per employee. The result could look like this: -.. image:: https://raw.githubusercontent.com/web_widget_x2many_2d_matrix/static/description/screenshot.png +.. image:: https://raw.githubusercontent.com/OCA/web/12.0/web_widget_x2many_2d_matrix/static/description/screenshot.png :alt: Screenshot The beauty of this is that you have an arbitrary amount of columns with this @@ -168,6 +168,21 @@ Known issues / Roadmap * Support extra invisible fields inside each cell. +Changelog +========= + +12.0.1.0.1 (2018-12-07) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [FIX] Cells are unable to render property. + (`#1126 `_) + +12.0.1.0.0 (2018-11-20) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [12.0][MIG] web_widget_x2many_2d_matrix + (`#1101 `_) + Bug Tracker =========== @@ -187,6 +202,7 @@ Authors * Therp BV * Tecnativa * Camptocamp +* Brainbean Apps Contributors ~~~~~~~~~~~~ diff --git a/web_widget_x2many_2d_matrix/__manifest__.py b/web_widget_x2many_2d_matrix/__manifest__.py index bfee53ec3550..3299e66b71ac 100644 --- a/web_widget_x2many_2d_matrix/__manifest__.py +++ b/web_widget_x2many_2d_matrix/__manifest__.py @@ -4,11 +4,12 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': '2D matrix for x2many fields', - 'version': '12.0.1.0.0', + 'version': '12.0.1.0.1', 'author': ( 'Therp BV, ' 'Tecnativa, ' 'Camptocamp, ' + 'Brainbean Apps, ' 'Odoo Community Association (OCA)' ), 'website': 'https://github.com/OCA/web', diff --git a/web_widget_x2many_2d_matrix/readme/DESCRIPTION.rst b/web_widget_x2many_2d_matrix/readme/DESCRIPTION.rst index a84da8005ae6..d3f10cae8eef 100644 --- a/web_widget_x2many_2d_matrix/readme/DESCRIPTION.rst +++ b/web_widget_x2many_2d_matrix/readme/DESCRIPTION.rst @@ -15,7 +15,7 @@ An example use case would be: Select some projects and some employees so that a manager can easily fill in the planned_hours for one task per employee. The result could look like this: -.. image:: /web_widget_x2many_2d_matrix/static/description/screenshot.png +.. image:: https://raw.githubusercontent.com/OCA/web/12.0/web_widget_x2many_2d_matrix/static/description/screenshot.png :alt: Screenshot The beauty of this is that you have an arbitrary amount of columns with this diff --git a/web_widget_x2many_2d_matrix/readme/HISTORY.rst b/web_widget_x2many_2d_matrix/readme/HISTORY.rst new file mode 100644 index 000000000000..8bad8c46cd42 --- /dev/null +++ b/web_widget_x2many_2d_matrix/readme/HISTORY.rst @@ -0,0 +1,11 @@ +12.0.1.0.1 (2018-12-07) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [FIX] Cells are unable to render property. + (`#1126 `_) + +12.0.1.0.0 (2018-11-20) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [12.0][MIG] web_widget_x2many_2d_matrix + (`#1101 `_) diff --git a/web_widget_x2many_2d_matrix/static/description/index.html b/web_widget_x2many_2d_matrix/static/description/index.html index bd5775f28619..1be53a2a7d6c 100644 --- a/web_widget_x2many_2d_matrix/static/description/index.html +++ b/web_widget_x2many_2d_matrix/static/description/index.html @@ -397,29 +397,34 @@

2D matrix for x2many fields

An example use case would be: Select some projects and some employees so that a manager can easily fill in the planned_hours for one task per employee. The result could look like this:

-Screenshot +Screenshot

The beauty of this is that you have an arbitrary amount of columns with this widget, trying to get this in standard x2many lists involves some quite ugly hacks.

Table of contents

-

Usage

+

Usage

Use this widget by saying:

 <field name="my_field" widget="x2many_2d_matrix" />
@@ -457,7 +462,7 @@ 

Usage

column totals. True by default
-

Example

+

Example

You need a data structure already filled with values. Let’s assume we want to use this widget in a wizard that lets the user fill in planned hours for one task per project per user. In this case, we can use project.task as our @@ -509,7 +514,7 @@

Example

-

Known issues / Roadmap

+

Known issues / Roadmap

  • Support extra attributes on each field cell via field_extra_attrs param. We could set a cell as not editable, required or readonly for instance. @@ -523,8 +528,25 @@

    Known issues / Roadmap

  • Support extra invisible fields inside each cell.
+
+

Changelog

+
+

12.0.1.0.1 (2018-12-07)

+
    +
  • [FIX] Cells are unable to render property. +(#1126)
  • +
+
+
+

12.0.1.0.0 (2018-11-20)

+
    +
  • [12.0][MIG] web_widget_x2many_2d_matrix +(#1101)
  • +
+
+
-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed @@ -532,17 +554,18 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • Therp BV
  • Tecnativa
  • Camptocamp
  • +
  • Brainbean Apps
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose diff --git a/web_widget_x2many_2d_matrix/static/src/js/2d_matrix_renderer.js b/web_widget_x2many_2d_matrix/static/src/js/2d_matrix_renderer.js index ac627e44c7c0..7338957f8009 100644 --- a/web_widget_x2many_2d_matrix/static/src/js/2d_matrix_renderer.js +++ b/web_widget_x2many_2d_matrix/static/src/js/2d_matrix_renderer.js @@ -1,23 +1,25 @@ /* Copyright 2018 Simone Orsi + * Copyright 2018 Brainbean Apps * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (require) { "use strict"; - // Heavily inspired by Odoo's `ListRenderer` var BasicRenderer = require('web.BasicRenderer'); var config = require('web.config'); var core = require('web.core'); var field_utils = require('web.field_utils'); var _t = core._t; + var FIELD_CLASSES = { - // Copied from ListRenderer float: 'o_list_number', integer: 'o_list_number', monetary: 'o_list_number', text: 'o_list_text', }; + // X2Many2dMatrixRenderer is heavily inspired by Odoo's ListRenderer + // and is reusing portions of code from list_renderer.js var X2Many2dMatrixRenderer = BasicRenderer.extend({ /** @@ -53,8 +55,11 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ _renderView: function () { var self = this; + this.$el + .removeClass('table-responsive') + .empty(); + // Display a nice message if there's no data to display - this.$el.empty(); if (!self.rows.length) { var $alert = $('

', {'class': 'alert alert-info'}); $alert.text(_t('Sorry no matrix data to display.')); @@ -246,9 +251,7 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ */ _renderBodyCell: function (record, node, colIndex, options) { var tdClassName = 'o_data_cell'; - if (node.tag === 'button') { - tdClassName += ' o_list_button'; - } else if (node.tag === 'field') { + if (node.tag === 'field') { var typeClass = FIELD_CLASSES[ this.state.fields[node.attrs.name].type ]; @@ -259,11 +262,14 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ tdClassName += ' o_' + node.attrs.widget + '_cell'; } } + // TODO roadmap: here we should collect possible extra params // the user might want to attach to each single cell. + var $td = $('', { 'class': tdClassName, }); + if (_.isUndefined(record)) { // Without record, nothing elese to do return $td; @@ -272,6 +278,7 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ 'data-form-id': record.id, 'data-id': record.data.id, }); + // We register modifiers on the element so that it gets // the correct modifiers classes (for styling) var modifiers = this._registerModifiers( @@ -286,13 +293,28 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ if (modifiers.invisible && !(options && options.renderInvisible)) { return $td; } + // Enforce mode of the parent options.mode = this.getParent().mode; - var widget = this._renderFieldWidget( - node, record, _.pick(options, 'mode') - ); - this._handleAttributes(widget.$el, node); - return $td.append(widget.$el); + + if (node.tag === 'widget') { + return $td.append(this._renderWidget(record, node)); + } + if (node.attrs.widget || (options && options.renderWidgets)) { + var $el = this._renderFieldWidget(node, record, _.pick(options, 'mode')); + this._handleAttributes($el, node); + return $td.append($el); + } + var name = node.attrs.name; + var field = this.state.fields[name]; + var value = record.data[name]; + var formattedValue = field_utils.format[field.type](value, field, { + data: record.data, + escape: true, + isPassword: 'password' in node.attrs, + }); + this._handleAttributes($td, node); + return $td.html(formattedValue); }, /**