diff --git a/UI/WebServerResources/SchedulerUI.js b/UI/WebServerResources/SchedulerUI.js index f3944c852..6b2e524b1 100644 --- a/UI/WebServerResources/SchedulerUI.js +++ b/UI/WebServerResources/SchedulerUI.js @@ -884,35 +884,86 @@ function browseUrl(anchor, event) { return false; } -function initTimeWidgets() -{ - document.forms['editform']["startTime_time_hour"].addEventListener("change", onTimeWidgetChange, false); - document.forms['editform']["startTime_time_minute"].addEventListener("change", onTimeWidgetChange, false); - document.forms['editform']["endTime_time_hour"].addEventListener("change", onTimeWidgetChange, false); - document.forms['editform']["endTime_time_minute"].addEventListener("change", onTimeWidgetChange, false); - - document.forms['editform']["startTime_date"].assignReplica($("FBStartTimeReplica_date")); - document.forms['editform']["endTime_date"].assignReplica($("FBEndTimeReplica_date")); - document.forms['editform']["startTime_time_hour"].assignReplica(document.forms['editform']["FBStartTimeReplica_time_hour"]); - document.forms['editform']["endTime_time_hour"].assignReplica(document.forms['editform']["FBEndTimeReplica_time_hour"]); - document.forms['editform']["startTime_time_minute"].assignReplica(document.forms['editform']["FBStartTimeReplica_time_minute"]); - document.forms['editform']["endTime_time_minute"].assignReplica(document.forms['editform']["FBEndTimeReplica_time_minute"]); -} - -function onTimeWidgetChange() -{ - setTimeout("redisplayFreeBusyZone();", 1000); -} - -function dayAsShortDateString(node) { - var dateStr = ''; - var date = node.value.split("/"); +HTMLInputElement.prototype.valueAsDate = function () { + var newDate; + var date = this.value.split("/"); if (date.length == 3) - dateStr += date[2] + date[1] + date[0]; + newDate = new Date(date[2], date[1] - 1, date[0]); else { - date = node.value.split("-"); - dateStr += date[0] + date[1] + date[2]; + date = this.value.split("-"); + newDate = new Date(date[0], date[1] - 1, date[2]); } + return newDate; +} + +HTMLInputElement.prototype._detectDateSeparator = function() { + var date = this.value.split("/"); + if (date.length == 3) + this.dateSeparator = "/"; + else + this.dateSeparator = "-"; +} + +HTMLInputElement.prototype.valueAsShortDateString = function() { + var dateStr = ''; + + if (!this.dateSeparator) + this._detectDateSeparator(); + + var date = this.value.split(this.dateSeparator); + if (this.dateSeparator == '/') + dateStr += date[2] + date[1] + date[0]; + else + dateStr += date[0] + date[1] + date[2]; + return dateStr; } + +Date.prototype.sogoDayName = function() { + var dayName = ""; + + var day = this.getDay(); + if (day == 0) { + dayName = labels['a2_Sunday']; + } else if (day == 1) { + dayName = labels['a2_Monday']; + } else if (day == 2) { + dayName = labels['a2_Tuesday']; + } else if (day == 3) { + dayName = labels['a2_Wednesday']; + } else if (day == 4) { + dayName = labels['a2_Thursday']; + } else if (day == 5) { + dayName = labels['a2_Friday']; + } else if (day == 6) { + dayName = labels['a2_Saturday']; + } + + return dayName; +} + +Date.prototype.daysUpTo = function(otherDate) { + var days = new Array(); + var day1 = this.getTime(); + var day2 = otherDate.getTime(); + + var nbrDays = Math.floor((day2 - day1) / 86400000) + 1; + for (var i = 0; i < nbrDays; i++) { + var newDate = new Date(); + newDate.setTime(day1 + (i * 86400000)); + days.push(newDate); + } + + return days; +} + +Date.prototype.sogoFreeBusyStringWithSeparator = function(separator) { + var str = this.sogoDayName() + ", "; + if (separator == '-') + str += (this.getYear() + 1900) + '-' + (this.getMonth() + 1) + '-' + this.getDate(); + else + str += this.getDate() + '/' + (this.getMonth() + 1) + '/' + (this.getYear() + 1900); + + return str; +} diff --git a/UI/WebServerResources/UIxAppointmentEditor.js b/UI/WebServerResources/UIxAppointmentEditor.js index 0e71419ea..94fe422d9 100644 --- a/UI/WebServerResources/UIxAppointmentEditor.js +++ b/UI/WebServerResources/UIxAppointmentEditor.js @@ -176,9 +176,9 @@ function saveEvent(sender) { } function startDayAsShortString() { - return dayAsShortDateString($('startTime_date')); + return $('startTime_date').valueAsShortDateString(); } function endDayAsShortString() { - return dayAsShortDateString($('endTime_date')); + return $('endTime_date').valueAsShortDateString(); } diff --git a/UI/WebServerResources/UIxFreeBusyUserSelector.js b/UI/WebServerResources/UIxFreeBusyUserSelector.js index c65fc6cfe..a1839e878 100644 --- a/UI/WebServerResources/UIxFreeBusyUserSelector.js +++ b/UI/WebServerResources/UIxFreeBusyUserSelector.js @@ -56,12 +56,11 @@ function resetFreeBusyZone() { var table = $("attendeesView").childNodesWithTag("div")[0].childNodesWithTag("table")[0]; var row = table.tHead.rows[2]; - 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"); - } + 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"); + } } function redisplayFreeBusyZone() @@ -231,6 +230,11 @@ function resetAttendeesValue() input.value = uids.join(","); } +function onTimeRangeChange(event) +{ + window.alert("onchange: " + event); +} + function initializeFreeBusyUserSelector(selectorId) { freeBusySelectorId = selectorId; @@ -246,9 +250,61 @@ function resetAllFreeBusys() for (var i = 0; i < inputs.length - 2; i++) { var currentInput = inputs[i]; currentInput.hasfreebusy = false; - log ("input: " + currentInput.uid); +// log ("input: " + currentInput.uid); awaitingFreeBusyRequests.push(currentInput); } if (awaitingFreeBusyRequests.length > 0) displayFreeBusyForNode(awaitingFreeBusyRequests.shift()); } + +function initTimeWidgets(widgets) +{ + this.timeWidgets = widgets; + + widgets['start']['hour'].addEventListener("change", onTimeWidgetChange, false); + widgets['end']['minute'].addEventListener("change", onTimeWidgetChange, false); + widgets['start']['hour'].addEventListener("change", onTimeWidgetChange, false); + 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['start']['hour'].assignReplica($("FBStartTimeReplica_time_hour")); + widgets['start']['minute'].assignReplica($("FBStartTimeReplica_time_minute")); + widgets['end']['date'].assignReplica($("FBEndTimeReplica_date")); + widgets['end']['hour'].assignReplica($("FBEndTimeReplica_time_hour")); + widgets['end']['minute'].assignReplica($("FBEndTimeReplica_time_minute")); +} + +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(); + } + document.timeWidgetsFreeBusyAjaxRequest = null; + } +} + +function onTimeWidgetChange() +{ + setTimeout("redisplayFreeBusyZone();", 1000); +} diff --git a/UI/WebServerResources/generic.js b/UI/WebServerResources/generic.js index 405fe4248..3dcc48f2a 100644 --- a/UI/WebServerResources/generic.js +++ b/UI/WebServerResources/generic.js @@ -1213,6 +1213,14 @@ String.prototype.trim = function() { return this.replace(/(^\s+|\s+$)/g, ''); } +String.prototype.capitalize = function() { + return this.replace(/\w+/g, + function(a) { + return ( a.charAt(0).toUpperCase() + + a.substr(1).toLowerCase() ); + }); +} + String.prototype.decodeEntities = function() { return this.replace(/&#(\d+);/g, function(wholematch, parenmatch1) { @@ -1221,21 +1229,37 @@ String.prototype.decodeEntities = function() { } HTMLInputElement.prototype._replicate = function() { - this.replica.value = this.value; + if (this.replica) { + this.replica.value = this.value; + var onReplicaChangeEvent = document.createEvent("Event"); + onReplicaChangeEvent.initEvent("change", true, true); + this.replica.dispatchEvent(onReplicaChangeEvent); + } } HTMLInputElement.prototype.assignReplica = function(otherInput) { + if (!this._onChangeBound) { + this.addEventListener("change", this._replicate, false); + this._onChangeBound = true; + } this.replica = otherInput; - this.addEventListener("change", this._replicate, false); } HTMLSelectElement.prototype._replicate = function() { - this.replica.value = this.value; + if (this.replica) { + this.replica.value = this.value; + var onReplicaChangeEvent = document.createEvent("Event"); + onReplicaChangeEvent.initEvent("change", true, true); + this.replica.dispatchEvent(onReplicaChangeEvent); + } } HTMLSelectElement.prototype.assignReplica = function(otherSelect) { + if (!this._onChangeBound) { + this.addEventListener("change", this._replicate, false); + this._onChangeBound = true; + } this.replica = otherSelect; - this.addEventListener("change", this._replicate, false); } function d2h(d) {