-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendarApp.js
141 lines (120 loc) · 4.54 KB
/
calendarApp.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// ************************** //
// Copyright Steven Mott 2016 //
// ************************** //
(function(app) {
app.calendarController = (function() {
var selectors = app.selectors;
var id = 0;
/**
* Creates and instance of calendarController
*
* @constructor
* @param {event[]} _events The events to initialize the calendars with.
* @param {panel} _panel The appointmentPanel to use with these calendars.
*/
function calendarController(_events, _panel) {
panel = _panel;
events = _events;
}
/**
* Initializes the calendarController.
*/
calendarController.prototype.init = function() {
id = events[events.length - 1].id + 1;
$(selectors.calendar).fullCalendar({
contentHeight: 'auto',
dayClick: function(date, jsEvent, view) {
changeDate(date);
},
editable: true,
events: function(start, end, timezone, callback) {
callback(events);
},
eventClick: function(calEvent, jsEvent, view) {
editAppointment(calEvent);
},
eventDrop: function(event, delta, revertFunc) {
updateAppointment(event);
},
eventLimit: true,
height: 'auto',
selectable: false
});
$(selectors.agenda).fullCalendar({
defaultView: 'agendaDay',
editable: true,
events: function(start, end, timezone, callback) {
callback(events);
},
eventClick: function(calEvent, jsEvent, view) {
editAppointment(calEvent);
},
eventDrop: function(event, delta, revertFunc) {
updateAppointment(event);
},
eventResize: function(event, delta, revertFunc) {
updateAppointment(event);
},
height: 'parent',
select: function(start, end) {
createAppointment(start, end);
},
selectable: true,
selectHelper: false,
viewRender: function(view, element) {
updateCalendarSelectedDate(view.start);
}
});
}
var changeDate = function(date) {
$(selectors.agenda).fullCalendar('gotoDate', date);
}
var updateCalendarSelectedDate = function(moment) {
$(selectors.calendar).fullCalendar('unselect');
$(selectors.calendar).fullCalendar('select', moment);
}
var createAppointment = function (start, end) {
var event = {
id: id++,
title: 'Event name',
start: start,
end: end
};
$(selectors.appointmentPanel).on('saveEvent', function(_event, calEvent) {
_event.stopPropagation();
events.push(calEvent);
updateCalendarViews();
$(selectors.appointmentPanel).off();
});
panel.show(event);
}
var editAppointment = function (event) {
var eventToEdit = getEventForEdit(event);
$(selectors.appointmentPanel).on('saveEvent', function(_event, calEvent) {
_event.stopPropagation();
eventToEdit.title = event.title;
eventToEdit.description = event.description;
updateCalendarViews();
$(selectors.appointmentPanel).off();
});
panel.show(event);
}
var getEventForEdit = function (event) {
return events.find(function(value) {
return value.id === event.id;
});
}
var updateAppointment = function(event) {
var eventToUpdate = getEventForEdit(event);
eventToUpdate.title = event.title;
eventToUpdate.start = event.start;
eventToUpdate.end = event.end;
updateCalendarViews();
}
var updateCalendarViews = function() {
$(selectors.calendar).fullCalendar('refetchEvents');
$(selectors.agenda).fullCalendar('refetchEvents');
}
return calendarController;
})();
})(window.app || (window.app = {}));