nextcloud/apps/calendar/js/calendar.js

929 lines
32 KiB
JavaScript
Raw Normal View History

2011-09-24 00:59:24 +04:00
/**
2012-01-15 03:06:26 +04:00
* Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
2011-09-24 00:59:24 +04:00
* 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.
*/
2011-08-31 17:59:22 +04:00
Calendar={
UI:{
2011-12-28 00:48:04 +04:00
loading: function(isLoading){
if (isLoading){
$('#loading').show();
}else{
$('#loading').hide();
}
},
2011-09-16 19:50:55 +04:00
startEventDialog:function(){
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(false);
2011-10-25 22:01:04 +04:00
$('.tipsy').remove();
$('#calendar_holder').fullCalendar('unselect');
2011-09-16 19:50:55 +04:00
Calendar.UI.lockTime();
$( "#from" ).datepicker({
dateFormat : 'dd-mm-yy'
});
$( "#to" ).datepicker({
dateFormat : 'dd-mm-yy'
});
$('#fromtime').timepicker({
showPeriodLabels: false
});
$('#totime').timepicker({
showPeriodLabels: false
});
$('#category').multiple_autocomplete({source: categories});
2011-12-26 02:19:49 +04:00
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');
});
$( "#event" ).tabs({ selected: 0});
2011-09-16 19:50:55 +04:00
$('#event').dialog({
width : 500,
2012-06-09 17:38:03 +04:00
height: 600,
2011-09-16 19:50:55 +04:00
close : function(event, ui) {
$(this).dialog('destroy').remove();
}
});
},
2011-10-25 21:57:20 +04:00
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{
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(true);
2012-02-20 14:27:25 +04:00
$('#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();
2011-09-15 23:20:42 +04:00
}else{
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(true);
2012-06-09 16:40:15 +04:00
$('#dialog_holder').load(OC.filePath('calendar', 'ajax/event', 'edit.form.php'), {id: id}, Calendar.UI.startEventDialog);
2011-09-15 23:20:42 +04:00
}
},
submitDeleteEventForm:function(url){
2011-10-19 21:09:01 +04:00
var post = $( '#event_form' ).serialize();
$('#errorbox').empty();
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(true);
$.post(url, post, function(data){
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(false);
if(data.status == 'success'){
2011-10-19 21:09:01 +04:00
$('#calendar_holder').fullCalendar('removeEvents', $('#event_form input[name=id]').val());
$('#event').dialog('destroy').remove();
} else {
2011-10-19 21:09:01 +04:00
$('#errorbox').html(t('calendar', 'Deletion failed'));
}
}, "json");
},
validateEventForm:function(url){
var post = $( "#event_form" ).serialize();
$("#errorbox").empty();
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(true);
$.post(url, post,
function(data){
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(false);
if(data.status == "error"){
2011-10-22 15:14:54 +04:00
var output = missing_field + ": <br />";
if(data.title == "true"){
2011-10-22 15:14:54 +04:00
output = output + missing_field_title + "<br />";
}
if(data.cal == "true"){
2011-10-22 15:14:54 +04:00
output = output + missing_field_calendar + "<br />";
}
if(data.from == "true"){
2011-10-22 15:14:54 +04:00
output = output + missing_field_fromdate + "<br />";
}
if(data.fromtime == "true"){
2011-10-22 15:14:54 +04:00
output = output + missing_field_fromtime + "<br />";
}
if(data.to == "true"){
2011-10-22 15:14:54 +04:00
output = output + missing_field_todate + "<br />";
}
if(data.totime == "true"){
2011-10-22 15:14:54 +04:00
output = output + missing_field_totime + "<br />";
}
if(data.endbeforestart == "true"){
2011-10-22 15:14:54 +04:00
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();
2011-10-19 21:09:01 +04:00
$('#calendar_holder').fullCalendar('refetchEvents');
}
},"json");
},
2011-10-19 00:25:54 +04:00
moveEvent:function(event, dayDelta, minuteDelta, allDay, revertFunc){
2011-10-28 00:56:22 +04:00
$('.tipsy').remove();
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(true);
2012-02-20 14:27:25 +04:00
$.post(OC.filePath('calendar', 'ajax/event', 'move.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, allDay: allDay?1:0, lastmodified: event.lastmodified},
function(data) {
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(false);
2011-10-19 00:25:54 +04:00
if (data.status == 'success'){
event.lastmodified = data.lastmodified;
2011-10-19 00:25:54 +04:00
console.log("Event moved successfully");
}else{
revertFunc();
$('#calendar_holder').fullCalendar('refetchEvents');
2011-10-19 00:25:54 +04:00
}
});
},
2011-10-19 01:02:00 +04:00
resizeEvent:function(event, dayDelta, minuteDelta, revertFunc){
2011-10-28 00:56:22 +04:00
$('.tipsy').remove();
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(true);
2012-02-20 14:27:25 +04:00
$.post(OC.filePath('calendar', 'ajax/event', 'resize.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, lastmodified: event.lastmodified},
2011-10-19 01:02:00 +04:00
function(data) {
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(false);
2011-10-19 01:02:00 +04:00
if (data.status == 'success'){
event.lastmodified = data.lastmodified;
2011-10-19 01:02:00 +04:00
console.log("Event resized successfully");
}else{
revertFunc();
$('#calendar_holder').fullCalendar('refetchEvents');
2011-10-19 01:02:00 +04:00
}
});
},
showadvancedoptions:function(){
2011-12-26 02:19:49 +04:00
$("#advanced_options").slideDown('slow');
$("#advanced_options_button").css("display", "none");
},
2011-12-26 02:19:49 +04:00
showadvancedoptionsforrepeating:function(){
if($("#advanced_options_repeating").is(":hidden")){
$('#advanced_options_repeating').slideDown('slow');
}else{
$('#advanced_options_repeating').slideUp('slow');
}
},
getEventPopupText:function(event){
2011-10-18 23:15:11 +04:00
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}")
2011-10-21 00:18:17 +04:00
// Tue 18 October 2011 08:00 - 16:00
}
2011-10-21 23:47:42 +04:00
var html =
'<div class="summary">' + event.title + '</div>' +
'<div class="timespan">' + timespan + '</div>';
if (event.description){
html += '<div class="description">' + 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');
}
},
2011-09-16 19:50:55 +04:00
showCalDAVUrl:function(username, calname){
2012-06-22 01:27:45 +04:00
$('#caldav_url').val(totalurl + '/' + username + '/' + decodeURIComponent(calname));
2011-09-16 19:50:55 +04:00
$('#caldav_url').show();
$("#caldav_url_close").show();
},
initScroll:function(){
2011-10-14 15:46:28 +04:00
if(window.addEventListener)
document.addEventListener('DOMMouseScroll', Calendar.UI.scrollCalendar, false);
2011-10-14 15:46:28 +04:00
//}else{
document.onmousewheel = Calendar.UI.scrollCalendar;
2011-10-14 15:46:28 +04:00
//}
},
scrollCalendar:function(event){
2011-10-28 00:56:22 +04:00
$('.tipsy').remove();
2011-10-14 15:46:28 +04:00
var direction;
if(event.detail){
if(event.detail < 0){
direction = 'top';
2011-10-14 15:46:28 +04:00
}else{
direction = 'down';
2011-10-14 15:46:28 +04:00
}
}
if (event.wheelDelta){
if(event.wheelDelta > 0){
direction = 'top';
2011-10-14 15:46:28 +04:00
}else{
direction = 'down';
2011-10-14 15:46:28 +04:00
}
}
2011-10-25 21:56:57 +04:00
var scroll = $(document).scrollTop(),
doc_height = $(document).height(),
win_height = $(window).height();
if(direction == 'down' && win_height == (doc_height - scroll)){
$('#calendar_holder').fullCalendar('next');
2011-11-18 02:53:06 +04:00
$(document).scrollTop(0);
event.preventDefault();
2011-10-25 21:56:57 +04:00
}else if (direction == 'top' && scroll == 0) {
$('#calendar_holder').fullCalendar('prev');
2011-11-18 02:53:06 +04:00
$(document).scrollTop(win_height);
event.preventDefault();
2011-10-14 15:46:28 +04:00
}
},
2011-12-26 02:19:49 +04:00
repeat:function(task){
if(task=='init'){
$('#byweekno').multiselect({
header: false,
noneSelectedText: $('#advanced_byweekno').attr('title'),
selectedList: 2,
minWidth:'auto'
});
$('#weeklyoptions').multiselect({
header: false,
noneSelectedText: $('#weeklyoptions').attr('title'),
selectedList: 2,
minWidth:'auto'
});
$('input[name="bydate"]').datepicker({
dateFormat : 'dd-mm-yy'
});
$('#byyearday').multiselect({
header: false,
noneSelectedText: $('#byyearday').attr('title'),
selectedList: 2,
minWidth:'auto'
});
$('#bymonth').multiselect({
header: false,
noneSelectedText: $('#bymonth').attr('title'),
selectedList: 2,
minWidth:'auto'
});
$('#bymonthday').multiselect({
header: false,
noneSelectedText: $('#bymonthday').attr('title'),
selectedList: 2,
minWidth:'auto'
});
Calendar.UI.repeat('end');
Calendar.UI.repeat('month');
Calendar.UI.repeat('year');
2012-01-05 23:54:44 +04:00
Calendar.UI.repeat('repeat');
2011-12-26 02:19:49 +04:00
}
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');
2012-01-05 23:54:44 +04:00
Calendar.UI.repeat('month');
2011-12-26 02:19:49 +04:00
}
if($('#repeat option:selected').val() == 'weekly'){
$('#advanced_weekday').css('display', 'block');
}
if($('#repeat option:selected').val() == 'yearly'){
$('#advanced_year').css('display', 'block');
2012-01-05 23:54:44 +04:00
Calendar.UI.repeat('year');
2011-12-26 02:19:49 +04:00
}
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');
2011-12-26 02:19:49 +04:00
}
if($('#advanced_year_select option:selected').val() == 'byweekno'){
2011-12-26 02:19:49 +04:00
$('#advanced_byweekno').css('display', 'block');
}
if($('#advanced_year_select option:selected').val() == 'bydaymonth'){
2011-12-26 02:19:49 +04:00
$('#advanced_bymonth').css('display', 'block');
$('#advanced_bymonthday').css('display', 'block');
$('#advanced_weekday').css('display', 'block');
}
}
2012-01-05 23:54:44 +04:00
2011-12-26 02:19:49 +04:00
},
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 'list':
id = 'listview_radio';
break;
}
$('#'+id).addClass('active');
2012-01-15 03:06:26 +04:00
},
categoriesChanged:function(newcategories){
categories = $.map(newcategories, function(v) {return v;});
console.log('Calendar categories changed to: ' + categories);
$('#category').multiple_autocomplete('option', 'source', categories);
},
Calendar:{
overview:function(){
if($('#choosecalendar_dialog').dialog('isOpen') == true){
$('#choosecalendar_dialog').dialog('moveToTop');
}else{
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(true);
2012-02-20 14:27:25 +04:00
$('#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();
}
});
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(false);
});
}
},
activation:function(checkbox, calendarid)
{
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(true);
2012-02-20 14:27:25 +04:00
$.post(OC.filePath('calendar', 'ajax/calendar', 'activation.php'), { calendarid: calendarid, active: checkbox.checked?1:0 },
function(data) {
2011-12-28 00:48:04 +04:00
Calendar.UI.loading(false);
2011-10-19 21:07:56 +04:00
if (data.status == 'success'){
checkbox.checked = data.active == 1;
if (data.active == 1){
$('#calendar_holder').fullCalendar('addEventSource', data.eventSource);
}else{
$('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url);
}
}
});
},
newCalendar:function(object){
var tr = $(document.createElement('tr'))
2012-02-20 14:27:25 +04:00
.load(OC.filePath('calendar', 'ajax/calendar', 'new.form.php'),
2011-10-14 16:56:18 +04:00
function(){Calendar.UI.Calendar.colorPicker(this)});
$(object).closest('tr').after(tr).hide();
},
edit:function(object, calendarid){
var tr = $(document.createElement('tr'))
2012-06-09 16:40:15 +04:00
.load(OC.filePath('calendar', 'ajax/calendar', 'edit.form.php'), {calendarid: calendarid},
function(){Calendar.UI.Calendar.colorPicker(this)});
$(object).closest('tr').after(tr).hide();
},
2011-10-19 21:07:56 +04:00
deleteCalendar:function(calid){
var check = confirm("Do you really want to delete this calendar?");
if(check == false){
return false;
}else{
2012-02-20 14:27:25 +04:00
$.post(OC.filePath('calendar', 'ajax/calendar', 'delete.php'), { calendarid: calid},
2011-10-19 21:07:56 +04:00
function(data) {
if (data.status == 'success'){
var url = 'ajax/events.php?calendar_id='+calid;
$('#calendar_holder').fullCalendar('removeEventSource', url);
$('#choosecalendar_dialog').dialog('destroy').remove();
Calendar.UI.Calendar.overview();
2012-06-15 04:07:32 +04:00
$('#calendar_holder').fullCalendar('refetchEvents');
2011-10-19 21:07:56 +04:00
}
});
}
},
submit:function(button, calendarid){
2012-01-21 20:42:34 +04:00
var displayname = $.trim($("#displayname_"+calendarid).val());
2011-10-19 21:07:56 +04:00
var active = $("#edit_active_"+calendarid+":checked").length;
var description = $("#description_"+calendarid).val();
var calendarcolor = $("#calendarcolor_"+calendarid).val();
2012-01-21 20:42:34 +04:00
if(displayname == ''){
$("#displayname_"+calendarid).css('background-color', '#FF2626');
$("#displayname_"+calendarid).focus(function(){
$("#displayname_"+calendarid).css('background-color', '#F8F8F8');
});
}
2011-10-19 21:07:56 +04:00
var url;
if (calendarid == 'new'){
2012-02-20 14:27:25 +04:00
url = OC.filePath('calendar', 'ajax/calendar', 'new.php');
2011-10-19 21:07:56 +04:00
}else{
2012-02-20 14:27:25 +04:00
url = OC.filePath('calendar', 'ajax/calendar', 'update.php');
2011-10-19 21:07:56 +04:00
}
$.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor },
function(data){
if(data.status == 'success'){
$(button).closest('tr').prev().html(data.page).show().next().remove();
$('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url);
$('#calendar_holder').fullCalendar('addEventSource', data.eventSource);
if (calendarid == 'new'){
2012-02-05 00:23:31 +04:00
$('#choosecalendar_dialog > table:first').append('<tr><td colspan="6"><a href="#" onclick="Calendar.UI.Calendar.newCalendar(this);"><input type="button" value="' + newcalendar + '"></a></td></tr>');
}
2012-01-21 20:42:34 +04:00
}else{
$("#displayname_"+calendarid).css('background-color', '#FF2626');
$("#displayname_"+calendarid).focus(function(){
$("#displayname_"+calendarid).css('background-color', '#F8F8F8');
});
2011-10-19 21:07:56 +04:00
}
}, 'json');
},
cancel:function(button, calendarid){
$(button).closest('tr').prev().show().next().remove();
},
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
});
2011-10-19 21:07:56 +04:00
}
2012-02-05 00:23:31 +04:00
},
Share:{
currentid: 'false',
idtype: '',
activation:function(object,owner,id){
2012-06-09 16:40:15 +04:00
$.post(OC.filePath('calendar', 'ajax/share', 'activation.php'),{id:id, idtype:'calendar', activation:object.checked?1:0});
$('#calendar_holder').fullCalendar('refetchEvents');
},
2012-02-05 00:23:31 +04:00
dropdown:function(userid, calid){
$('.calendar_share_dropdown').remove();
var element = document.getElementById(userid+'_'+calid);
$('<div class="calendar_share_dropdown"></div>').appendTo(element);
2012-06-09 16:40:15 +04:00
$.post(OC.filePath('calendar', 'ajax/share', 'dropdown.php'), {calid: calid}, function(data){
$('.calendar_share_dropdown').html(data);
$('.calendar_share_dropdown').show('blind');
2012-02-05 00:23:31 +04:00
$('#share_user').chosen();
$('#share_group').chosen();
});
Calendar.UI.Share.currentid = calid;
Calendar.UI.Share.idtype = 'calendar';
},
share:function(id, idtype, sharewith, sharetype){
2012-06-09 16:40:15 +04:00
$.post(OC.filePath('calendar', 'ajax/share', 'share.php'),{id:id, idtype:idtype, sharewith:sharewith, sharetype:sharetype}, function(data){
if(sharetype == 'public'){
$('#public_token').val(parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=calendar&t='+data.message);
$('#public_token').css('display', 'block');
}
2012-02-05 00:23:31 +04:00
});
},
unshare:function(id, idtype, sharewith, sharetype){
2012-06-09 16:40:15 +04:00
$.post(OC.filePath('calendar', 'ajax/share', 'unshare.php'),{id:id, idtype:idtype, sharewith:sharewith, sharetype:sharetype}, function(){
2012-02-05 00:23:31 +04:00
if(sharetype == 'public'){
$('#public_token').val('');
$('#public_token').css('display', 'none');
}
});
},
changepermission:function(id, idtype, sharewith, sharetype, permission){
2012-06-09 16:40:15 +04:00
$.post(OC.filePath('calendar', 'ajax/share', 'changepermission.php'),{id:id, idtype:idtype, sharewith: sharewith, sharetype:sharetype, permission: (permission?1:0)});
2012-02-05 00:23:31 +04:00
},
init:function(){
$('.calendar_share_dropdown').live('mouseleave', function(){
$('.calendar_share_dropdown').hide('blind', function(){
$('.calendar_share_dropdown').remove();
});
});
$('#share_user').live('change', function(){
if($('#sharewithuser_' + $('#share_user option:selected').text()).length == 0){
Calendar.UI.Share.share(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $('#share_user option:selected').text(), 'user');
var newitem = '<li id="sharewithuser_' + $('#share_user option:selected').text() +'"><input type="checkbox" width="12px" style="visibility:hidden;" title="' + $('#share_user option:selected').text() + '">' + $('#share_user option:selected').text() + '<img src="' + OC.imagePath('core', 'actions/delete.svg') + '" class="svg action" style="display:none;float:right;"></li>';
2012-02-05 00:23:31 +04:00
$('#sharewithuser_list').append(newitem);
$('#sharewithuser_' + $('#share_user option:selected').text() + ' > img').click(function(){
2012-02-11 16:30:15 +04:00
$('#share_user option[value="' + $(this).parent().text() + '"]').removeAttr('disabled');
2012-02-05 00:23:31 +04:00
Calendar.UI.Share.unshare(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $(this).parent().text(), 'user' );
2012-02-11 16:30:15 +04:00
$("#share_user").trigger("liszt:updated");
2012-02-18 00:19:04 +04:00
$(this).parent().remove();
2012-02-05 00:23:31 +04:00
});
$('#share_user option:selected').attr('disabled', 'disabled');
$("#share_user").trigger("liszt:updated");
}
});
$('#share_group').live('change', function(){
if($('#sharewithgroup_' + $('#share_group option:selected').text()).length == 0){
Calendar.UI.Share.share(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $('#share_group option:selected').text(), 'group');
var newitem = '<li id="sharewithgroup_' + $('#share_group option:selected').text() +'"><input type="checkbox" width="12px" style="visibility:hidden;" title="' + $('#share_group option:selected').text() + '">' + $('#share_group option:selected').text() + '<img src="' + OC.imagePath('core', 'actions/delete.svg') + '" class="svg action" style="display:none;float:right;"></li>';
2012-02-05 00:23:31 +04:00
$('#sharewithgroup_list').append(newitem);
2012-02-11 16:30:15 +04:00
$('#sharewithgroup_' + $('#share_group option:selected').text() + ' > img').click(function(){
$('#share_group option[value="' + $(this).parent().text() + '"]').removeAttr('disabled');
2012-02-05 00:23:31 +04:00
Calendar.UI.Share.unshare(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $(this).parent().text(), 'group');
2012-02-11 16:30:15 +04:00
$("#share_group").trigger("liszt:updated");
2012-02-18 00:19:04 +04:00
$(this).parent().remove();
2012-02-05 00:23:31 +04:00
});
$('#share_group option:selected').attr('disabled', 'disabled');
$("#share_group").trigger("liszt:updated");
}
});
$('#sharewithuser_list > li > input:checkbox').live('change', function(){
Calendar.UI.Share.changepermission(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $(this).parent().text(), 'user', this.checked);
});
$('#sharewithgroup_list > li > input:checkbox').live('change', function(){
Calendar.UI.Share.changepermission(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $(this).parent().text(), 'group', this.checked);
});
$('#publish').live('change', function(){
if(this.checked == 1){
Calendar.UI.Share.share(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, '', 'public');
}else{
Calendar.UI.Share.unshare(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, '', 'public');
}
});
$('#sharewithuser_list').live('mouseenter', function(){
$('#sharewithuser_list > li > img').css('display', 'block');
$('#sharewithuser_list > li > input').css('visibility', 'visible');
});
$('#sharewithuser_list').live('mouseleave', function(){
$('#sharewithuser_list > li > img').css('display', 'none');
$('#sharewithuser_list > li > input').css('visibility', 'hidden');
});
$('#sharewithgroup_list').live('mouseenter', function(){
$('#sharewithgroup_list > li > img').css('display', 'block');
$('#sharewithgroup_list > li > input').css('visibility', 'visible');
});
$('#sharewithgroup_list').live('mouseleave', function(){
$('#sharewithgroup_list > li > img').css('display', 'none');
$('#sharewithgroup_list > li > input').css('visibility', 'hidden');
});
/*var permissions = (this.checked) ? 1 : 0;*/
}
2012-05-13 17:05:57 +04:00
},
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('calendar_holder');
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]
reader = new FileReader();
reader.onload = function(event){
if(file.type != 'text/calendar'){
$('#notification').html('At least one file don\'t seems to be a calendar file. File skipped.');
$('#notification').slideDown();
window.setTimeout(function(){$('#notification').slideUp();}, 5000);
return false;
}else{
Calendar.UI.Drop.import(event.target.result);
2012-05-13 17:08:27 +04:00
$('#calendar_holder').fullCalendar('refetchEvents');
2012-05-13 17:05:57 +04:00
}
}
reader.readAsDataURL(file);
}
},
import:function(data){
$.post(OC.filePath('calendar', 'ajax/import', 'dropimport.php'), {'data':data},function(result) {
2012-05-13 17:08:27 +04:00
if(result.status == 'success'){
2012-05-13 17:05:57 +04:00
return true;
}else{
$('#notification').html('ownCloud wasn\'t able to import at least one file. File skipped.');
$('#notification').slideDown();
window.setTimeout(function(){$('#notification').slideUp();}, 5000);
}
});
}
2011-10-21 00:18:17 +04:00
}
}
}
$.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;
function setHeight(height, dateChanged) {
}
function setWidth(width) {
}
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);
2011-10-21 00:18:17 +04:00
if (!opt('weekends')) {
skipWeekend(t.start, delta < 0 ? -1 : 1);
2011-09-07 17:13:26 +04:00
}
2011-10-21 00:18:17 +04:00
}else{
addDays(t.start, 7);
2011-10-21 00:18:17 +04:00
addDays(t.end, 7);
if (!opt('weekends')) {
skipWeekend(t.end, delta < 0 ? -1 : 1);
2011-09-07 17:13:26 +04:00
}
2011-10-21 00:18:17 +04:00
}
}
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">' +
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);
2011-09-03 16:05:20 +04:00
}
2011-10-21 00:18:17 +04:00
$.merge(dayRows, eventElement);
eventElementHandlers(event, eventElement);
reportEventElement(event, eventElement);
}
}
2011-10-21 00:18:17 +04:00
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);
}
}
2011-09-07 17:13:26 +04:00
$(document).ready(function(){
2011-10-25 21:56:57 +04:00
Calendar.UI.initScroll();
2011-10-18 21:58:47 +04:00
$('#calendar_holder').fullCalendar({
header: false,
firstDay: firstDay,
2011-10-18 21:58:47 +04:00
editable: true,
2011-10-18 22:42:22 +04:00
defaultView: defaultView,
timeFormat: {
agenda: agendatime,
'': defaulttime
2011-10-18 22:42:22 +04:00
},
columnFormat: {
month: t('calendar', 'ddd'), // Mon
week: t('calendar', 'ddd M/d'), // Mon 9/7
day: t('calendar', 'dddd M/d') // Monday 9/7
},
2011-10-21 00:18:17 +04:00
titleFormat: {
month: t('calendar', 'MMMM yyyy'),
// September 2009
week: t('calendar', "MMM d[ yyyy]{ '&#8212;'[ MMM] d yyyy}"),
// Sep 7 - 13 2009
day: t('calendar', 'dddd, MMM d, yyyy'),
// Tuesday, Sep 8, 2009
2011-10-21 00:18:17 +04:00
},
axisFormat: defaulttime,
2011-10-18 22:42:22 +04:00
monthNames: monthNames,
monthNamesShort: monthNamesShort,
dayNames: dayNames,
dayNamesShort: dayNamesShort,
allDayText: allDayText,
2011-10-18 21:58:47 +04:00
viewDisplay: function(view) {
$('#datecontrol_date').val($('<p>').html(view.title).text());
if (view.name != defaultView) {
2012-06-09 16:40:15 +04:00
$.post(OC.filePath('calendar', 'ajax', 'changeview.php'), {v:view.name});
defaultView = view.name;
}
Calendar.UI.setViewActive(view.name);
if (view.name == 'agendaWeek') {
$('#calendar_holder').fullCalendar('option', 'aspectRatio', 0.1);
}
else {
$('#calendar_holder').fullCalendar('option', 'aspectRatio', 1.35);
}
},
2012-01-21 20:42:34 +04:00
columnFormat: {
week: 'ddd d. MMM'
},
2011-10-25 21:57:20 +04:00
selectable: true,
selectHelper: true,
select: Calendar.UI.newEvent,
2011-10-18 23:15:11 +04:00
eventClick: Calendar.UI.editEvent,
2011-10-19 00:25:54 +04:00
eventDrop: Calendar.UI.moveEvent,
2011-10-19 01:02:00 +04:00
eventResize: Calendar.UI.resizeEvent,
2011-10-21 23:47:42 +04:00
eventRender: function(event, element) {
element.find('.fc-event-title').html(element.find('.fc-event-title').text());
2011-10-21 23:47:42 +04:00
element.tipsy({
className: 'tipsy-event',
opacity: 0.9,
gravity:$.fn.tipsy.autoBounds(150, 's'),
fade:true,
delayIn: 400,
html:true,
title:function() {
return Calendar.UI.getEventPopupText(event);
}
});
},
2011-12-28 00:48:04 +04:00
loading: Calendar.UI.loading,
2011-10-18 23:15:11 +04:00
eventSources: eventSources
2011-10-18 21:58:47 +04:00
});
$('#datecontrol_date').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
beforeShow: function(input, inst) {
var calendar_holder = $('#calendar_holder');
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');
$('#calendar_holder').fullCalendar('gotoDate', date);
}
});
fillWindow($('#content'));
OCCategories.changed = Calendar.UI.categoriesChanged;
OCCategories.app = 'calendar';
2011-10-18 21:58:47 +04:00
$('#oneweekview_radio').click(function(){
$('#calendar_holder').fullCalendar('changeView', 'agendaWeek');
});
$('#onemonthview_radio').click(function(){
$('#calendar_holder').fullCalendar('changeView', 'month');
});
2011-10-21 00:18:17 +04:00
$('#listview_radio').click(function(){
$('#calendar_holder').fullCalendar('changeView', 'list');
});
2011-10-18 21:58:47 +04:00
$('#today_input').click(function(){
$('#calendar_holder').fullCalendar('today');
});
$('#datecontrol_left').click(function(){
$('#calendar_holder').fullCalendar('prev');
});
$('#datecontrol_right').click(function(){
$('#calendar_holder').fullCalendar('next');
});
2012-02-05 00:23:31 +04:00
Calendar.UI.Share.init();
2012-05-13 17:05:57 +04:00
Calendar.UI.Drop.init();
2011-09-07 17:13:26 +04:00
});