Browse Source

Merge 5610f1b1e3 into ad79aa45cf

pull/1287/merge
Adria Gil Sorribes 5 years ago
committed by GitHub
parent
commit
5e6ae64f29
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      setup/_metapackage/setup.py
  2. 48
      web_switch_company_warning/static/src/js/switch_company_warning.js
  3. 22
      web_switch_company_warning/static/src/js/switch_company_warning_worker.js
  4. 11
      web_switch_context_warning/README.rst
  5. 0
      web_switch_context_warning/__init__.py
  6. 12
      web_switch_context_warning/__manifest__.py
  7. 16
      web_switch_context_warning/i18n/web_switch_context_warning.pot
  8. 0
      web_switch_context_warning/static/description/icon.png
  9. 59
      web_switch_context_warning/static/src/js/switch_context_warning.js
  10. 26
      web_switch_context_warning/static/src/js/switch_context_warning_worker.js
  11. 4
      web_switch_context_warning/static/src/xml/switch_company_warning.xml
  12. 4
      web_switch_context_warning/view/view.xml

2
setup/_metapackage/setup.py

@ -43,7 +43,7 @@ setuptools.setup(
'odoo10-addon-web_send_message_popup',
'odoo10-addon-web_sheet_full_width',
'odoo10-addon-web_shortcut',
'odoo10-addon-web_switch_company_warning',
'odoo10-addon-web_switch_context_warning',
'odoo10-addon-web_timeline',
'odoo10-addon-web_translate_dialog',
'odoo10-addon-web_tree_dynamic_colored_field',

48
web_switch_company_warning/static/src/js/switch_company_warning.js

@ -1,48 +0,0 @@
'use strict';
odoo.define('web_switch_company_warning.widget', function (require) {
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() {
this._super();
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 [this.session.company_id, this.session.db].join();
}
});
UserMenu.include({
init: function(parent) {
this._super(parent);
var switchCompanyWarning = new SwitchCompanyWarningWidget();
switchCompanyWarning.appendTo('#oe_main_menu_navbar');
}
});
return SwitchCompanyWarningWidget;
});

22
web_switch_company_warning/static/src/js/switch_company_warning_worker.js

@ -1,22 +0,0 @@
"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);

11
web_switch_company_warning/README.rst → web_switch_context_warning/README.rst

@ -2,12 +2,13 @@
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
===========================
Web Switch Company Warning
===========================
==========================
Web Switch Context Warning
==========================
Shows a warning if current company has been switched in another tab or window.
Shows a warning if current user, company or database have been switched
in another tab or window.
Known issues / Roadmap
@ -16,7 +17,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).
* 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...)
* Switching user, database or 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

0
web_switch_company_warning/__init__.py → web_switch_context_warning/__init__.py

12
web_switch_company_warning/__manifest__.py → web_switch_context_warning/__manifest__.py

@ -2,12 +2,12 @@
# 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": "10.0.0.1.1",
"name": "Switch Context Warning",
"summary": "Show a warning if current user, company or database"
" have been switched in another tab or window.",
"version": "10.0.1.2.0",
"category": "web",
"website": "http://akretion.com",
"website": "https://github.com/OCA/web",
"license": "AGPL-3",
"author": "Akretion, "
"Odoo Community Association (OCA)",
@ -18,7 +18,7 @@
"view/view.xml",
],
"qweb": [
"static/src/xml/switch_company_warning.xml",
"static/src/xml/switch_context_warning.xml",
],
'installable': True,
"application": False,

16
web_switch_company_warning/i18n/web_switch_company_warning.pot → web_switch_context_warning/i18n/web_switch_context_warning.pot

@ -1,6 +1,6 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_switch_company_warning
# * web_switch_context_warning
#
msgid ""
msgstr ""
@ -13,23 +13,23 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: web_switch_company_warning
#. module: web_switch_context_warning
#. openerp-web
#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:6
#: code:addons/web_switch_context_warning/static/src/xml/switch_company_warning.xml:6
#, python-format
msgid "Reload"
msgstr ""
#. module: web_switch_company_warning
#. module: web_switch_context_warning
#. openerp-web
#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:5
#: code:addons/web_switch_context_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"
msgid "You switched to a different user, company or database with another tab or window"
msgstr ""
#. module: web_switch_company_warning
#. module: web_switch_context_warning
#. openerp-web
#: code:addons/web_switch_company_warning/static/src/xml/switch_company_warning.xml:6
#: code:addons/web_switch_context_warning/static/src/xml/switch_company_warning.xml:6
#, python-format
msgid "to refresh your session"
msgstr ""

0
web_switch_company_warning/static/description/icon.png → web_switch_context_warning/static/description/icon.png

Before

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

After

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

59
web_switch_context_warning/static/src/js/switch_context_warning.js

@ -0,0 +1,59 @@
odoo.define('web_switch_context_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_context_warning.warningWidget',
init: function () {
this._super();
var self = this;
var w = new SharedWorker('/web_switch_context_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 [this.session.uid, this.session.company_id, this.session.db].join();
},
});
UserMenu.include({
init: function(parent) {
this._super(parent);
var switchCompanyWarning = new SwitchCompanyWarningWidget();
// Check if Odoo version is Enterprise
var isEnterprise = odoo.session_info.server_version_info[5] === 'e';
if (isEnterprise) {
switchCompanyWarning.insertAfter('.o_main_navbar');
} else {
// Choose where to append depending on whether web_responsive is installed or not
if (document.getElementById('oe_main_menu_navbar')) {
switchCompanyWarning.appendTo('#oe_main_menu_navbar');
} else {
switchCompanyWarning.insertAfter('.main-nav');
}
}
}
});
return SwitchCompanyWarningWidget;
});

26
web_switch_context_warning/static/src/js/switch_context_warning_worker.js

@ -0,0 +1,26 @@
// 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) {
"use strict";
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);

4
web_switch_company_warning/static/src/xml/switch_company_warning.xml → web_switch_context_warning/static/src/xml/switch_company_warning.xml

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<t t-name="web_switch_company_warning.warningWidget">
<t t-name="web_switch_context_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>
<h3>You switched to a different user, 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>

4
web_switch_company_warning/view/view.xml → web_switch_context_warning/view/view.xml

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template id="assets_backend" name="web_switch_company_warning assets" inherit_id="web.assets_backend">
<template id="assets_backend" name="web_switch_context_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>
<script type="text/javascript" src="/web_switch_context_warning/static/src/js/switch_context_warning.js"></script>
</xpath>
</template>
</data>
Loading…
Cancel
Save