[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) {
|
if (result.view) {
|
||||||
self = 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(
|
.done(
|
||||||
function(result) {
|
function(result) {
|
||||||
var sidebar_items = {};
|
var sidebar_items = {};
|
||||||
@@ -64,10 +64,11 @@ function reload_favorite_list(result) {
|
|||||||
}
|
}
|
||||||
instance.web_calendar.CalendarView.include({
|
instance.web_calendar.CalendarView.include({
|
||||||
extraSideBar: function(){
|
extraSideBar: function(){
|
||||||
this._super();
|
result = this._super();
|
||||||
if (this.useContacts){
|
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() {
|
add_filter: function() {
|
||||||
var self = this;
|
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) {
|
$.map(self.ir_model_m2o.display_value, function(element,index) {
|
||||||
if (result.partner_id[0] != index){
|
if (result.partner_id[0] != index){
|
||||||
self.ds_message = new instance.web.DataSetSearch(self, 'calendar.contacts');
|
self.ds_message = new instance.web.DataSetSearch(self, 'calendar.contacts');
|
||||||
self.ds_message.call("create", [{'partner_id': index}]);
|
self.ds_message.call("create", [{'partner_id': index}]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}).then(reload_favorite_list(this));
|
||||||
new reload_favorite_list(this);
|
|
||||||
},
|
},
|
||||||
destroy_filter: function(e) {
|
destroy_filter: function(e) {
|
||||||
var self= this;
|
var self= this;
|
||||||
@@ -125,9 +125,7 @@ function reload_favorite_list(result) {
|
|||||||
var id = $(e.currentTarget)[0].dataset.id;
|
var id = $(e.currentTarget)[0].dataset.id;
|
||||||
self.ds_message.call('search', [[['partner_id', '=', parseInt(id)]]]).then(function(record){
|
self.ds_message.call('search', [[['partner_id', '=', parseInt(id)]]]).then(function(record){
|
||||||
return self.ds_message.unlink(record);
|
return self.ds_message.unlink(record);
|
||||||
}).done(function() {
|
}).done(reload_favorite_list(self));
|
||||||
new reload_favorite_list(self);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -67,10 +67,14 @@ openerp.google_calendar = function(instance) {
|
|||||||
|
|
||||||
instance.web_calendar.CalendarView.include({
|
instance.web_calendar.CalendarView.include({
|
||||||
extraSideBar: function() {
|
extraSideBar: function() {
|
||||||
this._super();
|
var self = this;
|
||||||
|
result = this._super();
|
||||||
if (this.dataset.model == "calendar.event") {
|
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();
|
return $.when();
|
||||||
},
|
},
|
||||||
extraSideBar: function() {
|
extraSideBar: function() {
|
||||||
|
return $.when();
|
||||||
},
|
},
|
||||||
|
|
||||||
open_quick_create: function(data_template) {
|
open_quick_create: function(data_template) {
|
||||||
@@ -680,9 +681,9 @@ openerp.web_calendar = function(instance) {
|
|||||||
},
|
},
|
||||||
_do_search: function(domain, context, _group_by) {
|
_do_search: function(domain, context, _group_by) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (! self.all_filters) {
|
if (! self.all_filters) {
|
||||||
self.all_filters = {}
|
self.all_filters = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! _.isUndefined(this.event_source)) {
|
if (! _.isUndefined(this.event_source)) {
|
||||||
this.$calendar.fullCalendar('removeEventSource', this.event_source);
|
this.$calendar.fullCalendar('removeEventSource', this.event_source);
|
||||||
@@ -690,9 +691,19 @@ openerp.web_calendar = function(instance) {
|
|||||||
this.event_source = {
|
this.event_source = {
|
||||||
events: function(start, end, callback) {
|
events: function(start, end, callback) {
|
||||||
var current_event_source = self.event_source;
|
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), {
|
self.dataset.read_slice(_.keys(self.fields), {
|
||||||
offset: 0,
|
offset: 0,
|
||||||
domain: self.get_range_domain(domain, start, end),
|
domain: event_domain,
|
||||||
context: context,
|
context: context,
|
||||||
}).done(function(events) {
|
}).done(function(events) {
|
||||||
if (self.dataset.index === null) {
|
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]; });
|
var all_attendees = $.map(events, function (e) { return e[self.attendee_people]; });
|
||||||
all_attendees = _.chain(all_attendees).flatten().uniq().value();
|
all_attendees = _.chain(all_attendees).flatten().uniq().value();
|
||||||
|
|
||||||
@@ -801,22 +797,12 @@ openerp.web_calendar = function(instance) {
|
|||||||
get_range_domain: function(domain, start, end) {
|
get_range_domain: function(domain, start, end) {
|
||||||
var format = instance.web.date_to_str;
|
var format = instance.web.date_to_str;
|
||||||
|
|
||||||
extend_domain = [[this.date_start, '>=', format(start)],
|
extend_domain = [[this.date_start, '<=', format(end)]];
|
||||||
[this.date_start, '<=', format(end)]];
|
|
||||||
|
|
||||||
if (this.date_stop) {
|
if (this.date_stop) {
|
||||||
//add at start
|
|
||||||
extend_domain.splice(0,0,'|','|','&');
|
|
||||||
//add at end
|
|
||||||
extend_domain.push(
|
extend_domain.push(
|
||||||
'&',
|
[this.date_stop, '>=', format(start)]
|
||||||
[this.date_start, '<=', format(start)],
|
|
||||||
[this.date_stop, '>=', format(start)],
|
|
||||||
'&',
|
|
||||||
[this.date_start, '<=', format(end)],
|
|
||||||
[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);
|
return new instance.web.CompoundDomain(domain, extend_domain);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user