diff options
-rw-r--r-- | languages/en.php | 1 | ||||
-rw-r--r-- | models/model.php | 39 | ||||
-rw-r--r-- | start.php | 1 | ||||
-rw-r--r-- | views/default/event_calendar/full_calendar_view.php | 37 |
4 files changed, 70 insertions, 8 deletions
diff --git a/languages/en.php b/languages/en.php index d58e35523..1a356524b 100644 --- a/languages/en.php +++ b/languages/en.php @@ -255,6 +255,7 @@ You can manage calendar requests for this event here: ."need to apply to do so (closed) or have no option at all (private - so only you or a site admin can add the event to calendars).", 'event_calendar:settings:full_calendar:title' => "Support full calendar", + 'event_calendar:modify_full_calendar:error' => "Error: could not modify full calendar", /** * Event calendar river diff --git a/models/model.php b/models/model.php index 76d2d7b61..f1ed39369 100644 --- a/models/model.php +++ b/models/model.php @@ -38,7 +38,7 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) { 'brief_description','fees','contact','organiser', 'tags'); - if ($event_calendar_times == 'yes') { + if ($event_calendar_times != 'no') { $required_fields[] = 'start_time'; if ($event_calendar_hide_end != 'yes') { $required_fields[] = 'end_time'; @@ -83,9 +83,15 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) { $start_date_text = date("Y-m-d",$start_date); $event->start_date = strtotime($start_date_text." ".date_default_timezone_get()); - $event->end_date = get_input('end_date',''); + $end_date = trim(get_input('end_date','')); + if ($end_date) { + $end_date_text = date("Y-m-d",$end_date); + $event->end_date = strtotime($end_date_text." ".date_default_timezone_get()); + } else { + $event->end_date = ''; + } - if ($event_calendar_times == 'yes') { + if ($event_calendar_times != 'no') { $sh = get_input('start_time_h',''); $sm = get_input('start_time_m',''); if (is_numeric($sh) && is_numeric($sm)) { @@ -961,7 +967,7 @@ function event_calendar_get_formatted_full_items($event) { function event_calendar_get_formatted_time($event) { $date_format = 'j M Y'; - $event_calendar_times = elgg_get_plugin_setting('times', 'event_calendar') == 'yes'; + $event_calendar_times = elgg_get_plugin_setting('times', 'event_calendar') != 'no'; $start_date = date($date_format,$event->start_date); if ((!$event->end_date) || ($event->end_date == $event->start_date)) { @@ -1731,3 +1737,28 @@ function getLastDayOfMonth($month,$year) { return idate('d', mktime(0, 0, 0, ($month + 1), 0, $year)); } +// TODO - this is not quite right across daylight savings time divides +// Possible solution: convert stored date to server date, do inc and then convert back to GMT + +function event_calendar_modify_full_calendar($event_guid,$day_delta,$minute_delta) { + $event = get_entity($event_guid); + if (elgg_instanceof($event,'object','event_calendar') && $event->canEdit()) { + $event->start_date = strtotime("$day_delta days",$event->start_date)+60*$minute_delta; + if ($event->end_date) { + $event->end_date = strtotime("$day_delta days",$event->end_date); + } + $times = elgg_get_plugin_setting('times','event_calendar'); + //$inc = 24*60*60*$day_delta+60*$minute_delta; + + //$event->real_end_time += $inc; + $event->real_end_time = strtotime("$day_delta days",$event->real_end_time)+60*$minute_delta; + if ($times != 'no') { + $event->start_time += $minute_delta; + if ($event->end_time) { + $event->end_time += $minute_delta; + } + } + return TRUE; + } + return FALSE; +} @@ -107,6 +107,7 @@ function event_calendar_init() { elgg_register_action("event_calendar/add_to_group_members","$action_path/add_to_group_members.php"); elgg_register_action("event_calendar/remove_from_group_members","$action_path/remove_from_group_members.php"); elgg_register_action("event_calendar/manage_subscribers","$action_path/manage_subscribers.php"); + elgg_register_action("event_calendar/modify_full_calendar","$action_path/modify_full_calendar.php"); } diff --git a/views/default/event_calendar/full_calendar_view.php b/views/default/event_calendar/full_calendar_view.php index 80406ac13..d4e85724e 100644 --- a/views/default/event_calendar/full_calendar_view.php +++ b/views/default/event_calendar/full_calendar_view.php @@ -8,7 +8,7 @@ $times_supported = elgg_get_plugin_setting('times','event_calendar') != 'no'; foreach($events as $e) { $event_item = array( - 'id' => $e->guid, + 'guid' => $e->guid, 'title' => $e->title, 'start_date' => $e->start_date, 'end_date' => $e->real_end_time, @@ -18,7 +18,7 @@ foreach($events as $e) { } else { $event_item['allDay'] = TRUE; } - + $event_array[] = $event_item; } @@ -27,12 +27,39 @@ $json_events_string = json_encode($event_array); // TODO: is there an easy way to avoid embedding JS? ?> <script> + +handleEventDrop = function(event,dayDelta,minuteDelta,allDay,revertFunc) { + + alert( + event.title + "(" + event.guid + ") was moved " + + dayDelta + " days and " + + minuteDelta + " minutes." + ); + + if (!confirm("Are you sure about this change?")) { + revertFunc(); + } else { + elgg.action('event_calendar/modify_full_calendar', + { + data: {event_guid: event.guid,dayDelta: dayDelta, minuteDelta: minuteDelta}, + success: function (res) { + var success = res.success; + var msg = res.message; + if (!success) { + elgg.register_error(msg,2000); + revertFunc() + } + } + } + ); + } +} $(document).ready(function() { var events = <?php echo $json_events_string; ?>; var cal_events = []; for (var i = 0; i < events.length; i++) { cal_events.push({ - id: events[i].id, + guid: events[i].guid, title : events[i].title, start : new Date(1000*events[i].start_date), end : new Date(1000*events[i].end_date), @@ -47,8 +74,10 @@ $(document).ready(function() { right: 'month,agendaWeek,agendaDay' }, editable: true, + slotMinutes: 5, + eventDrop: handleEventDrop, events: cal_events }); }); </script> -<div id='calendar'></div>
\ No newline at end of file +<div id='calendar'></div> |