~openerp-dev/openerp-web/trunk-widget-blockreason-mba

« back to all changes in this revision

Viewing changes to addons/web_calendar/static/src/js/web_calendar.js

  • Committer: Mahendra Barad(OpenERP)
  • Date: 2014-02-28 13:19:07 UTC
  • mfrom: (3910.1.40 trunk)
  • Revision ID: mba@tinyerp.com-20140228131907-byupoh7m80vbw5yl
[Merge]with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
_.str.toBoolElse = function(str, elseValues, trueValues, falseValues) {
6
6
      var ret = _.str.toBool(str, trueValues, falseValues);
7
7
      if (_.isUndefined(ret)) {
8
 
        return elseValues
 
8
        return elseValues;
9
9
      }
10
 
      return ret
 
10
      return ret;
11
11
};
12
12
 
13
13
openerp.web_calendar = function(instance) {
37
37
    }
38
38
 
39
39
    function isNullOrUndef(value) {
40
 
        return _.isUndefined(value) || _.isNull(value)
 
40
        return _.isUndefined(value) || _.isNull(value);
41
41
    }
42
42
    
43
43
    instance.web.views.add('calendar', 'instance.web_calendar.CalendarView');
60
60
            this.range_start = null;
61
61
            this.range_stop = null;
62
62
            this.selected_filters = [];
63
 
                        
64
63
        },
65
64
 
