mirror of https://github.com/OCA/web.git
commit
897f924d4e
|
@ -11,6 +11,7 @@
|
||||||
'website': 'https://github.com/OCA/web',
|
'website': 'https://github.com/OCA/web',
|
||||||
'demo': [
|
'demo': [
|
||||||
"demo/res_users.xml",
|
"demo/res_users.xml",
|
||||||
|
"demo/ir_translation.xml",
|
||||||
],
|
],
|
||||||
'data': [
|
'data': [
|
||||||
'views/web_tree_dynamic_colored_field.xml',
|
'views/web_tree_dynamic_colored_field.xml',
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="view_translation_tree_view">
|
||||||
|
<field name="name">ir.translation.tree#demo@web_tree_dynamic_colored_field</field>
|
||||||
|
<field name="model">ir.translation</field>
|
||||||
|
<field name="inherit_id" ref="base.view_translation_tree"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree position="attributes">
|
||||||
|
<attribute name="colors">color_field: value; bgcolor_field: source</attribute>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- Create fake translation for demoing -->
|
||||||
|
<record id="colored_sample_1" model="ir.translation">
|
||||||
|
<field name="name">Light Green</field>
|
||||||
|
<field name="source">#90ffb1</field>
|
||||||
|
<field name="value">yellow</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- Create fake translation for demoing -->
|
||||||
|
<record id="colored_sample_2" model="ir.translation">
|
||||||
|
<field name="name">Light Red</field>
|
||||||
|
<field name="source">#ffb0ba</field>
|
||||||
|
<field name="value">blue</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
|
@ -12,4 +12,5 @@ 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 ``colors`` to use as color
|
* Add attribute ``color_field`` on the tree element's ``colors`` to use as text color
|
||||||
|
* Add attribute ``bg_color_field`` on the tree element's ``colors`` to use as background color
|
||||||
|
|
|
@ -30,9 +30,10 @@
|
||||||
|
|
||||||
...
|
...
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="View name" colors="color_field: my_color" >
|
<tree string="View name" colors="color_field: my_color; bg_color_field: my_background_color" >
|
||||||
...
|
...
|
||||||
<field name="my_color" invisible="1"/>
|
<field name="my_color" invisible="1"/>
|
||||||
|
<field name="my_background_color" invisible="1"/>
|
||||||
...
|
...
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
|
|
|
@ -13,9 +13,11 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
|
||||||
_renderBody: function () {
|
_renderBody: function () {
|
||||||
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) {
|
for (var i=0, len=colorAttr.length; i<len; i++) {
|
||||||
var colorType = colorAttr[0].split(':')[0].trim()
|
var attr = colorAttr[i].split(':')
|
||||||
var colorField = colorAttr[0].split(':')[1].trim();
|
if (attr.length == 2) {
|
||||||
|
var colorType = attr[0].trim()
|
||||||
|
var colorField = attr[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") {
|
if (colorType === "color_field") {
|
||||||
|
@ -28,6 +30,9 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
|
||||||
"No field named '" + colorField + "' present in view."
|
"No field named '" + colorField + "' present in view."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.warn("Invalid colors attribute:", attr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this._super();
|
return this._super();
|
||||||
|
|
Loading…
Reference in New Issue