diff --git a/setup/web_switch_context_warning/odoo/addons/web_switch_context_warning b/setup/web_switch_context_warning/odoo/addons/web_switch_context_warning new file mode 120000 index 000000000..f253d8443 --- /dev/null +++ b/setup/web_switch_context_warning/odoo/addons/web_switch_context_warning @@ -0,0 +1 @@ +../../../../web_switch_context_warning \ No newline at end of file diff --git a/setup/web_switch_context_warning/setup.py b/setup/web_switch_context_warning/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_switch_context_warning/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_switch_context_warning/README.rst b/web_switch_context_warning/README.rst new file mode 100644 index 000000000..c27c58a85 --- /dev/null +++ b/web_switch_context_warning/README.rst @@ -0,0 +1,81 @@ +====================== +Switch Context Warning +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/12.0/web_switch_context_warning + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_switch_context_warning + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Shows a warning if current user, company or database have been switched in another tab or window. + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + + * If the browser don't implement Shared 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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Hparfr +* Adria Gil Sorribes + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_switch_context_warning/__init__.py b/web_switch_context_warning/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/web_switch_context_warning/__manifest__.py b/web_switch_context_warning/__manifest__.py new file mode 100644 index 000000000..15c9eaf87 --- /dev/null +++ b/web_switch_context_warning/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2017 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Switch Context Warning", + "summary": "Show a warning if current user, company or database " + "have been switched in another tab or window.", + "version": "14.0.1.0.0", + "category": "web", + "website": "https://github.com/OCA/web", + "license": "AGPL-3", + "author": "Akretion, " "Odoo Community Association (OCA)", + "depends": ["web"], + "data": ["view/view.xml"], + "qweb": ["static/src/xml/switch_context_warning.xml"], + "installable": True, + "application": False, +} diff --git a/web_switch_context_warning/i18n/fr.po b/web_switch_context_warning/i18n/fr.po new file mode 100644 index 000000000..a1406f294 --- /dev/null +++ b/web_switch_context_warning/i18n/fr.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_switch_context_warning +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-01-22 11:13+0000\n" +"Last-Translator: Martronic SA \n" +"Language-Team: none\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 3.10\n" + +#. module: web_switch_context_warning +#. openerp-web +#: code:addons/web_switch_context_warning/static/src/xml/switch_context_warning.xml:6 +#, python-format +msgid "Reload" +msgstr "Recharger" + +#. module: web_switch_context_warning +#. openerp-web +#: code:addons/web_switch_context_warning/static/src/xml/switch_context_warning.xml:5 +#, python-format +msgid "You switched to a different user, company or database with another tab or window" +msgstr "" +"Vous avez changé d'utilisateur, de société ou de base de donnes dans un " +"autre onglet ou fenêtre" + +#. module: web_switch_context_warning +#. openerp-web +#: code:addons/web_switch_context_warning/static/src/xml/switch_context_warning.xml:6 +#, python-format +msgid "to refresh your session" +msgstr "pour rafraîchir votre session" diff --git a/web_switch_context_warning/i18n/web_switch_company_warning.pot b/web_switch_context_warning/i18n/web_switch_company_warning.pot new file mode 100644 index 000000000..ccf2d1b51 --- /dev/null +++ b/web_switch_context_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 10.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 "" + diff --git a/web_switch_context_warning/i18n/web_switch_context_warning.pot b/web_switch_context_warning/i18n/web_switch_context_warning.pot new file mode 100644 index 000000000..6eb3b72fe --- /dev/null +++ b/web_switch_context_warning/i18n/web_switch_context_warning.pot @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_switch_context_warning +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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_context_warning +#. openerp-web +#: code:addons/web_switch_context_warning/static/src/xml/switch_context_warning.xml:6 +#, python-format +msgid "Reload" +msgstr "" + +#. module: web_switch_context_warning +#. openerp-web +#: code:addons/web_switch_context_warning/static/src/xml/switch_context_warning.xml:5 +#, python-format +msgid "You switched to a different user, company or database with another tab or window" +msgstr "" + +#. module: web_switch_context_warning +#. openerp-web +#: code:addons/web_switch_context_warning/static/src/xml/switch_context_warning.xml:6 +#, python-format +msgid "to refresh your session" +msgstr "" + diff --git a/web_switch_context_warning/i18n/zh_CN.po b/web_switch_context_warning/i18n/zh_CN.po new file mode 100644 index 000000000..aeca01528 --- /dev/null +++ b/web_switch_context_warning/i18n/zh_CN.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_switch_context_warning +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-09-01 12:52+0000\n" +"Last-Translator: 黎伟杰 <674416404@qq.com>\n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 3.8\n" + +#. module: web_switch_context_warning +#. openerp-web +#: code:addons/web_switch_context_warning/static/src/xml/switch_context_warning.xml:6 +#, python-format +msgid "Reload" +msgstr "刷新" + +#. module: web_switch_context_warning +#. openerp-web +#: code:addons/web_switch_context_warning/static/src/xml/switch_context_warning.xml:5 +#, python-format +msgid "You switched to a different user, company or database with another tab or window" +msgstr "您使用其他选项卡或窗口切换到其他用户,公司或数据库" + +#. module: web_switch_context_warning +#. openerp-web +#: code:addons/web_switch_context_warning/static/src/xml/switch_context_warning.xml:6 +#, python-format +msgid "to refresh your session" +msgstr "刷新你的会话" diff --git a/web_switch_context_warning/readme/CONTRIBUTORS.rst b/web_switch_context_warning/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..885eef112 --- /dev/null +++ b/web_switch_context_warning/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Hparfr +* Adria Gil Sorribes +* Helly kapatel diff --git a/web_switch_context_warning/readme/DESCRIPTION.rst b/web_switch_context_warning/readme/DESCRIPTION.rst new file mode 100644 index 000000000..8049cca37 --- /dev/null +++ b/web_switch_context_warning/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +In Odoo 14 possible to work in different tabs with different companies, now the module only shows a warning when the user or database has been switched. diff --git a/web_switch_context_warning/readme/ROADMAP.rst b/web_switch_context_warning/readme/ROADMAP.rst new file mode 100644 index 000000000..d3b5cc0de --- /dev/null +++ b/web_switch_context_warning/readme/ROADMAP.rst @@ -0,0 +1,3 @@ + * If the browser don't implement Shared Worker (http://www.w3.org/TR/workers/#sharedworker), the warning message will not be displayed (there is no polyfill). + + * Switching user or database 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...) diff --git a/web_switch_context_warning/readme/USAGE.rst b/web_switch_context_warning/readme/USAGE.rst new file mode 100644 index 000000000..e69de29bb diff --git a/web_switch_context_warning/static/description/icon.png b/web_switch_context_warning/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/web_switch_context_warning/static/description/icon.png differ diff --git a/web_switch_context_warning/static/description/index.html b/web_switch_context_warning/static/description/index.html new file mode 100644 index 000000000..2ad35e6e2 --- /dev/null +++ b/web_switch_context_warning/static/description/index.html @@ -0,0 +1,430 @@ + + + + + + +Switch Context Warning + + + +
+

