Browse Source

[ADD] web_tree_dynamic_colored_field v9

pull/473/head
Holger Brunn 8 years ago
parent
commit
02a16e07e5
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 17
      web_tree_dynamic_colored_field/README.rst
  2. 21
      web_tree_dynamic_colored_field/__init__.py
  3. 29
      web_tree_dynamic_colored_field/__openerp__.py
  4. 52
      web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js

17
web_tree_dynamic_colored_field/README.rst

@ -65,18 +65,17 @@ Usage
With this example, the content of the field named `color` will be used to
populate the `color` CSS value. Use a function field to return whichever
color you want depending on the other record values. Note this this
color you want depending on the other record values. Note that this
overrides the `colors` attribute, and that you need the tree to load your
field in the first place by adding it as invisible field.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <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, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/web/issues/new?body=module:%20web_widget_color_tree_field%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Bugs are tracked on `GitHub Issues
<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,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
@ -90,9 +89,9 @@ Contributors
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
:target: https://odoo-community.org
This module is maintained by the OCA.
@ -100,4 +99,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.
To contribute to this module, please visit https://odoo-community.org.

21
web_tree_dynamic_colored_field/__init__.py

@ -1,20 +1,3 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Damien Crier
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# © 2015 Camptocamp SA, Damien Crier
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

29
web_tree_dynamic_colored_field/__openerp__.py

@ -1,32 +1,15 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Damien Crier
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# © 2015 Camptocamp SA, Damien Crier
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Colorize field in tree views',
'summary': 'Allows you to dynamically color fields on tree views',
'category': 'Hidden',
'version': '8.0.2.0.0',
'category': 'Hidden/Dependency',
'version': '9.0.2.0.0',
'depends': ['web'],
'author': "Camptocamp,Odoo Community Association (OCA)",
'author': "Camptocamp,Therp BV,Odoo Community Association (OCA)",
'license': 'AGPL-3',
'website': 'http://www.camptocamp.com',
'website': 'https://github.com/OCA/web',
'data': [
'views/web_tree_dynamic_colored_field.xml',
],

52
web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js

@ -1,10 +1,16 @@
openerp.web_tree_dynamic_colored_field = function(instance){
odoo.define('web_tree_dynamic_colored_field', function(require)
{
'use strict';
var ListView = require('web.ListView'),
pyeval = require('web.pyeval'),
py = window.py;
var pair_colors = function(pair_color){
if (pair_color != ""){
if (pair_color !== ""){
var pair_list = pair_color.split(':'),
color = pair_list[0],
expression = pair_list[1];
return [color, py.parse(py.tokenize(expression)), expression]
return [color, py.parse(py.tokenize(expression)), expression];
}
};
@ -12,7 +18,7 @@ openerp.web_tree_dynamic_colored_field = function(instance){
return _.extend(
{},
record.attributes,
instance.web.pyeval.context()
pyeval.context()
);
};
@ -22,21 +28,21 @@ openerp.web_tree_dynamic_colored_field = function(instance){
var colors = _(column[field_attribute].split(';'))
.chain()
.map(pair_colors)
.value();
var colors = colors.filter(function CheckUndefined(value, index, ar) {
return value != undefined;
})
.value()
.filter(function CheckUndefined(value, index, ar) {
return value !== undefined;
});
var ctx = get_eval_context(record);
for(i=0, len=colors.length; i<len; ++i) {
pair = colors[i];
var color = pair[0];
var expression = pair[1];
for(var i=0, len=colors.length; i<len; ++i) {
var pair = colors[i],
color = pair[0],
expression = pair[1];
if (py.evaluate(expression, ctx).toJSON()) {
result = css_attribute + ': ' + color + ';';
}
}
}
return result
return result;
};
var colorize = function(record, column){
@ -46,14 +52,28 @@ openerp.web_tree_dynamic_colored_field = function(instance){
return res;
};
instance.web.ListView.List.include({
ListView.List.include({
init: function(group, opts){
this._super(group, opts);
this.columns.fct_colorize = colorize;
},
});
instance.web.ListView.include({
ListView.include({
load_view: function()
{
var self = this;
return this._super.apply(this, arguments)
.then(function()
{
// the style_for helper is only called if one of colors or
// fonts is not null
if(self.fields_view.arch.attrs.color_field)
{
self.colors = [];
}
});
},
style_for: function (record)
{
var result = this._super.apply(this, arguments);
@ -72,4 +92,4 @@ openerp.web_tree_dynamic_colored_field = function(instance){
return result;
},
});
}
});
Loading…
Cancel
Save