From e05d2159935a3c0cc03661423d232dde0077fc98 Mon Sep 17 00:00:00 2001 From: "Thomas Binsfeld (ACSONE)" Date: Wed, 31 May 2017 11:25:59 +0200 Subject: [PATCH] [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 --- .gitignore | 1 + web_environment_ribbon/README.rst | 3 ++ web_environment_ribbon/__init__.py | 2 ++ web_environment_ribbon/__openerp__.py | 2 ++ web_environment_ribbon/data/ribbon_data.xml | 2 +- web_environment_ribbon/models/__init__.py | 1 + .../models/web_environment_ribbon_backend.py | 33 +++++++++++++++++++ .../web_environment_ribbon_backend.xml | 17 ++++++++++ .../static/src/css/ribbon.css | 8 +++-- .../static/src/js/ribbon.js | 33 ++++++++----------- 10 files changed, 79 insertions(+), 23 deletions(-) create mode 100644 web_environment_ribbon/models/__init__.py create mode 100644 web_environment_ribbon/models/web_environment_ribbon_backend.py create mode 100644 web_environment_ribbon/security/web_environment_ribbon_backend.xml diff --git a/.gitignore b/.gitignore index 2daa5c85..8c376df5 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ var/ *.egg-info/ .installed.cfg *.egg +*.eggs # Installer logs pip-log.txt diff --git a/web_environment_ribbon/README.rst b/web_environment_ribbon/README.rst index c5f17c01..8479cded 100644 --- a/web_environment_ribbon/README.rst +++ b/web_environment_ribbon/README.rst @@ -25,6 +25,8 @@ Configuration * 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. +* You can add the database name in the ribbon by adding "{db_name}" in the + system parameter "ribbon.name". Usage ===== @@ -53,6 +55,7 @@ Contributors * Francesco Apruzzese * Javi Melendez * Antonio Espinosa +* Thomas Binsfeld Maintainer ---------- diff --git a/web_environment_ribbon/__init__.py b/web_environment_ribbon/__init__.py index 467b4cbe..548366e6 100644 --- a/web_environment_ribbon/__init__.py +++ b/web_environment_ribbon/__init__.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- # Copyright 2015 Francesco OpenCode Apruzzese # Copyright 2016 Antonio Espinosa +# Copyright 2017 Thomas Binsfeld # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import models diff --git a/web_environment_ribbon/__openerp__.py b/web_environment_ribbon/__openerp__.py index fb2dfb8a..48212a9d 100644 --- a/web_environment_ribbon/__openerp__.py +++ b/web_environment_ribbon/__openerp__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Copyright 2015 Francesco OpenCode Apruzzese # Copyright 2016 Antonio Espinosa +# Copyright 2017 Thomas Binsfeld # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { @@ -16,6 +17,7 @@ 'web', ], "data": [ + 'security/web_environment_ribbon_backend.xml', 'view/base_view.xml', 'data/ribbon_data.xml', ], diff --git a/web_environment_ribbon/data/ribbon_data.xml b/web_environment_ribbon/data/ribbon_data.xml index 4c18ddd7..0ba37985 100644 --- a/web_environment_ribbon/data/ribbon_data.xml +++ b/web_environment_ribbon/data/ribbon_data.xml @@ -6,7 +6,7 @@ ribbon.name - TEST + ({db_name})]]> diff --git a/web_environment_ribbon/models/__init__.py b/web_environment_ribbon/models/__init__.py new file mode 100644 index 00000000..18368b47 --- /dev/null +++ b/web_environment_ribbon/models/__init__.py @@ -0,0 +1 @@ +from . import web_environment_ribbon_backend diff --git a/web_environment_ribbon/models/web_environment_ribbon_backend.py b/web_environment_ribbon/models/web_environment_ribbon_backend.py new file mode 100644 index 00000000..aa4694f7 --- /dev/null +++ b/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'), + } diff --git a/web_environment_ribbon/security/web_environment_ribbon_backend.xml b/web_environment_ribbon/security/web_environment_ribbon_backend.xml new file mode 100644 index 00000000..55199b4d --- /dev/null +++ b/web_environment_ribbon/security/web_environment_ribbon_backend.xml @@ -0,0 +1,17 @@ + + + + + + + web.environment.ribbon.backend access name + + + + + + + + + diff --git a/web_environment_ribbon/static/src/css/ribbon.css b/web_environment_ribbon/static/src/css/ribbon.css index 999c64f7..462cd2ff 100644 --- a/web_environment_ribbon/static/src/css/ribbon.css +++ b/web_environment_ribbon/static/src/css/ribbon.css @@ -1,12 +1,14 @@ /* Copyright 2015 Francesco OpenCode Apruzzese + Copyright 2017 Thomas Binsfeld * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ .test-ribbon{ - width: 200px; + width: 300px; top: 25px; - left: -50px; + left: -100px; text-align: center; - line-height: 50px; + padding: 10px; + line-height: 20px; letter-spacing: 1px; color: #f0f0f0; -webkit-transform: rotate(-45deg); diff --git a/web_environment_ribbon/static/src/js/ribbon.js b/web_environment_ribbon/static/src/js/ribbon.js index 90037f4e..c9e132c8 100644 --- a/web_environment_ribbon/static/src/js/ribbon.js +++ b/web_environment_ribbon/static/src/js/ribbon.js @@ -1,6 +1,7 @@ /* Copyright 2015 Sylvain Calador Copyright 2015 Javi Melendez Copyright 2016 Antonio Espinosa + Copyright 2017 Thomas Binsfeld * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ odoo.define('web_environment_ribbon.ribbon', function(require) { @@ -10,7 +11,7 @@ var $ = require('$'); var Model = require('web.Model'); 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/ function validStrColour(strToTest) { @@ -30,27 +31,21 @@ core.bus.on('web_client_ready', null, function () { var ribbon = $('
'); $('body').append(ribbon); 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(); } - } - ); - // Get ribbon color from system parameters - model.call('get_param', ['ribbon.color']).then( - function (strColor) { - if (strColor && validStrColour(strColor)) { - ribbon.css('color', strColor); + // Ribbon color + if (ribbon_data.color && validStrColour(ribbon_data.color)) { + ribbon.css('color', ribbon_data.color); } - } - ); - // 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); } } );