[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',
'version': '12.0.1.0.0',
'depends': ['web'],
'author': "Camptocamp, Therp BV, Odoo Community Association (OCA)",
'author': "Camptocamp, Therp BV, GRAP, Odoo Community Association (OCA)",
'license': 'AGPL-3',
'website': 'https://github.com/OCA/web',
'demo': [

View File

@ -2,3 +2,4 @@
* Holger Brunn <hbrunn@therp.nl>
* Artem Kostyuk <a.kostyuk@mobilunity.com>
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Sylvain LE GAL <https://twitter.com/legalsylvain>

View File

@ -38,6 +38,9 @@
</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 ';':
.. code::

View File

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