From 48ccea132fae11540fe2e16e83ee37a9cb5fdaa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Gil=20Sorribes?= Date: Fri, 24 May 2019 14:02:18 +0200 Subject: [PATCH] [11.0][MIG] web_switch_company_warning module --- web_switch_company_warning/README.rst | 69 ++- web_switch_company_warning/__init__.py | 1 - web_switch_company_warning/__manifest__.py | 5 +- .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + web_switch_company_warning/readme/ROADMAP.rst | 3 + web_switch_company_warning/readme/USAGE.rst | 0 .../static/description/index.html | 429 ++++++++++++++++++ .../static/src/js/switch_company_warning.js | 39 +- .../src/js/switch_company_warning_worker.js | 9 +- 10 files changed, 511 insertions(+), 46 deletions(-) create mode 100644 web_switch_company_warning/readme/CONTRIBUTORS.rst create mode 100644 web_switch_company_warning/readme/DESCRIPTION.rst create mode 100644 web_switch_company_warning/readme/ROADMAP.rst create mode 100644 web_switch_company_warning/readme/USAGE.rst create mode 100644 web_switch_company_warning/static/description/index.html diff --git a/web_switch_company_warning/README.rst b/web_switch_company_warning/README.rst index cdfc5d4b..e51ab70d 100644 --- a/web_switch_company_warning/README.rst +++ b/web_switch_company_warning/README.rst @@ -1,55 +1,80 @@ -.. 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 -=========================== - +===================================== +Multicompany - Switch Company 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_company_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_company_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 company has 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 `_. +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 `here `_. +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 -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. 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. +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_company_warning/__init__.py b/web_switch_company_warning/__init__.py index 40a96afc..e69de29b 100644 --- a/web_switch_company_warning/__init__.py +++ b/web_switch_company_warning/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/web_switch_company_warning/__manifest__.py b/web_switch_company_warning/__manifest__.py index ebeb21f6..b62fab79 100644 --- a/web_switch_company_warning/__manifest__.py +++ b/web_switch_company_warning/__manifest__.py @@ -1,13 +1,12 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Akretion # 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.2", + "version": "11.0.1.0.0", "category": "web", - "website": "http://akretion.com", + "website": "https://github.com/OCA/web", "license": "AGPL-3", "author": "Akretion, " "Odoo Community Association (OCA)", diff --git a/web_switch_company_warning/readme/CONTRIBUTORS.rst b/web_switch_company_warning/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..6d47ddbd --- /dev/null +++ b/web_switch_company_warning/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Hparfr diff --git a/web_switch_company_warning/readme/DESCRIPTION.rst b/web_switch_company_warning/readme/DESCRIPTION.rst new file mode 100644 index 00000000..907bca11 --- /dev/null +++ b/web_switch_company_warning/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Shows a warning if current company has been switched in another tab or window. diff --git a/web_switch_company_warning/readme/ROADMAP.rst b/web_switch_company_warning/readme/ROADMAP.rst new file mode 100644 index 00000000..cbb4925b --- /dev/null +++ b/web_switch_company_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_company_warning/readme/USAGE.rst b/web_switch_company_warning/readme/USAGE.rst new file mode 100644 index 00000000..e69de29b diff --git a/web_switch_company_warning/static/description/index.html b/web_switch_company_warning/static/description/index.html new file mode 100644 index 00000000..250fbdd5 --- /dev/null +++ b/web_switch_company_warning/static/description/index.html @@ -0,0 +1,429 @@ + + + + + + +Multicompany - Switch Company Warning + + + +
+

Multicompany - Switch Company Warning

+ + +

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

+

Shows a warning if current company has 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
  • +
+
+ +
+

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_company_warning/static/src/js/switch_company_warning.js b/web_switch_company_warning/static/src/js/switch_company_warning.js index 7ef73984..9327b56b 100644 --- a/web_switch_company_warning/static/src/js/switch_company_warning.js +++ b/web_switch_company_warning/static/src/js/switch_company_warning.js @@ -1,18 +1,19 @@ -'use strict'; - 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) + 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 + // Not supported return; } var SwitchCompanyWarningWidget = Widget.extend({ template:'web_switch_company_warning.warningWidget', - init: function() { + init: function () { this._super(); var self = this; var w = new SharedWorker('/web_switch_company_warning/static/src/js/switch_company_warning_worker.js'); @@ -20,7 +21,7 @@ odoo.define('web_switch_company_warning.widget', function (require) { if (msg.data.type !== 'newCtx') { return; } - if(msg.data.newCtx === self.generateSignature()) { + if (msg.data.newCtx === self.generateSignature()) { self.$el.hide(); } else { self.$el.show(); @@ -29,22 +30,28 @@ odoo.define('web_switch_company_warning.widget', function (require) { w.port.start(); w.port.postMessage(this.generateSignature()); }, - generateSignature: function() { - return [this.session.company_id, this.session.db].join(); - } + generateSignature: function () { + return [session.company_id, session.db].join(); + }, }); UserMenu.include({ - init: function(parent) { + init: function (parent) { this._super(parent); var switchCompanyWarning = new SwitchCompanyWarningWidget(); - // 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'); + // Check if Odoo version is Enterprise + var isEnterprise = odoo.session_info.server_version_info[5] === 'e'; + if (isEnterprise) { + switchCompanyWarning.insertAfter('.o_main_navbar'); } else { - switchCompanyWarning.insertAfter('.main-nav'); + // 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'); + } } - } + }, }); diff --git a/web_switch_company_warning/static/src/js/switch_company_warning_worker.js b/web_switch_company_warning/static/src/js/switch_company_warning_worker.js index f5f23add..dd8a0860 100644 --- a/web_switch_company_warning/static/src/js/switch_company_warning_worker.js +++ b/web_switch_company_warning/static/src/js/switch_company_warning_worker.js @@ -1,11 +1,12 @@ -"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) +// 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) { +addEventListener("connect", function (ee) { + "use strict"; + var port = ee.ports[0]; con.push(port);