From a4255c3c1ac63ff01d43caae87db6a60fb0f4050 Mon Sep 17 00:00:00 2001 From: hparfr Date: Fri, 8 Sep 2017 15:17:08 +0000 Subject: [PATCH 1/5] Migrate switch_company_warning to 10 --- web_switch_company_warning/__manifest__.py | 11 ++++--- .../static/src/js/switch_company_warning.js | 32 +++++++------------ .../static/src/xml/switch_company_warning.xml | 4 +-- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/web_switch_company_warning/__manifest__.py b/web_switch_company_warning/__manifest__.py index 3cda8a1f..b8674d64 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/static/src/js/switch_company_warning.js b/web_switch_company_warning/static/src/js/switch_company_warning.js index a49040fc..ababba27 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,44 @@ '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({ - - template:'web_switch_company_warning.warningWidget', + var SwitchCompanyWarningWidget = Widget.extend({ + template:'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; w.port.addEventListener('message', function (msg) { - if (msg.data.type !== 'newCtx') - return; - + if (msg.data.type !== 'newCtx') + return; if(msg.data.newCtx != self.session.company_id) { self.$el.show(); } else { self.$el.hide(); } }); - 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/xml/switch_company_warning.xml b/web_switch_company_warning/static/src/xml/switch_company_warning.xml index 7943516e..8c3983a9 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 @@ -1,9 +1,9 @@ \ No newline at end of file + From 7303c02cac5085411d67520340d512061ab5d902 Mon Sep 17 00:00:00 2001 From: hparfr Date: Mon, 11 Sep 2017 10:29:11 +0000 Subject: [PATCH 2/5] Lint --- .../static/src/js/switch_company_warning.js | 18 ++++++++++-------- .../src/js/switch_company_warning_worker.js | 8 +++----- 2 files changed, 13 insertions(+), 13 deletions(-) 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 ababba27..b7af4c42 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 @@ -6,23 +6,25 @@ odoo.define('web_switch_company_warning.widget', function (require) { //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 - + if (!window.SharedWorker) { + //not supported + return; + } var SwitchCompanyWarningWidget = Widget.extend({ template:'WarningWidget', init: function() { this._super(); var self = this; - var w = new SharedWorker('/web_switch_company_warning/static/src/js/switch_company_warning_worker.js'); + 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') + if (msg.data.type !== 'newCtx') { return; - if(msg.data.newCtx != self.session.company_id) { - self.$el.show(); - } else { + } + if(msg.data.newCtx === self.session.company_id) { self.$el.hide(); + } else { + self.$el.show(); } }); w.port.start(); 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..014fcfb3 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,8 +3,7 @@ //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]; @@ -13,12 +12,11 @@ addEventListener("connect", function(ee) { port.onmessage = function (e) { //addEventListener doesnt seams to work well var newCtx = e.data; - if (lastCtx && newCtx != lastCtx) { + if (lastCtx && newCtx !== lastCtx) { con.map(function (eport) { - eport.postMessage({ type: "newCtx", "newCtx": newCtx, "lastCtx": lastCtx}); + eport.postMessage({type: "newCtx", "newCtx": newCtx, "lastCtx": lastCtx}); }); } lastCtx = newCtx; }; - }, false); From 048943447931d3126cf4b7fff24ca39789cafa2c Mon Sep 17 00:00:00 2001 From: hparfr Date: Mon, 11 Sep 2017 11:49:24 +0000 Subject: [PATCH 3/5] Lint part 2 --- web_switch_company_warning/__manifest__.py | 2 +- .../static/src/js/switch_company_warning_worker.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web_switch_company_warning/__manifest__.py b/web_switch_company_warning/__manifest__.py index b8674d64..d7f6e43f 100644 --- a/web_switch_company_warning/__manifest__.py +++ b/web_switch_company_warning/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Multicompany - Switch Company Warning", "summary": "Show a warning if current company has been switched" - " in another tab or window.", + " in another tab or window.", "version": "10.0.0.1.0", "category": "web", "website": "http://akretion.com", 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 014fcfb3..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 @@ -9,11 +9,11 @@ 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) { + con.forEach(function (eport) { eport.postMessage({type: "newCtx", "newCtx": newCtx, "lastCtx": lastCtx}); }); } From 995954da3cc654bff6466a8a8297bbc69f55ab42 Mon Sep 17 00:00:00 2001 From: Hpar Date: Mon, 11 Sep 2017 13:59:13 +0200 Subject: [PATCH 4/5] lint part 3 --- web_switch_company_warning/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_switch_company_warning/__manifest__.py b/web_switch_company_warning/__manifest__.py index d7f6e43f..51532b83 100644 --- a/web_switch_company_warning/__manifest__.py +++ b/web_switch_company_warning/__manifest__.py @@ -10,7 +10,7 @@ "website": "http://akretion.com", "license": "AGPL-3", "author": "Akretion, " - "Odoo Community Association (OCA)", + "Odoo Community Association (OCA)", "depends": [ 'web', ], From 967d0f5489fc50f232428190d2e4b198987a15f2 Mon Sep 17 00:00:00 2001 From: hpar Date: Tue, 17 Oct 2017 10:54:46 +0200 Subject: [PATCH 5/5] Switch to old name --- .../static/src/js/switch_company_warning.js | 2 +- .../static/src/xml/switch_company_warning.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 b7af4c42..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 @@ -11,7 +11,7 @@ odoo.define('web_switch_company_warning.widget', function (require) { return; } var SwitchCompanyWarningWidget = Widget.extend({ - template:'WarningWidget', + template:'web_switch_company_warning.warningWidget', init: function() { this._super(); var self = this; 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 8c3983a9..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 @@ -1,6 +1,6 @@