forked from Techsystech/web
[IMP] web_switch_context_warning: black, isort
parent
bb9b0f9118
commit
0c6150bedd
|
@ -8,17 +8,10 @@
|
||||||
"category": "web",
|
"category": "web",
|
||||||
"website": "https://github.com/OCA/web",
|
"website": "https://github.com/OCA/web",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"author": "Akretion, "
|
"author": "Akretion, " "Odoo Community Association (OCA)",
|
||||||
"Odoo Community Association (OCA)",
|
"depends": ["web"],
|
||||||
"depends": [
|
"data": ["view/view.xml"],
|
||||||
'web',
|
"qweb": ["static/src/xml/switch_context_warning.xml"],
|
||||||
],
|
"installable": True,
|
||||||
"data": [
|
|
||||||
"view/view.xml",
|
|
||||||
],
|
|
||||||
"qweb": [
|
|
||||||
"static/src/xml/switch_context_warning.xml",
|
|
||||||
],
|
|
||||||
'installable': True,
|
|
||||||
"application": False,
|
"application": False,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
odoo.define('web_switch_context_warning.widget', function (require) {
|
odoo.define("web_switch_context_warning.widget", function(require) {
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
var Widget = require('web.Widget');
|
var Widget = require("web.Widget");
|
||||||
var UserMenu = require('web.UserMenu');
|
var UserMenu = require("web.UserMenu");
|
||||||
var session = require('web.session');
|
var session = require("web.session");
|
||||||
// Show a big banner in the top of the page if the context has been
|
// Show a big banner in the top of the page if the context has been
|
||||||
// changed in another tab or window (in the same browser)
|
// changed in another tab or window (in the same browser)
|
||||||
|
|
||||||
|
@ -12,13 +12,15 @@ odoo.define('web_switch_context_warning.widget', function (require) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var SwitchCompanyWarningWidget = Widget.extend({
|
var SwitchCompanyWarningWidget = Widget.extend({
|
||||||
template:'web_switch_context_warning.warningWidget',
|
template: "web_switch_context_warning.warningWidget",
|
||||||
init: function () {
|
init: function() {
|
||||||
this._super();
|
this._super();
|
||||||
var self = this;
|
var self = this;
|
||||||
var w = new SharedWorker('/web_switch_context_warning/static/src/js/switch_context_warning_worker.js');
|
var w = new SharedWorker(
|
||||||
w.port.addEventListener('message', function (msg) {
|
"/web_switch_context_warning/static/src/js/switch_context_warning_worker.js"
|
||||||
if (msg.data.type !== 'newCtx') {
|
);
|
||||||
|
w.port.addEventListener("message", function(msg) {
|
||||||
|
if (msg.data.type !== "newCtx") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.data.newCtx === self.generateSignature()) {
|
if (msg.data.newCtx === self.generateSignature()) {
|
||||||
|
@ -30,20 +32,18 @@ odoo.define('web_switch_context_warning.widget', function (require) {
|
||||||
w.port.start();
|
w.port.start();
|
||||||
w.port.postMessage(this.generateSignature());
|
w.port.postMessage(this.generateSignature());
|
||||||
},
|
},
|
||||||
generateSignature: function () {
|
generateSignature: function() {
|
||||||
return [session.uid, session.company_id, session.db].join();
|
return [session.uid, session.company_id, session.db].join();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
UserMenu.include({
|
UserMenu.include({
|
||||||
init: function (parent) {
|
init: function(parent) {
|
||||||
this._super(parent);
|
this._super(parent);
|
||||||
var switchCompanyWarning = new SwitchCompanyWarningWidget();
|
var switchCompanyWarning = new SwitchCompanyWarningWidget();
|
||||||
switchCompanyWarning.insertAfter('.o_main_navbar');
|
switchCompanyWarning.insertAfter(".o_main_navbar");
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return SwitchCompanyWarningWidget;
|
return SwitchCompanyWarningWidget;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -4,20 +4,28 @@
|
||||||
var con = [];
|
var con = [];
|
||||||
var lastCtx = null;
|
var lastCtx = null;
|
||||||
|
|
||||||
addEventListener("connect", function (ee) {
|
addEventListener(
|
||||||
|
"connect",
|
||||||
|
function(ee) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var port = ee.ports[0];
|
var port = ee.ports[0];
|
||||||
con.push(port);
|
con.push(port);
|
||||||
|
|
||||||
port.onmessage = function (e) {
|
port.onmessage = function(e) {
|
||||||
var newCtx = e.data;
|
var newCtx = e.data;
|
||||||
|
|
||||||
if (lastCtx && newCtx !== lastCtx) {
|
if (lastCtx && newCtx !== lastCtx) {
|
||||||
con.forEach(function (eport) {
|
con.forEach(function(eport) {
|
||||||
eport.postMessage({type: "newCtx", "newCtx": newCtx, "lastCtx": lastCtx});
|
eport.postMessage({
|
||||||
|
type: "newCtx",
|
||||||
|
newCtx: newCtx,
|
||||||
|
lastCtx: lastCtx,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
lastCtx = newCtx;
|
lastCtx = newCtx;
|
||||||
};
|
};
|
||||||
}, false);
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<template>
|
<template>
|
||||||
<t t-name="web_switch_context_warning.warningWidget">
|
<t t-name="web_switch_context_warning.warningWidget">
|
||||||
<div class="container-fluid bg-warning" style="text-align: center; display:none;padding-top:20px;padding-bottom:5px">
|
<div
|
||||||
<h3>You switched to a different user, company or database with another tab or window</h3>
|
class="container-fluid bg-warning"
|
||||||
<p><button onclick="location.reload(true);" class="btn">Reload</button> to refresh your session</p>
|
style="text-align: center; display:none;padding-top:20px;padding-bottom:5px"
|
||||||
|
>
|
||||||
|
<h3
|
||||||
|
>You switched to a different user, company or database with another tab or window</h3>
|
||||||
|
<p><button
|
||||||
|
onclick="location.reload(true);"
|
||||||
|
class="btn"
|
||||||
|
>Reload</button> to refresh your session</p>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<openerp>
|
<openerp>
|
||||||
<data>
|
<data>
|
||||||
<template id="assets_backend" name="web_switch_context_warning assets" inherit_id="web.assets_backend">
|
<template
|
||||||
|
id="assets_backend"
|
||||||
|
name="web_switch_context_warning assets"
|
||||||
|
inherit_id="web.assets_backend"
|
||||||
|
>
|
||||||
<xpath expr="." position="inside">
|
<xpath expr="." position="inside">
|
||||||
<script type="text/javascript" src="/web_switch_context_warning/static/src/js/switch_context_warning.js"></script>
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_switch_context_warning/static/src/js/switch_context_warning.js"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
</data>
|
</data>
|
||||||
|
|
Loading…
Reference in New Issue