forked from Techsystech/web
[ADD] web_switch_company_warning : display a message saying it's time to reload the page
[fix] .rst formatting [FIX] web_switch_company_warning Remove place holders in readme Add "use strict" in js [UPD] prefix versions with 8.0 [MIG] Make modules uninstallable [MIG] Rename manifest files11.0
parent
f0ca9461dc
commit
af43c5c763
|
@ -0,0 +1,55 @@
|
||||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||||
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
|
===========================
|
||||||
|
Web Switch Company Warning
|
||||||
|
===========================
|
||||||
|
|
||||||
|
|
||||||
|
Shows a warning if current company has been switched in another tab or window.
|
||||||
|
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
|
||||||
|
* If the browser don't implement Sharded Worker (http://www.w3.org/TR/workers/#sharedworker), the warning message will not be displayed (there is no polyfill).
|
||||||
|
|
||||||
|
* Switching company in a separate browser or in private browsing mode will not be detected by this module. It's a limitation of Shared Wworker(limit to browser session, server:port...)
|
||||||
|
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/
|
||||||
|
web/issues>`_.
|
||||||
|
In case of trouble, please check there if your issue has already been reported.
|
||||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here <https://github.com/OCA/
|
||||||
|
web/issues/new?body=module:%20
|
||||||
|
web_switch_company_warning%0Aversion:%20
|
||||||
|
0.1%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||||
|
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Hparfr <https://github.com/hparfr>
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. image:: https://odoo-community.org/logo.png
|
||||||
|
:alt: Odoo Community Association
|
||||||
|
:target: https://odoo-community.org
|
||||||
|
|
||||||
|
This module is maintained by the OCA.
|
||||||
|
|
||||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
|
mission is to support the collaborative development of Odoo features and
|
||||||
|
promote its widespread use.
|
||||||
|
|
||||||
|
To contribute to this module, please visit http://odoo-community.org.
|
|
@ -0,0 +1 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
|
@ -0,0 +1,24 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © <2015> <Akretion, OCA>
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
{
|
||||||
|
"name": "Multicompany - Switch Company Warning",
|
||||||
|
"summary": "Show a warning if current company has been switched"
|
||||||
|
" in another tab or window.",
|
||||||
|
"version": "8.0.0.1.0",
|
||||||
|
"category": "web",
|
||||||
|
"website": "http://akretion.com",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"author": "Akretion / Odoo Community Association (OCA)",
|
||||||
|
"depends": [
|
||||||
|
'web',
|
||||||
|
],
|
||||||
|
"data": [
|
||||||
|
"view/view.xml",
|
||||||
|
],
|
||||||
|
"qweb": [
|
||||||
|
"static/src/xml/switch_company_warning.xml",
|
||||||
|
],
|
||||||
|
'installable': False,
|
||||||
|
"application": False,
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
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,24 @@
|
||||||
|
"use strict";
|
||||||
|
//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,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>
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
<template id="assets_backend" name="web_switch_company_warning assets" inherit_id="web.assets_backend">
|
||||||
|
<xpath expr="." position="inside">
|
||||||
|
<script type="text/javascript" src="/web_switch_company_warning/static/src/js/switch_company_warning.js"></script>
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
|
</data>
|
||||||
|
</openerp>
|
Loading…
Reference in New Issue