From 92bbe2e88312ebd5b4b08103104d4059cc6b7d77 Mon Sep 17 00:00:00 2001 From: Javi Melendez Date: Mon, 25 Apr 2016 13:12:58 +0200 Subject: [PATCH 1/2] [IMP] ribbon color customization (#347) * [IMP] web_environment_ribbon: add color customization The ribbon color and background-color can be modified through system parameters: * ribbon.color * ribbon.background.color Added Copyright in .js Delete duplicate entries in css --- web_environment_ribbon/README.rst | 25 +++++-------- web_environment_ribbon/__openerp__.py | 2 +- web_environment_ribbon/data/ribbon_data.xml | 12 ++++++ .../static/src/css/ribbon.css | 4 +- .../static/src/js/ribbon.js | 37 ++++++++++++++++++- 5 files changed, 59 insertions(+), 21 deletions(-) diff --git a/web_environment_ribbon/README.rst b/web_environment_ribbon/README.rst index a3ecc310..d9ffbd16 100644 --- a/web_environment_ribbon/README.rst +++ b/web_environment_ribbon/README.rst @@ -12,16 +12,17 @@ Mark a Test Environment with a red ribbon on the top left corner in every page Installation ============ - * No special setup +No special setup Configuration ============= - * You can change the ribbon's name ("TEST") by editing - the default system parameter "ribbon.name" - (in the menu Settings > Parameters > System Parameters) - To hide the ribbon, set this parameter to "False" or - delete it. +* You can change the ribbon's name ("TEST") by editing the default system + parameter "ribbon.name" (in the menu Settings > Parameters > System + Parameters) To hide the ribbon, set this parameter to "False" or delete it. +* You can customize the ribbon color and background color through system + parameters: "ribbon.color", "ribbon.background.color". Fill with valid CSS + colors or just set to "False" to use default values. Usage ===== @@ -29,22 +30,15 @@ Usage To use this module, you need only to install it. After installation, a red ribbon will be visible on top left corner of every Odoo backend page - -Known issues / Roadmap -====================== - -* Allow to define in some place (system parameter, configuration file...) the - ribbon color. - 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 +If you spotted it first, help us smashing it by providing a detailed and +welcomed feedback `here `_. - Credits ======= @@ -52,6 +46,7 @@ Contributors ------------ * Francesco Apruzzese +* Javi Melendez Maintainer ---------- diff --git a/web_environment_ribbon/__openerp__.py b/web_environment_ribbon/__openerp__.py index 067d3068..5e3753bf 100644 --- a/web_environment_ribbon/__openerp__.py +++ b/web_environment_ribbon/__openerp__.py @@ -21,7 +21,7 @@ { 'name': "Web Environment Ribbon", - 'version': '8.0.0.1.0', + 'version': '8.0.1.0.0', 'category': 'Web', 'author': 'Francesco OpenCode Apruzzese,Odoo Community Association (OCA)', 'website': 'https://it.linkedin.com/in/francescoapruzzese', diff --git a/web_environment_ribbon/data/ribbon_data.xml b/web_environment_ribbon/data/ribbon_data.xml index 9ce2b3e6..e3eb9c46 100644 --- a/web_environment_ribbon/data/ribbon_data.xml +++ b/web_environment_ribbon/data/ribbon_data.xml @@ -8,5 +8,17 @@ TEST + + + ribbon.color + #f0f0f0 + + + + + ribbon.background.color + rgba(255,0,0,.6) + + diff --git a/web_environment_ribbon/static/src/css/ribbon.css b/web_environment_ribbon/static/src/css/ribbon.css index 627bd851..d5d5e8d9 100644 --- a/web_environment_ribbon/static/src/css/ribbon.css +++ b/web_environment_ribbon/static/src/css/ribbon.css @@ -1,7 +1,5 @@ .test-ribbon{ width: 200px; - background: #e43; - position: absolute; top: 50px; left: -50px; text-align: center; @@ -16,7 +14,7 @@ z-index: 1000; position: fixed; box-shadow: 0 0 3px rgba(0,0,0,.3); - background: rgba(255, 0, 0, .6);; + background: rgba(255,0,0,.6); } .test-ribbon b { diff --git a/web_environment_ribbon/static/src/js/ribbon.js b/web_environment_ribbon/static/src/js/ribbon.js index 48848fc8..6a7f0bc8 100644 --- a/web_environment_ribbon/static/src/js/ribbon.js +++ b/web_environment_ribbon/static/src/js/ribbon.js @@ -2,6 +2,9 @@ Copyright (C) 2015 Akretion (http://www.akretion.com) @author Sylvain Calador + Copyright (C) 2016 Algi Open Source Solutions (http://www.algios.com) + @author Javi Melendez + 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 @@ -22,9 +25,8 @@ openerp.web_environment_ribbon = function(instance) { ribbon.hide(); var model = new instance.web.Model('ir.config_parameter'); - var key = 'ribbon.name'; - var res = model.call('get_param', [key]).then( + var res = model.call('get_param', ['ribbon.name']).then( function (name) { if (name && name != 'False') { ribbon.html(name); @@ -32,4 +34,35 @@ openerp.web_environment_ribbon = function(instance) { } } ); + + // Get ribbon color from system parameters + var res = model.call('get_param', ['ribbon.color']).then( + function (strColor) { + if (strColor && validStrColour(strColor)) { + ribbon.css('color', strColor); + } + } + ); + + // Get ribbon background color from system parameters + var res = model.call('get_param', ['ribbon.background.color']).then( + function (strBackgroundColor) { + if (strBackgroundColor && validStrColour(strBackgroundColor)) { + ribbon.css('background-color', strBackgroundColor); + } + } + ); + // Code from: http://jsfiddle.net/WK_of_Angmar/xgA5C/ + function validStrColour(strToTest) { + if (strToTest === "") { return false; } + if (strToTest === "inherit") { return true; } + if (strToTest === "transparent") { return true; } + var image = document.createElement("img"); + image.style.color = "rgb(0, 0, 0)"; + image.style.color = strToTest; + if (image.style.color !== "rgb(0, 0, 0)") { return true; } + image.style.color = "rgb(255, 255, 255)"; + image.style.color = strToTest; + return image.style.color !== "rgb(255, 255, 255)"; + } } From 0ac9dc818e4a3e580864dcb7b3b9d4cb91ba89e2 Mon Sep 17 00:00:00 2001 From: Antonio Espinosa Date: Wed, 20 Jul 2016 14:50:34 +0200 Subject: [PATCH 2/2] [MIG] web_environment_ribbon --- web_environment_ribbon/README.rst | 20 +-- web_environment_ribbon/__init__.py | 22 +--- web_environment_ribbon/__openerp__.py | 30 ++--- web_environment_ribbon/data/ribbon_data.xml | 38 +++--- .../static/src/css/ribbon.css | 3 + .../static/src/js/ribbon.js | 119 +++++++++--------- web_environment_ribbon/view/base_view.xml | 39 +++--- 7 files changed, 124 insertions(+), 147 deletions(-) diff --git a/web_environment_ribbon/README.rst b/web_environment_ribbon/README.rst index d9ffbd16..c5f17c01 100644 --- a/web_environment_ribbon/README.rst +++ b/web_environment_ribbon/README.rst @@ -1,6 +1,8 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :alt: License: AGPL-3 + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +====================== Web Environment Ribbon ====================== @@ -30,14 +32,17 @@ Usage To use this module, you need only to install it. After installation, a red ribbon will be visible on top left corner of every Odoo backend page +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/162/9.0 + 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 ======= @@ -47,6 +52,7 @@ Contributors * Francesco Apruzzese * Javi Melendez +* Antonio Espinosa Maintainer ---------- @@ -61,4 +67,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_environment_ribbon/__init__.py b/web_environment_ribbon/__init__.py index 5d2935f8..467b4cbe 100644 --- a/web_environment_ribbon/__init__.py +++ b/web_environment_ribbon/__init__.py @@ -1,20 +1,4 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (C) 2015 Francesco OpenCode Apruzzese () -# All Rights Reserved -# -# 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 . -# -############################################################################## +# Copyright 2015 Francesco OpenCode Apruzzese +# Copyright 2016 Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/web_environment_ribbon/__openerp__.py b/web_environment_ribbon/__openerp__.py index 5e3753bf..fb2dfb8a 100644 --- a/web_environment_ribbon/__openerp__.py +++ b/web_environment_ribbon/__openerp__.py @@ -1,29 +1,15 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (C) 2015 Francesco OpenCode Apruzzese () -# All Rights Reserved -# -# 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 . -# -############################################################################## +# Copyright 2015 Francesco OpenCode Apruzzese +# Copyright 2016 Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': "Web Environment Ribbon", - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'category': 'Web', - 'author': 'Francesco OpenCode Apruzzese,Odoo Community Association (OCA)', + 'author': 'Francesco OpenCode Apruzzese, ' + 'Tecnativa, ' + 'Odoo Community Association (OCA)', 'website': 'https://it.linkedin.com/in/francescoapruzzese', 'license': 'AGPL-3', "depends": [ @@ -36,5 +22,5 @@ "update_xml": [], "demo_xml": [], "auto_install": False, - 'installable': False + "installable": True } diff --git a/web_environment_ribbon/data/ribbon_data.xml b/web_environment_ribbon/data/ribbon_data.xml index e3eb9c46..4c18ddd7 100644 --- a/web_environment_ribbon/data/ribbon_data.xml +++ b/web_environment_ribbon/data/ribbon_data.xml @@ -1,24 +1,24 @@ - - + + - - - ribbon.name - TEST - + + + ribbon.name + TEST + - - - ribbon.color - #f0f0f0 - + + + ribbon.color + #f0f0f0 + - - - ribbon.background.color - rgba(255,0,0,.6) - + + + ribbon.background.color + rgba(255,0,0,.6) + - - + diff --git a/web_environment_ribbon/static/src/css/ribbon.css b/web_environment_ribbon/static/src/css/ribbon.css index d5d5e8d9..375ffee8 100644 --- a/web_environment_ribbon/static/src/css/ribbon.css +++ b/web_environment_ribbon/static/src/css/ribbon.css @@ -1,3 +1,6 @@ +/* Copyright 2015 Francesco OpenCode Apruzzese + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + .test-ribbon{ width: 200px; top: 50px; diff --git a/web_environment_ribbon/static/src/js/ribbon.js b/web_environment_ribbon/static/src/js/ribbon.js index 6a7f0bc8..68dbee33 100644 --- a/web_environment_ribbon/static/src/js/ribbon.js +++ b/web_environment_ribbon/static/src/js/ribbon.js @@ -1,68 +1,61 @@ -/****************************************************************************** - Copyright (C) 2015 Akretion (http://www.akretion.com) - @author Sylvain Calador - - Copyright (C) 2016 Algi Open Source Solutions (http://www.algios.com) - @author Javi Melendez - - 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 . -******************************************************************************/ - -openerp.web_environment_ribbon = function(instance) { - - var ribbon = $(document).find('.test-ribbon'); - ribbon.hide(); - - var model = new instance.web.Model('ir.config_parameter'); +/* Copyright 2015 Sylvain Calador + Copyright 2015 Javi Melendez + Copyright 2016 Antonio Espinosa + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +odoo.define('web_environment_ribbon.ribbon', function(require) { +"use strict"; + +var $ = require('$'); +var Model = require('web.Model'); +var core = require('web.core'); + +var model = new Model('ir.config_parameter'); + +// Code from: http://jsfiddle.net/WK_of_Angmar/xgA5C/ +function validStrColour(strToTest) { + if (strToTest === "") { return false; } + if (strToTest === "inherit") { return true; } + if (strToTest === "transparent") { return true; } + var image = document.createElement("img"); + image.style.color = "rgb(0, 0, 0)"; + image.style.color = strToTest; + if (image.style.color !== "rgb(0, 0, 0)") { return true; } + image.style.color = "rgb(255, 255, 255)"; + image.style.color = strToTest; + return image.style.color !== "rgb(255, 255, 255)"; +} - var res = model.call('get_param', ['ribbon.name']).then( - function (name) { - if (name && name != 'False') { - ribbon.html(name); - ribbon.show(); +core.bus.on('web_client_ready', null, function () { + var ribbon = $('.test-ribbon'); + // If ribbon is found in DOM + if (ribbon.length) { + ribbon.hide(); + model.call('get_param', ['ribbon.name']).then( + function (name) { + if (name && name != 'False') { + ribbon.html(name); + ribbon.show(); + } } - } - ); - - // Get ribbon color from system parameters - var res = model.call('get_param', ['ribbon.color']).then( - function (strColor) { - if (strColor && validStrColour(strColor)) { - ribbon.css('color', strColor); + ); + // Get ribbon color from system parameters + model.call('get_param', ['ribbon.color']).then( + function (strColor) { + if (strColor && validStrColour(strColor)) { + ribbon.css('color', strColor); + } } - } - ); - - // Get ribbon background color from system parameters - var res = model.call('get_param', ['ribbon.background.color']).then( - function (strBackgroundColor) { - if (strBackgroundColor && validStrColour(strBackgroundColor)) { - ribbon.css('background-color', strBackgroundColor); + ); + // Get ribbon background color from system parameters + model.call('get_param', ['ribbon.background.color']).then( + function (strBackgroundColor) { + if (strBackgroundColor && validStrColour(strBackgroundColor)) { + ribbon.css('background-color', strBackgroundColor); + } } - } - ); - // Code from: http://jsfiddle.net/WK_of_Angmar/xgA5C/ - function validStrColour(strToTest) { - if (strToTest === "") { return false; } - if (strToTest === "inherit") { return true; } - if (strToTest === "transparent") { return true; } - var image = document.createElement("img"); - image.style.color = "rgb(0, 0, 0)"; - image.style.color = strToTest; - if (image.style.color !== "rgb(0, 0, 0)") { return true; } - image.style.color = "rgb(255, 255, 255)"; - image.style.color = strToTest; - return image.style.color !== "rgb(255, 255, 255)"; + ); } -} +}); + +}); // odoo.define diff --git a/web_environment_ribbon/view/base_view.xml b/web_environment_ribbon/view/base_view.xml index 6d9efc9c..464a71dd 100644 --- a/web_environment_ribbon/view/base_view.xml +++ b/web_environment_ribbon/view/base_view.xml @@ -1,21 +1,26 @@ - - + + - -