Commit f2f4ac1f authored by Moises Lopez - https://www.vauxoo.com/'s avatar Moises Lopez - https://www.vauxoo.com/ Committed by GitHub
Browse files

Merge pull request #661 from acsone/10.0-ribbon-vars-sbi

[10.0] web_environment_ribbon forward port
parents 27706685 8e6b0138
......@@ -20,6 +20,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
*.eggs
# Installer logs
pip-log.txt
......
......@@ -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 <cescoap@gmail.com>
* Javi Melendez <javimelex@gmail.com>
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
* Thomas Binsfeld <thomas.binsfeld@acsone.eu>
Maintainer
----------
......
# -*- coding: utf-8 -*-
# Copyright 2015 Francesco OpenCode Apruzzese <cescoap@gmail.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).
from . import models
# -*- coding: utf-8 -*-
# Copyright 2015 Francesco OpenCode Apruzzese <cescoap@gmail.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).
{
......
......@@ -6,7 +6,7 @@
<!-- Add ribbon name default configuration parameter -->
<record id="default_ribbon_name" model="ir.config_parameter">
<field name="key">ribbon.name</field>
<field name="value">TEST</field>
<field name="value"><![CDATA[TEST<br/>({db_name})]]></field>
</record>
<!-- Add ribbon color configuration parameter -->
......
from . import web_environment_ribbon_backend
# -*- 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.AbstractModel):
_name = 'web.environment.ribbon.backend'
_description = 'Web Environment Ribbon Backend'
@api.model
def _prepare_ribbon_format_vals(self):
return {
'db_name': self.env.cr.dbname,
}
@api.model
def _prepare_ribbon_name(self):
name_tmpl = self.env['ir.config_parameter'].get_param('ribbon.name')
vals = self._prepare_ribbon_format_vals()
return name_tmpl.format(**vals)
@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'),
}
/* 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). */
.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);
......
/* Copyright 2015 Sylvain Calador <sylvain.calador@akretion.com>
Copyright 2015 Javi Melendez <javi.melendez@algios.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). */
odoo.define('web_environment_ribbon.ribbon', function(require) {
......@@ -10,7 +11,7 @@ var $ = require('jquery');
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 = $('<div class="test-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);
}
}
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment