3
0
Fork 0
10.0
hparfr 2017-09-11 10:29:11 +00:00
parent a4255c3c1a
commit 7303c02cac
2 changed files with 13 additions and 13 deletions

View File

@ -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();

View File

@ -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);