Switch Context Warning

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

Shows a warning if current user, company or database have been switched in another tab or window.

+

Table of contents

+ +
+

Known issues / Roadmap

+
+
    +
  • If the browser don’t implement Shared 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. +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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_switch_context_warning/static/src/js/switch_context_warning.js b/web_switch_context_warning/static/src/js/switch_context_warning.js new file mode 100644 index 000000000..80533b070 --- /dev/null +++ b/web_switch_context_warning/static/src/js/switch_context_warning.js @@ -0,0 +1,49 @@ +odoo.define("web_switch_context_warning.widget", function (require) { + "use strict"; + + var Widget = require("web.Widget"); + var UserMenu = require("web.UserMenu"); + var session = require("web.session"); + // Show a big banner in the top of the page if the context has been + // changed in another tab or window (in the same browser) + + if (!window.SharedWorker) { + // Not supported + return; + } + var SwitchContextWarningWidget = 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_context_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 [session.uid, session.db].join(); + }, + }); + + UserMenu.include({ + init: function (parent) { + this._super(parent); + var switchContextWarning = new SwitchContextWarningWidget(); + switchContextWarning.insertAfter(".o_main_navbar"); + }, + }); + + return SwitchContextWarningWidget; +}); diff --git a/web_switch_context_warning/static/src/js/switch_context_warning_worker.js b/web_switch_context_warning/static/src/js/switch_context_warning_worker.js new file mode 100644 index 000000000..7c9d1446f --- /dev/null +++ b/web_switch_context_warning/static/src/js/switch_context_warning_worker.js @@ -0,0 +1,31 @@ +// Show a big banner in the top of the page if the context 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 +); diff --git a/web_switch_context_warning/static/src/xml/switch_context_warning.xml b/web_switch_context_warning/static/src/xml/switch_context_warning.xml new file mode 100644 index 000000000..bca952dfb --- /dev/null +++ b/web_switch_context_warning/static/src/xml/switch_context_warning.xml @@ -0,0 +1,16 @@ + + diff --git a/web_switch_context_warning/view/view.xml b/web_switch_context_warning/view/view.xml new file mode 100644 index 000000000..35c5714bc --- /dev/null +++ b/web_switch_context_warning/view/view.xml @@ -0,0 +1,17 @@ + + + +