2013-08-06 20:23:33 +00:00
|
|
|
/**
|
|
|
|
* Base Javascript class for the Calendar plugin
|
|
|
|
*
|
|
|
|
* @author Lazlo Westerhof <hello@lazlo.me>
|
|
|
|
* @author Thomas Bruederli <bruederli@kolabsys.com>
|
|
|
|
*
|
2015-03-12 21:37:40 +00:00
|
|
|
* @licstart The following is the entire license notice for the
|
|
|
|
* JavaScript code in this page.
|
|
|
|
*
|
2013-08-06 20:23:33 +00:00
|
|
|
* Copyright (C) 2010, Lazlo Westerhof <hello@lazlo.me>
|
2015-03-12 21:37:40 +00:00
|
|
|
* Copyright (C) 2013-2015, Kolab Systems AG <contact@kolabsys.com>
|
2013-08-06 20:23:33 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-03-12 21:37:40 +00:00
|
|
|
*
|
|
|
|
* @licend The above is the entire license notice
|
|
|
|
* for the JavaScript code in this page.
|
2013-08-06 20:23:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Basic setup for Roundcube calendar client class
|
|
|
|
function rcube_calendar(settings)
|
|
|
|
{
|
|
|
|
// extend base class
|
|
|
|
rcube_libcalendaring.call(this, settings);
|
|
|
|
|
|
|
|
// member vars
|
2017-09-01 09:50:35 +00:00
|
|
|
this.ui;
|
2013-08-06 20:23:33 +00:00
|
|
|
this.ui_loaded = false;
|
2015-03-12 21:37:40 +00:00
|
|
|
this.selected_attachment = null;
|
2013-08-06 20:23:33 +00:00
|
|
|
|
|
|
|
// private vars
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
// create new event from current mail message
|
2014-09-15 19:24:14 +00:00
|
|
|
this.create_from_mail = function(uid)
|
2013-08-06 20:23:33 +00:00
|
|
|
{
|
2014-09-15 19:24:14 +00:00
|
|
|
if (uid || (uid = rcmail.get_single_uid())) {
|
2013-08-06 20:23:33 +00:00
|
|
|
// load calendar UI (scripts and edit dialog template)
|
|
|
|
if (!this.ui_loaded) {
|
|
|
|
$.when(
|
2015-03-12 21:37:40 +00:00
|
|
|
$.getScript(rcmail.assets_path('plugins/calendar/calendar_ui.js')),
|
|
|
|
$.getScript(rcmail.assets_path('plugins/calendar/lib/js/fullcalendar.js')),
|
2017-09-01 09:50:35 +00:00
|
|
|
$.get(rcmail.url('calendar/inlineui'), function(html){ $(document.body).append(html); }, 'html')
|
2013-08-06 20:23:33 +00:00
|
|
|
).then(function() {
|
|
|
|
// disable attendees feature (autocompletion and stuff is not initialized)
|
|
|
|
for (var c in rcmail.env.calendars)
|
2015-03-12 21:37:40 +00:00
|
|
|
rcmail.env.calendars[c].attendees = rcmail.env.calendars[c].resources = false;
|
2017-09-01 09:50:35 +00:00
|
|
|
|
2013-08-06 20:23:33 +00:00
|
|
|
me.ui_loaded = true;
|
|
|
|
me.ui = new rcube_calendar_ui(me.settings);
|
2014-09-15 19:24:14 +00:00
|
|
|
me.create_from_mail(uid); // start over
|
2013-08-06 20:23:33 +00:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2017-09-01 09:50:35 +00:00
|
|
|
else {
|
|
|
|
// get message contents for event dialog
|
|
|
|
var lock = rcmail.set_busy(true, 'loading');
|
|
|
|
rcmail.http_post('calendar/mailtoevent', {
|
|
|
|
'_mbox': rcmail.env.mailbox,
|
|
|
|
'_uid': uid
|
|
|
|
}, lock);
|
|
|
|
}
|
2013-08-06 20:23:33 +00:00
|
|
|
}
|
|
|
|
};
|
2017-09-01 09:50:35 +00:00
|
|
|
|
2013-08-06 20:23:33 +00:00
|
|
|
// callback function triggered from server with contents for the new event
|
|
|
|
this.mail2event_dialog = function(event)
|
|
|
|
{
|
|
|
|
if (event.title) {
|
|
|
|
this.ui.add_event(event);
|
2015-03-12 21:37:40 +00:00
|
|
|
if (rcmail.message_list)
|
|
|
|
rcmail.message_list.blur();
|
2013-08-06 20:23:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-12 21:37:40 +00:00
|
|
|
// handler for attachment-save-calendar commands
|
|
|
|
this.save_to_calendar = function(p)
|
|
|
|
{
|
|
|
|
// TODO: show dialog to select the calendar for importing
|
|
|
|
if (this.selected_attachment && window.rcube_libcalendaring) {
|
|
|
|
rcmail.http_post('calendar/mailimportattach', {
|
|
|
|
_uid: rcmail.env.uid,
|
|
|
|
_mbox: rcmail.env.mailbox,
|
2017-09-01 09:50:35 +00:00
|
|
|
_part: this.selected_attachment,
|
2015-03-12 21:37:40 +00:00
|
|
|
// _calendar: $('#calendar-attachment-saveto').val(),
|
|
|
|
}, rcmail.set_busy(true, 'itip.savingdata'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-06 20:23:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* calendar plugin initialization (for non-calendar tasks) */
|
|
|
|
window.rcmail && rcmail.addEventListener('init', function(evt) {
|
|
|
|
if (rcmail.task != 'calendar') {
|
|
|
|
var cal = new rcube_calendar($.extend(rcmail.env.calendar_settings, rcmail.env.libcal_settings));
|
|
|
|
|
|
|
|
// register create-from-mail command to message_commands array
|
|
|
|
if (rcmail.env.task == 'mail') {
|
2017-09-01 09:50:35 +00:00
|
|
|
rcmail.register_command('calendar-create-from-mail', function() { cal.create_from_mail() });
|
|
|
|
rcmail.register_command('attachment-save-calendar', function() { cal.save_to_calendar() });
|
|
|
|
rcmail.addEventListener('plugin.mail2event_dialog', function(p){ cal.mail2event_dialog(p) });
|
|
|
|
rcmail.addEventListener('plugin.unlock_saving', function(p){ cal.ui && cal.ui.unlock_saving(); });
|
|
|
|
|
2013-08-06 20:23:33 +00:00
|
|
|
if (rcmail.env.action != 'show') {
|
|
|
|
rcmail.env.message_commands.push('calendar-create-from-mail');
|
|
|
|
rcmail.add_element($('<a>'));
|
|
|
|
}
|
2015-03-12 21:37:40 +00:00
|
|
|
else {
|
2013-08-06 20:23:33 +00:00
|
|
|
rcmail.enable_command('calendar-create-from-mail', true);
|
2014-09-15 19:24:14 +00:00
|
|
|
}
|
2015-03-12 21:37:40 +00:00
|
|
|
|
|
|
|
rcmail.addEventListener('beforemenu-open', function(p) {
|
|
|
|
if (p.menu == 'attachmentmenu') {
|
|
|
|
cal.selected_attachment = p.id;
|
|
|
|
var mimetype = rcmail.env.attachments[p.id];
|
|
|
|
rcmail.enable_command('attachment-save-calendar', mimetype == 'text/calendar' || mimetype == 'text/x-vcalendar' || mimetype == 'application/ics');
|
|
|
|
}
|
|
|
|
});
|
2013-08-06 20:23:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rcmail.register_command('plugin.calendar', function() { rcmail.switch_task('calendar'); }, true);
|
2017-09-01 09:50:35 +00:00
|
|
|
|
|
|
|
rcmail.addEventListener('plugin.ping_url', function(p){
|
2013-08-06 20:23:33 +00:00
|
|
|
var action = p.action;
|
|
|
|
p.action = p.event = null;
|
|
|
|
new Image().src = rcmail.url(action, p);
|
|
|
|
});
|
|
|
|
});
|