Browse Source

[9.0] [IMP] Web Environment Ribbon: support variables in ribbon name (eg db_name) (#621)

* [ADD] .eggs in gitignore

* [IMP] Web Environment Ribbon: add backend
This commit adds a simple bakend to facilitate inheritance

* [IMP] Web Environment Ribbon: add the databse name
This commit adds the database name under the ribbon name, in the ribbon

* [IMP] Web Environment Ribbon: prepare method for ribbon name

* [IMP] README: explain how to use db_name
pull/661/head
Thomas Binsfeld (ACSONE) 8 years ago
committed by Stéphane Bidoul (ACSONE)
parent
commit
28d935d8c4
No known key found for this signature in database GPG Key ID: 866D394B4986F82D
  1. 1
      .gitignore
  2. 3
      web_environment_ribbon/README.rst
  3. 2
      web_environment_ribbon/__init__.py
  4. 2
      web_environment_ribbon/__manifest__.py
  5. 2
      web_environment_ribbon/data/ribbon_data.xml
  6. 1
      web_environment_ribbon/models/__init__.py
  7. 33
      web_environment_ribbon/models/web_environment_ribbon_backend.py
  8. 17
      web_environment_ribbon/security/web_environment_ribbon_backend.xml
  9. 8
      web_environment_ribbon/static/src/css/ribbon.css
  10. 33
      web_environment_ribbon/static/src/js/ribbon.js

1
.gitignore

@ -20,6 +20,7 @@ var/
*.egg-info/ *.egg-info/
.installed.cfg .installed.cfg
*.egg *.egg
*.eggs
# Installer logs # Installer logs
pip-log.txt pip-log.txt

3
web_environment_ribbon/README.rst

@ -25,6 +25,8 @@ Configuration
* You can customize the ribbon color and background color through system * You can customize the ribbon color and background color through system
parameters: "ribbon.color", "ribbon.background.color". Fill with valid CSS parameters: "ribbon.color", "ribbon.background.color". Fill with valid CSS
colors or just set to "False" to use default values. colors or just set to "False" to use default values.
* You can add the database name in the ribbon by adding "{db_name}" in the
system parameter "ribbon.name".
Usage Usage
===== =====
@ -53,6 +55,7 @@ Contributors
* Francesco Apruzzese <cescoap@gmail.com> * Francesco Apruzzese <cescoap@gmail.com>
* Javi Melendez <javimelex@gmail.com> * Javi Melendez <javimelex@gmail.com>
* Antonio Espinosa <antonio.espinosa@tecnativa.com> * Antonio Espinosa <antonio.espinosa@tecnativa.com>
* Thomas Binsfeld <thomas.binsfeld@acsone.eu>
Maintainer Maintainer
---------- ----------

2
web_environment_ribbon/__init__.py

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2015 Francesco OpenCode Apruzzese <cescoap@gmail.com> # Copyright 2015 Francesco OpenCode Apruzzese <cescoap@gmail.com>
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> # Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# Copyright 2017 Thomas Binsfeld <thomas.binsfeld@acsone.eu>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models

2
web_environment_ribbon/__manifest__.py

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2015 Francesco OpenCode Apruzzese <cescoap@gmail.com> # Copyright 2015 Francesco OpenCode Apruzzese <cescoap@gmail.com>
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> # Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# Copyright 2017 Thomas Binsfeld <thomas.binsfeld@acsone.eu>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
@ -16,6 +17,7 @@
'web', 'web',
], ],
"data": [ "data": [
'security/web_environment_ribbon_backend.xml',
'view/base_view.xml', 'view/base_view.xml',
'data/ribbon_data.xml', 'data/ribbon_data.xml',
], ],

2
web_environment_ribbon/data/ribbon_data.xml

@ -6,7 +6,7 @@
<!-- Add ribbon name default configuration parameter --> <!-- Add ribbon name default configuration parameter -->
<record id="default_ribbon_name" model="ir.config_parameter"> <record id="default_ribbon_name" model="ir.config_parameter">
<field name="key">ribbon.name</field> <field name="key">ribbon.name</field>
<field name="value">TEST</field>
<field name="value"><![CDATA[TEST<br/>({db_name})]]></field>
</record> </record>
<!-- Add ribbon color configuration parameter --> <!-- Add ribbon color configuration parameter -->

1
web_environment_ribbon/models/__init__.py

@ -0,0 +1 @@
from . import web_environment_ribbon_backend

