From 0618f7f5a49f004e11a128b7845c1c81c2a4515a Mon Sep 17 00:00:00 2001 From: Antonio Espinosa Date: Wed, 20 Jul 2016 14:50:34 +0200 Subject: [PATCH] [MIG] web_environment_ribbon --- web_environment_ribbon/README.rst | 20 +-- web_environment_ribbon/__init__.py | 22 +--- web_environment_ribbon/__openerp__.py | 30 ++--- web_environment_ribbon/data/ribbon_data.xml | 38 +++--- .../static/src/css/ribbon.css | 3 + .../static/src/js/ribbon.js | 119 +++++++++--------- web_environment_ribbon/view/base_view.xml | 39 +++--- 7 files changed, 124 insertions(+), 147 deletions(-) diff --git a/web_environment_ribbon/README.rst b/web_environment_ribbon/README.rst index d9ffbd16..c5f17c01 100644 --- a/web_environment_ribbon/README.rst +++ b/web_environment_ribbon/README.rst @@ -1,6 +1,8 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :alt: License: AGPL-3 + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +====================== Web Environment Ribbon ====================== @@ -30,14 +32,17 @@ 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 +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/162/9.0 + Bug Tracker =========== -Bugs are tracked on `GitHub 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 -`here `_. +Bugs are tracked on `GitHub 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. Credits ======= @@ -47,6 +52,7 @@ Contributors * Francesco Apruzzese * Javi Melendez +* Antonio Espinosa Maintainer ---------- @@ -61,4 +67,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. diff --git a/web_environment_ribbon/__init__.py b/web_environment_ribbon/__init__.py index 5d2935f8..467b4cbe 100644 --- a/web_environment_ribbon/__init__.py +++ b/web_environment_ribbon/__init__.py @@ -1,20 +1,4 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (C) 2015 Francesco OpenCode Apruzzese () -# All Rights Reserved -# -# 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 License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Copyright 2015 Francesco OpenCode Apruzzese +# Copyright 2016 Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/web_environment_ribbon/__openerp__.py b/web_environment_ribbon/__openerp__.py index 5e3753bf..fb2dfb8a 100644 --- a/web_environment_ribbon/__openerp__.py +++ b/web_environment_ribbon/__openerp__.py @@ -1,29 +1,15 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (C) 2015 Francesco OpenCode Apruzzese () -# All Rights Reserved -# -# 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 License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Copyright 2015 Francesco OpenCode Apruzzese +# Copyright 2016 Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': "Web Environment Ribbon", - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'category': 'Web', - 'author': 'Francesco OpenCode Apruzzese,Odoo Community Association (OCA)', + 'author': 'Francesco OpenCode Apruzzese, ' + 'Tecnativa, ' + 'Odoo Community Association (OCA)', 'website': 'https://it.linkedin.com/in/francescoapruzzese', 'license': 'AGPL-3', "depends": [ @@ -36,5 +22,5 @@ "update_xml": [], "demo_xml": [], "auto_install": False, - 'installable': False + "installable": True } diff --git a/web_environment_ribbon/data/ribbon_data.xml b/web_environment_ribbon/data/ribbon_data.xml index e3eb9c46..4c18ddd7 100644 --- a/web_environment_ribbon/data/ribbon_data.xml +++ b/web_environment_ribbon/data/ribbon_data.xml @@ -1,24 +1,24 @@ - - + + - - - ribbon.name - TEST - + + + ribbon.name + TEST + - - - ribbon.color - #f0f0f0 - + + + ribbon.color + #f0f0f0 + - - - ribbon.background.color - rgba(255,0,0,.6) - + + + ribbon.background.color + rgba(255,0,0,.6) + - - + diff --git a/web_environment_ribbon/static/src/css/ribbon.css b/web_environment_ribbon/static/src/css/ribbon.css index d5d5e8d9..375ffee8 100644 --- a/web_environment_ribbon/static/src/css/ribbon.css +++ b/web_environment_ribbon/static/src/css/ribbon.css @@ -1,3 +1,6 @@ +/* Copyright 2015 Francesco OpenCode Apruzzese + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + .test-ribbon{ width: 200px; top: 50px; diff --git a/web_environment_ribbon/static/src/js/ribbon.js b/web_environment_ribbon/static/src/js/ribbon.js index 6a7f0bc8..68dbee33 100644 --- a/web_environment_ribbon/static/src/js/ribbon.js +++ b/web_environment_ribbon/static/src/js/ribbon.js @@ -1,68 +1,61 @@ -/****************************************************************************** - Copyright (C) 2015 Akretion (http://www.akretion.com) - @author Sylvain Calador - - Copyright (C) 2016 Algi Open Source Solutions (http://www.algios.com) - @author Javi Melendez - - 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 - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -******************************************************************************/ - -openerp.web_environment_ribbon = function(instance) { - - var ribbon = $(document).find('.test-ribbon'); - ribbon.hide(); - - var model = new instance.web.Model('ir.config_parameter'); +/* Copyright 2015 Sylvain Calador + Copyright 2015 Javi Melendez + Copyright 2016 Antonio Espinosa + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +odoo.define('web_environment_ribbon.ribbon', function(require) { +"use strict"; + +var $ = require('$'); +var Model = require('web.Model'); +var core = require('web.core'); + +var model = new Model('ir.config_parameter'); + +// 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)"; +} - var res = model.call('get_param', ['ribbon.name']).then( - function (name) { - if (name && name != 'False') { - ribbon.html(name); - ribbon.show(); +core.bus.on('web_client_ready', null, function () { + var ribbon = $('.test-ribbon'); + // If ribbon is found in DOM + if (ribbon.length) { + ribbon.hide(); + model.call('get_param', ['ribbon.name']).then( + function (name) { + if (name && name != 'False') { + ribbon.html(name); + ribbon.show(); + } } - } - ); - - // 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 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 - var res = model.call('get_param', ['ribbon.background.color']).then( - function (strBackgroundColor) { - if (strBackgroundColor && validStrColour(strBackgroundColor)) { - ribbon.css('background-color', strBackgroundColor); + ); + // 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); + } } - } - ); - // 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)"; + ); } -} +}); + +}); // odoo.define diff --git a/web_environment_ribbon/view/base_view.xml b/web_environment_ribbon/view/base_view.xml index 6d9efc9c..464a71dd 100644 --- a/web_environment_ribbon/view/base_view.xml +++ b/web_environment_ribbon/view/base_view.xml @@ -1,21 +1,26 @@ - - + + - -