mirror of https://github.com/OCA/web.git
Remove support of dynamic colors on <tree>
The 'colors' and 'options' fields are not supported by the RelaxNG schema of the <tree> element. Remove the support until we find a good solution for this.pull/2771/head
parent
b14ea17570
commit
a706cb2a2d
|
@ -4,9 +4,6 @@
|
||||||
<field name="model">res.users</field>
|
<field name="model">res.users</field>
|
||||||
<field name="inherit_id" ref="base.view_users_tree" />
|
<field name="inherit_id" ref="base.view_users_tree" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree position="attributes">
|
|
||||||
<attribute name="options">{"color_field": "lang"}</attribute>
|
|
||||||
</tree>
|
|
||||||
<field name="login_date" position="attributes">
|
<field name="login_date" position="attributes">
|
||||||
<attribute name="options">{
|
<attribute name="options">{
|
||||||
"bg_color": "#9e1635: login_date == False",
|
"bg_color": "#9e1635: login_date == False",
|
||||||
|
|
|
@ -1,15 +1,8 @@
|
||||||
This module aims to add support for dynamically coloring fields in tree view
|
This module aims to add support for dynamically coloring fields in tree view
|
||||||
according to data in the record.
|
according to data in the record.
|
||||||
|
|
||||||
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 ``options`` to use
|
|
||||||
a field's value as color.
|
|
||||||
|
|
||||||
Features
|
Features
|
||||||
========
|
========
|
||||||
|
|
||||||
* Add attribute ``bg_color`` on field's ``options`` to color background of a cell in tree view
|
* 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 ``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 ``options`` to use as color
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
* Before version 13.0, this module had a feature allowing to change the color of
|
||||||
|
a line depending on a field, using a ``colors`` attribute with the name of the
|
||||||
|
field on the ``<tree>`` element. Since 13.0, the ``colors`` attribute is no
|
||||||
|
longer in the RelaxNG schema of the tree view, so we can't use it anymore.
|
||||||
|
This feature has then been dropped, but could be reimplement in another way.
|
|
@ -26,18 +26,6 @@
|
||||||
|
|
||||||
With this example, column which renders 'name' field will have its text colored in white on a customer records.
|
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::
|
|
||||||
|
|
||||||
...
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<tree string="View name" options='{"color_field": "my_color"}' >
|
|
||||||
...
|
|
||||||
<field name="my_color" invisible="1"/>
|
|
||||||
...
|
|
||||||
</tree>
|
|
||||||
</field>
|
|
||||||
...
|
|
||||||
|
|
||||||
* If you want to use more than one color, you can split the attributes using ';':
|
* If you want to use more than one color, you can split the attributes using ';':
|
||||||
|
|
||||||
.. code::
|
.. code::
|
||||||
|
|
|
@ -5,31 +5,6 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
|
||||||
var pyUtils = require("web.py_utils");
|
var pyUtils = require("web.py_utils");
|
||||||
|
|
||||||
ListRenderer.include({
|
ListRenderer.include({
|
||||||
/**
|
|
||||||
* Look up for a `color_field` parameter in tree `colors` attribute
|
|
||||||
*
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
_renderBody: function () {
|
|
||||||
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 {
|
|
||||||
console.warn(
|
|
||||||
"No field named '" + colorField + "' present in view."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this._super();
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* Colorize a cell during it's render
|
* Colorize a cell during it's render
|
||||||
*
|
*
|
||||||
|
@ -49,12 +24,6 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
|
||||||
* @param {Object} node an XML node (must be a <field>)
|
* @param {Object} node an XML node (must be a <field>)
|
||||||
*/
|
*/
|
||||||
applyColorize: function ($td, record, node, ctx) {
|
applyColorize: function ($td, record, node, ctx) {
|
||||||
// safely resolve value of `color_field` given in <tree>
|
|
||||||
var treeColor = record.data[this.colorField];
|
|
||||||
if (treeColor) {
|
|
||||||
$td.css('color', treeColor);
|
|
||||||
}
|
|
||||||
// apply <field>'s own `options`
|
|
||||||
if (!node.attrs.options) { return; }
|
if (!node.attrs.options) { return; }
|
||||||
if (node.tag !== 'field') { return; }
|
if (node.tag !== 'field') { return; }
|
||||||
var nodeOptions = node.attrs.options;
|
var nodeOptions = node.attrs.options;
|
||||||
|
|
Loading…
Reference in New Issue