Mercurial > hg > rc1
annotate plugins/calendar/calendar_ui.js @ 12:ff1f27bd05ad
partial success in getting back_link to message when making event from mail
author | Charlie Root |
---|---|
date | Sat, 13 Jan 2018 09:39:32 -0500 |
parents | f6fe4b6ae66a |
children | 3bd5fe8166b8 |
rev | line source |
---|---|
3 | 1 /** |
2 * Client UI Javascript for the Calendar plugin | |
3 * | |
4 * @author Lazlo Westerhof <hello@lazlo.me> | |
5 * @author Thomas Bruederli <bruederli@kolabsys.com> | |
6 * | |
7 * @licstart The following is the entire license notice for the | |
8 * JavaScript code in this file. | |
9 * | |
10 * Copyright (C) 2010, Lazlo Westerhof <hello@lazlo.me> | |
11 * Copyright (C) 2014-2015, Kolab Systems AG <contact@kolabsys.com> | |
12 * | |
13 * This program is free software: you can redistribute it and/or modify | |
14 * it under the terms of the GNU Affero General Public License as | |
15 * published by the Free Software Foundation, either version 3 of the | |
16 * License, or (at your option) any later version. | |
17 * | |
18 * This program is distributed in the hope that it will be useful, | |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 * GNU Affero General Public License for more details. | |
22 * | |
23 * You should have received a copy of the GNU Affero General Public License | |
24 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25 * | |
26 * @licend The above is the entire license notice | |
27 * for the JavaScript code in this file. | |
28 */ | |
29 | |
30 // Roundcube calendar UI client class | |
31 function rcube_calendar_ui(settings) | |
32 { | |
33 // extend base class | |
34 rcube_calendar.call(this, settings); | |
35 | |
36 /*** member vars ***/ | |
37 this.is_loading = false; | |
38 this.selected_event = null; | |
39 this.selected_calendar = null; | |
40 this.search_request = null; | |
41 this.saving_lock = null; | |
42 this.calendars = {}; | |
43 this.quickview_sources = []; | |
44 | |
45 | |
46 /*** private vars ***/ | |
47 var DAY_MS = 86400000; | |
48 var HOUR_MS = 3600000; | |
49 var me = this; | |
50 var day_clicked = day_clicked_ts = 0; | |
51 var ignore_click = false; | |
52 var event_defaults = { free_busy:'busy', alarms:'' }; | |
53 var event_attendees = []; | |
54 var calendars_list; | |
55 var calenders_search_list; | |
56 var calenders_search_container; | |
57 var search_calendars = {}; | |
58 var attendees_list; | |
59 var resources_list; | |
60 var resources_treelist; | |
61 var resources_data = {}; | |
62 var resources_index = []; | |
63 var resource_owners = {}; | |
64 var resources_events_source = { url:null, editable:false }; | |
65 var freebusy_ui = { workinhoursonly:false, needsupdate:false }; | |
66 var freebusy_data = {}; | |
67 var current_view = null; | |
68 var count_sources = []; | |
69 var exec_deferred = bw.ie6 ? 5 : 1; | |
70 var sensitivitylabels = { 'public':rcmail.gettext('public','calendar'), 'private':rcmail.gettext('private','calendar'), 'confidential':rcmail.gettext('confidential','calendar') }; | |
71 var ui_loading = rcmail.set_busy(true, 'loading'); | |
72 | |
73 // general datepicker settings | |
74 var datepicker_settings = { | |
75 // translate from fullcalendar format to datepicker format | |
76 dateFormat: settings['date_format'].replace(/M/g, 'm').replace(/mmmmm/, 'MM').replace(/mmm/, 'M').replace(/dddd/, 'DD').replace(/ddd/, 'D').replace(/yy/g, 'y'), | |
77 firstDay : settings['first_day'], | |
78 dayNamesMin: settings['days_short'], | |
79 monthNames: settings['months'], | |
80 monthNamesShort: settings['months'], | |
81 changeMonth: false, | |
82 showOtherMonths: true, | |
83 selectOtherMonths: true | |
84 }; | |
85 | |
86 // global fullcalendar settings | |
87 var fullcalendar_defaults = { | |
88 aspectRatio: 1, | |
89 ignoreTimezone: true, // will treat the given date strings as in local (browser's) timezone | |
90 monthNames : settings.months, | |
91 monthNamesShort : settings.months_short, | |
92 dayNames : settings.days, | |
93 dayNamesShort : settings.days_short, | |
94 firstDay : settings.first_day, | |
95 firstHour : settings.first_hour, | |
96 slotMinutes : 60/settings.timeslots, | |
97 timeFormat: { | |
98 '': settings.time_format, | |
99 agenda: settings.time_format + '{ - ' + settings.time_format + '}', | |
100 list: settings.time_format + '{ - ' + settings.time_format + '}', | |
101 table: settings.time_format + '{ - ' + settings.time_format + '}' | |
102 }, | |
103 axisFormat : settings.time_format, | |
104 columnFormat: { | |
105 month: 'ddd', // Mon | |
106 week: 'ddd ' + settings.date_short, // Mon 9/7 | |
107 day: 'dddd ' + settings.date_short, // Monday 9/7 | |
108 table: settings.date_agenda | |
109 }, | |
110 titleFormat: { | |
111 month: 'MMMM yyyy', | |
112 week: settings.dates_long, | |
113 day: 'dddd ' + settings['date_long'], | |
114 table: settings.dates_long | |
115 }, | |
116 listPage: 7, // advance one week in agenda view | |
117 listRange: settings.agenda_range, | |
118 listSections: settings.agenda_sections, | |
119 tableCols: ['handle', 'date', 'time', 'title', 'location'], | |
120 defaultView: rcmail.env.view || settings.default_view, | |
121 allDayText: rcmail.gettext('all-day', 'calendar'), | |
122 buttonText: { | |
123 prev: ' ◄ ', | |
124 next: ' ► ', | |
125 today: settings['today'], | |
126 day: rcmail.gettext('day', 'calendar'), | |
127 week: rcmail.gettext('week', 'calendar'), | |
128 month: rcmail.gettext('month', 'calendar'), | |
129 table: rcmail.gettext('agenda', 'calendar') | |
130 }, | |
131 listTexts: { | |
132 until: rcmail.gettext('until', 'calendar'), | |
133 past: rcmail.gettext('pastevents', 'calendar'), | |
134 today: rcmail.gettext('today', 'calendar'), | |
135 tomorrow: rcmail.gettext('tomorrow', 'calendar'), | |
136 thisWeek: rcmail.gettext('thisweek', 'calendar'), | |
137 nextWeek: rcmail.gettext('nextweek', 'calendar'), | |
138 thisMonth: rcmail.gettext('thismonth', 'calendar'), | |
139 nextMonth: rcmail.gettext('nextmonth', 'calendar'), | |
140 future: rcmail.gettext('futureevents', 'calendar'), | |
141 week: rcmail.gettext('weekofyear', 'calendar') | |
142 }, | |
143 currentTimeIndicator: settings.time_indicator, | |
144 // event rendering | |
145 eventRender: function(event, element, view) { | |
146 if (view.name != 'list' && view.name != 'table') { | |
147 var prefix = event.sensitivity && event.sensitivity != 'public' ? String(sensitivitylabels[event.sensitivity]).toUpperCase()+': ' : ''; | |
148 element.attr('title', prefix + event.title); | |
149 } | |
150 if (view.name != 'month') { | |
151 if (event.location) { | |
152 element.find('div.fc-event-title').after('<div class="fc-event-location">@ ' + Q(event.location) + '</div>'); | |
153 } | |
154 if (event.sensitivity && event.sensitivity != 'public') | |
155 element.find('div.fc-event-time').append('<i class="fc-icon-sensitive"></i>'); | |
156 if (event.recurrence) | |
157 element.find('div.fc-event-time').append('<i class="fc-icon-recurring"></i>'); | |
158 if (event.alarms || (event.valarms && event.valarms.length)) | |
159 element.find('div.fc-event-time').append('<i class="fc-icon-alarms"></i>'); | |
160 } | |
161 if (event.status) { | |
162 element.addClass('cal-event-status-' + String(event.status).toLowerCase()); | |
163 } | |
164 | |
165 element.attr('aria-label', event.title + ', ' + me.event_date_text(event, true)); | |
166 }, | |
167 // render element indicating more (invisible) events | |
168 overflowRender: function(data, element) { | |
169 element.html(rcmail.gettext('andnmore', 'calendar').replace('$nr', data.count)) | |
170 .click(function(e){ me.fisheye_view(data.date); }); | |
171 }, | |
172 // callback when a specific event is clicked | |
173 eventClick: function(event, ev, view) { | |
174 if (!event.temp && String(event.className).indexOf('fc-type-freebusy') < 0) | |
175 event_show_dialog(event, ev); | |
176 } | |
177 }; | |
178 | |
179 /*** imports ***/ | |
180 var Q = this.quote_html; | |
181 var text2html = this.text2html; | |
182 var event_date_text = this.event_date_text; | |
183 var parse_datetime = this.parse_datetime; | |
184 var date2unixtime = this.date2unixtime; | |
185 var fromunixtime = this.fromunixtime; | |
186 var parseISO8601 = this.parseISO8601; | |
187 var date2servertime = this.date2ISO8601; | |
188 var render_message_links = this.render_message_links; | |
189 | |
190 | |
191 /*** private methods ***/ | |
192 | |
193 // same as str.split(delimiter) but it ignores delimiters within quoted strings | |
194 var explode_quoted_string = function(str, delimiter) | |
195 { | |
196 var result = [], | |
197 strlen = str.length, | |
198 q, p, i, chr, last; | |
199 | |
200 for (q = p = i = 0; i < strlen; i++) { | |
201 chr = str.charAt(i); | |
202 if (chr == '"' && last != '\\') { | |
203 q = !q; | |
204 } | |
205 else if (!q && chr == delimiter) { | |
206 result.push(str.substring(p, i)); | |
207 p = i + 1; | |
208 } | |
209 last = chr; | |
210 } | |
211 | |
212 result.push(str.substr(p)); | |
213 return result; | |
214 }; | |
215 | |
216 // Change the first charcter to uppercase | |
217 var ucfirst = function(str) | |
218 { | |
219 return str.charAt(0).toUpperCase() + str.substr(1); | |
220 }; | |
221 | |
222 // clone the given date object and optionally adjust time | |
223 var clone_date = function(date, adjust) | |
224 { | |
225 var d = new Date(date.getTime()); | |
226 | |
227 // set time to 00:00 | |
228 if (adjust == 1) { | |
229 d.setHours(0); | |
230 d.setMinutes(0); | |
231 } | |
232 // set time to 23:59 | |
233 else if (adjust == 2) { | |
234 d.setHours(23); | |
235 d.setMinutes(59); | |
236 } | |
237 | |
238 return d; | |
239 }; | |
240 | |
241 // fix date if jumped over a DST change | |
242 var fix_date = function(date) | |
243 { | |
244 if (date.getHours() == 23) | |
245 date.setTime(date.getTime() + HOUR_MS); | |
246 else if (date.getHours() > 0) | |
247 date.setHours(0); | |
248 }; | |
249 | |
250 var date2timestring = function(date, dateonly) | |
251 { | |
252 return date2servertime(date).replace(/[^0-9]/g, '').substr(0, (dateonly ? 8 : 14)); | |
253 } | |
254 | |
255 var format_datetime = function(date, mode, voice) | |
256 { | |
257 return me.format_datetime(date, mode, voice); | |
258 } | |
259 | |
260 var render_link = function(url) | |
261 { | |
262 var islink = false, href = url; | |
263 if (url.match(/^[fhtpsmailo]+?:\/\//i)) { | |
264 islink = true; | |
265 } | |
266 else if (url.match(/^[a-z0-9.-:]+(\/|$)/i)) { | |
267 islink = true; | |
268 href = 'http://' + url; | |
269 } | |
270 return islink ? '<a href="' + Q(href) + '" target="_blank">' + Q(url) + '</a>' : Q(url); | |
271 } | |
272 | |
273 // determine whether the given date is on a weekend | |
274 var is_weekend = function(date) | |
275 { | |
276 return date.getDay() == 0 || date.getDay() == 6; | |
277 }; | |
278 | |
279 var is_workinghour = function(date) | |
280 { | |
281 if (settings['work_start'] > settings['work_end']) | |
282 return date.getHours() >= settings['work_start'] || date.getHours() < settings['work_end']; | |
283 else | |
284 return date.getHours() >= settings['work_start'] && date.getHours() < settings['work_end']; | |
285 }; | |
286 | |
287 var load_attachment = function(event, att) | |
288 { | |
289 var query = { _id: att.id, _event: event.recurrence_id || event.id, _cal:event.calendar, _frame: 1 }; | |
290 if (event.rev) | |
291 query._rev = event.rev; | |
292 | |
293 if (event.calendar == "--invitation--itip") | |
294 $.extend(query, {_uid: event._uid, _part: event._part, _mbox: event._mbox}); | |
295 | |
296 // open attachment in frame if it's of a supported mimetype | |
297 if (id && att.mimetype && $.inArray(att.mimetype, settings.mimetypes)>=0) { | |
298 if (rcmail.open_window(rcmail.url('get-attachment', query), true, true)) { | |
299 return; | |
300 } | |
301 } | |
302 | |
303 query._frame = null; | |
304 query._download = 1; | |
305 rcmail.goto_url('get-attachment', query, false); | |
306 }; | |
307 | |
308 // build event attachments list | |
309 var event_show_attachments = function(list, container, event, edit) | |
310 { | |
311 var i, id, len, img, content, li, elem, | |
312 ul = document.createElement('UL'); | |
313 ul.className = 'attachmentslist'; | |
314 | |
315 for (i=0, len=list.length; i<len; i++) { | |
316 elem = list[i]; | |
317 li = document.createElement('LI'); | |
318 li.className = elem.classname; | |
319 | |
320 if (edit) { | |
321 rcmail.env.attachments[elem.id] = elem; | |
322 // delete icon | |
323 content = $('<a href="#delete" />') | |
324 .attr('title', rcmail.gettext('delete')) | |
325 .attr('aria-label', rcmail.gettext('delete') + ' ' + Q(elem.name)) | |
326 .addClass('delete') | |
327 .click({id: elem.id}, function(e) { remove_attachment(this, e.data.id); return false; }); | |
328 | |
329 if (!rcmail.env.deleteicon) | |
330 content.html(rcmail.gettext('delete')); | |
331 else { | |
332 img = document.createElement('IMG'); | |
333 img.src = rcmail.env.deleteicon; | |
334 img.alt = rcmail.gettext('delete'); | |
335 content.append(img); | |
336 } | |
337 | |
338 content.appendTo(li); | |
339 } | |
340 | |
341 // name/link | |
342 content = $('<a href="#load" />') | |
343 .html(Q(elem.name)) | |
344 .addClass('file') | |
345 .click({event: event, att: elem}, function(e) { | |
346 load_attachment(e.data.event, e.data.att); | |
347 return false; | |
348 }) | |
349 .appendTo(li); | |
350 | |
351 ul.appendChild(li); | |
352 } | |
353 | |
354 if (edit && rcmail.gui_objects.attachmentlist) { | |
355 ul.id = rcmail.gui_objects.attachmentlist.id; | |
356 rcmail.gui_objects.attachmentlist = ul; | |
357 } | |
358 | |
359 container.empty().append(ul); | |
360 }; | |
361 | |
362 var remove_attachment = function(elem, id) | |
363 { | |
364 $(elem.parentNode).hide(); | |
365 rcmail.env.deleted_attachments.push(id); | |
366 delete rcmail.env.attachments[id]; | |
367 }; | |
368 | |
369 // event details dialog (show only) | |
370 var event_show_dialog = function(event, ev, temp) | |
371 { | |
372 var $dialog = $("#eventshow"); | |
373 var calendar = event.calendar && me.calendars[event.calendar] ? me.calendars[event.calendar] : { editable:false, rights:'lrs' }; | |
374 | |
375 if (!temp) | |
376 me.selected_event = event; | |
377 | |
378 if ($dialog.is(':ui-dialog')) | |
379 $dialog.dialog('close'); | |
380 | |
381 // remove status-* and sensitivity-* classes | |
382 $dialog.removeClass(function(i, oldclass) { | |
383 var oldies = String(oldclass).split(' '); | |
384 return $.grep(oldies, function(cls) { return cls.indexOf('status-') === 0 || cls.indexOf('sensitivity-') === 0 }).join(' '); | |
385 }); | |
386 | |
387 // convert start/end dates if not done yet by fullcalendar | |
388 if (typeof event.start == 'string') | |
389 event.start = parseISO8601(event.start); | |
390 if (typeof event.end == 'string') | |
391 event.end = parseISO8601(event.end); | |
392 | |
393 // allow other plugins to do actions when event form is opened | |
394 rcmail.triggerEvent('calendar-event-init', {o: event}); | |
395 | |
396 $dialog.find('div.event-section, div.event-line').hide(); | |
397 $('#event-title').html(Q(event.title)).show(); | |
398 | |
399 if (event.location) | |
400 $('#event-location').html('@ ' + text2html(event.location)).show(); | |
401 if (event.description) | |
12
ff1f27bd05ad
partial success in getting back_link to message when making event from mail
Charlie Root
parents:
3
diff
changeset
|
402 $('#event-description').show().html(event.description); |
ff1f27bd05ad
partial success in getting back_link to message when making event from mail
Charlie Root
parents:
3
diff
changeset
|
403 //children('.event-text').html(text2html(event.description, 300, 6)); |
3 | 404 if (event.vurl) |
405 $('#event-url').show().children('.event-text').html(render_link(event.vurl)); | |
406 | |
407 // render from-to in a nice human-readable way | |
408 // -> now shown in dialog title | |
409 // $('#event-date').html(Q(me.event_date_text(event))).show(); | |
410 | |
411 if (event.recurrence && event.recurrence_text) | |
412 $('#event-repeat').show().children('.event-text').html(Q(event.recurrence_text)); | |
413 | |
414 if (event.valarms && event.alarms_text) | |
415 $('#event-alarm').show().children('.event-text').html(Q(event.alarms_text).replace(',', ',<br>')); | |
416 | |
417 if (calendar.name) | |
418 $('#event-calendar').show().children('.event-text').html(Q(calendar.name)).attr('class', 'event-text cal-'+calendar.id).css('color', calendar.textColor || calendar.color || ''); | |
419 if (event.categories) | |
420 $('#event-category').show().children('.event-text').html(Q(event.categories)).attr('class', 'event-text cat-'+String(event.categories).toLowerCase().replace(rcmail.identifier_expr, '')); | |
421 if (event.free_busy) | |
422 $('#event-free-busy').show().children('.event-text').html(Q(rcmail.gettext(event.free_busy, 'calendar'))); | |
423 if (event.priority > 0) { | |
424 var priolabels = [ '', rcmail.gettext('highest'), rcmail.gettext('high'), '', '', rcmail.gettext('normal'), '', '', rcmail.gettext('low'), rcmail.gettext('lowest') ]; | |
425 $('#event-priority').show().children('.event-text').html(Q(event.priority+' '+priolabels[event.priority])); | |
426 } | |
427 | |
428 if (event.status) { | |
429 var status_lc = String(event.status).toLowerCase(); | |
430 $('#event-status').show().children('.event-text').text(rcmail.gettext('status-'+status_lc,'calendar')); | |
431 $('#event-status-badge > span').text(rcmail.gettext('status-'+status_lc,'calendar')); | |
432 $dialog.addClass('status-'+status_lc); | |
433 } | |
434 if (event.sensitivity && event.sensitivity != 'public') { | |
435 $('#event-sensitivity').show().children('.event-text').text(sensitivitylabels[event.sensitivity]); | |
436 $('#event-status-badge > span').text(sensitivitylabels[event.sensitivity]); | |
437 $dialog.addClass('sensitivity-'+event.sensitivity); | |
438 } | |
439 if (event.created || event.changed) { | |
440 var created = parseISO8601(event.created), | |
441 changed = parseISO8601(event.changed) | |
442 $('#event-created-changed .event-created').html(Q(created ? format_datetime(created) : rcmail.gettext('unknown','calendar'))) | |
443 $('#event-created-changed .event-changed').html(Q(changed ? format_datetime(changed) : rcmail.gettext('unknown','calendar'))) | |
444 $('#event-created-changed').show() | |
445 } | |
446 | |
447 // create attachments list | |
448 if ($.isArray(event.attachments)) { | |
449 event_show_attachments(event.attachments, $('#event-attachments').children('.event-text'), event); | |
450 if (event.attachments.length > 0) { | |
451 $('#event-attachments').show(); | |
452 } | |
453 } | |
454 else if (calendar.attachments) { | |
455 // fetch attachments, some drivers doesn't set 'attachments' prop of the event? | |
456 } | |
457 | |
458 // build attachments list | |
459 $('#event-links').hide(); | |
460 if ($.isArray(event.links) && event.links.length) { | |
461 render_message_links(event.links || [], $('#event-links').children('.event-text'), false, 'calendar'); | |
462 $('#event-links').show(); | |
463 } | |
464 | |
465 // list event attendees | |
466 if (calendar.attendees && event.attendees) { | |
467 // sort resources to the end | |
468 event.attendees.sort(function(a,b) { | |
469 var j = a.cutype == 'RESOURCE' ? 1 : 0, | |
470 k = b.cutype == 'RESOURCE' ? 1 : 0; | |
471 return (j - k); | |
472 }); | |
473 | |
474 var data, mystatus = null, rsvp, line, morelink, html = '', overflow = '', | |
475 organizer = me.is_organizer(event); | |
476 | |
477 for (var j=0; j < event.attendees.length; j++) { | |
478 data = event.attendees[j]; | |
479 if (data.email) { | |
480 if (data.role != 'ORGANIZER' && settings.identity.emails.indexOf(';'+data.email) >= 0) { | |
481 mystatus = data.status.toLowerCase(); | |
482 if (data.status == 'NEEDS-ACTION' || data.status == 'TENTATIVE' || data.rsvp) | |
483 rsvp = mystatus; | |
484 } | |
485 } | |
486 | |
487 line = rcube_libcalendaring.attendee_html(data); | |
488 | |
489 if (morelink) | |
490 overflow += ' ' + line; | |
491 else | |
492 html += ' ' + line; | |
493 | |
494 // stop listing attendees | |
495 if (j == 7 && event.attendees.length >= 7) { | |
496 morelink = $('<a href="#more" class="morelink"></a>').html(rcmail.gettext('andnmore', 'calendar').replace('$nr', event.attendees.length - j - 1)); | |
497 } | |
498 } | |
499 | |
500 if (html && (event.attendees.length > 1 || !organizer)) { | |
501 $('#event-attendees').show() | |
502 .children('.event-text') | |
503 .html(html) | |
504 .find('a.mailtolink').click(event_attendee_click); | |
505 | |
506 // display all attendees in a popup when clicking the "more" link | |
507 if (morelink) { | |
508 $('#event-attendees .event-text').append(morelink); | |
509 morelink.click(function(e){ | |
510 rcmail.show_popup_dialog( | |
511 '<div id="all-event-attendees" class="event-attendees">' + html + overflow + '</div>', | |
512 rcmail.gettext('tabattendees','calendar'), | |
513 null, | |
514 { width:450, modal:false }); | |
515 $('#all-event-attendees a.mailtolink').click(event_attendee_click); | |
516 return false; | |
517 }) | |
518 } | |
519 } | |
520 | |
521 if (mystatus && !rsvp) { | |
522 $('#event-partstat').show().children('.changersvp') | |
523 .removeClass('accepted tentative declined delegated needs-action') | |
524 .addClass(mystatus) | |
525 .children('.event-text') | |
526 .text(rcmail.gettext('status' + mystatus, 'libcalendaring')); | |
527 } | |
528 | |
529 var show_rsvp = rsvp && !organizer && event.status != 'CANCELLED' && me.has_permission(calendar, 'v'); | |
530 $('#event-rsvp')[(show_rsvp ? 'show' : 'hide')](); | |
531 $('#event-rsvp .rsvp-buttons input').prop('disabled', false).filter('input[rel='+mystatus+']').prop('disabled', true); | |
532 | |
533 if (show_rsvp && event.comment) | |
534 $('#event-rsvp-comment').show().children('.event-text').html(Q(event.comment)); | |
535 | |
536 $('#event-rsvp a.reply-comment-toggle').show(); | |
537 $('#event-rsvp .itip-reply-comment textarea').hide().val(''); | |
538 | |
539 if (event.recurrence && event.id) { | |
540 var sel = event._savemode || (event.thisandfuture ? 'future' : (event.isexception ? 'current' : 'all')); | |
541 $('#event-rsvp .rsvp-buttons').addClass('recurring'); | |
542 } | |
543 else { | |
544 $('#event-rsvp .rsvp-buttons').removeClass('recurring'); | |
545 } | |
546 } | |
547 | |
548 var buttons = []; | |
549 if (!temp && calendar.editable && event.editable !== false) { | |
550 buttons.push({ | |
551 text: rcmail.gettext('edit', 'calendar'), | |
552 click: function() { | |
553 event_edit_dialog('edit', event); | |
554 } | |
555 }); | |
556 } | |
557 if (!temp && me.has_permission(calendar, 'td') && event.editable !== false) { | |
558 buttons.push({ | |
559 text: rcmail.gettext('delete', 'calendar'), | |
560 'class': 'delete', | |
561 click: function() { | |
562 me.delete_event(event); | |
563 $dialog.dialog('close'); | |
564 } | |
565 }); | |
566 } | |
567 | |
568 if (!buttons.length) { | |
569 buttons.push({ | |
570 text: rcmail.gettext('close', 'calendar'), | |
571 click: function(){ | |
572 $dialog.dialog('close'); | |
573 } | |
574 }); | |
575 } | |
576 | |
577 // open jquery UI dialog | |
578 $dialog.dialog({ | |
579 modal: false, | |
580 resizable: !bw.ie6, | |
581 closeOnEscape: (!bw.ie6 && !bw.ie7), // disable for performance reasons | |
582 title: me.event_date_text(event), | |
583 open: function() { | |
584 $dialog.attr('aria-hidden', 'false'); | |
585 setTimeout(function(){ | |
586 $dialog.parent().find('.ui-button:not(.ui-dialog-titlebar-close)').first().focus(); | |
587 }, 5); | |
588 }, | |
589 close: function() { | |
590 $dialog.dialog('destroy').attr('aria-hidden', 'true').hide(); | |
591 rcmail.command('menu-close','eventoptionsmenu'); | |
592 $('.libcal-rsvp-replymode').hide(); | |
593 }, | |
594 dragStart: function() { | |
595 rcmail.command('menu-close','eventoptionsmenu'); | |
596 $('.libcal-rsvp-replymode').hide(); | |
597 }, | |
598 resizeStart: function() { | |
599 rcmail.command('menu-close','eventoptionsmenu'); | |
600 $('.libcal-rsvp-replymode').hide(); | |
601 }, | |
602 buttons: buttons, | |
603 minWidth: 320, | |
604 width: 420 | |
605 }).show(); | |
606 | |
607 // remember opener element (to be focused on close) | |
608 $dialog.data('opener', ev && rcube_event.is_keyboard(ev) ? ev.target : null); | |
609 | |
610 // set voice title on dialog widget | |
611 $dialog.dialog('widget').removeAttr('aria-labelledby') | |
612 .attr('aria-label', me.event_date_text(event, true) + ', ', event.title); | |
613 | |
614 // set dialog size according to content | |
615 me.dialog_resize($dialog.get(0), $dialog.height(), 420); | |
616 | |
617 // add link for "more options" drop-down | |
618 if (!temp && !event.temporary && event.calendar != '_resource') { | |
619 $('<a>') | |
620 .attr('href', '#') | |
621 .html(rcmail.gettext('eventoptions','calendar')) | |
622 .addClass('dropdown-link') | |
623 .click(function(e) { | |
624 return rcmail.command('menu-open','eventoptionsmenu', this, e) | |
625 }) | |
626 .appendTo($dialog.parent().find('.ui-dialog-buttonset')); | |
627 } | |
628 | |
629 rcmail.enable_command('event-history', calendar.history) | |
630 | |
631 rcmail.triggerEvent('calendar-event-dialog', {dialog: $dialog}); | |
632 }; | |
633 | |
634 // event handler for clicks on an attendee link | |
635 var event_attendee_click = function(e) | |
636 { | |
637 var cutype = $(this).attr('data-cutype'), | |
638 mailto = this.href.substr(7); | |
639 if (rcmail.env.calendar_resources && cutype == 'RESOURCE') { | |
640 event_resources_dialog(mailto); | |
641 } | |
642 else { | |
643 rcmail.command('compose', mailto, e ? e.target : null, e); | |
644 } | |
645 return false; | |
646 }; | |
647 | |
648 // bring up the event dialog (jquery-ui popup) | |
649 var event_edit_dialog = function(action, event) | |
650 { | |
651 // copy opener element from show dialog | |
652 var op_elem = $("#eventshow:ui-dialog").data('opener'); | |
653 | |
654 // close show dialog first | |
655 $("#eventshow:ui-dialog").data('opener', null).dialog('close'); | |
656 | |
657 var $dialog = $('<div>'); | |
658 var calendar = event.calendar && me.calendars[event.calendar] ? me.calendars[event.calendar] : { editable:true, rights: action=='new' ? 'lrwitd' : 'lrs' }; | |
659 me.selected_event = $.extend($.extend({}, event_defaults), event); // clone event object (with defaults) | |
660 event = me.selected_event; // change reference to clone | |
661 freebusy_ui.needsupdate = false; | |
662 | |
663 // reset dialog first | |
664 $('#eventtabs').get(0).reset(); | |
665 $('#event-panel-recurrence input, #event-panel-recurrence select, #event-panel-attachments input').prop('disabled', false); | |
666 $('#event-panel-recurrence, #event-panel-attachments').removeClass('disabled'); | |
667 | |
668 // allow other plugins to do actions when event form is opened | |
669 rcmail.triggerEvent('calendar-event-init', {o: event}); | |
670 | |
671 // event details | |
672 var title = $('#edit-title').val(event.title || ''); | |
673 var location = $('#edit-location').val(event.location || ''); | |
674 var vurl = $('#edit-url').val(event.vurl || ''); | |
675 var categories = $('#edit-categories').val(event.categories); | |
676 var calendars = $('#edit-calendar').val(event.calendar); | |
677 var eventstatus = $('#edit-event-status').val(event.status); | |
678 var freebusy = $('#edit-free-busy').val(event.free_busy); | |
679 var priority = $('#edit-priority').val(event.priority); | |
680 var sensitivity = $('#edit-sensitivity').val(event.sensitivity); | |
681 | |
682 var duration = Math.round((event.end.getTime() - event.start.getTime()) / 1000); | |
683 var startdate = $('#edit-startdate').val($.fullCalendar.formatDate(event.start, settings['date_format'])).data('duration', duration); | |
684 var starttime = $('#edit-starttime').val($.fullCalendar.formatDate(event.start, settings['time_format'])).show(); | |
685 var enddate = $('#edit-enddate').val($.fullCalendar.formatDate(event.end, settings['date_format'])); | |
686 var endtime = $('#edit-endtime').val($.fullCalendar.formatDate(event.end, settings['time_format'])).show(); | |
687 var allday = $('#edit-allday').get(0); | |
688 var notify = $('#edit-attendees-donotify').get(0); | |
689 var invite = $('#edit-attendees-invite').get(0); | |
690 var comment = $('#edit-attendees-comment'); | |
691 | |
692 // make sure any calendar is selected | |
693 if (!calendars.val()) | |
694 calendars.val($('option:first', calendars).attr('value')); | |
695 | |
696 invite.checked = settings.itip_notify & 1 > 0; | |
697 notify.checked = me.has_attendees(event) && invite.checked; | |
698 | |
699 if (event.allDay) { | |
700 starttime.val("12:00").hide(); | |
701 endtime.val("13:00").hide(); | |
702 allday.checked = true; | |
703 } | |
704 else { | |
705 allday.checked = false; | |
706 } | |
707 | |
708 // set calendar selection according to permissions | |
709 calendars.find('option').each(function(i, opt) { | |
710 var cal = me.calendars[opt.value] || {}; | |
711 $(opt).prop('disabled', !(cal.editable || (action == 'new' && me.has_permission(cal, 'i')))) | |
712 }); | |
713 | |
714 // set alarm(s) | |
715 me.set_alarms_edit('#edit-alarms', action != 'new' && event.valarms && calendar.alarms ? event.valarms : []); | |
716 | |
717 // enable/disable alarm property according to backend support | |
718 $('#edit-alarms')[(calendar.alarms ? 'show' : 'hide')](); | |
719 | |
720 // check categories drop-down: add value if not exists | |
721 if (event.categories && !categories.find("option[value='"+event.categories+"']").length) { | |
722 $('<option>').attr('value', event.categories).text(event.categories).appendTo(categories).prop('selected', true); | |
723 } | |
724 | |
12
ff1f27bd05ad
partial success in getting back_link to message when making event from mail
Charlie Root
parents:
3
diff
changeset
|
725 var description; |
3 | 726 if ($.isArray(event.links) && event.links.length) { |
12
ff1f27bd05ad
partial success in getting back_link to message when making event from mail
Charlie Root
parents:
3
diff
changeset
|
727 render_message_links(event.links, $('#edit-event-links .event-text'), true, 'calendar'); |
ff1f27bd05ad
partial success in getting back_link to message when making event from mail
Charlie Root
parents:
3
diff
changeset
|
728 // hack! database_driver doesn't save the links property :-( |
ff1f27bd05ad
partial success in getting back_link to message when making event from mail
Charlie Root
parents:
3
diff
changeset
|
729 description = $('#edit-description').html("<div><a href='"+event.links[0].mailurl+"'>"+event.links[0].subject+"</a>\n<textarea class='text' rows='5' cols='40'>"+(event.description || '')+"</textarea></div>"); |
ff1f27bd05ad
partial success in getting back_link to message when making event from mail
Charlie Root
parents:
3
diff
changeset
|
730 $('#edit-event-links').show(); |
3 | 731 } |
732 else { | |
12
ff1f27bd05ad
partial success in getting back_link to message when making event from mail
Charlie Root
parents:
3
diff
changeset
|
733 description = $('#edit-description').html("<div><textarea class='text' rows='5' cols='40'>"+(event.description || '')+"</textarea></div>"); |
ff1f27bd05ad
partial success in getting back_link to message when making event from mail
Charlie Root
parents:
3
diff
changeset
|
734 $('#edit-event-links').hide(); |
3 | 735 } |
736 | |
737 // show warning if editing a recurring event | |
738 if (event.id && event.recurrence) { | |
739 var sel = event._savemode || (event.thisandfuture ? 'future' : (event.isexception ? 'current' : 'all')); | |
740 $('#edit-recurring-warning').show(); | |
741 $('input.edit-recurring-savemode[value="'+sel+'"]').prop('checked', true).change(); | |
742 } | |
743 else | |
744 $('#edit-recurring-warning').hide(); | |
745 | |
746 // init attendees tab | |
747 var organizer = !event.attendees || me.is_organizer(event), | |
748 allow_invitations = organizer || (calendar.owner && calendar.owner == 'anonymous') || settings.invite_shared; | |
749 event_attendees = []; | |
750 attendees_list = $('#edit-attendees-table > tbody').html(''); | |
751 resources_list = $('#edit-resources-table > tbody').html(''); | |
752 $('#edit-attendees-notify')[(action != 'new' && allow_invitations && me.has_attendees(event) && (settings.itip_notify & 2) ? 'show' : 'hide')](); | |
753 $('#edit-localchanges-warning')[(action != 'new' && me.has_attendees(event) && !(allow_invitations || (calendar.owner && me.is_organizer(event, calendar.owner))) ? 'show' : 'hide')](); | |
754 | |
755 var load_attendees_tab = function() | |
756 { | |
757 var j, data, organizer_attendee, reply_selected = 0; | |
758 if (event.attendees) { | |
759 for (j=0; j < event.attendees.length; j++) { | |
760 data = event.attendees[j]; | |
761 // reset attendee status | |
762 if (event._savemode == 'new' && data.role != 'ORGANIZER') { | |
763 data.status = 'NEEDS-ACTION'; | |
764 delete data.noreply; | |
765 } | |
766 add_attendee(data, !allow_invitations); | |
767 if (allow_invitations && data.role != 'ORGANIZER' && !data.noreply) | |
768 reply_selected++; | |
769 | |
770 if (data.role == 'ORGANIZER') | |
771 organizer_attendee = data; | |
772 } | |
773 } | |
774 | |
775 // make sure comment box is visible if at least one attendee has reply enabled | |
776 // or global "send invitations" checkbox is checked | |
777 $('#eventedit .attendees-commentbox')[(reply_selected || invite.checked ? 'show' : 'hide')](); | |
778 | |
779 // select the correct organizer identity | |
780 var identity_id = 0; | |
781 $.each(settings.identities, function(i,v){ | |
782 if (organizer && typeof organizer == 'object' && v == organizer.email) { | |
783 identity_id = i; | |
784 return false; | |
785 } | |
786 }); | |
787 | |
788 // In case the user is not the (shared) event organizer we'll add the organizer to the selection list | |
789 if (!identity_id && !organizer && organizer_attendee) { | |
790 var organizer_name = organizer_attendee.email; | |
791 if (organizer_attendee.name) | |
792 organizer_name = '"' + organizer_attendee.name + '" <' + organizer_name + '>'; | |
793 $('#edit-identities-list').append($('<option value="0">').text(organizer_name)); | |
794 } | |
795 | |
796 $('#edit-identities-list').val(identity_id); | |
797 $('#edit-attendees-form')[(allow_invitations?'show':'hide')](); | |
798 $('#edit-attendee-schedule')[(calendar.freebusy?'show':'hide')](); | |
799 }; | |
800 | |
801 // attachments | |
802 var load_attachments_tab = function() | |
803 { | |
804 rcmail.enable_command('remove-attachment', calendar.editable && !event.recurrence_id); | |
805 rcmail.env.deleted_attachments = []; | |
806 // we're sharing some code for uploads handling with app.js | |
807 rcmail.env.attachments = []; | |
808 rcmail.env.compose_id = event.id; // for rcmail.async_upload_form() | |
809 | |
810 if ($.isArray(event.attachments)) { | |
811 event_show_attachments(event.attachments, $('#edit-attachments'), event, true); | |
812 } | |
813 else { | |
814 $('#edit-attachments > ul').empty(); | |
815 // fetch attachments, some drivers doesn't set 'attachments' array for event? | |
816 } | |
817 }; | |
818 | |
819 // init dialog buttons | |
820 var buttons = []; | |
821 | |
822 // save action | |
823 buttons.push({ | |
824 text: rcmail.gettext('save', 'calendar'), | |
825 'class': 'mainaction', | |
826 click: function() { | |
827 var start = parse_datetime(allday.checked ? '12:00' : starttime.val(), startdate.val()); | |
828 var end = parse_datetime(allday.checked ? '13:00' : endtime.val(), enddate.val()); | |
829 | |
830 // basic input validatetion | |
831 if (start.getTime() > end.getTime()) { | |
832 alert(rcmail.gettext('invalideventdates', 'calendar')); | |
833 return false; | |
834 } | |
835 | |
836 // post data to server | |
837 var data = { | |
838 calendar: event.calendar, | |
839 start: date2servertime(start), | |
840 end: date2servertime(end), | |
841 allday: allday.checked?1:0, | |
842 title: title.val(), | |
12
ff1f27bd05ad
partial success in getting back_link to message when making event from mail
Charlie Root
parents:
3
diff
changeset
|
843 description: description.html(), |
3 | 844 location: location.val(), |
845 categories: categories.val(), | |
846 vurl: vurl.val(), | |
847 free_busy: freebusy.val(), | |
848 priority: priority.val(), | |
849 sensitivity: sensitivity.val(), | |
850 status: eventstatus.val(), | |
851 recurrence: me.serialize_recurrence(endtime.val()), | |
852 valarms: me.serialize_alarms('#edit-alarms'), | |
853 attendees: event_attendees, | |
854 links: me.selected_event.links, | |
855 deleted_attachments: rcmail.env.deleted_attachments, | |
856 attachments: [] | |
857 }; | |
858 | |
859 // uploaded attachments list | |
860 for (var i in rcmail.env.attachments) | |
861 if (i.match(/^rcmfile(.+)/)) | |
862 data.attachments.push(RegExp.$1); | |
863 | |
864 // read attendee roles | |
865 $('select.edit-attendee-role').each(function(i, elem){ | |
866 if (data.attendees[i]) | |
867 data.attendees[i].role = $(elem).val(); | |
868 }); | |
869 | |
870 if (organizer) | |
871 data._identity = $('#edit-identities-list option:selected').val(); | |
872 | |
873 // per-attendee notification suppression | |
874 var need_invitation = false; | |
875 if (allow_invitations) { | |
876 $.each(data.attendees, function (i, v) { | |
877 if (v.role != 'ORGANIZER') { | |
878 if ($('input.edit-attendee-reply[value="' + v.email + '"]').prop('checked') || v.cutype == 'RESOURCE') { | |
879 need_invitation = true; | |
880 delete data.attendees[i]['noreply']; | |
881 } | |
882 else if (settings.itip_notify > 0) { | |
883 data.attendees[i].noreply = 1; | |
884 } | |
885 } | |
886 }); | |
887 } | |
888 | |
889 // tell server to send notifications | |
890 if ((data.attendees.length || (event.id && event.attendees.length)) && allow_invitations && (notify.checked || invite.checked || need_invitation)) { | |
891 data._notify = settings.itip_notify; | |
892 data._comment = comment.val(); | |
893 } | |
894 | |
895 data.calendar = calendars.val(); | |
896 | |
897 if (event.id) { | |
898 data.id = event.id; | |
899 if (event.recurrence) | |
900 data._savemode = $('input.edit-recurring-savemode:checked').val(); | |
901 if (data.calendar && data.calendar != event.calendar) | |
902 data._fromcalendar = event.calendar; | |
903 } | |
904 | |
905 update_event(action, data); | |
906 $dialog.dialog("close"); | |
907 } // end click: | |
908 }); | |
909 | |
910 if (event.id) { | |
911 buttons.push({ | |
912 text: rcmail.gettext('delete', 'calendar'), | |
913 'class': 'delete', | |
914 click: function() { | |
915 me.delete_event(event); | |
916 $dialog.dialog('close'); | |
917 } | |
918 }); | |
919 } | |
920 | |
921 buttons.push({ | |
922 text: rcmail.gettext('cancel', 'calendar'), | |
923 click: function() { | |
924 $dialog.dialog("close"); | |
925 } | |
926 }); | |
927 | |
928 // show/hide tabs according to calendar's feature support | |
929 $('#edit-tab-attendees')[(calendar.attendees?'show':'hide')](); | |
930 $('#edit-tab-resources')[(rcmail.env.calendar_resources?'show':'hide')](); | |
931 $('#edit-tab-attachments')[(calendar.attachments?'show':'hide')](); | |
932 | |
933 // activate the first tab | |
934 $('#eventtabs').tabs('option', 'active', 0); | |
935 | |
936 // hack: set task to 'calendar' to make all dialog actions work correctly | |
937 var comm_path_before = rcmail.env.comm_path; | |
938 rcmail.env.comm_path = comm_path_before.replace(/_task=[a-z]+/, '_task=calendar'); | |
939 | |
940 var editform = $("#eventedit"); | |
941 | |
942 // open jquery UI dialog | |
943 $dialog.dialog({ | |
944 modal: true, | |
945 resizable: (!bw.ie6 && !bw.ie7), // disable for performance reasons | |
946 closeOnEscape: false, | |
947 title: rcmail.gettext((action == 'edit' ? 'edit_event' : 'new_event'), 'calendar'), | |
948 open: function() { | |
949 editform.attr('aria-hidden', 'false'); | |
950 }, | |
951 close: function() { | |
952 editform.hide().attr('aria-hidden', 'true').appendTo(document.body); | |
953 $dialog.dialog("destroy").remove(); | |
954 rcmail.ksearch_blur(); | |
955 freebusy_data = {}; | |
956 rcmail.env.comm_path = comm_path_before; // restore comm_path | |
957 if (op_elem) | |
958 $(op_elem).focus(); | |
959 }, | |
960 buttons: buttons, | |
961 minWidth: 500, | |
962 width: 600 | |
963 }).append(editform.show()); // adding form content AFTERWARDS massively speeds up opening on IE6 | |
964 | |
965 // set dialog size according to form content | |
966 me.dialog_resize($dialog.get(0), editform.height() + (bw.ie ? 20 : 0), 550); | |
967 | |
968 title.select(); | |
969 | |
970 // init other tabs asynchronously | |
971 window.setTimeout(function(){ me.set_recurrence_edit(event); }, exec_deferred); | |
972 if (calendar.attendees) | |
973 window.setTimeout(load_attendees_tab, exec_deferred); | |
974 if (calendar.attachments) | |
975 window.setTimeout(load_attachments_tab, exec_deferred); | |
976 | |
977 rcmail.triggerEvent('calendar-event-dialog', {dialog: $dialog}); | |
978 }; | |
979 | |
980 // show event changelog in a dialog | |
981 var event_history_dialog = function(event) | |
982 { | |
983 if (!event.id || !window.libkolab_audittrail) | |
984 return false | |
985 | |
986 // render dialog | |
987 var $dialog = libkolab_audittrail.object_history_dialog({ | |
988 module: 'calendar', | |
989 container: '#eventhistory', | |
990 title: rcmail.gettext('objectchangelog','calendar') + ' - ' + event.title + ', ' + me.event_date_text(event), | |
991 | |
992 // callback function for list actions | |
993 listfunc: function(action, rev) { | |
994 me.loading_lock = rcmail.set_busy(true, 'loading', me.loading_lock); | |
995 rcmail.http_post('event', { action:action, e:{ id:event.id, calendar:event.calendar, rev: rev } }, me.loading_lock); | |
996 }, | |
997 | |
998 // callback function for comparing two object revisions | |
999 comparefunc: function(rev1, rev2) { | |
1000 me.loading_lock = rcmail.set_busy(true, 'loading', me.loading_lock); | |
1001 rcmail.http_post('event', { action:'diff', e:{ id:event.id, calendar:event.calendar, rev1: rev1, rev2: rev2 } }, me.loading_lock); | |
1002 } | |
1003 }); | |
1004 | |
1005 $dialog.data('event', event); | |
1006 | |
1007 // fetch changelog data | |
1008 me.loading_lock = rcmail.set_busy(true, 'loading', me.loading_lock); | |
1009 rcmail.http_post('event', { action:'changelog', e:{ id:event.id, calendar:event.calendar } }, me.loading_lock); | |
1010 }; | |
1011 | |
1012 // callback from server with changelog data | |
1013 var render_event_changelog = function(data) | |
1014 { | |
1015 var $dialog = $('#eventhistory'), | |
1016 event = $dialog.data('event'); | |
1017 | |
1018 if (data === false || !data.length || !event) { | |
1019 // display 'unavailable' message | |
1020 $('<div class="notfound-message event-dialog-message warning">' + rcmail.gettext('objectchangelognotavailable','calendar') + '</div>') | |
1021 .insertBefore($dialog.find('.changelog-table').hide()); | |
1022 return; | |
1023 } | |
1024 | |
1025 data.module = 'calendar'; | |
1026 libkolab_audittrail.render_changelog(data, event, me.calendars[event.calendar]); | |
1027 | |
1028 // set dialog size according to content | |
1029 me.dialog_resize($dialog.get(0), $dialog.height(), 600); | |
1030 }; | |
1031 | |
1032 // callback from server with event diff data | |
1033 var event_show_diff = function(data) | |
1034 { | |
1035 var event = me.selected_event, | |
1036 $dialog = $("#eventdiff"); | |
1037 | |
1038 $dialog.find('div.event-section, div.event-line, h1.event-title-new').hide().data('set', false).find('.index').html(''); | |
1039 $dialog.find('div.event-section.clone, div.event-line.clone').remove(); | |
1040 | |
1041 // always show event title and date | |
1042 $('.event-title', $dialog).text(event.title).removeClass('event-text-old').show(); | |
1043 $('.event-date', $dialog).text(me.event_date_text(event)).show(); | |
1044 | |
1045 // show each property change | |
1046 $.each(data.changes, function(i,change) { | |
1047 var prop = change.property, r2, html = false, | |
1048 row = $('div.event-' + prop, $dialog).first(); | |
1049 | |
1050 // special case: title | |
1051 if (prop == 'title') { | |
1052 $('.event-title', $dialog).addClass('event-text-old').text(change['old'] || '--'); | |
1053 $('.event-title-new', $dialog).text(change['new'] || '--').show(); | |
1054 } | |
1055 | |
1056 // no display container for this property | |
1057 if (!row.length) { | |
1058 return true; | |
1059 } | |
1060 | |
1061 // clone row if already exists | |
1062 if (row.data('set')) { | |
1063 r2 = row.clone().addClass('clone').insertAfter(row); | |
1064 row = r2; | |
1065 } | |
1066 | |
1067 // format dates | |
1068 if (['start','end','changed'].indexOf(prop) >= 0) { | |
1069 if (change['old']) change.old_ = me.format_datetime(parseISO8601(change['old'])); | |
1070 if (change['new']) change.new_ = me.format_datetime(parseISO8601(change['new'])); | |
1071 } | |
1072 // render description text | |
1073 else if (prop == 'description') { | |
1074 // TODO: show real text diff | |
1075 if (!change.diff_ && change['old']) change.old_ = text2html(change['old']); | |
1076 if (!change.diff_ && change['new']) change.new_ = text2html(change['new']); | |
1077 html = true; | |
1078 } | |
1079 // format attendees struct | |
1080 else if (prop == 'attendees') { | |
1081 if (change['old']) change.old_ = rcube_libcalendaring.attendee_html(change['old']); | |
1082 if (change['new']) change.new_ = rcube_libcalendaring.attendee_html($.extend({}, change['old'] || {}, change['new'])); | |
1083 html = true; | |
1084 } | |
1085 // localize priority values | |
1086 else if (prop == 'priority') { | |
1087 var priolabels = [ '', rcmail.gettext('highest'), rcmail.gettext('high'), '', '', rcmail.gettext('normal'), '', '', rcmail.gettext('low'), rcmail.gettext('lowest') ]; | |
1088 if (change['old']) change.old_ = change['old'] + ' ' + (priolabels[change['old']] || ''); | |
1089 if (change['new']) change.new_ = change['new'] + ' ' + (priolabels[change['new']] || ''); | |
1090 } | |
1091 // localize status | |
1092 else if (prop == 'status') { | |
1093 var status_lc = String(event.status).toLowerCase(); | |
1094 if (change['old']) change.old_ = rcmail.gettext(String(change['old']).toLowerCase(), 'calendar'); | |
1095 if (change['new']) change.new_ = rcmail.gettext(String(change['new']).toLowerCase(), 'calendar'); | |
1096 } | |
1097 | |
1098 // format attachments struct | |
1099 if (prop == 'attachments') { | |
1100 if (change['old']) event_show_attachments([change['old']], row.children('.event-text-old'), event, false); | |
1101 else row.children('.event-text-old').text('--'); | |
1102 if (change['new']) event_show_attachments([$.extend({}, change['old'] || {}, change['new'])], row.children('.event-text-new'), event, false); | |
1103 else row.children('.event-text-new').text('--'); | |
1104 // remove click handler as we're currentyl not able to display the according attachment contents | |
1105 $('.attachmentslist li a', row).unbind('click').removeAttr('href'); | |
1106 } | |
1107 else if (change.diff_) { | |
1108 row.children('.event-text-diff').html(change.diff_); | |
1109 row.children('.event-text-old, .event-text-new').hide(); | |
1110 } | |
1111 else { | |
1112 if (!html) { | |
1113 // escape HTML characters | |
1114 change.old_ = Q(change.old_ || change['old'] || '--') | |
1115 change.new_ = Q(change.new_ || change['new'] || '--') | |
1116 } | |
1117 row.children('.event-text-old').html(change.old_ || change['old'] || '--'); | |
1118 row.children('.event-text-new').html(change.new_ || change['new'] || '--'); | |
1119 } | |
1120 | |
1121 // display index number | |
1122 if (typeof change.index != 'undefined') { | |
1123 row.find('.index').html('(' + change.index + ')'); | |
1124 } | |
1125 | |
1126 row.show().data('set', true); | |
1127 | |
1128 // hide event-date line | |
1129 if (prop == 'start' || prop == 'end') | |
1130 $('.event-date', $dialog).hide(); | |
1131 }); | |
1132 | |
1133 var buttons = {}; | |
1134 buttons[rcmail.gettext('close', 'calendar')] = function() { | |
1135 $dialog.dialog('close'); | |
1136 }; | |
1137 | |
1138 // open jquery UI dialog | |
1139 $dialog.dialog({ | |
1140 modal: false, | |
1141 resizable: true, | |
1142 closeOnEscape: true, | |
1143 title: rcmail.gettext('objectdiff','calendar').replace('$rev1', data.rev1).replace('$rev2', data.rev2) + ' - ' + event.title, | |
1144 open: function() { | |
1145 $dialog.attr('aria-hidden', 'false'); | |
1146 setTimeout(function(){ | |
1147 $dialog.parent().find('.ui-button:not(.ui-dialog-titlebar-close)').first().focus(); | |
1148 }, 5); | |
1149 }, | |
1150 close: function() { | |
1151 $dialog.dialog('destroy').attr('aria-hidden', 'true').hide(); | |
1152 }, | |
1153 buttons: buttons, | |
1154 minWidth: 320, | |
1155 width: 450 | |
1156 }).show(); | |
1157 | |
1158 // set dialog size according to content | |
1159 me.dialog_resize($dialog.get(0), $dialog.height(), 400); | |
1160 }; | |
1161 | |
1162 // close the event history dialog | |
1163 var close_history_dialog = function() | |
1164 { | |
1165 $('#eventhistory, #eventdiff').each(function(i, elem) { | |
1166 var $dialog = $(elem); | |
1167 if ($dialog.is(':ui-dialog')) | |
1168 $dialog.dialog('close'); | |
1169 }); | |
1170 } | |
1171 | |
1172 // exports | |
1173 this.event_show_diff = event_show_diff; | |
1174 this.event_show_dialog = event_show_dialog; | |
1175 this.event_history_dialog = event_history_dialog; | |
1176 this.render_event_changelog = render_event_changelog; | |
1177 this.close_history_dialog = close_history_dialog; | |
1178 | |
1179 // open a dialog to display detailed free-busy information and to find free slots | |
1180 var event_freebusy_dialog = function() | |
1181 { | |
1182 var $dialog = $('#eventfreebusy'), | |
1183 event = me.selected_event; | |
1184 | |
1185 if ($dialog.is(':ui-dialog')) | |
1186 $dialog.dialog('close'); | |
1187 | |
1188 if (!event_attendees.length) | |
1189 return false; | |
1190 | |
1191 // set form elements | |
1192 var allday = $('#edit-allday').get(0); | |
1193 var duration = Math.round((event.end.getTime() - event.start.getTime()) / 1000); | |
1194 freebusy_ui.startdate = $('#schedule-startdate').val($.fullCalendar.formatDate(event.start, settings['date_format'])).data('duration', duration); | |
1195 freebusy_ui.starttime = $('#schedule-starttime').val($.fullCalendar.formatDate(event.start, settings['time_format'])).show(); | |
1196 freebusy_ui.enddate = $('#schedule-enddate').val($.fullCalendar.formatDate(event.end, settings['date_format'])); | |
1197 freebusy_ui.endtime = $('#schedule-endtime').val($.fullCalendar.formatDate(event.end, settings['time_format'])).show(); | |
1198 | |
1199 if (allday.checked) { | |
1200 freebusy_ui.starttime.val("12:00").hide(); | |
1201 freebusy_ui.endtime.val("13:00").hide(); | |
1202 event.allDay = true; | |
1203 } | |
1204 | |
1205 // read attendee roles from drop-downs | |
1206 $('select.edit-attendee-role').each(function(i, elem){ | |
1207 if (event_attendees[i]) | |
1208 event_attendees[i].role = $(elem).val(); | |
1209 }); | |
1210 | |
1211 // render time slots | |
1212 var now = new Date(), fb_start = new Date(), fb_end = new Date(); | |
1213 fb_start.setTime(event.start); | |
1214 fb_start.setHours(0); fb_start.setMinutes(0); fb_start.setSeconds(0); fb_start.setMilliseconds(0); | |
1215 fb_end.setTime(fb_start.getTime() + DAY_MS); | |
1216 | |
1217 freebusy_data = { required:{}, all:{} }; | |
1218 freebusy_ui.loading = 1; // prevent render_freebusy_grid() to load data yet | |
1219 freebusy_ui.numdays = Math.max(allday.checked ? 14 : 1, Math.ceil(duration * 2 / 86400)); | |
1220 freebusy_ui.interval = allday.checked ? 1440 : (60 / (settings.timeslots || 1)); | |
1221 freebusy_ui.start = fb_start; | |
1222 freebusy_ui.end = new Date(freebusy_ui.start.getTime() + DAY_MS * freebusy_ui.numdays); | |
1223 render_freebusy_grid(0); | |
1224 | |
1225 // render list of attendees | |
1226 freebusy_ui.attendees = {}; | |
1227 var domid, dispname, data, role_html, list_html = ''; | |
1228 for (var i=0; i < event_attendees.length; i++) { | |
1229 data = event_attendees[i]; | |
1230 dispname = Q(data.name || data.email); | |
1231 domid = String(data.email).replace(rcmail.identifier_expr, ''); | |
1232 role_html = '<a class="attendee-role-toggle" id="rcmlia' + domid + '" title="' + Q(rcmail.gettext('togglerole', 'calendar')) + '"> </a>'; | |
1233 list_html += '<div class="attendee ' + String(data.role).toLowerCase() + '" id="rcmli' + domid + '">' + role_html + dispname + '</div>'; | |
1234 | |
1235 // clone attendees data for local modifications | |
1236 freebusy_ui.attendees[i] = freebusy_ui.attendees[domid] = $.extend({}, data); | |
1237 } | |
1238 | |
1239 // add total row | |
1240 list_html += '<div class="attendee spacer"> </div>'; | |
1241 list_html += '<div class="attendee total">' + rcmail.gettext('reqallattendees','calendar') + '</div>'; | |
1242 | |
1243 $('#schedule-attendees-list').html(list_html) | |
1244 .unbind('click.roleicons') | |
1245 .bind('click.roleicons', function(e){ | |
1246 // toggle attendee status upon click on icon | |
1247 if (e.target.id && e.target.id.match(/rcmlia(.+)/)) { | |
1248 var attendee, domid = RegExp.$1, | |
1249 roles = [ 'REQ-PARTICIPANT', 'OPT-PARTICIPANT', 'NON-PARTICIPANT', 'CHAIR' ]; | |
1250 if ((attendee = freebusy_ui.attendees[domid]) && attendee.role != 'ORGANIZER') { | |
1251 var req = attendee.role != 'OPT-PARTICIPANT' && attendee.role != 'NON-PARTICIPANT'; | |
1252 var j = $.inArray(attendee.role, roles); | |
1253 j = (j+1) % roles.length; | |
1254 attendee.role = roles[j]; | |
1255 $(e.target).parent().attr('class', 'attendee '+String(attendee.role).toLowerCase()); | |
1256 | |
1257 // update total display if required-status changed | |
1258 if (req != (roles[j] != 'OPT-PARTICIPANT' && roles[j] != 'NON-PARTICIPANT')) { | |
1259 compute_freebusy_totals(); | |
1260 update_freebusy_display(attendee.email); | |
1261 } | |
1262 } | |
1263 } | |
1264 | |
1265 return false; | |
1266 }); | |
1267 | |
1268 // enable/disable buttons | |
1269 $('#shedule-find-prev').button('option', 'disabled', (fb_start.getTime() < now.getTime())); | |
1270 | |
1271 // dialog buttons | |
1272 var buttons = {}; | |
1273 | |
1274 buttons[rcmail.gettext('select', 'calendar')] = function() { | |
1275 $('#edit-startdate').val(freebusy_ui.startdate.val()); | |
1276 $('#edit-starttime').val(freebusy_ui.starttime.val()); | |
1277 $('#edit-enddate').val(freebusy_ui.enddate.val()); | |
1278 $('#edit-endtime').val(freebusy_ui.endtime.val()); | |
1279 | |
1280 // write role changes back to main dialog | |
1281 $('select.edit-attendee-role').each(function(i, elem){ | |
1282 if (event_attendees[i] && freebusy_ui.attendees[i]) { | |
1283 event_attendees[i].role = freebusy_ui.attendees[i].role; | |
1284 $(elem).val(event_attendees[i].role); | |
1285 } | |
1286 }); | |
1287 | |
1288 if (freebusy_ui.needsupdate) | |
1289 update_freebusy_status(me.selected_event); | |
1290 freebusy_ui.needsupdate = false; | |
1291 $dialog.dialog("close"); | |
1292 }; | |
1293 | |
1294 buttons[rcmail.gettext('cancel', 'calendar')] = function() { | |
1295 $dialog.dialog("close"); | |
1296 }; | |
1297 | |
1298 $dialog.dialog({ | |
1299 modal: true, | |
1300 resizable: true, | |
1301 closeOnEscape: (!bw.ie6 && !bw.ie7), | |
1302 title: rcmail.gettext('scheduletime', 'calendar'), | |
1303 open: function() { | |
1304 rcmail.ksearch_blur(); | |
1305 $dialog.attr('aria-hidden', 'false').find('#shedule-find-next, #shedule-find-prev').not(':disabled').first().focus(); | |
1306 }, | |
1307 close: function() { | |
1308 if (bw.ie6) | |
1309 $("#edit-attendees-table").css('visibility','visible'); | |
1310 $dialog.dialog("destroy").attr('aria-hidden', 'true').hide(); | |
1311 // TODO: focus opener button | |
1312 }, | |
1313 resizeStop: function() { | |
1314 render_freebusy_overlay(); | |
1315 }, | |
1316 buttons: buttons, | |
1317 minWidth: 640, | |
1318 width: 850 | |
1319 }).show(); | |
1320 | |
1321 // hide edit dialog on IE6 because of drop-down elements | |
1322 if (bw.ie6) | |
1323 $("#edit-attendees-table").css('visibility','hidden'); | |
1324 | |
1325 // adjust dialog size to fit grid without scrolling | |
1326 var gridw = $('#schedule-freebusy-times').width(); | |
1327 var overflow = gridw - $('#attendees-freebusy-table td.times').width(); | |
1328 me.dialog_resize($dialog.get(0), $dialog.height() + (bw.ie ? 20 : 0), 800 + Math.max(0, overflow)); | |
1329 | |
1330 // fetch data from server | |
1331 freebusy_ui.loading = 0; | |
1332 load_freebusy_data(freebusy_ui.start, freebusy_ui.interval); | |
1333 }; | |
1334 | |
1335 // render an HTML table showing free-busy status for all the event attendees | |
1336 var render_freebusy_grid = function(delta) | |
1337 { | |
1338 if (delta) { | |
1339 freebusy_ui.start.setTime(freebusy_ui.start.getTime() + DAY_MS * delta); | |
1340 fix_date(freebusy_ui.start); | |
1341 | |
1342 // skip weekends if in workinhoursonly-mode | |
1343 if (Math.abs(delta) == 1 && freebusy_ui.workinhoursonly) { | |
1344 while (is_weekend(freebusy_ui.start)) | |
1345 freebusy_ui.start.setTime(freebusy_ui.start.getTime() + DAY_MS * delta); | |
1346 fix_date(freebusy_ui.start); | |
1347 } | |
1348 | |
1349 freebusy_ui.end = new Date(freebusy_ui.start.getTime() + DAY_MS * freebusy_ui.numdays); | |
1350 } | |
1351 | |
1352 var dayslots = Math.floor(1440 / freebusy_ui.interval); | |
1353 var date_format = 'ddd '+ (dayslots <= 2 ? settings.date_short : settings.date_format); | |
1354 var lastdate, datestr, css, | |
1355 curdate = new Date(), | |
1356 allday = (freebusy_ui.interval == 1440), | |
1357 interval = allday ? 1440 : (freebusy_ui.interval * (settings.timeslots || 1)); | |
1358 times_css = (allday ? 'allday ' : ''), | |
1359 dates_row = '<tr class="dates">', | |
1360 times_row = '<tr class="times">', | |
1361 slots_row = ''; | |
1362 | |
1363 for (var s = 0, t = freebusy_ui.start.getTime(); t < freebusy_ui.end.getTime(); s++) { | |
1364 curdate.setTime(t); | |
1365 datestr = fc.fullCalendar('formatDate', curdate, date_format); | |
1366 if (datestr != lastdate) { | |
1367 if (lastdate && !allday) break; | |
1368 dates_row += '<th colspan="' + dayslots + '" class="boxtitle date' + $.fullCalendar.formatDate(curdate, 'ddMMyyyy') + '">' + Q(datestr) + '</th>'; | |
1369 lastdate = datestr; | |
1370 } | |
1371 | |
1372 // set css class according to working hours | |
1373 css = is_weekend(curdate) || (freebusy_ui.interval <= 60 && !is_workinghour(curdate)) ? 'offhours' : 'workinghours'; | |
1374 times_row += '<td class="' + times_css + css + '" id="t-' + Math.floor(t/1000) + '">' + Q(allday ? rcmail.gettext('all-day','calendar') : $.fullCalendar.formatDate(curdate, settings['time_format'])) + '</td>'; | |
1375 slots_row += '<td class="' + css + '"> </td>'; | |
1376 | |
1377 t += interval * 60000; | |
1378 } | |
1379 dates_row += '</tr>'; | |
1380 times_row += '</tr>'; | |
1381 | |
1382 // render list of attendees | |
1383 var domid, data, list_html = '', times_html = ''; | |
1384 for (var i=0; i < event_attendees.length; i++) { | |
1385 data = event_attendees[i]; | |
1386 domid = String(data.email).replace(rcmail.identifier_expr, ''); | |
1387 times_html += '<tr id="fbrow' + domid + '">' + slots_row + '</tr>'; | |
1388 } | |
1389 | |
1390 // add line for all/required attendees | |
1391 times_html += '<tr class="spacer"><td colspan="' + (dayslots * freebusy_ui.numdays) + '"></td>'; | |
1392 times_html += '<tr id="fbrowall">' + slots_row + '</tr>'; | |
1393 | |
1394 var table = $('#schedule-freebusy-times'); | |
1395 table.children('thead').html(dates_row + times_row); | |
1396 table.children('tbody').html(times_html); | |
1397 | |
1398 // initialize event handlers on grid | |
1399 if (!freebusy_ui.grid_events) { | |
1400 freebusy_ui.grid_events = true; | |
1401 table.children('thead').click(function(e){ | |
1402 // move event to the clicked date/time | |
1403 if (e.target.id && e.target.id.match(/t-(\d+)/)) { | |
1404 var newstart = new Date(RegExp.$1 * 1000); | |
1405 // set time to 00:00 | |
1406 if (me.selected_event.allDay) { | |
1407 newstart.setMinutes(0); | |
1408 newstart.setHours(0); | |
1409 } | |
1410 update_freebusy_dates(newstart, new Date(newstart.getTime() + freebusy_ui.startdate.data('duration') * 1000)); | |
1411 render_freebusy_overlay(); | |
1412 } | |
1413 }); | |
1414 } | |
1415 | |
1416 // if we have loaded free-busy data, show it | |
1417 if (!freebusy_ui.loading) { | |
1418 if (freebusy_ui.start < freebusy_data.start || freebusy_ui.end > freebusy_data.end || freebusy_ui.interval != freebusy_data.interval) { | |
1419 load_freebusy_data(freebusy_ui.start, freebusy_ui.interval); | |
1420 } | |
1421 else { | |
1422 for (var email, i=0; i < event_attendees.length; i++) { | |
1423 if ((email = event_attendees[i].email)) | |
1424 update_freebusy_display(email); | |
1425 } | |
1426 } | |
1427 } | |
1428 | |
1429 // render current event date/time selection over grid table | |
1430 // use timeout to let the dom attributes (width/height/offset) be set first | |
1431 window.setTimeout(function(){ render_freebusy_overlay(); }, 10); | |
1432 }; | |
1433 | |
1434 // render overlay element over the grid to visiualize the current event date/time | |
1435 var render_freebusy_overlay = function() | |
1436 { | |
1437 var overlay = $('#schedule-event-time'); | |
1438 if (me.selected_event.end.getTime() <= freebusy_ui.start.getTime() || me.selected_event.start.getTime() >= freebusy_ui.end.getTime()) { | |
1439 overlay.hide(); | |
1440 if (overlay.data('isdraggable')) | |
1441 overlay.draggable('disable'); | |
1442 } | |
1443 else { | |
1444 var i, n, table = $('#schedule-freebusy-times'), | |
1445 width = 0, | |
1446 pos = { top:table.children('thead').height(), left:0 }, | |
1447 eventstart = date2unixtime(clone_date(me.selected_event.start, me.selected_event.allDay?1:0)), | |
1448 eventend = date2unixtime(clone_date(me.selected_event.end, me.selected_event.allDay?2:0)) - 60, | |
1449 slotstart = date2unixtime(freebusy_ui.start), | |
1450 slotsize = freebusy_ui.interval * 60, | |
1451 slotnum = freebusy_ui.interval > 60 ? 1 : (60 / freebusy_ui.interval), | |
1452 cells = table.children('thead').find('td'), | |
1453 cell_width = cells.first().get(0).offsetWidth, | |
1454 slotend; | |
1455 | |
1456 // iterate through slots to determine position and size of the overlay | |
1457 for (i=0; i < cells.length; i++) { | |
1458 for (n=0; n < slotnum; n++) { | |
1459 slotend = slotstart + slotsize - 1; | |
1460 // event starts in this slot: compute left | |
1461 if (eventstart >= slotstart && eventstart <= slotend) { | |
1462 pos.left = Math.round(i * cell_width + (cell_width / slotnum) * n); | |
1463 } | |
1464 // event ends in this slot: compute width | |
1465 if (eventend >= slotstart && eventend <= slotend) { | |
1466 width = Math.round(i * cell_width + (cell_width / slotnum) * (n + 1)) - pos.left; | |
1467 } | |
1468 slotstart += slotsize; | |
1469 } | |
1470 } | |
1471 | |
1472 if (!width) | |
1473 width = table.width() - pos.left; | |
1474 | |
1475 // overlay is visible | |
1476 if (width > 0) { | |
1477 overlay.css({ width: (width-4)+'px', height:(table.children('tbody').height() - 4)+'px', left:pos.left+'px', top:pos.top+'px' }).show(); | |
1478 | |
1479 // configure draggable | |
1480 if (!overlay.data('isdraggable')) { | |
1481 overlay.draggable({ | |
1482 axis: 'x', | |
1483 scroll: true, | |
1484 stop: function(e, ui){ | |
1485 // convert pixels to time | |
1486 var px = ui.position.left; | |
1487 var range_p = $('#schedule-freebusy-times').width(); | |
1488 var range_t = freebusy_ui.end.getTime() - freebusy_ui.start.getTime(); | |
1489 var newstart = new Date(freebusy_ui.start.getTime() + px * (range_t / range_p)); | |
1490 newstart.setSeconds(0); newstart.setMilliseconds(0); | |
1491 // snap to day boundaries | |
1492 if (me.selected_event.allDay) { | |
1493 if (newstart.getHours() >= 12) // snap to next day | |
1494 newstart.setTime(newstart.getTime() + DAY_MS); | |
1495 newstart.setMinutes(0); | |
1496 newstart.setHours(0); | |
1497 } | |
1498 else { | |
1499 // round to 5 minutes | |
1500 // @TODO: round to timeslots? | |
1501 var round = newstart.getMinutes() % 5; | |
1502 if (round > 2.5) newstart.setTime(newstart.getTime() + (5 - round) * 60000); | |
1503 else if (round > 0) newstart.setTime(newstart.getTime() - round * 60000); | |
1504 } | |
1505 // update event times and display | |
1506 update_freebusy_dates(newstart, new Date(newstart.getTime() + freebusy_ui.startdate.data('duration') * 1000)); | |
1507 if (me.selected_event.allDay) | |
1508 render_freebusy_overlay(); | |
1509 } | |
1510 }).data('isdraggable', true); | |
1511 } | |
1512 else | |
1513 overlay.draggable('enable'); | |
1514 } | |
1515 else | |
1516 overlay.draggable('disable').hide(); | |
1517 } | |
1518 }; | |
1519 | |
1520 // fetch free-busy information for each attendee from server | |
1521 var load_freebusy_data = function(from, interval) | |
1522 { | |
1523 var start = new Date(from.getTime() - DAY_MS * 2); // start 2 days before event | |
1524 fix_date(start); | |
1525 var end = new Date(start.getTime() + DAY_MS * Math.max(14, freebusy_ui.numdays + 7)); // load min. 14 days | |
1526 freebusy_ui.numrequired = 0; | |
1527 freebusy_data.all = []; | |
1528 freebusy_data.required = []; | |
1529 | |
1530 // load free-busy information for every attendee | |
1531 var domid, email; | |
1532 for (var i=0; i < event_attendees.length; i++) { | |
1533 if ((email = event_attendees[i].email)) { | |
1534 domid = String(email).replace(rcmail.identifier_expr, ''); | |
1535 $('#rcmli' + domid).addClass('loading'); | |
1536 freebusy_ui.loading++; | |
1537 | |
1538 $.ajax({ | |
1539 type: 'GET', | |
1540 dataType: 'json', | |
1541 url: rcmail.url('freebusy-times'), | |
1542 data: { email:email, start:date2servertime(clone_date(start, 1)), end:date2servertime(clone_date(end, 2)), interval:interval, _remote:1 }, | |
1543 success: function(data) { | |
1544 freebusy_ui.loading--; | |
1545 | |
1546 // find attendee | |
1547 var i, attendee = null; | |
1548 for (i=0; i < event_attendees.length; i++) { | |
1549 if (freebusy_ui.attendees[i].email == data.email) { | |
1550 attendee = freebusy_ui.attendees[i]; | |
1551 break; | |
1552 } | |
1553 } | |
1554 | |
1555 // copy data to member var | |
1556 var ts, status, | |
1557 req = attendee.role != 'OPT-PARTICIPANT', | |
1558 start = parseISO8601(data.start); | |
1559 | |
1560 freebusy_data.start = new Date(start); | |
1561 freebusy_data.end = parseISO8601(data.end); | |
1562 freebusy_data.interval = data.interval; | |
1563 freebusy_data[data.email] = {}; | |
1564 | |
1565 for (i=0; i < data.slots.length; i++) { | |
1566 ts = date2timestring(start, data.interval > 60); | |
1567 status = data.slots.charAt(i); | |
1568 freebusy_data[data.email][ts] = status | |
1569 start = new Date(start.getTime() + data.interval * 60000); | |
1570 | |
1571 // set totals | |
1572 if (!freebusy_data.required[ts]) | |
1573 freebusy_data.required[ts] = [0,0,0,0]; | |
1574 if (req) | |
1575 freebusy_data.required[ts][status]++; | |
1576 | |
1577 if (!freebusy_data.all[ts]) | |
1578 freebusy_data.all[ts] = [0,0,0,0]; | |
1579 freebusy_data.all[ts][status]++; | |
1580 } | |
1581 | |
1582 // hide loading indicator | |
1583 var domid = String(data.email).replace(rcmail.identifier_expr, ''); | |
1584 $('#rcmli' + domid).removeClass('loading'); | |
1585 | |
1586 // update display | |
1587 update_freebusy_display(data.email); | |
1588 } | |
1589 }); | |
1590 | |
1591 // count required attendees | |
1592 if (freebusy_ui.attendees[i].role != 'OPT-PARTICIPANT') | |
1593 freebusy_ui.numrequired++; | |
1594 } | |
1595 } | |
1596 }; | |
1597 | |
1598 // re-calculate total status after role change | |
1599 var compute_freebusy_totals = function() | |
1600 { | |
1601 freebusy_ui.numrequired = 0; | |
1602 freebusy_data.all = []; | |
1603 freebusy_data.required = []; | |
1604 | |
1605 var email, req, status; | |
1606 for (var i=0; i < event_attendees.length; i++) { | |
1607 if (!(email = event_attendees[i].email)) | |
1608 continue; | |
1609 | |
1610 req = freebusy_ui.attendees[i].role != 'OPT-PARTICIPANT'; | |
1611 if (req) | |
1612 freebusy_ui.numrequired++; | |
1613 | |
1614 for (var ts in freebusy_data[email]) { | |
1615 if (!freebusy_data.required[ts]) | |
1616 freebusy_data.required[ts] = [0,0,0,0]; | |
1617 if (!freebusy_data.all[ts]) | |
1618 freebusy_data.all[ts] = [0,0,0,0]; | |
1619 | |
1620 status = freebusy_data[email][ts]; | |
1621 freebusy_data.all[ts][status]++; | |
1622 | |
1623 if (req) | |
1624 freebusy_data.required[ts][status]++; | |
1625 } | |
1626 } | |
1627 }; | |
1628 | |
1629 // update free-busy grid with status loaded from server | |
1630 var update_freebusy_display = function(email) | |
1631 { | |
1632 var status_classes = ['unknown','free','busy','tentative','out-of-office']; | |
1633 var domid = String(email).replace(rcmail.identifier_expr, ''); | |
1634 var row = $('#fbrow' + domid); | |
1635 var rowall = $('#fbrowall').children(); | |
1636 var dateonly = freebusy_ui.interval > 60, | |
1637 t, ts = date2timestring(freebusy_ui.start, dateonly), | |
1638 curdate = new Date(), | |
1639 fbdata = freebusy_data[email]; | |
1640 | |
1641 if (fbdata && fbdata[ts] !== undefined && row.length) { | |
1642 t = freebusy_ui.start.getTime(); | |
1643 row.children().each(function(i, cell) { | |
1644 var j, n, attr, last, all_slots = [], slots = [], | |
1645 all_cell = rowall.get(i), | |
1646 cnt = dateonly ? 1 : (60 / freebusy_ui.interval), | |
1647 percent = (100 / cnt); | |
1648 | |
1649 for (n=0; n < cnt; n++) { | |
1650 curdate.setTime(t); | |
1651 ts = date2timestring(curdate, dateonly); | |
1652 attr = { | |
1653 'style': 'float:left; width:' + percent.toFixed(2) + '%', | |
1654 'class': fbdata[ts] ? status_classes[fbdata[ts]] : 'unknown' | |
1655 }; | |
1656 | |
1657 slots.push($('<div>').attr(attr)); | |
1658 | |
1659 // also update total row if all data was loaded | |
1660 if (!freebusy_ui.loading && freebusy_data.all[ts] && all_cell) { | |
1661 var all_status = freebusy_data.all[ts][2] ? 'busy' : 'unknown', | |
1662 req_status = freebusy_data.required[ts][2] ? 'busy' : 'free'; | |
1663 | |
1664 for (j=1; j < status_classes.length; j++) { | |
1665 if (freebusy_ui.numrequired && freebusy_data.required[ts][j] >= freebusy_ui.numrequired) | |
1666 req_status = status_classes[j]; | |
1667 if (freebusy_data.all[ts][j] == event_attendees.length) | |
1668 all_status = status_classes[j]; | |
1669 } | |
1670 | |
1671 attr['class'] = req_status + ' all-' + all_status; | |
1672 | |
1673 // these elements use some specific styling, so we want to minimize their number | |
1674 if (last && last.attr('class') == attr['class']) | |
1675 last.css('width', (percent + parseFloat(last.css('width').replace('%', ''))).toFixed(2) + '%'); | |
1676 else { | |
1677 last = $('<div>').attr(attr); | |
1678 all_slots.push(last); | |
1679 } | |
1680 } | |
1681 | |
1682 t += freebusy_ui.interval * 60000; | |
1683 } | |
1684 | |
1685 $(cell).html('').append(slots); | |
1686 if (all_slots.length) | |
1687 $(all_cell).html('').append(all_slots); | |
1688 }); | |
1689 } | |
1690 }; | |
1691 | |
1692 // write changed event date/times back to form fields | |
1693 var update_freebusy_dates = function(start, end) | |
1694 { | |
1695 // fix all-day evebt times | |
1696 if (me.selected_event.allDay) { | |
1697 var numdays = Math.floor((me.selected_event.end.getTime() - me.selected_event.start.getTime()) / DAY_MS); | |
1698 start.setHours(12); | |
1699 start.setMinutes(0); | |
1700 end.setTime(start.getTime() + numdays * DAY_MS); | |
1701 end.setHours(13); | |
1702 end.setMinutes(0); | |
1703 } | |
1704 me.selected_event.start = start; | |
1705 me.selected_event.end = end; | |
1706 freebusy_ui.startdate.val($.fullCalendar.formatDate(start, settings['date_format'])); | |
1707 freebusy_ui.starttime.val($.fullCalendar.formatDate(start, settings['time_format'])); | |
1708 freebusy_ui.enddate.val($.fullCalendar.formatDate(end, settings['date_format'])); | |
1709 freebusy_ui.endtime.val($.fullCalendar.formatDate(end, settings['time_format'])); | |
1710 freebusy_ui.needsupdate = true; | |
1711 }; | |
1712 | |
1713 // attempt to find a time slot where all attemdees are available | |
1714 var freebusy_find_slot = function(dir) | |
1715 { | |
1716 // exit if free-busy data isn't available yet | |
1717 if (!freebusy_data || !freebusy_data.start) | |
1718 return false; | |
1719 | |
1720 var event = me.selected_event, | |
1721 eventstart = clone_date(event.start, event.allDay ? 1 : 0).getTime(), // calculate with integers | |
1722 eventend = clone_date(event.end, event.allDay ? 2 : 0).getTime(), | |
1723 duration = eventend - eventstart - (event.allDay ? HOUR_MS : 0), /* make sure we don't cross day borders on DST change */ | |
1724 sinterval = freebusy_data.interval * 60000, | |
1725 intvlslots = 1, | |
1726 numslots = Math.ceil(duration / sinterval), | |
1727 fb_start = freebusy_data.start.getTime(), | |
1728 fb_end = freebusy_data.end.getTime(), | |
1729 checkdate, slotend, email, ts, slot, slotdate = new Date(), | |
1730 candidatecount = 0, candidatestart = false, success = false; | |
1731 | |
1732 // shift event times to next possible slot | |
1733 eventstart += sinterval * intvlslots * dir; | |
1734 eventend += sinterval * intvlslots * dir; | |
1735 | |
1736 // iterate through free-busy slots and find candidates | |
1737 for (slot = dir > 0 ? fb_start : fb_end - sinterval; | |
1738 (dir > 0 && slot < fb_end) || (dir < 0 && slot >= fb_start); | |
1739 slot += sinterval * dir | |
1740 ) { | |
1741 slotdate.setTime(slot); | |
1742 // fix slot if just crossed a DST change | |
1743 if (event.allDay) { | |
1744 fix_date(slotdate); | |
1745 slot = slotdate.getTime(); | |
1746 } | |
1747 slotend = slot + sinterval; | |
1748 | |
1749 if ((dir > 0 && slotend <= eventstart) || (dir < 0 && slot >= eventend)) // skip | |
1750 continue; | |
1751 | |
1752 // respect workinghours setting | |
1753 if (freebusy_ui.workinhoursonly) { | |
1754 if (is_weekend(slotdate) || (freebusy_data.interval <= 60 && !is_workinghour(slotdate))) { // skip off-hours | |
1755 candidatestart = false; | |
1756 candidatecount = 0; | |
1757 continue; | |
1758 } | |
1759 } | |
1760 | |
1761 if (!candidatestart) | |
1762 candidatestart = slot; | |
1763 | |
1764 ts = date2timestring(slotdate, freebusy_data.interval > 60); | |
1765 | |
1766 // check freebusy data for all attendees | |
1767 for (var i=0; i < event_attendees.length; i++) { | |
1768 if (freebusy_ui.attendees[i].role != 'OPT-PARTICIPANT' && (email = freebusy_ui.attendees[i].email) && freebusy_data[email] && freebusy_data[email][ts] > 1) { | |
1769 candidatestart = false; | |
1770 break; | |
1771 } | |
1772 } | |
1773 | |
1774 // occupied slot | |
1775 if (!candidatestart) { | |
1776 slot += Math.max(0, intvlslots - candidatecount - 1) * sinterval * dir; | |
1777 candidatecount = 0; | |
1778 continue; | |
1779 } | |
1780 else if (dir < 0) | |
1781 candidatestart = slot; | |
1782 | |
1783 candidatecount++; | |
1784 | |
1785 // if candidate is big enough, this is it! | |
1786 if (candidatecount == numslots) { | |
1787 event.start.setTime(candidatestart); | |
1788 event.end.setTime(candidatestart + duration); | |
1789 success = true; | |
1790 break; | |
1791 } | |
1792 } | |
1793 | |
1794 // update event date/time display | |
1795 if (success) { | |
1796 update_freebusy_dates(event.start, event.end); | |
1797 | |
1798 // move freebusy grid if necessary | |
1799 var offset = Math.ceil((event.start.getTime() - freebusy_ui.end.getTime()) / DAY_MS); | |
1800 if (event.start.getTime() >= freebusy_ui.end.getTime()) | |
1801 render_freebusy_grid(Math.max(1, offset)); | |
1802 else if (event.end.getTime() <= freebusy_ui.start.getTime()) | |
1803 render_freebusy_grid(Math.min(-1, offset)); | |
1804 else | |
1805 render_freebusy_overlay(); | |
1806 | |
1807 var now = new Date(); | |
1808 $('#shedule-find-prev').button('option', 'disabled', (event.start.getTime() < now.getTime())); | |
1809 | |
1810 // speak new selection | |
1811 rcmail.display_message(rcmail.gettext('suggestedslot', 'calendar') + ': ' + me.event_date_text(event, true), 'voice'); | |
1812 } | |
1813 else { | |
1814 alert(rcmail.gettext('noslotfound','calendar')); | |
1815 } | |
1816 }; | |
1817 | |
1818 // update event properties and attendees availability if event times have changed | |
1819 var event_times_changed = function() | |
1820 { | |
1821 if (me.selected_event) { | |
1822 var allday = $('#edit-allday').get(0); | |
1823 me.selected_event.allDay = allday.checked; | |
1824 me.selected_event.start = parse_datetime(allday.checked ? '12:00' : $('#edit-starttime').val(), $('#edit-startdate').val()); | |
1825 me.selected_event.end = parse_datetime(allday.checked ? '13:00' : $('#edit-endtime').val(), $('#edit-enddate').val()); | |
1826 if (event_attendees) | |
1827 freebusy_ui.needsupdate = true; | |
1828 $('#edit-startdate').data('duration', Math.round((me.selected_event.end.getTime() - me.selected_event.start.getTime()) / 1000)); | |
1829 } | |
1830 }; | |
1831 | |
1832 // add the given list of participants | |
1833 var add_attendees = function(names, params) | |
1834 { | |
1835 names = explode_quoted_string(names.replace(/,\s*$/, ''), ','); | |
1836 | |
1837 // parse name/email pairs | |
1838 var item, email, name, success = false; | |
1839 for (var i=0; i < names.length; i++) { | |
1840 email = name = ''; | |
1841 item = $.trim(names[i]); | |
1842 | |
1843 if (!item.length) { | |
1844 continue; | |
1845 } // address in brackets without name (do nothing) | |
1846 else if (item.match(/^<[^@]+@[^>]+>$/)) { | |
1847 email = item.replace(/[<>]/g, ''); | |
1848 } // address without brackets and without name (add brackets) | |
1849 else if (rcube_check_email(item)) { | |
1850 email = item; | |
1851 } // address with name | |
1852 else if (item.match(/([^\s<@]+@[^>]+)>*$/)) { | |
1853 email = RegExp.$1; | |
1854 name = item.replace(email, '').replace(/^["\s<>]+/, '').replace(/["\s<>]+$/, ''); | |
1855 } | |
1856 if (email) { | |
1857 add_attendee($.extend({ email:email, name:name }, params)); | |
1858 success = true; | |
1859 } | |
1860 else { | |
1861 alert(rcmail.gettext('noemailwarning')); | |
1862 } | |
1863 } | |
1864 | |
1865 return success; | |
1866 }; | |
1867 | |
1868 // add the given attendee to the list | |
1869 var add_attendee = function(data, readonly, before) | |
1870 { | |
1871 if (!me.selected_event) | |
1872 return false; | |
1873 | |
1874 // check for dupes... | |
1875 var exists = false; | |
1876 $.each(event_attendees, function(i, v){ exists |= (v.email == data.email); }); | |
1877 if (exists) | |
1878 return false; | |
1879 | |
1880 var calendar = me.selected_event && me.calendars[me.selected_event.calendar] ? me.calendars[me.selected_event.calendar] : me.calendars[me.selected_calendar]; | |
1881 | |
1882 var dispname = Q(data.name || data.email); | |
1883 if (data.email) | |
1884 dispname = '<a href="mailto:' + data.email + '" title="' + Q(data.email) + '" class="mailtolink" data-cutype="' + data.cutype + '">' + dispname + '</a>'; | |
1885 | |
1886 // role selection | |
1887 var organizer = data.role == 'ORGANIZER'; | |
1888 var opts = {}; | |
1889 if (organizer) | |
1890 opts.ORGANIZER = rcmail.gettext('calendar.roleorganizer'); | |
1891 opts['REQ-PARTICIPANT'] = rcmail.gettext('calendar.rolerequired'); | |
1892 opts['OPT-PARTICIPANT'] = rcmail.gettext('calendar.roleoptional'); | |
1893 opts['NON-PARTICIPANT'] = rcmail.gettext('calendar.rolenonparticipant'); | |
1894 | |
1895 if (data.cutype != 'RESOURCE') | |
1896 opts['CHAIR'] = rcmail.gettext('calendar.rolechair'); | |
1897 | |
1898 if (organizer && !readonly) | |
1899 dispname = rcmail.env['identities-selector']; | |
1900 | |
1901 var select = '<select class="edit-attendee-role"' + (organizer || readonly ? ' disabled="true"' : '') + ' aria-label="' + rcmail.gettext('role','calendar') + '">'; | |
1902 for (var r in opts) | |
1903 select += '<option value="'+ r +'" class="' + r.toLowerCase() + '"' + (data.role == r ? ' selected="selected"' : '') +'>' + Q(opts[r]) + '</option>'; | |
1904 select += '</select>'; | |
1905 | |
1906 // availability | |
1907 var avail = data.email ? 'loading' : 'unknown'; | |
1908 | |
1909 // delete icon | |
1910 var icon = rcmail.env.deleteicon ? '<img src="' + rcmail.env.deleteicon + '" alt="" />' : rcmail.gettext('delete'); | |
1911 var dellink = '<a href="#delete" class="iconlink delete deletelink" title="' + Q(rcmail.gettext('delete')) + '">' + icon + '</a>'; | |
1912 var tooltip = '', status = (data.status || '').toLowerCase(), | |
1913 status_label = rcmail.gettext('status' + status, 'libcalendaring'); | |
1914 | |
1915 // send invitation checkbox | |
1916 var invbox = '<input type="checkbox" class="edit-attendee-reply" value="' + Q(data.email) +'" title="' + Q(rcmail.gettext('calendar.sendinvitations')) + '" ' | |
1917 + (!data.noreply && settings.itip_notify & 1 ? 'checked="checked" ' : '') + '/>'; | |
1918 | |
1919 if (data['delegated-to']) | |
1920 tooltip = rcmail.gettext('libcalendaring.delegatedto') + ' ' + data['delegated-to']; | |
1921 else if (data['delegated-from']) | |
1922 tooltip = rcmail.gettext('libcalendaring.delegatedfrom') + ' ' + data['delegated-from']; | |
1923 else if (status) | |
1924 tooltip = status_label; | |
1925 | |
1926 // add expand button for groups | |
1927 if (data.cutype == 'GROUP') { | |
1928 dispname += ' <a href="#expand" data-email="' + Q(data.email) + '" class="iconbutton add expandlink" title="' + rcmail.gettext('expandattendeegroup','libcalendaring') + '">' + | |
1929 rcmail.gettext('expandattendeegroup','libcalendaring') + '</a>'; | |
1930 } | |
1931 | |
1932 var img_src = rcmail.assets_path('program/resources/blank.gif'); | |
1933 var html = '<td class="role">' + select + '</td>' + | |
1934 '<td class="name"><span class="attendee-name">' + dispname + '</span></td>' + | |
1935 '<td class="availability"><img src="' + img_src + '" class="availabilityicon ' + avail + '" data-email="' + data.email + '" alt="" /></td>' + | |
1936 '<td class="confirmstate"><span class="' + status + '" title="' + Q(tooltip) + '">' + Q(status ? status_label : '') + '</span></td>' + | |
1937 (data.cutype != 'RESOURCE' ? '<td class="invite">' + (organizer || readonly || !invbox ? '' : invbox) + '</td>' : '') + | |
1938 '<td class="options">' + (organizer || readonly ? '' : dellink) + '</td>'; | |
1939 | |
1940 var table = rcmail.env.calendar_resources && data.cutype == 'RESOURCE' ? resources_list : attendees_list; | |
1941 var tr = $('<tr>') | |
1942 .addClass(String(data.role).toLowerCase()) | |
1943 .html(html); | |
1944 | |
1945 if (before) | |
1946 tr.insertBefore(before) | |
1947 else | |
1948 tr.appendTo(table); | |
1949 | |
1950 tr.find('a.deletelink').click({ id:(data.email || data.name) }, function(e) { remove_attendee(this, e.data.id); return false; }); | |
1951 tr.find('a.mailtolink').click(event_attendee_click); | |
1952 tr.find('a.expandlink').click(data, function(e) { me.expand_attendee_group(e, add_attendee, remove_attendee); return false; }); | |
1953 tr.find('input.edit-attendee-reply').click(function() { | |
1954 var enabled = $('#edit-attendees-invite:checked').length || $('input.edit-attendee-reply:checked').length; | |
1955 $('#eventedit .attendees-commentbox')[enabled ? 'show' : 'hide'](); | |
1956 }); | |
1957 | |
1958 // select organizer identity | |
1959 if (data.identity_id) | |
1960 $('#edit-identities-list').val(data.identity_id); | |
1961 | |
1962 // check free-busy status | |
1963 if (avail == 'loading') { | |
1964 check_freebusy_status(tr.find('img.availabilityicon'), data.email, me.selected_event); | |
1965 } | |
1966 | |
1967 event_attendees.push(data); | |
1968 return true; | |
1969 }; | |
1970 | |
1971 // iterate over all attendees and update their free-busy status display | |
1972 var update_freebusy_status = function(event) | |
1973 { | |
1974 attendees_list.find('img.availabilityicon').each(function(i,v) { | |
1975 var email, icon = $(this); | |
1976 if (email = icon.attr('data-email')) | |
1977 check_freebusy_status(icon, email, event); | |
1978 }); | |
1979 | |
1980 freebusy_ui.needsupdate = false; | |
1981 }; | |
1982 | |
1983 // load free-busy status from server and update icon accordingly | |
1984 var check_freebusy_status = function(icon, email, event) | |
1985 { | |
1986 var calendar = event.calendar && me.calendars[event.calendar] ? me.calendars[event.calendar] : { freebusy:false }; | |
1987 if (!calendar.freebusy) { | |
1988 $(icon).attr('class', 'availabilityicon unknown'); | |
1989 return; | |
1990 } | |
1991 | |
1992 icon = $(icon).attr('class', 'availabilityicon loading'); | |
1993 | |
1994 $.ajax({ | |
1995 type: 'GET', | |
1996 dataType: 'html', | |
1997 url: rcmail.url('freebusy-status'), | |
1998 data: { email:email, start:date2servertime(clone_date(event.start, event.allDay?1:0)), end:date2servertime(clone_date(event.end, event.allDay?2:0)), _remote: 1 }, | |
1999 success: function(status){ | |
2000 var avail = String(status).toLowerCase(); | |
2001 icon.removeClass('loading').addClass(avail).attr('alt', rcmail.gettext('avail' + avail, 'calendar')); | |
2002 }, | |
2003 error: function(){ | |
2004 icon.removeClass('loading').addClass('unknown').attr('alt', rcmail.gettext('availunknown', 'calendar')); | |
2005 } | |
2006 }); | |
2007 }; | |
2008 | |
2009 // remove an attendee from the list | |
2010 var remove_attendee = function(elem, id) | |
2011 { | |
2012 $(elem).closest('tr').remove(); | |
2013 event_attendees = $.grep(event_attendees, function(data){ return (data.name != id && data.email != id) }); | |
2014 }; | |
2015 | |
2016 // open a dialog to display detailed free-busy information and to find free slots | |
2017 var event_resources_dialog = function(search) | |
2018 { | |
2019 var $dialog = $('#eventresourcesdialog'); | |
2020 | |
2021 if ($dialog.is(':ui-dialog')) | |
2022 $dialog.dialog('close'); | |
2023 | |
2024 // dialog buttons | |
2025 var buttons = {}; | |
2026 | |
2027 buttons[rcmail.gettext('addresource', 'calendar')] = function() { | |
2028 rcmail.command('add-resource'); | |
2029 }; | |
2030 | |
2031 buttons[rcmail.gettext('close')] = function() { | |
2032 $dialog.dialog("close"); | |
2033 }; | |
2034 | |
2035 // open jquery UI dialog | |
2036 $dialog.dialog({ | |
2037 modal: true, | |
2038 resizable: true, | |
2039 closeOnEscape: true, | |
2040 title: rcmail.gettext('findresources', 'calendar'), | |
2041 open: function() { | |
2042 rcmail.ksearch_blur(); | |
2043 $dialog.attr('aria-hidden', 'false'); | |
2044 }, | |
2045 close: function() { | |
2046 $dialog.dialog('destroy').attr('aria-hidden', 'true').hide(); | |
2047 }, | |
2048 resize: function(e) { | |
2049 var container = $(rcmail.gui_objects.resourceinfocalendar); | |
2050 container.fullCalendar('option', 'height', container.height() + 4); | |
2051 }, | |
2052 buttons: buttons, | |
2053 width: 900, | |
2054 height: 500 | |
2055 }).show(); | |
2056 | |
2057 // define add-button as main action | |
2058 $('.ui-dialog-buttonset .ui-button', $dialog.parent()).first().addClass('mainaction').attr('id', 'rcmbtncalresadd'); | |
2059 | |
2060 me.dialog_resize($dialog.get(0), 540, Math.min(1000, $(window).width() - 50)); | |
2061 | |
2062 // set search query | |
2063 $('#resourcesearchbox').val(search || ''); | |
2064 | |
2065 // initialize the treelist widget | |
2066 if (!resources_treelist) { | |
2067 resources_treelist = new rcube_treelist_widget(rcmail.gui_objects.resourceslist, { | |
2068 id_prefix: 'rcres', | |
2069 id_encode: rcmail.html_identifier_encode, | |
2070 id_decode: rcmail.html_identifier_decode, | |
2071 selectable: true, | |
2072 save_state: true | |
2073 }); | |
2074 resources_treelist.addEventListener('select', function(node) { | |
2075 if (resources_data[node.id]) { | |
2076 resource_showinfo(resources_data[node.id]); | |
2077 rcmail.enable_command('add-resource', me.selected_event && $("#eventedit").is(':visible') ? true : false); | |
2078 } | |
2079 else { | |
2080 rcmail.enable_command('add-resource', false); | |
2081 $(rcmail.gui_objects.resourceinfo).hide(); | |
2082 $(rcmail.gui_objects.resourceownerinfo).hide(); | |
2083 $(rcmail.gui_objects.resourceinfocalendar).fullCalendar('removeEventSource', resources_events_source); | |
2084 } | |
2085 }); | |
2086 | |
2087 // fetch (all) resource data from server | |
2088 me.loading_lock = rcmail.set_busy(true, 'loading', me.loading_lock); | |
2089 rcmail.http_request('resources-list', {}, me.loading_lock); | |
2090 | |
2091 // register button | |
2092 rcmail.register_button('add-resource', 'rcmbtncalresadd', 'uibutton'); | |
2093 | |
2094 // initialize resource calendar display | |
2095 var resource_cal = $(rcmail.gui_objects.resourceinfocalendar); | |
2096 resource_cal.fullCalendar($.extend({}, fullcalendar_defaults, { | |
2097 header: { left: '', center: '', right: '' }, | |
2098 height: resource_cal.height() + 4, | |
2099 defaultView: 'agendaWeek', | |
2100 eventSources: [], | |
2101 slotMinutes: 60, | |
2102 allDaySlot: false, | |
2103 eventRender: function(event, element, view) { | |
2104 var title = rcmail.get_label(event.status, 'calendar'); | |
2105 element.addClass('status-' + event.status); | |
2106 element.find('.fc-event-head').hide(); | |
2107 element.find('.fc-event-title').text(title); | |
2108 element.attr('aria-label', me.event_date_text(event, true) + ': ' + title); | |
2109 } | |
2110 })); | |
2111 | |
2112 $('#resource-calendar-prev').click(function(){ | |
2113 resource_cal.fullCalendar('prev'); | |
2114 return false; | |
2115 }); | |
2116 $('#resource-calendar-next').click(function(){ | |
2117 resource_cal.fullCalendar('next'); | |
2118 return false; | |
2119 }); | |
2120 } | |
2121 else if (search) { | |
2122 resource_search(); | |
2123 } | |
2124 else { | |
2125 resource_render_list(resources_index); | |
2126 } | |
2127 | |
2128 if (me.selected_event && me.selected_event.start) { | |
2129 $(rcmail.gui_objects.resourceinfocalendar).fullCalendar('gotoDate', me.selected_event.start); | |
2130 } | |
2131 }; | |
2132 | |
2133 // render the resource details UI box | |
2134 var resource_showinfo = function(resource) | |
2135 { | |
2136 // inline function to render a resource attribute | |
2137 function render_attrib(value) { | |
2138 if (typeof value == 'boolean') { | |
2139 return value ? rcmail.get_label('yes') : rcmail.get_label('no'); | |
2140 } | |
2141 | |
2142 return value; | |
2143 } | |
2144 | |
2145 if (rcmail.gui_objects.resourceinfo) { | |
2146 var tr, table = $(rcmail.gui_objects.resourceinfo).show().find('tbody').html(''), | |
2147 attribs = $.extend({ name:resource.name }, resource.attributes||{}) | |
2148 attribs.description = resource.description; | |
2149 | |
2150 for (var k in attribs) { | |
2151 if (typeof attribs[k] == 'undefined') | |
2152 continue; | |
2153 table.append($('<tr>').addClass(k) | |
2154 .append('<td class="title">' + Q(ucfirst(rcmail.get_label(k, 'calendar'))) + '</td>') | |
2155 .append('<td class="value">' + text2html(render_attrib(attribs[k])) + '</td>') | |
2156 ); | |
2157 } | |
2158 | |
2159 $(rcmail.gui_objects.resourceownerinfo).hide(); | |
2160 $(rcmail.gui_objects.resourceinfocalendar).fullCalendar('removeEventSource', resources_events_source); | |
2161 | |
2162 if (resource.owner) { | |
2163 // display cached data | |
2164 if (resource_owners[resource.owner]) { | |
2165 resource_owner_load(resource_owners[resource.owner]); | |
2166 } | |
2167 else { | |
2168 // fetch owner data from server | |
2169 me.loading_lock = rcmail.set_busy(true, 'loading', me.loading_lock); | |
2170 rcmail.http_request('resources-owner', { _id: resource.owner }, me.loading_lock); | |
2171 } | |
2172 } | |
2173 | |
2174 // load resource calendar | |
2175 resources_events_source.url = "./?_task=calendar&_action=resources-calendar&_id="+urlencode(resource.ID); | |
2176 $(rcmail.gui_objects.resourceinfocalendar).fullCalendar('addEventSource', resources_events_source); | |
2177 } | |
2178 }; | |
2179 | |
2180 // callback from server for resource listing | |
2181 var resource_data_load = function(data) | |
2182 { | |
2183 var resources_tree = {}; | |
2184 | |
2185 // store data by ID | |
2186 $.each(data, function(i, rec) { | |
2187 resources_data[rec.ID] = rec; | |
2188 | |
2189 // assign parent-relations | |
2190 if (rec.members) { | |
2191 $.each(rec.members, function(j, m){ | |
2192 resources_tree[m] = rec.ID; | |
2193 }); | |
2194 } | |
2195 }); | |
2196 | |
2197 // walk the parent-child tree to determine the depth of each node | |
2198 $.each(data, function(i, rec) { | |
2199 rec._depth = 0; | |
2200 if (resources_tree[rec.ID]) | |
2201 rec.parent_id = resources_tree[rec.ID]; | |
2202 | |
2203 var parent_id = resources_tree[rec.ID]; | |
2204 while (parent_id) { | |
2205 rec._depth++; | |
2206 parent_id = resources_tree[parent_id]; | |
2207 } | |
2208 }); | |
2209 | |
2210 // sort by depth, collection and name | |
2211 data.sort(function(a,b) { | |
2212 var j = a._type == 'collection' ? 1 : 0, | |
2213 k = b._type == 'collection' ? 1 : 0, | |
2214 d = a._depth - b._depth; | |
2215 if (!d) d = (k - j); | |
2216 if (!d) d = b.name < a.name ? 1 : -1; | |
2217 return d; | |
2218 }); | |
2219 | |
2220 $.each(data, function(i, rec) { | |
2221 resources_index.push(rec.ID); | |
2222 }); | |
2223 | |
2224 // apply search filter... | |
2225 if ($('#resourcesearchbox').val() != '') | |
2226 resource_search(); | |
2227 else // ...or render full list | |
2228 resource_render_list(resources_index); | |
2229 | |
2230 rcmail.set_busy(false, null, me.loading_lock); | |
2231 }; | |
2232 | |
2233 // renders the given list of resource records into the treelist | |
2234 var resource_render_list = function(index) { | |
2235 var rec, link; | |
2236 | |
2237 resources_treelist.reset(); | |
2238 | |
2239 $.each(index, function(i, dn) { | |
2240 if (rec = resources_data[dn]) { | |
2241 link = $('<a>').attr('href', '#') | |
2242 .attr('rel', rec.ID) | |
2243 .html(Q(rec.name)); | |
2244 | |
2245 resources_treelist.insert({ id:rec.ID, html:link, classes:[rec._type], collapsed:true }, rec.parent_id, false); | |
2246 } | |
2247 }); | |
2248 }; | |
2249 | |
2250 // callback from server for owner information display | |
2251 var resource_owner_load = function(data) | |
2252 { | |
2253 if (data) { | |
2254 // cache this! | |
2255 resource_owners[data.ID] = data; | |
2256 | |
2257 var table = $(rcmail.gui_objects.resourceownerinfo).find('tbody').html(''); | |
2258 | |
2259 for (var k in data) { | |
2260 if (k == 'event' || k == 'ID') | |
2261 continue; | |
2262 | |
2263 table.append($('<tr>').addClass(k) | |
2264 .append('<td class="title">' + Q(ucfirst(rcmail.get_label(k, 'calendar'))) + '</td>') | |
2265 .append('<td class="value">' + text2html(data[k]) + '</td>') | |
2266 ); | |
2267 } | |
2268 | |
2269 table.parent().show(); | |
2270 } | |
2271 } | |
2272 | |
2273 // quick-filter the loaded resource data | |
2274 var resource_search = function() | |
2275 { | |
2276 var dn, rec, dataset = [], | |
2277 q = $('#resourcesearchbox').val().toLowerCase(); | |
2278 | |
2279 if (q.length && resources_data) { | |
2280 // search by iterating over all resource records | |
2281 for (dn in resources_data) { | |
2282 rec = resources_data[dn]; | |
2283 if ((rec.name && String(rec.name).toLowerCase().indexOf(q) >= 0) | |
2284 || (rec.email && String(rec.email).toLowerCase().indexOf(q) >= 0) | |
2285 || (rec.description && String(rec.description).toLowerCase().indexOf(q) >= 0) | |
2286 ) { | |
2287 dataset.push(rec.ID); | |
2288 } | |
2289 } | |
2290 | |
2291 resource_render_list(dataset); | |
2292 | |
2293 // select single match | |
2294 if (dataset.length == 1) { | |
2295 resources_treelist.select(dataset[0]); | |
2296 } | |
2297 } | |
2298 else { | |
2299 $('#resourcesearchbox').val(''); | |
2300 } | |
2301 }; | |
2302 | |
2303 // | |
2304 var reset_resource_search = function() | |
2305 { | |
2306 $('#resourcesearchbox').val('').focus(); | |
2307 resource_render_list(resources_index); | |
2308 }; | |
2309 | |
2310 // | |
2311 var add_resource2event = function() | |
2312 { | |
2313 var resource = resources_data[resources_treelist.get_selection()]; | |
2314 if (resource) { | |
2315 if (add_attendee($.extend({ role:'REQ-PARTICIPANT', status:'NEEDS-ACTION', cutype:'RESOURCE' }, resource))) | |
2316 rcmail.display_message(rcmail.get_label('resourceadded', 'calendar'), 'confirmation'); | |
2317 } | |
2318 } | |
2319 | |
2320 // when the user accepts or declines an event invitation | |
2321 var event_rsvp = function(response, delegate, replymode) | |
2322 { | |
2323 var btn; | |
2324 if (typeof response == 'object') { | |
2325 btn = $(response); | |
2326 response = btn.attr('rel') | |
2327 } | |
2328 else { | |
2329 btn = $('#event-rsvp input.button[rel='+response+']'); | |
2330 } | |
2331 | |
2332 // show menu to select rsvp reply mode (current or all) | |
2333 if (me.selected_event && me.selected_event.recurrence && !replymode) { | |
2334 rcube_libcalendaring.itip_rsvp_recurring(btn, function(resp, mode) { | |
2335 event_rsvp(resp, null, mode); | |
2336 }); | |
2337 return; | |
2338 } | |
2339 | |
2340 if (me.selected_event && me.selected_event.attendees && response) { | |
2341 // bring up delegation dialog | |
2342 if (response == 'delegated' && !delegate) { | |
2343 rcube_libcalendaring.itip_delegate_dialog(function(data) { | |
2344 data.rsvp = data.rsvp ? 1 : ''; | |
2345 event_rsvp('delegated', data, replymode); | |
2346 }); | |
2347 return; | |
2348 } | |
2349 | |
2350 // update attendee status | |
2351 attendees = []; | |
2352 for (var data, i=0; i < me.selected_event.attendees.length; i++) { | |
2353 data = me.selected_event.attendees[i]; | |
2354 if (settings.identity.emails.indexOf(';'+String(data.email).toLowerCase()) >= 0) { | |
2355 data.status = response.toUpperCase(); | |
2356 data.rsvp = 0; // unset RSVP flag | |
2357 | |
2358 if (data.status == 'DELEGATED') { | |
2359 data['delegated-to'] = delegate.to; | |
2360 data.rsvp = delegate.rsvp | |
2361 } | |
2362 else { | |
2363 if (data['delegated-to']) { | |
2364 delete data['delegated-to']; | |
2365 if (data.role == 'NON-PARTICIPANT' && data.status != 'DECLINED') | |
2366 data.role = 'REQ-PARTICIPANT'; | |
2367 } | |
2368 } | |
2369 | |
2370 attendees.push(i) | |
2371 } | |
2372 else if (response != 'DELEGATED' && data['delegated-from'] && | |
2373 settings.identity.emails.indexOf(';'+String(data['delegated-from']).toLowerCase()) >= 0) { | |
2374 delete data['delegated-from']; | |
2375 } | |
2376 | |
2377 // set free_busy status to transparent if declined (#4425) | |
2378 if (data.status == 'DECLINED' || data.role == 'NON-PARTICIPANT') { | |
2379 me.selected_event.free_busy = 'free'; | |
2380 } | |
2381 else { | |
2382 me.selected_event.free_busy = 'busy'; | |
2383 } | |
2384 } | |
2385 | |
2386 // submit status change to server | |
2387 var submit_data = $.extend({}, me.selected_event, { source:null, comment:$('#reply-comment-event-rsvp').val(), _savemode: replymode || 'all' }, (delegate || {})), | |
2388 noreply = $('#noreply-event-rsvp:checked').length ? 1 : 0; | |
2389 | |
2390 // import event from mail (temporary iTip event) | |
2391 if (submit_data._mbox && submit_data._uid) { | |
2392 me.saving_lock = rcmail.set_busy(true, 'calendar.savingdata'); | |
2393 rcmail.http_post('mailimportitip', { | |
2394 _mbox: submit_data._mbox, | |
2395 _uid: submit_data._uid, | |
2396 _part: submit_data._part, | |
2397 _status: response, | |
2398 _to: (delegate ? delegate.to : null), | |
2399 _rsvp: (delegate && delegate.rsvp) ? 1 : 0, | |
2400 _noreply: noreply, | |
2401 _comment: submit_data.comment, | |
2402 _instance: submit_data._instance, | |
2403 _savemode: submit_data._savemode | |
2404 }); | |
2405 } | |
2406 else if (settings.invitation_calendars) { | |
2407 update_event('rsvp', submit_data, { status:response, noreply:noreply, attendees:attendees }); | |
2408 } | |
2409 else { | |
2410 me.saving_lock = rcmail.set_busy(true, 'calendar.savingdata'); | |
2411 rcmail.http_post('event', { action:'rsvp', e:submit_data, status:response, attendees:attendees, noreply:noreply }); | |
2412 } | |
2413 | |
2414 event_show_dialog(me.selected_event); | |
2415 } | |
2416 }; | |
2417 | |
2418 // add the given date to the RDATE list | |
2419 var add_rdate = function(date) | |
2420 { | |
2421 var li = $('<li>') | |
2422 .attr('data-value', date2servertime(date)) | |
2423 .html('<span>' + Q($.fullCalendar.formatDate(date, settings['date_format'])) + '</span>') | |
2424 .appendTo('#edit-recurrence-rdates'); | |
2425 | |
2426 $('<a>').attr('href', '#del') | |
2427 .addClass('iconbutton delete') | |
2428 .html(rcmail.get_label('delete', 'calendar')) | |
2429 .attr('title', rcmail.get_label('delete', 'calendar')) | |
2430 .appendTo(li); | |
2431 }; | |
2432 | |
2433 // re-sort the list items by their 'data-value' attribute | |
2434 var sort_rdates = function() | |
2435 { | |
2436 var mylist = $('#edit-recurrence-rdates'), | |
2437 listitems = mylist.children('li').get(); | |
2438 listitems.sort(function(a, b) { | |
2439 var compA = $(a).attr('data-value'); | |
2440 var compB = $(b).attr('data-value'); | |
2441 return (compA < compB) ? -1 : (compA > compB) ? 1 : 0; | |
2442 }) | |
2443 $.each(listitems, function(idx, item) { mylist.append(item); }); | |
2444 } | |
2445 | |
2446 // remove the link reference matching the given uri | |
2447 function remove_link(elem) | |
2448 { | |
2449 var $elem = $(elem), uri = $elem.attr('data-uri'); | |
2450 | |
2451 me.selected_event.links = $.grep(me.selected_event.links, function(link) { return link.uri != uri; }); | |
2452 | |
2453 // remove UI list item | |
2454 $elem.hide().closest('li').addClass('deleted'); | |
2455 } | |
2456 | |
2457 // post the given event data to server | |
2458 var update_event = function(action, data, add) | |
2459 { | |
2460 me.saving_lock = rcmail.set_busy(true, 'calendar.savingdata'); | |
2461 rcmail.http_post('calendar/event', $.extend({ action:action, e:data }, (add || {}))); | |
2462 | |
2463 // render event temporarily into the calendar | |
2464 if ((data.start && data.end) || data.id) { | |
2465 var event = data.id ? $.extend(fc.fullCalendar('clientEvents', function(e){ return e.id == data.id; })[0], data) : data; | |
2466 if (data.start) | |
2467 event.start = data.start; | |
2468 if (data.end) | |
2469 event.end = data.end; | |
2470 if (data.allday !== undefined) | |
2471 event.allDay = data.allday; | |
2472 event.editable = false; | |
2473 event.temp = true; | |
2474 event.className = 'fc-event-cal-'+data.calendar+' fc-event-temp'; | |
2475 fc.fullCalendar(data.id ? 'updateEvent' : 'renderEvent', event); | |
2476 | |
2477 // mark all recurring instances as temp | |
2478 if (event.recurrence || event.recurrence_id) { | |
2479 var base_id = event.recurrence_id ? event.recurrence_id : String(event.id).replace(/-\d+(T\d{6})?$/, ''); | |
2480 $.each(fc.fullCalendar('clientEvents', function(e){ return e.id == base_id || e.recurrence_id == base_id; }), function(i,ev) { | |
2481 ev.temp = true; | |
2482 ev.editable = false; | |
2483 event.className += ' fc-event-temp'; | |
2484 fc.fullCalendar('updateEvent', ev); | |
2485 }); | |
2486 } | |
2487 } | |
2488 }; | |
2489 | |
2490 // mouse-click handler to check if the show dialog is still open and prevent default action | |
2491 var dialog_check = function(e) | |
2492 { | |
2493 var showd = $("#eventshow"); | |
2494 if (showd.is(':visible') && !$(e.target).closest('.ui-dialog').length && !$(e.target).closest('.popupmenu').length) { | |
2495 showd.dialog('close'); | |
2496 e.stopImmediatePropagation(); | |
2497 ignore_click = true; | |
2498 return false; | |
2499 } | |
2500 else if (ignore_click) { | |
2501 window.setTimeout(function(){ ignore_click = false; }, 20); | |
2502 return false; | |
2503 } | |
2504 return true; | |
2505 }; | |
2506 | |
2507 // display confirm dialog when modifying/deleting an event | |
2508 var update_event_confirm = function(action, event, data) | |
2509 { | |
2510 // Allow other plugins to do actions here | |
2511 // E.g. when you move/resize the event init wasn't called | |
2512 // but we need it as some plugins may modify user identities | |
2513 // we depend on here (kolab_delegation) | |
2514 rcmail.triggerEvent('calendar-event-init', {o: event}); | |
2515 | |
2516 if (!data) data = event; | |
2517 var decline = false, notify = false, html = '', cal = me.calendars[event.calendar], | |
2518 _has_attendees = me.has_attendees(event), | |
2519 _is_attendee = _has_attendees && me.is_attendee(event), | |
2520 _is_organizer = me.is_organizer(event); | |
2521 | |
2522 // event has attendees, ask whether to notify them | |
2523 if (_has_attendees) { | |
2524 var checked = (settings.itip_notify & 1 ? ' checked="checked"' : ''); | |
2525 | |
2526 if (action == 'remove' && cal.group != 'shared' && !_is_organizer && _is_attendee) { | |
2527 decline = true; | |
2528 checked = event.status != 'CANCELLED' ? checked : ''; | |
2529 html += '<div class="message">' + | |
2530 '<label><input class="confirm-attendees-decline" type="checkbox"' + checked + ' value="1" name="decline" /> ' + | |
2531 rcmail.gettext('itipdeclineevent', 'calendar') + | |
2532 '</label></div>'; | |
2533 } | |
2534 else if (_is_organizer) { | |
2535 notify = true; | |
2536 if (settings.itip_notify & 2) { | |
2537 html += '<div class="message">' + | |
2538 '<label><input class="confirm-attendees-donotify" type="checkbox"' + checked + ' value="1" name="notify" /> ' + | |
2539 rcmail.gettext((action == 'remove' ? 'sendcancellation' : 'sendnotifications'), 'calendar') + | |
2540 '</label></div>'; | |
2541 } | |
2542 else { | |
2543 data._notify = settings.itip_notify; | |
2544 } | |
2545 } | |
2546 } | |
2547 | |
2548 // recurring event: user needs to select the savemode | |
2549 if (event.recurrence) { | |
2550 var future_disabled = '', message_label = (action == 'remove' ? 'removerecurringeventwarning' : 'changerecurringeventwarning'); | |
2551 | |
2552 // disable the 'future' savemode if I'm an attendee | |
2553 // reason: no calendaring system supports the thisandfuture range parameter in iTip REPLY | |
2554 if (action == 'remove' && !_is_organizer && _is_attendee) { | |
2555 future_disabled = ' disabled'; | |
2556 } | |
2557 | |
2558 html += '<div class="message"><span class="ui-icon ui-icon-alert"></span>' + | |
2559 rcmail.gettext(message_label, 'calendar') + '</div>' + | |
2560 '<div class="savemode">' + | |
2561 '<a href="#current" class="button">' + rcmail.gettext('currentevent', 'calendar') + '</a>' + | |
2562 '<a href="#future" class="button' + future_disabled + '">' + rcmail.gettext('futurevents', 'calendar') + '</a>' + | |
2563 '<a href="#all" class="button">' + rcmail.gettext('allevents', 'calendar') + '</a>' + | |
2564 (action != 'remove' ? '<a href="#new" class="button">' + rcmail.gettext('saveasnew', 'calendar') + '</a>' : '') + | |
2565 '</div>'; | |
2566 } | |
2567 | |
2568 // show dialog | |
2569 if (html) { | |
2570 var $dialog = $('<div>').html(html); | |
2571 | |
2572 $dialog.find('a.button').button().filter(':not(.disabled)').click(function(e) { | |
2573 data._savemode = String(this.href).replace(/.+#/, ''); | |
2574 data._notify = settings.itip_notify; | |
2575 | |
2576 // open event edit dialog when saving as new | |
2577 if (data._savemode == 'new') { | |
2578 event._savemode = 'new'; | |
2579 event_edit_dialog('edit', event); | |
2580 fc.fullCalendar('refetchEvents'); | |
2581 } | |
2582 else { | |
2583 if ($dialog.find('input.confirm-attendees-donotify').length) | |
2584 data._notify = $dialog.find('input.confirm-attendees-donotify').get(0).checked ? 1 : 0; | |
2585 if (decline) { | |
2586 data._decline = $dialog.find('input.confirm-attendees-decline:checked').length; | |
2587 data._notify = 0; | |
2588 } | |
2589 update_event(action, data); | |
2590 } | |
2591 | |
2592 $dialog.dialog("close"); | |
2593 return false; | |
2594 }); | |
2595 | |
2596 var buttons = []; | |
2597 | |
2598 if (!event.recurrence) { | |
2599 buttons.push({ | |
2600 text: rcmail.gettext((action == 'remove' ? 'delete' : 'save'), 'calendar'), | |
2601 click: function() { | |
2602 data._notify = notify && $dialog.find('input.confirm-attendees-donotify:checked').length ? 1 : 0; | |
2603 data._decline = decline && $dialog.find('input.confirm-attendees-decline:checked').length ? 1 : 0; | |
2604 update_event(action, data); | |
2605 $(this).dialog("close"); | |
2606 } | |
2607 }); | |
2608 } | |
2609 | |
2610 buttons.push({ | |
2611 text: rcmail.gettext('cancel', 'calendar'), | |
2612 click: function() { | |
2613 $(this).dialog("close"); | |
2614 } | |
2615 }); | |
2616 | |
2617 $dialog.dialog({ | |
2618 modal: true, | |
2619 width: 460, | |
2620 dialogClass: 'warning', | |
2621 title: rcmail.gettext((action == 'remove' ? 'removeeventconfirm' : 'changeeventconfirm'), 'calendar'), | |
2622 buttons: buttons, | |
2623 open: function() { | |
2624 setTimeout(function(){ | |
2625 $dialog.parent().find('.ui-button:not(.ui-dialog-titlebar-close)').first().focus(); | |
2626 }, 5); | |
2627 }, | |
2628 close: function(){ | |
2629 $dialog.dialog("destroy").remove(); | |
2630 if (!rcmail.busy) | |
2631 fc.fullCalendar('refetchEvents'); | |
2632 } | |
2633 }).addClass('event-update-confirm').show(); | |
2634 | |
2635 return false; | |
2636 } | |
2637 // show regular confirm box when deleting | |
2638 else if (action == 'remove' && !cal.undelete) { | |
2639 if (!confirm(rcmail.gettext('deleteventconfirm', 'calendar'))) | |
2640 return false; | |
2641 } | |
2642 | |
2643 // do update | |
2644 update_event(action, data); | |
2645 | |
2646 return true; | |
2647 }; | |
2648 | |
2649 var update_agenda_toolbar = function() | |
2650 { | |
2651 $('#agenda-listrange').val(fc.fullCalendar('option', 'listRange')); | |
2652 $('#agenda-listsections').val(fc.fullCalendar('option', 'listSections')); | |
2653 } | |
2654 | |
2655 | |
2656 /*** public methods ***/ | |
2657 | |
2658 /** | |
2659 * Remove saving lock and free the UI for new input | |
2660 */ | |
2661 this.unlock_saving = function() | |
2662 { | |
2663 if (me.saving_lock) | |
2664 rcmail.set_busy(false, null, me.saving_lock); | |
2665 }; | |
2666 | |
2667 // opens calendar day-view in a popup | |
2668 this.fisheye_view = function(date) | |
2669 { | |
2670 $('#fish-eye-view:ui-dialog').dialog('close'); | |
2671 | |
2672 // create list of active event sources | |
2673 var src, cals = {}, sources = []; | |
2674 for (var id in this.calendars) { | |
2675 src = $.extend({}, this.calendars[id]); | |
2676 src.editable = false; | |
2677 src.url = null; | |
2678 src.events = []; | |
2679 | |
2680 if (src.active) { | |
2681 cals[id] = src; | |
2682 sources.push(src); | |
2683 } | |
2684 } | |
2685 | |
2686 // copy events already loaded | |
2687 var events = fc.fullCalendar('clientEvents'); | |
2688 for (var event, i=0; i< events.length; i++) { | |
2689 event = events[i]; | |
2690 if (event.source && (src = cals[event.source.id])) { | |
2691 src.events.push(event); | |
2692 } | |
2693 } | |
2694 | |
2695 var h = $(window).height() - 50; | |
2696 var dialog = $('<div>') | |
2697 .attr('id', 'fish-eye-view') | |
2698 .dialog({ | |
2699 modal: true, | |
2700 width: 680, | |
2701 height: h, | |
2702 title: $.fullCalendar.formatDate(date, 'dddd ' + settings['date_long']), | |
2703 close: function(){ | |
2704 dialog.dialog("destroy"); | |
2705 me.fisheye_date = null; | |
2706 } | |
2707 }) | |
2708 .fullCalendar($.extend({}, fullcalendar_defaults, { | |
2709 defaultView: 'agendaDay', | |
2710 header: { left: '', center: '', right: '' }, | |
2711 height: h - 50, | |
2712 date: date.getDate(), | |
2713 month: date.getMonth(), | |
2714 year: date.getFullYear(), | |
2715 eventSources: sources | |
2716 })); | |
2717 | |
2718 this.fisheye_date = date; | |
2719 }; | |
2720 | |
2721 // opens the given calendar in a popup dialog | |
2722 this.quickview = function(id, shift) | |
2723 { | |
2724 var src, in_quickview = false; | |
2725 $.each(this.quickview_sources, function(i,cal) { | |
2726 if (cal.id == id) { | |
2727 in_quickview = true; | |
2728 src = cal; | |
2729 } | |
2730 }); | |
2731 | |
2732 // remove source from quickview | |
2733 if (in_quickview && shift) { | |
2734 this.quickview_sources = $.grep(this.quickview_sources, function(src) { return src.id != id; }); | |
2735 } | |
2736 else { | |
2737 if (!shift) { | |
2738 // remove all current quickview event sources | |
2739 if (this.quickview_active) { | |
2740 fc.fullCalendar('removeEventSources'); | |
2741 } | |
2742 | |
2743 this.quickview_sources = []; | |
2744 | |
2745 // uncheck all active quickview icons | |
2746 calendars_list.container.find('div.focusview') | |
2747 .add('#calendars .searchresults div.focusview') | |
2748 .removeClass('focusview') | |
2749 .find('a.quickview').attr('aria-checked', 'false'); | |
2750 } | |
2751 | |
2752 if (!in_quickview) { | |
2753 // clone and modify calendar properties | |
2754 src = $.extend({}, this.calendars[id]); | |
2755 src.url += '&_quickview=1'; | |
2756 this.quickview_sources.push(src); | |
2757 } | |
2758 } | |
2759 | |
2760 // disable quickview | |
2761 if (this.quickview_active && !this.quickview_sources.length) { | |
2762 // register regular calendar event sources | |
2763 $.each(this.calendars, function(k, cal) { | |
2764 if (cal.active) | |
2765 fc.fullCalendar('addEventSource', cal); | |
2766 }); | |
2767 | |
2768 this.quickview_active = false; | |
2769 $('body').removeClass('quickview-active'); | |
2770 | |
2771 // uncheck all active quickview icons | |
2772 calendars_list.container.find('div.focusview') | |
2773 .add('#calendars .searchresults div.focusview') | |
2774 .removeClass('focusview') | |
2775 .find('a.quickview').attr('aria-checked', 'false'); | |
2776 } | |
2777 // activate quickview | |
2778 else if (!this.quickview_active) { | |
2779 // remove regular calendar event sources | |
2780 fc.fullCalendar('removeEventSources'); | |
2781 | |
2782 // register quickview event sources | |
2783 $.each(this.quickview_sources, function(i, src) { | |
2784 fc.fullCalendar('addEventSource', src); | |
2785 }); | |
2786 | |
2787 this.quickview_active = true; | |
2788 $('body').addClass('quickview-active'); | |
2789 } | |
2790 // update quickview sources | |
2791 else if (in_quickview) { | |
2792 fc.fullCalendar('removeEventSource', src); | |
2793 } | |
2794 else if (src) { | |
2795 fc.fullCalendar('addEventSource', src); | |
2796 } | |
2797 | |
2798 // activate quickview icon | |
2799 if (this.quickview_active) { | |
2800 $(calendars_list.get_item(id)).find('.calendar').first() | |
2801 .add('#calendars .searchresults .cal-' + id) | |
2802 [in_quickview ? 'removeClass' : 'addClass']('focusview') | |
2803 .find('a.quickview').attr('aria-checked', in_quickview ? 'false' : 'true'); | |
2804 } | |
2805 }; | |
2806 | |
2807 // disable quickview mode | |
2808 function reset_quickview() | |
2809 { | |
2810 // remove all current quickview event sources | |
2811 if (me.quickview_active) { | |
2812 fc.fullCalendar('removeEventSources'); | |
2813 me.quickview_sources = []; | |
2814 } | |
2815 | |
2816 // register regular calendar event sources | |
2817 $.each(me.calendars, function(k, cal) { | |
2818 if (cal.active) | |
2819 fc.fullCalendar('addEventSource', cal); | |
2820 }); | |
2821 | |
2822 // uncheck all active quickview icons | |
2823 calendars_list.container.find('div.focusview') | |
2824 .add('#calendars .searchresults div.focusview') | |
2825 .removeClass('focusview') | |
2826 .find('a.quickview').attr('aria-checked', 'false'); | |
2827 | |
2828 me.quickview_active = false; | |
2829 $('body').removeClass('quickview-active'); | |
2830 }; | |
2831 | |
2832 //public method to show the print dialog. | |
2833 this.print_calendars = function(view) | |
2834 { | |
2835 if (!view) view = fc.fullCalendar('getView').name; | |
2836 var date = fc.fullCalendar('getDate') || new Date(); | |
2837 var range = fc.fullCalendar('option', 'listRange'); | |
2838 var sections = fc.fullCalendar('option', 'listSections'); | |
2839 rcmail.open_window(rcmail.url('print', { view: view, date: date2unixtime(date), range: range, sections: sections, search: this.search_query }), true, true); | |
2840 }; | |
2841 | |
2842 // public method to bring up the new event dialog | |
2843 this.add_event = function(templ) { | |
2844 if (this.selected_calendar) { | |
2845 var now = new Date(); | |
2846 var date = fc.fullCalendar('getDate'); | |
2847 if (typeof date != 'Date') | |
2848 date = now; | |
2849 date.setHours(now.getHours()+1); | |
2850 date.setMinutes(0); | |
2851 var end = new Date(date.getTime()); | |
2852 end.setHours(date.getHours()+1); | |
2853 event_edit_dialog('new', $.extend({ start:date, end:end, allDay:false, calendar:this.selected_calendar }, templ || {})); | |
2854 } | |
2855 }; | |
2856 | |
2857 // delete the given event after showing a confirmation dialog | |
2858 this.delete_event = function(event) { | |
2859 // show confirm dialog for recurring events, use jquery UI dialog | |
2860 return update_event_confirm('remove', event, { id:event.id, calendar:event.calendar, attendees:event.attendees }); | |
2861 }; | |
2862 | |
2863 // opens a jquery UI dialog with event properties (or empty for creating a new calendar) | |
2864 this.calendar_edit_dialog = function(calendar) | |
2865 { | |
2866 // close show dialog first | |
2867 var $dialog = $("#calendarform"); | |
2868 if ($dialog.is(':ui-dialog')) | |
2869 $dialog.dialog('close'); | |
2870 | |
2871 if (!calendar) | |
2872 calendar = { name:'', color:'cc0000', editable:true, showalarms:true }; | |
2873 | |
2874 var form, name, color, alarms; | |
2875 | |
2876 $dialog.html(rcmail.get_label('loading')); | |
2877 $.ajax({ | |
2878 type: 'GET', | |
2879 dataType: 'html', | |
2880 url: rcmail.url('calendar'), | |
2881 data: { action:(calendar.id ? 'form-edit' : 'form-new'), c:{ id:calendar.id } }, | |
2882 success: function(data) { | |
2883 $dialog.html(data); | |
2884 // resize and reposition dialog window | |
2885 form = $('#calendarpropform'); | |
2886 me.dialog_resize('#calendarform', form.height(), form.width()); | |
2887 name = $('#calendar-name').prop('disabled', !calendar.editable).val(calendar.editname || calendar.name); | |
2888 color = $('#calendar-color').val(calendar.color).miniColors({ value: calendar.color, colorValues:rcmail.env.mscolors }); | |
2889 alarms = $('#calendar-showalarms').prop('checked', calendar.showalarms).get(0); | |
2890 name.select(); | |
2891 } | |
2892 }); | |
2893 | |
2894 // dialog buttons | |
2895 var buttons = {}; | |
2896 | |
2897 buttons[rcmail.gettext('save', 'calendar')] = function() { | |
2898 // form is not loaded | |
2899 if (!form || !form.length) | |
2900 return; | |
2901 | |
2902 // TODO: do some input validation | |
2903 if (!name.val() || name.val().length < 2) { | |
2904 alert(rcmail.gettext('invalidcalendarproperties', 'calendar')); | |
2905 name.select(); | |
2906 return; | |
2907 } | |
2908 | |
2909 // post data to server | |
2910 var data = form.serializeJSON(); | |
2911 if (data.color) | |
2912 data.color = data.color.replace(/^#/, ''); | |
2913 if (calendar.id) | |
2914 data.id = calendar.id; | |
2915 if (alarms) | |
2916 data.showalarms = alarms.checked ? 1 : 0; | |
2917 | |
2918 me.saving_lock = rcmail.set_busy(true, 'calendar.savingdata'); | |
2919 rcmail.http_post('calendar', { action:(calendar.id ? 'edit' : 'new'), c:data }); | |
2920 $dialog.dialog("close"); | |
2921 }; | |
2922 | |
2923 buttons[rcmail.gettext('cancel', 'calendar')] = function() { | |
2924 $dialog.dialog("close"); | |
2925 }; | |
2926 | |
2927 // open jquery UI dialog | |
2928 $dialog.dialog({ | |
2929 modal: true, | |
2930 resizable: true, | |
2931 closeOnEscape: false, | |
2932 title: rcmail.gettext((calendar.id ? 'editcalendar' : 'createcalendar'), 'calendar'), | |
2933 open: function() { | |
2934 $dialog.parent().find('.ui-dialog-buttonset .ui-button').first().addClass('mainaction'); | |
2935 }, | |
2936 close: function() { | |
2937 $dialog.html('').dialog("destroy").hide(); | |
2938 }, | |
2939 buttons: buttons, | |
2940 minWidth: 400, | |
2941 width: 420 | |
2942 }).show(); | |
2943 | |
2944 }; | |
2945 | |
2946 this.calendar_remove = function(calendar) | |
2947 { | |
2948 this.calendar_destroy_source(calendar.id); | |
2949 rcmail.http_post('calendar', { action:'subscribe', c:{ id:calendar.id, active:0, permanent:0, recursive:1 } }); | |
2950 return true; | |
2951 }; | |
2952 | |
2953 this.calendar_delete = function(calendar) | |
2954 { | |
2955 if (confirm(rcmail.gettext(calendar.children ? 'deletecalendarconfirmrecursive' : 'deletecalendarconfirm', 'calendar'))) { | |
2956 rcmail.http_post('calendar', { action:'delete', c:{ id:calendar.id } }); | |
2957 return true; | |
2958 } | |
2959 return false; | |
2960 }; | |
2961 | |
2962 this.calendar_refresh_source = function(id) | |
2963 { | |
2964 // got race-conditions fc.currentFetchID when using refetchEvents, | |
2965 // so we remove and add the source instead | |
2966 // fc.fullCalendar('refetchEvents', me.calendars[id]); | |
2967 fc.fullCalendar('removeEventSource', me.calendars[id]); | |
2968 fc.fullCalendar('addEventSource', me.calendars[id]); | |
2969 }; | |
2970 | |
2971 this.calendar_destroy_source = function(id) | |
2972 { | |
2973 var delete_ids = []; | |
2974 | |
2975 if (this.calendars[id]) { | |
2976 // find sub-calendars | |
2977 if (this.calendars[id].children) { | |
2978 for (var child_id in this.calendars) { | |
2979 if (String(child_id).indexOf(id) == 0) | |
2980 delete_ids.push(child_id); | |
2981 } | |
2982 } | |
2983 else { | |
2984 delete_ids.push(id); | |
2985 } | |
2986 } | |
2987 | |
2988 // delete all calendars in the list | |
2989 for (var i=0; i < delete_ids.length; i++) { | |
2990 id = delete_ids[i]; | |
2991 calendars_list.remove(id); | |
2992 fc.fullCalendar('removeEventSource', this.calendars[id]); | |
2993 $('#edit-calendar option[value="'+id+'"]').remove(); | |
2994 delete this.calendars[id]; | |
2995 } | |
2996 }; | |
2997 | |
2998 // open a dialog to upload an .ics file with events to be imported | |
2999 this.import_events = function(calendar) | |
3000 { | |
3001 // close show dialog first | |
3002 var $dialog = $("#eventsimport"), | |
3003 form = rcmail.gui_objects.importform; | |
3004 | |
3005 if ($dialog.is(':ui-dialog')) | |
3006 $dialog.dialog('close'); | |
3007 | |
3008 if (calendar) | |
3009 $('#event-import-calendar').val(calendar.id); | |
3010 | |
3011 var buttons = {}; | |
3012 buttons[rcmail.gettext('import', 'calendar')] = function() { | |
3013 if (form && form.elements._data.value) { | |
3014 rcmail.async_upload_form(form, 'import_events', function(e) { | |
3015 rcmail.set_busy(false, null, me.saving_lock); | |
3016 $('.ui-dialog-buttonpane button', $dialog.parent()).button('enable'); | |
3017 | |
3018 // display error message if no sophisticated response from server arrived (e.g. iframe load error) | |
3019 if (me.import_succeeded === null) | |
3020 rcmail.display_message(rcmail.get_label('importerror', 'calendar'), 'error'); | |
3021 }); | |
3022 | |
3023 // display upload indicator (with extended timeout) | |
3024 var timeout = rcmail.env.request_timeout; | |
3025 rcmail.env.request_timeout = 600; | |
3026 me.import_succeeded = null; | |
3027 me.saving_lock = rcmail.set_busy(true, 'uploading'); | |
3028 $('.ui-dialog-buttonpane button', $dialog.parent()).button('disable'); | |
3029 | |
3030 // restore settings | |
3031 rcmail.env.request_timeout = timeout; | |
3032 } | |
3033 }; | |
3034 | |
3035 buttons[rcmail.gettext('cancel', 'calendar')] = function() { | |
3036 $dialog.dialog("close"); | |
3037 }; | |
3038 | |
3039 // open jquery UI dialog | |
3040 $dialog.dialog({ | |
3041 modal: true, | |
3042 resizable: false, | |
3043 closeOnEscape: false, | |
3044 title: rcmail.gettext('importevents', 'calendar'), | |
3045 open: function() { | |
3046 $dialog.parent().find('.ui-dialog-buttonset .ui-button').first().addClass('mainaction'); | |
3047 }, | |
3048 close: function() { | |
3049 $('.ui-dialog-buttonpane button', $dialog.parent()).button('enable'); | |
3050 $dialog.dialog("destroy").hide(); | |
3051 }, | |
3052 buttons: buttons, | |
3053 width: 520 | |
3054 }).show(); | |
3055 }; | |
3056 | |
3057 // callback from server if import succeeded | |
3058 this.import_success = function(p) | |
3059 { | |
3060 this.import_succeeded = true; | |
3061 $("#eventsimport:ui-dialog").dialog('close'); | |
3062 rcmail.set_busy(false, null, me.saving_lock); | |
3063 rcmail.gui_objects.importform.reset(); | |
3064 | |
3065 if (p.refetch) | |
3066 this.refresh(p); | |
3067 }; | |
3068 | |
3069 // callback from server to report errors on import | |
3070 this.import_error = function(p) | |
3071 { | |
3072 this.import_succeeded = false; | |
3073 rcmail.set_busy(false, null, me.saving_lock); | |
3074 rcmail.display_message(p.message || rcmail.get_label('importerror', 'calendar'), 'error'); | |
3075 } | |
3076 | |
3077 // open a dialog to select calendars for export | |
3078 this.export_events = function(calendar) | |
3079 { | |
3080 // close show dialog first | |
3081 var $dialog = $("#eventsexport"), | |
3082 form = rcmail.gui_objects.exportform; | |
3083 | |
3084 if ($dialog.is(':ui-dialog')) | |
3085 $dialog.dialog('close'); | |
3086 | |
3087 if (calendar) | |
3088 $('#event-export-calendar').val(calendar.id); | |
3089 | |
3090 $('#event-export-range').change(function(e){ | |
3091 var custom = $('option:selected', this).val() == 'custom', | |
3092 input = $('#event-export-startdate') | |
3093 input.parent()[(custom?'show':'hide')](); | |
3094 if (custom) | |
3095 input.select(); | |
3096 }) | |
3097 | |
3098 var buttons = {}; | |
3099 buttons[rcmail.gettext('export', 'calendar')] = function() { | |
3100 if (form) { | |
3101 var start = 0, range = $('#event-export-range option:selected', this).val(), | |
3102 source = $('#event-export-calendar option:selected').val(), | |
3103 attachmt = $('#event-export-attachments').get(0).checked; | |
3104 | |
3105 if (range == 'custom') | |
3106 start = date2unixtime(parse_datetime('00:00', $('#event-export-startdate').val())); | |
3107 else if (range > 0) | |
3108 start = 'today -' + range + ' months'; | |
3109 | |
3110 rcmail.goto_url('export_events', { source:source, start:start, attachments:attachmt?1:0 }); | |
3111 } | |
3112 $dialog.dialog("close"); | |
3113 }; | |
3114 | |
3115 buttons[rcmail.gettext('cancel', 'calendar')] = function() { | |
3116 $dialog.dialog("close"); | |
3117 }; | |
3118 | |
3119 // open jquery UI dialog | |
3120 $dialog.dialog({ | |
3121 modal: true, | |
3122 resizable: false, | |
3123 closeOnEscape: false, | |
3124 title: rcmail.gettext('exporttitle', 'calendar'), | |
3125 open: function() { | |
3126 $dialog.parent().find('.ui-dialog-buttonset .ui-button').first().addClass('mainaction'); | |
3127 }, | |
3128 close: function() { | |
3129 $('.ui-dialog-buttonpane button', $dialog.parent()).button('enable'); | |
3130 $dialog.dialog("destroy").hide(); | |
3131 }, | |
3132 buttons: buttons, | |
3133 width: 520 | |
3134 }).show(); | |
3135 }; | |
3136 | |
3137 // download the selected event as iCal | |
3138 this.event_download = function(event) | |
3139 { | |
3140 if (event && event.id) { | |
3141 rcmail.goto_url('export_events', { source:event.calendar, id:event.id, attachments:1 }); | |
3142 } | |
3143 }; | |
3144 | |
3145 // open the message compose step with a calendar_event parameter referencing the selected event. | |
3146 // the server-side plugin hook will pick that up and attach the event to the message. | |
3147 this.event_sendbymail = function(event, e) | |
3148 { | |
3149 if (event && event.id) { | |
3150 rcmail.command('compose', { _calendar_event:event._id }, e ? e.target : null, e); | |
3151 } | |
3152 }; | |
3153 | |
3154 // display the edit dialog, request 'new' action and pass the selected event | |
3155 this.event_copy = function(event) { | |
3156 if (event && event.id) { | |
3157 var copy = $.extend(true, {}, event); | |
3158 | |
3159 delete copy.id; | |
3160 delete copy._id; | |
3161 delete copy.created; | |
3162 delete copy.changed; | |
3163 delete copy.recurrence_id; | |
3164 delete copy.attachments; // @TODO | |
3165 | |
3166 $.each(copy.attendees, function (k, v) { | |
3167 if (v.role != 'ORGANIZER') { | |
3168 v.status = 'NEEDS-ACTION'; | |
3169 } | |
3170 }) | |
3171 | |
3172 event_edit_dialog('new', copy); | |
3173 } | |
3174 }; | |
3175 | |
3176 // show URL of the given calendar in a dialog box | |
3177 this.showurl = function(calendar) | |
3178 { | |
3179 var $dialog = $('#calendarurlbox'); | |
3180 | |
3181 if ($dialog.is(':ui-dialog')) | |
3182 $dialog.dialog('close'); | |
3183 | |
3184 if (calendar.feedurl) { | |
3185 if (calendar.caldavurl) { | |
3186 $('#caldavurl').val(calendar.caldavurl); | |
3187 $('#calendarcaldavurl').show(); | |
3188 } | |
3189 else { | |
3190 $('#calendarcaldavurl').hide(); | |
3191 } | |
3192 | |
3193 $dialog.dialog({ | |
3194 resizable: true, | |
3195 closeOnEscape: true, | |
3196 title: rcmail.gettext('showurl', 'calendar'), | |
3197 close: function() { | |
3198 $dialog.dialog("destroy").hide(); | |
3199 }, | |
3200 width: 520 | |
3201 }).show(); | |
3202 | |
3203 $('#calfeedurl').val(calendar.feedurl).select(); | |
3204 } | |
3205 }; | |
3206 | |
3207 // refresh the calendar view after saving event data | |
3208 this.refresh = function(p) | |
3209 { | |
3210 var source = me.calendars[p.source]; | |
3211 | |
3212 // helper function to update the given fullcalendar view | |
3213 function update_view(view, event, source) { | |
3214 var existing = view.fullCalendar('clientEvents', event._id); | |
3215 if (existing.length) { | |
3216 $.extend(existing[0], event); | |
3217 view.fullCalendar('updateEvent', existing[0]); | |
3218 // remove old recurrence instances | |
3219 if (event.recurrence && !event.recurrence_id) | |
3220 view.fullCalendar('removeEvents', function(e){ return e._id.indexOf(event._id+'-') == 0; }); | |
3221 } | |
3222 else { | |
3223 event.source = source; // link with source | |
3224 view.fullCalendar('renderEvent', event); | |
3225 } | |
3226 } | |
3227 | |
3228 // remove temp events | |
3229 fc.fullCalendar('removeEvents', function(e){ return e.temp; }); | |
3230 | |
3231 if (source && (p.refetch || (p.update && !source.active))) { | |
3232 // activate event source if new event was added to an invisible calendar | |
3233 if (this.quickview_active) { | |
3234 // map source to the quickview_sources equivalent | |
3235 $.each(this.quickview_sources, function(src) { | |
3236 if (src.id == source.id) { | |
3237 source = src; | |
3238 return false; | |
3239 } | |
3240 }); | |
3241 fc.fullCalendar('refetchEvents', source, true); | |
3242 } | |
3243 else if (!source.active) { | |
3244 source.active = true; | |
3245 fc.fullCalendar('addEventSource', source); | |
3246 $('#rcmlical' + source.id + ' input').prop('checked', true); | |
3247 } | |
3248 else | |
3249 fc.fullCalendar('refetchEvents', source, true); | |
3250 | |
3251 fetch_counts(); | |
3252 } | |
3253 // add/update single event object | |
3254 else if (source && p.update) { | |
3255 var event = p.update; | |
3256 event.temp = false; | |
3257 event.editable = 0; | |
3258 | |
3259 // update fish-eye view | |
3260 if (this.fisheye_date) | |
3261 update_view($('#fish-eye-view'), event, source); | |
3262 | |
3263 // update main view | |
3264 event.editable = source.editable; | |
3265 update_view(fc, event, source); | |
3266 | |
3267 // update the currently displayed event dialog | |
3268 if ($('#eventshow').is(':visible') && me.selected_event && me.selected_event.id == event.id) | |
3269 event_show_dialog(event) | |
3270 } | |
3271 // refetch all calendars | |
3272 else if (p.refetch) { | |
3273 fc.fullCalendar('refetchEvents', undefined, true); | |
3274 fetch_counts(); | |
3275 } | |
3276 }; | |
3277 | |
3278 // modify query parameters for refresh requests | |
3279 this.before_refresh = function(query) | |
3280 { | |
3281 var view = fc.fullCalendar('getView'); | |
3282 | |
3283 query.start = date2unixtime(view.visStart); | |
3284 query.end = date2unixtime(view.visEnd); | |
3285 | |
3286 if (this.search_query) | |
3287 query.q = this.search_query; | |
3288 | |
3289 return query; | |
3290 }; | |
3291 | |
3292 // callback from server providing event counts | |
3293 this.update_counts = function(p) | |
3294 { | |
3295 $.each(p.counts, function(cal, count) { | |
3296 var li = calendars_list.get_item(cal), | |
3297 bubble = $(li).children('.calendar').find('span.count'); | |
3298 | |
3299 if (!bubble.length && count > 0) { | |
3300 bubble = $('<span>') | |
3301 .addClass('count') | |
3302 .appendTo($(li).children('.calendar').first()) | |
3303 } | |
3304 | |
3305 if (count > 0) { | |
3306 bubble.text(count).show(); | |
3307 } | |
3308 else { | |
3309 bubble.text('').hide(); | |
3310 } | |
3311 }); | |
3312 }; | |
3313 | |
3314 // callback after an iTip message event was imported | |
3315 this.itip_message_processed = function(data) | |
3316 { | |
3317 // remove temporary iTip source | |
3318 fc.fullCalendar('removeEventSource', this.calendars['--invitation--itip']); | |
3319 | |
3320 $('#eventshow:ui-dialog').dialog('close'); | |
3321 this.selected_event = null; | |
3322 | |
3323 // refresh destination calendar source | |
3324 this.refresh({ source:data.calendar, refetch:true }); | |
3325 | |
3326 this.unlock_saving(); | |
3327 | |
3328 // process 'after_action' in mail task | |
3329 if (window.opener && window.opener.rcube_libcalendaring) | |
3330 window.opener.rcube_libcalendaring.itip_message_processed(data); | |
3331 }; | |
3332 | |
3333 // reload the calendar view by keeping the current date/view selection | |
3334 this.reload_view = function() | |
3335 { | |
3336 var query = { view: fc.fullCalendar('getView').name }, | |
3337 date = fc.fullCalendar('getDate'); | |
3338 if (date) | |
3339 query.date = date2unixtime(date); | |
3340 rcmail.redirect(rcmail.url('', query)); | |
3341 } | |
3342 | |
3343 // update browser location to remember current view | |
3344 this.update_state = function() | |
3345 { | |
3346 var query = { view: current_view }, | |
3347 date = fc.fullCalendar('getDate'); | |
3348 if (date) | |
3349 query.date = date2unixtime(date); | |
3350 | |
3351 if (window.history.replaceState) | |
3352 window.history.replaceState({}, document.title, rcmail.url('', query).replace('&_action=', '')); | |
3353 }; | |
3354 | |
3355 this.resource_search = resource_search; | |
3356 this.reset_resource_search = reset_resource_search; | |
3357 this.add_resource2event = add_resource2event; | |
3358 this.resource_data_load = resource_data_load; | |
3359 this.resource_owner_load = resource_owner_load; | |
3360 | |
3361 | |
3362 /*** event searching ***/ | |
3363 | |
3364 // execute search | |
3365 this.quicksearch = function() | |
3366 { | |
3367 if (rcmail.gui_objects.qsearchbox) { | |
3368 var q = rcmail.gui_objects.qsearchbox.value; | |
3369 if (q != '') { | |
3370 var id = 'search-'+q; | |
3371 var sources = []; | |
3372 | |
3373 if (me.quickview_active) | |
3374 reset_quickview(); | |
3375 | |
3376 if (this._search_message) | |
3377 rcmail.hide_message(this._search_message); | |
3378 | |
3379 for (var sid in this.calendars) { | |
3380 if (this.calendars[sid]) { | |
3381 this.calendars[sid].url = this.calendars[sid].url.replace(/&q=.+/, '') + '&q=' + urlencode(q); | |
3382 sources.push(sid); | |
3383 } | |
3384 } | |
3385 id += '@'+sources.join(','); | |
3386 | |
3387 // ignore if query didn't change | |
3388 if (this.search_request == id) { | |
3389 return; | |
3390 } | |
3391 // remember current view | |
3392 else if (!this.search_request) { | |
3393 this.default_view = fc.fullCalendar('getView').name; | |
3394 } | |
3395 | |
3396 this.search_request = id; | |
3397 this.search_query = q; | |
3398 | |
3399 // change to list view | |
3400 fc.fullCalendar('option', 'listSections', 'month') | |
3401 .fullCalendar('option', 'listRange', Math.max(60, settings['agenda_range'])) | |
3402 .fullCalendar('changeView', 'table'); | |
3403 | |
3404 update_agenda_toolbar(); | |
3405 | |
3406 // refetch events with new url (if not already triggered by changeView) | |
3407 if (!this.is_loading) | |
3408 fc.fullCalendar('refetchEvents'); | |
3409 } | |
3410 else // empty search input equals reset | |
3411 this.reset_quicksearch(); | |
3412 } | |
3413 }; | |
3414 | |
3415 // reset search and get back to normal event listing | |
3416 this.reset_quicksearch = function() | |
3417 { | |
3418 $(rcmail.gui_objects.qsearchbox).val(''); | |
3419 | |
3420 if (this._search_message) | |
3421 rcmail.hide_message(this._search_message); | |
3422 | |
3423 if (this.search_request) { | |
3424 // hide bottom links of agenda view | |
3425 fc.find('.fc-list-content > .fc-listappend').hide(); | |
3426 | |
3427 // restore original event sources and view mode from fullcalendar | |
3428 fc.fullCalendar('option', 'listSections', settings['agenda_sections']) | |
3429 .fullCalendar('option', 'listRange', settings['agenda_range']); | |
3430 | |
3431 update_agenda_toolbar(); | |
3432 | |
3433 for (var sid in this.calendars) { | |
3434 if (this.calendars[sid]) | |
3435 this.calendars[sid].url = this.calendars[sid].url.replace(/&q=.+/, ''); | |
3436 } | |
3437 if (this.default_view) | |
3438 fc.fullCalendar('changeView', this.default_view); | |
3439 | |
3440 if (!this.is_loading) | |
3441 fc.fullCalendar('refetchEvents'); | |
3442 | |
3443 this.search_request = this.search_query = null; | |
3444 } | |
3445 }; | |
3446 | |
3447 // callback if all sources have been fetched from server | |
3448 this.events_loaded = function(count) | |
3449 { | |
3450 var addlinks, append = ''; | |
3451 | |
3452 // enhance list view when searching | |
3453 if (this.search_request) { | |
3454 if (!count) { | |
3455 this._search_message = rcmail.display_message(rcmail.gettext('searchnoresults', 'calendar'), 'notice'); | |
3456 append = '<div class="message">' + rcmail.gettext('searchnoresults', 'calendar') + '</div>'; | |
3457 } | |
3458 append += '<div class="fc-bottomlinks formlinks"></div>'; | |
3459 addlinks = true; | |
3460 } | |
3461 | |
3462 if (fc.fullCalendar('getView').name == 'table') { | |
3463 var container = fc.find('.fc-list-content > .fc-listappend'); | |
3464 if (append) { | |
3465 if (!container.length) | |
3466 container = $('<div class="fc-listappend"></div>').appendTo(fc.find('.fc-list-content')); | |
3467 container.html(append).show(); | |
3468 } | |
3469 else if (container.length) | |
3470 container.hide(); | |
3471 | |
3472 // add links to adjust search date range | |
3473 if (addlinks) { | |
3474 var lc = container.find('.fc-bottomlinks'); | |
3475 $('<a>').attr('href', '#').html(rcmail.gettext('searchearlierdates', 'calendar')).appendTo(lc).click(function(){ | |
3476 fc.fullCalendar('incrementDate', 0, -1, 0); | |
3477 }); | |
3478 lc.append(" "); | |
3479 $('<a>').attr('href', '#').html(rcmail.gettext('searchlaterdates', 'calendar')).appendTo(lc).click(function(){ | |
3480 var range = fc.fullCalendar('option', 'listRange'); | |
3481 if (range < 90) { | |
3482 fc.fullCalendar('option', 'listRange', fc.fullCalendar('option', 'listRange') + 30).fullCalendar('render'); | |
3483 update_agenda_toolbar(); | |
3484 } | |
3485 else | |
3486 fc.fullCalendar('incrementDate', 0, 1, 0); | |
3487 }); | |
3488 } | |
3489 } | |
3490 | |
3491 if (this.fisheye_date) | |
3492 this.fisheye_view(this.fisheye_date); | |
3493 }; | |
3494 | |
3495 // adjust calendar view size | |
3496 this.view_resize = function() | |
3497 { | |
3498 var footer = fc.fullCalendar('getView').name == 'table' ? $('#agendaoptions').outerHeight() : 0; | |
3499 fc.fullCalendar('option', 'height', $('#calendar').height() - footer); | |
3500 }; | |
3501 | |
3502 // mark the given calendar folder as selected | |
3503 this.select_calendar = function(id, nolistupdate) | |
3504 { | |
3505 if (!nolistupdate) | |
3506 calendars_list.select(id); | |
3507 | |
3508 // trigger event hook | |
3509 rcmail.triggerEvent('selectfolder', { folder:id, prefix:'rcmlical' }); | |
3510 | |
3511 this.selected_calendar = id; | |
3512 | |
3513 rcmail.update_state({source: id}); | |
3514 }; | |
3515 | |
3516 // register the given calendar to the current view | |
3517 var add_calendar_source = function(cal) | |
3518 { | |
3519 var color, brightness, select, id = cal.id; | |
3520 | |
3521 me.calendars[id] = $.extend({ | |
3522 url: rcmail.url('calendar/load_events', { source: id }), | |
3523 className: 'fc-event-cal-'+id, | |
3524 id: id | |
3525 }, cal); | |
3526 | |
3527 // choose black text color when background is bright, white otherwise | |
3528 if (color = settings.event_coloring % 2 ? '' : '#' + cal.color) { | |
3529 if (/^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i.test(color)) { | |
3530 // use information about brightness calculation found at | |
3531 // http://javascriptrules.com/2009/08/05/css-color-brightness-contrast-using-javascript/ | |
3532 brightness = (parseInt(RegExp.$1, 16) * 299 + parseInt(RegExp.$2, 16) * 587 + parseInt(RegExp.$3, 16) * 114) / 1000; | |
3533 if (brightness > 125) | |
3534 me.calendars[id].textColor = 'black'; | |
3535 } | |
3536 | |
3537 me.calendars[id].color = color; | |
3538 } | |
3539 | |
3540 if (fc && (cal.active || cal.subscribed)) { | |
3541 if (cal.active) | |
3542 fc.fullCalendar('addEventSource', me.calendars[id]); | |
3543 | |
3544 var submit = { id: id, active: cal.active ? 1 : 0 }; | |
3545 if (cal.subscribed !== undefined) | |
3546 submit.permanent = cal.subscribed ? 1 : 0; | |
3547 rcmail.http_post('calendar', { action:'subscribe', c:submit }); | |
3548 } | |
3549 | |
3550 // insert to #calendar-select options if writeable | |
3551 select = $('#edit-calendar'); | |
3552 if (fc && me.has_permission(cal, 'i') && select.length && !select.find('option[value="'+id+'"]').length) { | |
3553 $('<option>').attr('value', id).html(cal.name).appendTo(select); | |
3554 } | |
3555 } | |
3556 | |
3557 // fetch counts for some calendars from the server | |
3558 var fetch_counts = function() | |
3559 { | |
3560 if (count_sources.length) { | |
3561 setTimeout(function() { | |
3562 rcmail.http_request('calendar/count', { source:count_sources }); | |
3563 }, 500); | |
3564 } | |
3565 }; | |
3566 | |
3567 | |
3568 /*** startup code ***/ | |
3569 | |
3570 // create list of event sources AKA calendars | |
3571 var id, cal, active, event_sources = []; | |
3572 for (id in rcmail.env.calendars) { | |
3573 cal = rcmail.env.calendars[id]; | |
3574 active = cal.active || false; | |
3575 add_calendar_source(cal); | |
3576 | |
3577 // check active calendars | |
3578 $('#rcmlical'+id+' > .calendar input').prop('checked', active); | |
3579 | |
3580 if (active) { | |
3581 event_sources.push(this.calendars[id]); | |
3582 } | |
3583 if (cal.counts) { | |
3584 count_sources.push(id); | |
3585 } | |
3586 | |
3587 if (cal.editable && !this.selected_calendar) { | |
3588 this.selected_calendar = id; | |
3589 rcmail.enable_command('addevent', true); | |
3590 } | |
3591 } | |
3592 | |
3593 // initialize treelist widget that controls the calendars list | |
3594 var widget_class = window.kolab_folderlist || rcube_treelist_widget; | |
3595 calendars_list = new widget_class(rcmail.gui_objects.calendarslist, { | |
3596 id_prefix: 'rcmlical', | |
3597 selectable: true, | |
3598 save_state: true, | |
3599 keyboard: false, | |
3600 searchbox: '#calendarlistsearch', | |
3601 search_action: 'calendar/calendar', | |
3602 search_sources: [ 'folders', 'users' ], | |
3603 search_title: rcmail.gettext('calsearchresults','calendar') | |
3604 }); | |
3605 calendars_list.addEventListener('select', function(node) { | |
3606 if (node && node.id && me.calendars[node.id]) { | |
3607 me.select_calendar(node.id, true); | |
3608 rcmail.enable_command('calendar-edit', 'calendar-showurl', true); | |
3609 rcmail.enable_command('calendar-delete', me.calendars[node.id].editable); | |
3610 rcmail.enable_command('calendar-remove', me.calendars[node.id] && me.calendars[node.id].removable); | |
3611 } | |
3612 }); | |
3613 calendars_list.addEventListener('insert-item', function(p) { | |
3614 var cal = p.data; | |
3615 if (cal && cal.id) { | |
3616 add_calendar_source(cal); | |
3617 | |
3618 // add css classes related to this calendar to document | |
3619 if (cal.css) { | |
3620 $('<style type="text/css"></style>') | |
3621 .html(cal.css) | |
3622 .appendTo('head'); | |
3623 } | |
3624 } | |
3625 }); | |
3626 calendars_list.addEventListener('subscribe', function(p) { | |
3627 var cal; | |
3628 if ((cal = me.calendars[p.id])) { | |
3629 cal.subscribed = p.subscribed || false; | |
3630 rcmail.http_post('calendar', { action:'subscribe', c:{ id:p.id, active:cal.active?1:0, permanent:cal.subscribed?1:0 } }); | |
3631 } | |
3632 }); | |
3633 calendars_list.addEventListener('remove', function(p) { | |
3634 if (me.calendars[p.id] && me.calendars[p.id].removable) { | |
3635 me.calendar_remove(me.calendars[p.id]); | |
3636 } | |
3637 }); | |
3638 calendars_list.addEventListener('search-complete', function(data) { | |
3639 if (data.length) | |
3640 rcmail.display_message(rcmail.gettext('nrcalendarsfound','calendar').replace('$nr', data.length), 'voice'); | |
3641 else | |
3642 rcmail.display_message(rcmail.gettext('nocalendarsfound','calendar'), 'info'); | |
3643 }); | |
3644 calendars_list.addEventListener('click-item', function(event) { | |
3645 // handle clicks on quickview icon: temprarily add this source and open in quickview | |
3646 if ($(event.target).hasClass('quickview') && event.data) { | |
3647 if (!me.calendars[event.data.id]) { | |
3648 event.data.readonly = true; | |
3649 event.data.active = false; | |
3650 event.data.subscribed = false; | |
3651 add_calendar_source(event.data); | |
3652 } | |
3653 me.quickview(event.data.id, event.shiftKey || event.metaKey || event.ctrlKey); | |
3654 return false; | |
3655 } | |
3656 }); | |
3657 | |
3658 // init (delegate) event handler on calendar list checkboxes | |
3659 $(rcmail.gui_objects.calendarslist).on('click', 'input[type=checkbox]', function(e) { | |
3660 e.stopPropagation(); | |
3661 | |
3662 if (me.quickview_active) { | |
3663 this.checked = !this.checked; | |
3664 return false; | |
3665 } | |
3666 | |
3667 var id = this.value; | |
3668 if (me.calendars[id]) { // add or remove event source on click | |
3669 var action; | |
3670 if (this.checked) { | |
3671 action = 'addEventSource'; | |
3672 me.calendars[id].active = true; | |
3673 } | |
3674 else { | |
3675 action = 'removeEventSource'; | |
3676 me.calendars[id].active = false; | |
3677 } | |
3678 | |
3679 // adjust checked state of original list item | |
3680 if (calendars_list.is_search()) { | |
3681 calendars_list.container.find('input[value="'+id+'"]').prop('checked', this.checked); | |
3682 } | |
3683 | |
3684 // add/remove event source | |
3685 fc.fullCalendar(action, me.calendars[id]); | |
3686 rcmail.http_post('calendar', { action:'subscribe', c:{ id:id, active:me.calendars[id].active?1:0 } }); | |
3687 } | |
3688 }) | |
3689 .on('keypress', 'input[type=checkbox]', function(e) { | |
3690 // select calendar on <Enter> | |
3691 if (e.keyCode == 13) { | |
3692 calendars_list.select(this.value); | |
3693 return rcube_event.cancel(e); | |
3694 } | |
3695 }) | |
3696 // init (delegate) event handler on quickview links | |
3697 .on('click', 'a.quickview', function(e) { | |
3698 var id = $(this).closest('li').attr('id').replace(/^rcmlical/, ''); | |
3699 | |
3700 if (calendars_list.is_search()) | |
3701 id = id.replace(/--xsR$/, ''); | |
3702 | |
3703 if (me.calendars[id]) | |
3704 me.quickview(id, e.shiftKey || e.metaKey || e.ctrlKey); | |
3705 | |
3706 if (!rcube_event.is_keyboard(e) && this.blur) | |
3707 this.blur(); | |
3708 | |
3709 e.stopPropagation(); | |
3710 return false; | |
3711 }); | |
3712 | |
3713 // register dbl-click handler to open calendar edit dialog | |
3714 $(rcmail.gui_objects.calendarslist).on('dblclick', ':not(.virtual) > .calname', function(e){ | |
3715 var id = $(this).closest('li').attr('id').replace(/^rcmlical/, ''); | |
3716 me.calendar_edit_dialog(me.calendars[id]); | |
3717 }); | |
3718 | |
3719 // select default calendar | |
3720 if (rcmail.env.source && this.calendars[rcmail.env.source]) | |
3721 this.selected_calendar = rcmail.env.source; | |
3722 else if (settings.default_calendar && this.calendars[settings.default_calendar] && this.calendars[settings.default_calendar].editable) | |
3723 this.selected_calendar = settings.default_calendar; | |
3724 | |
3725 if (this.selected_calendar) | |
3726 this.select_calendar(this.selected_calendar); | |
3727 | |
3728 var viewdate = new Date(); | |
3729 if (rcmail.env.date) | |
3730 viewdate.setTime(fromunixtime(rcmail.env.date)); | |
3731 | |
3732 // add source with iTip event data for rendering | |
3733 if (rcmail.env.itip_events && rcmail.env.itip_events.length) { | |
3734 me.calendars['--invitation--itip'] = { | |
3735 events: rcmail.env.itip_events, | |
3736 className: 'fc-event-cal---invitation--itip', | |
3737 color: '#fff', | |
3738 textColor: '#333', | |
3739 editable: false, | |
3740 rights: 'lrs', | |
3741 attendees: true | |
3742 }; | |
3743 event_sources.push(me.calendars['--invitation--itip']); | |
3744 } | |
3745 | |
3746 // initalize the fullCalendar plugin | |
3747 var fc = $('#calendar').fullCalendar($.extend({}, fullcalendar_defaults, { | |
3748 header: { | |
3749 right: 'prev,next today', | |
3750 center: 'title', | |
3751 left: 'agendaDay,agendaWeek,month,table' | |
3752 }, | |
3753 date: viewdate.getDate(), | |
3754 month: viewdate.getMonth(), | |
3755 year: viewdate.getFullYear(), | |
3756 height: $('#calendar').height(), | |
3757 eventSources: event_sources, | |
3758 selectable: true, | |
3759 selectHelper: false, | |
3760 loading: function(isLoading) { | |
3761 me.is_loading = isLoading; | |
3762 this._rc_loading = rcmail.set_busy(isLoading, 'loading', this._rc_loading); | |
3763 // trigger callback | |
3764 if (!isLoading) | |
3765 me.events_loaded($(this).fullCalendar('clientEvents').length); | |
3766 }, | |
3767 // callback for date range selection | |
3768 select: function(start, end, allDay, e, view) { | |
3769 var range_select = (!allDay || start.getDate() != end.getDate()) | |
3770 if (dialog_check(e) && range_select) | |
3771 event_edit_dialog('new', { start:start, end:end, allDay:allDay, calendar:me.selected_calendar }); | |
3772 if (range_select || ignore_click) | |
3773 view.calendar.unselect(); | |
3774 }, | |
3775 // callback for clicks in all-day box | |
3776 dayClick: function(date, allDay, e, view) { | |
3777 var now = new Date().getTime(); | |
3778 if (now - day_clicked_ts < 400 && day_clicked == date.getTime()) { // emulate double-click on day | |
3779 var enddate = new Date(); enddate.setTime(date.getTime() + DAY_MS - 60000); | |
3780 return event_edit_dialog('new', { start:date, end:enddate, allDay:allDay, calendar:me.selected_calendar }); | |
3781 } | |
3782 | |
3783 if (!ignore_click) { | |
3784 view.calendar.gotoDate(date); | |
3785 if (day_clicked && new Date(day_clicked).getMonth() != date.getMonth()) | |
3786 view.calendar.select(date, date, allDay); | |
3787 } | |
3788 day_clicked = date.getTime(); | |
3789 day_clicked_ts = now; | |
3790 }, | |
3791 // callback when an event was dragged and finally dropped | |
3792 eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc) { | |
3793 if (event.end == null || event.end.getTime() < event.start.getTime()) { | |
3794 event.end = new Date(event.start.getTime() + (allDay ? DAY_MS : HOUR_MS)); | |
3795 } | |
3796 // moved to all-day section: set times to 12:00 - 13:00 | |
3797 if (allDay && !event.allDay) { | |
3798 event.start.setHours(12); | |
3799 event.start.setMinutes(0); | |
3800 event.start.setSeconds(0); | |
3801 event.end.setHours(13); | |
3802 event.end.setMinutes(0); | |
3803 event.end.setSeconds(0); | |
3804 } | |
3805 // moved from all-day section: set times to working hours | |
3806 else if (event.allDay && !allDay) { | |
3807 var newstart = event.start.getTime(); | |
3808 revertFunc(); // revert to get original duration | |
3809 var numdays = Math.max(1, Math.round((event.end.getTime() - event.start.getTime()) / DAY_MS)) - 1; | |
3810 event.start = new Date(newstart); | |
3811 event.end = new Date(newstart + numdays * DAY_MS); | |
3812 event.end.setHours(settings['work_end'] || 18); | |
3813 event.end.setMinutes(0); | |
3814 | |
3815 if (event.end.getTime() < event.start.getTime()) | |
3816 event.end = new Date(newstart + HOUR_MS); | |
3817 } | |
3818 | |
3819 // send move request to server | |
3820 var data = { | |
3821 id: event.id, | |
3822 calendar: event.calendar, | |
3823 start: date2servertime(event.start), | |
3824 end: date2servertime(event.end), | |
3825 allday: allDay?1:0 | |
3826 }; | |
3827 update_event_confirm('move', event, data); | |
3828 }, | |
3829 // callback for event resizing | |
3830 eventResize: function(event, delta) { | |
3831 // sanitize event dates | |
3832 if (event.allDay) | |
3833 event.start.setHours(12); | |
3834 if (!event.end || event.end.getTime() < event.start.getTime()) | |
3835 event.end = new Date(event.start.getTime() + HOUR_MS); | |
3836 | |
3837 // send resize request to server | |
3838 var data = { | |
3839 id: event.id, | |
3840 calendar: event.calendar, | |
3841 start: date2servertime(event.start), | |
3842 end: date2servertime(event.end) | |
3843 }; | |
3844 update_event_confirm('resize', event, data); | |
3845 }, | |
3846 viewDisplay: function(view) { | |
3847 $('#agendaoptions')[view.name == 'table' ? 'show' : 'hide'](); | |
3848 if (minical) { | |
3849 window.setTimeout(function(){ minical.datepicker('setDate', fc.fullCalendar('getDate')); }, exec_deferred); | |
3850 if (view.name != current_view) | |
3851 me.view_resize(); | |
3852 current_view = view.name; | |
3853 me.update_state(); | |
3854 } | |
3855 }, | |
3856 viewRender: function(view) { | |
3857 if (fc && view.name == 'month') | |
3858 fc.fullCalendar('option', 'maxHeight', Math.floor((view.element.parent().height()-18) / 6) - 35); | |
3859 } | |
3860 })); | |
3861 | |
3862 // if start date is changed, shift end date according to initial duration | |
3863 var shift_enddate = function(dateText) { | |
3864 var newstart = parse_datetime('0', dateText); | |
3865 var newend = new Date(newstart.getTime() + $('#edit-startdate').data('duration') * 1000); | |
3866 $('#edit-enddate').val($.fullCalendar.formatDate(newend, me.settings['date_format'])); | |
3867 event_times_changed(); | |
3868 }; | |
3869 | |
3870 // Set as calculateWeek to determine the week of the year based on the ISO 8601 definition. | |
3871 // Uses the default $.datepicker.iso8601Week() function but takes firstDay setting into account. | |
3872 // This is a temporary fix until http://bugs.jqueryui.com/ticket/8420 is resolved. | |
3873 var iso8601Week = datepicker_settings.calculateWeek = function(date) { | |
3874 var mondayOffset = Math.abs(1 - datepicker_settings.firstDay); | |
3875 return $.datepicker.iso8601Week(new Date(date.getTime() + mondayOffset * 86400000)); | |
3876 }; | |
3877 | |
3878 var minical; | |
3879 var init_calendar_ui = function() | |
3880 { | |
3881 // initialize small calendar widget using jQuery UI datepicker | |
3882 minical = $('#datepicker').datepicker($.extend(datepicker_settings, { | |
3883 inline: true, | |
3884 showWeek: true, | |
3885 changeMonth: true, | |
3886 changeYear: true, | |
3887 onSelect: function(dateText, inst) { | |
3888 ignore_click = true; | |
3889 var d = minical.datepicker('getDate'); //parse_datetime('0:0', dateText); | |
3890 fc.fullCalendar('gotoDate', d).fullCalendar('select', d, d, true); | |
3891 }, | |
3892 onChangeMonthYear: function(year, month, inst) { | |
3893 minical.data('year', year).data('month', month); | |
3894 }, | |
3895 beforeShowDay: function(date) { | |
3896 var view = fc.fullCalendar('getView'); | |
3897 var active = view.visStart && date.getTime() >= view.visStart.getTime() && date.getTime() < view.visEnd.getTime(); | |
3898 return [ true, (active ? 'ui-datepicker-activerange ui-datepicker-active-' + view.name : ''), '']; | |
3899 } | |
3900 })) // set event handler for clicks on calendar week cell of the datepicker widget | |
3901 .on('click', 'td.ui-datepicker-week-col', function(e) { | |
3902 var cell = $(e.target); | |
3903 if (e.target.tagName == 'TD') { | |
3904 var base_date = minical.datepicker('getDate'); | |
3905 if (minical.data('month')) | |
3906 base_date.setMonth(minical.data('month')-1); | |
3907 if (minical.data('year')) | |
3908 base_date.setYear(minical.data('year')); | |
3909 base_date.setHours(12); | |
3910 base_date.setDate(base_date.getDate() - ((base_date.getDay() + 6) % 7) + datepicker_settings.firstDay); | |
3911 var base_kw = iso8601Week(base_date), | |
3912 target_kw = parseInt(cell.html()), | |
3913 wdiff = target_kw - base_kw; | |
3914 if (wdiff > 10) // year jump | |
3915 base_date.setYear(base_date.getFullYear() - 1); | |
3916 else if (wdiff < -10) | |
3917 base_date.setYear(base_date.getFullYear() + 1); | |
3918 // select monday of the chosen calendar week | |
3919 var day_off = base_date.getDay() - datepicker_settings.firstDay, | |
3920 date = new Date(base_date.getTime() - day_off * DAY_MS + wdiff * 7 * DAY_MS); | |
3921 fc.fullCalendar('gotoDate', date).fullCalendar('setDate', date).fullCalendar('changeView', 'agendaWeek'); | |
3922 minical.datepicker('setDate', date); | |
3923 } | |
3924 }); | |
3925 | |
3926 minical.find('.ui-datepicker-inline').attr('aria-labelledby', 'aria-label-minical'); | |
3927 | |
3928 if (rcmail.env.date) { | |
3929 var viewdate = new Date(); | |
3930 viewdate.setTime(fromunixtime(rcmail.env.date)); | |
3931 minical.datepicker('setDate', viewdate); | |
3932 } | |
3933 | |
3934 // init event dialog | |
3935 $('#eventtabs').tabs({ | |
3936 activate: function(event, ui) { | |
3937 // newPanel.selector for jQuery-UI 1.10, newPanel.attr('id') for jQuery-UI 1.12 | |
3938 var tab = String(ui.newPanel.selector || ui.newPanel.attr('id')) | |
3939 .replace(/^#?event-panel-/, '').replace(/s$/, ''); | |
3940 | |
3941 var has_real_attendee = function(attendees) { | |
3942 for (var i=0; i < (attendees ? attendees.length : 0); i++) { | |
3943 if (attendees[i].cutype != 'RESOURCE') | |
3944 return true; | |
3945 } | |
3946 }; | |
3947 | |
3948 if (tab == 'attendee' || tab == 'resource') { | |
3949 if (!rcube_event.is_keyboard(event)) | |
3950 $('#edit-'+tab+'-name').select(); | |
3951 // update free-busy status if needed | |
3952 if (freebusy_ui.needsupdate && me.selected_event) | |
3953 update_freebusy_status(me.selected_event); | |
3954 // add current user as organizer if non added yet | |
3955 if (tab == 'attendee' && !has_real_attendee(event_attendees)) { | |
3956 add_attendee($.extend({ role:'ORGANIZER' }, settings.identity)); | |
3957 $('#edit-attendees-form .attendees-invitebox').show(); | |
3958 } | |
3959 } | |
3960 // reset autocompletion on tab change (#3389) | |
3961 rcmail.ksearch_blur(); | |
3962 } | |
3963 }); | |
3964 $('#edit-enddate').datepicker(datepicker_settings); | |
3965 $('#edit-startdate').datepicker(datepicker_settings).datepicker('option', 'onSelect', shift_enddate).change(function(){ shift_enddate(this.value); }); | |
3966 $('#edit-enddate').datepicker('option', 'onSelect', event_times_changed).change(event_times_changed); | |
3967 $('#edit-allday').click(function(){ $('#edit-starttime, #edit-endtime')[(this.checked?'hide':'show')](); event_times_changed(); }); | |
3968 | |
3969 // configure drop-down menu on time input fields based on jquery UI autocomplete | |
3970 $('#edit-starttime, #edit-endtime, #eventedit input.edit-alarm-time').each(function() { | |
3971 me.init_time_autocomplete(this, { | |
3972 container: '#eventedit', | |
3973 change: event_times_changed | |
3974 }); | |
3975 }); | |
3976 | |
3977 // adjust end time when changing start | |
3978 $('#edit-starttime').change(function(e) { | |
3979 var dstart = $('#edit-startdate'), | |
3980 newstart = parse_datetime(this.value, dstart.val()), | |
3981 newend = new Date(newstart.getTime() + dstart.data('duration') * 1000); | |
3982 $('#edit-endtime').val($.fullCalendar.formatDate(newend, me.settings['time_format'])); | |
3983 $('#edit-enddate').val($.fullCalendar.formatDate(newend, me.settings['date_format'])); | |
3984 event_times_changed(); | |
3985 }); | |
3986 | |
3987 // register events on alarms and recurrence fields | |
3988 me.init_alarms_edit('#edit-alarms'); | |
3989 me.init_recurrence_edit('#eventedit'); | |
3990 | |
3991 // reload free-busy status when changing the organizer identity | |
3992 $('#eventedit').on('change', '#edit-identities-list', function(e) { | |
3993 var email = settings.identities[$(this).val()], | |
3994 icon = $(this).closest('tr').find('img.availabilityicon'); | |
3995 | |
3996 if (email && icon.length) { | |
3997 icon.attr('data-email', email); | |
3998 check_freebusy_status(icon, email, me.selected_event); | |
3999 } | |
4000 }); | |
4001 | |
4002 $('#event-export-startdate').datepicker(datepicker_settings); | |
4003 | |
4004 // init attendees autocompletion | |
4005 var ac_props; | |
4006 // parallel autocompletion | |
4007 if (rcmail.env.autocomplete_threads > 0) { | |
4008 ac_props = { | |
4009 threads: rcmail.env.autocomplete_threads, | |
4010 sources: rcmail.env.autocomplete_sources | |
4011 }; | |
4012 } | |
4013 rcmail.init_address_input_events($('#edit-attendee-name'), ac_props); | |
4014 rcmail.addEventListener('autocomplete_insert', function(e) { | |
4015 var success = false; | |
4016 if (e.field.name == 'participant') { | |
4017 success = add_attendees(e.insert, { role:'REQ-PARTICIPANT', status:'NEEDS-ACTION', cutype:(e.data && e.data.type == 'group' ? 'GROUP' : 'INDIVIDUAL') }); | |
4018 } | |
4019 else if (e.field.name == 'resource' && e.data && e.data.email) { | |
4020 success = add_attendee($.extend(e.data, { role:'REQ-PARTICIPANT', status:'NEEDS-ACTION', cutype:'RESOURCE' })); | |
4021 } | |
4022 if (e.field && success) { | |
4023 e.field.value = ''; | |
4024 } | |
4025 }); | |
4026 | |
4027 $('#edit-attendee-add').click(function(){ | |
4028 var input = $('#edit-attendee-name'); | |
4029 rcmail.ksearch_blur(); | |
4030 if (add_attendees(input.val(), { role:'REQ-PARTICIPANT', status:'NEEDS-ACTION', cutype:'INDIVIDUAL' })) { | |
4031 input.val(''); | |
4032 } | |
4033 }); | |
4034 | |
4035 rcmail.init_address_input_events($('#edit-resource-name'), { action:'calendar/resources-autocomplete' }); | |
4036 | |
4037 $('#edit-resource-add').click(function(){ | |
4038 var input = $('#edit-resource-name'); | |
4039 rcmail.ksearch_blur(); | |
4040 if (add_attendees(input.val(), { role:'REQ-PARTICIPANT', status:'NEEDS-ACTION', cutype:'RESOURCE' })) { | |
4041 input.val(''); | |
4042 } | |
4043 }); | |
4044 | |
4045 $('#edit-resource-find').click(function(){ | |
4046 event_resources_dialog(); | |
4047 return false; | |
4048 }); | |
4049 | |
4050 // handle change of "send invitations" checkbox | |
4051 $('#edit-attendees-invite').change(function() { | |
4052 $('#edit-attendees-donotify,input.edit-attendee-reply').prop('checked', this.checked); | |
4053 // hide/show comment field | |
4054 $('#eventedit .attendees-commentbox')[this.checked ? 'show' : 'hide'](); | |
4055 }); | |
4056 | |
4057 // delegate change event to "send invitations" checkbox | |
4058 $('#edit-attendees-donotify').change(function() { | |
4059 $('#edit-attendees-invite').click(); | |
4060 return false; | |
4061 }); | |
4062 | |
4063 $('#edit-attendee-schedule').click(function(){ | |
4064 event_freebusy_dialog(); | |
4065 }); | |
4066 | |
4067 $('#shedule-freebusy-prev').html(bw.ie6 ? '<<' : '◄').button().click(function(){ render_freebusy_grid(-1); }); | |
4068 $('#shedule-freebusy-next').html(bw.ie6 ? '>>' : '►').button().click(function(){ render_freebusy_grid(1); }).parent().buttonset(); | |
4069 | |
4070 $('#shedule-find-prev').button().click(function(){ freebusy_find_slot(-1); }); | |
4071 $('#shedule-find-next').button().click(function(){ freebusy_find_slot(1); }); | |
4072 | |
4073 $('#schedule-freebusy-workinghours').click(function(){ | |
4074 freebusy_ui.workinhoursonly = this.checked; | |
4075 $('#workinghourscss').remove(); | |
4076 if (this.checked) | |
4077 $('<style type="text/css" id="workinghourscss"> td.offhours { opacity:0.3; filter:alpha(opacity=30) } </style>').appendTo('head'); | |
4078 }); | |
4079 | |
4080 $('#event-rsvp input.button').click(function(e) { | |
4081 event_rsvp(this) | |
4082 }); | |
4083 | |
4084 $('#eventedit input.edit-recurring-savemode').change(function(e) { | |
4085 var sel = $('input.edit-recurring-savemode:checked').val(), | |
4086 disabled = sel == 'current' || sel == 'future'; | |
4087 $('#event-panel-recurrence input, #event-panel-recurrence select, #event-panel-attachments input').prop('disabled', disabled); | |
4088 $('#event-panel-recurrence, #event-panel-attachments')[(disabled?'addClass':'removeClass')]('disabled'); | |
4089 }) | |
4090 | |
4091 $('#eventshow .changersvp').click(function(e) { | |
4092 var d = $('#eventshow'), | |
4093 h = -$(this).closest('.event-line').toggle().height(); | |
4094 $('#event-rsvp').slideDown(300, function() { | |
4095 h += $(this).height(); | |
4096 me.dialog_resize(d.get(0), d.height() + h, d.outerWidth() - 50); | |
4097 }); | |
4098 return false; | |
4099 }) | |
4100 | |
4101 // register click handler for message links | |
4102 $('#edit-event-links, #event-links').on('click', 'li a.messagelink', function(e) { | |
4103 rcmail.open_window(this.href); | |
4104 if (!rcube_event.is_keyboard(e) && this.blur) | |
4105 this.blur(); | |
4106 return false; | |
4107 }); | |
4108 | |
4109 // register click handler for message delete buttons | |
4110 $('#edit-event-links').on('click', 'li a.delete', function(e) { | |
4111 remove_link(e.target); | |
4112 return false; | |
4113 }); | |
4114 | |
4115 $('#agenda-listrange').change(function(e){ | |
4116 settings['agenda_range'] = parseInt($(this).val()); | |
4117 fc.fullCalendar('option', 'listRange', settings['agenda_range']).fullCalendar('render'); | |
4118 // TODO: save new settings in prefs | |
4119 }).val(settings['agenda_range']); | |
4120 | |
4121 $('#agenda-listsections').change(function(e){ | |
4122 settings['agenda_sections'] = $(this).val(); | |
4123 fc.fullCalendar('option', 'listSections', settings['agenda_sections']).fullCalendar('render'); | |
4124 // TODO: save new settings in prefs | |
4125 }).val(fc.fullCalendar('option', 'listSections')); | |
4126 | |
4127 // hide event dialog when clicking somewhere into document | |
4128 $(document).bind('mousedown', dialog_check); | |
4129 | |
4130 rcmail.set_busy(false, 'loading', ui_loading); | |
4131 } | |
4132 | |
4133 // initialize more UI elements (deferred) | |
4134 window.setTimeout(init_calendar_ui, exec_deferred); | |
4135 | |
4136 // fetch counts for some calendars | |
4137 fetch_counts(); | |
4138 | |
4139 // add proprietary css styles if not IE | |
4140 if (!bw.ie) | |
4141 $('div.fc-content').addClass('rcube-fc-content'); | |
4142 | |
4143 // IE supresses 2nd click event when double-clicking | |
4144 if (bw.ie && bw.vendver < 9) { | |
4145 $('div.fc-content').bind('dblclick', function(e){ | |
4146 if (!$(this).hasClass('fc-widget-header') && fc.fullCalendar('getView').name != 'table') { | |
4147 var date = fc.fullCalendar('getDate'); | |
4148 var enddate = new Date(); enddate.setTime(date.getTime() + DAY_MS - 60000); | |
4149 event_edit_dialog('new', { start:date, end:enddate, allDay:true, calendar:me.selected_calendar }); | |
4150 } | |
4151 }); | |
4152 } | |
4153 } // end rcube_calendar class | |
4154 | |
4155 | |
4156 /* calendar plugin initialization */ | |
4157 window.rcmail && rcmail.addEventListener('init', function(evt) { | |
4158 // configure toolbar buttons | |
4159 rcmail.register_command('addevent', function(){ cal.add_event(); }, true); | |
4160 rcmail.register_command('print', function(){ cal.print_calendars(); }, true); | |
4161 | |
4162 // configure list operations | |
4163 rcmail.register_command('calendar-create', function(){ cal.calendar_edit_dialog(null); }, true); | |
4164 rcmail.register_command('calendar-edit', function(){ cal.calendar_edit_dialog(cal.calendars[cal.selected_calendar]); }, false); | |
4165 rcmail.register_command('calendar-remove', function(){ cal.calendar_remove(cal.calendars[cal.selected_calendar]); }, false); | |
4166 rcmail.register_command('calendar-delete', function(){ cal.calendar_delete(cal.calendars[cal.selected_calendar]); }, false); | |
4167 rcmail.register_command('events-import', function(){ cal.import_events(cal.calendars[cal.selected_calendar]); }, true); | |
4168 rcmail.register_command('calendar-showurl', function(){ cal.showurl(cal.calendars[cal.selected_calendar]); }, false); | |
4169 rcmail.register_command('event-download', function(){ cal.event_download(cal.selected_event); }, true); | |
4170 rcmail.register_command('event-sendbymail', function(p, obj, e){ cal.event_sendbymail(cal.selected_event, e); }, true); | |
4171 rcmail.register_command('event-copy', function(){ cal.event_copy(cal.selected_event); }, true); | |
4172 rcmail.register_command('event-history', function(p, obj, e){ cal.event_history_dialog(cal.selected_event); }, false); | |
4173 | |
4174 // search and export events | |
4175 rcmail.register_command('export', function(){ cal.export_events(cal.calendars[cal.selected_calendar]); }, true); | |
4176 rcmail.register_command('search', function(){ cal.quicksearch(); }, true); | |
4177 rcmail.register_command('reset-search', function(){ cal.reset_quicksearch(); }, true); | |
4178 | |
4179 // resource invitation dialog | |
4180 rcmail.register_command('search-resource', function(){ cal.resource_search(); }, true); | |
4181 rcmail.register_command('reset-resource-search', function(){ cal.reset_resource_search(); }, true); | |
4182 rcmail.register_command('add-resource', function(){ cal.add_resource2event(); }, false); | |
4183 | |
4184 // register callback commands | |
4185 rcmail.addEventListener('plugin.refresh_source', function(data) { cal.calendar_refresh_source(data); }); | |
4186 rcmail.addEventListener('plugin.destroy_source', function(p){ cal.calendar_destroy_source(p.id); }); | |
4187 rcmail.addEventListener('plugin.unlock_saving', function(p){ cal.unlock_saving(); }); | |
4188 rcmail.addEventListener('plugin.refresh_calendar', function(p){ cal.refresh(p); }); | |
4189 rcmail.addEventListener('plugin.import_success', function(p){ cal.import_success(p); }); | |
4190 rcmail.addEventListener('plugin.import_error', function(p){ cal.import_error(p); }); | |
4191 rcmail.addEventListener('plugin.update_counts', function(p){ cal.update_counts(p); }); | |
4192 rcmail.addEventListener('plugin.reload_view', function(p){ cal.reload_view(p); }); | |
4193 rcmail.addEventListener('plugin.resource_data', function(p){ cal.resource_data_load(p); }); | |
4194 rcmail.addEventListener('plugin.resource_owner', function(p){ cal.resource_owner_load(p); }); | |
4195 rcmail.addEventListener('plugin.render_event_changelog', function(data){ cal.render_event_changelog(data); }); | |
4196 rcmail.addEventListener('plugin.event_show_diff', function(data){ cal.event_show_diff(data); }); | |
4197 rcmail.addEventListener('plugin.close_history_dialog', function(data){ cal.close_history_dialog(); }); | |
4198 rcmail.addEventListener('plugin.event_show_revision', function(data){ cal.event_show_dialog(data, null, true); }); | |
4199 rcmail.addEventListener('plugin.itip_message_processed', function(data){ cal.itip_message_processed(data); }); | |
4200 rcmail.addEventListener('requestrefresh', function(q){ return cal.before_refresh(q); }); | |
4201 | |
4202 // let's go | |
4203 var cal = new rcube_calendar_ui($.extend(rcmail.env.calendar_settings, rcmail.env.libcal_settings)); | |
4204 | |
4205 $(window).resize(function(e) { | |
4206 // check target due to bugs in jquery | |
4207 // http://bugs.jqueryui.com/ticket/7514 | |
4208 // http://bugs.jquery.com/ticket/9841 | |
4209 if (e.target == window) { | |
4210 cal.view_resize(); | |
4211 } | |
4212 }).resize(); | |
4213 | |
4214 // show calendars list when ready | |
4215 $('#calendars').css('visibility', 'inherit'); | |
4216 | |
4217 // show toolbar | |
4218 $('#toolbar').show(); | |
4219 | |
4220 }); |