diff options
| author | Yannick Tivisse <yti@odoo.com> | 2016-02-09 15:43:06 +0100 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2016-02-09 17:40:34 +0100 |
| commit | 7db8f1ca3081b67afb9e31f1d3e65c6a35eec35f (patch) | |
| tree | 199c7135181c2e379f54d18ad94f8256d17d2fba /addons/web/static/src/js | |
| parent | 52193c4953f4108dee5eafef0dd40c1f466946ef (diff) | |
[IMP] web: remove rpc call on SwitchCompany widget loading
By setting the information returned by read_companies on the session
information, we are able to remove the rpc call and the willStart
method definition
Also: Set a debounce on SwitchCompany widget to avoid multiple RPC
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/widgets/switch_company_menu.js | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/addons/web/static/src/js/widgets/switch_company_menu.js b/addons/web/static/src/js/widgets/switch_company_menu.js index 67b3ae57b6c..2879a0a2b0d 100644 --- a/addons/web/static/src/js/widgets/switch_company_menu.js +++ b/addons/web/static/src/js/widgets/switch_company_menu.js @@ -8,39 +8,28 @@ odoo.define('web.SwitchCompanyMenu', function(require) { var SwitchCompanyMenu = Widget.extend({ template: 'SwitchCompanyMenu', - willStart: function(){ - var self = this; - var def = $.Deferred(); - new Model("res.users").call("read_companies").then(function(res) { - if (res){ - self.all_allowed_companies = res.all_allowed_companies; - self.current_company = res.current_company; - def.resolve(); - } else { - def.reject(); - } - }).fail(function(){ - def.reject(); - }); - return $.when(this._super(), def); + willStart: function() { + if (!session.user_companies) { + return $.Deferred().reject(); + } + return this._super(); }, start: function() { var self = this; - - this.$el.on('click', '.dropdown-menu li a[data-menu]', function(ev) { + this.$el.on('click', '.dropdown-menu li a[data-menu]', _.debounce(function(ev) { ev.preventDefault(); var company_id = $(ev.currentTarget).data('company-id'); new Model('res.users').call('write', [[session.uid], {'company_id': company_id}]).then(function() { location.reload(); }); - }); + }, 1500, true)); - self.$('.oe_topbar_name').text(self.current_company[1]); + self.$('.oe_topbar_name').text(session.user_companies.current_company[1]); var companies_list = ''; - _.each(self.all_allowed_companies, function(company) { + _.each(session.user_companies.allowed_companies, function(company) { var a = ''; - if(company[0] == self.current_company[0]) { + if(company[0] == session.user_companies.current_company[0]) { a = '<i class="fa fa-check o_current_company"></i>'; } else { a = '<span class="o_company"/>'; |
