Browse Source

Lint

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

16
web_switch_company_warning/static/src/js/switch_company_warning.js

@ -6,9 +6,10 @@ 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() {
@ -17,12 +18,13 @@ odoo.define('web_switch_company_warning.widget', function (require) {
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();

4
web_switch_company_warning/static/src/js/switch_company_warning_worker.js

@ -3,7 +3,6 @@
//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) {
@ -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