[FIX] calendar: avoid double popup, opw 606297
authorMartin Trigaux <mat@openerp.com>
Mon, 2 Jun 2014 16:00:25 +0000 (18:00 +0200)
committerMartin Trigaux <mat@openerp.com>
Mon, 2 Jun 2014 16:22:06 +0000 (18:22 +0200)
Some browsers (e.g. chrome) trigger onEmptyClick as well as
onBeforeLightbox during drag&drop which calls two slow_create
calls (and two popups). Workaround to kill the second one.

addons/web_calendar/static/src/js/calendar.js

index f7f08c3..f2cc0f7 100644 (file)
@@ -57,6 +57,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
         this.range_stop = null;
         this.update_range_dates(Date.today());
         this.selected_filters = [];
+        this.is_slow_open = false;
     },
     view_loading: function(r) {
         return this.load_calendar(r);
@@ -465,6 +466,13 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
     },
     slow_create: function(event_id, event_obj) {
         var self = this;
+        // Workaround, some browsers trigger onEmptyClick as well as onBeforeLightbox
+        // during drag&drop which calls two slow_create calls, kills the second one
+        if (this.is_slow_open) {
+            scheduler.deleteEvent(event_id);
+            return;
+        }
+        this.is_slow_open = true;
         if (this.current_mode() === 'month') {
             event_obj['start_date'].addHours(8);
             if (event_obj._length === 1) {
@@ -487,6 +495,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
             view_id: pop_infos.view_id,
         });
         pop.on('closed', self, function() {
+            this.is_slow_open = false;
             if (!something_saved) {
                 scheduler.deleteEvent(event_id);
             }