annotate plugins/calendar/calendar_ui.js @ 12:ff1f27bd05ad

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