diff options
author | Mario Vavti <mario@mariovavti.com> | 2019-05-21 12:29:00 +0200 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2019-05-21 12:29:00 +0200 |
commit | f96958adf84f7f2a45aa7860e52198f3de74f9e0 (patch) | |
tree | fed75c73887eb13dcf9eca1c93c6654ecaf8703c | |
parent | c9d64d75f3acab6b44d28cd7bcc6e7e5dd042e77 (diff) | |
download | volse-hubzilla-f96958adf84f7f2a45aa7860e52198f3de74f9e0.tar.gz volse-hubzilla-f96958adf84f7f2a45aa7860e52198f3de74f9e0.tar.bz2 volse-hubzilla-f96958adf84f7f2a45aa7860e52198f3de74f9e0.zip |
fix all day events for caldav calendars
-rw-r--r-- | Zotlabs/Module/Cdav.php | 60 | ||||
-rw-r--r-- | view/tpl/cdav_calendar.tpl | 23 |
2 files changed, 60 insertions, 23 deletions
diff --git a/Zotlabs/Module/Cdav.php b/Zotlabs/Module/Cdav.php index 275873db5..0c3450c70 100644 --- a/Zotlabs/Module/Cdav.php +++ b/Zotlabs/Module/Cdav.php @@ -274,9 +274,12 @@ class Cdav extends Controller { $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); $tz = (($timezone) ? $timezone : date_default_timezone_get()); + $allday = $_REQUEST['allday']; + $title = $_REQUEST['title']; $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); $dtstart = new \DateTime($start); + if($_REQUEST['dtend']) { $end = datetime_convert($tz, 'UTC', $_REQUEST['dtend']); $dtend = new \DateTime($end); @@ -304,16 +307,23 @@ class Cdav extends Controller { 'DTSTART' => $dtstart ] ]); + if($dtend) { $vcalendar->VEVENT->add('DTEND', $dtend); - $vcalendar->VEVENT->DTEND['TZID'] = $tz; + if($allday) + $vcalendar->VEVENT->DTEND['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTEND['TZID'] = $tz; } if($description) $vcalendar->VEVENT->add('DESCRIPTION', $description); if($location) $vcalendar->VEVENT->add('LOCATION', $location); - $vcalendar->VEVENT->DTSTART['TZID'] = $tz; + if($allday) + $vcalendar->VEVENT->DTSTART['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTSTART['TZID'] = $tz; $calendarData = $vcalendar->serialize(); @@ -354,6 +364,8 @@ class Cdav extends Controller { $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); $tz = (($timezone) ? $timezone : date_default_timezone_get()); + $allday = $_REQUEST['allday']; + $uri = $_REQUEST['uri']; $title = $_REQUEST['title']; $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); @@ -371,12 +383,23 @@ class Cdav extends Controller { if($title) $vcalendar->VEVENT->SUMMARY = $title; - if($dtstart) + if($dtstart) { $vcalendar->VEVENT->DTSTART = $dtstart; - if($dtend) + if($allday) + $vcalendar->VEVENT->DTSTART['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTSTART['TZID'] = $tz; + } + if($dtend) { $vcalendar->VEVENT->DTEND = $dtend; + if($allday) + $vcalendar->VEVENT->DTEND['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTEND['TZID'] = $tz; + } else unset($vcalendar->VEVENT->DTEND); + if($description) $vcalendar->VEVENT->DESCRIPTION = $description; if($location) @@ -415,6 +438,8 @@ class Cdav extends Controller { $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); $tz = (($timezone) ? $timezone : date_default_timezone_get()); + $allday = $_REQUEST['allday']; + $uri = $_REQUEST['uri']; $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); $dtstart = new \DateTime($start); @@ -429,13 +454,20 @@ class Cdav extends Controller { if($dtstart) { $vcalendar->VEVENT->DTSTART = $dtstart; + if($allday) + $vcalendar->VEVENT->DTSTART['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTSTART['TZID'] = $tz; } if($dtend) { $vcalendar->VEVENT->DTEND = $dtend; + if($allday) + $vcalendar->VEVENT->DTEND['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTEND['TZID'] = $tz; } - else { + else unset($vcalendar->VEVENT->DTEND); - } $calendarData = $vcalendar->serialize(); @@ -1001,6 +1033,9 @@ class Cdav extends Controller { $title = ['title', t('Event title') ]; $dtstart = ['dtstart', t('Start date and time')]; $dtend = ['dtend', t('End date and time')]; + $timezone_select = ['timezone_select' , t('Timezone:'), date_default_timezone_get(), '', get_timezones()]; + $allday = ['allday', t('All day event'), '', '', [t('No'), t('Yes')]]; + $description = ['description', t('Description')]; $location = ['location', t('Location')]; @@ -1061,7 +1096,8 @@ class Cdav extends Controller { '$resource' => json_encode($resource), '$categories' => $categories, - '$timezone_select' => ((feature_enabled(local_channel(),'event_tz_select')) ? ['timezone_select' , t('Timezone:'), date_default_timezone_get(), '', get_timezones()] : []) + '$timezone_select' => ((feature_enabled(local_channel(),'event_tz_select')) ? $timezone_select : ''), + '$allday' => $allday ]); @@ -1091,8 +1127,8 @@ class Cdav extends Controller { $filters['comp-filters'][0]['time-range']['end'] = $end; $uris = $caldavBackend->calendarQuery($id, $filters); - if($uris) { + $objects = $caldavBackend->getMultipleCalendarObjects($id, $uris); foreach($objects as $object) { @@ -1121,13 +1157,7 @@ class Cdav extends Controller { $timezone = $recurrent_timezone; } - $allDay = false; - - // allDay event rules - if(!strpos($dtstart, 'T') && !strpos($dtend, 'T')) - $allDay = true; - if(strpos($dtstart, 'T000000') && strpos($dtend, 'T000000')) - $allDay = true; + $allDay = (((string)$vevent->DTSTART['VALUE'] == 'DATE') ? true : false); $events[] = [ 'calendar_id' => $id, diff --git a/view/tpl/cdav_calendar.tpl b/view/tpl/cdav_calendar.tpl index 533c0add1..da4a6d156 100644 --- a/view/tpl/cdav_calendar.tpl +++ b/view/tpl/cdav_calendar.tpl @@ -17,6 +17,8 @@ var resource = {{$resource}}; var default_view = resource !== null ? 'timeGridDay' : 'dayGridMonth'; var default_date = resource !== null ? new Date(resource.dtstart) : new Date(); +var allday; + $(document).ready(function() { var calendarEl = document.getElementById('calendar'); calendar = new FullCalendar.Calendar(calendarEl, { @@ -43,7 +45,6 @@ $(document).ready(function() { dayNamesShort: aStr['dayNamesShort'], allDayText: aStr['allday'], - defaultTimedEventDuration: '01:00:00', snapDuration: '00:15:00', dateClick: function(info) { @@ -53,8 +54,10 @@ $(document).ready(function() { new_event = {}; } + allday = info.allDay; + var dtend = new Date(info.date.toUTCString()); - if(info.view.type == 'dayGridMonth') { + if(allday) { dtend.setDate(dtend.getDate() + 1); } else{ @@ -76,10 +79,10 @@ $(document).ready(function() { $('#event_submit').val('create_event').html('{{$create}}'); $('#event_delete').hide(); - new_event = { id: new_event_id, title : 'New event', start: $('#id_dtstart').val(), end: $('#id_dtend').val(), editable: true, color: '#bbb' }; + new_event = { id: new_event_id, title: 'New event', start: $('#id_dtstart').val(), end: $('#id_dtend').val(), allDay: info.allDay, editable: true, color: '#bbb' }; calendar.addEvent(new_event); }, - + eventClick: function(info) { //reset categories $('#id_categories').tagsinput('removeAll'); @@ -180,6 +183,7 @@ $(document).ready(function() { }, eventResize: function(info) { + console.log(info); var event = info.event._def; var dtstart = new Date(info.event._instance.range.start); @@ -219,7 +223,8 @@ $(document).ready(function() { 'uri': event.extendedProps.uri, 'timezone_select': event.extendedProps.timezone, 'dtstart': dtstart ? dtstart.toUTCString() : '', - 'dtend': dtend ? dtend.toUTCString() : '' + 'dtend': dtend ? dtend.toUTCString() : '', + 'allday': event.allDay ? 1 : 0 }) .fail(function() { info.revert(); @@ -267,7 +272,8 @@ $(document).ready(function() { 'uri': event.extendedProps.uri, 'timezone_select': event.extendedProps.timezone, 'dtstart': dtstart ? dtstart.toUTCString() : '', - 'dtend': dtend ? dtend.toUTCString() : '' + 'dtend': dtend ? dtend.toUTCString() : '', + 'allday': event.allDay ? 1 : 0 }) .fail(function() { info.revert(); @@ -424,7 +430,7 @@ function on_submit() { 'summary': $('#id_title').val(), 'dtstart': $('#id_dtstart').val(), 'dtend': $('#id_dtend').val(), - 'adjust': 1, + 'adjust': allday ? 0 : 1, 'categories': $('#id_categories').val(), 'desc': $('#id_description').val(), 'location': $('#id_location').val(), @@ -452,7 +458,8 @@ function on_submit() { 'dtstart': $('#id_dtstart').val(), 'dtend': $('#id_dtend').val(), 'description': $('#id_description').val(), - 'location': $('#id_location').val() + 'location': $('#id_location').val(), + 'allday': allday ? 1 : 0 }) .done(function() { var parts = $('#calendar_select').val().split(':'); |