diff --git a/web_switch_context_warning/__manifest__.py b/web_switch_context_warning/__manifest__.py index 275a5233b..90f8f6b22 100644 --- a/web_switch_context_warning/__manifest__.py +++ b/web_switch_context_warning/__manifest__.py @@ -3,22 +3,15 @@ { "name": "Switch Context Warning", "summary": "Show a warning if current user, company or database " - "have been switched in another tab or window.", + "have been switched in another tab or window.", "version": "12.0.2.0.0", "category": "web", "website": "https://github.com/OCA/web", "license": "AGPL-3", - "author": "Akretion, " - "Odoo Community Association (OCA)", - "depends": [ - 'web', - ], - "data": [ - "view/view.xml", - ], - "qweb": [ - "static/src/xml/switch_context_warning.xml", - ], - 'installable': True, + "author": "Akretion, " "Odoo Community Association (OCA)", + "depends": ["web"], + "data": ["view/view.xml"], + "qweb": ["static/src/xml/switch_context_warning.xml"], + "installable": True, "application": False, } 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 index 2c868ce03..7f9ad6392 100644 --- a/web_switch_context_warning/static/src/js/switch_context_warning.js +++ b/web_switch_context_warning/static/src/js/switch_context_warning.js @@ -1,9 +1,9 @@ -odoo.define('web_switch_context_warning.widget', function (require) { - 'use strict'; +odoo.define("web_switch_context_warning.widget", function(require) { + "use strict"; - var Widget = require('web.Widget'); - var UserMenu = require('web.UserMenu'); - var session = require('web.session'); + var Widget = require("web.Widget"); + var UserMenu = require("web.UserMenu"); + var session = require("web.session"); // Show a big banner in the top of the page if the context has been // changed in another tab or window (in the same browser) @@ -12,13 +12,15 @@ odoo.define('web_switch_context_warning.widget', function (require) { return; } var SwitchCompanyWarningWidget = Widget.extend({ - template:'web_switch_context_warning.warningWidget', - init: function () { + 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_context_warning_worker.js'); - w.port.addEventListener('message', function (msg) { - if (msg.data.type !== 'newCtx') { + var w = new SharedWorker( + "/web_switch_context_warning/static/src/js/switch_context_warning_worker.js" + ); + w.port.addEventListener("message", function(msg) { + if (msg.data.type !== "newCtx") { return; } if (msg.data.newCtx === self.generateSignature()) { @@ -30,20 +32,18 @@ odoo.define('web_switch_context_warning.widget', function (require) { w.port.start(); w.port.postMessage(this.generateSignature()); }, - generateSignature: function () { + generateSignature: function() { return [session.uid, session.company_id, session.db].join(); }, }); UserMenu.include({ - init: function (parent) { + init: function(parent) { this._super(parent); var switchCompanyWarning = new SwitchCompanyWarningWidget(); - switchCompanyWarning.insertAfter('.o_main_navbar'); + switchCompanyWarning.insertAfter(".o_main_navbar"); }, - }); 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 index 901239a7a..c1bf96400 100644 --- 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 @@ -4,20 +4,28 @@ var con = []; var lastCtx = null; -addEventListener("connect", function (ee) { - "use strict"; +addEventListener( + "connect", + function(ee) { + "use strict"; - var port = ee.ports[0]; - con.push(port); + var port = ee.ports[0]; + con.push(port); - port.onmessage = function (e) { - var newCtx = e.data; + 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); + if (lastCtx && newCtx !== lastCtx) { + con.forEach(function(eport) { + eport.postMessage({ + type: "newCtx", + newCtx: newCtx, + lastCtx: lastCtx, + }); + }); + } + lastCtx = newCtx; + }; + }, + false +); diff --git a/web_switch_context_warning/static/src/xml/switch_context_warning.xml b/web_switch_context_warning/static/src/xml/switch_context_warning.xml index ee02d0173..b134d0556 100644 --- a/web_switch_context_warning/static/src/xml/switch_context_warning.xml +++ b/web_switch_context_warning/static/src/xml/switch_context_warning.xml @@ -1,9 +1,16 @@ - + diff --git a/web_switch_context_warning/view/view.xml b/web_switch_context_warning/view/view.xml index 5270fa591..35c5714bc 100644 --- a/web_switch_context_warning/view/view.xml +++ b/web_switch_context_warning/view/view.xml @@ -1,9 +1,16 @@ - + -