From 4b0a8d4096be411b1516f8f89ea3d9950b167cf0 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 10 Mar 2015 17:22:35 +0100 Subject: [PATCH] [IMP] Web, web_calendar: push_state rendering logic When a new state is rendered, it is now first appended to a documentFragment, and then appended to the DOM when ready. Doing so, there is no more a intermediate step where two widgets are in the DOM, the new one being appended below. This required a web_calendar fix: Not exactly fixed per-se, apparently when fullcalendar is rendered hidden/out of document it doesn't generate correct range dates, and calls the events callback with invalid dates. The code would blindly take those invalid date, get bits out of them (NaN), generate a timestamp full of NaNs and blindly search() the table with that. Just skip the events callback entirely if the start or end date of the current period is invalid (~isNaN(date.valueOf())). --- addons/web/static/src/js/action_manager.js | 9 +++++++-- addons/web_calendar/static/src/js/web_calendar.js | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/action_manager.js b/addons/web/static/src/js/action_manager.js index d1aa1fe3d06..de0f17691f3 100644 --- a/addons/web/static/src/js/action_manager.js +++ b/addons/web/static/src/js/action_manager.js @@ -203,8 +203,13 @@ var ActionManager = Widget.extend({ this.inner_action = new_action; this.inner_widget = widget; - // Append the inner_widget and hide the old one - return $.when(this.inner_widget.appendTo(this.$el)).done(function () { + // render the inner_widget in a fragment, and append it to the + // document only when it's ready + var new_widget_fragment = document.createDocumentFragment(); + return $.when(this.inner_widget.appendTo(new_widget_fragment)).done(function() { + self.$el.append(new_widget_fragment); + // Hide the old_widget as it will be removed from the DOM when it + // is destroyed if (old_widget) { old_widget.$el.hide(); } diff --git a/addons/web_calendar/static/src/js/web_calendar.js b/addons/web_calendar/static/src/js/web_calendar.js index 60597a32bfb..578826ccdeb 100644 --- a/addons/web_calendar/static/src/js/web_calendar.js +++ b/addons/web_calendar/static/src/js/web_calendar.js @@ -688,6 +688,12 @@ var CalendarView = View.extend({ } this.event_source = { events: function(start, end, callback) { + // catch invalid dates (start/end dates not parseable yet) + // => ignore request + if (isNaN(start) || isNaN(end)) { + return; + } + var current_event_source = self.event_source; self.dataset.read_slice(_.keys(self.fields), { offset: 0,