66
65
        set_default_options: function(options) {
72
71
 
73
72
        destroy: function() {
74
73
            this.$calendar.fullCalendar('destroy');
75
 
            this.$small_calendar.datepicker('destroy');
 
74
            if (this.$small_calendar){
 
75
                this.$small_calendar.datepicker('destroy');
 
76
            }
76
77
            this._super.apply(this, arguments);
77
78
        },
78
79
 
112
113
            this.date_start = attrs.date_start;     // Field name of starting date field
113
114
            this.date_delay = attrs.date_delay;     // duration
114
115
            this.date_stop = attrs.date_stop;
115
 
            this.all_day = attrs.all_day; 
116
 
            this.attendee_people = attrs.attendee;  
 
116
            this.all_day = attrs.all_day;
117
117
            this.how_display_event = '';
118
 
           
 
118
            this.attendee_people = attrs.attendee;
 
119
 
119
120
            if (!isNullOrUndef(attrs.quick_create_instance)) {
120
 
                self.quick_create_instance = 'instance.' + attrs.quick_create_instance;                
 
121
                self.quick_create_instance = 'instance.' + attrs.quick_create_instance;
121
122
            }
122
123
                
123
124
            //if quick_add = False, we don't allow quick_add
124
125
            //if quick_add = not specified in view, we use the default quick_create_instance
125
126
            //if quick_add = is NOT False and IS specified in view, we this one for quick_create_instance'   
126
127
            
127
 
            this.quick_add_pop = (isNullOrUndef(attrs.quick_add) || _.str.toBoolElse(attrs.quick_add,true) );            
 
128
            this.quick_add_pop = (isNullOrUndef(attrs.quick_add) || _.str.toBoolElse(attrs.quick_add,true) );
128
129
            if (this.quick_add_pop && !isNullOrUndef(attrs.quick_add)) {
129
 
                self.quick_create_instance = 'instance.' + attrs.quick_add;                
 
130
                self.quick_create_instance = 'instance.' + attrs.quick_add;
130
131
            }
131
132
            // The display format which will be used to display the event where fields are between "[" and "]"
132
133
            if (!isNullOrUndef(attrs.display)) {
135
136
            
136
137
            // If this field is set ot true, we don't open the event in form view, but in a popup with the view_id passed by this parameter
137
138
            if (isNullOrUndef(attrs.event_open_popup) || !_.str.toBoolElse(attrs.event_open_popup,true)) {
138
 
                this.open_popup_action = false; 
 
139
                this.open_popup_action = false;
139
140
            }
140
141
            else {
141
142
                this.open_popup_action = attrs.event_open_popup;
142
143
            }
143
144
            
144
 
            // If this field is set to true, we will use de calendar_friends model as filter and not the color field.
145
 
            this.useContacts = (!isNullOrUndef(attrs.use_contacts) && _.str.toBool(attrs.use_contacts)); 
 
145
 
 
146
            // If this field is set to true, we will use the calendar_friends model as filter and not the color field.
 
147
            this.useContacts = (!isNullOrUndef(attrs.use_contacts) && _.str.toBool(attrs.use_contacts)) && (!isNullOrUndef(self.options.$sidebar));
146
148
 
147
149
            // If this field is set ot true, we don't add itself as an attendee when we use attendee_people to add each attendee icon on an event
148
150
            // The color is the color of the attendee, so don't need to show again that it will be present
149
 
            this.colorIsAttendee = (!(isNullOrUndef(attrs.color_is_attendee) || !_.str.toBoolElse(attrs.color_is_attendee,true))); 
 
151
            this.colorIsAttendee = (!(isNullOrUndef(attrs.color_is_attendee) || !_.str.toBoolElse(attrs.color_is_attendee, true))) && (!isNullOrUndef(self.options.$sidebar));
 
152
 
 
153
 
 
154
 
 
155
            // if we have not sidebar, (eg: Dashboard), we don't use the filter "coworkers"
 
156
            if (isNullOrUndef(self.options.$sidebar)) {
 
157
                this.useContacts = false;
 
158
                this.colorIsAttendee = false;
 
159
                this.attendee_people = undefined;
 
160
            }
 
161
 
150
162
                
151
163
/*
152
164
            Will be more logic to do it in futur, but see below to stay Retro-compatible
164
176
            }            
165
177
*/
166
178
            if (isNullOrUndef(attrs.avatar_model)) {
167
 
                this.avatar_model = null; 
 
179
                this.avatar_model = null;
168
180
            }
169
181
            else {
170
182
                this.avatar_model = attrs.avatar_model;
171
183
            }
172
184
           
173
185
            if (isNullOrUndef(attrs.avatar_title)) {
174
 
                this.avatar_title = this.avatar_model; 
 
186
                this.avatar_title = this.avatar_model;
175
187
            }
176
188
            else {
177
189
                this.avatar_title = attrs.avatar_title;
195
207
                .call("check_access_rights", ["create", false])
196
208
                .then(function (create_right) {
197
209
                    self.create_right = create_right;
198
 
                    self.init_calendar().then(function() {    
 
210
                    self.init_calendar().then(function() {
199
211
                        self.trigger('calendar_view_loaded', fv);
200
212
                        self.ready.resolve();
201
213
                    });
231
243
                    self.proxy('update_record')(event._id, data);
232
244
                },
233
245
                eventRender: function (event, element, view) {
234
 
                    element.find('.fc-event-title').html(event.title);                    
 
246
                    element.find('.fc-event-title').html(event.title);
235
247
                },
236
 
                eventAfterRender: function (event, element, view) {                    
 
248
                eventAfterRender: function (event, element, view) {
237
249
                    if ((view.name !== 'month') && (((event.end-event.start)/60000)<=30)) {
238
250
                        //if duration is too small, we see the html code of img
239
251
                        var current_title = $(element.find('.fc-event-time')).text();
240
 
                        var new_title = current_title.substr(0,current_title.indexOf("<img")>0?current_title.indexOf("<img"):current_title.length)
 
252
                        var new_title = current_title.substr(0,current_title.indexOf("<img")>0?current_title.indexOf("<img"):current_title.length);
241
253
                        element.find('.fc-event-time').html(new_title);
242
 
                    }                    
 
254
                    }
243
255
                },
244
256
                eventClick: function (event) { self.open_event(event._id,event.title); },
245
257
                select: function (start_date, end_date, all_day, _js_event, _view) {
248
260
                        end: end_date,
249
261
                        allDay: all_day,
250
262
                    });
251
 
 
252
263
                    self.open_quick_create(data_template);
253
264
 
254
265
                },
277
288
                            agenda: 'h:mm{ - h:mm}', // 5:00 - 6:30
278
289
 
279
290
                            // for all other views
280
 
                            '': 'h(:mm)tt'            // 7pm
 
291
                            '': 'h(:mm)tt'  // 7pm
281
292
                        },
282
293
                weekMode : 'liquid',
283
294
                aspectRatio: 1.8,
294
305
                        context.$calendar.fullCalendar('changeView','agendaDay');
295
306
                    }
296
307
                }
297
 
                else if (curView.name != "agendaDay" || (curView.name == "agendaDay" && curDate.compareTo(curView.start)==0)) {
 
308
                else if (curView.name != "agendaDay" || (curView.name == "agendaDay" && curDate.compareTo(curView.start)===0)) {
298
309
                        context.$calendar.fullCalendar('changeView','agendaWeek');
299
310
                }
300
311
                context.$calendar.fullCalendar('gotoDate', obj.currentYear , obj.currentMonth, obj.currentDay);
301
 
            }
 
312
            };
