diff --git a/web_switch_company_warning/__manifest__.py b/web_switch_company_warning/__manifest__.py index 3cda8a1f..51532b83 100644 --- a/web_switch_company_warning/__manifest__.py +++ b/web_switch_company_warning/__manifest__.py @@ -1,15 +1,16 @@ # -*- coding: utf-8 -*- -# © <2015> +# Copyright 2017 Akretion # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Multicompany - Switch Company Warning", "summary": "Show a warning if current company has been switched" - " in another tab or window.", - "version": "8.0.0.1.0", + " in another tab or window.", + "version": "10.0.0.1.0", "category": "web", "website": "http://akretion.com", "license": "AGPL-3", - "author": "Akretion / Odoo Community Association (OCA)", + "author": "Akretion, " + "Odoo Community Association (OCA)", "depends": [ 'web', ], @@ -19,6 +20,6 @@ "qweb": [ "static/src/xml/switch_company_warning.xml", ], - 'installable': False, + 'installable': True, "application": False, } diff --git a/web_switch_company_warning/i18n/web_switch_company_warning.pot b/web_switch_company_warning/i18n/web_switch_company_warning.pot new file mode 100644 index 00000000..10fc1db6 --- /dev/null +++ b/web_switch_company_warning/i18n/web_switch_company_warning.pot @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_switch_company_warning +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_switch_company_warning +#. openerp-web +#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:6 +#, python-format +msgid "Reload" +msgstr "" + +#. module: web_switch_company_warning +#. openerp-web +#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:5 +#, python-format +msgid "You switched to a different company with another tab or window" +msgstr "" + +#. module: web_switch_company_warning +#. openerp-web +#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:6 +#, python-format +msgid "to refresh your session" +msgstr "" + diff --git a/web_switch_company_warning/static/description/icon.png b/web_switch_company_warning/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/web_switch_company_warning/static/description/icon.png differ diff --git a/web_switch_company_warning/static/src/js/switch_company_warning.js b/web_switch_company_warning/static/src/js/switch_company_warning.js index a49040fc..d0053164 100644 --- a/web_switch_company_warning/static/src/js/switch_company_warning.js +++ b/web_switch_company_warning/static/src/js/switch_company_warning.js @@ -1,52 +1,46 @@ 'use strict'; -openerp.web_switch_company_warning = function (instance) { - +odoo.define('web_switch_company_warning.widget', function (require) { + var Widget = require('web.Widget'); + var UserMenu = require('web.UserMenu'); //Show a big banner in the top of the page if the company has been //changed in another tab or window (in the same browser) - if (!window.SharedWorker) - return; //not supported - - instance.web.SwitchCompanyWorker = null; //keep a global reference - - instance.web.SwitchCompanyWarningWidget = instance.web.Widget.extend({ - + if (!window.SharedWorker) { + //not supported + return; + } + var SwitchCompanyWarningWidget = Widget.extend({ template:'web_switch_company_warning.warningWidget', init: function() { this._super(); - var self = this; - - var w = new SharedWorker('/web_switch_company_warning/static/src/js/switch_company_warning_worker.js'); - instance.web.SwitchCompanyWorker = w; + var w = new SharedWorker('/web_switch_company_warning/static/src/js/switch_company_warning_worker.js'); w.port.addEventListener('message', function (msg) { - if (msg.data.type !== 'newCtx') - return; - - if(msg.data.newCtx != self.session.company_id) { - self.$el.show(); - } else { + if (msg.data.type !== 'newCtx') { + return; + } + if(msg.data.newCtx === self.session.company_id) { self.$el.hide(); + } else { + self.$el.show(); } }); - w.port.start(); w.port.postMessage(this.session.company_id); } }); - instance.web.UserMenu = instance.web.UserMenu.extend({ - + UserMenu.include({ init: function(parent) { this._super(parent); - - var switchCompanyWarning = new instance.web.SwitchCompanyWarningWidget(); - switchCompanyWarning.insertAfter(instance.webclient.$el.find('#oe_main_menu_navbar')); + var switchCompanyWarning = new SwitchCompanyWarningWidget(); + switchCompanyWarning.appendTo('#oe_main_menu_navbar'); } }); -}; + return SwitchCompanyWarningWidget; +}); diff --git a/web_switch_company_warning/static/src/js/switch_company_warning_worker.js b/web_switch_company_warning/static/src/js/switch_company_warning_worker.js index d4b4fbe4..f5f23add 100644 --- a/web_switch_company_warning/static/src/js/switch_company_warning_worker.js +++ b/web_switch_company_warning/static/src/js/switch_company_warning_worker.js @@ -3,22 +3,20 @@ //changed in another tab or window (in the same browser) var con = []; - -var lastCtx = null; +var lastCtx = null; addEventListener("connect", function(ee) { var port = ee.ports[0]; con.push(port); - port.onmessage = function (e) { //addEventListener doesnt seams to work well + port.onmessage = function (e) { var newCtx = e.data; - if (lastCtx && newCtx != lastCtx) { - con.map(function (eport) { - eport.postMessage({ type: "newCtx", "newCtx": newCtx, "lastCtx": lastCtx}); + if (lastCtx && newCtx !== lastCtx) { + con.forEach(function (eport) { + eport.postMessage({type: "newCtx", "newCtx": newCtx, "lastCtx": lastCtx}); }); } lastCtx = newCtx; }; - }, false); diff --git a/web_switch_company_warning/static/src/xml/switch_company_warning.xml b/web_switch_company_warning/static/src/xml/switch_company_warning.xml index 7943516e..13612008 100644 --- a/web_switch_company_warning/static/src/xml/switch_company_warning.xml +++ b/web_switch_company_warning/static/src/xml/switch_company_warning.xml @@ -6,4 +6,4 @@

to refresh your session

- \ No newline at end of file +