diff --git a/web_switch_context_warning/README.rst b/web_switch_context_warning/README.rst new file mode 100644 index 00000000..78258d6c --- /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/11.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-11-0/web-11-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/11.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 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 `_. +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 00000000..e69de29b diff --git a/web_switch_context_warning/__manifest__.py b/web_switch_context_warning/__manifest__.py new file mode 100644 index 00000000..e405f8f9 --- /dev/null +++ b/web_switch_context_warning/__manifest__.py @@ -0,0 +1,24 @@ +# 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": "11.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_company_warning.xml", + ], + 'installable': True, + "application": False, +} 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 00000000..ed79158e --- /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_context_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_context_warning +#. openerp-web +#: code:addons/web_switch_context_warning/static/src/xml/switch_company_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_company_warning.xml:5 +#, python-format +msgid "You switched to a different 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_company_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 00000000..0e095736 --- /dev/null +++ b/web_switch_context_warning/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Hparfr +* Adria Gil Sorribes diff --git a/web_switch_context_warning/readme/DESCRIPTION.rst b/web_switch_context_warning/readme/DESCRIPTION.rst new file mode 100644 index 00000000..166b67eb --- /dev/null +++ b/web_switch_context_warning/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Shows a warning if current user, company or database have been switched in another tab or window. diff --git a/web_switch_context_warning/readme/ROADMAP.rst b/web_switch_context_warning/readme/ROADMAP.rst new file mode 100644 index 00000000..cbb4925b --- /dev/null +++ b/web_switch_context_warning/readme/ROADMAP.rst @@ -0,0 +1,3 @@ + * 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...) diff --git a/web_switch_context_warning/readme/USAGE.rst b/web_switch_context_warning/readme/USAGE.rst new file mode 100644 index 00000000..e69de29b 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 00000000..3a0328b5 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 00000000..529d70c6 --- /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 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. +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_company_warning.js b/web_switch_context_warning/static/src/js/switch_company_warning.js new file mode 100644 index 00000000..49b505ca --- /dev/null +++ b/web_switch_context_warning/static/src/js/switch_company_warning.js @@ -0,0 +1,61 @@ +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 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 () { + console.log(session) + return [session.uid, session.company_id, 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; +}); + diff --git a/web_switch_context_warning/static/src/js/switch_company_warning_worker.js b/web_switch_context_warning/static/src/js/switch_company_warning_worker.js new file mode 100644 index 00000000..dd8a0860 --- /dev/null +++ b/web_switch_context_warning/static/src/js/switch_company_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) { + "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_company_warning.xml b/web_switch_context_warning/static/src/xml/switch_company_warning.xml new file mode 100644 index 00000000..28b6b6c3 --- /dev/null +++ b/web_switch_context_warning/static/src/xml/switch_company_warning.xml @@ -0,0 +1,9 @@ + + diff --git a/web_switch_context_warning/view/view.xml b/web_switch_context_warning/view/view.xml new file mode 100644 index 00000000..3e34ab1b --- /dev/null +++ b/web_switch_context_warning/view/view.xml @@ -0,0 +1,10 @@ + + + + + +