Browse Source

Merge pull request #886 from guewen/11.0-fix-dynamic-colored-json-parse-object

Fix several issues in web_tree_dynamic_colored_field
pull/922/head
Pedro M. Baeza 7 years ago
committed by GitHub
parent
commit
a095b86105
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      web_tree_dynamic_colored_field/README.rst
  2. 2
      web_tree_dynamic_colored_field/__manifest__.py
  3. 15
      web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js

9
web_tree_dynamic_colored_field/README.rst

@ -25,13 +25,13 @@ Features
Usage Usage
===== =====
* In the tree view declaration, put ``options='"bg_color": "red: customer==True"`` attribute in the ``field`` tag::
* In the tree view declaration, put ``options='{"bg_color": "red: customer==True"}`` attribute in the ``field`` tag::
... ...
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="View name"> <tree string="View name">
... ...
<field name="name" options='"bg_color": "red: customer == True"'/>
<field name="name" options='{"bg_color": "red: customer == True"}'/>
... ...
</tree> </tree>
</field> </field>
@ -39,13 +39,13 @@ Usage
With this example, column which renders 'name' field will have its background colored in red. With this example, column which renders 'name' field will have its background colored in red.
* In the tree view declaration, put ``options='"fg_color": "white:customer == True"'`` attribute in the ``field`` tag::
* In the tree view declaration, put ``options='{"fg_color": "white:customer == True"}'`` attribute in the ``field`` tag::
... ...
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="View name"> <tree string="View name">
... ...
<field name="name" 'options="fg_color": "white:customer == True"'/>
<field name="name" options='{"fg_color": "white:customer == True"}'/>
... ...
</tree> </tree>
</field> </field>
@ -90,6 +90,7 @@ Contributors
* Damien Crier <damien.crier@camptocamp.com> * Damien Crier <damien.crier@camptocamp.com>
* Holger Brunn <hbrunn@therp.nl> * Holger Brunn <hbrunn@therp.nl>
* Artem Kostyuk <a.kostyuk@mobilunity.com> * Artem Kostyuk <a.kostyuk@mobilunity.com>
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
Maintainer Maintainer
---------- ----------

2
web_tree_dynamic_colored_field/__manifest__.py

@ -4,7 +4,7 @@
'name': 'Colorize field in tree views', 'name': 'Colorize field in tree views',
'summary': 'Allows you to dynamically color fields on tree views', 'summary': 'Allows you to dynamically color fields on tree views',
'category': 'Hidden/Dependency', 'category': 'Hidden/Dependency',
'version': '11.0.1.0.0',
'version': '11.0.1.0.1',
'depends': ['web'], 'depends': ['web'],
'author': "Camptocamp, Therp BV, Odoo Community Association (OCA)", 'author': "Camptocamp, Therp BV, Odoo Community Association (OCA)",
'license': 'AGPL-3', 'license': 'AGPL-3',

15
web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js

@ -12,10 +12,10 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
*/ */
_renderBody: function () { _renderBody: function () {
if (this.arch.attrs.colors) { if (this.arch.attrs.colors) {
var colorField = this.arch.attrs.colors.split(';')
.filter(color => color.trim().startsWith('color_field'))[0]
.split(':')[1]
.trim();
var colorAttr = this.arch.attrs.colors.split(';')
.filter(color => color.trim().startsWith('color_field'));
if (colorAttr.length > 0) {
var colorField = colorAttr[0].split(':')[1].trim();
// validate the presence of that field in tree view // validate the presence of that field in tree view
var fieldNames = _(this.columns).map( var fieldNames = _(this.columns).map(
(value) => { return value.attrs.name; } (value) => { return value.attrs.name; }
@ -28,6 +28,7 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
this.colorField = colorField; this.colorField = colorField;
} }
} }
}
return this._super(); return this._super();
}, },
/** /**
@ -56,7 +57,11 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
} }
// apply <field>'s own `options` // apply <field>'s own `options`
if (!node.attrs.options) { return; } if (!node.attrs.options) { return; }
var nodeOptions = JSON.parse(node.attrs.options);
if (node.tag !== 'field') { return; }
var nodeOptions = node.attrs.options;
if (!_.isObject(nodeOptions)) {
nodeOptions = pyeval.py_eval(nodeOptions);
}
this.applyColorizeHelper($td, nodeOptions, node, 'fg_color', 'color', ctx); this.applyColorizeHelper($td, nodeOptions, node, 'fg_color', 'color', ctx);
this.applyColorizeHelper($td, nodeOptions, node, 'bg_color', 'background-color', ctx); this.applyColorizeHelper($td, nodeOptions, node, 'bg_color', 'background-color', ctx);
}, },

Loading…
Cancel
Save