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-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) {
|
|
|
|
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-09 15:49:19 +00:00
|
|
|
this.creating_event_id = null;
|
2011-08-11 16:07:54 +00:00
|
|
|
this.dataset_events = [];
|
2012-04-17 12:26:11 +00:00
|
|
|
this.form_dialog = new instance.web_calendar.CalendarFormDialog(this, {
|
2011-12-21 13:43:06 +00:00
|
|
|
destroy_on_close: false,
|
|
|
|
width: '80%',
|
|
|
|
min_width: 850
|
|
|
|
}, this.options.action_views_ids.form, dataset);
|
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 = [];
|
2011-07-25 10:32:54 +00:00
|
|
|
},
|
2011-08-01 12:48:02 +00:00
|
|
|
start: function() {
|
2011-09-15 09:42:46 +00:00
|
|
|
this._super();
|
2012-04-10 16:05:09 +00:00
|
|
|
return this.rpc("/web/view/load", {"model": this.model, "view_id": this.view_id, "view_type":"calendar", 'toolbar': false}, this.on_loaded);
|
2011-08-01 12:48:02 +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
|
|
|
},
|
2011-05-31 11:25:45 +00:00
|
|
|
on_loaded: function(data) {
|
2011-09-06 23:08:59 +00:00
|
|
|
this.fields_view = data;
|
2012-06-27 15:17:33 +00:00
|
|
|
this.$element.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;
|
|
|
|
if (default_filter = this.dataset.context['calendar_default_' + this.color_field]) {
|
|
|
|
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) {
|
2011-10-04 13:37:53 +00:00
|
|
|
throw new Error("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') {
|
|
|
|
throw new Error("Calendar view has a 'date_delay' type != float");
|
|
|
|
}
|
|
|
|
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-04-30 21:28:08 +00:00
|
|
|
this.has_been_loaded.pipe(this.sidebar.appendTo(this.$element.find('.oe_calendar_sidebar_container')));
|
2011-08-01 15:48:56 +00:00
|
|
|
}
|
|
|
|
|
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';
|
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-04-30 21:28:08 +00:00
|
|
|
scheduler.init(this.$element.find('.oe_calendar')[0], null, this.mode || 'month');
|
2011-08-01 12:48:02 +00:00
|
|
|
|
2011-10-27 11:12:00 +00:00
|
|
|
// Remove hard coded style attributes from dhtmlx scheduler
|
|
|
|
this.$element.find(".dhx_cal_navline div").removeAttr('style');
|
|
|
|
|
2011-08-04 14:54:53 +00:00
|
|
|
scheduler.detachAllEvents();
|
2011-08-03 11:05:50 +00:00
|
|
|
scheduler.attachEvent('onEventAdded', this.do_create_event);
|
|
|
|
scheduler.attachEvent('onEventDeleted', this.do_delete_event);
|
|
|
|
scheduler.attachEvent('onEventChanged', this.do_save_event);
|
2011-12-08 14:36:30 +00:00
|
|
|
scheduler.attachEvent('onClick', this.do_edit_event);
|
2011-12-12 16:02:42 +00:00
|
|
|
scheduler.attachEvent('onLightbox', this.do_edit_event);
|
2011-08-01 12:48:02 +00:00
|
|
|
|
2011-12-13 16:22:35 +00:00
|
|
|
scheduler.attachEvent('onViewChange', this.on_view_changed);
|
|
|
|
this.refresh_scheduler();
|
2011-08-01 15:48:56 +00:00
|
|
|
},
|
2011-12-13 16:22:35 +00:00
|
|
|
on_view_changed: function(mode, date) {
|
2012-04-30 21:28:08 +00:00
|
|
|
this.$element.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);
|
|
|
|
this.do_ranged_search();
|
|
|
|
}
|
|
|
|
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
|
|
|
},
|
|
|
|
refresh_minical: function() {
|
2012-04-18 14:24:39 +00:00
|
|
|
if (this.sidebar) {
|
2012-04-10 16:05:09 +00:00
|
|
|
scheduler.updateCalendar(this.sidebar.mini_calendar);
|
2011-11-16 10:59:47 +00:00
|
|
|
}
|
2011-08-01 12:48:02 +00:00
|
|
|
},
|
2011-08-09 15:49:19 +00:00
|
|
|
reload_event: function(id) {
|
2012-01-10 15:45:00 +00:00
|
|
|
this.dataset.read_ids([id], _.keys(this.fields)).then(this.on_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
|
|
|
},
|
2011-08-11 16:07:54 +00:00
|
|
|
on_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 = {};
|
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) {
|
2011-08-18 19:18:26 +00:00
|
|
|
var filter_value = (typeof filter === 'object') ? filter[0] : filter;
|
|
|
|
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,
|
|
|
|
label: (typeof filter === 'object') ? filter[1] : filter,
|
|
|
|
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();
|
|
|
|
this.refresh_minical();
|
2012-04-18 14:24:39 +00:00
|
|
|
if (!no_filter_reload && this.sidebar) {
|
2012-04-10 16:05:09 +00:00
|
|
|
this.sidebar.filter.on_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];
|
|
|
|
});
|
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
|
|
|
do_create_event: function(event_id, event_obj) {
|
|
|
|
var self = this,
|
|
|
|
data = this.get_event_data(event_obj);
|
|
|
|
this.dataset.create(data, function(r) {
|
2011-12-01 23:07:36 +00:00
|
|
|
var id = r.result;
|
2011-08-03 11:05:50 +00:00
|
|
|
self.dataset.ids.push(id);
|
|
|
|
scheduler.changeEventId(event_id, id);
|
2011-08-04 14:54:53 +00:00
|
|
|
self.refresh_minical();
|
2012-01-04 17:38:55 +00:00
|
|
|
self.reload_event(id);
|
2011-08-03 11:05:50 +00:00
|
|
|
}, function(r, event) {
|
2011-08-09 15:49:19 +00:00
|
|
|
event.preventDefault();
|
2011-12-01 23:07:36 +00:00
|
|
|
self.do_create_event_with_formdialog(event_id, event_obj);
|
2011-08-03 11:05:50 +00:00
|
|
|
});
|
|
|
|
},
|
2011-12-01 23:07:36 +00:00
|
|
|
do_create_event_with_formdialog: function(event_id, event_obj) {
|
2012-08-16 10:03:53 +00:00
|
|
|
var self = this;
|
|
|
|
$.when(! self.form_dialog.dialog_inited ? self.form_dialog.init_dialog() : true).then(function() {
|
|
|
|
debugger;
|
|
|
|
if (!event_obj) {
|
|
|
|
event_obj = scheduler.getEvent(event_id);
|
|
|
|
}
|
|
|
|
var data = self.get_event_data(event_obj),
|
|
|
|
fields_to_fetch = _(self.form_dialog.form.fields_view.fields).keys();
|
|
|
|
self.dataset.index = null;
|
|
|
|
self.creating_event_id = event_id;
|
|
|
|
self.form_dialog.form.do_show().then(function() {
|
|
|
|
_.each(['date_start', 'date_delay', 'date_stop'], function(field) {
|
|
|
|
var field_name = self[field];
|
|
|
|
if (field_name && self.form_dialog.form.fields[field_name]) {
|
|
|
|
var ffield = self.form_dialog.form.fields[field_name];
|
|
|
|
ffield._dirty_flag = false;
|
|
|
|
$.when(ffield.set_value(data[field_name])).then(function() {
|
|
|
|
ffield._dirty_flag = true;
|
|
|
|
self.form_dialog.form.do_onchange(ffield);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
self.form_dialog.open();
|
2012-01-04 17:01:18 +00:00
|
|
|
});
|
2011-08-04 14:54:53 +00:00
|
|
|
});
|
2011-08-03 11:05:50 +00:00
|
|
|
},
|
2011-12-01 23:07:36 +00:00
|
|
|
do_save_event: function(event_id, event_obj) {
|
|
|
|
var self = this,
|
|
|
|
data = this.get_event_data(event_obj),
|
|
|
|
index = this.dataset.get_id_index(event_id);
|
|
|
|
if (index != null) {
|
2011-12-12 15:14:26 +00:00
|
|
|
event_id = this.dataset.ids[index];
|
2011-12-01 23:07:36 +00:00
|
|
|
this.dataset.write(event_id, data, {}, function() {
|
|
|
|
self.refresh_minical();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2011-08-03 11:05:50 +00:00
|
|
|
do_delete_event: function(event_id, event_obj) {
|
2011-08-04 10:07:31 +00:00
|
|
|
// dhtmlx sends this event even when it does not exist in openerp.
|
|
|
|
// Eg: use cancel in dhtmlx new event dialog
|
2011-12-01 23:07:36 +00:00
|
|
|
var self = this,
|
|
|
|
index = this.dataset.get_id_index(event_id);
|
|
|
|
if (index !== null) {
|
|
|
|
this.dataset.unlink(event_id, function() {
|
2011-08-04 14:54:53 +00:00
|
|
|
self.refresh_minical();
|
2011-08-08 14:18:40 +00:00
|
|
|
});
|
2011-08-04 10:07:31 +00:00
|
|
|
}
|
2011-08-03 11:05:50 +00:00
|
|
|
},
|
2012-03-12 12:58:12 +00:00
|
|
|
do_edit_event: function(event_id, evt) {
|
2011-10-19 10:21:49 +00:00
|
|
|
var self = this;
|
2011-12-01 23:07:36 +00:00
|
|
|
var index = this.dataset.get_id_index(event_id);
|
|
|
|
if (index !== null) {
|
2011-08-09 15:49:19 +00:00
|
|
|
this.dataset.index = index;
|
2012-04-10 14:29:01 +00:00
|
|
|
this.do_switch_view('form');
|
2011-12-01 23:07:36 +00:00
|
|
|
} else if (scheduler.getState().mode === 'month') {
|
2011-12-12 15:06:09 +00:00
|
|
|
var event_obj = scheduler.getEvent(event_id);
|
|
|
|
if (event_obj._length === 1) {
|
|
|
|
event_obj['start_date'].addHours(8);
|
|
|
|
event_obj['end_date'] = new Date(event_obj['start_date']);
|
|
|
|
event_obj['end_date'].addHours(1);
|
2012-01-12 14:23:07 +00:00
|
|
|
} else {
|
2012-02-08 13:20:15 +00:00
|
|
|
event_obj['start_date'].addHours(8);
|
|
|
|
event_obj['end_date'].addHours(-4);
|
2011-12-12 15:06:09 +00:00
|
|
|
}
|
|
|
|
this.do_create_event_with_formdialog(event_id, event_obj);
|
2011-12-12 16:02:42 +00:00
|
|
|
// return false;
|
|
|
|
// Theorically, returning false should prevent the lightbox to open.
|
|
|
|
// It works, but then the scheduler is in a buggy state where drag'n drop
|
|
|
|
// related internal Event won't be fired anymore.
|
|
|
|
// I tried scheduler.editStop(event_id); but doesn't work either
|
|
|
|
// After losing one hour on this, here's a quick and very dirty fix :
|
|
|
|
$(".dhx_cancel_btn").click();
|
2012-03-12 12:58:12 +00:00
|
|
|
} else {
|
|
|
|
scheduler.editStop($(evt.target).hasClass('icon_save'));
|
2011-08-09 15:49:19 +00:00
|
|
|
}
|
|
|
|
},
|
2011-08-03 11:05:50 +00:00
|
|
|
get_event_data: function(event_obj) {
|
|
|
|
var data = {
|
|
|
|
name: event_obj.text
|
|
|
|
};
|
2012-04-17 12:26:11 +00:00
|
|
|
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;
|
|
|
|
this.do_ranged_search();
|
|
|
|
},
|
|
|
|
do_ranged_search: function() {
|
2012-01-25 08:53:10 +00:00
|
|
|
var self = this;
|
2011-08-11 16:07:54 +00:00
|
|
|
scheduler.clearAll();
|
2011-12-13 16:22:35 +00:00
|
|
|
$.when(this.has_been_loaded, this.ready).then(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-01-10 16:54:51 +00:00
|
|
|
}).then(function(events) {
|
2011-09-29 12:19:02 +00:00
|
|
|
self.dataset_events = events;
|
|
|
|
self.on_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() {
|
2012-04-17 12:26:11 +00:00
|
|
|
var format = instance.web.date_to_str,
|
2011-12-13 16:22:35 +00:00
|
|
|
domain = this.last_search[0].slice(0);
|
|
|
|
domain.unshift([this.date_start, '>=', format(this.range_start.clone().addDays(-6))]);
|
|
|
|
domain.unshift([this.date_start, '<=', format(this.range_stop.clone().addDays(6))]);
|
|
|
|
return domain;
|
|
|
|
},
|
2011-08-01 12:48:02 +00:00
|
|
|
do_show: function () {
|
2011-08-01 15:48:56 +00:00
|
|
|
var self = this;
|
|
|
|
$.when(this.has_been_loaded).then(function() {
|
|
|
|
self.$element.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 [];
|
2011-04-13 12:50:42 +00:00
|
|
|
}
|
2011-04-07 16:41:06 +00:00
|
|
|
});
|
2011-08-01 15:48:56 +00:00
|
|
|
|
2012-04-17 12:26:11 +00:00
|
|
|
instance.web_calendar.CalendarFormDialog = instance.web.Dialog.extend({
|
2011-08-09 15:49:19 +00:00
|
|
|
init: function(view, options, view_id, dataset) {
|
|
|
|
this._super(view, options);
|
|
|
|
this.dataset = dataset;
|
|
|
|
this.view_id = view_id;
|
|
|
|
this.view = view;
|
|
|
|
},
|
|
|
|
start: function() {
|
2011-12-21 13:57:16 +00:00
|
|
|
var self = this;
|
2011-08-10 12:05:48 +00:00
|
|
|
this._super();
|
2012-04-17 12:26:11 +00:00
|
|
|
this.form = new instance.web.FormView(this, this.dataset, this.view_id, {
|
2011-08-09 15:49:19 +00:00
|
|
|
pager: false
|
|
|
|
});
|
2012-08-16 10:03:53 +00:00
|
|
|
var def = this.form.appendTo(this.$element);
|
2011-08-09 15:49:19 +00:00
|
|
|
this.form.on_created.add_last(this.on_form_dialog_saved);
|
|
|
|
this.form.on_saved.add_last(this.on_form_dialog_saved);
|
2011-12-21 13:57:16 +00:00
|
|
|
this.form.on_button_cancel = function() {
|
2011-12-19 16:13:42 +00:00
|
|
|
self.close();
|
2011-12-21 13:57:16 +00:00
|
|
|
}
|
2012-08-16 10:03:53 +00:00
|
|
|
return def;
|
2011-08-09 15:49:19 +00:00
|
|
|
},
|
|
|
|
on_form_dialog_saved: function() {
|
|
|
|
var id = this.dataset.ids[this.dataset.index];
|
|
|
|
if (this.view.creating_event_id) {
|
|
|
|
scheduler.changeEventId(this.view.creating_event_id, id);
|
|
|
|
this.view.creating_event_id = null;
|
|
|
|
}
|
|
|
|
this.view.reload_event(id);
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
on_close: function() {
|
|
|
|
if (this.view.creating_event_id) {
|
|
|
|
scheduler.deleteEvent(this.view.creating_event_id);
|
|
|
|
this.view.creating_event_id = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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({
|
|
|
|
container: this.$element.find('.oe_calendar_mini')[0],
|
|
|
|
navigation: true,
|
|
|
|
date: scheduler._date,
|
|
|
|
handler: function(date, calendar) {
|
|
|
|
scheduler.setCurrentView(date, 'day');
|
|
|
|
}
|
|
|
|
});
|
2012-04-17 12:26:11 +00:00
|
|
|
this.filter = new instance.web_calendar.SidebarFilter(this, this.getParent());
|
2012-04-10 16:05:09 +00:00
|
|
|
this.filter.appendTo(this.$element.find('.oe_calendar_filter'));
|
|
|
|
}
|
|
|
|
});
|
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: {
|
|
|
|
'change input:checkbox': 'on_filter_click'
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
on_events_loaded: function(filters) {
|
2012-01-12 11:09:53 +00:00
|
|
|
var selected_filters = this.view.selected_filters.slice(0);
|
2012-04-10 16:05:09 +00:00
|
|
|
this.$element.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
|
|
|
},
|
2011-08-11 16:07:54 +00:00
|
|
|
on_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) {
|
|
|
|
this.view.on_events_loaded(this.view.dataset_events, function(filter_value) {
|
|
|
|
return _.indexOf(responsibles, filter_value.toString()) > -1;
|
|
|
|
}, true);
|
|
|
|
} else {
|
|
|
|
this.view.on_events_loaded(this.view.dataset_events, false, true);
|
|
|
|
}
|
2011-08-01 15:48:56 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-04-07 16:41:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// DEBUG_RPC:rpc.request:('execute', 'addons-dsh-l10n_us', 1, '*', ('ir.filters', 'get_filters', u'res.partner'))
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|