From 65bf28b57fe2e1629c95c9b4467ba38fdb6794a5 Mon Sep 17 00:00:00 2001 From: hparfr Date: Fri, 25 Sep 2015 14:13:20 +0200 Subject: [PATCH] [ADD] web_switch_company_warning : display a message saying it's time to reload the page [fix] .rst formatting [FIX] web_switch_company_warning Remove place holders in readme Add "use strict" in js [UPD] prefix versions with 8.0 [MIG] Make modules uninstallable [MIG] Rename manifest files --- web_switch_company_warning/README.rst | 55 +++++++++++++++++++ web_switch_company_warning/__init__.py | 1 + web_switch_company_warning/__manifest__.py | 24 ++++++++ .../static/src/js/switch_company_warning.js | 52 ++++++++++++++++++ .../src/js/switch_company_warning_worker.js | 24 ++++++++ .../static/src/xml/switch_company_warning.xml | 9 +++ web_switch_company_warning/view/view.xml | 10 ++++ 7 files changed, 175 insertions(+) create mode 100644 web_switch_company_warning/README.rst create mode 100644 web_switch_company_warning/__init__.py create mode 100644 web_switch_company_warning/__manifest__.py create mode 100644 web_switch_company_warning/static/src/js/switch_company_warning.js create mode 100644 web_switch_company_warning/static/src/js/switch_company_warning_worker.js create mode 100644 web_switch_company_warning/static/src/xml/switch_company_warning.xml create mode 100644 web_switch_company_warning/view/view.xml diff --git a/web_switch_company_warning/README.rst b/web_switch_company_warning/README.rst new file mode 100644 index 00000000..bdf0b58a --- /dev/null +++ b/web_switch_company_warning/README.rst @@ -0,0 +1,55 @@ +.. 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 +=========================== + + +Shows a warning if current company has been switched in another tab or window. + + +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 Wworker(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 `here `_. + + +Credits +======= + +Contributors +------------ + +* Hparfr + +Maintainer +---------- + +.. 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. diff --git a/web_switch_company_warning/__init__.py b/web_switch_company_warning/__init__.py new file mode 100644 index 00000000..40a96afc --- /dev/null +++ b/web_switch_company_warning/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/web_switch_company_warning/__manifest__.py b/web_switch_company_warning/__manifest__.py new file mode 100644 index 00000000..3cda8a1f --- /dev/null +++ b/web_switch_company_warning/__manifest__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# © <2015> +# 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": "8.0.0.1.0", + "category": "web", + "website": "http://akretion.com", + "license": "AGPL-3", + "author": "Akretion / Odoo Community Association (OCA)", + "depends": [ + 'web', + ], + "data": [ + "view/view.xml", + ], + "qweb": [ + "static/src/xml/switch_company_warning.xml", + ], + 'installable': False, + "application": False, +} 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 new file mode 100644 index 00000000..a49040fc --- /dev/null +++ b/web_switch_company_warning/static/src/js/switch_company_warning.js @@ -0,0 +1,52 @@ +'use strict'; + +openerp.web_switch_company_warning = function (instance) { + + //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) + return; //not supported + + instance.web.SwitchCompanyWorker = null; //keep a global reference + + instance.web.SwitchCompanyWarningWidget = instance.web.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'); + instance.web.SwitchCompanyWorker = w; + + w.port.addEventListener('message', function (msg) { + if (msg.data.type !== 'newCtx') + return; + + if(msg.data.newCtx != self.session.company_id) { + self.$el.show(); + } else { + self.$el.hide(); + } + }); + + w.port.start(); + w.port.postMessage(this.session.company_id); + } + }); + + instance.web.UserMenu = instance.web.UserMenu.extend({ + + init: function(parent) { + this._super(parent); + + var switchCompanyWarning = new instance.web.SwitchCompanyWarningWidget(); + switchCompanyWarning.insertAfter(instance.webclient.$el.find('#oe_main_menu_navbar')); + } + + }); + +}; + 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 new file mode 100644 index 00000000..d4b4fbe4 --- /dev/null +++ b/web_switch_company_warning/static/src/js/switch_company_warning_worker.js @@ -0,0 +1,24 @@ +"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) { //addEventListener doesnt seams to work well + var newCtx = e.data; + + if (lastCtx && newCtx != lastCtx) { + con.map(function (eport) { + eport.postMessage({ type: "newCtx", "newCtx": newCtx, "lastCtx": lastCtx}); + }); + } + lastCtx = newCtx; + }; + +}, false); diff --git a/web_switch_company_warning/static/src/xml/switch_company_warning.xml b/web_switch_company_warning/static/src/xml/switch_company_warning.xml new file mode 100644 index 00000000..7943516e --- /dev/null +++ b/web_switch_company_warning/static/src/xml/switch_company_warning.xml @@ -0,0 +1,9 @@ + + \ No newline at end of file diff --git a/web_switch_company_warning/view/view.xml b/web_switch_company_warning/view/view.xml new file mode 100644 index 00000000..793ed8de --- /dev/null +++ b/web_switch_company_warning/view/view.xml @@ -0,0 +1,10 @@ + + + + + +