mirror of https://github.com/OCA/web.git
[MIG] web_tree_dynamic_colored_field: Migration to 13.0
Use 'options' instead of 'colors' on tree views
The colors attribute has been removed from the RelaxNG schema in
Odoo [0], so use the 'options' instead.
Closes #1479
[0] 7024f8d58b (diff-e9acd2f731cc01f302055b6e232df983)
pull/3107/head
parent
4cfae73348
commit
1a06367d49
|
@ -4,7 +4,7 @@
|
|||
"name": "Colorize field in tree views",
|
||||
"summary": "Allows you to dynamically color fields on tree views",
|
||||
"category": "Hidden/Dependency",
|
||||
"version": "12.0.1.0.0",
|
||||
"version": "13.0.1.0.0",
|
||||
"depends": ["web"],
|
||||
"author": "Camptocamp, Therp BV, Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<field name="inherit_id" ref="base.view_users_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<tree position="attributes">
|
||||
<attribute name="colors">color_field: lang</attribute>
|
||||
<attribute name="options">{"color_field": "lang"}</attribute>
|
||||
</tree>
|
||||
<field name="login_date" position="attributes">
|
||||
<attribute name="options">{
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
This module aims to add support for dynamically coloring fields in tree view
|
||||
according to data in the record.
|
||||
|
||||
It provides attributes on fields with the similar syntax as the ``colors`` attribute
|
||||
It provides attributes on fields with a similar syntax as the ``colors`` attribute
|
||||
in tree tags.
|
||||
|
||||
Further, it provides a ``color_field`` attribute on tree tags's ``colors`` to use
|
||||
Further, it provides a ``color_field`` attribute on tree tags's ``options`` to use
|
||||
a field's value as color.
|
||||
|
||||
Features
|
||||
|
@ -12,4 +12,4 @@ Features
|
|||
|
||||
* Add attribute ``bg_color`` on field's ``options`` to color background of a cell in tree view
|
||||
* Add attribute ``fg_color`` on field's ``options`` to change text color of a cell in tree view
|
||||
* Add attribute ``color_field`` on the tree element's ``colors`` to use as color
|
||||
* Add attribute ``color_field`` on the tree element's ``options`` to use as color
|
||||
|
|
|
@ -26,11 +26,11 @@
|
|||
|
||||
With this example, column which renders 'name' field will have its text colored in white on a customer records.
|
||||
|
||||
* In the tree view declaration, use ``options='"color_field": "my_color"'`` attribute in the ``tree`` tag::
|
||||
* In the tree view declaration, use ``options='{"color_field": "my_color"}'`` attribute in the ``tree`` tag::
|
||||
|
||||
...
|
||||
<field name="arch" type="xml">
|
||||
<tree string="View name" colors="color_field: my_color" >
|
||||
<tree string="View name" options='{"color_field": "my_color"}' >
|
||||
...
|
||||
<field name="my_color" invisible="1"/>
|
||||
...
|
||||
|
|
|
@ -11,11 +11,14 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
|
|||
* @override
|
||||
*/
|
||||
_renderBody: function () {
|
||||
if (this.arch.attrs.colors) {
|
||||
var colorAttr = this.arch.attrs.colors.split(';');
|
||||
if (colorAttr.length > 0) {
|
||||
var colorField = colorAttr[0].split(':')[1].trim();
|
||||
// validate the presence of that field in tree view
|
||||
if (this.arch.attrs.options) {
|
||||
var archOptions = this.arch.attrs.options;
|
||||
if (!_.isObject(archOptions)) {
|
||||
archOptions = pyUtils.py_eval(archOptions);
|
||||
}
|
||||
var colorField = archOptions.color_field;
|
||||
if (colorField) {
|
||||
// Validate the presence of that field in tree view
|
||||
if (this.state.data.length && colorField in this.state.data[0].data) {
|
||||
this.colorField = colorField;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue