From 45c3bba7b037397d5259aaef6a7145ccbd3fb1fb Mon Sep 17 00:00:00 2001 From: hparfr Date: Fri, 25 Sep 2015 14:13:20 +0200 Subject: [PATCH 1/8] [ADD] web_switch_company_warning : display a message saying it's time to reload the page --- web_switch_company_warning/__init__.py | 1 + web_switch_company_warning/__openerp__.py | 23 ++++++ web_switch_company_warning/readme.rst | 74 +++++++++++++++++++ .../src/js/switch_comapny_warning_worker.js | 23 ++++++ .../static/src/js/switch_company_warning.js | 50 +++++++++++++ .../static/src/xml/switch_company_warning.xml | 9 +++ web_switch_company_warning/view/view.xml | 10 +++ 7 files changed, 190 insertions(+) create mode 100644 web_switch_company_warning/__init__.py create mode 100644 web_switch_company_warning/__openerp__.py create mode 100644 web_switch_company_warning/readme.rst create mode 100644 web_switch_company_warning/static/src/js/switch_comapny_warning_worker.js create mode 100644 web_switch_company_warning/static/src/js/switch_company_warning.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/__init__.py b/web_switch_company_warning/__init__.py new file mode 100644 index 00000000..7c68785e --- /dev/null +++ b/web_switch_company_warning/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- \ No newline at end of file diff --git a/web_switch_company_warning/__openerp__.py b/web_switch_company_warning/__openerp__.py new file mode 100644 index 00000000..a2b0595c --- /dev/null +++ b/web_switch_company_warning/__openerp__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# © <2015> +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Multicompany - Switch Company Warning", + "summary": "Shows a warning if current company has been switched in another tab or window." + "version": "0.1", + "category": "web", + "website": "https://github.com/OCA/web/blob/8.0/web_switch_company_warning", + "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_company_warning/readme.rst b/web_switch_company_warning/readme.rst new file mode 100644 index 00000000..f618200e --- /dev/null +++ b/web_switch_company_warning/readme.rst @@ -0,0 +1,74 @@ +.. 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. + + +Configuration +============= + +No configuration. + +Usage +===== + + +* go to ... + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch} + +.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt +.. branch is "8.0" for example + +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/static/src/js/switch_comapny_warning_worker.js b/web_switch_company_warning/static/src/js/switch_comapny_warning_worker.js new file mode 100644 index 00000000..680592d5 --- /dev/null +++ b/web_switch_company_warning/static/src/js/switch_comapny_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) { + 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/js/switch_company_warning.js b/web_switch_company_warning/static/src/js/switch_company_warning.js new file mode 100644 index 00000000..31e1a7ee --- /dev/null +++ b/web_switch_company_warning/static/src/js/switch_company_warning.js @@ -0,0 +1,50 @@ +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/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 @@ + + + + + + From 06a9b7d5ae61440725391c88047683ec139d6fac Mon Sep 17 00:00:00 2001 From: hparfr Date: Tue, 29 Sep 2015 18:22:17 +0200 Subject: [PATCH 2/8] [fix] .rst formatting --- web_switch_company_warning/readme.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_switch_company_warning/readme.rst b/web_switch_company_warning/readme.rst index f618200e..38c0b23d 100644 --- a/web_switch_company_warning/readme.rst +++ b/web_switch_company_warning/readme.rst @@ -2,9 +2,9 @@ :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. From 7d8a2c0abf7ebb425cbc49b2522d3ff656e434df Mon Sep 17 00:00:00 2001 From: hparfr Date: Tue, 29 Sep 2015 18:26:39 +0200 Subject: [PATCH 3/8] [FIX] .rst formating --- web_switch_company_warning/readme.rst | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/web_switch_company_warning/readme.rst b/web_switch_company_warning/readme.rst index 38c0b23d..201e3baf 100644 --- a/web_switch_company_warning/readme.rst +++ b/web_switch_company_warning/readme.rst @@ -2,42 +2,23 @@ :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. - - -Configuration -============= - -No configuration. - -Usage -===== +=========================== -* go to ... - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch} +Shows a warning if current company has been switched in another tab or window. -.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt -.. branch is "8.0" for example 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 =========== From 2ab6a436cc3f58d4c2805fc3901c44903ae1b8c3 Mon Sep 17 00:00:00 2001 From: hparfr Date: Wed, 30 Sep 2015 09:41:05 +0200 Subject: [PATCH 4/8] [FIX] web_switch_company_warning Remove place holders in readme Add "use strict" in js --- web_switch_company_warning/readme.rst | 8 ++++---- .../static/src/js/switch_comapny_warning_worker.js | 3 ++- .../static/src/js/switch_company_warning.js | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/web_switch_company_warning/readme.rst b/web_switch_company_warning/readme.rst index 201e3baf..bdf0b58a 100644 --- a/web_switch_company_warning/readme.rst +++ b/web_switch_company_warning/readme.rst @@ -23,12 +23,12 @@ Bug Tracker =========== Bugs are tracked on `GitHub Issues `_. +web/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 `_. +web/issues/new?body=module:%20 +web_switch_company_warning%0Aversion:%20 +0.1%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. Credits diff --git a/web_switch_company_warning/static/src/js/switch_comapny_warning_worker.js b/web_switch_company_warning/static/src/js/switch_comapny_warning_worker.js index 680592d5..d4b4fbe4 100644 --- a/web_switch_company_warning/static/src/js/switch_comapny_warning_worker.js +++ b/web_switch_company_warning/static/src/js/switch_comapny_warning_worker.js @@ -1,3 +1,4 @@ +"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) @@ -14,7 +15,7 @@ addEventListener("connect", function(ee) { if (lastCtx && newCtx != lastCtx) { con.map(function (eport) { - eport.postMessage({ type: 'newCtx', "newCtx": newCtx, "lastCtx": lastCtx}); + eport.postMessage({ type: "newCtx", "newCtx": newCtx, "lastCtx": lastCtx}); }); } lastCtx = newCtx; 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 31e1a7ee..a49040fc 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,3 +1,5 @@ +'use strict'; + openerp.web_switch_company_warning = function (instance) { //Show a big banner in the top of the page if the company has been From e94c27983e0ebe35dde624ad3740562e7a9bf66b Mon Sep 17 00:00:00 2001 From: hparfr Date: Wed, 30 Sep 2015 09:44:06 +0200 Subject: [PATCH 5/8] [FIX] web_switch_company_warning Rename readme in README --- web_switch_company_warning/{readme.rst => README.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename web_switch_company_warning/{readme.rst => README.rst} (100%) diff --git a/web_switch_company_warning/readme.rst b/web_switch_company_warning/README.rst similarity index 100% rename from web_switch_company_warning/readme.rst rename to web_switch_company_warning/README.rst From a582b8c68ec66eeffa99f9cb34acd73950b20634 Mon Sep 17 00:00:00 2001 From: hparfr Date: Wed, 30 Sep 2015 09:54:08 +0200 Subject: [PATCH 6/8] [FIX] web_switch_company_warning Fix travis build stuff. --- web_switch_company_warning/__init__.py | 2 +- web_switch_company_warning/__openerp__.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/web_switch_company_warning/__init__.py b/web_switch_company_warning/__init__.py index 7c68785e..40a96afc 100644 --- a/web_switch_company_warning/__init__.py +++ b/web_switch_company_warning/__init__.py @@ -1 +1 @@ -# -*- coding: utf-8 -*- \ No newline at end of file +# -*- coding: utf-8 -*- diff --git a/web_switch_company_warning/__openerp__.py b/web_switch_company_warning/__openerp__.py index a2b0595c..609fb32b 100644 --- a/web_switch_company_warning/__openerp__.py +++ b/web_switch_company_warning/__openerp__.py @@ -3,10 +3,11 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Multicompany - Switch Company Warning", - "summary": "Shows a warning if current company has been switched in another tab or window." + "summary": "Show a warning if current company has been switched" + " in another tab or window." "version": "0.1", "category": "web", - "website": "https://github.com/OCA/web/blob/8.0/web_switch_company_warning", + "website": "http://akretion.com", "license": "AGPL-3", "author": "Akretion / Odoo Community Association (OCA)", "depends": [ From 8c2e3090805168e423d598fc47855efb29626156 Mon Sep 17 00:00:00 2001 From: hparfr Date: Wed, 30 Sep 2015 09:56:45 +0200 Subject: [PATCH 7/8] [FIX] web_switch_company_warning Missing , in __openerp_.py --- web_switch_company_warning/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_switch_company_warning/__openerp__.py b/web_switch_company_warning/__openerp__.py index 609fb32b..29ee5179 100644 --- a/web_switch_company_warning/__openerp__.py +++ b/web_switch_company_warning/__openerp__.py @@ -4,7 +4,7 @@ { "name": "Multicompany - Switch Company Warning", "summary": "Show a warning if current company has been switched" - " in another tab or window." + " in another tab or window.", "version": "0.1", "category": "web", "website": "http://akretion.com", From 861ad87e7e15452c98e9d35604b56cb54c4d0a1c Mon Sep 17 00:00:00 2001 From: hparfr Date: Wed, 30 Sep 2015 11:04:49 +0200 Subject: [PATCH 8/8] [FIX] web_switch_company_warning Fix typo in worker file name --- ...comapny_warning_worker.js => switch_company_warning_worker.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename web_switch_company_warning/static/src/js/{switch_comapny_warning_worker.js => switch_company_warning_worker.js} (100%) diff --git a/web_switch_company_warning/static/src/js/switch_comapny_warning_worker.js b/web_switch_company_warning/static/src/js/switch_company_warning_worker.js similarity index 100% rename from web_switch_company_warning/static/src/js/switch_comapny_warning_worker.js rename to web_switch_company_warning/static/src/js/switch_company_warning_worker.js