302
313
        },
303
314
 
304
315
        init_calendar: function() {
312
323
                this.$small_calendar.datepicker({ onSelect: self.calendarMiniChanged(self) });
313
324
            
314
325
                if (this.useContacts) {
 
326
                    //Get my Partner ID
315
327
                    new instance.web.Model("res.users").query(["partner_id"]).filter([["id", "=",this.dataset.context.uid]]).first()
316
328
                        .done(
317
 
                            function(result) { 
 
329
                            function(result) {
318
330
                                var sidebar_items = {};
319
331
                                var filter_value = result.partner_id[0];
320
332
                                var filter_item = {
326
338
                                sidebar_items[filter_value] = filter_item ;
327
339
                                filter_item = {
328
340
                                        value: -1,
329
 
                                        label: _lt("All calendars"),
 
341
                                        label: _lt("Everybody's calendars"),
330
342
                                        color: self.get_color(-1),
331
343
                                        avatar_model: self.avatar_model
332
344
                                    };
333
345
                                sidebar_items[-1] = filter_item ;
334
 
 
 
346
                                //Get my coworkers/contacts
335
347
                                new instance.web.Model("calendar.contacts").query(["partner_id"]).filter([["user_id", "=",self.dataset.context.uid]]).all().then(function(result) {
336
348
                                    _.each(result, function(item) {
337
349
                                        filter_value = item.partner_id[0];
347
359
                                    self.allFilters = sidebar_items;
348
360
                                    self.sidebar.filter.events_loaded(sidebar_items);
349
361
                                    self.sidebar.filter.addUpdateButton();
350
 
                                }).done(function () { 
351
 
                                    self.$calendar.fullCalendar('refetchEvents');            
 
362
                                }).done(function () {
 
363
                                    self.$calendar.fullCalendar('refetchEvents');
352
364
                                });
353
365
                            }
354
 
                         );               
355
 
                };
 
366
                         );
 
367
                }
356
368
                this.extraSideBar();
357
369
                
358
370
            }
380
392
                        delete this.quick;
381
393
                        this.$calendar.fullCalendar('unselect');
382
394
                    });
383
 
            this.quick.replace($(".oe_calendar_qc_placeholder"));
 
395
            this.quick.replace(this.$el.find('.oe_calendar_qc_placeholder'));
384
396
            this.quick.focus();
385
397
            
386
398
        },
486
498
        event_data_transform: function(evt) {
487
499
            var self = this;
488
500
 
489
 
            var date_start = instance.web.auto_str_to_date(evt[this.date_start]),
490
 
                date_stop = this.date_stop ? instance.web.auto_str_to_date(evt[this.date_stop]) : null,
491
 
                date_delay = evt[this.date_delay] || 1.0,
 
501
            var date_delay = evt[this.date_delay] || 1.0,
492
502
                all_day = this.all_day ? evt[this.all_day] : false,
493
503
                res_computed_text = '',
494
504
                the_title = '',
495
 
                attendees = [];                
 
505
                attendees = [];
496
506
 
497
 
            if (this.date_stop && this.fields[this.date_stop].type == 'date') {
498
 
                date_stop.addDay(1);
 
507
            if (!all_day) {
 
508
                date_start = instance.web.auto_str_to_date(evt[this.date_start]);
 
509
                date_stop = this.date_stop ? instance.web.auto_str_to_date(evt[this.date_stop]) : null;
 
510
            }
 
511
            else {
 
512
                date_start = instance.web.auto_str_to_date(evt[this.date_start].split(' ')[0],'date');
 
513
                date_stop = this.date_stop  ? instance.web.auto_str_to_date(evt[this.date_stop].split(' ')[0],'date').addMinutes(-1) : null;
499
514
            }
500
515
 
501
516
            if (this.info_fields) {
530
545
                        temp_ret[fieldname] = value;
531
546
                    }
532
547
                    res_computed_text = res_computed_text.replace("["+fieldname+"]",temp_ret[fieldname]);
533
 
                });                
 
548
                });
534
549
 
535
550
                
536
551
                if (res_computed_text.length) {
538
553
                }
539
554
                else {
540
555
                    var res_text= [];
541
 
                    _.each(temp_ret, function(val,key) { res_text.push(val)} );
542
 
                    the_title = res_text.join(', ');                    
 
556
                    _.each(temp_ret, function(val,key) { res_text.push(val); });
 
557
                    the_title = res_text.join(', ');
543
558
                }
