diff --git a/setup/_metapackage/setup.py b/setup/_metapackage/setup.py index 26c456b1..336db6c3 100644 --- a/setup/_metapackage/setup.py +++ b/setup/_metapackage/setup.py @@ -43,7 +43,7 @@ setuptools.setup( 'odoo10-addon-web_send_message_popup', 'odoo10-addon-web_sheet_full_width', 'odoo10-addon-web_shortcut', - 'odoo10-addon-web_switch_company_warning', + 'odoo10-addon-web_switch_context_warning', 'odoo10-addon-web_timeline', 'odoo10-addon-web_translate_dialog', 'odoo10-addon-web_tree_dynamic_colored_field', 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 deleted file mode 100644 index aa017e3e..00000000 --- a/web_switch_company_warning/static/src/js/switch_company_warning.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict'; - -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) { - //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'); - w.port.addEventListener('message', function (msg) { - if (msg.data.type !== 'newCtx') { - return; - } - if(msg.data.newCtx === self.generateSignature()) { - self.$el.hide(); - } else { - self.$el.show(); - } - }); - w.port.start(); - w.port.postMessage(this.generateSignature()); - }, - generateSignature: function() { - return [this.session.company_id, this.session.db].join(); - } - }); - - UserMenu.include({ - init: function(parent) { - this._super(parent); - 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 deleted file mode 100644 index f5f23add..00000000 --- a/web_switch_company_warning/static/src/js/switch_company_warning_worker.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -//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) - -var con = []; -var lastCtx = null; - -addEventListener("connect", function(ee) { - var port = ee.ports[0]; - con.push(port); - - port.onmessage = function (e) { - var newCtx = e.data; - - 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/README.rst b/web_switch_context_warning/README.rst similarity index 78% rename from web_switch_company_warning/README.rst rename to web_switch_context_warning/README.rst index cdfc5d4b..2998fd3b 100644 --- a/web_switch_company_warning/README.rst +++ b/web_switch_context_warning/README.rst @@ -2,12 +2,13 @@ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 -=========================== -Web Switch Company Warning -=========================== +========================== +Web Switch Context Warning +========================== -Shows a warning if current company has been switched in another tab or window. +Shows a warning if current user, company or database have been switched +in another tab or window. Known issues / Roadmap @@ -16,7 +17,7 @@ Known issues / Roadmap * If the browser don't implement Sharded Worker (http://www.w3.org/TR/workers/#sharedworker), the warning message will not be displayed (there is no polyfill). - * Switching company in a separate browser or in private browsing mode will not be detected by this module. It's a limitation of Shared Worker(limit to browser session, server:port...) + * Switching user, database or company in a separate browser or in private browsing mode will not be detected by this module. It's a limitation of Shared Worker(limit to browser session, server:port...) Bug Tracker diff --git a/web_switch_company_warning/__init__.py b/web_switch_context_warning/__init__.py similarity index 100% rename from web_switch_company_warning/__init__.py rename to web_switch_context_warning/__init__.py diff --git a/web_switch_company_warning/__manifest__.py b/web_switch_context_warning/__manifest__.py similarity index 59% rename from web_switch_company_warning/__manifest__.py rename to web_switch_context_warning/__manifest__.py index 0d53e5d8..ab1b0152 100644 --- a/web_switch_company_warning/__manifest__.py +++ b/web_switch_context_warning/__manifest__.py @@ -2,12 +2,12 @@ # 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": "10.0.0.1.1", + "name": "Switch Context Warning", + "summary": "Show a warning if current user, company or database" + " have been switched in another tab or window.", + "version": "10.0.1.2.0", "category": "web", - "website": "http://akretion.com", + "website": "https://github.com/OCA/web", "license": "AGPL-3", "author": "Akretion, " "Odoo Community Association (OCA)", @@ -18,7 +18,7 @@ "view/view.xml", ], "qweb": [ - "static/src/xml/switch_company_warning.xml", + "static/src/xml/switch_context_warning.xml", ], 'installable': True, "application": False, diff --git a/web_switch_company_warning/i18n/web_switch_company_warning.pot b/web_switch_context_warning/i18n/web_switch_context_warning.pot similarity index 57% rename from web_switch_company_warning/i18n/web_switch_company_warning.pot rename to web_switch_context_warning/i18n/web_switch_context_warning.pot index ccf2d1b5..183f7db3 100644 --- a/web_switch_company_warning/i18n/web_switch_company_warning.pot +++ b/web_switch_context_warning/i18n/web_switch_context_warning.pot @@ -1,6 +1,6 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * web_switch_company_warning +# * web_switch_context_warning # msgid "" msgstr "" @@ -13,23 +13,23 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" -#. module: web_switch_company_warning +#. module: web_switch_context_warning #. openerp-web -#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:6 +#: code:addons/web_switch_context_warning/static/src/xml/switch_company_warning.xml:6 #, python-format msgid "Reload" msgstr "" -#. module: web_switch_company_warning +#. module: web_switch_context_warning #. openerp-web -#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:5 +#: code:addons/web_switch_context_warning/static/src/xml/switch_company_warning.xml:5 #, python-format -msgid "You switched to a different company or database with another tab or window" +msgid "You switched to a different user, company or database with another tab or window" msgstr "" -#. module: web_switch_company_warning +#. module: web_switch_context_warning #. openerp-web -#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:6 +#: code:addons/web_switch_context_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_context_warning/static/description/icon.png similarity index 100% rename from web_switch_company_warning/static/description/icon.png rename to web_switch_context_warning/static/description/icon.png diff --git a/web_switch_context_warning/static/src/js/switch_context_warning.js b/web_switch_context_warning/static/src/js/switch_context_warning.js new file mode 100644 index 00000000..d6bea549 --- /dev/null +++ b/web_switch_context_warning/static/src/js/switch_context_warning.js @@ -0,0 +1,59 @@ +odoo.define('web_switch_context_warning.widget', function (require) { + 'use strict'; + + 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) { + // Not supported + return; + } + var SwitchCompanyWarningWidget = Widget.extend({ + template:'web_switch_context_warning.warningWidget', + init: function () { + this._super(); + var self = this; + var w = new SharedWorker('/web_switch_context_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.generateSignature()) { + self.$el.hide(); + } else { + self.$el.show(); + } + }); + w.port.start(); + w.port.postMessage(this.generateSignature()); + }, + generateSignature: function () { + return [this.session.uid, this.session.company_id, this.session.db].join(); + }, + }); + + UserMenu.include({ + init: function(parent) { + this._super(parent); + var switchCompanyWarning = new SwitchCompanyWarningWidget(); + // Check if Odoo version is Enterprise + var isEnterprise = odoo.session_info.server_version_info[5] === 'e'; + if (isEnterprise) { + switchCompanyWarning.insertAfter('.o_main_navbar'); + } else { + // Choose where to append depending on whether web_responsive is installed or not + if (document.getElementById('oe_main_menu_navbar')) { + switchCompanyWarning.appendTo('#oe_main_menu_navbar'); + } else { + switchCompanyWarning.insertAfter('.main-nav'); + } + } + } + + }); + + return SwitchCompanyWarningWidget; +}); + diff --git a/web_switch_context_warning/static/src/js/switch_context_warning_worker.js b/web_switch_context_warning/static/src/js/switch_context_warning_worker.js new file mode 100644 index 00000000..b246c763 --- /dev/null +++ b/web_switch_context_warning/static/src/js/switch_context_warning_worker.js @@ -0,0 +1,26 @@ +// 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) +var con = []; +var lastCtx = null; + +addEventListener("connect", function (ee) { + "use strict"; + + var port = ee.ports[0]; + con.push(port); + + port.onmessage = function (e) { + var newCtx = e.data; + + 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_context_warning/static/src/xml/switch_company_warning.xml similarity index 64% rename from web_switch_company_warning/static/src/xml/switch_company_warning.xml rename to web_switch_context_warning/static/src/xml/switch_company_warning.xml index 3bf86e9d..28b6b6c3 100644 --- a/web_switch_company_warning/static/src/xml/switch_company_warning.xml +++ b/web_switch_context_warning/static/src/xml/switch_company_warning.xml @@ -1,8 +1,8 @@