2006-10-26 01:58:29 +02:00
|
|
|
var resultsDiv;
|
|
|
|
var searchField;
|
|
|
|
var running = false;
|
|
|
|
var address;
|
|
|
|
var delay = 500;
|
|
|
|
var requestField;
|
2006-10-26 18:43:50 +02:00
|
|
|
var awaitingFreeBusyRequests = new Array();
|
|
|
|
var freeBusySelectorId;
|
2006-10-26 01:58:29 +02:00
|
|
|
|
2006-11-13 19:46:00 +01:00
|
|
|
function onContactKeydown(event) {
|
|
|
|
if (event.keyCode == 9) {
|
|
|
|
event.preventDefault();
|
|
|
|
if (this.confirmedValue)
|
|
|
|
this.value = this.confirmedValue;
|
|
|
|
var row = this.parentNode.parentNode.nextSibling;
|
|
|
|
while (!(row instanceof HTMLTableRowElement))
|
|
|
|
row = row.nextSibling;
|
|
|
|
this.blur();
|
|
|
|
var input = row.cells[0].childNodesWithTag("input")[0];
|
|
|
|
if (input.readOnly)
|
|
|
|
newAttendee(null);
|
|
|
|
else {
|
|
|
|
input.focus();
|
|
|
|
input.select();
|
|
|
|
input.focussed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!running) {
|
2006-11-06 18:44:07 +01:00
|
|
|
if (event.keyCode == 8
|
|
|
|
|| event.keyCode == 32
|
|
|
|
|| event.keyCode > 47) {
|
|
|
|
running = true;
|
2006-11-13 19:46:00 +01:00
|
|
|
requestField = this;
|
2006-11-06 18:44:07 +01:00
|
|
|
setTimeout("triggerRequest()", delay);
|
2006-11-13 19:46:00 +01:00
|
|
|
}
|
|
|
|
else if (this.confirmedValue) {
|
2006-11-09 00:49:21 +01:00
|
|
|
if (event.keyCode == 13) {
|
2006-11-13 19:46:00 +01:00
|
|
|
this.setSelectionRange(this.value.length, this.value.length);
|
2006-11-09 00:49:21 +01:00
|
|
|
}
|
2006-11-06 18:44:07 +01:00
|
|
|
}
|
2006-10-26 01:58:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function triggerRequest() {
|
|
|
|
if (document.contactLookupAjaxRequest) {
|
|
|
|
document.contactLookupAjaxRequest.aborted = yes;
|
|
|
|
document.contactLookupAjaxRequest.abort();
|
|
|
|
}
|
|
|
|
var urlstr = ( UserFolderURL + "Contacts/contactSearch?search="
|
|
|
|
+ requestField.value );
|
|
|
|
document.contactLookupAjaxRequest = triggerAjaxRequest(urlstr,
|
|
|
|
updateResults,
|
|
|
|
requestField);
|
|
|
|
}
|
|
|
|
|
2006-11-13 19:46:00 +01:00
|
|
|
function updateResults(http) {
|
2006-10-26 01:58:29 +02:00
|
|
|
if (http.readyState == 4) {
|
|
|
|
if (http.status == 200) {
|
|
|
|
var searchField = http.callbackData;
|
|
|
|
var start = searchField.value.length;
|
|
|
|
var text = http.responseText.split(":");
|
|
|
|
if (text[0].length > 0)
|
|
|
|
searchField.uid = text[0];
|
|
|
|
else
|
|
|
|
searchField.uid = null;
|
|
|
|
searchField.hasfreebusy = false;
|
2006-11-06 18:44:07 +01:00
|
|
|
if (text[1].substring(0, searchField.value.length).toUpperCase()
|
|
|
|
== searchField.value.toUpperCase())
|
|
|
|
searchField.value = text[1];
|
|
|
|
else {
|
|
|
|
searchField.value += ' >> ' + text[1];
|
|
|
|
}
|
|
|
|
searchField.confirmedValue = text[1];
|
2006-11-13 19:46:00 +01:00
|
|
|
if (searchField.focussed) {
|
|
|
|
var end = searchField.value.length;
|
|
|
|
searchField.setSelectionRange(start, end);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
searchField.value = text[1];
|
2006-10-26 01:58:29 +02:00
|
|
|
}
|
|
|
|
running = false;
|
|
|
|
document.contactLookupAjaxRequest = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetFreeBusyZone()
|
|
|
|
{
|
|
|
|
var table = $("attendeesView").childNodesWithTag("div")[0].childNodesWithTag("table")[0];
|
|
|
|
var row = table.tHead.rows[2];
|
2006-10-30 23:43:13 +01:00
|
|
|
for (var i = 1; i < row.cells.length; i++) {
|
|
|
|
var nodes = row.cells[i].childNodesWithTag("span");
|
|
|
|
for (var j = 0; j < nodes.length; j++)
|
|
|
|
nodes[j].removeClassName("busy");
|
|
|
|
}
|
2006-10-26 01:58:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function redisplayFreeBusyZone()
|
|
|
|
{
|
|
|
|
var table = $("attendeesView").childNodesWithTag("div")[0].childNodesWithTag("table")[0];
|
|
|
|
var row = table.tHead.rows[2];
|
2006-10-31 00:33:41 +01:00
|
|
|
var stDay = this.timeWidgets['start']['date'].valueAsDate();
|
|
|
|
var etDay = this.timeWidgets['end']['date'].valueAsDate();
|
|
|
|
var days = stDay.daysUpTo(etDay);
|
|
|
|
var addDays = days.length - 1;
|
|
|
|
var stHour = parseInt(this.timeWidgets['start']['hour'].value);
|
|
|
|
var stMinute = parseInt(this.timeWidgets['start']['minute'].value) / 15;
|
|
|
|
var etHour = parseInt(this.timeWidgets['end']['hour'].value);
|
|
|
|
var etMinute = parseInt(this.timeWidgets['end']['minute'].value) / 15;
|
2006-10-26 01:58:29 +02:00
|
|
|
if (stHour < 8) {
|
|
|
|
stHour = 8;
|
|
|
|
stMinute = 0;
|
|
|
|
}
|
2006-10-31 00:33:41 +01:00
|
|
|
if (stHour > 19) {
|
|
|
|
stHour = 19
|
2006-10-26 01:58:29 +02:00
|
|
|
stMinute = 0;
|
|
|
|
}
|
|
|
|
if (etHour < 8) {
|
|
|
|
etHour = 8;
|
|
|
|
etMinute = 0;
|
|
|
|
}
|
2006-10-31 00:33:41 +01:00
|
|
|
if (etHour > 19) {
|
|
|
|
etHour = 19;
|
2006-10-26 01:58:29 +02:00
|
|
|
etMinute = 0;
|
|
|
|
}
|
|
|
|
if (stHour > etHour) {
|
|
|
|
var swap = etHour;
|
|
|
|
etHour = stHour;
|
|
|
|
stHour = swap;
|
|
|
|
swap = etMinute;
|
|
|
|
etMinute = stMinute;
|
|
|
|
stMinute = etMinute;
|
2006-10-31 00:33:41 +01:00
|
|
|
} else {
|
|
|
|
if (stMinute > etMinute) {
|
|
|
|
var swap = etMinute;
|
|
|
|
etMinute = stMinute;
|
|
|
|
stMinute = swap;
|
|
|
|
}
|
2006-10-26 01:58:29 +02:00
|
|
|
}
|
|
|
|
|
2006-10-31 00:33:41 +01:00
|
|
|
var deltaCells = (etHour - stHour) + (11 * addDays);
|
2006-10-26 01:58:29 +02:00
|
|
|
var deltaSpans = (deltaCells * 4 ) + (etMinute - stMinute);
|
|
|
|
var currentCellNbr = stHour - 7;
|
|
|
|
var currentCell = row.cells[currentCellNbr];
|
|
|
|
var currentSpanNbr = stMinute;
|
|
|
|
var spans = currentCell.childNodesWithTag("span");
|
|
|
|
resetFreeBusyZone();
|
|
|
|
while (deltaSpans > 0) {
|
|
|
|
var currentSpan = spans[currentSpanNbr];
|
|
|
|
currentSpan.addClassName("busy");
|
|
|
|
currentSpanNbr++;
|
|
|
|
if (currentSpanNbr > 3) {
|
|
|
|
currentSpanNbr = 0;
|
|
|
|
currentCellNbr++;
|
|
|
|
currentCell = row.cells[currentCellNbr];
|
|
|
|
spans = currentCell.childNodesWithTag("span");
|
|
|
|
}
|
|
|
|
deltaSpans--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-13 19:46:00 +01:00
|
|
|
function newAttendee(event)
|
2006-10-26 01:58:29 +02:00
|
|
|
{
|
|
|
|
var table = $("attendeesView").childNodesWithTag("div")[0].childNodesWithTag("table")[0];
|
2006-11-13 19:46:00 +01:00
|
|
|
var tbody = table.tBodies[0];
|
2006-10-26 01:58:29 +02:00
|
|
|
var model = tbody.rows[tbody.rows.length - 1];
|
|
|
|
var newAttendeeRow = tbody.rows[tbody.rows.length - 2]
|
|
|
|
var newRow = model.cloneNode(true);
|
2006-11-13 19:46:00 +01:00
|
|
|
var input = newRow.cells[0].childNodesWithTag("input")[0];
|
|
|
|
input.setAttribute("autocomplete", "off");
|
2006-10-26 01:58:29 +02:00
|
|
|
newRow.setAttribute("class", "");
|
|
|
|
tbody.insertBefore(newRow, newAttendeeRow);
|
2006-11-13 19:46:00 +01:00
|
|
|
input.serial = "pouet";
|
|
|
|
input.addEventListener("blur", checkAttendee, false);
|
|
|
|
input.addEventListener("keydown", onContactKeydown, false);
|
|
|
|
input.focus();
|
|
|
|
input.focussed = true;
|
2006-10-26 01:58:29 +02:00
|
|
|
}
|
|
|
|
|
2006-11-13 19:46:00 +01:00
|
|
|
function checkAttendee()
|
2006-10-26 01:58:29 +02:00
|
|
|
{
|
2006-11-13 19:46:00 +01:00
|
|
|
this.focussed = false;
|
|
|
|
var th = this.parentNode.parentNode;
|
2006-10-26 01:58:29 +02:00
|
|
|
var tbody = th.parentNode;
|
2006-11-13 19:46:00 +01:00
|
|
|
if (this.value.trim().length == 0)
|
2006-10-26 01:58:29 +02:00
|
|
|
tbody.removeChild(th);
|
2006-11-13 19:46:00 +01:00
|
|
|
else if (!this.hasfreebusy) {
|
|
|
|
if (this.confirmedValue)
|
|
|
|
this.value = this.confirmedValue;
|
|
|
|
displayFreeBusyForNode(this);
|
|
|
|
this.hasfreebusy = true;
|
2006-10-26 01:58:29 +02:00
|
|
|
}
|
2006-10-26 18:43:50 +02:00
|
|
|
resetAttendeesValue();
|
2006-10-26 01:58:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function displayFreeBusyForNode(node)
|
|
|
|
{
|
2006-10-26 18:43:50 +02:00
|
|
|
var nodes = node.parentNode.parentNode.cells;
|
2006-10-26 01:58:29 +02:00
|
|
|
if (node.uid) {
|
|
|
|
for (var i = 1; i < nodes.length; i++) {
|
|
|
|
nodes[i].removeClassName("noFreeBusy");
|
|
|
|
nodes[i].innerHTML = ('<span class="freeBusyZoneElement"></span>'
|
|
|
|
+ '<span class="freeBusyZoneElement"></span>'
|
|
|
|
+ '<span class="freeBusyZoneElement"></span>'
|
|
|
|
+ '<span class="freeBusyZoneElement"></span>');
|
|
|
|
}
|
|
|
|
if (document.contactFreeBusyAjaxRequest) {
|
|
|
|
document.contactFreeBusyAjaxRequest.aborted = true;
|
|
|
|
document.contactFreeBusyAjaxRequest.abort();
|
|
|
|
}
|
|
|
|
var sd = startDayAsShortString();
|
|
|
|
var ed = endDayAsShortString();
|
|
|
|
var urlstr = ( UserFolderURL + "../" + node.uid + "/freebusy.ifb/ajaxRead?"
|
2006-10-26 18:43:50 +02:00
|
|
|
+ "sday=" + sd + "&eday=" + ed + "&additional=2" );
|
|
|
|
document.contactFreeBusyAjaxRequest
|
|
|
|
= triggerAjaxRequest(urlstr,
|
|
|
|
updateFreeBusyData,
|
|
|
|
node);
|
2006-10-26 01:58:29 +02:00
|
|
|
} else {
|
|
|
|
for (var i = 1; i < nodes.length; i++) {
|
|
|
|
nodes[i].addClassName("noFreeBusy");
|
|
|
|
nodes[i].innerHTML = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSlot(tds, nbr, status) {
|
|
|
|
var tdnbr = Math.floor(nbr / 4);
|
|
|
|
var spannbr = nbr - (tdnbr * 4);
|
|
|
|
var days = 0;
|
|
|
|
if (tdnbr > 24) {
|
2006-10-26 02:41:03 +02:00
|
|
|
days = Math.floor(tdnbr / 24);
|
2006-10-26 01:58:29 +02:00
|
|
|
tdnbr -= (days * 24);
|
|
|
|
}
|
|
|
|
if (tdnbr > 7 && tdnbr < 19) {
|
2006-10-26 02:41:03 +02:00
|
|
|
var i = (days * 11 + tdnbr - 7);
|
|
|
|
var td = tds[i];
|
2006-10-26 01:58:29 +02:00
|
|
|
var spans = td.childNodesWithTag("span");
|
2006-10-26 18:43:50 +02:00
|
|
|
if (status == '2')
|
|
|
|
spans[spannbr].addClassName("maybe-busy");
|
|
|
|
else
|
|
|
|
spans[spannbr].addClassName("busy");
|
2006-10-26 01:58:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateFreeBusyData(http)
|
|
|
|
{
|
|
|
|
if (http.readyState == 4) {
|
|
|
|
if (http.status == 200) {
|
|
|
|
var node = http.callbackData;
|
|
|
|
var slots = http.responseText.split(",");
|
|
|
|
var tds = node.parentNode.parentNode.cells;
|
|
|
|
for (var i = 0; i < slots.length; i++) {
|
|
|
|
if (slots[i] != '0')
|
|
|
|
setSlot(tds, i, slots[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.contactFreeBusyAjaxRequest = null;
|
2006-10-26 18:43:50 +02:00
|
|
|
if (awaitingFreeBusyRequests.length > 0)
|
|
|
|
displayFreeBusyForNode(awaitingFreeBusyRequests.shift());
|
2006-10-26 01:58:29 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-26 18:43:50 +02:00
|
|
|
|
|
|
|
function resetAttendeesValue()
|
|
|
|
{
|
|
|
|
var table = $("attendeesView").childNodesWithTag("div")[0].childNodesWithTag("table")[0];
|
|
|
|
var inputs = table.getElementsByTagName("input");
|
|
|
|
var uids = new Array();
|
|
|
|
for (var i = 0; i < inputs.length - 2; i++) {
|
|
|
|
var currentInput = inputs[i];
|
|
|
|
var uid = currentInput.getAttribute("uid");
|
|
|
|
if (uid) {
|
|
|
|
currentInput.uid = uid;
|
|
|
|
currentInput.setAttribute("uid", null);
|
|
|
|
}
|
|
|
|
uids.push(currentInput.uid);
|
2006-11-13 19:46:00 +01:00
|
|
|
currentInput.setAttribute("autocomplete", "off");
|
|
|
|
currentInput.addEventListener("keydown", onContactKeydown, false);
|
|
|
|
currentInput.addEventListener("blur", checkAttendee, false);
|
2006-10-26 18:43:50 +02:00
|
|
|
}
|
|
|
|
var input = $(freeBusySelectorId);
|
|
|
|
input.value = uids.join(",");
|
2006-11-13 19:46:00 +01:00
|
|
|
inputs[inputs.length - 2].setAttribute("autocomplete", "off");
|
|
|
|
inputs[inputs.length - 2].addEventListener("click", newAttendee, false);
|
2006-10-26 18:43:50 +02:00
|
|
|
}
|
|
|
|
|
2006-11-13 19:46:00 +01:00
|
|
|
function initializeFreeBusyUserSelector()
|
2006-10-26 18:43:50 +02:00
|
|
|
{
|
|
|
|
resetAttendeesValue();
|
|
|
|
resetAllFreeBusys();
|
2006-11-13 19:46:00 +01:00
|
|
|
disableAnchor($('FBStartTimeReplica_date').parentNode.childNodesWithTag('a')[0]);
|
|
|
|
disableAnchor($('FBEndTimeReplica_date').parentNode.childNodesWithTag('a')[0]);
|
2006-10-26 18:43:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function resetAllFreeBusys()
|
|
|
|
{
|
|
|
|
var table = $("attendeesView").childNodesWithTag("div")[0].childNodesWithTag("table")[0];
|
|
|
|
var inputs = table.getElementsByTagName("input");
|
|
|
|
|
|
|
|
for (var i = 0; i < inputs.length - 2; i++) {
|
|
|
|
var currentInput = inputs[i];
|
|
|
|
currentInput.hasfreebusy = false;
|
2006-10-30 23:43:13 +01:00
|
|
|
// log ("input: " + currentInput.uid);
|
2006-10-26 18:43:50 +02:00
|
|
|
awaitingFreeBusyRequests.push(currentInput);
|
|
|
|
}
|
|
|
|
if (awaitingFreeBusyRequests.length > 0)
|
|
|
|
displayFreeBusyForNode(awaitingFreeBusyRequests.shift());
|
|
|
|
}
|
2006-10-30 23:43:13 +01:00
|
|
|
|
2006-11-07 17:13:03 +01:00
|
|
|
if (this.initTimeWidgets)
|
|
|
|
this.oldInitTimeWidgets = this.initTimeWidgets;
|
|
|
|
|
|
|
|
this.initTimeWidgets = function(widgets) {
|
|
|
|
if (this.oldInitTimeWidgets)
|
|
|
|
this.oldInitTimeWidgets(widgets);
|
|
|
|
|
2006-10-30 23:43:13 +01:00
|
|
|
this.timeWidgets = widgets;
|
|
|
|
|
|
|
|
widgets['start']['hour'].addEventListener("change", onTimeWidgetChange, false);
|
2006-10-31 00:33:41 +01:00
|
|
|
widgets['start']['minute'].addEventListener("change", onTimeWidgetChange, false);
|
|
|
|
widgets['end']['hour'].addEventListener("change", onTimeWidgetChange, false);
|
2006-10-30 23:43:13 +01:00
|
|
|
widgets['end']['minute'].addEventListener("change", onTimeWidgetChange, false);
|
|
|
|
widgets['start']['date'].addEventListener("change", onTimeDateWidgetChange, false);
|
|
|
|
widgets['end']['date'].addEventListener("change", onTimeDateWidgetChange, false);
|
|
|
|
|
|
|
|
widgets['start']['date'].assignReplica($("FBStartTimeReplica_date"));
|
|
|
|
widgets['end']['date'].assignReplica($("FBEndTimeReplica_date"));
|
2006-10-31 00:33:41 +01:00
|
|
|
|
|
|
|
var form = $("FBStartTimeReplica_date").form;
|
|
|
|
widgets['end']['hour'].assignReplica(form["FBEndTimeReplica_time_hour"]);
|
|
|
|
widgets['end']['minute'].assignReplica(form["FBEndTimeReplica_time_minute"]);
|
|
|
|
widgets['start']['hour'].assignReplica(form["FBStartTimeReplica_time_hour"]);
|
|
|
|
widgets['start']['minute'].assignReplica(form["FBStartTimeReplica_time_minute"]);
|
2006-10-30 23:43:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onTimeDateWidgetChange(event) {
|
|
|
|
if (document.timeWidgetsFreeBusyAjaxRequest) {
|
|
|
|
document.timeWidgetsFreeBusyAjaxRequest.aborted = true;
|
|
|
|
document.timeWidgetsFreeBusyAjaxRequest.abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
var date1 = window.timeWidgets['start']['date'].valueAsShortDateString();
|
|
|
|
var date2 = window.timeWidgets['end']['date'].valueAsShortDateString();
|
|
|
|
var attendees = $(freeBusySelectorId).value;
|
|
|
|
var urlstr = ( "../freeBusyTable?sday=" + date1 + "&eday=" + date2
|
|
|
|
+ "&attendees=" + attendees );
|
|
|
|
document.timeWidgetsFreeBusyAjaxRequest
|
|
|
|
= triggerAjaxRequest(urlstr, timeWidgetsFreeBusyCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
function timeWidgetsFreeBusyCallback(http)
|
|
|
|
{
|
|
|
|
if (http.readyState == 4) {
|
|
|
|
if (http.status == 200) {
|
|
|
|
var div = $("parentOf" + freeBusySelectorId.capitalize());
|
|
|
|
div.innerHTML = http.responseText;
|
|
|
|
resetAttendeesValue();
|
|
|
|
resetAllFreeBusys();
|
2006-10-31 00:33:41 +01:00
|
|
|
redisplayFreeBusyZone();
|
2006-10-30 23:43:13 +01:00
|
|
|
}
|
|
|
|
document.timeWidgetsFreeBusyAjaxRequest = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTimeWidgetChange()
|
|
|
|
{
|
|
|
|
setTimeout("redisplayFreeBusyZone();", 1000);
|
|
|
|
}
|
2006-11-13 19:46:00 +01:00
|
|
|
|
|
|
|
function onFreeBusyLoadHandler() {
|
|
|
|
initializeFreeBusyUserSelector();
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("load", onFreeBusyLoadHandler, false);
|