544
559
                the_title = _.escape(the_title);
545
560
                
551
566
                    var attendee_showed = 0;
552
567
                    var attendee_other = '';
553
568
 
554
 
                    _.each(temp_ret[this.attendee_people], 
555
 
                        function (the_attendee_people) { 
 
569
                    _.each(temp_ret[this.attendee_people],
 
570
                        function (the_attendee_people) {
556
571
                            attendees.push(the_attendee_people);
557
572
                            attendee_showed += 1;
558
 
                            if (attendee_showed<= MAX_ATTENDEES) {                            
559
 
                                if (self.avatar_model != null) {
560
 
                                       the_title_avatar += '<img title="' + self.all_attendees[the_attendee_people] + '" class="attendee_head" src="/web/binary/image?model=' + self.avatar_model + '&field=image_small&id=' + the_attendee_people + '"></img>';                                
 
573
                            if (attendee_showed<= MAX_ATTENDEES) {
 
574
                                if (self.avatar_model !== null) {
 
575
                                       the_title_avatar += '<img title="' + self.all_attendees[the_attendee_people] + '" class="attendee_head"  \
 
576
                                                            src="/web/binary/image?model=' + self.avatar_model + '&field=image_small&id=' + the_attendee_people + '"></img>';
561
577
                                }
562
578
                                else {
563
579
                                    if (!self.colorIsAttendee || the_attendee_people != temp_ret[self.color_field]) {
564
580
                                            tempColor = (self.all_filters[the_attendee_people] != undefined) 
565
581
                                                                ? self.all_filters[the_attendee_people].color
566
582
                                                                : self.all_filters[-1].color;
567
 
                                            
568
 
                                        the_title_avatar += '<i class="fa fa-user attendee_head color_'+tempColor+'" title="' + self.all_attendees[the_attendee_people] + '" ></i>' 
 
583
                                        the_title_avatar += '<i class="fa fa-user attendee_head color_'+tempColor+'" title="' + self.all_attendees[the_attendee_people] + '" ></i>';
569
584
                                    }//else don't add myself
570
585
                                }
571
586
                            }
572
587
                            else {
573
588
                                attendee_other += self.all_attendees[the_attendee_people] +", ";
574
 
                            }                                    
 
589
                            }
575
590
                        }
576
591
                    );
577
592
                    if (attendee_other.length>2) {
578
 
                        the_title_avatar += '<span class="attendee_head" title="' + attendee_other.slice(0, -2) + '">+</span>';                    
 
593
                        the_title_avatar += '<span class="attendee_head" title="' + attendee_other.slice(0, -2) + '">+</span>';
579
594
                    }
580
595
                    the_title = the_title_avatar + the_title;
581
 
                }                
 
596
                }
582
597
            }
583
598
            
584
599
            if (!date_stop && date_delay) {
585
600
                date_stop = date_start.clone().addHours(date_delay);
586
601
            }
587
602
            if (this.fields[this.date_start].type != "date" && all_day) {
588
 
                date_stop.addDays(-1);
 
603
                //date_stop.addDays(-1);
589
604
            }
590
605
            var r = {
591
606
                'start': date_start.toString('yyyy-MM-dd HH:mm:ss'),
597
612
            };
598
613
            
599
614
 
600
 
            if (!self.useContacts || self.all_filters[evt[this.color_field]] != undefined) {
 
615
            if (!self.useContacts || self.all_filters[evt[this.color_field]] !== undefined) {
601
616
                if (this.color_field && evt[this.color_field]) {
602
617
                    var color_key = evt[this.color_field];
603
618
                    if (typeof color_key === "object") {
604
619
                        color_key = color_key[0];
605
620
                    }
606
 
                    r.className = 'cal_opacity calendar_color_'+ this.get_color(color_key);                                
 
621
                    r.className = 'cal_opacity calendar_color_'+ this.get_color(color_key);
607
622
                }
608
623
            }
609
624
            else  { // if form all, get color -1
610
625
 
611
626
                  r.className = 'cal_opacity calendar_color_'+ self.all_filters[-1].color;
612
627
            }
613
 
            
614
628
            return r;
615
629
        },
616
630
        
627
641
            
628
642
            var event_end = event.end;
629
643
            //Bug when we move an all_day event from week or day view, we don't have a dateend or duration...            
630
 
            if (event_end == null) {
 
644
            if (event_end === null) {
631
645
                event_end = new Date(event.start).addHours(2);
632
646
            }
633
647
 
637
651
                    event_end = new Date(event.start);
638
652
                }
