Blame view

sources/apps/calendar/js/calendar.js 36.6 KB
d1bafeea1   Kload   [fix] Upgrade to ...
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
  /**
   * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
   * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
   * This file is licensed under the Affero General Public License version 3 or
   * later.
   * See the COPYING-README file.
   */
  
  Calendar={
  	Util:{
  		sendmail: function(eventId, location, description, dtstart, dtend){
  			Calendar.UI.loading(true);
  			$.post(
  			OC.filePath('calendar','ajax/event','sendmail.php'),
  			{
  				eventId:eventId,
  				location:location,
  				description:description,
  				dtstart:dtstart,
  				dtend:dtend
  			},
  			function(result){
  				if(result.status !== 'success'){
  					OC.dialogs.alert(result.data.message, 'Error sending mail');
  				}
  				Calendar.UI.loading(false);
  			}
  		);
  		},
  		dateTimeToTimestamp:function(dateString, timeString){
  			dateTuple = dateString.split('-');
  			timeTuple = timeString.split(':');
  			
  			var day, month, year, minute, hour;
  			day = parseInt(dateTuple[0], 10);
  			month = parseInt(dateTuple[1], 10);
  			year = parseInt(dateTuple[2], 10);
  			hour = parseInt(timeTuple[0], 10);
  			minute = parseInt(timeTuple[1], 10);
  			
  			var date = new Date(year, month-1, day, hour, minute);
  			
  			return parseInt(date.getTime(), 10);
  		},
  		formatDate:function(year, month, day){
  			if(day < 10){
  				day = '0' + day;
  			}
  			if(month < 10){
  				month = '0' + month;
  			}
  			return day + '-' + month + '-' + year;
  		},
  		formatTime:function(hour, minute){
  			if(hour < 10){
  				hour = '0' + hour;
  			}
  			if(minute < 10){
  				minute = '0' + minute;
  			}
  			return hour + ':' + minute;
  		}, 
  		adjustDate:function(){
  			var fromTime = $('#fromtime').val();
  			var fromDate = $('#from').val();
  			var fromTimestamp = Calendar.Util.dateTimeToTimestamp(fromDate, fromTime);
  
  			var toTime = $('#totime').val();
  			var toDate = $('#to').val();
  			var toTimestamp = Calendar.Util.dateTimeToTimestamp(toDate, toTime);
  
  			if(fromTimestamp >= toTimestamp){
  				fromTimestamp += 30*60*1000;
  				
  				var date = new Date(fromTimestamp);
  				movedTime = Calendar.Util.formatTime(date.getHours(), date.getMinutes());
  				movedDate = Calendar.Util.formatDate(date.getFullYear(),
  						date.getMonth()+1, date.getDate());
  
  				$('#to').val(movedDate);
  				$('#totime').val(movedTime);
  			}
6d9380f96   Cédric Dupont   Update sources OC...
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
  		},
  		getDayOfWeek:function(iDay){
  			var weekArray=['sun','mon','tue','wed','thu','fri','sat'];
  			return weekArray[iDay];
  		},
  		setTimeline : function() {
  			var curTime = new Date();
  			if (curTime.getHours() == 0 && curTime.getMinutes() <= 5)// Because I am calling this function every 5 minutes
  			{
  				// the day has changed
  				var todayElem = $(".fc-today");
  				todayElem.removeClass("fc-today");
  				todayElem.removeClass("fc-state-highlight");
  
  				todayElem.next().addClass("fc-today");
  				todayElem.next().addClass("fc-state-highlight");
  			}
  
  			var parentDiv = $(".fc-agenda-slots:visible").parent();
  			var timeline = parentDiv.children(".timeline");
  			if (timeline.length == 0) {//if timeline isn't there, add it
  				timeline = $("<hr>").addClass("timeline");
  				parentDiv.prepend(timeline);
  			}
  
  			var curCalView = $('#fullcalendar').fullCalendar("getView");
  			if (curCalView.visStart < curTime && curCalView.visEnd > curTime) {
  				timeline.show();
  			} else {
  				timeline.hide();
  			}
  
  			var curSeconds = (curTime.getHours() * 60 * 60) + (curTime.getMinutes() * 60) + curTime.getSeconds();
  			var percentOfDay = curSeconds / 86400;
  			//24 * 60 * 60 = 86400, # of seconds in a day
  			var topLoc = Math.floor(parentDiv.height() * percentOfDay);
  			var appNavigationWidth = ($(window).width() > 768) ? $('#app-navigation').width() : 0;
  			timeline.css({'left':($('.fc-today').offset().left-appNavigationWidth),'width': $('.fc-today').width(),'top':topLoc + 'px'});
  		},
d1bafeea1   Kload   [fix] Upgrade to ...
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
  	},
  	UI:{
  		loading: function(isLoading){
  			if (isLoading){
  				$('#loading').show();
  			}else{
  				$('#loading').hide();
  			}
  		},
  		startEventDialog:function(){
  			Calendar.UI.loading(false);
  			$('#fullcalendar').fullCalendar('unselect');
  			Calendar.UI.lockTime();
  			$( "#from" ).datepicker({
  				dateFormat : 'dd-mm-yy',
  				onSelect: function(){ Calendar.Util.adjustDate(); }
  			});
  			$( "#to" ).datepicker({
  				dateFormat : 'dd-mm-yy'
  			});
  			$('#fromtime').timepicker({
  				showPeriodLabels: false,
  				onSelect: function(){ Calendar.Util.adjustDate(); }
  			});
  			$('#totime').timepicker({
  				showPeriodLabels: false
  			});
  			$('#category').multiple_autocomplete({source: categories});
  			Calendar.UI.repeat('init');
  			$('#end').change(function(){
  				Calendar.UI.repeat('end');
  			});
  			$('#repeat').change(function(){
  				Calendar.UI.repeat('repeat');
  			});
  			$('#advanced_year').change(function(){
  				Calendar.UI.repeat('year');
  			});
  			$('#advanced_month').change(function(){
  				Calendar.UI.repeat('month');
  			});
6d9380f96   Cédric Dupont   Update sources OC...
163
164
165
166
167
  			$('#event-title').bind('keydown', function(event){
  				if (event.which == 13){
  					$('#event_form #submitNewEvent').click();
  				}
  			});
d1bafeea1   Kload   [fix] Upgrade to ...
168
169
170
171
172
173
174
175
176
177
178
179
180
  			$( "#event" ).tabs({ selected: 0});
  			$('#event').dialog({
  				width : 500,
  				height: 600,
  				resizable: false,
  				draggable: false,
  				close : function(event, ui) {
  					$(this).dialog('destroy').remove();
  				}
  			});
  			Calendar.UI.Share.init();
  			$('#sendemailbutton').click(function() {
  				Calendar.Util.sendmail($(this).attr('data-eventid'), $(this).attr('data-location'), $(this).attr('data-description'), $(this).attr('data-dtstart'), $(this).attr('data-dtend'));
6d9380f96   Cédric Dupont   Update sources OC...
181
182
183
184
  			});
  			// Focus the title, and reset the text value so that it isn't selected.
  			var val = $('#event-title').val();
  			$('#event-title').focus().val('').val(val);
d1bafeea1   Kload   [fix] Upgrade to ...
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
  		},
  		newEvent:function(start, end, allday){
  			start = Math.round(start.getTime()/1000);
  			if (end){
  				end = Math.round(end.getTime()/1000);
  			}
  			if($('#event').dialog('isOpen') == true){
  				// TODO: save event
  				$('#event').dialog('destroy').remove();
  			}else{
  				Calendar.UI.loading(true);
  				$('#dialog_holder').load(OC.filePath('calendar', 'ajax/event', 'new.form.php'), {start:start, end:end, allday:allday?1:0}, Calendar.UI.startEventDialog);
  			}
  		},
  		editEvent:function(calEvent, jsEvent, view){
  			if (calEvent.editable == false || calEvent.source.editable == false) {
  				return;
  			}
  			var id = calEvent.id;
  			if($('#event').dialog('isOpen') == true){
  				// TODO: save event
  				$('#event').dialog('destroy').remove();
  			}else{
  				Calendar.UI.loading(true);
  				$('#dialog_holder').load(OC.filePath('calendar', 'ajax/event', 'edit.form.php'), {id: id}, Calendar.UI.startEventDialog);
  			}
  		},
  		submitDeleteEventForm:function(url){
  			var id = $('input[name="id"]').val();
  			$('#errorbox').empty();
  			Calendar.UI.loading(true);
  			$.post(url, {id:id}, function(data){
  					Calendar.UI.loading(false);
  					if(data.status == 'success'){
  						$('#fullcalendar').fullCalendar('removeEvents', $('#event_form input[name=id]').val());
  						$('#event').dialog('destroy').remove();
  					} else {
  						$('#errorbox').html(t('calendar', 'Deletion failed'));
  					}
  
  			}, "json");
  		},
  		validateEventForm:function(url){
  			var post = $( "#event_form" ).serialize();
  			$("#errorbox").empty();
  			Calendar.UI.loading(true);
  			$.post(url, post,
  				function(data){
  					Calendar.UI.loading(false);
  					if(data.status == "error"){
  						var output = missing_field + ": <br />";
  						if(data.title == "true"){
  							output = output + missing_field_title + "<br />";
  						}
  						if(data.cal == "true"){
  							output = output + missing_field_calendar + "<br />";
  						}
  						if(data.from == "true"){
  							output = output + missing_field_fromdate + "<br />";
  						}
  						if(data.fromtime == "true"){
  							output = output + missing_field_fromtime + "<br />";
  						}
6d9380f96   Cédric Dupont   Update sources OC...
248
249
250
  						if(data.interval == "true"){
  							output = output + missing_field_interval + "<br />";
  						}
d1bafeea1   Kload   [fix] Upgrade to ...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
  						if(data.to == "true"){
  							output = output + missing_field_todate + "<br />";
  						}
  						if(data.totime == "true"){
  							output = output + missing_field_totime + "<br />";
  						}
  						if(data.endbeforestart == "true"){
  							output = output + missing_field_startsbeforeends + "!<br/>";
  						}
  						if(data.dberror == "true"){
  							output = "There was a database fail!";
  						}
  						$("#errorbox").html(output);
  					} else
  					if(data.status == 'success'){
  						$('#event').dialog('destroy').remove();
  						$('#fullcalendar').fullCalendar('refetchEvents');
  					}
  				},"json");
  		},
  		moveEvent:function(event, dayDelta, minuteDelta, allDay, revertFunc){
6d9380f96   Cédric Dupont   Update sources OC...
272
273
274
275
  			if($('#event').length != 0) {
  				revertFunc();
  				return;
  			}
d1bafeea1   Kload   [fix] Upgrade to ...
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
  			Calendar.UI.loading(true);
  			$.post(OC.filePath('calendar', 'ajax/event', 'move.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, allDay: allDay?1:0, lastmodified: event.lastmodified},
  			function(data) {
  				Calendar.UI.loading(false);
  				if (data.status == 'success'){
  					event.lastmodified = data.lastmodified;
  					console.log("Event moved successfully");
  				}else{
  					revertFunc();
  					$('#fullcalendar').fullCalendar('refetchEvents');
  				}
  			});
  		},
  		resizeEvent:function(event, dayDelta, minuteDelta, revertFunc){
  			Calendar.UI.loading(true);
  			$.post(OC.filePath('calendar', 'ajax/event', 'resize.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, lastmodified: event.lastmodified},
  			function(data) {
  				Calendar.UI.loading(false);
  				if (data.status == 'success'){
  					event.lastmodified = data.lastmodified;
  					console.log("Event resized successfully");
  				}else{
  					revertFunc();
  					$('#fullcalendar').fullCalendar('refetchEvents');
  				}
  			});
  		},
  		showadvancedoptions:function(){
  			$("#advanced_options").slideDown('slow');
  			$("#advanced_options_button").css("display", "none");
  		},
  		showadvancedoptionsforrepeating:function(){
  			if($("#advanced_options_repeating").is(":hidden")){
  				$('#advanced_options_repeating').slideDown('slow');
  			}else{
  				$('#advanced_options_repeating').slideUp('slow');
  			}
  		},
  		getEventPopupText:function(event){
  			if (event.allDay){
  				var timespan = $.fullCalendar.formatDates(event.start, event.end, 'ddd d MMMM[ yyyy]{ - [ddd d] MMMM yyyy}', {monthNamesShort: monthNamesShort, monthNames: monthNames, dayNames: dayNames, dayNamesShort: dayNamesShort}); //t('calendar', "ddd d MMMM[ yyyy]{ - [ddd d] MMMM yyyy}")
  			}else{
  				var timespan = $.fullCalendar.formatDates(event.start, event.end, 'ddd d MMMM[ yyyy] ' + defaulttime + '{ - [ ddd d MMMM yyyy]' + defaulttime + '}', {monthNamesShort: monthNamesShort, monthNames: monthNames, dayNames: dayNames, dayNamesShort: dayNamesShort}); //t('calendar', "ddd d MMMM[ yyyy] HH:mm{ - [ ddd d MMMM yyyy] HH:mm}")
  				// Tue 18 October 2011 08:00 - 16:00
  			}
  			var html =
  				'<div class="summary">' + escapeHTML(event.title) + '</div>' +
  				'<div class="timespan">' + timespan + '</div>';
  			if (event.description){
  				html += '<div class="description">' + escapeHTML(event.description) + '</div>';
  			}
  			return html;
  		},
  		lockTime:function(){
  			if($('#allday_checkbox').is(':checked')) {
  				$("#fromtime").attr('disabled', true)
  					.addClass('disabled');
  				$("#totime").attr('disabled', true)
  					.addClass('disabled');
  			} else {
  				$("#fromtime").attr('disabled', false)
  					.removeClass('disabled');
  				$("#totime").attr('disabled', false)
  					.removeClass('disabled');
  			}
  		},
  		showCalDAVUrl:function(username, calname){
6d9380f96   Cédric Dupont   Update sources OC...
343
  			$('#caldav_url').val(totalurl + '/' + encodeURIComponent(username) + '/' + calname);
d1bafeea1   Kload   [fix] Upgrade to ...
344
345
346
347
348
  			$('#caldav_url').show();
  			$("#caldav_url_close").show();
  		},
  		repeat:function(task){
  			if(task=='init'){
6d9380f96   Cédric Dupont   Update sources OC...
349
350
  				
  				var byWeekNoTitle = $('#advanced_byweekno').attr('title');
d1bafeea1   Kload   [fix] Upgrade to ...
351
352
  				$('#byweekno').multiselect({
  					header: false,
6d9380f96   Cédric Dupont   Update sources OC...
353
  					noneSelectedText: byWeekNoTitle,
d1bafeea1   Kload   [fix] Upgrade to ...
354
  					selectedList: 2,
6d9380f96   Cédric Dupont   Update sources OC...
355
  					minWidth : 60
d1bafeea1   Kload   [fix] Upgrade to ...
356
  				});
6d9380f96   Cédric Dupont   Update sources OC...
357
358
  				
  				var weeklyoptionsTitle = $('#weeklyoptions').attr('title');
d1bafeea1   Kload   [fix] Upgrade to ...
359
360
  				$('#weeklyoptions').multiselect({
  					header: false,
6d9380f96   Cédric Dupont   Update sources OC...
361
  					noneSelectedText: weeklyoptionsTitle,
d1bafeea1   Kload   [fix] Upgrade to ...
362
  					selectedList: 2,
6d9380f96   Cédric Dupont   Update sources OC...
363
  					minWidth : 110
d1bafeea1   Kload   [fix] Upgrade to ...
364
365
366
367
  				});
  				$('input[name="bydate"]').datepicker({
  					dateFormat : 'dd-mm-yy'
  				});
6d9380f96   Cédric Dupont   Update sources OC...
368
369
  				
  				var byyeardayTitle = $('#byyearday').attr('title');
d1bafeea1   Kload   [fix] Upgrade to ...
370
371
  				$('#byyearday').multiselect({
  					header: false,
6d9380f96   Cédric Dupont   Update sources OC...
372
  					noneSelectedText: byyeardayTitle,
d1bafeea1   Kload   [fix] Upgrade to ...
373
  					selectedList: 2,
6d9380f96   Cédric Dupont   Update sources OC...
374
  					minWidth : 60
d1bafeea1   Kload   [fix] Upgrade to ...
375
  				});
6d9380f96   Cédric Dupont   Update sources OC...
376
377
  				
  				var bymonthTitle = $('#bymonth').attr('title');
d1bafeea1   Kload   [fix] Upgrade to ...
378
379
  				$('#bymonth').multiselect({
  					header: false,
6d9380f96   Cédric Dupont   Update sources OC...
380
  					noneSelectedText: bymonthTitle,
d1bafeea1   Kload   [fix] Upgrade to ...
381
  					selectedList: 2,
6d9380f96   Cédric Dupont   Update sources OC...
382
  					minWidth : 110
d1bafeea1   Kload   [fix] Upgrade to ...
383
  				});
6d9380f96   Cédric Dupont   Update sources OC...
384
385
  				
  				var bymonthdayTitle = $('#bymonthday').attr('title');
d1bafeea1   Kload   [fix] Upgrade to ...
386
387
  				$('#bymonthday').multiselect({
  					header: false,
6d9380f96   Cédric Dupont   Update sources OC...
388
  					noneSelectedText: bymonthdayTitle,
d1bafeea1   Kload   [fix] Upgrade to ...
389
  					selectedList: 2,
6d9380f96   Cédric Dupont   Update sources OC...
390
  					minWidth : 60
d1bafeea1   Kload   [fix] Upgrade to ...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
  				});
  				Calendar.UI.repeat('end');
  				Calendar.UI.repeat('month');
  				Calendar.UI.repeat('year');
  				Calendar.UI.repeat('repeat');
  			}
  			if(task == 'end'){
  				$('#byoccurrences').css('display', 'none');
  				$('#bydate').css('display', 'none');
  				if($('#end option:selected').val() == 'count'){
  					$('#byoccurrences').css('display', 'block');
  				}
  				if($('#end option:selected').val() == 'date'){
  					$('#bydate').css('display', 'block');
  				}
  			}
  			if(task == 'repeat'){
  				$('#advanced_month').css('display', 'none');
  				$('#advanced_weekday').css('display', 'none');
  				$('#advanced_weekofmonth').css('display', 'none');
  				$('#advanced_byyearday').css('display', 'none');
  				$('#advanced_bymonth').css('display', 'none');
  				$('#advanced_byweekno').css('display', 'none');
  				$('#advanced_year').css('display', 'none');
  				$('#advanced_bymonthday').css('display', 'none');
  				if($('#repeat option:selected').val() == 'monthly'){
  					$('#advanced_month').css('display', 'block');
  					Calendar.UI.repeat('month');
  				}
  				if($('#repeat option:selected').val() == 'weekly'){
  					$('#advanced_weekday').css('display', 'block');
  				}
  				if($('#repeat option:selected').val() == 'yearly'){
  					$('#advanced_year').css('display', 'block');
  					Calendar.UI.repeat('year');
  				}
  				if($('#repeat option:selected').val() == 'doesnotrepeat'){
  					$('#advanced_options_repeating').slideUp('slow');
  				}
  			}
  			if(task == 'month'){
  				$('#advanced_weekday').css('display', 'none');
  				$('#advanced_weekofmonth').css('display', 'none');
  				if($('#advanced_month_select option:selected').val() == 'weekday'){
  					$('#advanced_weekday').css('display', 'block');
  					$('#advanced_weekofmonth').css('display', 'block');
  				}
  			}
  			if(task == 'year'){
  				$('#advanced_weekday').css('display', 'none');
  				$('#advanced_byyearday').css('display', 'none');
  				$('#advanced_bymonth').css('display', 'none');
  				$('#advanced_byweekno').css('display', 'none');
  				$('#advanced_bymonthday').css('display', 'none');
  				if($('#advanced_year_select option:selected').val() == 'byyearday'){
  					//$('#advanced_byyearday').css('display', 'block');
  				}
  				if($('#advanced_year_select option:selected').val() == 'byweekno'){
  					$('#advanced_byweekno').css('display', 'block');
  				}
  				if($('#advanced_year_select option:selected').val() == 'bydaymonth'){
  					$('#advanced_bymonth').css('display', 'block');
  					$('#advanced_bymonthday').css('display', 'block');
  					$('#advanced_weekday').css('display', 'block');
  				}
  			}
  
  		},
  		setViewActive: function(view){
  			$('#view input[type="button"]').removeClass('active');
  			var id;
  			switch (view) {
  				case 'agendaWeek':
  					id = 'oneweekview_radio';
  					break;
  				case 'month':
  					id = 'onemonthview_radio';
  					break;
  				case 'agendaDay':
  					id = 'onedayview_radio';
  					break;
  			}
  			$('#'+id).addClass('active');
  		},
  		categoriesChanged:function(newcategories){
  			categories = $.map(newcategories, function(v) {return v.name;});
  			console.log('Calendar categories changed to: ' + categories);
  			$('#category').multiple_autocomplete('option', 'source', categories);
  		},
6d9380f96   Cédric Dupont   Update sources OC...
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
  		lastView:null,
  		isToday:true,
  		timerHolder:null,
  		timerInterval:300000, // 300000 = 5*60*1000ms = 5 min
  		changeView:function(view){
  			switch (view){
  				case 'today':
  				case 'prev':
  				case 'next':
  					$('#fullcalendar').fullCalendar(view);
  					if (view=='today' && Calendar.UI.isToday) {
  						Calendar.UI.changeView('refresh')
  					}
  					if (view=='today'){
  						Calendar.UI.isToday = true;
  					}else{
  						Calendar.UI.isToday = false;
  					}
  					break;
  
  				case 'agendaDay':
  				case 'agendaWeek':
  				case 'month':
  					$('#fullcalendar').fullCalendar('changeView', view);
  					if (Calendar.UI.lastView == view) {
  						Calendar.UI.changeView('refresh')
  					}
  					Calendar.UI.lastView = view;
  					break;
  
  				case 'refresh':
  					// refetch the events.
  					$('#fullcalendar').fullCalendar('refetchEvents');
  				case 'auto_refresh':
  					// reset the timer not to refetch before new 5 min.
  					if (Calendar.UI.timerHolder){
  						window.clearTimeout(Calendar.UI.timerHolder)
  					}
  					Calendar.UI.timerHolder = window.setTimeout( function(){Calendar.UI.changeView('refresh')}, Calendar.UI.timerInterval);
  					break;
  
  				default:
  					console.error('unsupported change view to:' + view);
  			}
  		},
d1bafeea1   Kload   [fix] Upgrade to ...
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
  		Calendar:{
  			overview:function(){
  				if($('#choosecalendar_dialog').dialog('isOpen') == true){
  					$('#choosecalendar_dialog').dialog('moveToTop');
  				}else{
  					Calendar.UI.loading(true);
  					$('#dialog_holder').load(OC.filePath('calendar', 'ajax/calendar', 'overview.php'), function(){
  						$('#choosecalendar_dialog').dialog({
  							width : 600,
  							height: 400,
  							close : function(event, ui) {
  								$(this).dialog('destroy').remove();
  							}
  						});
  						Calendar.UI.loading(false);
  					});
  				}
  			},
  			activation:function(checkbox, calendarid)
  			{
6d9380f96   Cédric Dupont   Update sources OC...
545
546
547
548
549
550
  				if(checkbox.checked?1:0) {
  					$('#checkbox_'+calendarid).removeClass('unchecked');
  				}
  				else {
  					$('#checkbox_'+calendarid).addClass('unchecked');
  				}
d1bafeea1   Kload   [fix] Upgrade to ...
551
552
553
554
555
556
557
558
559
560
561
562
563
564
  				Calendar.UI.loading(true);
  				$.post(OC.filePath('calendar', 'ajax/calendar', 'activation.php'), { calendarid: calendarid, active: checkbox.checked?1:0 },
  				  function(data) {
  					Calendar.UI.loading(false);
  					if (data.status == 'success'){
  						checkbox.checked = data.active == 1;
  						if (data.active == 1){
  							$('#fullcalendar').fullCalendar('addEventSource', data.eventSource);
  						}else{
  							$('#fullcalendar').fullCalendar('removeEventSource', data.eventSource.url);
  						}
  					}
  				  });
  			},
6d9380f96   Cédric Dupont   Update sources OC...
565
566
567
568
569
570
571
572
  			sharedEventsActivation:function(checkbox)
  			{
  				if (checkbox.checked){
  					$('#fullcalendar').fullCalendar('addEventSource', sharedEventSource);
  				}else{
  					$('#fullcalendar').fullCalendar('removeEventSource', sharedEventSource.url);
  				}
  			},
d1bafeea1   Kload   [fix] Upgrade to ...
573
  			newCalendar:function(object){
6d9380f96   Cédric Dupont   Update sources OC...
574
  				var div = $('<div />')
d1bafeea1   Kload   [fix] Upgrade to ...
575
  					.load(OC.filePath('calendar', 'ajax/calendar', 'new.form.php'),
6d9380f96   Cédric Dupont   Update sources OC...
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
  						function(){
  							Calendar.UI.Calendar.colorPicker(this);
  							$('#displayname_new').focus();
  						});
  				
  				var bodyListener = function(e) {
  					if($('#newcalendar_dialog').find($(e.target)).length === 0) {
  						$('#newcalendar_dialog').parent().remove();
  						$("#newCalendar").css('display', '');
  						$('body').unbind('click', bodyListener);
  					}
  				};
  				$('body').bind('click', bodyListener);
  				
  				$('#newCalendar').after(div);
  				$('#newCalendar').css('display', 'none');
d1bafeea1   Kload   [fix] Upgrade to ...
592
593
  			},
  			edit:function(object, calendarid){
6d9380f96   Cédric Dupont   Update sources OC...
594
  				var li = $(document.createElement('li'))
d1bafeea1   Kload   [fix] Upgrade to ...
595
596
  					.load(OC.filePath('calendar', 'ajax/calendar', 'edit.form.php'), {calendarid: calendarid},
  						function(){Calendar.UI.Calendar.colorPicker(this)});
6d9380f96   Cédric Dupont   Update sources OC...
597
598
599
600
601
602
603
604
605
606
607
  				
  				var bodyListener = function(e) {
  					if($('#editcalendar_dialog').find($(e.target)).length === 0) {
  						$(object).closest('li').before(li).show();
  						$('#editcalendar_dialog').parent().remove();
  						$('body').unbind('click', bodyListener);
  					}
  				};
  				$('body').bind('click', bodyListener);
  				
  				$(object).closest('li').after(li).hide();
d1bafeea1   Kload   [fix] Upgrade to ...
608
609
610
611
612
613
614
615
616
617
618
  			},
  			deleteCalendar:function(calid){
  				var check = confirm("Do you really want to delete this calendar?");
  				if(check == false){
  					return false;
  				}else{
  					$.post(OC.filePath('calendar', 'ajax/calendar', 'delete.php'), { calendarid: calid},
  					  function(data) {
  						if (data.status == 'success'){
  							var url = 'ajax/events.php?calendar_id='+calid;
  							$('#fullcalendar').fullCalendar('removeEventSource', url);
6d9380f96   Cédric Dupont   Update sources OC...
619
620
  							$('#navigation-list li[data-id="'+calid+'"]').fadeOut(400,function(){
  								$('#navigation-list li[data-id="'+calid+'"]').remove();
d1bafeea1   Kload   [fix] Upgrade to ...
621
622
623
624
625
626
627
628
  							});
  							$('#fullcalendar').fullCalendar('refetchEvents');
  						}
  					  });
  				}
  			},
  			submit:function(button, calendarid){
  				var displayname = $.trim($("#displayname_"+calendarid).val());
6d9380f96   Cédric Dupont   Update sources OC...
629
  				var active = $("#active_"+calendarid).attr("checked") ? 1 : 0;
d1bafeea1   Kload   [fix] Upgrade to ...
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
  				
  				var description = $("#description_"+calendarid).val();
  				var calendarcolor = $("#calendarcolor_"+calendarid).val();
  				if(displayname == ''){
  					$("#displayname_"+calendarid).css('background-color', '#FF2626');
  					$("#displayname_"+calendarid).focus(function(){
  						$("#displayname_"+calendarid).css('background-color', '#F8F8F8');
  					});
  				}
  
  				var url;
  				if (calendarid == 'new'){
  					url = OC.filePath('calendar', 'ajax/calendar', 'new.php');
  				}else{
  					url = OC.filePath('calendar', 'ajax/calendar', 'update.php');
  				}
  				$.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor },
  					function(data){
  						if(data.status == 'success'){
6d9380f96   Cédric Dupont   Update sources OC...
649
650
651
652
  							if(active) {
  								$('#fullcalendar').fullCalendar('removeEventSource', data.eventSource.url);
  								$('#fullcalendar').fullCalendar('addEventSource', data.eventSource);
  							}
d1bafeea1   Kload   [fix] Upgrade to ...
653
  							if (calendarid == 'new'){
6d9380f96   Cédric Dupont   Update sources OC...
654
655
656
657
658
659
660
661
662
  								$('#newcalendar_dialog').parent().remove();
  								$("#newCalendar").css('display', '');
  								var li = $(document.createElement('li')).append(data.page);
  								$("#navigation-list").append(li);
  								$('#caldav_url_entry').appendTo("#navigation-list");
  							}
  							else {
  								$('#editcalendar_dialog').parent().remove();
  								$('#navigation-list li[data-id="'+calendarid+'"]').html(data.page).show();
d1bafeea1   Kload   [fix] Upgrade to ...
663
664
665
666
667
668
669
670
671
672
  							}
  						}else{
  							$("#displayname_"+calendarid).css('background-color', '#FF2626');
  							$("#displayname_"+calendarid).focus(function(){
  								$("#displayname_"+calendarid).css('background-color', '#F8F8F8');
  							});
  						}
  					}, 'json');
  			},
  			cancel:function(button, calendarid){
6d9380f96   Cédric Dupont   Update sources OC...
673
674
  				$('#newcalendar_dialog').parent().remove();
  				$("#newCalendar").css('display', '');
d1bafeea1   Kload   [fix] Upgrade to ...
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
  			},
  			colorPicker:function(container){
  				// based on jquery-colorpicker at jquery.webspirited.com
  				var obj = $('.colorpicker', container);
  				var picker = $('<div class="calendar-colorpicker"></div>');
  				//build an array of colors
  				var colors = {};
  				$(obj).children('option').each(function(i, elm) {
  					colors[i] = {};
  					colors[i].color = $(elm).val();
  					colors[i].label = $(elm).text();
  				});
  				for (var i in colors) {
  					picker.append('<span class="calendar-colorpicker-color ' + (colors[i].color == $(obj).children(":selected").val() ? ' active' : '') + '" rel="' + colors[i].label + '" style="background-color: ' + colors[i].color + ';"></span>');
  				}
  				picker.delegate(".calendar-colorpicker-color", "click", function() {
  					$(obj).val($(this).attr('rel'));
  					$(obj).change();
  					picker.children('.calendar-colorpicker-color.active').removeClass('active');
  					$(this).addClass('active');
  				});
  				$(obj).after(picker);
  				$(obj).css({
  					position: 'absolute',
  					left: -10000
  				});
  			}
  		},
  		Share:{
  			init:function(){
  				if(typeof OC.Share !== typeof undefined){
  					var itemShares = [OC.Share.SHARE_TYPE_USER, OC.Share.SHARE_TYPE_GROUP];
  					$('#sharewith').autocomplete({minLength: 1, source: function(search, response) {
  						$.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term, itemShares: itemShares }, function(result) {
  							if (result.status == 'success' && result.data.length > 0) {
  								response(result.data);
  							}
  						});
  					},
  					focus: function(event, focused) {
  						event.preventDefault();
  					},
  					select: function(event, selected) {
  						var itemType = 'event';
  						var itemSource = $('#sharewith').data('item-source');
  						var shareType = selected.item.value.shareType;
  						var shareWith = selected.item.value.shareWith;
  						$(this).val(shareWith);
  						// Default permissions are Read and Share
  						var permissions = OC.PERMISSION_READ | OC.PERMISSION_SHARE;
  						OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, function(data) {
  							var newitem = '<li data-item-type="event"'
  								+ 'data-share-with="'+shareWith+'" '
  								+ 'data-permissions="'+permissions+'" '
  								+ 'data-share-type="'+shareType+'">'
  								+ shareWith
  								+ (shareType === OC.Share.SHARE_TYPE_GROUP ? ' ('+t('core', 'group')+')' : '')
  								+ '<span class="shareactions">'
  								+ '<label><input class="update" type="checkbox" checked="checked">'+t('core', 'can edit')+'</label>'
  								+ '<label><input class="share" type="checkbox" checked="checked">'+t('core', 'can share')+'</label>'
  								+ '<img class="svg action delete" title="Unshare"src="'+ OC.imagePath('core', 'actions/delete.svg') +'"></span></li>';
  							$('.sharedby.eventlist').append(newitem);
  							$('#sharedWithNobody').remove();
  							$('#sharewith').val('');
  						});
  						return false;
  					}
  					});
  	
  					$('.shareactions > input:checkbox').change(function() {
  						var container = $(this).parents('li').first();
  						var permissions = parseInt(container.data('permissions'));
  						var itemType = container.data('item-type');
  						var shareType = container.data('share-type');
  						var itemSource = container.data('item');
  						var shareWith = container.data('share-with');
  						var permission = null;
  						if($(this).hasClass('update')) {
  							permission = OC.PERMISSION_UPDATE;
  							permission = OC.PERMISSION_DELETE;
  						} else if($(this).hasClass('share')) {
  							permission = OC.PERMISSION_SHARE;
  						}
  						// This is probably not the right way, but it works :-P
  						if($(this).is(':checked')) {
  							permissions += permission;
  						} else {
  							permissions -= permission;
  						}
  						
  						container.data('permissions',permissions);
  						
  						OC.Share.setPermissions(itemType, itemSource, shareType, shareWith, permissions);
  					});
  	
  					$('.shareactions > .delete').click(function() {
  						var container = $(this).parents('li').first();
  						var itemType = container.data('item-type');
  						var shareType = container.data('share-type');
  						var itemSource = container.data('item');
  						var shareWith = container.data('share-with');
  						OC.Share.unshare(itemType, itemSource, shareType, shareWith, function() {
  							container.remove();
  						});
  					});
  				}
  			}
  		},
  		Drop:{
  			init:function(){
  				if (typeof window.FileReader === 'undefined') {
  					console.log('The drop-import feature is not supported in your browser :(');
  					return false;
  				}
  				droparea = document.getElementById('fullcalendar');
  				droparea.ondrop = function(e){
  					e.preventDefault();
  					Calendar.UI.Drop.drop(e);
  				}
  				console.log('Drop initialized successfully');
  			},
  			drop:function(e){
  				var files = e.dataTransfer.files;
  				for(var i = 0;i < files.length;i++){
  					var file = files[i];
  					var reader = new FileReader();
  					reader.onload = function(event){
  						Calendar.UI.Drop.doImport(event.target.result);
  						$('#fullcalendar').fullCalendar('refetchEvents');
  					}
  					reader.readAsDataURL(file);
  				}
  			},
  			doImport:function(data){
  				$.post(OC.filePath('calendar', 'ajax/import', 'dropimport.php'), {'data':data},function(result) {
  					if(result.status == 'success'){
  						$('#fullcalendar').fullCalendar('addEventSource', result.eventSource);
  						$('#notification').html(result.message);
  						$('#notification').slideDown();
  						window.setTimeout(function(){$('#notification').slideUp();}, 5000);
  						return true;
  					}else{
  						$('#notification').html(result.message);
  						$('#notification').slideDown();
  						window.setTimeout(function(){$('#notification').slideUp();}, 5000);
  					}
  				});
  			}
  		}
  	},
  	Settings:{
  		//
  	},
  
  }
  $.fullCalendar.views.list = ListView;
  function ListView(element, calendar) {
  	var t = this;
  
  	// imports
  	jQuery.fullCalendar.views.month.call(t, element, calendar);
  	var opt = t.opt;
  	var trigger = t.trigger;
  	var eventElementHandlers = t.eventElementHandlers;
  	var reportEventElement = t.reportEventElement;
  	var formatDate = calendar.formatDate;
  	var formatDates = calendar.formatDates;
  	var addDays = $.fullCalendar.addDays;
  	var cloneDate = $.fullCalendar.cloneDate;
  	function skipWeekend(date, inc, excl) {
  		inc = inc || 1;
  		while (!date.getDay() || (excl && date.getDay()==1 || !excl && date.getDay()==6)) {
  			addDays(date, inc);
  		}
  		return date;
  	}
  
  	// overrides
  	t.name='list';
  	t.render=render;
  	t.renderEvents=renderEvents;
  	t.setHeight=setHeight;
  	t.setWidth=setWidth;
  	t.clearEvents=clearEvents;
d1bafeea1   Kload   [fix] Upgrade to ...
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
  	function clearEvents() {
  		this.reportEventClear();
  	}
  
  	// main
  	function sortEvent(a, b) {
  		return a.start - b.start;
  	}
  
  	function render(date, delta) {
  		if (!t.start){
  			t.start = addDays(cloneDate(date, true), -7);
  			t.end = addDays(cloneDate(date, true), 7);
  		}
  		if (delta) {
  			if (delta < 0){
  				addDays(t.start, -7);
  				addDays(t.end, -7);
  				if (!opt('weekends')) {
  					skipWeekend(t.start, delta < 0 ? -1 : 1);
  				}
  			}else{
  				addDays(t.start, 7);
  				addDays(t.end, 7);
  				if (!opt('weekends')) {
  					skipWeekend(t.end, delta < 0 ? -1 : 1);
  				}
  			}
  		}
  		t.title = formatDates(
  			t.start,
  			t.end,
  			opt('titleFormat', 'week')
  		);
  		t.visStart = cloneDate(t.start);
  		t.visEnd = cloneDate(t.end);
  	}
  
  	function eventsOfThisDay(events, theDate) {
  		var start = cloneDate(theDate, true);
  		var end = addDays(cloneDate(start), 1);
  		var retArr = new Array();
  		for (i in events) {
  			var event_end = t.eventEnd(events[i]);
  			if (events[i].start < end && event_end >= start) {
  				retArr.push(events[i]);
  			}
  		}
  		return retArr;
  	}
  
  	function renderEvent(event) {
  		if (event.allDay) { //all day event
  			var time = opt('allDayText');
  		}
  		else {
  			var time = formatDates(event.start, event.end, opt('timeFormat', 'agenda'));
  		}
  		var classes = ['fc-event', 'fc-list-event'];
  		classes = classes.concat(event.className);
  		if (event.source) {
  			classes = classes.concat(event.source.className || []);
  		}
  		var html = '<tr>' +
  			'<td>&nbsp;</td>' +
  			'<td class="fc-list-time">' +
  			time +
  			'</td>' +
  			'<td>&nbsp;</td>' +
  			'<td class="fc-list-event">' +
  			'<span id="list' + event.id + '"' +
  			' class="' + classes.join(' ') + '"' +
  			'>' +
  			'<span class="fc-event-title">' +
  			escapeHTML(event.title) +
  			'</span>' +
  			'</span>' +
  			'</td>' +
  			'</tr>';
  		return html;
  	}
  
  	function renderDay(date, events) {
  		var dayRows = $('<tr>' +
  			'<td colspan="4" class="fc-list-date">' +
  			'<span>' +
  			formatDate(date, opt('titleFormat', 'day')) +
  			'</span>' +
  			'</td>' +
  			'</tr>');
  		for (i in events) {
  			var event = events[i];
  			var eventElement = $(renderEvent(event));
  			triggerRes = trigger('eventRender', event, event, eventElement);
  			if (triggerRes === false) {
  				eventElement.remove();
  			}else{
  				if (triggerRes && triggerRes !== true) {
  					eventElement.remove();
  					eventElement = $(triggerRes);
  				}
  				$.merge(dayRows, eventElement);
  				eventElementHandlers(event, eventElement);
  				reportEventElement(event, eventElement);
  			}
  		}
  		return dayRows;
  	}
  
  	function renderEvents(events, modifiedEventId) {
  		events = events.sort(sortEvent);
  
  		var table = $('<table class="fc-list-table"></table>');
  		var total = events.length;
  		if (total > 0) {
  			var date = cloneDate(t.visStart);
  			while (date <= t.visEnd) {
  				var dayEvents = eventsOfThisDay(events, date);
  				if (dayEvents.length > 0) {
  					table.append(renderDay(date, dayEvents));
  				}
  				date=addDays(date, 1);
  			}
  		}
  
  		this.element.html(table);
  	}
  }
  $(document).ready(function(){
6d9380f96   Cédric Dupont   Update sources OC...
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
  	Calendar.UI.lastView = defaultView;
  	Calendar.UI.changeView('auto_refresh');
  	
  	/**
  	* Set an interval timer to make the timeline move 
  	*/
  	setInterval(Calendar.Util.setTimeline,60000);	
  	$(window).resize(_.debounce(function() {
  		/**
  		* When i use it instant the timeline is walking behind the facts
  		* A little timeout will make sure that it positions correctly
  		*/
  		setTimeout(Calendar.Util.setTimeline,500);
  	}));
d1bafeea1   Kload   [fix] Upgrade to ...
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
  	$('#fullcalendar').fullCalendar({
  		header: false,
  		firstDay: firstDay,
  		editable: true,
  		defaultView: defaultView,
  		timeFormat: {
  			agenda: agendatime,
  			'': defaulttime
  			},
  		columnFormat: {
  			month: t('calendar', 'ddd'),    // Mon
  			week: t('calendar', 'ddd M/d'), // Mon 9/7
  			day: t('calendar', 'dddd M/d')  // Monday 9/7
  			},
  		titleFormat: {
  			month: t('calendar', 'MMMM yyyy'),
  					// September 2009
  			week: t('calendar', "MMM d[ yyyy]{ '–'[ MMM] d yyyy}"),
  					// Sep 7 - 13 2009
  			day: t('calendar', 'dddd, MMM d, yyyy'),
  					// Tuesday, Sep 8, 2009
  			},
  		axisFormat: defaulttime,
  		monthNames: monthNames,
  		monthNamesShort: monthNamesShort,
  		dayNames: dayNames,
  		dayNamesShort: dayNamesShort,
  		allDayText: allDayText,
6d9380f96   Cédric Dupont   Update sources OC...
1030
1031
1032
  		viewRender: function(view) {
  			$('#datecontrol_current').html($('<p>').html(view.title).text());
  			$( "#datecontrol_date" ).datepicker("setDate", $('#fullcalendar').fullCalendar('getDate'));
d1bafeea1   Kload   [fix] Upgrade to ...
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
  			if (view.name != defaultView) {
  				$.post(OC.filePath('calendar', 'ajax', 'changeview.php'), {v:view.name});
  				defaultView = view.name;
  			}
  			if(view.name === 'agendaDay') {
  				$('td.fc-state-highlight').css('background-color', '#ffffff');
  			} else{
  				$('td.fc-state-highlight').css('background-color', '#ffc');
  			}
  			Calendar.UI.setViewActive(view.name);
  			if (view.name == 'agendaWeek') {
  				$('#fullcalendar').fullCalendar('option', 'aspectRatio', 0.1);
  			}
  			else {
  				$('#fullcalendar').fullCalendar('option', 'aspectRatio', 1.35);
  			}
6d9380f96   Cédric Dupont   Update sources OC...
1049
1050
1051
1052
  			try {
  				Calendar.Util.setTimeline();
  			} catch(err) {
  			}
d1bafeea1   Kload   [fix] Upgrade to ...
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
  		},
  		columnFormat: {
  		    week: 'ddd d. MMM'
  		},
  		selectable: true,
  		selectHelper: true,
  		select: Calendar.UI.newEvent,
  		eventClick: Calendar.UI.editEvent,
  		eventDrop: Calendar.UI.moveEvent,
  		eventResize: Calendar.UI.resizeEvent,
  		eventRender: function(event, element) {
  			element.find('.fc-event-title').text($("<div/>").html(escapeHTML(event.title)).text())
  		},
  		loading: Calendar.UI.loading,
  		eventSources: eventSources
  	});
  	$('#datecontrol_date').datepicker({
  		changeMonth: true,
  		changeYear: true,
  		showButtonPanel: true,
  		beforeShow: function(input, inst) {
  			var calendar_holder = $('#fullcalendar');
  			var date = calendar_holder.fullCalendar('getDate');
  			inst.input.datepicker('setDate', date);
  			inst.input.val(calendar_holder.fullCalendar('getView').title);
  			return inst;
  		},
  		onSelect: function(value, inst) {
  			var date = inst.input.datepicker('getDate');
  			$('#fullcalendar').fullCalendar('gotoDate', date);
6d9380f96   Cédric Dupont   Update sources OC...
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
  			
  			var view = $('#fullcalendar').fullCalendar('getView');
  			if(view.name == 'agendaWeek'){
  				$("[class*='fc-col']").removeClass('activeDay');
  				daySel=Calendar.Util.getDayOfWeek(date.getDay());
  				$('td.fc-'+daySel).addClass('activeDay');
  			}
  			if (view.name == 'month') {
  					$('td.fc-day').removeClass('activeDay');
  					prettyDate = $.datepicker.formatDate( 'yy-mm-dd',date);
  					$('td[data-date=' + prettyDate + ']').addClass('activeDay');
  			}
d1bafeea1   Kload   [fix] Upgrade to ...
1095
1096
  		}
  	});
d1bafeea1   Kload   [fix] Upgrade to ...
1097
1098
1099
1100
1101
1102
1103
1104
  
  	$(OC.Tags).on('change', function(event, data) {
  		if(data.type === 'event') {
  			Calendar.UI.categoriesChanged(data.tags);
  		}
  	});
  
  	$('#oneweekview_radio').click(function(){
6d9380f96   Cédric Dupont   Update sources OC...
1105
  		Calendar.UI.changeView('agendaWeek');
d1bafeea1   Kload   [fix] Upgrade to ...
1106
1107
  	});
  	$('#onemonthview_radio').click(function(){
6d9380f96   Cédric Dupont   Update sources OC...
1108
  		Calendar.UI.changeView('month');
d1bafeea1   Kload   [fix] Upgrade to ...
1109
1110
  	});
  	$('#onedayview_radio').click(function(){
6d9380f96   Cédric Dupont   Update sources OC...
1111
  		Calendar.UI.changeView('agendaDay');
d1bafeea1   Kload   [fix] Upgrade to ...
1112
1113
  	});
  	$('#today_input').click(function(){
6d9380f96   Cédric Dupont   Update sources OC...
1114
  		Calendar.UI.changeView('today');
d1bafeea1   Kload   [fix] Upgrade to ...
1115
1116
  	});
  	$('#datecontrol_left').click(function(){
6d9380f96   Cédric Dupont   Update sources OC...
1117
  		Calendar.UI.changeView('prev');
d1bafeea1   Kload   [fix] Upgrade to ...
1118
1119
  	});
  	$('#datecontrol_today').click(function(){
6d9380f96   Cédric Dupont   Update sources OC...
1120
  		Calendar.UI.changeView('today');
d1bafeea1   Kload   [fix] Upgrade to ...
1121
1122
  	});
  	$('#datecontrol_right').click(function(){
6d9380f96   Cédric Dupont   Update sources OC...
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
  		Calendar.UI.changeView('next');
  	});
  	$('#datecontrol_current').click(function() {
  		$('#datecontrol_date').slideToggle(500);
  	});
  	$('#datecontrol_date').hide();
  	$('#app-settings-header').on('click keydown',function(event) {
  		if(wrongKey(event)) {
  			return;
  		}
  		var bodyListener = function(e) {
  			if($('#app-settings').find($(e.target)).length === 0) {
  				$('#app-settings').switchClass('open', '');
  			}
  		};
  		if($('#app-settings').hasClass('open')) {
  			$('#app-settings').switchClass('open', '');
  			$('body').unbind('click', bodyListener);
  		} else {
  			$('#app-settings').switchClass('', 'open');
  			$('body').bind('click', bodyListener);
  		}
d1bafeea1   Kload   [fix] Upgrade to ...
1145
1146
1147
  	});
  	Calendar.UI.Share.init();
  	Calendar.UI.Drop.init();
6d9380f96   Cédric Dupont   Update sources OC...
1148
1149
1150
1151
1152
1153
1154
  	$('#fullcalendar').fullCalendar('option', 'height', $(window).height() - $('#controls').height() - $('#header').height());
  	// Save the eventSource for shared events.
  	for (var i in eventSources) {
  		if (eventSources[i].url.substr(-13) === 'shared_events') {
  			sharedEventSource = eventSources[i];
  		}
  	}
d1bafeea1   Kload   [fix] Upgrade to ...
1155
  });
6d9380f96   Cédric Dupont   Update sources OC...
1156
1157
1158
1159
1160
  
  var wrongKey = function(event) {
  	return ((event.type === 'keydown' || event.type === 'keypress') 
  		&& (event.keyCode !== 32 && event.keyCode !== 13));
  };