You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. 'use strict';
  2. odoo.define('web_switch_company_warning.widget', function (require) {
  3. var Widget = require('web.Widget');
  4. var UserMenu = require('web.UserMenu');
  5. //Show a big banner in the top of the page if the company has been
  6. //changed in another tab or window (in the same browser)
  7. if (!window.SharedWorker) {
  8. //not supported
  9. return;
  10. }
  11. var SwitchCompanyWarningWidget = Widget.extend({
  12. template:'web_switch_company_warning.warningWidget',
  13. init: function() {
  14. this._super();
  15. var self = this;
  16. var w = new SharedWorker('/web_switch_company_warning/static/src/js/switch_company_warning_worker.js');
  17. w.port.addEventListener('message', function (msg) {
  18. if (msg.data.type !== 'newCtx') {
  19. return;
  20. }
  21. if(msg.data.newCtx === self.generateSignature()) {
  22. self.$el.hide();
  23. } else {
  24. self.$el.show();
  25. }
  26. });
  27. w.port.start();
  28. w.port.postMessage(this.generateSignature());
  29. },
  30. generateSignature: function() {
  31. return [this.session.company_id, this.session.db].join();
  32. }
  33. });
  34. UserMenu.include({
  35. init: function(parent) {
  36. this._super(parent);
  37. var switchCompanyWarning = new SwitchCompanyWarningWidget();
  38. switchCompanyWarning.appendTo('#oe_main_menu_navbar');
  39. }
  40. });
  41. return SwitchCompanyWarningWidget;
  42. });