annotate plugins/calendar/calendar_ui.js @ 17:3bd5fe8166b8

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