-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
calendar.js
210 lines (169 loc) · 6.77 KB
/
calendar.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
document.addEventListener('DOMContentLoaded', function() {
var url ='./';
$('body').on('click', '.datetimepicker', function() {
$(this).not('.hasDateTimePicker').datetimepicker({
controlType: 'select',
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
timeFormat: 'HH:mm:ss',
yearRange: "1900:+10",
showOn:'focus',
firstDay: 1
}).focus();
});
$(".colorpicker").colorpicker();
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: ['interaction', 'dayGrid', 'timeGrid', 'list'],
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'
},
navLinks: true, // can click day/week names to navigate views
businessHours: true, // display business hours
editable: true,
//uncomment to have a default date
//defaultDate: '2020-04-07',
events: url+'api/load.php',
eventDrop: function(arg) {
var start = arg.event.start.toDateString()+' '+arg.event.start.getHours()+':'+arg.event.start.getMinutes()+':'+arg.event.start.getSeconds();
if (arg.event.end == null) {
end = start;
} else {
var end = arg.event.end.toDateString()+' '+arg.event.end.getHours()+':'+arg.event.end.getMinutes()+':'+arg.event.end.getSeconds();
}
$.ajax({
url:url+"api/update.php",
type:"POST",
data:{id:arg.event.id, start:start, end:end},
});
},
eventResize: function(arg) {
var start = arg.event.start.toDateString()+' '+arg.event.start.getHours()+':'+arg.event.start.getMinutes()+':'+arg.event.start.getSeconds();
var end = arg.event.end.toDateString()+' '+arg.event.end.getHours()+':'+arg.event.end.getMinutes()+':'+arg.event.end.getSeconds();
$.ajax({
url:url+"api/update.php",
type:"POST",
data:{id:arg.event.id, start:start, end:end},
});
},
eventClick: function(arg) {
var id = arg.event.id;
$('#editEventId').val(id);
$('#deleteEvent').attr('data-id', id);
$.ajax({
url:url+"api/getevent.php",
type:"POST",
dataType: 'json',
data:{id:id},
success: function(data) {
$('#editEventTitle').val(data.title);
$('#editStartDate').val(data.start);
$('#editEndDate').val(data.end);
$('#editColor').val(data.color);
$('#editTextColor').val(data.textColor);
$('#editeventmodal').modal();
}
});
$('body').on('click', '#deleteEvent', function() {
if(confirm("Are you sure you want to remove it?")) {
$.ajax({
url:url+"api/delete.php",
type:"POST",
data:{id:arg.event.id},
});
//close model
$('#editeventmodal').modal('hide');
//refresh calendar
calendar.refetchEvents();
}
});
calendar.refetchEvents();
}
});
calendar.render();
$('#createEvent').submit(function(event) {
// stop the form refreshing the page
event.preventDefault();
$('.form-group').removeClass('has-error'); // remove the error class
$('.help-block').remove(); // remove the error text
// process the form
$.ajax({
type : "POST",
url : url+'api/insert.php',
data : $(this).serialize(),
dataType : 'json',
encode : true
}).done(function(data) {
// insert worked
if (data.success) {
//remove any form data
$('#createEvent').trigger("reset");
//close model
$('#addeventmodal').modal('hide');
//refresh calendar
calendar.refetchEvents();
} else {
//if error exists update html
if (data.errors.date) {
$('#date-group').addClass('has-error');
$('#date-group').append('<div class="help-block">' + data.errors.date + '</div>');
}
if (data.errors.title) {
$('#title-group').addClass('has-error');
$('#title-group').append('<div class="help-block">' + data.errors.title + '</div>');
}
}
});
});
$('#editEvent').submit(function(event) {
// stop the form refreshing the page
event.preventDefault();
$('.form-group').removeClass('has-error'); // remove the error class
$('.help-block').remove(); // remove the error text
//form data
var id = $('#editEventId').val();
var title = $('#editEventTitle').val();
var start = $('#editStartDate').val();
var end = $('#editEndDate').val();
var color = $('#editColor').val();
var textColor = $('#editTextColor').val();
// process the form
$.ajax({
type : "POST",
url : url+'api/update.php',
data : {
id:id,
title:title,
start:start,
end:end,
color:color,
text_color:textColor
},
dataType : 'json',
encode : true
}).done(function(data) {
// insert worked
if (data.success) {
//remove any form data
$('#editEvent').trigger("reset");
//close model
$('#editeventmodal').modal('hide');
//refresh calendar
calendar.refetchEvents();
} else {
//if error exists update html
if (data.errors.date) {
$('#date-group').addClass('has-error');
$('#date-group').append('<div class="help-block">' + data.errors.date + '</div>');
}
if (data.errors.title) {
$('#title-group').addClass('has-error');
$('#title-group').append('<div class="help-block">' + data.errors.title + '</div>');
}
}
});
});
});