Browse Source

Add module web_switch_company_warning

pull/1303/head
Benoît Fontaine 5 years ago
parent
commit
546019d102
  1. 55
      web_switch_company_warning/README.rst
  2. 1
      web_switch_company_warning/__init__.py
  3. 18
      web_switch_company_warning/__manifest__.py
  4. 36
      web_switch_company_warning/i18n/fr.po
  5. 36
      web_switch_company_warning/i18n/web_switch_company_warning.pot
  6. BIN
      web_switch_company_warning/static/description/icon.png
  7. 47
      web_switch_company_warning/static/src/js/switch_company_warning.js
  8. 26
      web_switch_company_warning/static/src/js/switch_company_warning_worker.js
  9. 9
      web_switch_company_warning/static/src/xml/switch_company_warning.xml
  10. 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 Worker(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

18
web_switch_company_warning/__manifest__.py

@ -0,0 +1,18 @@
# coding: utf-8
# Copyright 2017 Akretion <raphael.reverdy@akretion.com>
# 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": "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": True,
"application": False,
}

36
web_switch_company_warning/i18n/fr.po

@ -0,0 +1,36 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_switch_company_warning
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: web_switch_company_warning
#. openerp-web
#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:6
#, python-format
msgid "Reload"
msgstr "Actualiser"
#. module: web_switch_company_warning
#. openerp-web
#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:5
#, python-format
msgid "You switched to a different company or database with another tab or window"
msgstr "Vous avez changé de société dans un autre onglet ou une autre fenêtre"
#. module: web_switch_company_warning
#. openerp-web
#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:6
#, python-format
msgid "to refresh your session"
msgstr "pour rafraîchir votre session"

36
web_switch_company_warning/i18n/web_switch_company_warning.pot

@ -0,0 +1,36 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_switch_company_warning
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: web_switch_company_warning
#. openerp-web
#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:6
#, python-format
msgid "Reload"
msgstr ""
#. module: web_switch_company_warning
#. openerp-web
#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:5
#, python-format
msgid "You switched to a different company or database with another tab or window"
msgstr ""
#. module: web_switch_company_warning
#. openerp-web
#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:6
#, python-format
msgid "to refresh your session"
msgstr ""

BIN
web_switch_company_warning/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

47
web_switch_company_warning/static/src/js/switch_company_warning.js

@ -0,0 +1,47 @@
odoo.define('web_switch_company_warning.widget', function(require) {
'use strict';
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
//changed in another tab or window (in the same browser)
if (!window.SharedWorker) {
//not supported
return;
}
var SwitchCompanyWarningWidget = Widget.extend({
template: 'web_switch_company_warning.warningWidget',
init: function(parent) {
console.log(parent);
this._super(parent);
var self = this;
var w = new SharedWorker('/web_switch_company_warning/static/src/js/switch_company_warning_worker.js');
w.port.addEventListener('message', function(msg) {
if (msg.data.type !== 'newCtx') {
return;
}
if (msg.data.newCtx === self.generateSignature()) {
self.$el.hide();
} else {
self.$el.show();
}
});
w.port.start();
w.port.postMessage(this.generateSignature());
},
generateSignature: function() {
return [odoo.session_info.company_id, odoo.session_info.db].join();
}
});
UserMenu.include({
init: function(parent) {
this._super(parent);
var switchCompanyWarning = new SwitchCompanyWarningWidget();
switchCompanyWarning.appendTo('header');
}
});
return SwitchCompanyWarningWidget;
});

26
web_switch_company_warning/static/src/js/switch_company_warning_worker.js

@ -0,0 +1,26 @@
"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) {
var newCtx = e.data;
if (lastCtx && newCtx !== lastCtx) {
con.forEach(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 or database 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