Browse Source

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

[10.0] web_environment_ribbon forward port
pull/672/head
Moises Lopez - https://www.vauxoo.com/ 7 years ago
committed by GitHub
parent
commit
f2f4ac1f39
  1. 1
      .gitignore
  2. 3
      web_environment_ribbon/README.rst
  3. 2
      web_environment_ribbon/__init__.py
  4. 1
      web_environment_ribbon/__manifest__.py
  5. 2
      web_environment_ribbon/data/ribbon_data.xml
  6. 1
      web_environment_ribbon/models/__init__.py
  7. 38
      web_environment_ribbon/models/web_environment_ribbon_backend.py
  8. 8
      web_environment_ribbon/static/src/css/ribbon.css
  9. 33
      web_environment_ribbon/static/src/js/ribbon.js

1
.gitignore

@ -20,6 +20,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
*.eggs
# Installer logs
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
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
----------

2
web_environment_ribbon/__init__.py

@ -1,4 +1,6 @@
# -*- 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

1
web_environment_ribbon/__manifest__.py

@ -1,6 +1,7 @@
# -*- 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).
{

2
web_environment_ribbon/data/ribbon_data.xml

@ -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 -->

1
web_environment_ribbon/models/__init__.py

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

38
web_environment_ribbon/models/web_environment_ribbon_backend.py

@ -0,0 +1,38 @@
# -*- 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'),
}

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

@ -1,12 +1,14 @@
/* 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);

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

@ -1,6 +1,7 @@
/* 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();
}
// 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