[FIX] calendar: filter events by attendees when sidebar is used with useContacts
Add some missing deferred chains + change domain for loading calendar.events.
This commit is contained in:
@@ -10,7 +10,7 @@ function reload_favorite_list(result) {
|
||||
if (result.view) {
|
||||
self = result.view;
|
||||
}
|
||||
new instance.web.Model("res.users").query(["partner_id"]).filter([["id", "=",self.dataset.context.uid]]).first()
|
||||
return new instance.web.Model("res.users").query(["partner_id"]).filter([["id", "=",self.dataset.context.uid]]).first()
|
||||
.done(
|
||||
function(result) {
|
||||
var sidebar_items = {};
|
||||
@@ -64,10 +64,11 @@ function reload_favorite_list(result) {
|
||||
}
|
||||
instance.web_calendar.CalendarView.include({
|
||||
extraSideBar: function(){
|
||||
this._super();
|
||||
result = this._super();
|
||||
if (this.useContacts){
|
||||
new reload_favorite_list(this);
|
||||
return result.then(reload_favorite_list(this));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -107,15 +108,14 @@ function reload_favorite_list(result) {
|
||||
},
|
||||
add_filter: function() {
|
||||
var self = this;
|
||||
new instance.web.Model("res.users").query(["partner_id"]).filter([["id", "=",this.view.dataset.context.uid]]).first().done(function(result){
|
||||
return new instance.web.Model("res.users").query(["partner_id"]).filter([["id", "=",this.view.dataset.context.uid]]).first().done(function(result) {
|
||||
$.map(self.ir_model_m2o.display_value, function(element,index) {
|
||||
if (result.partner_id[0] != index){
|
||||
self.ds_message = new instance.web.DataSetSearch(self, 'calendar.contacts');
|
||||
self.ds_message.call("create", [{'partner_id': index}]);
|
||||
}
|
||||
});
|
||||
});
|
||||
new reload_favorite_list(this);
|
||||
}).then(reload_favorite_list(this));
|
||||
},
|
||||
destroy_filter: function(e) {
|
||||
var self= this;
|
||||
@@ -125,9 +125,7 @@ function reload_favorite_list(result) {
|
||||
var id = $(e.currentTarget)[0].dataset.id;
|
||||
self.ds_message.call('search', [[['partner_id', '=', parseInt(id)]]]).then(function(record){
|
||||
return self.ds_message.unlink(record);
|
||||
}).done(function() {
|
||||
new reload_favorite_list(self);
|
||||
});
|
||||
}).done(reload_favorite_list(self));
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -67,10 +67,14 @@ openerp.google_calendar = function(instance) {
|
||||
|
||||
instance.web_calendar.CalendarView.include({
|
||||
extraSideBar: function() {
|
||||
this._super();
|
||||
var self = this;
|
||||
result = this._super();
|
||||
if (this.dataset.model == "calendar.event") {
|
||||
this.$el.find('.oe_calendar_filter').prepend(QWeb.render('GoogleCalendar.buttonSynchro'));
|
||||
return result.then(function() {
|
||||
self.$el.find('.oe_calendar_filter').prepend(QWeb.render('GoogleCalendar.buttonSynchro'));
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -364,6 +364,7 @@ openerp.web_calendar = function(instance) {
|
||||
return $.when();
|
||||
},
|
||||
extraSideBar: function() {
|
||||
return $.when();
|
||||
},
|
||||
|
||||
open_quick_create: function(data_template) {
|
||||
@@ -680,9 +681,9 @@ openerp.web_calendar = function(instance) {
|
||||
},
|
||||
_do_search: function(domain, context, _group_by) {
|
||||
var self = this;
|
||||
if (! self.all_filters) {
|
||||
self.all_filters = {}
|
||||
}
|
||||
if (! self.all_filters) {
|
||||
self.all_filters = {}
|
||||
}
|
||||
|
||||
if (! _.isUndefined(this.event_source)) {
|
||||
this.$calendar.fullCalendar('removeEventSource', this.event_source);
|
||||
@@ -690,9 +691,19 @@ openerp.web_calendar = function(instance) {
|
||||
this.event_source = {
|
||||
events: function(start, end, callback) {
|
||||
var current_event_source = self.event_source;
|
||||
var event_domain = self.get_range_domain(domain, start, end);
|
||||
if (self.useContacts && (!self.all_filters[-1] || !self.all_filters[-1].is_checked)) {
|
||||
var partner_ids = $.map(self.all_filters, function(o) { if (o.is_checked) { return o.value; }});
|
||||
if (!_.isEmpty(partner_ids)) {
|
||||
event_domain = new instance.web.CompoundDomain(
|
||||
event_domain,
|
||||
[[self.attendee_people, 'in', partner_ids]]
|
||||
);
|
||||
}
|
||||
}
|
||||
self.dataset.read_slice(_.keys(self.fields), {
|
||||
offset: 0,
|
||||
domain: self.get_range_domain(domain, start, end),
|
||||
domain: event_domain,
|
||||
context: context,
|
||||
}).done(function(events) {
|
||||
if (self.dataset.index === null) {
|
||||
@@ -752,21 +763,6 @@ openerp.web_calendar = function(instance) {
|
||||
}
|
||||
|
||||
}
|
||||
else { //WE USE CONTACT
|
||||
if (self.attendee_people !== undefined) {
|
||||
//if we don't filter on 'Everybody's Calendar
|
||||
if (!self.all_filters[-1] || !self.all_filters[-1].is_checked) {
|
||||
var checked_filter = $.map(self.all_filters, function(o) { if (o.is_checked) { return o.value; }});
|
||||
// If we filter on contacts... we keep only events from coworkers
|
||||
events = $.map(events, function (e) {
|
||||
if (_.intersection(checked_filter,e[self.attendee_people]).length) {
|
||||
return e;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
var all_attendees = $.map(events, function (e) { return e[self.attendee_people]; });
|
||||
all_attendees = _.chain(all_attendees).flatten().uniq().value();
|
||||
|
||||
@@ -801,22 +797,12 @@ openerp.web_calendar = function(instance) {
|
||||
get_range_domain: function(domain, start, end) {
|
||||
var format = instance.web.date_to_str;
|
||||
|
||||
extend_domain = [[this.date_start, '>=', format(start)],
|
||||
[this.date_start, '<=', format(end)]];
|
||||
extend_domain = [[this.date_start, '<=', format(end)]];
|
||||
|
||||
if (this.date_stop) {
|
||||
//add at start
|
||||
extend_domain.splice(0,0,'|','|','&');
|
||||
//add at end
|
||||
extend_domain.push(
|
||||
'&',
|
||||
[this.date_start, '<=', format(start)],
|
||||
[this.date_stop, '>=', format(start)],
|
||||
'&',
|
||||
[this.date_start, '<=', format(end)],
|
||||
[this.date_stop, '>=', format(start)]
|
||||
[this.date_stop, '>=', format(start)]
|
||||
);
|
||||
//final -> (A & B) | (C & D) | (E & F) -> | | & A B & C D & E F
|
||||
}
|
||||
return new instance.web.CompoundDomain(domain, extend_domain);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user