2011-04-07 16:41:06 +00:00
|
|
|
/*---------------------------------------------------------
|
2011-09-05 12:28:15 +00:00
|
|
|
* OpenERP web_calendar
|
2011-04-07 16:41:06 +00:00
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
2012-11-12 15:11:31 +00:00
|
|
|
(function() {
|
|
|
|
// Monkey patch dhtml scheduler in order to fix a bug.
|
|
|
|
if (this.scheduler) {
|
2013-05-24 14:28:56 +00:00
|
|
|
// It manually implements some kind of dbl click event
|
|
|
|
// bubbling but fails to do it properly.
|
2012-11-12 15:11:31 +00:00
|
|
|
var old_scheduler_dblclick = scheduler._on_dbl_click;
|
|
|
|
scheduler._on_dbl_click = function(e, src) {
|
|
|
|
if (src && !src.className) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
old_scheduler_dblclick.apply(this, arguments);
|
|
|
|
}
|
|
|
|
};
|
2013-05-24 13:55:20 +00:00
|
|
|
|
2013-05-24 14:28:56 +00:00
|
|
|
// It uses the date+time format, leading to month range being between
|
|
|
|
// 1/5 08:53 - 1/6 08:52 instead of 1/5 00:00 - 31/5 23:59
|
2013-05-24 13:55:20 +00:00
|
|
|
scheduler._click.dhx_cal_today_button = function() {
|
|
|
|
if (scheduler.callEvent("onBeforeTodayDisplayed", [])) {
|
|
|
|
scheduler.setCurrentView( scheduler.date.date_part(new Date()) );
|
|
|
|
}
|
|
|
|
};
|
2012-11-12 15:11:31 +00:00
|
|
|
}
|
|
|
|
}());
|
|
|
|
|
2012-04-17 12:26:11 +00:00
|
|
|
openerp.web_calendar = function(instance) {
|
|
|
|
var _t = instance.web._t,
|
|
|
|
_lt = instance.web._lt;
|
|
|
|
var QWeb = instance.web.qweb;
|
|
|
|
instance.web.views.add('calendar', 'instance.web_calendar.CalendarView');
|
|
|
|
instance.web_calendar.CalendarView = instance.web.View.extend({
|
2012-04-30 21:28:08 +00:00
|
|
|
template: "CalendarView",
|
2011-12-16 13:00:00 +00:00
|
|
|
display_name: _lt('Calendar'),
|
2011-04-07 16:41:06 +00:00
|
|
|
// Dhtmlx scheduler ?
|
2011-09-15 09:49:44 +00:00
|
|
|
init: function(parent, dataset, view_id, options) {
|
2012-10-18 11:49:50 +00:00
|
|
|
var self = this;
|
2011-09-15 09:49:44 +00:00
|
|
|
this._super(parent);
|
2011-12-13 16:22:35 +00:00
|
|
|
this.ready = $.Deferred();
|
2011-08-08 17:32:30 +00:00
|
|
|
this.set_default_options(options);
|
2011-04-07 16:41:06 +00:00
|
|
|
this.dataset = dataset;
|
|
|
|
this.model = dataset.model;
|
2011-09-29 12:19:02 +00:00
|
|
|
this.fields_view = {};
|
2011-04-07 16:41:06 +00:00
|
|
|
this.view_id = view_id;
|
2012-04-10 16:05:09 +00:00
|
|
|
this.view_type = 'calendar';
|
2011-08-01 15:48:56 +00:00
|
|
|
this.has_been_loaded = $.Deferred();
|
2011-08-11 16:07:54 +00:00
|
|
|
this.dataset_events = [];
|
2011-08-11 17:13:37 +00:00
|
|
|
this.COLOR_PALETTE = ['#f57900', '#cc0000', '#d400a8', '#75507b', '#3465a4', '#73d216', '#c17d11', '#edd400',
|
|
|
|
'#fcaf3e', '#ef2929', '#ff00c9', '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f',
|
|
|
|
'#ff8e00', '#ff0000', '#b0008c', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00',
|
|
|
|
'#905000', '#9b0000', '#840067', '#510090', '#0000c9', '#009b00', '#9abe00', '#ffc900' ];
|
2011-08-18 19:18:26 +00:00
|
|
|
this.color_map = {};
|
2011-12-08 14:36:30 +00:00
|
|
|
this.last_search = [];
|
2011-12-13 16:22:35 +00:00
|
|
|
this.range_start = null;
|
|
|
|
this.range_stop = null;
|
|
|
|
this.update_range_dates(Date.today());
|
2012-01-12 11:09:53 +00:00
|
|
|
this.selected_filters = [];
|
2012-12-13 14:09:14 +00:00
|
|
|
},
|
|
|
|
view_loading: function(r) {
|
|
|
|
return this.load_calendar(r);
|
2011-07-25 10:32:54 +00:00
|
|
|
},
|
2012-02-21 16:29:12 +00:00
|
|
|
destroy: function() {
|
2011-08-04 14:54:53 +00:00
|
|
|
scheduler.clearAll();
|
2011-09-28 15:16:13 +00:00
|
|
|
this._super();
|
2011-08-04 14:54:53 +00:00
|
|
|
},
|
2012-10-18 11:49:50 +00:00
|
|
|
load_calendar: function(data) {
|
2011-09-06 23:08:59 +00:00
|
|
|
this.fields_view = data;
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.addClass(this.fields_view.arch.attrs['class']);
|
2011-08-01 12:48:02 +00:00
|
|
|
this.calendar_fields = {};
|
|
|
|
this.ids = this.dataset.ids;
|
|
|
|
this.color_values = [];
|
|
|
|
this.info_fields = [];
|
|
|
|
|
2011-05-31 11:25:45 +00:00
|
|
|
this.name = this.fields_view.name || this.fields_view.arch.attrs.string;
|
2011-08-01 12:48:02 +00:00
|
|
|
this.view_id = this.fields_view.view_id;
|
|
|
|
|
2011-10-04 12:41:25 +00:00
|
|
|
// mode, one of month, week or day
|
|
|
|
this.mode = this.fields_view.arch.attrs.mode;
|
|
|
|
|
|
|
|
// date_start is mandatory, date_delay and date_stop are optional
|
2011-05-31 11:25:45 +00:00
|
|
|
this.date_start = this.fields_view.arch.attrs.date_start;
|
2011-08-01 12:48:02 +00:00
|
|
|
this.date_delay = this.fields_view.arch.attrs.date_delay;
|
|
|
|
this.date_stop = this.fields_view.arch.attrs.date_stop;
|
|
|
|
|
|
|
|
this.day_length = this.fields_view.arch.attrs.day_length || 8;
|
|
|
|
this.color_field = this.fields_view.arch.attrs.color;
|
2012-03-06 13:07:27 +00:00
|
|
|
this.color_string = this.fields_view.fields[this.color_field] ?
|
|
|
|
this.fields_view.fields[this.color_field].string : _t("Filter");
|
2012-01-12 11:09:53 +00:00
|
|
|
|
|
|
|
if (this.color_field && this.selected_filters.length === 0) {
|
|
|
|
var default_filter;
|
2012-10-24 15:06:05 +00:00
|
|
|
if ((default_filter = this.dataset.context['calendar_default_' + this.color_field])) {
|
2012-01-12 11:09:53 +00:00
|
|
|
this.selected_filters.push(default_filter + '');
|
|
|
|
}
|
|
|
|
}
|
2011-08-01 12:48:02 +00:00
|
|
|
this.fields = this.fields_view.fields;
|
2012-01-12 11:09:53 +00:00
|
|
|
|
2011-10-04 09:40:09 +00:00
|
|
|
if (!this.date_start) {
|
2012-11-29 00:22:00 +00:00
|
|
|
throw new Error(_t("Calendar view has not defined 'date_start' attribute."));
|
2011-10-04 09:40:09 +00:00
|
|
|
}
|
2011-08-01 12:48:02 +00:00
|
|
|
|
2011-05-31 11:25:45 +00:00
|
|
|
//* Calendar Fields *
|
2011-08-10 16:16:01 +00:00
|
|
|
this.calendar_fields.date_start = {'name': this.date_start, 'kind': this.fields[this.date_start].type};
|
2011-08-01 12:48:02 +00:00
|
|
|
|
|
|
|
if (this.date_delay) {
|
2011-08-10 16:16:01 +00:00
|
|
|
if (this.fields[this.date_delay].type != 'float') {
|
2012-11-29 00:22:00 +00:00
|
|
|
throw new Error(_t("Calendar view has a 'date_delay' type != float"));
|
2011-08-10 16:16:01 +00:00
|
|
|
}
|
|
|
|
this.calendar_fields.date_delay = {'name': this.date_delay, 'kind': this.fields[this.date_delay].type};
|
2011-08-01 12:48:02 +00:00
|
|
|
}
|
|
|
|
if (this.date_stop) {
|
2011-08-10 16:16:01 +00:00
|
|
|
this.calendar_fields.date_stop = {'name': this.date_stop, 'kind': this.fields[this.date_stop].type};
|
|
|
|
}
|
2011-08-01 12:48:02 +00:00
|
|
|
|
|
|
|
for (var fld = 0; fld < this.fields_view.arch.children.length; fld++) {
|
|
|
|
this.info_fields.push(this.fields_view.arch.children[fld].attrs.name);
|
|
|
|
}
|
2011-08-01 15:48:56 +00:00
|
|
|
|
2012-04-10 16:05:09 +00:00
|
|
|
this.init_scheduler();
|
|
|
|
|
2012-04-30 21:28:08 +00:00
|
|
|
if (!this.sidebar && this.options.$sidebar) {
|
2012-04-17 12:26:11 +00:00
|
|
|
this.sidebar = new instance.web_calendar.Sidebar(this);
|
2012-10-30 14:06:30 +00:00
|
|
|
this.has_been_loaded.then(this.sidebar.appendTo(this.$el.find('.oe_calendar_sidebar_container')));
|
2011-08-01 15:48:56 +00:00
|
|
|
}
|
2012-10-18 11:49:50 +00:00
|
|
|
this.trigger('calendar_view_loaded', data);
|
2012-04-10 16:05:09 +00:00
|
|
|
return this.has_been_loaded.resolve();
|
2011-05-31 11:25:45 +00:00
|
|
|
},
|
2011-08-01 12:48:02 +00:00
|
|
|
init_scheduler: function() {
|
|
|
|
var self = this;
|
2011-08-03 11:05:50 +00:00
|
|
|
scheduler.clearAll();
|
2011-08-01 12:48:02 +00:00
|
|
|
if (this.fields[this.date_start]['type'] == 'time') {
|
|
|
|
scheduler.config.xml_date = "%H:%M:%S";
|
|
|
|
} else {
|
2011-08-04 10:07:31 +00:00
|
|
|
scheduler.config.xml_date = "%Y-%m-%d %H:%i";
|
2011-08-01 12:48:02 +00:00
|
|
|
}
|
2011-08-04 10:07:31 +00:00
|
|
|
scheduler.config.api_date = "%Y-%m-%d %H:%i";
|
2011-08-01 12:48:02 +00:00
|
|
|
scheduler.config.multi_day = true; //Multi day events are not rendered in daily and weekly views
|
2012-06-25 11:58:39 +00:00
|
|
|
scheduler.config.start_on_monday = Date.CultureInfo.firstDayOfWeek !== 0; //Sunday = Sunday, Others = Monday
|
2011-12-12 12:38:57 +00:00
|
|
|
scheduler.config.time_step = 30;
|
2011-08-04 14:54:53 +00:00
|
|
|
scheduler.config.scroll_hour = 8;
|
2011-08-11 13:24:10 +00:00
|
|
|
scheduler.config.drag_resize = true;
|
|
|
|
scheduler.config.drag_create = true;
|
2011-12-08 14:36:30 +00:00
|
|
|
scheduler.config.mark_now = true;
|
|
|
|
scheduler.config.day_date = '%l %j';
|
2012-10-24 11:21:47 +00:00
|
|
|
scheduler.config.details_on_create = false;
|
2011-08-01 12:48:02 +00:00
|
|
|
|
2012-06-25 11:58:39 +00:00
|
|
|
scheduler.locale = {
|
|
|
|
date:{
|
|
|
|
month_full: Date.CultureInfo.monthNames,
|
|
|
|
month_short: Date.CultureInfo.abbreviatedMonthNames,
|
|
|
|
day_full: Date.CultureInfo.dayNames,
|
|
|
|
day_short: Date.CultureInfo.abbreviatedDayNames
|
|
|
|
},
|
|
|
|
labels:{
|
|
|
|
dhx_cal_today_button: _t("Today"),
|
|
|
|
day_tab: _t("Day"),
|
|
|
|
week_tab: _t("Week"),
|
|
|
|
month_tab: _t("Month"),
|
|
|
|
new_event: _t("New event"),
|
|
|
|
icon_save: _t("Save"),
|
|
|
|
icon_cancel: _t("Cancel"),
|
|
|
|
icon_details: _t("Details"),
|
|
|
|
icon_edit: _t("Edit"),
|
|
|
|
icon_delete: _t("Delete"),
|
|
|
|
confirm_closing: "",//Your changes will be lost, are your sure ?
|
|
|
|
confirm_deleting: _t("Event will be deleted permanently, are you sure?"),
|
|
|
|
section_description: _t("Description"),
|
|
|
|
section_time: _t("Time period"),
|
|
|
|
full_day: _t("Full day"),
|
|
|
|
|
|
|
|
/*recurring events*/
|
|
|
|
confirm_recurring: _t("Do you want to edit the whole set of repeated events?"),
|
|
|
|
section_recurring: _t("Repeat event"),
|
|
|
|
button_recurring: _t("Disabled"),
|
|
|
|
button_recurring_open: _t("Enabled"),
|
|
|
|
|
|
|
|
/*agenda view extension*/
|
|
|
|
agenda_tab: _t("Agenda"),
|
|
|
|
date: _t("Date"),
|
|
|
|
description: _t("Description"),
|
|
|
|
|
|
|
|
/*year view extension*/
|
|
|
|
year_tab: _t("Year"),
|
|
|
|
|
|
|
|
/* week agenda extension */
|
|
|
|
week_agenda_tab: _t("Agenda")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-24 18:27:07 +00:00
|
|
|
scheduler.init(this.$el.find('.oe_calendar')[0], null, this.mode || 'month');
|
2011-08-04 14:54:53 +00:00
|
|
|
scheduler.detachAllEvents();
|
2012-10-25 10:37:48 +00:00
|
|
|
scheduler.attachEvent('onViewChange', this.proxy('view_changed'));
|
2012-10-24 11:21:47 +00:00
|
|
|
scheduler.attachEvent('onEventChanged', this.proxy('quick_save'));
|
2012-10-24 15:06:05 +00:00
|
|
|
scheduler.attachEvent('onEventDeleted', this.proxy('delete_event'));
|
2012-10-25 10:16:01 +00:00
|
|
|
scheduler.attachEvent('onEventAdded', function(event_id, event_obj) {
|
|
|
|
var fn = event_obj._force_slow_create ? 'slow_create' : 'quick_create';
|
|
|
|
self[fn].apply(self, arguments);
|
|
|
|
});
|
2012-10-24 15:06:05 +00:00
|
|
|
scheduler.attachEvent('onClick', function(event_id, mouse_event) {
|
2012-10-29 10:53:03 +00:00
|
|
|
if (!self.$el.find('.dhx_cal_editor').length && self.current_mode() === 'month') {
|
|
|
|
self.open_event(event_id);
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
scheduler.attachEvent('onDblClick', function(event_id, mouse_event) {
|
2012-10-24 15:06:05 +00:00
|
|
|
if (!self.$el.find('.dhx_cal_editor').length) {
|
|
|
|
self.open_event(event_id);
|
|
|
|
}
|
2012-10-24 11:21:47 +00:00
|
|
|
});
|
2012-10-25 10:16:01 +00:00
|
|
|
scheduler.attachEvent('onEmptyClick', function(start_date, mouse_event) {
|
2012-11-05 15:04:12 +00:00
|
|
|
scheduler._loading = false; // Dirty workaround for a dhtmleditor bug I couln't track
|
2012-10-25 10:16:01 +00:00
|
|
|
if (!self.$el.find('.dhx_cal_editor').length) {
|
|
|
|
var end_date = new Date(start_date);
|
|
|
|
end_date.addHours(1);
|
|
|
|
scheduler.addEvent({
|
|
|
|
start_date: start_date,
|
|
|
|
end_date: end_date,
|
|
|
|
_force_slow_create: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-10-24 15:06:05 +00:00
|
|
|
scheduler.attachEvent("onBeforeLightbox", function (event_id) {
|
2012-10-24 11:21:47 +00:00
|
|
|
var index = self.dataset.get_id_index(event_id);
|
|
|
|
if (index !== null) {
|
|
|
|
self.open_event(self.dataset.ids[index]);
|
|
|
|
} else {
|
2012-10-24 15:06:05 +00:00
|
|
|
self.slow_create(event_id, scheduler.getEvent(event_id));
|
2012-10-24 11:21:47 +00:00
|
|
|
}
|
2012-10-24 15:06:05 +00:00
|
|
|
return false;
|
2012-10-24 11:21:47 +00:00
|
|
|
});
|
2011-08-01 12:48:02 +00:00
|
|
|
|
2011-12-13 16:22:35 +00:00
|
|
|
this.refresh_scheduler();
|
2012-09-24 14:11:44 +00:00
|
|
|
|
|
|
|
// Remove hard coded style attributes from dhtmlx scheduler
|
|
|
|
this.$el.find(".dhx_cal_navline").removeAttr('style');
|
|
|
|
instance.web.bus.on('resize',this,function(){
|
|
|
|
self.$el.find(".dhx_cal_navline").removeAttr('style');
|
|
|
|
});
|
2011-08-01 15:48:56 +00:00
|
|
|
},
|
2012-10-25 10:37:48 +00:00
|
|
|
view_changed: function(mode, date) {
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.find('.oe_calendar').removeClass('oe_cal_day oe_cal_week oe_cal_month').addClass('oe_cal_' + mode);
|
2011-12-13 16:22:35 +00:00
|
|
|
if (!date.between(this.range_start, this.range_stop)) {
|
|
|
|
this.update_range_dates(date);
|
2012-10-25 10:37:48 +00:00
|
|
|
this.ranged_search();
|
2011-12-13 16:22:35 +00:00
|
|
|
}
|
|
|
|
this.ready.resolve();
|
|
|
|
},
|
|
|
|
update_range_dates: function(date) {
|
|
|
|
this.range_start = date.clone().moveToFirstDayOfMonth();
|
|
|
|
this.range_stop = this.range_start.clone().addMonths(1).addSeconds(-1);
|
|
|
|
},
|
2011-08-04 14:54:53 +00:00
|
|
|
refresh_scheduler: function() {
|
2011-08-01 15:48:56 +00:00
|
|
|
scheduler.setCurrentView(scheduler._date);
|
2011-08-04 14:54:53 +00:00
|
|
|
},
|
2011-08-09 15:49:19 +00:00
|
|
|
reload_event: function(id) {
|
2012-11-05 20:17:17 +00:00
|
|
|
this.dataset.read_ids([id], _.keys(this.fields)).done(this.proxy('events_loaded'));
|
2011-08-09 15:49:19 +00:00
|
|
|
},
|
2011-08-18 19:18:26 +00:00
|
|
|
get_color: function(key) {
|
|
|
|
if (this.color_map[key]) {
|
|
|
|
return this.color_map[key];
|
|
|
|
}
|
|
|
|
var index = _.keys(this.color_map).length % this.COLOR_PALETTE.length;
|
|
|
|
var color = this.COLOR_PALETTE[index];
|
|
|
|
this.color_map[key] = color;
|
|
|
|
return color;
|
2011-08-11 17:13:37 +00:00
|
|
|
},
|
2012-10-25 10:37:48 +00:00
|
|
|
events_loaded: function(events, fn_filter, no_filter_reload) {
|
2011-08-01 12:48:02 +00:00
|
|
|
var self = this;
|
|
|
|
|
2011-05-31 11:25:45 +00:00
|
|
|
//To parse Events we have to convert date Format
|
2011-08-01 15:48:56 +00:00
|
|
|
var res_events = [],
|
2011-08-18 19:18:26 +00:00
|
|
|
sidebar_items = {};
|
2013-05-16 12:56:50 +00:00
|
|
|
var selection_label;
|
2013-04-03 13:23:46 +00:00
|
|
|
if(this.fields[this.color_field].selection) {
|
2013-05-16 12:56:50 +00:00
|
|
|
selection_label = {};
|
2013-04-03 13:23:46 +00:00
|
|
|
_(this.fields[this.color_field].selection).each(function(value){
|
|
|
|
selection_label[value[0]] = value[1];
|
|
|
|
});
|
|
|
|
}
|
2011-08-01 12:48:02 +00:00
|
|
|
for (var e = 0; e < events.length; e++) {
|
2011-05-31 11:25:45 +00:00
|
|
|
var evt = events[e];
|
2011-08-01 12:48:02 +00:00
|
|
|
if (!evt[this.date_start]) {
|
2011-05-31 11:25:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-08-01 12:48:02 +00:00
|
|
|
|
2011-08-01 15:48:56 +00:00
|
|
|
if (this.color_field) {
|
2011-08-11 16:07:54 +00:00
|
|
|
var filter = evt[this.color_field];
|
|
|
|
if (filter) {
|
2013-05-16 12:56:50 +00:00
|
|
|
if (typeof filter !== 'object') {
|
|
|
|
filter = [filter, filter];
|
2013-04-03 13:23:46 +00:00
|
|
|
}
|
2013-05-16 12:56:50 +00:00
|
|
|
if (selection_label) {
|
|
|
|
filter[1] = selection_label[filter[0]];
|
|
|
|
}
|
|
|
|
var filter_value = filter[0];
|
2011-08-18 19:18:26 +00:00
|
|
|
if (typeof(fn_filter) === 'function' && !fn_filter(filter_value)) {
|
2011-08-11 16:07:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-08-18 19:18:26 +00:00
|
|
|
var filter_item = {
|
|
|
|
value: filter_value,
|
2013-05-16 12:56:50 +00:00
|
|
|
label: filter[1],
|
2011-08-18 19:18:26 +00:00
|
|
|
color: this.get_color(filter_value)
|
2011-09-06 08:58:53 +00:00
|
|
|
};
|
2011-08-18 19:18:26 +00:00
|
|
|
if (!sidebar_items[filter_value]) {
|
|
|
|
sidebar_items[filter_value] = filter_item;
|
2011-08-01 15:48:56 +00:00
|
|
|
}
|
2011-08-18 19:18:26 +00:00
|
|
|
evt.color = filter_item.color;
|
2011-08-11 17:13:37 +00:00
|
|
|
evt.textColor = '#ffffff';
|
2012-07-02 15:34:39 +00:00
|
|
|
} else {
|
|
|
|
evt.textColor = '#000000';
|
2011-08-01 15:48:56 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-11 16:07:54 +00:00
|
|
|
|
2011-10-18 13:28:13 +00:00
|
|
|
if (this.fields[this.date_start]['type'] == 'date') {
|
2012-04-17 12:26:11 +00:00
|
|
|
evt[this.date_start] = instance.web.auto_str_to_date(evt[this.date_start]).set({hour: 9}).toString('yyyy-MM-dd HH:mm:ss');
|
2011-08-11 16:07:54 +00:00
|
|
|
}
|
|
|
|
if (this.date_stop && evt[this.date_stop] && this.fields[this.date_stop]['type'] == 'date') {
|
2012-04-17 12:26:11 +00:00
|
|
|
evt[this.date_stop] = instance.web.auto_str_to_date(evt[this.date_stop]).set({hour: 17}).toString('yyyy-MM-dd HH:mm:ss');
|
2011-08-11 17:13:37 +00:00
|
|
|
}
|
2011-08-01 12:48:02 +00:00
|
|
|
res_events.push(this.convert_event(evt));
|
2011-05-31 11:25:45 +00:00
|
|
|
}
|
2011-08-01 12:48:02 +00:00
|
|
|
scheduler.parse(res_events, 'json');
|
2011-08-04 14:54:53 +00:00
|
|
|
this.refresh_scheduler();
|
2012-04-18 14:24:39 +00:00
|
|
|
if (!no_filter_reload && this.sidebar) {
|
2012-10-25 10:37:48 +00:00
|
|
|
this.sidebar.filter.events_loaded(sidebar_items);
|
2011-08-11 16:07:54 +00:00
|
|
|
}
|
2011-08-01 12:48:02 +00:00
|
|
|
},
|
2011-08-11 13:24:10 +00:00
|
|
|
convert_event: function(evt) {
|
2012-04-17 12:26:11 +00:00
|
|
|
var date_start = instance.web.str_to_datetime(evt[this.date_start]),
|
|
|
|
date_stop = this.date_stop ? instance.web.str_to_datetime(evt[this.date_stop]) : null,
|
2011-10-04 09:40:09 +00:00
|
|
|
date_delay = evt[this.date_delay] || 1.0,
|
2012-04-05 06:52:16 +00:00
|
|
|
res_text = '';
|
2011-08-01 12:48:02 +00:00
|
|
|
|
|
|
|
if (this.info_fields) {
|
2012-04-05 06:52:16 +00:00
|
|
|
res_text = _.map(this.info_fields, function(fld) {
|
|
|
|
if(evt[fld] instanceof Array)
|
|
|
|
return evt[fld][1];
|
|
|
|
return evt[fld];
|
|
|
|
});
|
2014-02-14 11:42:58 +00:00
|
|
|
res_text = _.filter(res_text, function(e){return !_.isEmpty(e);});
|
2011-08-01 12:48:02 +00:00
|
|
|
}
|
2011-08-11 13:24:10 +00:00
|
|
|
if (!date_stop && date_delay) {
|
|
|
|
date_stop = date_start.clone().addHours(date_delay);
|
2011-08-01 12:48:02 +00:00
|
|
|
}
|
2011-08-11 16:07:54 +00:00
|
|
|
var r = {
|
2011-08-11 13:24:10 +00:00
|
|
|
'start_date': date_start.toString('yyyy-MM-dd HH:mm:ss'),
|
|
|
|
'end_date': date_stop.toString('yyyy-MM-dd HH:mm:ss'),
|
2012-04-17 10:15:17 +00:00
|
|
|
'text': res_text.join(', '),
|
2012-04-05 06:52:16 +00:00
|
|
|
'id': evt.id
|
2011-09-06 08:58:53 +00:00
|
|
|
};
|
2011-08-11 16:07:54 +00:00
|
|
|
if (evt.color) {
|
|
|
|
r.color = evt.color;
|
|
|
|
}
|
|
|
|
if (evt.textColor) {
|
|
|
|
r.textColor = evt.textColor;
|
|
|
|
}
|
|
|
|
return r;
|
2011-05-31 11:25:45 +00:00
|
|
|
},
|
2011-08-03 11:05:50 +00:00
|
|
|
get_event_data: function(event_obj) {
|
2012-10-24 11:21:47 +00:00
|
|
|
var data = {
|
2013-03-21 22:54:02 +00:00
|
|
|
name: event_obj.text || scheduler.locale.labels.new_event
|
2012-10-24 11:21:47 +00:00
|
|
|
};
|
2013-01-22 07:35:26 +00:00
|
|
|
if (this.fields[this.date_start].type == 'date') {
|
|
|
|
data[this.date_start] = instance.web.date_to_str(event_obj.start_date)
|
|
|
|
}else {
|
|
|
|
data[this.date_start] = instance.web.datetime_to_str(event_obj.start_date)
|
|
|
|
}
|
2011-08-03 11:05:50 +00:00
|
|
|
if (this.date_stop) {
|
2012-04-17 12:26:11 +00:00
|
|
|
data[this.date_stop] = instance.web.datetime_to_str(event_obj.end_date);
|
2011-08-03 11:05:50 +00:00
|
|
|
}
|
|
|
|
if (this.date_delay) {
|
2011-08-11 13:24:10 +00:00
|
|
|
var diff_seconds = Math.round((event_obj.end_date.getTime() - event_obj.start_date.getTime()) / 1000);
|
|
|
|
data[this.date_delay] = diff_seconds / 3600;
|
2011-08-03 11:05:50 +00:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
},
|
2011-09-29 12:19:02 +00:00
|
|
|
do_search: function(domain, context, group_by) {
|
2011-12-13 16:22:35 +00:00
|
|
|
this.last_search = arguments;
|
2012-10-25 10:37:48 +00:00
|
|
|
this.ranged_search();
|
2011-12-13 16:22:35 +00:00
|
|
|
},
|
2012-10-25 10:37:48 +00:00
|
|
|
ranged_search: function() {
|
2012-01-25 08:53:10 +00:00
|
|
|
var self = this;
|
2011-08-11 16:07:54 +00:00
|
|
|
scheduler.clearAll();
|
2012-10-30 14:06:30 +00:00
|
|
|
$.when(this.has_been_loaded, this.ready).done(function() {
|
2011-09-29 12:19:02 +00:00
|
|
|
self.dataset.read_slice(_.keys(self.fields), {
|
|
|
|
offset: 0,
|
2011-12-13 16:22:35 +00:00
|
|
|
domain: self.get_range_domain(),
|
|
|
|
context: self.last_search[1]
|
2012-10-30 14:06:30 +00:00
|
|
|
}).done(function(events) {
|
2011-09-29 12:19:02 +00:00
|
|
|
self.dataset_events = events;
|
2012-10-25 10:37:48 +00:00
|
|
|
self.events_loaded(events);
|
2011-08-10 13:19:35 +00:00
|
|
|
});
|
2011-05-31 11:25:45 +00:00
|
|
|
});
|
|
|
|
},
|
2011-12-13 16:22:35 +00:00
|
|
|
get_range_domain: function() {
|
2013-06-28 09:07:06 +00:00
|
|
|
var format = instance.web.date_to_str;
|
|
|
|
var A = format(this.range_start.clone().addDays(-6));
|
|
|
|
var B = format(this.range_stop.clone().addDays(6));
|
|
|
|
var domain = [
|
2013-07-19 09:25:15 +00:00
|
|
|
'&', [this.date_start, '>=', A], [this.date_start, '<=', B]
|
2013-06-28 09:07:06 +00:00
|
|
|
];
|
2013-07-19 09:25:15 +00:00
|
|
|
if (this.date_stop) {
|
|
|
|
domain.push(
|
|
|
|
'&', [this.date_stop, '>=', A], [this.date_stop, '<=', B],
|
|
|
|
'&', [this.date_start, '<', A], [this.date_stop, '>', B]);
|
|
|
|
domain.unshift("|", "|");
|
|
|
|
}
|
2013-06-28 09:07:06 +00:00
|
|
|
domain.concat(this.last_search[0].slice(0))
|
2011-12-13 16:22:35 +00:00
|
|
|
return domain;
|
|
|
|
},
|
2011-08-01 12:48:02 +00:00
|
|
|
do_show: function () {
|
2011-08-01 15:48:56 +00:00
|
|
|
var self = this;
|
2012-10-30 14:06:30 +00:00
|
|
|
$.when(this.has_been_loaded).done(function() {
|
2012-08-24 18:27:07 +00:00
|
|
|
self.$el.show();
|
2012-01-03 16:06:50 +00:00
|
|
|
self.do_push_state({});
|
2011-08-01 15:48:56 +00:00
|
|
|
});
|
2011-04-07 16:41:06 +00:00
|
|
|
},
|
2011-08-26 13:31:13 +00:00
|
|
|
get_selected_ids: function() {
|
|
|
|
// no way to select a record anyway
|
|
|
|
return [];
|
2012-10-24 15:06:05 +00:00
|
|
|
},
|
2012-10-29 10:53:03 +00:00
|
|
|
current_mode: function() {
|
|
|
|
return scheduler.getState().mode;
|
|
|
|
},
|
2011-08-01 15:48:56 +00:00
|
|
|
|
2012-10-24 15:06:05 +00:00
|
|
|
quick_save: function(event_id, event_obj) {
|
|
|
|
var self = this;
|
|
|
|
var data = this.get_event_data(event_obj);
|
|
|
|
delete(data.name);
|
|
|
|
var index = this.dataset.get_id_index(event_id);
|
|
|
|
if (index !== null) {
|
|
|
|
event_id = this.dataset.ids[index];
|
2012-11-21 16:04:52 +00:00
|
|
|
this.dataset.write(event_id, data, {});
|
2012-10-24 15:06:05 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
quick_create: function(event_id, event_obj) {
|
|
|
|
var self = this;
|
|
|
|
var data = this.get_event_data(event_obj);
|
2012-11-05 20:17:17 +00:00
|
|
|
this.dataset.create(data).done(function(r) {
|
2012-10-24 15:06:05 +00:00
|
|
|
var id = r;
|
|
|
|
self.dataset.ids.push(id);
|
|
|
|
scheduler.changeEventId(event_id, id);
|
|
|
|
self.reload_event(id);
|
2012-11-05 20:17:17 +00:00
|
|
|
}).fail(function(r, event) {
|
2012-10-24 15:06:05 +00:00
|
|
|
event.preventDefault();
|
|
|
|
self.slow_create(event_id, event_obj);
|
2012-10-15 13:52:36 +00:00
|
|
|
});
|
2011-08-09 15:49:19 +00:00
|
|
|
},
|
2013-02-04 14:38:04 +00:00
|
|
|
get_form_popup_infos: function() {
|
2013-02-04 12:43:48 +00:00
|
|
|
var parent = this.getParent();
|
2013-02-04 14:38:04 +00:00
|
|
|
var infos = {
|
|
|
|
view_id: false,
|
|
|
|
title: this.name,
|
|
|
|
};
|
2013-02-04 12:43:48 +00:00
|
|
|
if (parent instanceof instance.web.ViewManager) {
|
2013-02-04 14:38:04 +00:00
|
|
|
infos.view_id = parent.get_view_id('form');
|
|
|
|
if (parent instanceof instance.web.ViewManagerAction && parent.action && parent.action.name) {
|
|
|
|
infos.title = parent.action.name;
|
2013-02-04 12:43:48 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-04 14:38:04 +00:00
|
|
|
return infos;
|
|
|
|
},
|
|
|
|
slow_create: function(event_id, event_obj) {
|
|
|
|
var self = this;
|
2012-10-29 10:53:03 +00:00
|
|
|
if (this.current_mode() === 'month') {
|
2012-10-25 10:16:01 +00:00
|
|
|
event_obj['start_date'].addHours(8);
|
2012-10-24 15:06:05 +00:00
|
|
|
if (event_obj._length === 1) {
|
|
|
|
event_obj['end_date'] = new Date(event_obj['start_date']);
|
|
|
|
event_obj['end_date'].addHours(1);
|
|
|
|
} else {
|
|
|
|
event_obj['end_date'].addHours(-4);
|
|
|
|
}
|
|
|
|
}
|
2012-10-25 14:11:40 +00:00
|
|
|
var defaults = {};
|
|
|
|
_.each(this.get_event_data(event_obj), function(val, field_name) {
|
|
|
|
defaults['default_' + field_name] = val;
|
2011-08-09 15:49:19 +00:00
|
|
|
});
|
2012-10-25 14:11:40 +00:00
|
|
|
var something_saved = false;
|
|
|
|
var pop = new instance.web.form.FormOpenPopup(this);
|
2013-02-04 14:38:04 +00:00
|
|
|
var pop_infos = this.get_form_popup_infos();
|
2012-10-25 14:11:40 +00:00
|
|
|
pop.show_element(this.dataset.model, null, this.dataset.get_context(defaults), {
|
2013-02-04 14:38:04 +00:00
|
|
|
title: _.str.sprintf(_t("Create: %s"), pop_infos.title),
|
2012-10-25 14:11:40 +00:00
|
|
|
disable_multiple_selection: true,
|
2013-02-04 14:38:04 +00:00
|
|
|
view_id: pop_infos.view_id,
|
2012-10-25 14:11:40 +00:00
|
|
|
});
|
|
|
|
pop.on('closed', self, function() {
|
|
|
|
if (!something_saved) {
|
|
|
|
scheduler.deleteEvent(event_id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
pop.on('create_completed', self, function(id) {
|
|
|
|
something_saved = true;
|
|
|
|
self.dataset.ids.push(id);
|
|
|
|
scheduler.changeEventId(event_id, id);
|
|
|
|
self.reload_event(id);
|
|
|
|
});
|
2012-10-24 15:06:05 +00:00
|
|
|
},
|
|
|
|
open_event: function(event_id) {
|
2012-10-25 14:11:40 +00:00
|
|
|
var self = this;
|
|
|
|
var index = this.dataset.get_id_index(event_id);
|
|
|
|
if (index === null) {
|
2012-10-25 10:16:01 +00:00
|
|
|
// Some weird behaviour in dhtmlx scheduler could lead to this case
|
|
|
|
// eg: making multiple days event in week view, dhtmlx doesn't trigger eventAdded !!??
|
|
|
|
// so the user clicks back on the orphan event and we land here. We have to duplicate
|
|
|
|
// the dhtmlx internal event because it will delete it on next sheduler refresh.
|
|
|
|
var event_obj = scheduler.getEvent(event_id);
|
|
|
|
scheduler.deleteEvent(event_id);
|
|
|
|
scheduler.addEvent({
|
|
|
|
start_date: event_obj.start_date,
|
|
|
|
end_date: event_obj.end_date,
|
2012-11-05 15:04:12 +00:00
|
|
|
text: event_obj.text,
|
2012-10-25 10:16:01 +00:00
|
|
|
_force_slow_create: true,
|
|
|
|
});
|
|
|
|
} else {
|
2012-10-25 14:11:40 +00:00
|
|
|
var pop = new instance.web.form.FormOpenPopup(this);
|
2013-02-04 14:38:04 +00:00
|
|
|
var pop_infos = this.get_form_popup_infos();
|
2012-12-18 15:16:57 +00:00
|
|
|
var id_from_dataset = this.dataset.ids[index]; // dhtmlx scheduler loses id's type
|
|
|
|
pop.show_element(this.dataset.model, id_from_dataset, this.dataset.get_context(), {
|
2013-02-04 14:38:04 +00:00
|
|
|
title: _.str.sprintf(_t("Edit: %s"), pop_infos.title),
|
|
|
|
view_id: pop_infos.view_id,
|
2012-10-25 14:11:40 +00:00
|
|
|
});
|
|
|
|
pop.on('write_completed', self, function(){
|
2012-12-18 15:16:57 +00:00
|
|
|
self.reload_event(id_from_dataset);
|
2012-10-25 14:11:40 +00:00
|
|
|
});
|
2011-12-21 13:57:16 +00:00
|
|
|
}
|
2011-08-09 15:49:19 +00:00
|
|
|
},
|
2012-10-24 15:06:05 +00:00
|
|
|
delete_event: function(event_id, event_obj) {
|
|
|
|
// dhtmlx sends this event even when it does not exist in openerp.
|
|
|
|
// Eg: use cancel in dhtmlx new event dialog
|
|
|
|
var self = this;
|
|
|
|
var index = this.dataset.get_id_index(event_id);
|
|
|
|
if (index !== null) {
|
2013-03-27 12:24:47 +00:00
|
|
|
this.dataset.unlink(this.dataset.ids[index]);
|
2011-08-09 15:49:19 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-04-17 12:26:11 +00:00
|
|
|
instance.web_calendar.Sidebar = instance.web.Widget.extend({
|
2012-04-10 16:05:09 +00:00
|
|
|
template: 'CalendarView.sidebar',
|
|
|
|
start: function() {
|
|
|
|
this._super();
|
|
|
|
this.mini_calendar = scheduler.renderCalendar({
|
2012-08-24 18:27:07 +00:00
|
|
|
container: this.$el.find('.oe_calendar_mini')[0],
|
2012-04-10 16:05:09 +00:00
|
|
|
navigation: true,
|
|
|
|
date: scheduler._date,
|
|
|
|
handler: function(date, calendar) {
|
|
|
|
scheduler.setCurrentView(date, 'day');
|
|
|
|
}
|
|
|
|
});
|
2012-11-21 16:04:52 +00:00
|
|
|
scheduler.linkCalendar(this.mini_calendar);
|
2012-04-17 12:26:11 +00:00
|
|
|
this.filter = new instance.web_calendar.SidebarFilter(this, this.getParent());
|
2012-08-24 18:27:07 +00:00
|
|
|
this.filter.appendTo(this.$el.find('.oe_calendar_filter'));
|
2012-04-10 16:05:09 +00:00
|
|
|
}
|
|
|
|
});
|
2012-04-17 12:26:11 +00:00
|
|
|
instance.web_calendar.SidebarFilter = instance.web.Widget.extend({
|
2012-07-26 14:57:15 +00:00
|
|
|
events: {
|
2012-10-25 10:37:48 +00:00
|
|
|
'change input:checkbox': 'filter_click'
|
2012-07-26 14:57:15 +00:00
|
|
|
},
|
2011-10-10 12:34:32 +00:00
|
|
|
init: function(parent, view) {
|
2012-04-10 16:05:09 +00:00
|
|
|
this._super(parent);
|
2011-08-01 15:48:56 +00:00
|
|
|
this.view = view;
|
2011-08-11 16:07:54 +00:00
|
|
|
},
|
2012-10-25 10:37:48 +00:00
|
|
|
events_loaded: function(filters) {
|
2012-01-12 11:09:53 +00:00
|
|
|
var selected_filters = this.view.selected_filters.slice(0);
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.html(QWeb.render('CalendarView.sidebar.responsible', { filters: filters }));
|
2012-07-26 14:57:15 +00:00
|
|
|
this.$('div.oe_calendar_responsible input').each(function() {
|
2012-01-12 11:09:53 +00:00
|
|
|
if (_.indexOf(selected_filters, $(this).val()) > -1) {
|
|
|
|
$(this).click();
|
|
|
|
}
|
|
|
|
});
|
2011-08-01 15:48:56 +00:00
|
|
|
},
|
2012-10-25 10:37:48 +00:00
|
|
|
filter_click: function(e) {
|
2012-01-12 11:09:53 +00:00
|
|
|
var self = this,
|
|
|
|
responsibles = [],
|
2011-08-11 16:07:54 +00:00
|
|
|
$e = $(e.target);
|
2012-01-12 11:09:53 +00:00
|
|
|
this.view.selected_filters = [];
|
2012-07-26 14:57:15 +00:00
|
|
|
this.$('div.oe_calendar_responsible input:checked').each(function() {
|
2011-08-11 16:07:54 +00:00
|
|
|
responsibles.push($(this).val());
|
2012-01-12 11:09:53 +00:00
|
|
|
self.view.selected_filters.push($(this).val());
|
2011-08-11 16:07:54 +00:00
|
|
|
});
|
|
|
|
scheduler.clearAll();
|
|
|
|
if (responsibles.length) {
|
2012-10-25 10:37:48 +00:00
|
|
|
this.view.events_loaded(this.view.dataset_events, function(filter_value) {
|
2011-08-11 16:07:54 +00:00
|
|
|
return _.indexOf(responsibles, filter_value.toString()) > -1;
|
|
|
|
}, true);
|
|
|
|
} else {
|
2012-10-25 10:37:48 +00:00
|
|
|
this.view.events_loaded(this.view.dataset_events, false, true);
|
2011-08-11 16:07:54 +00:00
|
|
|
}
|
2011-08-01 15:48:56 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-04-07 16:41:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|