Browse Source

Lint

pull/722/head
hparfr 7 years ago
parent
commit
7303c02cac
  1. 18
      web_switch_company_warning/static/src/js/switch_company_warning.js
  2. 8
      web_switch_company_warning/static/src/js/switch_company_warning_worker.js

18
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 //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) //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({ var SwitchCompanyWarningWidget = Widget.extend({
template:'WarningWidget', template:'WarningWidget',
init: function() { init: function() {
this._super(); this._super();
var self = this; 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) { w.port.addEventListener('message', function (msg) {
if (msg.data.type !== 'newCtx')
if (msg.data.type !== 'newCtx') {
return; return;
if(msg.data.newCtx != self.session.company_id) {
self.$el.show();
} else {
}
if(msg.data.newCtx === self.session.company_id) {
self.$el.hide(); self.$el.hide();
} else {
self.$el.show();
} }
}); });
w.port.start(); w.port.start();

8
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) //changed in another tab or window (in the same browser)
var con = []; var con = [];
var lastCtx = null;
var lastCtx = null;
addEventListener("connect", function(ee) { addEventListener("connect", function(ee) {
var port = ee.ports[0]; var port = ee.ports[0];
@ -13,12 +12,11 @@ addEventListener("connect", function(ee) {
port.onmessage = function (e) { //addEventListener doesnt seams to work well port.onmessage = function (e) { //addEventListener doesnt seams to work well
var newCtx = e.data; var newCtx = e.data;
if (lastCtx && newCtx != lastCtx) {
if (lastCtx && newCtx !== lastCtx) {
con.map(function (eport) { con.map(function (eport) {
eport.postMessage({ type: "newCtx", "newCtx": newCtx, "lastCtx": lastCtx});
eport.postMessage({type: "newCtx", "newCtx": newCtx, "lastCtx": lastCtx});
}); });
} }
lastCtx = newCtx; lastCtx = newCtx;
}; };
}, false); }, false);
Loading…
Cancel
Save