Browse Source

Merge pull request #233 from hparfr/web_switch_company_warning

[ADD] web_switch_company_warning : display a message saying it's time…
pull/238/head
Sylvain LE GAL 9 years ago
parent
commit
c958936773
  1. 55
      web_switch_company_warning/README.rst
  2. 1
      web_switch_company_warning/__init__.py
  3. 24
      web_switch_company_warning/__openerp__.py
  4. 52
      web_switch_company_warning/static/src/js/switch_company_warning.js
  5. 24
      web_switch_company_warning/static/src/js/switch_company_warning_worker.js
  6. 9
      web_switch_company_warning/static/src/xml/switch_company_warning.xml
  7. 10
      web_switch_company_warning/view/view.xml

55
web_switch_company_warning/README.rst

@ -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.

1
web_switch_company_warning/__init__.py

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

24
web_switch_company_warning/__openerp__.py

@ -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": "0.1",
"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": True,
"application": False,
}

52
web_switch_company_warning/static/src/js/switch_company_warning.js

@ -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'));
}
});
};

24
web_switch_company_warning/static/src/js/switch_company_warning_worker.js

@ -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);

9
web_switch_company_warning/static/src/xml/switch_company_warning.xml

@ -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>

10
web_switch_company_warning/view/view.xml

@ -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…
Cancel
Save