Browse Source
Merge pull request #722 from akretion/10.0-mig-web_switch_company_warning
Merge pull request #722 from akretion/10.0-mig-web_switch_company_warning
[MIG] web_switch_company_warning to 10.0 Migrationpull/810/head
beau sebastien
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 39 deletions
-
9web_switch_company_warning/__manifest__.py
-
42web_switch_company_warning/static/src/js/switch_company_warning.js
-
8web_switch_company_warning/static/src/js/switch_company_warning_worker.js
@ -1,52 +1,46 @@ |
|||||
'use strict'; |
'use strict'; |
||||
|
|
||||
openerp.web_switch_company_warning = function (instance) { |
|
||||
|
|
||||
|
odoo.define('web_switch_company_warning.widget', function (require) { |
||||
|
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
|
//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)
|
//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({ |
|
||||
|
|
||||
|
if (!window.SharedWorker) { |
||||
|
//not supported
|
||||
|
return; |
||||
|
} |
||||
|
var SwitchCompanyWarningWidget = Widget.extend({ |
||||
template:'web_switch_company_warning.warningWidget', |
template:'web_switch_company_warning.warningWidget', |
||||
init: function() { |
init: function() { |
||||
this._super(); |
this._super(); |
||||
|
|
||||
var self = this; |
var self = this; |
||||
|
|
||||
var w = new SharedWorker('/web_switch_company_warning/static/src/js/switch_company_warning_worker.js'); |
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) { |
w.port.addEventListener('message', function (msg) { |
||||
if (msg.data.type !== 'newCtx') |
|
||||
|
if (msg.data.type !== 'newCtx') { |
||||
return; |
return; |
||||
|
|
||||
if(msg.data.newCtx != self.session.company_id) { |
|
||||
self.$el.show(); |
|
||||
} else { |
|
||||
|
} |
||||
|
if(msg.data.newCtx === self.session.company_id) { |
||||
self.$el.hide(); |
self.$el.hide(); |
||||
|
} else { |
||||
|
self.$el.show(); |
||||
} |
} |
||||
}); |
}); |
||||
|
|
||||
w.port.start(); |
w.port.start(); |
||||
w.port.postMessage(this.session.company_id); |
w.port.postMessage(this.session.company_id); |
||||
} |
} |
||||
}); |
}); |
||||
|
|
||||
instance.web.UserMenu = instance.web.UserMenu.extend({ |
|
||||
|
|
||||
|
UserMenu.include({ |
||||
init: function(parent) { |
init: function(parent) { |
||||
this._super(parent); |
this._super(parent); |
||||
|
|
||||
var switchCompanyWarning = new instance.web.SwitchCompanyWarningWidget(); |
|
||||
switchCompanyWarning.insertAfter(instance.webclient.$el.find('#oe_main_menu_navbar')); |
|
||||
|
var switchCompanyWarning = new SwitchCompanyWarningWidget(); |
||||
|
switchCompanyWarning.appendTo('#oe_main_menu_navbar'); |
||||
} |
} |
||||
|
|
||||
}); |
}); |
||||
|
|
||||
}; |
|
||||
|
return SwitchCompanyWarningWidget; |
||||
|
}); |
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue