mirror of https://github.com/OCA/web.git
web_tree_dynamic_colored_field: Migration to 12.0
parent
e559ae8b00
commit
c958606fb9
|
@ -1,5 +1,5 @@
|
||||||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg
|
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
|
||||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
:target: https://www.gnu.org/licenses/agpl
|
||||||
:alt: License: AGPL-3
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
============================
|
============================
|
||||||
|
@ -99,11 +99,16 @@ Bug Tracker
|
||||||
Bugs are tracked on `GitHub Issues
|
Bugs are tracked on `GitHub Issues
|
||||||
<https://github.com/OCA/web/issues>`_. In case of trouble, please
|
<https://github.com/OCA/web/issues>`_. In case of trouble, please
|
||||||
check there if your issue has already been reported. If you spotted it first,
|
check there if your issue has already been reported. If you spotted it first,
|
||||||
help us smash it by providing a detailed and welcomed feedback.
|
help us smash it by providing detailed and welcomed feedback.
|
||||||
|
|
||||||
Credits
|
Credits
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
Images
|
||||||
|
------
|
||||||
|
|
||||||
|
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
|
||||||
|
|
||||||
Contributors
|
Contributors
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
# Copyright 2015-2018 Camptocamp SA, Damien Crier
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
'name': 'Colorize field in tree views',
|
'name': 'Colorize field in tree views',
|
||||||
'summary': 'Allows you to dynamically color fields on tree views',
|
'summary': 'Allows you to dynamically color fields on tree views',
|
||||||
'category': 'Hidden/Dependency',
|
'category': 'Hidden/Dependency',
|
||||||
'version': '11.0.1.0.1',
|
'version': '12.0.1.0.0',
|
||||||
'depends': ['web'],
|
'depends': ['web'],
|
||||||
'author': "Camptocamp, Therp BV, Odoo Community Association (OCA)",
|
'author': "Camptocamp, Therp BV, Odoo Community Association (OCA)",
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
* Damien Crier <damien.crier@camptocamp.com>
|
||||||
|
* Holger Brunn <hbrunn@therp.nl>
|
||||||
|
* Artem Kostyuk <a.kostyuk@mobilunity.com>
|
||||||
|
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
|
@ -0,0 +1,15 @@
|
||||||
|
This module aims to add support for dynamically coloring fields in tree view
|
||||||
|
according to data in the record.
|
||||||
|
|
||||||
|
It provides attributes on fields with the similar syntax as the ``colors`` attribute
|
||||||
|
in tree tags.
|
||||||
|
|
||||||
|
Further, it provides a ``color_field`` attribute on tree tags's ``colors`` to use
|
||||||
|
a field's value as color.
|
||||||
|
|
||||||
|
Features
|
||||||
|
========
|
||||||
|
|
||||||
|
* 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 ``color_field`` on the tree element's ``colors`` to use as color
|
|
@ -0,0 +1,67 @@
|
||||||
|
* In the tree view declaration, put ``options='{"bg_color": "red: customer==True"}`` attribute in the ``field`` tag::
|
||||||
|
|
||||||
|
...
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="View name">
|
||||||
|
...
|
||||||
|
<field name="name" options='{"bg_color": "red: customer == True"}'/>
|
||||||
|
...
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
...
|
||||||
|
|
||||||
|
With this example, column which renders 'name' field will have its background colored in red.
|
||||||
|
|
||||||
|
* In the tree view declaration, put ``options='{"fg_color": "white:customer == True"}'`` attribute in the ``field`` tag::
|
||||||
|
|
||||||
|
...
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="View name">
|
||||||
|
...
|
||||||
|
<field name="name" options='{"fg_color": "white:customer == True"}'/>
|
||||||
|
...
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
...
|
||||||
|
|
||||||
|
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>
|
||||||
|
...
|
||||||
|
|
||||||
|
* If you want to use more than one color, you can split the attributes using ';':
|
||||||
|
|
||||||
|
.. code::
|
||||||
|
|
||||||
|
options='{"fg_color": "red:red_color == True; green:green_color == True"}'
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
.. code:: xml
|
||||||
|
|
||||||
|
...
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="View name">
|
||||||
|
...
|
||||||
|
<field name="name" options='{"fg_color": "red:red_color == True; green:green_color == True"}'/>
|
||||||
|
...
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
...
|
||||||
|
|
||||||
|
With this example, the content of the field named `my_color` will be used to
|
||||||
|
populate the `my_color` CSS value. Use a function field to return whichever
|
||||||
|
color you want depending on the other record values. Note that this
|
||||||
|
overrides the rest of `colors` attributes, and that you need the tree
|
||||||
|
to load your field in the first place by adding it as invisible field.
|
||||||
|
|
||||||
|
**Note that you should always use single quotes for fields' ``options`` and wrap nested values in double quotes since ``options`` is a JSON object.**
|
|
@ -13,7 +13,7 @@ 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(';')
|
||||||
.filter(color => color.trim().startsWith('color_field'));
|
.filter(color >= color.trim().startsWith('color_field'));
|
||||||
if (colorAttr.length > 0) {
|
if (colorAttr.length > 0) {
|
||||||
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
|
||||||
|
@ -90,7 +90,7 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse `<color>: <field> <operator> <value>` forms to
|
* Parse `<color>: <field> <operator> <value>` forms to
|
||||||
* evaluatable expressions
|
* evaluable expressions
|
||||||
*
|
*
|
||||||
* @param {string} pairColor `color: expression` pair
|
* @param {string} pairColor `color: expression` pair
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<odoo>
|
<odoo>
|
||||||
<template id="assets_backend" name="web_tree_dynamic_colored_field assets" inherit_id="web.assets_backend">
|
<template id="assets_backend" name="web_tree_dynamic_colored_field assets" inherit_id="web.assets_backend">
|
||||||
<xpath expr="." position="inside">
|
<xpath expr="." position="inside">
|
||||||
<script type="text/javascript" src="/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js"></script>
|
<script type="text/javascript" src="/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
Loading…
Reference in New Issue