From 02a16e07e503bfba022685842bdb1cdae4163150 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 8 Nov 2016 15:48:21 +0100 Subject: [PATCH] [ADD] web_tree_dynamic_colored_field v9 --- web_tree_dynamic_colored_field/README.rst | 17 +++--- web_tree_dynamic_colored_field/__init__.py | 21 +------- web_tree_dynamic_colored_field/__openerp__.py | 29 +++-------- .../src/js/web_tree_dynamic_colored_field.js | 52 +++++++++++++------ 4 files changed, 52 insertions(+), 67 deletions(-) diff --git a/web_tree_dynamic_colored_field/README.rst b/web_tree_dynamic_colored_field/README.rst index b1a0f354..ccc59f9b 100644 --- a/web_tree_dynamic_colored_field/README.rst +++ b/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 `_. -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 `_. - +Bugs are tracked on `GitHub 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. diff --git a/web_tree_dynamic_colored_field/__init__.py b/web_tree_dynamic_colored_field/__init__.py index c82f5352..ed8d9eff 100644 --- a/web_tree_dynamic_colored_field/__init__.py +++ b/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 . -# -############################################################################## +# © 2015 Camptocamp SA, Damien Crier +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/web_tree_dynamic_colored_field/__openerp__.py b/web_tree_dynamic_colored_field/__openerp__.py index 891f1c22..78dd78e0 100644 --- a/web_tree_dynamic_colored_field/__openerp__.py +++ b/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 . -# -############################################################################## +# © 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', ], diff --git a/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js b/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js index 36b4dac6..1d3a9273 100644 --- a/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js +++ b/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