Browse Source

Add detection of switching database

[UPD] Update web_switch_company_warning.pot
pull/1289/head
hparfr 6 years ago
committed by Adrià Gil Sorribes
parent
commit
fb0744c1f0
  1. 2
      web_switch_company_warning/README.rst
  2. 2
      web_switch_company_warning/__manifest__.py
  3. 2
      web_switch_company_warning/i18n/web_switch_company_warning.pot
  4. 8
      web_switch_company_warning/static/src/js/switch_company_warning.js
  5. 2
      web_switch_company_warning/static/src/xml/switch_company_warning.xml

2
web_switch_company_warning/README.rst

@ -16,7 +16,7 @@ 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). * 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...)
* 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 Bug Tracker

2
web_switch_company_warning/__manifest__.py

@ -5,7 +5,7 @@
"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": "10.0.0.1.0",
"version": "10.0.0.1.1",
"category": "web", "category": "web",
"website": "http://akretion.com", "website": "http://akretion.com",
"license": "AGPL-3", "license": "AGPL-3",

2
web_switch_company_warning/i18n/web_switch_company_warning.pot

@ -24,7 +24,7 @@ msgstr ""
#. openerp-web #. openerp-web
#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:5 #: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:5
#, python-format #, python-format
msgid "You switched to a different company with another tab or window"
msgid "You switched to a different company or database with another tab or window"
msgstr "" msgstr ""
#. module: web_switch_company_warning #. module: web_switch_company_warning

8
web_switch_company_warning/static/src/js/switch_company_warning.js

@ -16,19 +16,21 @@ odoo.define('web_switch_company_warning.widget', function (require) {
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');
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.generateSignature()) {
self.$el.hide(); self.$el.hide();
} else { } else {
self.$el.show(); self.$el.show();
} }
}); });
w.port.start(); w.port.start();
w.port.postMessage(this.session.company_id);
w.port.postMessage(this.generateSignature());
},
generateSignature: function() {
return [this.session.company_id, this.session.db].join();
} }
}); });

2
web_switch_company_warning/static/src/xml/switch_company_warning.xml

@ -2,7 +2,7 @@
<template> <template>
<t t-name="web_switch_company_warning.warningWidget"> <t t-name="web_switch_company_warning.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 or database 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>
</div> </div>
</t> </t>

Loading…
Cancel
Save