aboutsummaryrefslogtreecommitdiff
path: root/views/default/event_calendar/full_calendar_view.php
blob: d4e85724ef35caaa34ca9b661dd7ca210b68c225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
elgg_load_js('elgg.full_calendar');

$events = $vars['events'];

$event_array = array();
$times_supported = elgg_get_plugin_setting('times','event_calendar') != 'no';

foreach($events as $e) {
	$event_item = array(
		'guid' => $e->guid,
		'title' => $e->title,
		'start_date' => $e->start_date,
		'end_date' => $e->real_end_time,
	);
	if ($times_supported) {
		$event_item['allDay'] = FALSE;
	} else {
		$event_item['allDay'] = TRUE;
	}

	$event_array[] = $event_item;
}

$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({
			guid: events[i].guid,
			title : events[i].title,
			start : new Date(1000*events[i].start_date),
			end : new Date(1000*events[i].end_date),
			allDay: events[i].allDay
		});
	}
	
	$('#calendar').fullCalendar({
		header: {
			left: 'prev,next today',
			center: 'title',
			right: 'month,agendaWeek,agendaDay'
		},
		editable: true,
		slotMinutes: 5,
		eventDrop: handleEventDrop,
		events: cal_events
	});
});
</script>
<div id='calendar'></div>