639
653
                if (this.all_day) {
640
 
                    event_end = (new Date(event_end.getTime())).addDays(1); 
641
 
                    date_start_day = new Date(Date.UTC(event.start.getFullYear(),event.start.getMonth(),event.start.getDate()))
642
 
                    date_stop_day = new Date(Date.UTC(event_end.getFullYear(),event_end.getMonth(),event_end.getDate()))            
 
654
                    event_end = (new Date(event_end.getTime())).addDays(1);
 
655
                    date_start_day = new Date(event.start.getFullYear(),event.start.getMonth(),event.start.getDate(),12);
 
656
                    date_stop_day = new Date(event_end.getFullYear(),event_end.getMonth(),event_end.getDate(),12);
643
657
                }
644
658
                else {
645
 
                    date_start_day = new Date(Date.UTC(event.start.getFullYear(),event.start.getMonth(),event.start.getDate(),7))
646
 
                    date_stop_day = new Date(Date.UTC(event_end.getFullYear(),event_end.getMonth(),event_end.getDate(),19))            
647
 
                }                                
 
659
                    date_start_day = new Date(event.start.getFullYear(),event.start.getMonth(),event.start.getDate(),7);
 
660
                    date_stop_day = new Date(event_end.getFullYear(),event_end.getMonth(),event_end.getDate(),19);
 
661
                }
648
662
                data[this.date_start] = instance.web.parse_value(date_start_day, this.fields[this.date_start]);
649
663
                if (this.date_stop) {
650
664
                    data[this.date_stop] = instance.web.parse_value(date_stop_day, this.fields[this.date_stop]);
652
666
                                
653
667
            }
654
668
            else {
655
 
                
656
669
                data[this.date_start] = instance.web.parse_value(event.start, this.fields[this.date_start]);
657
670
                if (this.date_stop) {
658
671
                    data[this.date_stop] = instance.web.parse_value(event_end, this.fields[this.date_stop]);
659
 
                }            
660
 
 
 
672
                }
661
673
            }
662
674
 
663
675
 
664
676
            if (this.all_day) {
665
 
                data[this.all_day] = event.allDay;                
 
677
                data[this.all_day] = event.allDay;
666
678
            }
667
679
 
668
680
            if (this.date_delay) {
671
683
            }
672
684
            return data;
673
685
        },
 
686
 
