Browse Source

[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
pull/348/head
Javi Melendez 9 years ago
committed by Pedro M. Baeza
parent
commit
e91c7a73bf
  1. 25
      web_environment_ribbon/README.rst
  2. 2
      web_environment_ribbon/__openerp__.py
  3. 12
      web_environment_ribbon/data/ribbon_data.xml
  4. 4
      web_environment_ribbon/static/src/css/ribbon.css
  5. 37
      web_environment_ribbon/static/src/js/ribbon.js

25
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 <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
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_environment_ribbon%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
@ -52,6 +46,7 @@ Contributors
------------
* Francesco Apruzzese <cescoap@gmail.com>
* Javi Melendez <javimelex@gmail.com>
Maintainer
----------

2
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',

12
web_environment_ribbon/data/ribbon_data.xml

@ -8,5 +8,17 @@
<field name="value">TEST</field>
</record>
<!-- Add ribbon color configuration parameter -->
<record id="set_ribbon_color" model="ir.config_parameter">
<field name="key">ribbon.color</field>
<field name="value">#f0f0f0</field>
</record>
<!-- Add ribbon background color configuration parameter -->
<record id="set_ribbon_background_color" model="ir.config_parameter">
<field name="key">ribbon.background.color</field>
<field name="value">rgba(255,0,0,.6)</field>
</record>
</data>
</openerp>

4
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 {

37
web_environment_ribbon/static/src/js/ribbon.js

@ -2,6 +2,9 @@
Copyright (C) 2015 Akretion (http://www.akretion.com)
@author Sylvain Calador <sylvain.calador@akretion.com>
Copyright (C) 2016 Algi Open Source Solutions (http://www.algios.com)
@author Javi Melendez <javi.melendez@algios.com>
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)";
}
}
Loading…
Cancel
Save