Fix moving events from/to all-day section (#365); sanity check when saving data
This commit is contained in:
parent
fec6efe6a4
commit
03bbe1f925
3 changed files with 31 additions and 3 deletions
|
@ -31,6 +31,7 @@ function rcube_calendar_ui(settings)
|
|||
|
||||
/*** private vars ***/
|
||||
var DAY_MS = 86400000;
|
||||
var HOUR_MS = 3600000;
|
||||
var me = this;
|
||||
var gmt_offset = (new Date().getTimezoneOffset() / -60) - (settings.timezone || 0);
|
||||
var day_clicked = day_clicked_ts = 0;
|
||||
|
@ -1990,9 +1991,29 @@ function rcube_calendar_ui(settings)
|
|||
},
|
||||
// callback when an event was dragged and finally dropped
|
||||
eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc) {
|
||||
if (event.end == null) {
|
||||
event.end = event.start;
|
||||
if (event.end == null || event.end.getTime() < event.start.getTime()) {
|
||||
event.end = new Date(event.start.getTime() + (allDay ? DAY_MS : HOUR_MS));
|
||||
}
|
||||
// moved to all-day section: set times to 00:00 - 23:59
|
||||
if (allDay && !event.allday) {
|
||||
event.start.setHours(0);
|
||||
event.start.setMinutes(0);
|
||||
event.start.setSeconds(0);
|
||||
event.end.setHours(23);
|
||||
event.end.setMinutes(59);
|
||||
event.end.setSeconds(0);
|
||||
}
|
||||
// moved from all-day section: set times to working hours
|
||||
else if (event.allday && !allDay && minuteDelta) {
|
||||
var start = event.start.getTime();
|
||||
revertFunc();
|
||||
var numdays = Math.max(1, Math.round((event.end.getTime() - event.start.getTime()) / DAY_MS)) - 1;
|
||||
event.start = new Date(start);
|
||||
event.end = new Date(start + numdays * DAY_MS);
|
||||
event.end.setHours(settings['work_end'] || 18);
|
||||
event.end.setMinutes(0);
|
||||
}
|
||||
|
||||
// send move request to server
|
||||
var data = {
|
||||
id: event.id,
|
||||
|
|
|
@ -355,6 +355,8 @@ class database_driver extends calendar_driver
|
|||
// process event attendees
|
||||
$_attendees = '';
|
||||
foreach ((array)$event['attendees'] as $attendee) {
|
||||
if (!$attendee['name'] && !$attendee['email'])
|
||||
continue;
|
||||
$_attendees .= 'NAME="'.addcslashes($attendee['name'], '"') . '"' .
|
||||
';STATUS=' . $attendee['status'].
|
||||
';ROLE=' . $attendee['role'] .
|
||||
|
@ -732,7 +734,7 @@ class database_driver extends calendar_driver
|
|||
$event['attendees'] = $attendees;
|
||||
}
|
||||
|
||||
unset($event['event_id'], $event['calendar_id'], $event['notifyat'], $event['_attachments']);
|
||||
unset($event['event_id'], $event['calendar_id'], $event['notifyat'], $event['all_day'], $event['_attachments']);
|
||||
return $event;
|
||||
}
|
||||
|
||||
|
|
|
@ -700,6 +700,11 @@ class kolab_calendar
|
|||
$object['end-date'] += 60; // end is at 23:59 => jump to the next day
|
||||
$object['end-date'] += $tz_offset - date('Z'); // shift 00 times from user's timezone to server's timezone
|
||||
$object['start-date'] += $tz_offset - date('Z'); // because Horde_Kolab_Format_Date::encodeDate() uses strftime()
|
||||
|
||||
// sanity check: end date is same or smaller than start
|
||||
if (date('Y-m-d', $object['end-date']) <= date('Y-m-d', $object['start-date']))
|
||||
$object['end-date'] = mktime(0,0,0, date('n', $object['start-date']), date('j', $object['start-date']), date('Y', $object['start-date'])) + 86400;
|
||||
|
||||
$object['_is_all_day'] = 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue