[IMP] web_tree_dynamic_colored_field : Add bg_color_field option

pull/1950/head
Sylvain LE GAL 2021-06-09 16:36:55 +02:00
parent 9091b0781e
commit 7b005c4b6e
4 changed files with 16 additions and 3 deletions

View File

@ -6,7 +6,7 @@
'category': 'Hidden/Dependency', 'category': 'Hidden/Dependency',
'version': '12.0.1.0.0', 'version': '12.0.1.0.0',
'depends': ['web'], 'depends': ['web'],
'author': "Camptocamp, Therp BV, Odoo Community Association (OCA)", 'author': "Camptocamp, Therp BV, GRAP, Odoo Community Association (OCA)",
'license': 'AGPL-3', 'license': 'AGPL-3',
'website': 'https://github.com/OCA/web', 'website': 'https://github.com/OCA/web',
'demo': [ 'demo': [

View File

@ -2,3 +2,4 @@
* 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> * Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Sylvain LE GAL <https://twitter.com/legalsylvain>

View File

@ -38,6 +38,9 @@
</field> </field>
... ...
* You can also use ``colors="bg_color_field: my_color"`` to defined the field name that will be used
for the background color of the line.
* 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::

View File

@ -6,7 +6,7 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
ListRenderer.include({ ListRenderer.include({
/** /**
* Look up for a `color_field` parameter in tree `colors` attribute * Look up for a `color_field` or ``bg_color_field`` parameter in tree `colors` attribute
* *
* @override * @override
*/ */
@ -14,10 +14,15 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
if (this.arch.attrs.colors) { if (this.arch.attrs.colors) {
var colorAttr = this.arch.attrs.colors.split(';'); var colorAttr = this.arch.attrs.colors.split(';');
if (colorAttr.length > 0) { if (colorAttr.length > 0) {
var colorType = colorAttr[0].split(':')[0].trim()
var colorField = colorAttr[0].split(':')[1].trim(); 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
if (this.state.data.length && colorField in this.state.data[0].data) { if (this.state.data.length && colorField in this.state.data[0].data) {
if (colorType === "color_field") {
this.colorField = colorField; this.colorField = colorField;
} else if (colorType === "bg_color_field") {
this.bgColorField = colorField;
}
} else { } else {
console.warn( console.warn(
"No field named '" + colorField + "' present in view." "No field named '" + colorField + "' present in view."
@ -51,6 +56,10 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
if (treeColor) { if (treeColor) {
$td.css('color', treeColor); $td.css('color', treeColor);
} }
var treeBgColor = record.data[this.bgColorField];
if (treeBgColor) {
$td.css('background-color', treeBgColor);
}
// apply <field>'s own `options` // 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; }