674
687
        do_search: function(domain, context, _group_by) {
675
688
            var self = this;
 
689
 
 
690
            if (self.sidebar) {
 
691
                self.sidebar.filter.is_loaded = false;
 
692
            }
 
693
 
676
694
            if (! _.isUndefined(this.event_source)) {
677
695
                this.$calendar.fullCalendar('removeEventSource', this.event_source);
678
696
            }
684
702
                        domain: self.get_range_domain(domain, start, end),
685
703
                        context: context,
686
704
                    }).done(function(events) {
 
705
 
687
706
                        if (self.event_source !== current_event_source) {
688
707
                            console.log("Consecutive ``do_search`` called. Cancelling.");
689
708
                            return;
690
709
                        }
691
 
                        // We should make sure that *2many used in title of event have their extended form [ID, NAME]...
692
710
                        
693
 
                        events = $.map(events, function (e) {
694
 
                            
695
 
                            if (self.attendee_people != undefined) { //If we filter on contacts...
696
 
                                if (_.intersection(self.selected_filters,e[self.attendee_people]).length || (self.selected_filters.indexOf(-1) > -1)) {
697
 
                                    return e;
698
 
                                }
699
 
                                else {
700
 
                                    return null;
701
 
                                }   
 
711
                       if (self.attendee_people !== undefined) {
 
712
                            //Else we filter on 'Everybody's Calendar, we don't filter events 
 
713
                            if (self.selected_filters.indexOf(-1) == -1) {
 
714
 
 
715
                                //If we filter on contacts... we keep only events from coworkers                                 
 
716
                                events = $.map(events, function (e) {
 
717
                                        if (_.intersection(self.selected_filters,e[self.attendee_people]).length ) {
 
718
                                            return e;
 
719
                                        }
 
720
                                        return null;
 
721
                                });
702
722
                            }
703
 
                            else { //We adds all events 
704
 
                                return e;
705
 
                            }                            
706
 
                            return null;                            
707
 
                        });
 
723
                        }
708
724
                        
709
 
                        if (!self.useContacts) {  // If we use all peoples as filter in sidebars
 
725
                        if (!self.useContacts) {  // If we use all peoples displayed in the current month as filter in sidebars
710
726
                            var now_filters = {};
711
727
                            var filter_value;
712
728
                            var filter_item;
713
729
                            
 
730
                            
714
731
                            _.each(events, function (e) {
715
732
                                filter_value = e[self.color_field][0];
716
733
                                filter_item = {
724
741
                                }
725
742
                            });
726
743
                            
 
744
                            
727
745
                            self.allFilters = now_filters;
728
 
                            self.sidebar.filter.events_loaded(now_filters);                            
729
 
                            
 
746
 
 
747
                            if (self.sidebar) {
 
748
                                if (!self.sidebar.filter.is_loaded) {
 
749
                                    self.sidebar.filter.events_loaded(now_filters);
 
750
                                }
 
751
                                else {
 
752
                                    events = $.map(events, function (e) {
 
753
                                        if (_.contains(self.selected_filters,e[self.color_field][0]) ) {
 
754
                                            return e;
 
755
                                        }
 
756
                                        return null;
 
757
                                    });
 
758
                                }
 
759
                            }
730
760
                            return self.perform_necessary_name_gets(events).then(callback);
731
761
                        }
732
762
                        else {
733
763
                            var all_attendees = [];
734
764
                            
735
765
                            _.each(events, function (e) {
736
 
                                all_attendees.push(e[self.attendee_people]);                                
 
766
                                all_attendees.push(e[self.attendee_people]);
737
767
                            });
738
768
                            
739
 
                            self.all_attendees = {}
 
769
                            self.all_attendees = {};
740
770
                            
741
771
                            all_attendees = _.chain(all_attendees).flatten().uniq().value();
742
772
                            
743
 
                            if (self.avatar_title != null) {
 
773
                            if (self.avatar_title !== null) {
744
774
                                new instance.web.Model(self.avatar_title).query(["name"]).filter([["id", "in",all_attendees]]).all().then(function(result) {
745
775
                                    _.each(result, function(item) {
746
776
                                        self.all_attendees[item.id] = item.name;
747
777
                                    });
748
 
                                }).done(function() { 
 
778
                                }).done(function() {
749
779
                                    return self.perform_necessary_name_gets(events).then(callback);
750
780
                                });
751
 
                            }                                                        
 
781
                            }
752
782
                            else {
753
783
                                _.each(all_attendees,function(item){
754
784
                                        self.all_attendees[item] = '';
756
786
                                return self.perform_necessary_name_gets(events).then(callback);
757
787
                                
758
788
                            }
759
 
                            
760
789
                        }
761
 
                        
762
 
 
763
790
                    });
764
791
                },
765
792
                eventDataTransform: function (event) {
780
807
                 [this.date_start, '<=', format(end.clone())]]);
781
808
        },
782
809
 
783
 
 
784
810
        /**
785
811
         * Updates record identified by ``id`` with values in object ``data``
786
812
         */
803
829
            }
804
830
            return false;
805
831
        },
