mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[ADD] web_switch_company_warning : display a message saying it's time to reload the page
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
//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)
|
||||
|
||||
var con = [];
|
||||
|
||||
var lastCtx = null;
|
||||
|
||||
addEventListener("connect", function(ee) {
|
||||
var port = ee.ports[0];
|
||||
con.push(port);
|
||||
|
||||
port.onmessage = function (e) { //addEventListener doesnt seams to work well
|
||||
var newCtx = e.data;
|
||||
|
||||
if (lastCtx && newCtx != lastCtx) {
|
||||
con.map(function (eport) {
|
||||
eport.postMessage({ type: 'newCtx', "newCtx": newCtx, "lastCtx": lastCtx});
|
||||
});
|
||||
}
|
||||
lastCtx = newCtx;
|
||||
};
|
||||
|
||||
}, false);
|
||||
@@ -0,0 +1,50 @@
|
||||
openerp.web_switch_company_warning = function (instance) {
|
||||
|
||||
//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',
|
||||
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.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({
|
||||
|
||||
init: function(parent) {
|
||||
this._super(parent);
|
||||
|
||||
var switchCompanyWarning = new instance.web.SwitchCompanyWarningWidget();
|
||||
switchCompanyWarning.insertAfter(instance.webclient.$el.find('#oe_main_menu_navbar'));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<template>
|
||||
<t t-name="web_switch_company_warning.warningWidget">
|
||||
<div class="container-fluid bg-warning" style="text-align: center; display:none;">
|
||||
<h3>You switched to a different company with another tab or window</h3>
|
||||
<p><button onclick="location.reload(true);" class="btn">Reload</button> to refresh your session</p>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
Reference in New Issue
Block a user