7 var awaitingFreeBusyRequests = new Array();
8 var freeBusySelectorId;
10 function onContactKeydown(event) {
11 if (event.keyCode == 9) {
12 event.preventDefault();
13 if (this.confirmedValue)
14 this.value = this.confirmedValue;
15 var row = this.parentNode.parentNode.nextSibling;
16 while (!(row instanceof HTMLTableRowElement))
17 row = row.nextSibling;
19 var input = row.cells[0].childNodesWithTag("input")[0];
25 input.focussed = true;
29 if (event.keyCode == 8
30 || event.keyCode == 32
31 || event.keyCode > 47) {
34 setTimeout("triggerRequest()", delay);
36 else if (this.confirmedValue) {
37 if (event.keyCode == 13) {
38 this.setSelectionRange(this.value.length, this.value.length);
44 function triggerRequest() {
45 if (document.contactLookupAjaxRequest) {
46 document.contactLookupAjaxRequest.aborted = yes;
47 document.contactLookupAjaxRequest.abort();
49 var urlstr = ( UserFolderURL + "Contacts/contactSearch?search="
50 + requestField.value );
51 document.contactLookupAjaxRequest = triggerAjaxRequest(urlstr,
56 function updateResults(http) {
57 if (http.readyState == 4) {
58 if (http.status == 200) {
59 var searchField = http.callbackData;
60 var start = searchField.value.length;
61 var text = http.responseText.split(":");
62 if (text[0].length > 0)
63 searchField.uid = text[0];
65 searchField.uid = null;
66 searchField.hasfreebusy = false;
67 if (text[1].substring(0, searchField.value.length).toUpperCase()
68 == searchField.value.toUpperCase())
69 searchField.value = text[1];
71 searchField.value += ' >> ' + text[1];
73 searchField.confirmedValue = text[1];
74 if (searchField.focussed) {
75 var end = searchField.value.length;
76 searchField.setSelectionRange(start, end);
79 searchField.value = text[1];
82 document.contactLookupAjaxRequest = null;
86 function resetFreeBusyZone()
88 var table = $("attendeesView").childNodesWithTag("div")[0].childNodesWithTag("table")[0];
89 var row = table.tHead.rows[2];
90 for (var i = 1; i < row.cells.length; i++) {
91 var nodes = row.cells[i].childNodesWithTag("span");
92 for (var j = 0; j < nodes.length; j++)
93 nodes[j].removeClassName("busy");
97 function redisplayFreeBusyZone()
99 var table = $("attendeesView").childNodesWithTag("div")[0].childNodesWithTag("table")[0];
100 var row = table.tHead.rows[2];
101 var stDay = this.timeWidgets['start']['date'].valueAsDate();
102 var etDay = this.timeWidgets['end']['date'].valueAsDate();
103 var days = stDay.daysUpTo(etDay);
104 var addDays = days.length - 1;
105 var stHour = parseInt(this.timeWidgets['start']['hour'].value);
106 var stMinute = parseInt(this.timeWidgets['start']['minute'].value) / 15;
107 var etHour = parseInt(this.timeWidgets['end']['hour'].value);
108 var etMinute = parseInt(this.timeWidgets['end']['minute'].value) / 15;
125 if (stHour > etHour) {
133 if (stMinute > etMinute) {
140 var deltaCells = (etHour - stHour) + (11 * addDays);
141 var deltaSpans = (deltaCells * 4 ) + (etMinute - stMinute);
142 var currentCellNbr = stHour - 7;
143 var currentCell = row.cells[currentCellNbr];
144 var currentSpanNbr = stMinute;
145 var spans = currentCell.childNodesWithTag("span");
147 while (deltaSpans > 0) {
148 var currentSpan = spans[currentSpanNbr];
149 currentSpan.addClassName("busy");
151 if (currentSpanNbr > 3) {
154 currentCell = row.cells[currentCellNbr];
155 spans = currentCell.childNodesWithTag("span");
161 function newAttendee(event)
163 var table = $("attendeesView").childNodesWithTag("div")[0].childNodesWithTag("table")[0];
164 var tbody = table.tBodies[0];
165 var model = tbody.rows[tbody.rows.length - 1];
166 var newAttendeeRow = tbody.rows[tbody.rows.length - 2]
167 var newRow = model.cloneNode(true);
168 var input = newRow.cells[0].childNodesWithTag("input")[0];
169 input.setAttribute("autocomplete", "off");
170 newRow.setAttribute("class", "");
171 tbody.insertBefore(newRow, newAttendeeRow);
172 input.serial = "pouet";
173 input.addEventListener("blur", checkAttendee, false);
174 input.addEventListener("keydown", onContactKeydown, false);
176 input.focussed = true;
179 function checkAttendee()
181 this.focussed = false;
182 var th = this.parentNode.parentNode;
183 var tbody = th.parentNode;
184 if (this.value.trim().length == 0)
185 tbody.removeChild(th);
186 else if (!this.hasfreebusy) {
187 if (this.confirmedValue)
188 this.value = this.confirmedValue;
189 displayFreeBusyForNode(this);
190 this.hasfreebusy = true;
192 resetAttendeesValue();
195 function displayFreeBusyForNode(node)
197 var nodes = node.parentNode.parentNode.cells;
199 for (var i = 1; i < nodes.length; i++) {
200 nodes[i].removeClassName("noFreeBusy");
201 nodes[i].innerHTML = ('<span class="freeBusyZoneElement"></span>'
202 + '<span class="freeBusyZoneElement"></span>'
203 + '<span class="freeBusyZoneElement"></span>'
204 + '<span class="freeBusyZoneElement"></span>');
206 if (document.contactFreeBusyAjaxRequest) {
207 document.contactFreeBusyAjaxRequest.aborted = true;
208 document.contactFreeBusyAjaxRequest.abort();
210 var sd = startDayAsShortString();
211 var ed = endDayAsShortString();
212 var urlstr = ( UserFolderURL + "../" + node.uid + "/freebusy.ifb/ajaxRead?"
213 + "sday=" + sd + "&eday=" + ed + "&additional=2" );
214 document.contactFreeBusyAjaxRequest
215 = triggerAjaxRequest(urlstr,
219 for (var i = 1; i < nodes.length; i++) {
220 nodes[i].addClassName("noFreeBusy");
221 nodes[i].innerHTML = '';
226 function setSlot(tds, nbr, status) {
227 var tdnbr = Math.floor(nbr / 4);
228 var spannbr = nbr - (tdnbr * 4);
231 days = Math.floor(tdnbr / 24);
232 tdnbr -= (days * 24);
234 if (tdnbr > 7 && tdnbr < 19) {
235 var i = (days * 11 + tdnbr - 7);
237 var spans = td.childNodesWithTag("span");
239 spans[spannbr].addClassName("maybe-busy");
241 spans[spannbr].addClassName("busy");
245 function updateFreeBusyData(http)
247 if (http.readyState == 4) {
248 if (http.status == 200) {
249 var node = http.callbackData;
250 var slots = http.responseText.split(",");
251 var tds = node.parentNode.parentNode.cells;
252 for (var i = 0; i < slots.length; i++) {
254 setSlot(tds, i, slots[i]);
257 document.contactFreeBusyAjaxRequest = null;
258 if (awaitingFreeBusyRequests.length > 0)
259 displayFreeBusyForNode(awaitingFreeBusyRequests.shift());
263 function resetAttendeesValue()
265 var table = $("attendeesView").childNodesWithTag("div")[0].childNodesWithTag("table")[0];
266 var inputs = table.getElementsByTagName("input");
267 var uids = new Array();
268 for (var i = 0; i < inputs.length - 2; i++) {
269 var currentInput = inputs[i];
270 var uid = currentInput.getAttribute("uid");
272 currentInput.uid = uid;
273 currentInput.setAttribute("uid", null);
275 uids.push(currentInput.uid);
276 currentInput.setAttribute("autocomplete", "off");
277 currentInput.addEventListener("keydown", onContactKeydown, false);
278 currentInput.addEventListener("blur", checkAttendee, false);
280 var input = $(freeBusySelectorId);
281 input.value = uids.join(",");
282 inputs[inputs.length - 2].setAttribute("autocomplete", "off");
283 inputs[inputs.length - 2].addEventListener("click", newAttendee, false);
286 function initializeFreeBusyUserSelector()
288 resetAttendeesValue();
290 disableAnchor($('FBStartTimeReplica_date').parentNode.childNodesWithTag('a')[0]);
291 disableAnchor($('FBEndTimeReplica_date').parentNode.childNodesWithTag('a')[0]);
294 function resetAllFreeBusys()
296 var table = $("attendeesView").childNodesWithTag("div")[0].childNodesWithTag("table")[0];
297 var inputs = table.getElementsByTagName("input");
299 for (var i = 0; i < inputs.length - 2; i++) {
300 var currentInput = inputs[i];
301 currentInput.hasfreebusy = false;
302 // log ("input: " + currentInput.uid);
303 awaitingFreeBusyRequests.push(currentInput);
305 if (awaitingFreeBusyRequests.length > 0)
306 displayFreeBusyForNode(awaitingFreeBusyRequests.shift());
309 if (this.initTimeWidgets)
310 this.oldInitTimeWidgets = this.initTimeWidgets;
312 this.initTimeWidgets = function(widgets) {
313 if (this.oldInitTimeWidgets)
314 this.oldInitTimeWidgets(widgets);
316 this.timeWidgets = widgets;
318 widgets['start']['hour'].addEventListener("change", onTimeWidgetChange, false);
319 widgets['start']['minute'].addEventListener("change", onTimeWidgetChange, false);
320 widgets['end']['hour'].addEventListener("change", onTimeWidgetChange, false);
321 widgets['end']['minute'].addEventListener("change", onTimeWidgetChange, false);
322 widgets['start']['date'].addEventListener("change", onTimeDateWidgetChange, false);
323 widgets['end']['date'].addEventListener("change", onTimeDateWidgetChange, false);
325 widgets['start']['date'].assignReplica($("FBStartTimeReplica_date"));
326 widgets['end']['date'].assignReplica($("FBEndTimeReplica_date"));
328 var form = $("FBStartTimeReplica_date").form;
329 widgets['end']['hour'].assignReplica(form["FBEndTimeReplica_time_hour"]);
330 widgets['end']['minute'].assignReplica(form["FBEndTimeReplica_time_minute"]);
331 widgets['start']['hour'].assignReplica(form["FBStartTimeReplica_time_hour"]);
332 widgets['start']['minute'].assignReplica(form["FBStartTimeReplica_time_minute"]);
335 function onTimeDateWidgetChange(event) {
336 if (document.timeWidgetsFreeBusyAjaxRequest) {
337 document.timeWidgetsFreeBusyAjaxRequest.aborted = true;
338 document.timeWidgetsFreeBusyAjaxRequest.abort();
341 var date1 = window.timeWidgets['start']['date'].valueAsShortDateString();
342 var date2 = window.timeWidgets['end']['date'].valueAsShortDateString();
343 var attendees = $(freeBusySelectorId).value;
344 var urlstr = ( "../freeBusyTable?sday=" + date1 + "&eday=" + date2
345 + "&attendees=" + attendees );
346 document.timeWidgetsFreeBusyAjaxRequest
347 = triggerAjaxRequest(urlstr, timeWidgetsFreeBusyCallback);
350 function timeWidgetsFreeBusyCallback(http)
352 if (http.readyState == 4) {
353 if (http.status == 200) {
354 var div = $("parentOf" + freeBusySelectorId.capitalize());
355 div.innerHTML = http.responseText;
356 resetAttendeesValue();
358 redisplayFreeBusyZone();
360 document.timeWidgetsFreeBusyAjaxRequest = null;
364 function onTimeWidgetChange()
366 setTimeout("redisplayFreeBusyZone();", 1000);
369 function onFreeBusyLoadHandler() {
370 initializeFreeBusyUserSelector();
373 window.addEventListener("load", onFreeBusyLoadHandler, false);