806
 
        open_event: function(id,title) {
 
832
        open_event: function(id, title) {
807
833
            var self = this;
808
 
            if (! this.open_popup_action) { 
 
834
            if (! this.open_popup_action) {
809
835
                var index = this.dataset.get_id_index(id);
810
836
                this.dataset.index = index;
811
837
                this.do_switch_view('form', null, { mode: "edit" });
812
 
            }            
 
838
            }
813
839
            else {
814
 
 
815
 
                var self = this;
816
 
 
817
840
                var pop = new instance.web.form.FormOpenPopup(this);
818
 
                console.log(this.open_popup_action, +this.open_popup_action);
819
841
                pop.show_element(this.dataset.model, id, this.dataset.get_context(), {
820
842
                    title: _.str.sprintf(_t("View: %s"),title),
821
843
                    view_id: +this.open_popup_action,
822
844
                    res_id: id,
823
845
                    target: 'new',
824
846
                    readonly:true
825
 
                });              
 
847
                });
826
848
 
827
849
               var form_controller = pop.view_form;
828
850
               form_controller.on("load_record", self, function(){
830
852
                    button_edit = _.str.sprintf("<button class='oe_button oe_bold editme oe_highlight'><span> %s </span></button>",_t("Edit Event"));
831
853
                    
832
854
                    
833
 
                    pop.$el.closest(".ui-dialog").find(".ui-dialog-buttonpane").prepend(button_delete)
834
 
                    pop.$el.closest(".ui-dialog").find(".ui-dialog-buttonpane").prepend(button_edit)
 
855
                    pop.$el.closest(".ui-dialog").find(".ui-dialog-buttonpane").prepend(button_delete);
 
856
                    pop.$el.closest(".ui-dialog").find(".ui-dialog-buttonpane").prepend(button_edit);
835
857
                    
836
858
                    $('.delme').click(
837
 
                        function() { 
838
 
                            $('.oe_form_button_cancel').trigger('click'); 
839
 
                            self.remove_event(id); 
 
859
                        function() {
 
860
                            $('.oe_form_button_cancel').trigger('click');
 
861
                            self.remove_event(id);
840
862
                        }
841
863
                    );
842
864
                    $('.editme').click(
843
 
                        function() { 
844
 
                            $('.oe_form_button_cancel').trigger('click'); 
845
 
 
846
 
                            var index = self.dataset.get_id_index(id);
847
 
                            self.dataset.index = index;
 
865
                        function() {
 
866
                            $('.oe_form_button_cancel').trigger('click');
 
867
                            self.dataset.index = self.dataset.get_id_index(id);
848
868
                            self.do_switch_view('form', null, { mode: "edit" });
849
 
 
850
869
                        }
851
870
                    );
852
 
                    
853
 
                    
854
871
               });
855
 
                 
856
 
            }   
857
 
            
858
 
            return false;         
859
 
            
 
872
            }
 
873
            return false;
860
874
        },
861
875
 
862
876
        do_show: function() {
900
914
        slow_created: function () {
901
915
            // refresh all view, because maybe some recurrents item
902
916
            var self = this;
 
917
            if (self.sidebar) {
 
918
                // force filter refresh
 
919
                self.sidebar.filter.is_loaded = false;
 
920
            }
903
921
            self.$calendar.fullCalendar('refetchEvents');
904
922
        },
905
923
 
933
951
        template: 'CalendarView.quick_create',
934
952
        
935
953
        init: function(parent, dataset, buttons, options, data_template) {
936
 
            this._super(parent);            
 
954
            this._super(parent);
937
955
            this.dataset = dataset;
938
956
            this._buttons = buttons || false;
939
957
            this.options = options;
944
962
        get_title: function () {
945
963
            var parent = this.getParent();
946
964
            if (_.isUndefined(parent)) {
947
 
                return _t("Create")
 
965
                return _t("Create");
948
966
            }
949
967
            var title = (_.isUndefined(parent.field_widget)) ?
950
968
                    (parent.string || parent.name) :
965
983
                if(event.keyCode == 13){
966
984
                    self.$input.off('keyup', enterHandler);
967
985
                    if (!self.quick_add()){
968
 
                        self.$input.on('keyup', enterHandler);                    
 
986
                        self.$input.on('keyup', enterHandler);
969
987
                    }
970
988
                }
971
989
            });
974
992
            submit.click(function clickHandler() {
975
993
                submit.off('click', clickHandler);
976
994
                if (!self.quick_add()){
977
 
                   submit.on('click', clickHandler);                    
978
 
                }
 
995
                   submit.on('click', clickHandler);                }
979
996
                self.focus();
980
997
            });
981
998
            this.$el.find(".oe_calendar_quick_create_edit").click(function () {
982
999
                self.slow_add();
983
1000
                self.focus();
984
 
            });            
 
1001
            });
985
1002
            this.$el.find(".oe_calendar_quick_create_close").click(function (ev) {
986
1003
                ev.preventDefault();
987
1004
                self.trigger('close');
997
1014
            });
998
1015
            
999
1016
            self.$el.on('dialogclose', self, function() {
1000
 
                console.log("dialogclose");
1001
1017
                self.trigger('close');
1002
1018
            });
1003
1019
 
1011
1027
         */
