My favorites
▼
|
Sign in
fullcalendar
ISSUE TRACKER HAS MOVED. DO NOT USE THIS (more info)
Project Home
Issues
Export to GitHub
New issue
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
932
attachment: calendar_ext.js
(10.0 KB)
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
function toggle_worked_in_country() {
range_type = $('#type option:selected').text();
if (range_type == 'workday') {
$("#worked_in_country").attr('disabled', '');
$("#worked_in_country").attr('checked', 'checked');
}
else {
$("#worked_in_country").attr('disabled', 'disabled');
}
}
function toggle_alternate_location() {
worked_in_country = $("#worked_in_country").attr('checked')
if (worked_in_country == false) {
$('#alternate_location').attr('disabled', '');
$('#alternate_location_container').show()
}else {
$('#alternate_location').attr('disabled', 'disabled');
$('#alternate_location_container').hide()
}
}
$(document).ready(function() {
var url = window.location.pathname
var url_array = url.split('/')
var company_id = url_array[2]
var employee_id = url_array[4]
$("#worked_in_country").attr('disabled', 'disabled');
$('#alternate_location').attr('disabled', 'disabled');
$("#worked_in_country").change(function() {
toggle_alternate_location();
})
$(function() {
var title = $( "#title" ),
employee_name = $("#employee_name"),
worked_in_country = $("#worked_in_country"),
alternate_location = $("#alternate_location"),
type = $("#type")
allFields = $([]).add(worked_in_country).add(type).add(employee_name).add(alternate_location),
tips = $(".validate_tips");
function updateTips(t) {
tips
.text(t)
.addClass( "ui-state-highlight" );
setTimeout(function() {
tips.removeClass( "ui-state-highlight", 1500 );
}, 500 );
}
function checkLength( o, n, min, max ) {
if ( o.val().length > max || o.val().length < min ) {
o.addClass( "ui-state-error" );
updateTips( "Length of " + n + " must be between " +
min + " and " + max + "." );
return false;
} else {
return true;
}
}
function selectRequired(element) {
var select = $(element)
if (select.val() == "" || select.val() == null) {
updateTips("you must select the type of work range")
return false;
}
else {
return true;
}
}
function alternate_location_required() {
var alternate_location = $('#alternate_location').val()
if (alternate_location == '' || alternate_location == 'null') {
updateTips("you must select the country that you were located in")
return false
}else {
return true
}
}
function date_from_string(string) {
var date_string = string.replace('-', ',')
var date_string = date_string.replace('-', ',')
var date_array = date_string.split(',')
month = date_array[1] - 1
date = new Date(date_array[0], month, date_array[2], 0, 0, 0);
return date
}
function rangeIsOnlyWithinThisMonth(start, end) {
start_date = date_from_string(start)
end_date = date_from_string(end)
var currentTime = new Date()
var this_month = currentTime.getMonth() + 1
var starting_month = start_date.getMonth() + 1
var ending_month = end_date.getMonth() + 1
if (starting_month != this_month || ending_month != this_month) {
updateTips('you can only report time for this month')
return false;
}
else {
return true;
}
}
function not_duplicate_day(start) {
var duplicate_days = 0
rendered_events = $('#calendar').fullCalendar('clientEvents')
$.each(rendered_events, function(k, e) {
event_start = date_from_string(start)
if (e.start.toDateString() == event_start.toDateString()) {
duplicate_days++
}
})
if (duplicate_days > 0) {
updateTips('you cannot have 2 events on the same day');
return false
}else {
return true
}
}
function checkRegexp( o, regexp, n ) {
if ( !( regexp.test( o.val() ) ) ) {
o.addClass( "ui-state-error" );
updateTips( n );
return false;
} else {
return true;
}
}
$( "#day_form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Add a Date Range": function() {
var bValid = true;
allFields.removeClass( "ui-state-error" );
bValid = bValid && selectRequired($('#type'));
bValid = bValid && rangeIsOnlyWithinThisMonth($(this).data('start'), $(this).data('end'))
bValid = bValid && not_duplicate_day($(this).data('start'))
if ($('#worked_in_country').attr('checked')) {
bValid = bValid && alternate_location_required()
}
if (bValid) {
if ($(worked_in_country).attr('disabled')) {
wic = null
} else {
wic = worked_in_country.attr('checked')
}
var eventObject = {
title: employee_name.text(),
worked_in_country: wic,
range_type: $('#type option:selected').text(),
alternate_location: $('#alternate_location option:selected').text(),
start: $(this).data('start'),
end: $(this).data('end')
};
add_event(company_id, employee_id, eventObject)
$(this).dialog( "close" );
}
},
Cancel: function() {
$(this).dialog( "close" );
}
},
close: function() {
allFields.val( "" ).removeClass( "ui-state-error" );
}
}); //end of dialog
var calendar = $('#calendar').fullCalendar({
header: {
left: 'nothing',
center: 'title',
right: false
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var start_day = start.getDate();
var start_month = start.getMonth() + 1;
var start_year = start.getFullYear();
start_formatted = start_year + '-' + start_month + '-' + start_day
var end_day = end.getDate();
var end_month = end.getMonth() + 1;
var end_year = end.getFullYear();
end_formatted = end_year + '-' + end_month + '-' + end_day
$('#day_form')
.data('start', start_formatted)
.data('end', end_formatted)
.dialog('open');
$('#date_range_form').clearForm()
calendar.fullCalendar('unselect');
},
editable: false,
deleteable: true,
eventSources: [
'/companies/' + company_id + '/employees/' + employee_id + '/work_ranges.json'
// 'http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic'
],
eventRender: function(event, element) {
var child = $(element).child()
$(element).append('<a href="#" class="remove-event">remove</a>')
var delete_link = $(element).last()
$(delete_link).click(function(e) {
var answer = confirm("are you sure you want to delete this event?")
if (answer) {
remove_event(company_id, employee_id, event.id)
};
});
var full_event_string = default_event_string(event)
if (event.worked_in_country != null) {
full_event_string += worked_in_country_event_text(event)
if (event.alternate_location != null) {
full_event_string += alternate_location_event_text(event)
};
};
$(child).html(full_event_string)
}
});
});
}); //end of anonymous function
function default_event_string(event) {
return "<p>Employee: " + event.title + "</p><p>Range Type: " + event.range_type + "</p>"
}
function worked_in_country_event_text(event) {
return "<p>Worked in country? " + event.worked_in_country + "</p>"
}
function alternate_location_event_text(event) {
return "<p>Alternate location: " + event.alternate_location + "</p>"
}
function remove_event(company_id, employee_id, event_id) {
$.ajax({
url: '/companies/' + company_id + '/employees/' + employee_id + '/work_ranges/' + event_id,
type: 'POST',
data: { '_method': 'delete' },
success: function() {
$("#calendar").fullCalendar('removeEvents', event_id);
}
});
}
function add_event(company_id, employee_id, event) {
$.ajax({
url: '/companies/' + company_id + '/employees/' + employee_id + '/work_ranges',
type: 'POST',
data: {
'event': event
},
success: function(msg, status, xhr) {
if (xhr.responseText == 'your event was saved') {
$('#calendar').fullCalendar('renderEvent', event, true);
$('#calendar').fullCalendar('rerenderEvents')
}
else {
errors = jQuery.parseJSON(xhr.responseText)
}
}
});
}
$.fn.child = function(s) {
return $(this).children(s)[0];
}
$.fn.clearForm = function() {
return this.each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
if (tag == 'form')
return $(':input',this).clearForm();
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = '';
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
});
};
Powered by
Google Project Hosting