forked from Techsystech/web
[IMP] web_tree_dynamic_colored_field : Add bg_color_field option
parent
0afaa35fca
commit
110d8cd081
|
@ -3,3 +3,4 @@
|
||||||
* Artem Kostyuk <a.kostyuk@mobilunity.com>
|
* Artem Kostyuk <a.kostyuk@mobilunity.com>
|
||||||
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
||||||
* Phuc Tran Thanh <phuc@trobz.com>
|
* Phuc Tran Thanh <phuc@trobz.com>
|
||||||
|
* Sylvain LE GAL <https://twitter.com/legalsylvain>
|
||||||
|
|
|
@ -26,6 +26,21 @@
|
||||||
|
|
||||||
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" colors="color_field: my_color" >
|
||||||
|
...
|
||||||
|
<field name="my_color" invisible="1"/>
|
||||||
|
...
|
||||||
|
</tree>
|
||||||
|
</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::
|
||||||
|
|
|
@ -6,6 +6,33 @@ odoo.define("web_tree_dynamic_colored_field", function (require) {
|
||||||
var py = window.py;
|
var py = window.py;
|
||||||
|
|
||||||
ListRenderer.include({
|
ListRenderer.include({
|
||||||
|
/**
|
||||||
|
* Look up for a `color_field` or ``bg_color_field`` parameter in tree `colors` attribute
|
||||||
|
*
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
|
_renderBody: function () {
|
||||||
|
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."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this._super();
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Colorize a cell during it's render
|
* Colorize a cell during it's render
|
||||||
*
|
*
|
||||||
|
@ -33,6 +60,13 @@ odoo.define("web_tree_dynamic_colored_field", function (require) {
|
||||||
if (node.tag !== "field") {
|
if (node.tag !== "field") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
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; }
|
||||||
var nodeOptions = node.attrs.options;
|
var nodeOptions = node.attrs.options;
|
||||||
if (!_.isObject(nodeOptions)) {
|
if (!_.isObject(nodeOptions)) {
|
||||||
nodeOptions = pyUtils.py_eval(nodeOptions);
|
nodeOptions = pyUtils.py_eval(nodeOptions);
|
||||||
|
|
Loading…
Reference in New Issue