annotate plugins/libcalendaring/libcalendaring.js @ 4:888e774ee983

libcalendar plugin as distributed
author Charlie Root
date Sat, 13 Jan 2018 08:57:56 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
2 * Basic Javascript utilities for calendar-related plugins
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
3 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4 * @author Thomas Bruederli <bruederli@kolabsys.com>
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6 * @licstart The following is the entire license notice for the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 * JavaScript code in this page.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 * Copyright (C) 2012-2015, Kolab Systems AG <contact@kolabsys.com>
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 * This program is free software: you can redistribute it and/or modify
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 * it under the terms of the GNU Affero General Public License as
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 * published by the Free Software Foundation, either version 3 of the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 * License, or (at your option) any later version.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 * GNU Affero General Public License for more details.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 * You should have received a copy of the GNU Affero General Public License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 * @licend The above is the entire license notice
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25 * for the JavaScript code in this page.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 function rcube_libcalendaring(settings)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30 // member vars
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 this.settings = settings || {};
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 this.alarm_ids = [];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33 this.alarm_dialog = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 this.snooze_popup = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 this.dismiss_link = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 this.group2expand = {};
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 // abort if env isn't set
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 if (!settings || !settings.date_format)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42 // private vars
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43 var me = this;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 var gmt_offset = (new Date().getTimezoneOffset() / -60) - (settings.timezone || 0) - (settings.dst || 0);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 var client_timezone = new Date().getTimezoneOffset();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 // general datepicker settings
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 var datepicker_settings = {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 // translate from fullcalendar format to datepicker format
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50 dateFormat: settings.date_format.replace(/M/g, 'm').replace(/mmmmm/, 'MM').replace(/mmm/, 'M').replace(/dddd/, 'DD').replace(/ddd/, 'D').replace(/yy/g, 'y'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 firstDay : settings.first_day,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52 dayNamesMin: settings.days_short,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 monthNames: settings.months,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54 monthNamesShort: settings.months,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 changeMonth: false,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56 showOtherMonths: true,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 selectOtherMonths: true
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62 * Quote html entities
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64 var Q = this.quote_html = function(str)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 return String(str).replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70 * Create a nice human-readable string for the date/time range
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72 this.event_date_text = function(event, voice)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74 if (!event.start)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75 return '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
76 if (!event.end)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
77 event.end = event.start;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
78
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
79 var fromto, duration = event.end.getTime() / 1000 - event.start.getTime() / 1000,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
80 until = voice ? ' ' + rcmail.gettext('until','libcalendaring') + ' ' : ' — ';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
81 if (event.allDay) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
82 fromto = this.format_datetime(event.start, 1, voice)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
83 + (duration > 86400 || event.start.getDay() != event.end.getDay() ? until + this.format_datetime(event.end, 1, voice) : '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
84 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
85 else if (duration < 86400 && event.start.getDay() == event.end.getDay()) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
86 fromto = this.format_datetime(event.start, 0, voice)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
87 + (duration > 0 ? until + this.format_datetime(event.end, 2, voice) : '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
88 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
89 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
90 fromto = this.format_datetime(event.start, 0, voice)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
91 + (duration > 0 ? until + this.format_datetime(event.end, 0, voice) : '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
92 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
93
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
94 return fromto;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
95 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
96
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
97 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
98 * Checks if the event/task has 'real' attendees, excluding the current user
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
99 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
100 this.has_attendees = function(event)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
101 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
102 return !!(event.attendees && event.attendees.length && (event.attendees.length > 1 || String(event.attendees[0].email).toLowerCase() != settings.identity.email));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
103 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
104
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
105 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
106 * Check if the current user is an attendee of this event/task
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
107 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
108 this.is_attendee = function(event, role, email)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
109 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
110 var i, emails = email ? ';' + email.toLowerCase() : settings.identity.emails;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
111
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
112 for (i=0; event.attendees && i < event.attendees.length; i++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
113 if ((!role || event.attendees[i].role == role) && event.attendees[i].email && emails.indexOf(';'+event.attendees[i].email.toLowerCase()) >= 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
114 return event.attendees[i];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
115 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
116 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
117
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
118 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
119 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
120
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
121 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
122 * Checks if the current user is the organizer of the event/task
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
123 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
124 this.is_organizer = function(event, email)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
125 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
126 return this.is_attendee(event, 'ORGANIZER', email) || !event.id;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
127 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
128
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
129 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
130 * Check permissions on the given folder object
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
131 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
132 this.has_permission = function(folder, perm)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
133 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
134 // multiple chars means "either of"
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
135 if (String(perm).length > 1) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
136 for (var i=0; i < perm.length; i++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
137 if (this.has_permission(folder, perm[i])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
138 return true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
139 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
140 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
141 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
142
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
143 if (folder.rights && String(folder.rights).indexOf(perm) >= 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
144 return true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
145 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
146
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
147 return (perm == 'i' && folder.editable) || (perm == 'v' && folder.editable);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
148 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
149
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
150
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
151 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
152 * From time and date strings to a real date object
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
153 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
154 this.parse_datetime = function(time, date)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
155 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
156 // we use the utility function from datepicker to parse dates
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
157 var date = date ? $.datepicker.parseDate(datepicker_settings.dateFormat, date, datepicker_settings) : new Date();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
158
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
159 var time_arr = time.replace(/\s*[ap][.m]*/i, '').replace(/0([0-9])/g, '$1').split(/[:.]/);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
160 if (!isNaN(time_arr[0])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
161 date.setHours(time_arr[0]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
162 if (time.match(/p[.m]*/i) && date.getHours() < 12)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
163 date.setHours(parseInt(time_arr[0]) + 12);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
164 else if (time.match(/a[.m]*/i) && date.getHours() == 12)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
165 date.setHours(0);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
166 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
167 if (!isNaN(time_arr[1]))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
168 date.setMinutes(time_arr[1]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
169
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
170 return date;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
171 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
172
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
173 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
174 * Convert an ISO 8601 formatted date string from the server into a Date object.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
175 * Timezone information will be ignored, the server already provides dates in user's timezone.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
176 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
177 this.parseISO8601 = function(s)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
178 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
179 // already a Date object?
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
180 if (s && s.getMonth) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
181 return s;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
182 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
183
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
184 // force d to be on check's YMD, for daylight savings purposes
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
185 var fixDate = function(d, check) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
186 if (+d) { // prevent infinite looping on invalid dates
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
187 while (d.getDate() != check.getDate()) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
188 d.setTime(+d + (d < check ? 1 : -1) * 3600000);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
189 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
190 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
191 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
192
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
193 // derived from http://delete.me.uk/2005/03/iso8601.html
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
194 var m = s && s.match(/^([0-9]{4})(-([0-9]{2})(-([0-9]{2})([T ]([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2})(:?([0-9]{2}))?))?)?)?)?$/);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
195 if (!m) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
196 return null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
197 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
198
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
199 var date = new Date(m[1], 0, 2),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
200 check = new Date(m[1], 0, 2, 9, 0);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
201 if (m[3]) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
202 date.setMonth(m[3] - 1);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
203 check.setMonth(m[3] - 1);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
204 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
205 if (m[5]) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
206 date.setDate(m[5]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
207 check.setDate(m[5]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
208 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
209 fixDate(date, check);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
210 if (m[7]) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
211 date.setHours(m[7]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
212 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
213 if (m[8]) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
214 date.setMinutes(m[8]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
215 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
216 if (m[10]) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
217 date.setSeconds(m[10]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
218 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
219 if (m[12]) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
220 date.setMilliseconds(Number("0." + m[12]) * 1000);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
221 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
222 fixDate(date, check);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
223
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
224 return date;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
225 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
226
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
227 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
228 * Turn the given date into an ISO 8601 date string understandable by PHPs strtotime()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
229 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
230 this.date2ISO8601 = function(date)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
231 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
232 var zeropad = function(num) { return (num < 10 ? '0' : '') + num; };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
233
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
234 return date.getFullYear() + '-' + zeropad(date.getMonth()+1) + '-' + zeropad(date.getDate())
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
235 + 'T' + zeropad(date.getHours()) + ':' + zeropad(date.getMinutes()) + ':' + zeropad(date.getSeconds());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
236 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
237
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
238 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
239 * Format the given date object according to user's prefs
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
240 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
241 this.format_datetime = function(date, mode, voice)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
242 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
243 var res = '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
244 if (!mode || mode == 1) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
245 res += $.datepicker.formatDate(voice ? 'MM d yy' : datepicker_settings.dateFormat, date, datepicker_settings);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
246 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
247 if (!mode) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
248 res += voice ? ' ' + rcmail.gettext('at','libcalendaring') + ' ' : ' ';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
249 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
250 if (!mode || mode == 2) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
251 res += this.format_time(date, voice);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
252 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
253
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
254 return res;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
255 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
256
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
257 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
258 * Clone from fullcalendar.js
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
259 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
260 this.format_time = function(date, voice)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
261 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
262 var zeroPad = function(n) { return (n < 10 ? '0' : '') + n; }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
263 var formatters = {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
264 s : function(d) { return d.getSeconds() },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
265 ss : function(d) { return zeroPad(d.getSeconds()) },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
266 m : function(d) { return d.getMinutes() },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
267 mm : function(d) { return zeroPad(d.getMinutes()) },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
268 h : function(d) { return d.getHours() % 12 || 12 },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
269 hh : function(d) { return zeroPad(d.getHours() % 12 || 12) },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
270 H : function(d) { return d.getHours() },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
271 HH : function(d) { return zeroPad(d.getHours()) },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
272 t : function(d) { return d.getHours() < 12 ? 'a' : 'p' },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
273 tt : function(d) { return d.getHours() < 12 ? 'am' : 'pm' },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
274 T : function(d) { return d.getHours() < 12 ? 'A' : 'P' },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
275 TT : function(d) { return d.getHours() < 12 ? 'AM' : 'PM' }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
276 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
277
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
278 var i, i2, c, formatter, res = '',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
279 format = voice ? settings['time_format'].replace(':',' ').replace('HH','H').replace('hh','h').replace('mm','m').replace('ss','s') : settings['time_format'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
280 for (i=0; i < format.length; i++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
281 c = format.charAt(i);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
282 for (i2=Math.min(i+2, format.length); i2 > i; i2--) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
283 if (formatter = formatters[format.substring(i, i2)]) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
284 res += formatter(date);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
285 i = i2 - 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
286 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
287 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
288 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
289 if (i2 == i) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
290 res += c;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
291 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
292 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
293
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
294 return res;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
295 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
296
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
297 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
298 * Convert the given Date object into a unix timestamp respecting browser's and user's timezone settings
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
299 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
300 this.date2unixtime = function(date)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
301 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
302 var dst_offset = (client_timezone - date.getTimezoneOffset()) * 60; // adjust DST offset
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
303 return Math.round(date.getTime()/1000 + gmt_offset * 3600 + dst_offset);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
304 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
305
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
306 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
307 * Turn a unix timestamp value into a Date object
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
308 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
309 this.fromunixtime = function(ts)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
310 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
311 ts -= gmt_offset * 3600;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
312 var date = new Date(ts * 1000),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
313 dst_offset = (client_timezone - date.getTimezoneOffset()) * 60;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
314 if (dst_offset) // adjust DST offset
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
315 date.setTime((ts + 3600) * 1000);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
316 return date;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
317 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
318
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
319 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
320 * Simple plaintext to HTML converter, makig URLs clickable
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
321 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
322 this.text2html = function(str, maxlen, maxlines)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
323 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
324 var html = Q(String(str));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
325
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
326 // limit visible text length
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
327 if (maxlen) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
328 var morelink = '<span>... <a href="#more" onclick="$(this).parent().hide().next().show();return false" class="morelink">'+rcmail.gettext('showmore','libcalendaring')+'</a></span><span style="display:none">',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
329 lines = html.split(/\r?\n/),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
330 words, out = '', len = 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
331
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
332 for (var i=0; i < lines.length; i++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
333 len += lines[i].length;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
334 if (maxlines && i == maxlines - 1) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
335 out += lines[i] + '\n' + morelink;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
336 maxlen = html.length * 2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
337 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
338 else if (len > maxlen) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
339 len = out.length;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
340 words = lines[i].split(' ');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
341 for (var j=0; j < words.length; j++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
342 len += words[j].length + 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
343 out += words[j] + ' ';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
344 if (len > maxlen) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
345 out += morelink;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
346 maxlen = html.length * 2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
347 maxlines = 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
348 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
349 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
350 out += '\n';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
351 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
352 else
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
353 out += lines[i] + '\n';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
354 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
355
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
356 if (maxlen > str.length)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
357 out += '</span>';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
358
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
359 html = out;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
360 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
361
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
362 // simple link parser (similar to rcube_string_replacer class in PHP)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
363 var utf_domain = '[^?&@"\'/\\(\\)\\s\\r\\t\\n]+\\.([^\x00-\x2f\x3b-\x40\x5b-\x60\x7b-\x7f]{2,}|xn--[a-z0-9]{2,})';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
364 var url1 = '.:;,', url2 = 'a-z0-9%=#@+?&/_~\\[\\]-';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
365 var link_pattern = new RegExp('([hf]t+ps?://)('+utf_domain+'(['+url1+']?['+url2+']+)*)', 'ig');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
366 var mailto_pattern = new RegExp('([^\\s\\n\\(\\);]+@'+utf_domain+')', 'ig');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
367 var link_replace = function(matches, p1, p2) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
368 var title = '', text = p2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
369 if (p2 && p2.length > 55) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
370 text = p2.substr(0, 45) + '...' + p2.substr(-8);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
371 title = p1 + p2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
372 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
373 return '<a href="'+p1+p2+'" class="extlink" target="_blank" title="'+title+'">'+p1+text+'</a>'
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
374 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
375
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
376 return html
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
377 .replace(link_pattern, link_replace)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
378 .replace(mailto_pattern, '<a href="mailto:$1">$1</a>')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
379 .replace(/(mailto:)([^"]+)"/g, '$1$2" onclick="rcmail.command(\'compose\', \'$2\');return false"')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
380 .replace(/\n/g, "<br/>");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
381 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
382
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
383 this.init_alarms_edit = function(prefix, index)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
384 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
385 var edit_type = $(prefix+' select.edit-alarm-type'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
386 dom_id = edit_type.attr('id');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
387
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
388 // register events on alarm fields
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
389 edit_type.change(function(){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
390 $(this).parent().find('span.edit-alarm-values')[(this.selectedIndex>0?'show':'hide')]();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
391 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
392 $(prefix+' select.edit-alarm-offset').change(function(){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
393 var val = $(this).val(), parent = $(this).parent();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
394 parent.find('.edit-alarm-date, .edit-alarm-time')[val == '@' ? 'show' : 'hide']();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
395 parent.find('.edit-alarm-value').prop('disabled', val === '@' || val === '0');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
396 parent.find('.edit-alarm-related')[val == '@' ? 'hide' : 'show']();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
397 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
398
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
399 $(prefix+' .edit-alarm-date').removeClass('hasDatepicker').removeAttr('id').datepicker(datepicker_settings);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
400
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
401 $(prefix).on('click', 'a.delete-alarm', function(e){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
402 if ($(this).closest('.edit-alarm-item').siblings().length > 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
403 $(this).closest('.edit-alarm-item').remove();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
404 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
405 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
406 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
407
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
408 // set a unique id attribute and set label reference accordingly
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
409 if ((index || 0) > 0 && dom_id) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
410 dom_id += ':' + (new Date().getTime());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
411 edit_type.attr('id', dom_id);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
412 $(prefix+' label:first').attr('for', dom_id);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
413 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
414
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
415 $(prefix).on('click', 'a.add-alarm', function(e){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
416 var i = $(this).closest('.edit-alarm-item').siblings().length + 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
417 var item = $(this).closest('.edit-alarm-item').clone(false)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
418 .removeClass('first')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
419 .appendTo(prefix);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
420
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
421 me.init_alarms_edit(prefix + ' .edit-alarm-item:eq(' + i + ')', i);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
422 $('select.edit-alarm-type, select.edit-alarm-offset', item).change();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
423 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
424 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
425 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
426
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
427 this.set_alarms_edit = function(prefix, valarms)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
428 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
429 $(prefix + ' .edit-alarm-item:gt(0)').remove();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
430
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
431 var i, alarm, domnode, val, offset;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
432 for (i=0; i < valarms.length; i++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
433 alarm = valarms[i];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
434 if (!alarm.action)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
435 alarm.action = 'DISPLAY';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
436
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
437 if (i == 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
438 domnode = $(prefix + ' .edit-alarm-item').eq(0);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
439 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
440 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
441 domnode = $(prefix + ' .edit-alarm-item').eq(0).clone(false).removeClass('first').appendTo(prefix);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
442 this.init_alarms_edit(prefix + ' .edit-alarm-item:eq(' + i + ')', i);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
443 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
444
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
445 $('select.edit-alarm-type', domnode).val(alarm.action);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
446 $('select.edit-alarm-related', domnode).val(/END/i.test(alarm.related) ? 'end' : 'start');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
447
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
448 if (String(alarm.trigger).match(/@(\d+)/)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
449 var ondate = this.fromunixtime(parseInt(RegExp.$1));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
450 $('select.edit-alarm-offset', domnode).val('@');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
451 $('input.edit-alarm-value', domnode).val('');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
452 $('input.edit-alarm-date', domnode).val(this.format_datetime(ondate, 1));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
453 $('input.edit-alarm-time', domnode).val(this.format_datetime(ondate, 2));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
454 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
455 else if (String(alarm.trigger).match(/^[-+]*0[MHDS]$/)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
456 $('input.edit-alarm-value', domnode).val('0');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
457 $('select.edit-alarm-offset', domnode).val('0');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
458 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
459 else if (String(alarm.trigger).match(/([-+])(\d+)([MHDS])/)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
460 val = RegExp.$2; offset = ''+RegExp.$1+RegExp.$3;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
461 $('input.edit-alarm-value', domnode).val(val);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
462 $('select.edit-alarm-offset', domnode).val(offset);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
463 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
464 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
465
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
466 // set correct visibility by triggering onchange handlers
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
467 $(prefix + ' select.edit-alarm-type, ' + prefix + ' select.edit-alarm-offset').change();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
468 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
469
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
470 this.serialize_alarms = function(prefix)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
471 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
472 var valarms = [];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
473
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
474 $(prefix + ' .edit-alarm-item').each(function(i, elem) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
475 var val, offset, alarm = {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
476 action: $('select.edit-alarm-type', elem).val(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
477 related: $('select.edit-alarm-related', elem).val()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
478 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
479
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
480 if (alarm.action) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
481 offset = $('select.edit-alarm-offset', elem).val();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
482 if (offset == '@') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
483 alarm.trigger = '@' + me.date2unixtime(me.parse_datetime($('input.edit-alarm-time', elem).val(), $('input.edit-alarm-date', elem).val()));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
484 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
485 else if (offset === '0') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
486 alarm.trigger = '0S';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
487 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
488 else if (!isNaN((val = parseInt($('input.edit-alarm-value', elem).val()))) && val >= 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
489 alarm.trigger = offset[0] + val + offset[1];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
490 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
491
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
492 valarms.push(alarm);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
493 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
494 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
495
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
496 return valarms;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
497 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
498
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
499 // format time string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
500 var time_autocomplete_format = function(hour, minutes, start) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
501 var time, diff, unit, duration = '', d = new Date();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
502
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
503 d.setHours(hour);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
504 d.setMinutes(minutes);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
505 time = me.format_time(d);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
506
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
507 if (start) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
508 diff = Math.floor((d.getTime() - start.getTime()) / 60000);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
509 if (diff > 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
510 unit = 'm';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
511 if (diff >= 60) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
512 unit = 'h';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
513 diff = Math.round(diff / 3) / 20;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
514 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
515 duration = ' (' + diff + unit + ')';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
516 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
517 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
518
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
519 return [time, duration];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
520 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
521
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
522 var time_autocomplete_list = function(p, callback) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
523 // Time completions
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
524 var st, h, step = 15, result = [], now = new Date(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
525 id = String(this.element.attr('id')),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
526 m = id.match(/^(.*)-(starttime|endtime)$/),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
527 start = (m && m[2] == 'endtime'
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
528 && (st = $('#' + m[1] + '-starttime').val())
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
529 && $('#' + m[1] + '-startdate').val() == $('#' + m[1] + '-enddate').val())
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
530 ? me.parse_datetime(st, '') : null,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
531 full = p.term - 1 > 0 || p.term.length > 1,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
532 hours = start ? start.getHours() : (full ? me.parse_datetime(p.term, '') : now).getHours(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
533 minutes = hours * 60 + (full ? 0 : now.getMinutes()),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
534 min = Math.ceil(minutes / step) * step % 60,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
535 hour = Math.floor(Math.ceil(minutes / step) * step / 60);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
536
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
537 // list hours from 0:00 till now
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
538 for (h = start ? start.getHours() : 0; h < hours; h++)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
539 result.push(time_autocomplete_format(h, 0, start));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
540
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
541 // list 15min steps for the next two hours
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
542 for (; h < hour + 2 && h < 24; h++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
543 while (min < 60) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
544 result.push(time_autocomplete_format(h, min, start));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
545 min += step;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
546 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
547 min = 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
548 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
549
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
550 // list the remaining hours till 23:00
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
551 while (h < 24)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
552 result.push(time_autocomplete_format((h++), 0, start));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
553
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
554 return callback(result);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
555 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
556
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
557 var time_autocomplete_open = function(event, ui) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
558 // scroll to current time
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
559 var $this = $(this),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
560 widget = $this.autocomplete('widget')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
561 menu = $this.data('ui-autocomplete').menu,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
562 amregex = /^(.+)(a[.m]*)/i,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
563 pmregex = /^(.+)(a[.m]*)/i,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
564 val = $(this).val().replace(amregex, '0:$1').replace(pmregex, '1:$1');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
565
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
566 widget.css('width', '10em');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
567
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
568 if (val === '')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
569 menu._scrollIntoView(widget.children('li:first'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
570 else
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
571 widget.children().each(function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
572 var li = $(this),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
573 html = li.children().first().html()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
574 .replace(/\s+\(.+\)$/, '')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
575 .replace(amregex, '0:$1')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
576 .replace(pmregex, '1:$1');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
577
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
578 if (html.indexOf(val) == 0)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
579 menu._scrollIntoView(li);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
580 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
581 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
582
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
583 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
584 * Initializes time autocompletion
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
585 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
586 this.init_time_autocomplete = function(elem, props)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
587 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
588 var default_props = {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
589 delay: 100,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
590 minLength: 1,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
591 appendTo: props.container,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
592 source: time_autocomplete_list,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
593 open: time_autocomplete_open,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
594 // change: time_autocomplete_change,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
595 select: function(event, ui) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
596 $(this).val(ui.item[0]).change();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
597 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
598 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
599 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
600
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
601 $(elem).attr('autocomplete', "off")
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
602 .autocomplete($.extend(default_props, props))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
603 .click(function() { // show drop-down upon clicks
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
604 $(this).autocomplete('search', $(this).val() ? $(this).val().replace(/\D.*/, "") : " ");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
605 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
606
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
607 $(elem).data('ui-autocomplete')._renderItem = function(ul, item) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
608 return $('<li>')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
609 .data('ui-autocomplete-item', item)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
610 .append('<a>' + item[0] + item[1] + '</a>')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
611 .appendTo(ul);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
612 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
613 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
614
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
615 /***** Alarms handling *****/
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
616
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
617 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
618 * Display a notification for the given pending alarms
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
619 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
620 this.display_alarms = function(alarms)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
621 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
622 // clear old alert first
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
623 if (this.alarm_dialog)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
624 this.alarm_dialog.dialog('destroy').remove();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
625
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
626 var i, actions, adismiss, asnooze, alarm, html,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
627 audio_alarms = [], records = [], event_ids = [], buttons = {};
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
628
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
629 for (i=0; i < alarms.length; i++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
630 alarm = alarms[i];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
631 alarm.start = this.parseISO8601(alarm.start);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
632 alarm.end = this.parseISO8601(alarm.end);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
633
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
634 if (alarm.action == 'AUDIO') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
635 audio_alarms.push(alarm);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
636 continue;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
637 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
638
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
639 event_ids.push(alarm.id);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
640
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
641 html = '<h3 class="event-title">' + Q(alarm.title) + '</h3>';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
642 html += '<div class="event-section">' + Q(alarm.location || '') + '</div>';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
643 html += '<div class="event-section">' + Q(this.event_date_text(alarm)) + '</div>';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
644
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
645 adismiss = $('<a href="#" class="alarm-action-dismiss"></a>').html(rcmail.gettext('dismiss','libcalendaring')).click(function(e){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
646 me.dismiss_link = $(this);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
647 me.dismiss_alarm(me.dismiss_link.data('id'), 0, e);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
648 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
649 asnooze = $('<a href="#" class="alarm-action-snooze"></a>').html(rcmail.gettext('snooze','libcalendaring')).click(function(e){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
650 me.snooze_dropdown($(this), e);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
651 e.stopPropagation();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
652 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
653 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
654 actions = $('<div>').addClass('alarm-actions').append(adismiss.data('id', alarm.id)).append(asnooze.data('id', alarm.id));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
655
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
656 records.push($('<div>').addClass('alarm-item').html(html).append(actions));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
657 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
658
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
659 if (audio_alarms.length)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
660 this.audio_alarms(audio_alarms);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
661
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
662 if (!records.length)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
663 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
664
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
665 this.alarm_dialog = $('<div>').attr('id', 'alarm-display').append(records);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
666
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
667 buttons[rcmail.gettext('close')] = function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
668 $(this).dialog('close');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
669 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
670
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
671 buttons[rcmail.gettext('dismissall','libcalendaring')] = function(e) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
672 // submit dismissed event_ids to server
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
673 me.dismiss_alarm(me.alarm_ids.join(','), 0, e);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
674 $(this).dialog('close');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
675 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
676
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
677 this.alarm_dialog.appendTo(document.body).dialog({
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
678 modal: false,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
679 resizable: true,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
680 closeOnEscape: false,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
681 dialogClass: 'alarms',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
682 title: rcmail.gettext('alarmtitle','libcalendaring'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
683 buttons: buttons,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
684 open: function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
685 setTimeout(function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
686 me.alarm_dialog.parent().find('.ui-button:not(.ui-dialog-titlebar-close)').first().focus();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
687 }, 5);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
688 },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
689 close: function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
690 $('#alarm-snooze-dropdown').hide();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
691 $(this).dialog('destroy').remove();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
692 me.alarm_dialog = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
693 me.alarm_ids = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
694 },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
695 drag: function(event, ui) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
696 $('#alarm-snooze-dropdown').hide();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
697 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
698 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
699
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
700 this.alarm_dialog.closest('div[role=dialog]').attr('role', 'alertdialog');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
701
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
702 this.alarm_ids = event_ids;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
703 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
704
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
705 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
706 * Display a notification and play a sound for a set of alarms
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
707 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
708 this.audio_alarms = function(alarms)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
709 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
710 var elem, txt = [],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
711 src = rcmail.assets_path('plugins/libcalendaring/alarm'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
712 plugin = navigator.mimeTypes ? navigator.mimeTypes['audio/mp3'] : {};
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
713
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
714 // first generate and display notification text
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
715 $.each(alarms, function() { txt.push(this.title); });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
716
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
717 rcmail.display_message(rcmail.gettext('alarmtitle','libcalendaring') + ': ' + Q(txt.join(', ')), 'notice', 10000);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
718
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
719 // Internet Explorer does not support wav files,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
720 // support in other browsers depends on enabled plugins,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
721 // so we use wav as a fallback
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
722 src += bw.ie || (plugin && plugin.enabledPlugin) ? '.mp3' : '.wav';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
723
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
724 // HTML5
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
725 try {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
726 elem = $('<audio>').attr('src', src);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
727 elem.get(0).play();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
728 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
729 // old method
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
730 catch (e) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
731 elem = $('<embed id="libcalsound" src="' + src + '" hidden=true autostart=true loop=false />');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
732 elem.appendTo($('body'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
733 window.setTimeout("$('#libcalsound').remove()", 10000);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
734 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
735 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
736
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
737 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
738 * Show a drop-down menu with a selection of snooze times
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
739 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
740 this.snooze_dropdown = function(link, event)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
741 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
742 if (!this.snooze_popup) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
743 this.snooze_popup = $('#alarm-snooze-dropdown');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
744 // create popup if not found
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
745 if (!this.snooze_popup.length) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
746 this.snooze_popup = $('<div>').attr('id', 'alarm-snooze-dropdown').addClass('popupmenu').appendTo(document.body);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
747 this.snooze_popup.html(rcmail.env.snooze_select)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
748 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
749 $('#alarm-snooze-dropdown a').click(function(e){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
750 var time = String(this.href).replace(/.+#/, '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
751 me.dismiss_alarm($('#alarm-snooze-dropdown').data('id'), time, e);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
752 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
753 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
754 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
755
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
756 // hide visible popup
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
757 if (this.snooze_popup.is(':visible') && this.snooze_popup.data('id') == link.data('id')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
758 rcmail.command('menu-close', 'alarm-snooze-dropdown', link.get(0), event);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
759 this.dismiss_link = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
760 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
761 else { // open popup below the clicked link
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
762 rcmail.command('menu-open', 'alarm-snooze-dropdown', link.get(0), event);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
763 this.snooze_popup.data('id', link.data('id'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
764 this.dismiss_link = link;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
765 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
766 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
767
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
768 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
769 * Dismiss or snooze alarms for the given event
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
770 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
771 this.dismiss_alarm = function(id, snooze, event)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
772 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
773 rcmail.command('menu-close', 'alarm-snooze-dropdown', null, event);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
774 rcmail.http_post('utils/plugin.alarms', { action:'dismiss', data:{ id:id, snooze:snooze } });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
775
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
776 // remove dismissed alarm from list
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
777 if (this.dismiss_link) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
778 this.dismiss_link.closest('div.alarm-item').hide();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
779 var new_ids = jQuery.grep(this.alarm_ids, function(v){ return v != id; });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
780 if (new_ids.length)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
781 this.alarm_ids = new_ids;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
782 else
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
783 this.alarm_dialog.dialog('close');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
784 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
785
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
786 this.dismiss_link = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
787 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
788
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
789
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
790 /***** Recurrence form handling *****/
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
791
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
792 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
793 * Install event handlers on recurrence form elements
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
794 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
795 this.init_recurrence_edit = function(prefix)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
796 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
797 // toggle recurrence frequency forms
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
798 $('#edit-recurrence-frequency').change(function(e){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
799 var freq = $(this).val().toLowerCase();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
800 $('.recurrence-form').hide();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
801 if (freq) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
802 $('#recurrence-form-'+freq).show();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
803 if (freq != 'rdate')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
804 $('#recurrence-form-until').show();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
805 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
806 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
807 $('#recurrence-form-rdate input.button.add').click(function(e){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
808 var dt, dv = $('#edit-recurrence-rdate-input').val();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
809 if (dv && (dt = me.parse_datetime('12:00', dv))) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
810 me.add_rdate(dt);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
811 me.sort_rdates();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
812 $('#edit-recurrence-rdate-input').val('')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
813 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
814 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
815 $('#edit-recurrence-rdate-input').select();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
816 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
817 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
818 $('#edit-recurrence-rdates').on('click', 'a.delete', function(e){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
819 $(this).closest('li').remove();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
820 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
821 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
822
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
823 $('#edit-recurrence-enddate').datepicker(datepicker_settings).click(function(){ $("#edit-recurrence-repeat-until").prop('checked', true) });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
824 $('#edit-recurrence-repeat-times').change(function(e){ $('#edit-recurrence-repeat-count').prop('checked', true); });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
825 $('#edit-recurrence-rdate-input').datepicker(datepicker_settings);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
826 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
827
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
828 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
829 * Set recurrence form according to the given event/task record
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
830 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
831 this.set_recurrence_edit = function(rec)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
832 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
833 var recurrence = $('#edit-recurrence-frequency').val(rec.recurrence ? rec.recurrence.FREQ || (rec.recurrence.RDATE ? 'RDATE' : '') : '').change(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
834 interval = $('.recurrence-form select.edit-recurrence-interval').val(rec.recurrence ? rec.recurrence.INTERVAL || 1 : 1),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
835 rrtimes = $('#edit-recurrence-repeat-times').val(rec.recurrence ? rec.recurrence.COUNT || 1 : 1),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
836 rrenddate = $('#edit-recurrence-enddate').val(rec.recurrence && rec.recurrence.UNTIL ? this.format_datetime(this.parseISO8601(rec.recurrence.UNTIL), 1) : '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
837 $('.recurrence-form input.edit-recurrence-until:checked').prop('checked', false);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
838 $('#edit-recurrence-rdates').html('');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
839
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
840 var weekdays = ['SU','MO','TU','WE','TH','FR','SA'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
841 rrepeat_id = '#edit-recurrence-repeat-forever';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
842 if (rec.recurrence && rec.recurrence.COUNT) rrepeat_id = '#edit-recurrence-repeat-count';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
843 else if (rec.recurrence && rec.recurrence.UNTIL) rrepeat_id = '#edit-recurrence-repeat-until';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
844 $(rrepeat_id).prop('checked', true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
845
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
846 if (rec.recurrence && rec.recurrence.BYDAY && rec.recurrence.FREQ == 'WEEKLY') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
847 var wdays = rec.recurrence.BYDAY.split(',');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
848 $('input.edit-recurrence-weekly-byday').val(wdays);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
849 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
850 if (rec.recurrence && rec.recurrence.BYMONTHDAY) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
851 $('input.edit-recurrence-monthly-bymonthday').val(String(rec.recurrence.BYMONTHDAY).split(','));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
852 $('input.edit-recurrence-monthly-mode').val(['BYMONTHDAY']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
853 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
854 if (rec.recurrence && rec.recurrence.BYDAY && (rec.recurrence.FREQ == 'MONTHLY' || rec.recurrence.FREQ == 'YEARLY')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
855 var byday, section = rec.recurrence.FREQ.toLowerCase();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
856 if ((byday = String(rec.recurrence.BYDAY).match(/(-?[1-4])([A-Z]+)/))) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
857 $('#edit-recurrence-'+section+'-prefix').val(byday[1]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
858 $('#edit-recurrence-'+section+'-byday').val(byday[2]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
859 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
860 $('input.edit-recurrence-'+section+'-mode').val(['BYDAY']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
861 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
862 else if (rec.start) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
863 $('#edit-recurrence-monthly-byday').val(weekdays[rec.start.getDay()]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
864 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
865 if (rec.recurrence && rec.recurrence.BYMONTH) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
866 $('input.edit-recurrence-yearly-bymonth').val(String(rec.recurrence.BYMONTH).split(','));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
867 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
868 else if (rec.start) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
869 $('input.edit-recurrence-yearly-bymonth').val([String(rec.start.getMonth()+1)]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
870 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
871 if (rec.recurrence && rec.recurrence.RDATE) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
872 $.each(rec.recurrence.RDATE, function(i,rdate){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
873 me.add_rdate(me.parseISO8601(rdate));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
874 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
875 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
876 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
877
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
878 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
879 * Gather recurrence settings from form
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
880 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
881 this.serialize_recurrence = function(timestr)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
882 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
883 var recurrence = '',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
884 freq = $('#edit-recurrence-frequency').val();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
885
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
886 if (freq != '') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
887 recurrence = {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
888 FREQ: freq,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
889 INTERVAL: $('#edit-recurrence-interval-'+freq.toLowerCase()).val()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
890 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
891
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
892 var until = $('input.edit-recurrence-until:checked').val();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
893 if (until == 'count')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
894 recurrence.COUNT = $('#edit-recurrence-repeat-times').val();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
895 else if (until == 'until')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
896 recurrence.UNTIL = me.date2ISO8601(me.parse_datetime(timestr || '00:00', $('#edit-recurrence-enddate').val()));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
897
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
898 if (freq == 'WEEKLY') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
899 var byday = [];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
900 $('input.edit-recurrence-weekly-byday:checked').each(function(){ byday.push(this.value); });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
901 if (byday.length)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
902 recurrence.BYDAY = byday.join(',');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
903 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
904 else if (freq == 'MONTHLY') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
905 var mode = $('input.edit-recurrence-monthly-mode:checked').val(), bymonday = [];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
906 if (mode == 'BYMONTHDAY') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
907 $('input.edit-recurrence-monthly-bymonthday:checked').each(function(){ bymonday.push(this.value); });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
908 if (bymonday.length)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
909 recurrence.BYMONTHDAY = bymonday.join(',');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
910 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
911 else
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
912 recurrence.BYDAY = $('#edit-recurrence-monthly-prefix').val() + $('#edit-recurrence-monthly-byday').val();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
913 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
914 else if (freq == 'YEARLY') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
915 var byday, bymonth = [];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
916 $('input.edit-recurrence-yearly-bymonth:checked').each(function(){ bymonth.push(this.value); });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
917 if (bymonth.length)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
918 recurrence.BYMONTH = bymonth.join(',');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
919 if ((byday = $('#edit-recurrence-yearly-byday').val()))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
920 recurrence.BYDAY = $('#edit-recurrence-yearly-prefix').val() + byday;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
921 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
922 else if (freq == 'RDATE') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
923 recurrence = { RDATE:[] };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
924 // take selected but not yet added date into account
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
925 if ($('#edit-recurrence-rdate-input').val() != '') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
926 $('#recurrence-form-rdate input.button.add').click();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
927 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
928 $('#edit-recurrence-rdates li').each(function(i, li){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
929 recurrence.RDATE.push($(li).attr('data-value'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
930 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
931 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
932 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
933
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
934 return recurrence;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
935 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
936
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
937 // add the given date to the RDATE list
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
938 this.add_rdate = function(date)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
939 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
940 var li = $('<li>')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
941 .attr('data-value', this.date2ISO8601(date))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
942 .html('<span>' + Q(this.format_datetime(date, 1)) + '</span>')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
943 .appendTo('#edit-recurrence-rdates');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
944
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
945 $('<a>').attr('href', '#del')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
946 .addClass('iconbutton delete')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
947 .html(rcmail.get_label('delete', 'libcalendaring'))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
948 .attr('title', rcmail.get_label('delete', 'libcalendaring'))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
949 .appendTo(li);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
950 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
951
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
952 // re-sort the list items by their 'data-value' attribute
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
953 this.sort_rdates = function()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
954 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
955 var mylist = $('#edit-recurrence-rdates'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
956 listitems = mylist.children('li').get();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
957 listitems.sort(function(a, b) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
958 var compA = $(a).attr('data-value');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
959 var compB = $(b).attr('data-value');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
960 return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
961 })
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
962 $.each(listitems, function(idx, item) { mylist.append(item); });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
963 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
964
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
965
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
966 /***** Attendee form handling *****/
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
967
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
968 // expand the given contact group into individual event/task attendees
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
969 this.expand_attendee_group = function(e, add, remove)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
970 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
971 var id = (e.data ? e.data.email : null) || $(e.target).attr('data-email'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
972 role_select = $(e.target).closest('tr').find('select.edit-attendee-role option:selected');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
973
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
974 this.group2expand[id] = { link: e.target, data: $.extend({}, e.data || {}), adder: add, remover: remove }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
975
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
976 // copy group role from the according form element
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
977 if (role_select.length) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
978 this.group2expand[id].data.role = role_select.val();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
979 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
980
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
981 // register callback handler
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
982 if (!this._expand_attendee_listener) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
983 this._expand_attendee_listener = this.expand_attendee_callback;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
984 rcmail.addEventListener('plugin.expand_attendee_callback', function(result) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
985 me._expand_attendee_listener(result);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
986 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
987 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
988
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
989 rcmail.http_post('libcal/plugin.expand_attendee_group', { id: id, data: e.data || {} }, rcmail.set_busy(true, 'loading'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
990 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
991
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
992 // callback from server to expand an attendee group
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
993 this.expand_attendee_callback = function(result)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
994 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
995 var attendee, id = result.id,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
996 data = this.group2expand[id],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
997 row = $(data.link).closest('tr');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
998
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
999 // replace group entry with all members returned by the server
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1000 if (data && data.adder && result.members && result.members.length) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1001 for (var i=0; i < result.members.length; i++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1002 attendee = result.members[i];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1003 attendee.role = data.data.role;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1004 attendee.cutype = 'INDIVIDUAL';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1005 attendee.status = 'NEEDS-ACTION';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1006 data.adder(attendee, null, row);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1007 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1008
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1009 if (data.remover) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1010 data.remover(data.link, id)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1011 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1012 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1013 row.remove();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1014 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1015
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1016 delete this.group2expand[id];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1017 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1018 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1019 rcmail.display_message(result.error || rcmail.gettext('expandattendeegroupnodata','libcalendaring'), 'error');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1020 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1021 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1022
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1023
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1024 // Render message reference links to the given container
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1025 this.render_message_links = function(links, container, edit, plugin)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1026 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1027 var ul = $('<ul>').addClass('attachmentslist');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1028
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1029 $.each(links, function(i, link) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1030 if (!link.mailurl)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1031 return true; // continue
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1032
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1033 var li = $('<li>').addClass('link')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1034 .addClass('message eml')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1035 .append($('<a>')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1036 .attr('href', link.mailurl)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1037 .addClass('messagelink')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1038 .text(link.subject || link.uri)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1039 )
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1040 .appendTo(ul);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1041
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1042 // add icon to remove the link
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1043 if (edit) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1044 $('<a>')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1045 .attr('href', '#delete')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1046 .attr('title', rcmail.gettext('removelink', plugin))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1047 .attr('data-uri', link.uri)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1048 .addClass('delete')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1049 .text(rcmail.gettext('delete'))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1050 .appendTo(li);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1051 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1052 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1053
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1054 container.empty().append(ul);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1055 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1056
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1057 // resize and reposition (center) the dialog window
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1058 this.dialog_resize = function(id, height, width)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1059 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1060 var win = $(window), w = win.width(), h = win.height();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1061
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1062 $(id).dialog('option', {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1063 height: Math.min(h-20, height+130),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1064 width: Math.min(w-20, width+50)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1065 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1066 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1067 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1068
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1069 ////// static methods
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1070
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1071 // render HTML code for displaying an attendee record
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1072 rcube_libcalendaring.attendee_html = function(data)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1073 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1074 var name, tooltip = '', context = 'libcalendaring',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1075 dispname = data.name || data.email,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1076 status = data.role == 'ORGANIZER' ? 'ORGANIZER' : data.status;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1077
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1078 if (status)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1079 status = status.toLowerCase();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1080
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1081 if (data.email) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1082 tooltip = data.email;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1083 name = $('<a>').attr({href: 'mailto:' + data.email, 'class': 'mailtolink', 'data-cutype': data.cutype})
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1084
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1085 if (status)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1086 tooltip += ' (' + rcmail.gettext('status' + status, context) + ')';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1087 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1088 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1089 name = $('<span>');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1090 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1091
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1092 if (data['delegated-to'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1093 tooltip = rcmail.gettext('delegatedto', context) + ' ' + data['delegated-to'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1094 else if (data['delegated-from'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1095 tooltip = rcmail.gettext('delegatedfrom', context) + ' ' + data['delegated-from'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1096
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1097 return $('<span>').append(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1098 $('<span>').attr({'class': 'attendee ' + status, title: tooltip}).append(name.text(dispname))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1099 ).html();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1100 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1101
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1102 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1103 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1104 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1105 rcube_libcalendaring.add_from_itip_mail = function(mime_id, task, status, dom_id)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1106 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1107 // ask user to delete the declined event from the local calendar (#1670)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1108 var del = false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1109 if (rcmail.env.rsvp_saved && status == 'declined') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1110 del = confirm(rcmail.gettext('itip.declinedeleteconfirm'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1111 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1112
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1113 // open dialog for iTip delegation
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1114 if (status == 'delegated') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1115 rcube_libcalendaring.itip_delegate_dialog(function(data) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1116 rcmail.http_post(task + '/itip-delegate', {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1117 _uid: rcmail.env.uid,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1118 _mbox: rcmail.env.mailbox,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1119 _part: mime_id,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1120 _to: data.to,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1121 _rsvp: data.rsvp ? 1 : 0,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1122 _comment: data.comment,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1123 _folder: data.target
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1124 }, rcmail.set_busy(true, 'itip.savingdata'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1125 }, $('#rsvp-'+dom_id+' .folder-select'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1126 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1127 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1128
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1129 var noreply = 0, comment = '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1130 if (dom_id) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1131 noreply = $('#noreply-'+dom_id+':checked').length ? 1 : 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1132 if (!noreply)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1133 comment = $('#reply-comment-'+dom_id).val();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1134 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1135
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1136 rcmail.http_post(task + '/mailimportitip', {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1137 _uid: rcmail.env.uid,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1138 _mbox: rcmail.env.mailbox,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1139 _part: mime_id,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1140 _folder: $('#itip-saveto').val(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1141 _status: status,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1142 _del: del?1:0,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1143 _noreply: noreply,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1144 _comment: comment
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1145 }, rcmail.set_busy(true, 'itip.savingdata'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1146
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1147 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1148 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1149
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1150 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1151 * Helper function to render the iTip delegation dialog
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1152 * and trigger a callback function when submitted.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1153 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1154 rcube_libcalendaring.itip_delegate_dialog = function(callback, selector)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1155 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1156 // show dialog for entering the delegatee address and comment
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1157 var html = '<form class="itip-dialog-form" action="javascript:void()">' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1158 '<div class="form-section">' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1159 '<label for="itip-delegate-to">' + rcmail.gettext('itip.delegateto') + '</label><br/>' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1160 '<input type="text" id="itip-delegate-to" class="text" size="40" value="" />' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1161 '</div>' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1162 '<div class="form-section">' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1163 '<label for="itip-delegate-rsvp">' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1164 '<input type="checkbox" id="itip-delegate-rsvp" class="checkbox" size="40" value="" />' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1165 rcmail.gettext('itip.delegatersvpme') +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1166 '</label>' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1167 '</div>' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1168 '<div class="form-section">' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1169 '<textarea id="itip-delegate-comment" class="itip-comment" cols="40" rows="8" placeholder="' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1170 rcmail.gettext('itip.itipcomment') + '"></textarea>' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1171 '</div>' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1172 '<div class="form-section">' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1173 (selector && selector.length ? selector.html() : '') +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1174 '</div>' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1175 '</form>';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1176
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1177 var dialog, buttons = [];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1178 buttons.push({
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1179 text: rcmail.gettext('itipdelegated', 'itip'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1180 click: function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1181 var doc = window.parent.document,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1182 delegatee = String($('#itip-delegate-to', doc).val()).replace(/(^\s+)|(\s+$)/, '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1183
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1184 if (delegatee != '' && rcube_check_email(delegatee, true)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1185 callback({
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1186 to: delegatee,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1187 rsvp: $('#itip-delegate-rsvp', doc).prop('checked'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1188 comment: $('#itip-delegate-comment', doc).val(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1189 target: $('#itip-saveto', doc).val()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1190 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1191
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1192 setTimeout(function() { dialog.dialog("close"); }, 500);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1193 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1194 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1195 alert(rcmail.gettext('itip.delegateinvalidaddress'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1196 $('#itip-delegate-to', doc).focus();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1197 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1198 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1199 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1200
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1201 buttons.push({
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1202 text: rcmail.gettext('cancel', 'itip'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1203 click: function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1204 dialog.dialog('close');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1205 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1206 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1207
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1208 dialog = rcmail.show_popup_dialog(html, rcmail.gettext('delegateinvitation', 'itip'), buttons, {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1209 width: 460,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1210 open: function(event, ui) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1211 $(this).parent().find('.ui-button:not(.ui-dialog-titlebar-close)').first().addClass('mainaction');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1212 $(this).find('#itip-saveto').val('');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1213
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1214 // initialize autocompletion
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1215 var ac_props, rcm = rcmail.is_framed() ? parent.rcmail : rcmail;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1216 if (rcmail.env.autocomplete_threads > 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1217 ac_props = {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1218 threads: rcmail.env.autocomplete_threads,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1219 sources: rcmail.env.autocomplete_sources
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1220 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1221 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1222 rcm.init_address_input_events($(this).find('#itip-delegate-to').focus(), ac_props);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1223 rcm.env.recipients_delimiter = '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1224 },
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1225 close: function(event, ui) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1226 rcm = rcmail.is_framed() ? parent.rcmail : rcmail;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1227 rcm.ksearch_blur();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1228 $(this).remove();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1229 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1230 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1231
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1232 return dialog;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1233 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1234
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1235 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1236 * Show a menu for selecting the RSVP reply mode
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1237 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1238 rcube_libcalendaring.itip_rsvp_recurring = function(btn, callback)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1239 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1240 var mnu = $('<ul></ul>').addClass('popupmenu libcal-rsvp-replymode');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1241
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1242 $.each(['all','current'/*,'future'*/], function(i, mode) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1243 $('<li><a>' + rcmail.get_label('rsvpmode'+mode, 'libcalendaring') + '</a>')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1244 .addClass('ui-menu-item')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1245 .attr('rel', mode)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1246 .appendTo(mnu);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1247 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1248
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1249 var action = btn.attr('rel');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1250
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1251 // open the mennu
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1252 mnu.menu({
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1253 select: function(event, ui) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1254 callback(action, ui.item.attr('rel'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1255 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1256 })
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1257 .appendTo(document.body)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1258 .position({ my: 'left top', at: 'left bottom+2', of: btn })
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1259 .data('action', action);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1260
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1261 setTimeout(function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1262 $(document).one('click', function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1263 mnu.menu('destroy');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1264 mnu.remove();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1265 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1266 }, 100);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1267 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1268
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1269 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1270 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1271 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1272 rcube_libcalendaring.remove_from_itip = function(event, task, title)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1273 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1274 if (confirm(rcmail.gettext('itip.deleteobjectconfirm').replace('$title', title))) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1275 rcmail.http_post(task + '/itip-remove',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1276 event,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1277 rcmail.set_busy(true, 'itip.savingdata')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1278 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1279 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1280 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1281
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1282 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1283 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1284 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1285 rcube_libcalendaring.decline_attendee_reply = function(mime_id, task)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1286 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1287 // show dialog for entering a comment and send to server
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1288 var html = '<div class="itip-dialog-confirm-text">' + rcmail.gettext('itip.declineattendeeconfirm') + '</div>' +
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1289 '<textarea id="itip-decline-comment" class="itip-comment" cols="40" rows="8"></textarea>';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1290
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1291 var dialog, buttons = [];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1292 buttons.push({
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1293 text: rcmail.gettext('declineattendee', 'itip'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1294 click: function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1295 rcmail.http_post(task + '/itip-decline-reply', {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1296 _uid: rcmail.env.uid,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1297 _mbox: rcmail.env.mailbox,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1298 _part: mime_id,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1299 _comment: $('#itip-decline-comment', window.parent.document).val()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1300 }, rcmail.set_busy(true, 'itip.savingdata'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1301 dialog.dialog("close");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1302 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1303 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1304
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1305 buttons.push({
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1306 text: rcmail.gettext('cancel', 'itip'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1307 click: function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1308 dialog.dialog('close');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1309 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1310 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1311
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1312 dialog = rcmail.show_popup_dialog(html, rcmail.gettext('declineattendee', 'itip'), buttons, {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1313 width: 460,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1314 open: function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1315 $(this).parent().find('.ui-button:not(.ui-dialog-titlebar-close)').first().addClass('mainaction');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1316 $('#itip-decline-comment').focus();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1317 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1318 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1319
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1320 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1321 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1322
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1323 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1324 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1325 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1326 rcube_libcalendaring.fetch_itip_object_status = function(p)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1327 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1328 rcmail.http_post(p.task + '/itip-status', { data: p });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1329 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1330
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1331 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1332 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1333 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1334 rcube_libcalendaring.update_itip_object_status = function(p)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1335 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1336 rcmail.env.rsvp_saved = p.saved;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1337 rcmail.env.itip_existing = p.existing;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1338
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1339 // hide all elements first
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1340 $('#itip-buttons-'+p.id+' > div').hide();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1341 $('#rsvp-'+p.id+' .folder-select').remove();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1342
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1343 if (p.html) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1344 // append/replace rsvp status display
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1345 $('#loading-'+p.id).next('.rsvp-status').remove();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1346 $('#loading-'+p.id).hide().after(p.html);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1347 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1348
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1349 // enable/disable rsvp buttons
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1350 if (p.action == 'rsvp') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1351 $('#rsvp-'+p.id+' input.button').prop('disabled', false)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1352 .filter('.'+String(p.status||'unknown').toLowerCase()).prop('disabled', p.latest);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1353 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1354
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1355 // show rsvp/import buttons (with calendar selector)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1356 $('#'+p.action+'-'+p.id).show().find('input.button').last().after(p.select);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1357
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1358 // highlight date if date change detected
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1359 if (p.resheduled)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1360 $('.calendar-eventdetails td.date').addClass('modified');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1361
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1362 // show itip box appendix after replacing the given placeholders
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1363 if (p.append && p.append.selector) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1364 var elem = $(p.append.selector);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1365 if (p.append.replacements) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1366 $.each(p.append.replacements, function(k, html) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1367 elem.html(elem.html().replace(k, html));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1368 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1369 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1370 else if (p.append.html) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1371 elem.html(p.append.html)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1372 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1373 elem.show();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1374 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1375 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1376
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1377 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1378 * Callback from server after an iTip message has been processed
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1379 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1380 rcube_libcalendaring.itip_message_processed = function(metadata)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1381 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1382 if (metadata.after_action) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1383 setTimeout(function(){ rcube_libcalendaring.itip_after_action(metadata.after_action); }, 1200);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1384 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1385 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1386 rcube_libcalendaring.fetch_itip_object_status(metadata);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1387 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1388 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1389
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1390 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1391 * After-action on iTip request message. Action types:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1392 * 0 - no action
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1393 * 1 - move to Trash
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1394 * 2 - delete the message
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1395 * 3 - flag as deleted
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1396 * folder_name - move the message to the specified folder
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1397 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1398 rcube_libcalendaring.itip_after_action = function(action)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1399 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1400 if (!action) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1401 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1402 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1403
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1404 var rc = rcmail.is_framed() ? parent.rcmail : rcmail;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1405
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1406 if (action === 2) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1407 rc.permanently_remove_messages();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1408 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1409 else if (action === 3) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1410 rc.mark_message('delete');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1411 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1412 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1413 rc.move_messages(action === 1 ? rc.env.trash_mailbox : action);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1414 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1415 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1416
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1417 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1418 * Open the calendar preview for the current iTip event
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1419 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1420 rcube_libcalendaring.open_itip_preview = function(url, msgref)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1421 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1422 if (!rcmail.env.itip_existing)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1423 url += '&itip=' + escape(msgref);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1424
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1425 var win = rcmail.open_window(url);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1426 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1427
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1428
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1429 // extend jQuery
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1430 (function($){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1431 $.fn.serializeJSON = function(){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1432 var json = {};
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1433 jQuery.map($(this).serializeArray(), function(n, i) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1434 json[n['name']] = n['value'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1435 });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1436 return json;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1437 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1438 })(jQuery);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1439
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1440
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1441 /* libcalendaring plugin initialization */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1442 window.rcmail && rcmail.addEventListener('init', function(evt) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1443 if (rcmail.env.libcal_settings) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1444 var libcal = new rcube_libcalendaring(rcmail.env.libcal_settings);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1445 rcmail.addEventListener('plugin.display_alarms', function(alarms){ libcal.display_alarms(alarms); });
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1446 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1447
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1448 rcmail.addEventListener('plugin.update_itip_object_status', rcube_libcalendaring.update_itip_object_status)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1449 .addEventListener('plugin.fetch_itip_object_status', rcube_libcalendaring.fetch_itip_object_status)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1450 .addEventListener('plugin.itip_message_processed', rcube_libcalendaring.itip_message_processed);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1451
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1452 if (rcmail.env.action == 'get-attachment' && rcmail.gui_objects['attachmentframe']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1453 rcmail.register_command('print-attachment', function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1454 var frame = rcmail.get_frame_window(rcmail.gui_objects['attachmentframe'].id);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1455 if (frame) frame.print();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1456 }, true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1457 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1458
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1459 if (rcmail.env.action == 'get-attachment' && rcmail.env.attachment_download_url) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1460 rcmail.register_command('download-attachment', function() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1461 rcmail.location_href(rcmail.env.attachment_download_url, window);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1462 }, true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1463 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1464 });