[FIX] calendar: Various fixes
Traceback when: * click on first row of calendar * move an event somewhere else with drag and drop * click on the mini calendar * filter from the control panel triggers a traceback * add an attendee: traceback * day/week/month: traceback * cannot add a leave, the fromViewDialog does not open * one day oo server-side when select all day
This commit is contained in:
@@ -102,7 +102,7 @@ var CalendarController = AbstractController.extend({
|
||||
* @param {integer} record.id
|
||||
*/
|
||||
_updateRecord: function (record) {
|
||||
this.model.updateRecord(record).reload.bind(this);
|
||||
this.model.updateRecord(record).then(this.reload.bind(this));
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -156,7 +156,7 @@ var CalendarController = AbstractController.extend({
|
||||
}, function () {
|
||||
// This will occurs if there are some more fields required
|
||||
event.data.options.disable_quick_create = true;
|
||||
event.data.options.on_save = this.destroy.bind(this);
|
||||
event.data.data.on_save = self.quick.destroy.bind(self.quick);
|
||||
self._onOpenCreate(event.data);
|
||||
});
|
||||
},
|
||||
@@ -170,17 +170,17 @@ var CalendarController = AbstractController.extend({
|
||||
}
|
||||
var data = this.model.calendarEventToRecord(event.data);
|
||||
|
||||
var context = _.extend({}, this.context);
|
||||
context.default_name = data.name;
|
||||
context['default_' + this.mapping.date_start] = data.start;
|
||||
var context = _.extend({}, this.context, event.options && event.options.context);
|
||||
context.default_name = data.name || null;
|
||||
context['default_' + this.mapping.date_start] = data.start || null;
|
||||
if (this.mapping.date_stop) {
|
||||
context['default_' + this.mapping.date_stop] = data.stop;
|
||||
context['default_' + this.mapping.date_stop] = data.stop || null;
|
||||
}
|
||||
if (this.mapping.date_delay) {
|
||||
context['default_' + this.mapping.date_delay] = data.duration;
|
||||
context['default_' + this.mapping.date_delay] = data.duration || null;
|
||||
}
|
||||
if (this.mapping.all_day) {
|
||||
context['default_' + this.mapping.all_day] = data[this.mapping.all_day];
|
||||
context['default_' + this.mapping.all_day] = data[this.mapping.all_day] || null;
|
||||
}
|
||||
|
||||
for (var k in context) {
|
||||
@@ -189,9 +189,9 @@ var CalendarController = AbstractController.extend({
|
||||
}
|
||||
}
|
||||
|
||||
var options = _.extend({}, this.options, {context: context});
|
||||
var options = _.extend({}, this.options, event.options, {context: context});
|
||||
|
||||
if(!options.disable_quick_create && !event.data.disable_quick_create) {
|
||||
if(!options.disable_quick_create && !event.data.disable_quick_create && this.quick_add_pop) {
|
||||
if (this.quick != null) {
|
||||
this.quick.destroy();
|
||||
this.quick = null;
|
||||
|
||||
@@ -42,7 +42,7 @@ return AbstractModel.extend({
|
||||
end = start.clone().add(1, 'h');
|
||||
}
|
||||
|
||||
if (event.allDay || end.diff(start) === 86400000) {
|
||||
if (event.allDay || end.diff(start) % 86400000 === 0) {
|
||||
event.allDay = true;
|
||||
|
||||
if (this.scale === 'month') {
|
||||
@@ -62,7 +62,7 @@ return AbstractModel.extend({
|
||||
}
|
||||
} else if (this.mapping.all_day) {
|
||||
start.startOf('day');
|
||||
end.startOf('day');
|
||||
end.startOf('day').add(-1, 'days');
|
||||
} else {
|
||||
// default hours in the user's timezone
|
||||
start.hours(7).add(-this.getSession().tzOffset, 'minutes');
|
||||
@@ -235,6 +235,9 @@ return AbstractModel.extend({
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
reload: function (_handle, params) {
|
||||
if (params.domain) {
|
||||
this.data.domain = params.domain;
|
||||
}
|
||||
return this._loadCalendar();
|
||||
},
|
||||
/**
|
||||
@@ -290,7 +293,6 @@ return AbstractModel.extend({
|
||||
model: this.modelName,
|
||||
method: 'write',
|
||||
args: [record.id, data],
|
||||
context: _.pick(event.data.options, 'context'),
|
||||
});
|
||||
},
|
||||
|
||||
@@ -590,6 +592,10 @@ return AbstractModel.extend({
|
||||
date_start.add(this.getSession().tzOffset, 'minutes');
|
||||
date_stop.add(this.getSession().tzOffset, 'minutes');
|
||||
|
||||
if (this.mapping.all_day && evt[this.mapping.all_day]) {
|
||||
date_stop.add(1, 'days');
|
||||
}
|
||||
|
||||
var r = {
|
||||
'record': evt,
|
||||
'start': date_start,
|
||||
@@ -610,7 +616,7 @@ return AbstractModel.extend({
|
||||
r.reset_allday = r.allDay;
|
||||
r.allDay = true;
|
||||
r.start = date_start.format('YYYY-MM-DD');
|
||||
r.end = date_stop.clone().add(1, 'day').startOf('day').format('YYYY-MM-DD');
|
||||
r.end = date_stop.startOf('day').format('YYYY-MM-DD');
|
||||
}
|
||||
|
||||
return r;
|
||||
|
||||
@@ -314,10 +314,13 @@ return AbstractRenderer.extend({
|
||||
event.title = $render.find('.o_field_type_char:first').text();
|
||||
element.find('.fc-content').html($render.html());
|
||||
element.addClass($render.attr('class'));
|
||||
var display_hour = (event.start.format('HH:mm') === '00:00' ? event.r_start.format('HH:mm') : event.start.format('HH:mm')) + ' - ' +
|
||||
(event.end && event.end.format('HH:mm') !== '00:00' ? event.end.format('HH:mm') : event.r_end.format('HH:mm'));
|
||||
if (display_hour === '00:00 - 00:00') {
|
||||
display_hour = _t('All the day');
|
||||
var display_hour = '';
|
||||
if (!event.allDay) {
|
||||
display_hour = (event.start.format('HH:mm') === '00:00' ? event.r_start.format('HH:mm') : event.start.format('HH:mm')) + ' - ' +
|
||||
(event.end && event.end.format('HH:mm') !== '00:00' ? event.end.format('HH:mm') : event.r_end.format('HH:mm'));
|
||||
if (display_hour === '00:00 - 00:00') {
|
||||
display_hour = _t('All the day');
|
||||
}
|
||||
}
|
||||
element.find('.fc-content .fc-time').text(display_hour);
|
||||
},
|
||||
@@ -336,7 +339,7 @@ return AbstractRenderer.extend({
|
||||
this.$small_calendar.datepicker({
|
||||
'onSelect': function (datum, obj) {
|
||||
self.trigger_up('changeDate', {
|
||||
date: new Date(+obj.currentYear , +obj.currentMonth, +obj.currentDay).toString()
|
||||
date: moment(new Date(+obj.currentYear , +obj.currentMonth, +obj.currentDay))
|
||||
});
|
||||
},
|
||||
'dayNamesMin' : this.state.fc_options.dayNamesShort,
|
||||
|
||||
@@ -108,7 +108,7 @@ var CalendarView = AbstractView.extend({
|
||||
//if quick_add = False, we don't allow quick_add
|
||||
//if quick_add = not specified in view, we use the default widgets.QuickCreate
|
||||
//if quick_add = is NOT False and IS specified in view, we this one for widgets.QuickCreate'
|
||||
this.controllerParams.quick_add_pop = (attrs.quick_add || utils.toBoolElse(attrs.quick_add+'', true));
|
||||
this.controllerParams.quick_add_pop = (!('quick_add' in attrs) || utils.toBoolElse(attrs.quick_add+'', true));
|
||||
this.controllerParams.disable_quick_create = params.disable_quick_create || !this.controllerParams.quick_add_pop;
|
||||
this.controllerParams.confirm_on_delete = true;
|
||||
// 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
|
||||
|
||||
@@ -396,8 +396,8 @@ function dragAndDrop($el, $to) {
|
||||
function triggerMouseEvent($el, type) {
|
||||
var pos = $el.offset();
|
||||
var e = new $.Event(type);
|
||||
e.pageX = pos.left;
|
||||
e.pageY = pos.top;
|
||||
e.pageX = e.layerX = e.screenX = pos.left;
|
||||
e.pageY = e.layerY = e.screenY =pos.top;
|
||||
e.which = 1;
|
||||
$el.trigger(e);
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ QUnit.module('Views', {
|
||||
});
|
||||
|
||||
QUnit.test('create event with timezone in week mode', function (assert) {
|
||||
assert.expect(7);
|
||||
assert.expect(8);
|
||||
|
||||
this.data.event.records = [];
|
||||
|
||||
@@ -362,6 +362,17 @@ QUnit.module('Views', {
|
||||
session: {
|
||||
tzOffset: 120
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === "write") {
|
||||
assert.deepEqual(args.args[1], {
|
||||
"allday": false,
|
||||
"start": "2016-12-12 06:00:00",
|
||||
"stop": "2016-12-12 10:00:00"
|
||||
},
|
||||
"should move the event");
|
||||
}
|
||||
return this._super(route, args);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -433,10 +444,108 @@ QUnit.module('Views', {
|
||||
},
|
||||
"the new record should have the utc datetime (formViewDialog)");
|
||||
|
||||
testUtils.triggerPositionalMouseEvent(left, top, "mousedown");
|
||||
left = calendar.$('.fc-day:eq(1)').offset().left + 5;
|
||||
testUtils.triggerPositionalMouseEvent(left, top, "mousemove");
|
||||
testUtils.triggerPositionalMouseEvent(left, top, "mouseup");
|
||||
|
||||
calendar.destroy();
|
||||
$view.remove();
|
||||
});
|
||||
|
||||
QUnit.test('create all day event', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
this.data.event.records = [];
|
||||
|
||||
var calendar = createView({
|
||||
View: CalendarView,
|
||||
model: 'event',
|
||||
data: this.data,
|
||||
arch:
|
||||
'<calendar class="o_calendar_test" '+
|
||||
'scale_zoom="week" '+
|
||||
'date_start="start" '+
|
||||
'date_stop="stop" '+
|
||||
'all_day="allday" '+
|
||||
'mode="week" '+
|
||||
'readonly_form_view_id="1">'+
|
||||
'<field name="name"/>'+
|
||||
'</calendar>',
|
||||
archs: archs,
|
||||
viewOptions: {
|
||||
initialDate: initialDate,
|
||||
},
|
||||
session: {
|
||||
tzOffset: 120
|
||||
},
|
||||
});
|
||||
|
||||
var $view = $('#qunit-fixture').contents();
|
||||
$view.prependTo('body'); // => select with click position
|
||||
|
||||
|
||||
var pos = calendar.$('.fc-bg td:eq(4)').offset();
|
||||
testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousedown");
|
||||
pos = calendar.$('.fc-bg td:eq(5)').offset();
|
||||
testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousemove");
|
||||
testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mouseup");
|
||||
|
||||
$('.modal input:first').val('new event').trigger('input');
|
||||
$('.modal button.btn:contains(Create)').trigger('click');
|
||||
var $newevent = calendar.$('.fc-event:contains(new event)');
|
||||
|
||||
assert.strictEqual($newevent.text().replace(/[\s\n\r]+/g, ''), "newevent",
|
||||
"should display the new event with time and title");
|
||||
|
||||
assert.deepEqual($newevent.data('fcSeg').event.record,
|
||||
{
|
||||
display_name: "new event",
|
||||
start: "2016-12-14 00:00:00",
|
||||
stop: "2016-12-15 00:00:00",
|
||||
allday: true,
|
||||
name: "new event",
|
||||
id: 1
|
||||
},
|
||||
"the new record should have the utc datetime (quickCreate)");
|
||||
|
||||
calendar.destroy();
|
||||
$view.remove();
|
||||
});
|
||||
|
||||
QUnit.test('use mini calendar', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var calendar = createView({
|
||||
View: CalendarView,
|
||||
model: 'event',
|
||||
data: this.data,
|
||||
arch:
|
||||
'<calendar class="o_calendar_test" '+
|
||||
'scale_zoom="week" '+
|
||||
'date_start="start" '+
|
||||
'date_stop="stop" '+
|
||||
'all_day="allday" '+
|
||||
'mode="week" '+
|
||||
'readonly_form_view_id="1">'+
|
||||
'<field name="name"/>'+
|
||||
'</calendar>',
|
||||
archs: archs,
|
||||
viewOptions: {
|
||||
initialDate: initialDate,
|
||||
},
|
||||
session: {
|
||||
tzOffset: 120
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(calendar.$('.fc-event').length, 9, "should display 9 events on the week (4 event + 5 days event)");
|
||||
$('.o_calendar_mini a:contains(19)').click();
|
||||
assert.strictEqual(calendar.$('.fc-event').length, 4, "should display 4 events on the week (1 event + 3 days event)");
|
||||
|
||||
calendar.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('rendering, with many2many', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user