mirror of https://github.com/OCA/web.git
Migrate switch_company_warning to 10
parent
de8f773348
commit
a4255c3c1a
|
@ -1,15 +1,16 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © <2015> <Akretion, OCA>
|
# Copyright 2017 Akretion <raphael.reverdy@akretion.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
{
|
{
|
||||||
"name": "Multicompany - Switch Company Warning",
|
"name": "Multicompany - Switch Company Warning",
|
||||||
"summary": "Show a warning if current company has been switched"
|
"summary": "Show a warning if current company has been switched"
|
||||||
" in another tab or window.",
|
" in another tab or window.",
|
||||||
"version": "8.0.0.1.0",
|
"version": "10.0.0.1.0",
|
||||||
"category": "web",
|
"category": "web",
|
||||||
"website": "http://akretion.com",
|
"website": "http://akretion.com",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"author": "Akretion / Odoo Community Association (OCA)",
|
"author": "Akretion, "
|
||||||
|
"Odoo Community Association (OCA)",
|
||||||
"depends": [
|
"depends": [
|
||||||
'web',
|
'web',
|
||||||
],
|
],
|
||||||
|
@ -19,6 +20,6 @@
|
||||||
"qweb": [
|
"qweb": [
|
||||||
"static/src/xml/switch_company_warning.xml",
|
"static/src/xml/switch_company_warning.xml",
|
||||||
],
|
],
|
||||||
'installable': False,
|
'installable': True,
|
||||||
"application": False,
|
"application": False,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +1,44 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
openerp.web_switch_company_warning = function (instance) {
|
odoo.define('web_switch_company_warning.widget', function (require) {
|
||||||
|
var Widget = require('web.Widget');
|
||||||
|
var UserMenu = require('web.UserMenu');
|
||||||
//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)
|
if (!window.SharedWorker)
|
||||||
return; //not supported
|
return; //not supported
|
||||||
|
|
||||||
instance.web.SwitchCompanyWorker = null; //keep a global reference
|
var SwitchCompanyWarningWidget = Widget.extend({
|
||||||
|
template:'WarningWidget',
|
||||||
instance.web.SwitchCompanyWarningWidget = instance.web.Widget.extend({
|
|
||||||
|
|
||||||
template:'web_switch_company_warning.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');
|
||||||
instance.web.SwitchCompanyWorker = w;
|
|
||||||
|
|
||||||
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) {
|
if(msg.data.newCtx != self.session.company_id) {
|
||||||
self.$el.show();
|
self.$el.show();
|
||||||
} else {
|
} else {
|
||||||
self.$el.hide();
|
self.$el.hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
w.port.start();
|
w.port.start();
|
||||||
w.port.postMessage(this.session.company_id);
|
w.port.postMessage(this.session.company_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.web.UserMenu = instance.web.UserMenu.extend({
|
UserMenu.include({
|
||||||
|
|
||||||
init: function(parent) {
|
init: function(parent) {
|
||||||
this._super(parent);
|
this._super(parent);
|
||||||
|
var switchCompanyWarning = new SwitchCompanyWarningWidget();
|
||||||
var switchCompanyWarning = new instance.web.SwitchCompanyWarningWidget();
|
switchCompanyWarning.appendTo('#oe_main_menu_navbar');
|
||||||
switchCompanyWarning.insertAfter(instance.webclient.$el.find('#oe_main_menu_navbar'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
return SwitchCompanyWarningWidget;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<template>
|
<template>
|
||||||
<t t-name="web_switch_company_warning.warningWidget">
|
<t t-name="WarningWidget">
|
||||||
<div class="container-fluid bg-warning" style="text-align: center; display:none;">
|
<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>
|
<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>
|
<p><button onclick="location.reload(true);" class="btn">Reload</button> to refresh your session</p>
|
||||||
|
|
Loading…
Reference in New Issue