33
web_environment_ribbon/models/web_environment_ribbon_backend.py

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, models
class WebEnvironmentRibbonBackend(models.Model):
_name = 'web.environment.ribbon.backend'
_description = 'Web Environment Ribbon Backend'
@api.model
def _prepare_ribbon_name(self):
db_name = self.env.cr.dbname
name = self.env['ir.config_parameter'].get_param('ribbon.name')
name = name.format(db_name=db_name)
return name
@api.model
def get_environment_ribbon(self):
"""
This method returns the ribbon data from ir config parameters
:return: dictionary
"""
ir_config_model = self.env['ir.config_parameter']
name = self._prepare_ribbon_name()
return {
'name': name,
'color': ir_config_model.get_param('ribbon.color'),
'background_color': ir_config_model.get_param(
'ribbon.background.color'),
}

17
web_environment_ribbon/security/web_environment_ribbon_backend.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.model.access" id="web_environment_ribbon_backend_access_name">
<field name="name">web.environment.ribbon.backend access name</field>
<field name="model_id" ref="model_web_environment_ribbon_backend"/>
<field name="group_id" ref="base.group_user"/>
<field name="perm_read" eval="1"/>
<field name="perm_create" eval="0"/>
<field name="perm_write" eval="0"/>
<field name="perm_unlink" eval="0"/>
</record>
</odoo>

8
web_environment_ribbon/static/src/css/ribbon.css

@ -1,12 +1,14 @@
/* Copyright 2015 Francesco OpenCode Apruzzese <cescoap@gmail.com> /* Copyright 2015 Francesco OpenCode Apruzzese <cescoap@gmail.com>
Copyright 2017 Thomas Binsfeld <thomas.binsfeld@acsone.eu>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
.test-ribbon{ .test-ribbon{
width: 200px;
width: 300px;
top: 25px; top: 25px;
left: -50px;
left: -100px;
text-align: center; text-align: center;
line-height: 50px;
padding: 10px;
line-height: 20px;
letter-spacing: 1px; letter-spacing: 1px;
color: #f0f0f0; color: #f0f0f0;
-webkit-transform: rotate(-45deg); -webkit-transform: rotate(-45deg);

33
web_environment_ribbon/static/src/js/ribbon.js

@ -1,6 +1,7 @@
/* Copyright 2015 Sylvain Calador <sylvain.calador@akretion.com> /* Copyright 2015 Sylvain Calador <sylvain.calador@akretion.com>
Copyright 2015 Javi Melendez <javi.melendez@algios.com> Copyright 2015 Javi Melendez <javi.melendez@algios.com>
Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
Copyright 2017 Thomas Binsfeld <thomas.binsfeld@acsone.eu>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define('web_environment_ribbon.ribbon', function(require) { odoo.define('web_environment_ribbon.ribbon', function(require) {
@ -10,7 +11,7 @@ var $ = require('jquery');
var Model = require('web.Model'); var Model = require('web.Model');
var core = require('web.core'); var core = require('web.core');
var model = new Model('ir.config_parameter');
var backend_model = new Model('web.environment.ribbon.backend');
// Code from: http://jsfiddle.net/WK_of_Angmar/xgA5C/ // Code from: http://jsfiddle.net/WK_of_Angmar/xgA5C/
function validStrColour(strToTest) { function validStrColour(strToTest) {
@ -30,27 +31,21 @@ core.bus.on('web_client_ready', null, function () {
var ribbon = $('<div class="test-ribbon"/>'); var ribbon = $('<div class="test-ribbon"/>');
$('body').append(ribbon); $('body').append(ribbon);
ribbon.hide(); ribbon.hide();
model.call('get_param', ['ribbon.name']).then(
function (name) {
if (name && name != 'False') {
ribbon.html(name);
// Get ribbon data from backend
backend_model.call('get_environment_ribbon').then(
function (ribbon_data) {
// Ribbon name
if (ribbon_data.name && ribbon_data.name != 'False') {
ribbon.html(ribbon_data.name);
ribbon.show(); ribbon.show();
} }
// Ribbon color
if (ribbon_data.color && validStrColour(ribbon_data.color)) {
ribbon.css('color', ribbon_data.color);
} }
);
// 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
model.call('get_param', ['ribbon.background.color']).then(
function (strBackgroundColor) {
if (strBackgroundColor && validStrColour(strBackgroundColor)) {
ribbon.css('background-color', strBackgroundColor);
// Ribbon background color
if (ribbon_data.background_color && validStrColour(ribbon_data.background_color)) {
ribbon.css('background-color', ribbon_data.background_color);
} }
} }
); );

Loading…
Cancel
Save