2011-07-13 17:52:18 +03:00
|
|
|
/*
|
|
|
|
+-------------------------------------------------------------------------+
|
|
|
|
| Javascript for the Calendar Plugin |
|
|
|
|
| Version 0.3 beta |
|
|
|
|
| |
|
|
|
|
| This program is free software; you can redistribute it and/or modify |
|
|
|
|
| it under the terms of the GNU General Public License version 2 |
|
|
|
|
| as published by the Free Software Foundation. |
|
|
|
|
| |
|
|
|
|
+-------------------------------------------------------------------------+
|
|
|
|
| Author: Lazlo Westerhof <hello@lazlo.me> |
|
|
|
|
| Thomas Bruederli <roundcube@gmail.com> |
|
|
|
|
+-------------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2011-07-16 16:11:10 +02:00
|
|
|
/* calendar plugin printing code */
|
|
|
|
window.rcmail && rcmail.addEventListener('init', function(evt) {
|
2011-07-13 17:52:18 +03:00
|
|
|
|
2011-07-16 16:11:10 +02:00
|
|
|
// quote html entities
|
|
|
|
var Q = function(str)
|
|
|
|
{
|
|
|
|
return String(str).replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
|
|
};
|
|
|
|
|
|
|
|
var rc_loading;
|
|
|
|
var showdesc = true;
|
|
|
|
var settings = rcmail.env.calendar_settings;
|
|
|
|
|
|
|
|
// create list of event sources AKA calendars
|
2011-07-16 20:03:19 +02:00
|
|
|
var src, event_sources = [];
|
|
|
|
var add_url = (rcmail.env.search ? '&q='+escape(rcmail.env.search) : '');
|
2011-07-16 16:11:10 +02:00
|
|
|
for (var id in rcmail.env.calendars) {
|
|
|
|
source = $.extend({
|
2011-07-16 20:03:19 +02:00
|
|
|
url: "./?_task=calendar&_action=load_events&source=" + escape(id) + add_url,
|
2011-07-16 16:11:10 +02:00
|
|
|
className: 'fc-event-cal-'+id,
|
|
|
|
id: id
|
|
|
|
}, rcmail.env.calendars[id]);
|
2011-07-13 17:52:18 +03:00
|
|
|
|
2011-07-16 16:11:10 +02:00
|
|
|
event_sources.push(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
var viewdate = new Date();
|
|
|
|
if (rcmail.env.date)
|
|
|
|
viewdate.setTime(rcmail.env.date * 1000);
|
|
|
|
|
|
|
|
// initalize the fullCalendar plugin
|
|
|
|
var fc = $('#calendar').fullCalendar({
|
|
|
|
header: {
|
|
|
|
left: '',
|
|
|
|
center: 'title',
|
|
|
|
right: 'agendaDay,agendaWeek,month,table'
|
|
|
|
},
|
|
|
|
aspectRatio: 0.85,
|
|
|
|
ignoreTimezone: true, // will treat the given date strings as in local (browser's) timezone
|
|
|
|
date: viewdate.getDate(),
|
|
|
|
month: viewdate.getMonth(),
|
|
|
|
year: viewdate.getFullYear(),
|
|
|
|
defaultView: rcmail.env.view,
|
|
|
|
eventSources: event_sources,
|
|
|
|
monthNames : settings['months'],
|
|
|
|
monthNamesShort : settings['months_short'],
|
|
|
|
dayNames : settings['days'],
|
|
|
|
dayNamesShort : settings['days_short'],
|
|
|
|
firstDay : settings['first_day'],
|
|
|
|
firstHour : settings['first_hour'],
|
|
|
|
slotMinutes : 60/settings['timeslots'],
|
|
|
|
timeFormat: {
|
|
|
|
'': settings['time_format'],
|
|
|
|
agenda: settings['time_format'] + '{ - ' + settings['time_format'] + '}',
|
|
|
|
list: settings['time_format'] + '{ - ' + settings['time_format'] + '}',
|
|
|
|
table: settings['time_format'] + '{ - ' + settings['time_format'] + '}'
|
|
|
|
},
|
|
|
|
axisFormat : settings['time_format'],
|
|
|
|
columnFormat: {
|
|
|
|
month: 'ddd', // Mon
|
|
|
|
week: 'ddd ' + settings['date_short'], // Mon 9/7
|
|
|
|
day: 'dddd ' + settings['date_short'], // Monday 9/7
|
|
|
|
list: settings['date_agenda'],
|
|
|
|
table: settings['date_agenda']
|
|
|
|
},
|
|
|
|
titleFormat: {
|
|
|
|
month: 'MMMM yyyy',
|
2011-07-30 15:26:43 +02:00
|
|
|
week: settings['dates_long'],
|
2011-07-16 16:11:10 +02:00
|
|
|
day: 'dddd ' + settings['date_long'],
|
2011-07-30 15:26:43 +02:00
|
|
|
list: settings['dates_long'],
|
|
|
|
table: settings['dates_long']
|
2011-07-16 16:11:10 +02:00
|
|
|
},
|
|
|
|
listSections: 'smart',
|
2011-07-30 15:26:43 +02:00
|
|
|
listRange: rcmail.env.listRange || settings['agenda_range'],
|
2011-07-16 16:11:10 +02:00
|
|
|
tableCols: ['handle', 'date', 'time', 'title', 'location'],
|
|
|
|
allDayText: rcmail.gettext('all-day', 'calendar'),
|
|
|
|
buttonText: {
|
|
|
|
day: rcmail.gettext('day', 'calendar'),
|
|
|
|
week: rcmail.gettext('week', 'calendar'),
|
|
|
|
month: rcmail.gettext('month', 'calendar'),
|
|
|
|
table: rcmail.gettext('agenda', 'calendar')
|
|
|
|
},
|
|
|
|
loading: function(isLoading) {
|
|
|
|
rc_loading = rcmail.set_busy(isLoading, 'loading', rc_loading);
|
|
|
|
},
|
|
|
|
// event rendering
|
|
|
|
eventRender: function(event, element, view) {
|
|
|
|
if (view.name != 'month') {
|
|
|
|
var cont = element.find('div.fc-event-title');
|
|
|
|
if (event.location) {
|
|
|
|
cont.after('<div class="fc-event-location">@ ' + Q(event.location) + '</div>');
|
|
|
|
cont = cont.next();
|
|
|
|
}
|
|
|
|
if (event.description && showdesc) {
|
|
|
|
cont.after('<div class="fc-event-description">' + Q(event.description) + '</div>');
|
|
|
|
}
|
|
|
|
/* TODO: create icons black on white
|
|
|
|
if (event.recurrence)
|
|
|
|
element.find('div.fc-event-time').append('<i class="fc-icon-recurring"></i>');
|
|
|
|
if (event.alarms)
|
|
|
|
element.find('div.fc-event-time').append('<i class="fc-icon-alarms"></i>');
|
2011-07-13 17:52:18 +03:00
|
|
|
*/
|
2011-07-16 16:11:10 +02:00
|
|
|
}
|
|
|
|
if (view.name == 'table' && event.description && showdesc) {
|
|
|
|
var cols = element.children().css('border', 0).length;
|
|
|
|
element.after('<tr class="fc-event-row-secondary fc-event"><td colspan="'+cols+'" class="fc-event-description">' + Q(event.description) + '</td></tr>');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
viewDisplay: function(view) {
|
|
|
|
// remove hard-coded hight and make contents visible
|
|
|
|
window.setTimeout(function(){
|
|
|
|
if (view.name == 'table') {
|
|
|
|
$('div.fc-list-content').css('overflow', 'visible').height('auto');
|
2011-07-13 17:52:18 +03:00
|
|
|
}
|
|
|
|
else {
|
2011-07-16 16:11:10 +02:00
|
|
|
$('div.fc-agenda-divider')
|
|
|
|
.next().css('overflow', 'visible').height('auto')
|
|
|
|
.children('div').css('overflow', 'visible').height('auto');
|
2011-07-13 17:52:18 +03:00
|
|
|
}
|
2011-07-16 16:11:10 +02:00
|
|
|
// adjust fixed height if vertical day slots
|
|
|
|
var h = $('table.fc-agenda-slots:visible').height() + $('table.fc-agenda-allday:visible').height() + 4;
|
|
|
|
if (h) $('table.fc-agenda-days td.fc-widget-content').children('div').height(h);
|
|
|
|
}, 20);
|
|
|
|
}
|
|
|
|
});
|
2011-07-13 17:52:18 +03:00
|
|
|
|
2011-07-16 16:11:10 +02:00
|
|
|
// activate settings form
|
|
|
|
$('#propdescription').change(function(){
|
|
|
|
showdesc = this.checked;
|
|
|
|
fc.fullCalendar('render');
|
|
|
|
});
|
2011-07-13 17:52:18 +03:00
|
|
|
|
|
|
|
});
|