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. 33
      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
=====
* 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">
<tree string="View name">
...
<field name="name" options='"bg_color": "red: customer == True"'/>
<field name="name" options='{"bg_color": "red: customer == True"}'/>
...
</tree>
</field>
@ -39,13 +39,13 @@ Usage
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">
<tree string="View name">
...
<field name="name" 'options="fg_color": "white:customer == True"'/>
<field name="name" options='{"fg_color": "white:customer == True"}'/>
...
</tree>
</field>
@ -90,6 +90,7 @@ Contributors
* Damien Crier <damien.crier@camptocamp.com>
* Holger Brunn <hbrunn@therp.nl>
* Artem Kostyuk <a.kostyuk@mobilunity.com>
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
Maintainer
----------

2
web_tree_dynamic_colored_field/__manifest__.py

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

33
web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js

@ -12,20 +12,21 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
*/
_renderBody: function () {
if (this.arch.attrs.colors) {
var colorField = this.arch.attrs.colors.split(';')
.filter(color => color.trim().startsWith('color_field'))[0]
.split(':')[1]
.trim();
// validate the presence of that field in tree view
var fieldNames = _(this.columns).map(
(value) => { return value.attrs.name; }
);
if (fieldNames.indexOf(colorField) === -1) {
console.warn(
"No field named '" + colorField + "' present in view."
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
var fieldNames = _(this.columns).map(
(value) => { return value.attrs.name; }
);
} else {
this.colorField = colorField;
if (fieldNames.indexOf(colorField) === -1) {
console.warn(
"No field named '" + colorField + "' present in view."
);
} else {
this.colorField = colorField;
}
}
}
return this._super();
@ -56,7 +57,11 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
}
// apply <field>'s own `options`
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, 'bg_color', 'background-color', ctx);
},

Loading…
Cancel
Save