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)"; + } }