1012
1028
        quick_add: function() {
1013
1029
            var val = this.$input.val();
1014
 
            if (/^\s*$/.test(val)) { 
1015
 
                return false; 
 
1030
            if (/^\s*$/.test(val)) {
 
1031
                return false;
1016
1032
            }
1017
 
            return this.quick_create({'name': val}).always(function() { return true });
 
1033
            return this.quick_create({'name': val}).always(function() { return true; });
1018
1034
        },
1019
1035
        
1020
1036
        slow_add: function() {
1053
1069
            return infos;
1054
1070
        },
1055
1071
        slow_create: function(data) {
 
1072
            //if all day, we could reset time to display 00:00:00
 
1073
            
1056
1074
            var self = this;
1057
1075
            var def = $.Deferred();
1058
1076
            var defaults = {};
 
1077
 
1059
1078
            _.each($.extend({}, this.data_template, data), function(val, field_name) {
1060
1079
                defaults['default_' + field_name] = val;
1061
1080
            });
1062
 
            
1063
 
            if (defaults['default_allday'] && (defaults['default_date_deadline'] || defaults['default_duration'])) {
1064
 
                delete defaults['default_date_deadline'];
1065
 
                delete defaults['default_duration'];
1066
 
            }
1067
 
 
 
1081
                        
1068
1082
            var pop_infos = self.get_form_popup_infos();
1069
1083
            var pop = new instance.web.form.FormOpenPopup(this);
1070
 
            var context = new instance.web.CompoundContext(this.dataset.context, defaults)
 
1084
            var context = new instance.web.CompoundContext(this.dataset.context, defaults);
1071
1085
            pop.show_element(this.dataset.model, null, this.dataset.get_context(defaults), {
1072
1086
                title: this.get_title(),
1073
1087
                disable_multiple_selection: true,
1316
1330
        },
1317
1331
 
1318
1332
        render_value: function() {
1319
 
            console.log("In render value");
1320
1333
            var self = this;
1321
1334
            this.dataset.set_ids(this.get("value"));
1322
1335
            this.is_loaded = this.is_loaded.then(function() {
1360
1373
                },
1361
1374
 
1362
1375
                alternative_form_view: this.field.views ? this.field.views.form : undefined,
1363
 
                parent_view: this.view, //XXXvlab: to check ! this.view is likely undefined
 
1376
                parent_view: this.view,
1364
1377
                child_name: this.name,
1365
1378
                readonly: this.get("effective_readonly")
1366
1379
            });
1377
1390
        }
1378
1391
    });
1379
1392
    instance.web_calendar.SidebarFilter = instance.web.Widget.extend({
 
1393
        is_loaded:false,
1380
1394
        events: {
1381
1395
            'change input:checkbox': 'filter_click'
1382
1396
        },
1383
1397
        init: function(parent, view) {
1384
1398
            this._super(parent);
1385
 
            this.view = view;            
 
1399
            this.view = view;
1386
1400
        },
 
1401
 
 
1402
   
 
1403
 
1387
1404
        events_loaded: function(filters) {
1388
1405
            var self = this;
 
1406
            self.is_loaded=true;
 
1407
            
1389
1408
            self.selected_filters = [];
1390
1409
            self.view.all_filters = filters;
1391
1410
            this.$el.html(QWeb.render('CalendarView.sidebar.responsible', { filters: filters }));
1392
 
            this.filter_click(null);                        
 
1411
            this.filter_click(null);
 
1412
 
1393
1413
        },
1394
1414
        filter_click: function(e) {
1395
1415
            var self = this,
1398
1418
            this.$('div.oe_calendar_responsible input:checked').each(function() {
1399
1419
                responsibles.push($(this).val());
1400
1420
                
1401
 
                if (e==null && parseInt($(this).val())<0) {
 
1421
                if (e==null && parseInt($(this).val())<0){
1402
1422
                    $(this).prop('checked',false);
1403
1423
                    return;
1404
 
                }                    
 
1424
                }
 
1425
 
1405
1426
                self.view.selected_filters.push(parseInt($(this).val()));
1406
1427
            });
1407
 
            
1408
 
            if (e !== null) { //First intialize 
1409
 
                self.view.$calendar.fullCalendar('refetchEvents');  
1410
 
            }
1411
 
 
1412
 
            
 
1428
            self.view.$calendar.fullCalendar('refetchEvents');
1413
1429
        },
1414
1430
        addUpdateButton: function() {
1415
1431
            var self=this;
1416
1432
            this.$('div.oe_calendar_all_responsibles').append(QWeb.render('CalendarView.sidebar.button_add_contact'));
1417
 
            this.$(".add_contacts_link_btn").on('click', function() {  
1418
 
                self.rpc("/web/action/load", { 
1419
 
                    action_id: "calendar.action_calendar_contacts" 
 
1433
            this.$(".add_contacts_link_btn").on('click', function() {
 
1434
                self.rpc("/web/action/load", {
 
1435
                    action_id: "calendar.action_calendar_contacts"
1420
1436
                }).then( function(result) { return self.do_action(result); });
1421
1437
            });
1422
1438