3
|
1 /**
|
|
2 * Base Javascript class for the Calendar plugin
|
|
3 *
|
|
4 * @author Lazlo Westerhof <hello@lazlo.me>
|
|
5 * @author Thomas Bruederli <bruederli@kolabsys.com>
|
|
6 *
|
|
7 * @licstart The following is the entire license notice for the
|
|
8 * JavaScript code in this page.
|
|
9 *
|
|
10 * Copyright (C) 2010, Lazlo Westerhof <hello@lazlo.me>
|
|
11 * Copyright (C) 2013-2015, Kolab Systems AG <contact@kolabsys.com>
|
|
12 *
|
|
13 * This program is free software: you can redistribute it and/or modify
|
|
14 * it under the terms of the GNU Affero General Public License as
|
|
15 * published by the Free Software Foundation, either version 3 of the
|
|
16 * License, or (at your option) any later version.
|
|
17 *
|
|
18 * This program is distributed in the hope that it will be useful,
|
|
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 * GNU Affero General Public License for more details.
|
|
22 *
|
|
23 * You should have received a copy of the GNU Affero General Public License
|
|
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
25 *
|
|
26 * @licend The above is the entire license notice
|
|
27 * for the JavaScript code in this page.
|
|
28 */
|
|
29
|
|
30 // Basic setup for Roundcube calendar client class
|
|
31 function rcube_calendar(settings)
|
|
32 {
|
|
33 // extend base class
|
|
34 rcube_libcalendaring.call(this, settings);
|
|
35
|
|
36 // member vars
|
|
37 this.ui_loaded = false;
|
|
38 this.selected_attachment = null;
|
|
39
|
|
40 // private vars
|
|
41 var me = this;
|
|
42
|
|
43 // create new event from current mail message
|
|
44 this.create_from_mail = function(uid)
|
|
45 {
|
|
46 if (uid || (uid = rcmail.get_single_uid())) {
|
|
47 // load calendar UI (scripts and edit dialog template)
|
|
48 if (!this.ui_loaded) {
|
|
49 $.when(
|
|
50 $.getScript(rcmail.assets_path('plugins/calendar/calendar_ui.js')),
|
|
51 $.getScript(rcmail.assets_path('plugins/calendar/lib/js/fullcalendar.js')),
|
|
52 $.get(rcmail.url('calendar/inlineui'), function(html) { $(document.body).append(html); }, 'html')
|
|
53 ).then(function() {
|
|
54 // disable attendees feature (autocompletion and stuff is not initialized)
|
|
55 for (var c in rcmail.env.calendars)
|
|
56 rcmail.env.calendars[c].attendees = rcmail.env.calendars[c].resources = false;
|
|
57
|
|
58 me.ui_loaded = true;
|
|
59 me.ui = new rcube_calendar_ui(me.settings);
|
|
60 me.create_from_mail(uid); // start over
|
|
61 });
|
|
62
|
|
63 return;
|
|
64 }
|
|
65
|
|
66 // get message contents for event dialog
|
|
67 var lock = rcmail.set_busy(true, 'loading');
|
|
68 rcmail.http_post('calendar/mailtoevent', {
|
|
69 '_mbox': rcmail.env.mailbox,
|
|
70 '_uid': uid
|
|
71 }, lock);
|
|
72 }
|
|
73 };
|
|
74
|
|
75 // callback function triggered from server with contents for the new event
|
|
76 this.mail2event_dialog = function(event)
|
|
77 {
|
|
78 if (event.title) {
|
|
79 this.ui.add_event(event);
|
|
80 if (rcmail.message_list)
|
|
81 rcmail.message_list.blur();
|
|
82 }
|
|
83 };
|
|
84
|
|
85 // handler for attachment-save-calendar commands
|
|
86 this.save_to_calendar = function(p)
|
|
87 {
|
|
88 // TODO: show dialog to select the calendar for importing
|
|
89 if (this.selected_attachment && window.rcube_libcalendaring) {
|
|
90 rcmail.http_post('calendar/mailimportattach', {
|
|
91 _uid: rcmail.env.uid,
|
|
92 _mbox: rcmail.env.mailbox,
|
|
93 _part: this.selected_attachment
|
|
94 // _calendar: $('#calendar-attachment-saveto').val(),
|
|
95 }, rcmail.set_busy(true, 'itip.savingdata'));
|
|
96 }
|
|
97 }
|
|
98 }
|
|
99
|
|
100
|
|
101 /* calendar plugin initialization (for non-calendar tasks) */
|
|
102 window.rcmail && rcmail.addEventListener('init', function(evt) {
|
|
103 if (rcmail.task != 'calendar') {
|
|
104 var cal = new rcube_calendar($.extend(rcmail.env.calendar_settings, rcmail.env.libcal_settings));
|
|
105
|
|
106 // register create-from-mail command to message_commands array
|
|
107 if (rcmail.env.task == 'mail') {
|
|
108 rcmail.register_command('calendar-create-from-mail', function() { cal.create_from_mail(); });
|
|
109 rcmail.register_command('attachment-save-calendar', function() { cal.save_to_calendar(); });
|
|
110 rcmail.addEventListener('plugin.mail2event_dialog', function(p) { cal.mail2event_dialog(p); });
|
|
111 rcmail.addEventListener('plugin.unlock_saving', function(p) { cal.ui && cal.ui.unlock_saving(); });
|
|
112
|
|
113 if (rcmail.env.action != 'show') {
|
|
114 rcmail.env.message_commands.push('calendar-create-from-mail');
|
|
115 rcmail.add_element($('<a>'));
|
|
116 }
|
|
117 else {
|
|
118 rcmail.enable_command('calendar-create-from-mail', true);
|
|
119 }
|
|
120
|
|
121 rcmail.addEventListener('beforemenu-open', function(p) {
|
|
122 if (p.menu == 'attachmentmenu') {
|
|
123 cal.selected_attachment = p.id;
|
|
124 var mimetype = rcmail.env.attachments[p.id];
|
|
125 rcmail.enable_command('attachment-save-calendar', mimetype == 'text/calendar' || mimetype == 'text/x-vcalendar' || mimetype == 'application/ics');
|
|
126 }
|
|
127 });
|
|
128 }
|
|
129 }
|
|
130
|
|
131 rcmail.register_command('plugin.calendar', function() { rcmail.switch_task('calendar'); }, true);
|
|
132
|
|
133 rcmail.addEventListener('plugin.ping_url', function(p) {
|
|
134 var action = p.action;
|
|
135 p.action = p.event = null;
|
|
136 new Image().src = rcmail.url(action, p);
|
|
137 });
|
|
138 });
|