Browse Source

[ADD] web_switch_company_warning : display a message saying it's time to reload the page

pull/233/head
hparfr 9 years ago
parent
commit
45c3bba7b0
  1. 1
      web_switch_company_warning/__init__.py
  2. 23
      web_switch_company_warning/__openerp__.py
  3. 74
      web_switch_company_warning/readme.rst
  4. 23
      web_switch_company_warning/static/src/js/switch_comapny_warning_worker.js
  5. 50
      web_switch_company_warning/static/src/js/switch_company_warning.js
  6. 9
      web_switch_company_warning/static/src/xml/switch_company_warning.xml
  7. 10
      web_switch_company_warning/view/view.xml

1
web_switch_company_warning/__init__.py

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

23
web_switch_company_warning/__openerp__.py

@ -0,0 +1,23 @@
# -*- 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": "Shows a warning if current company has been switched in another tab or window."
"version": "0.1",
"category": "web",
"website": "https://github.com/OCA/web/blob/8.0/web_switch_company_warning",
"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,
}

74
web_switch_company_warning/readme.rst

@ -0,0 +1,74 @@
.. 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.
Configuration
=============
No configuration.
Usage
=====
* go to ...
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch}
.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "8.0" for example
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/
{project_repo}/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/
{project_repo}/issues/new?body=module:%20
{module_name}%0Aversion:%20
{version}%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.

23
web_switch_company_warning/static/src/js/switch_comapny_warning_worker.js

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

50
web_switch_company_warning/static/src/js/switch_company_warning.js

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

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