From 6534e2f203b64652876b903623d79d666d2ddf4c Mon Sep 17 00:00:00 2001 From: Mohammed Shekha Date: Mon, 3 Aug 2015 15:52:37 +0530 Subject: [PATCH] [FIX] web_calendar: Destroy m2o when events are reloaded when mode is switched m2o should be reinitialized, and old instance of field manager should be destroyed otherwise it will through traceback 'cannot call methods on autocomplete prior to initialization', also improved the reload_favorite_list, it should be called when calendar.contacts record is created --- .../calendar/static/src/js/base_calendar.js | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/addons/calendar/static/src/js/base_calendar.js b/addons/calendar/static/src/js/base_calendar.js index 8021d0e5914..aff3e31da7d 100644 --- a/addons/calendar/static/src/js/base_calendar.js +++ b/addons/calendar/static/src/js/base_calendar.js @@ -86,10 +86,24 @@ CalendarView.include({ }); widgets.SidebarFilter.include({ + events_loaded: function() { + this._super.apply(this, arguments); + this.reinitialize_m2o(); + }, add_favorite_calendar: function() { - var self = this; if (this.dfm) return; + this.initialize_m2o(); + }, + reinitialize_m2o: function() { + if (this.dfm) { + this.dfm.destroy(); + this.dfm = undefined; + } + this.initialize_m2o(); + }, + initialize_m2o: function() { + var self = this; this.dfm = new form_common.DefaultFieldManager(self); this.dfm.extend_field_desc({ partner_id: { @@ -113,6 +127,7 @@ widgets.SidebarFilter.include({ }, add_filter: function() { var self = this; + var defs = []; new Model("res.users") .query(["partner_id"]) .filter([["id", "=",this.view.dataset.context.uid]]) @@ -121,11 +136,13 @@ widgets.SidebarFilter.include({ $.map(self.ir_model_m2o.display_value, function(element,index) { if (result.partner_id[0] != index){ self.ds_message = new data.DataSetSearch(self, 'calendar.contacts'); - self.ds_message.call("create", [{'partner_id': index}]); + defs.push(self.ds_message.call("create", [{'partner_id': index}])); } }); }); - reload_favorite_list(this); + $.when.apply(null, defs).done(function() { + reload_favorite_list(self); + }); }, destroy_filter: function(e) { var self = this;