@@ -28,16 +28,42 @@ Colorize field in tree views
2828
2929|badge1 | |badge2 | |badge3 | |badge4 | |badge5 |
3030
31- This module aims to add support for dynamically coloring fields in tree
31+ This module aims to add support for dynamically coloring fields in list
3232view according to data in the record.
3333
3434Features
3535--------
3636
3737- Add attribute ``bg_color `` on field's ``options `` to color background
38- of a cell in tree view
38+ of a cell in list view
3939- Add attribute ``fg_color `` on field's ``options `` to change text color
40- of a cell in tree view
40+ of a cell in list view
41+ - Add attribute ``bg_color_field `` on list's ``colors `` to change
42+ background color of the entire row in list view (\* )
43+ - Add attribute ``fg_color_field `` on list's ``colors `` to change text
44+ color of the entire row in list view (\* )
45+
46+ (\* ) This functionality only works for a list defined in a form. (Since
47+ 13.0, the ``colors `` attribute is no longer in the RelaxNG schema of the
48+ list view, so we can't use it like before, but it looks like the RNG is
49+ not checked for embedded list.)
50+
51+ Testing
52+ -------
53+
54+ Some views are overriden for demoing this module functionnalities:
55+
56+ 1. On the Users list view: The ``name `` and ``login_date `` fields are
57+ colored according to conditions written in view definition.
58+ 2. On the Groups form view > "Access Rights": By renaming the rule name
59+ to a color (red, blue, yellow, #00FDF0), the entire row background
60+ color is immediatly updated.
61+ 3. On the System Parameters list view:
62+
63+ - For the ``key `` field: Its content is the text color, the ``value ``
64+ field is its background color.
65+ - For the ``value `` field: Its content is the text color, the
66+ ``value `` field is its background color.
4167
4268**Table of contents **
4369
@@ -47,92 +73,113 @@ Features
4773Usage
4874=====
4975
50- - In the tree view declaration, put
76+ Using view conditions
77+ =====================
78+
79+ - In the list view declaration, put
5180 ``options='{"bg_color": "red: customer==True"} `` attribute in the
5281 ``field `` tag:
5382
54- ::
83+ .. code :: xml
5584
5685 ...
5786 <field name =" arch" type =" xml" >
58- <tree string="View name">
87+ <list string =" View name" >
5988 ...
6089 <field name =" name" options =' {"bg_color": "red: customer == True"}' />
6190 ...
62- </tree >
91+ </list >
6392 </field >
6493 ...
6594
66- With this example, column which renders 'name' field will have its **background** colored in red on customer records.
95+ With this example, column which renders 'name' field will have its
96+ **background ** colored in red on customer records.
6797
68- - In the tree view declaration, put
98+ - In the list view declaration, put
6999 ``options='{"fg_color": "white:customer == True"}' `` attribute in the
70100 ``field `` tag:
71101
72- ::
102+ .. code :: xml
73103
74104 ...
75105 <field name =" arch" type =" xml" >
76- <tree string="View name">
106+ <list string =" View name" >
77107 ...
78108 <field name =" name" options =' {"fg_color": "white:customer == True"}' />
79109 ...
80- </tree >
110+ </list >
81111 </field >
82112 ...
83113
84- With this example, column which renders 'name' field will have its **text** colored in white on customer records.
114+ With this example, column which renders 'name' field will have its
115+ **text ** colored in white on customer records.
85116
86117- If you want to use more than one color, you can split the attributes
87118 using ';':
88119
89- ::
90-
91- options='{"fg_color": "red:red_color == True; green:green_color == True"}'
120+ ::
92121
93- Example:
122+ options='{"fg_color": "red:red_color == True; green:green_color == True"}'
94123
95- .. code :: xml
124+ .. code :: xml
96125
97- ...
98- <field name =" arch" type =" xml" >
99- < tree string =" View name" >
100- ...
101- <field name =" name" options =' {"fg_color": "red:red_color == True; green:green_color == True"}' />
102- ...
103- </ tree >
104- </field >
105- ...
126+ ...
127+ <field name =" arch" type =" xml" >
128+ < list string =" View name" >
129+ ...
130+ <field name =" name" options =' {"fg_color": "red:red_color == True; green:green_color == True"}' />
131+ ...
132+ </ list >
133+ </field >
134+ ...
106135
107- - Can use strings too... In the tree view declaration, put
136+ - Can use strings too... In the list view declaration, put
108137 ``options="{'fg_color': 'green:customer_state == \'success\''}" ``
109138 attribute in the ``field `` tag:
110139
111- ::
140+ .. code :: xml
112141
113142 ...
114143 <field name =" arch" type =" xml" >
115- <tree string="View name">
144+ <list string =" View name" >
116145 ...
117146 <field name =" name" options =" {'fg_color': 'green:customer_state == \'success\''}" />
118147 ...
119- </tree >
148+ </list >
120149 </field >
121150 ...
122151
123152 **Note that you can use single or normal quotes. If the declaration of
124153the options doesn't follow the JSON format, the options string will be
125154evaluated using py.eval() **
126155
156+ Using view fields
157+ =================
158+
159+ - In the list view declaration, put
160+ ``options='{"bg_color": "my_color"} `` attribute in the ``field `` tag:
161+
162+ .. code :: xml
163+
164+ ...
165+ <field name =" arch" type =" xml" >
166+ <list string =" View name" >
167+ ...
168+ <field name =" my_color" column_invisible =" 1" />
169+ <field name =" name" options =' {"bg_color": "my_color"}' />
170+ ...
171+ </list >
172+ </field >
173+ ...
174+
175+ With this example, the content of the field named ``my_color `` will be
176+ used to populate the ``background-color `` CSS value. Use a compute
177+ field to return whichever color you want depending on the other record
178+ values.
179+
127180Known issues / Roadmap
128181======================
129182
130- - Before version 13.0, this module had a feature allowing to change the
131- color of a line depending on a field, using a ``colors `` attribute
132- with the name of the field on the ``<tree> `` element. Since 13.0, the
133- ``colors `` attribute is no longer in the RelaxNG schema of the tree
134- view, so we can't use it anymore. This feature has then been dropped,
135- but could be reimplement in another way.
136183- Since version 17.0 coloring is written into ``style `` attribute of
137184 (td) element
138185
@@ -165,6 +212,7 @@ Contributors
165212- Phuc Tran Thanh <
[email protected] >
166213- Sylvain LE GAL <https://twitter.com/legalsylvain>
167214- Jurgis Pralgauskis <
[email protected] >
215+ - Yann Papouin <
[email protected] >
168216
169217Other credits
170218-------------
0 commit comments