2 Copyright (C) 2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 var contactSelectorAction = 'calendars-contacts';
24 function uixEarlierDate(date1, date2) {
25 // can this be done in a sane way?
26 if (date1.getYear() < date2.getYear()) return date1;
27 if (date1.getYear() > date2.getYear()) return date2;
29 if (date1.getMonth() < date2.getMonth()) return date1;
30 if (date1.getMonth() > date2.getMonth()) return date2;
32 if (date1.getDate() < date2.getDate()) return date1;
33 if (date1.getDate() > date2.getDate()) return date2;
38 function validateAptEditor() {
39 var e, startdate, enddate, tmpdate;
42 if (e.value.length == 0) {
43 if (!confirm(labels.validate_notitle))
47 e = $('startTime_date');
48 if (e.value.length != 10) {
49 alert(labels.validate_invalid_startdate);
52 startdate = e.calendar.prs_date(e.value);
53 if (startdate == null) {
54 alert(labels.validate_invalid_startdate);
58 e = $('endTime_date');
59 if (e.value.length != 10) {
60 alert(labels.validate_invalid_enddate);
63 enddate = e.calendar.prs_date(e.value);
64 if (enddate == null) {
65 alert(labels.validate_invalid_enddate);
68 tmpdate = uixEarlierDate(startdate, enddate);
69 if (tmpdate == enddate) {
70 alert(labels.validate_endbeforestart);
73 else if (tmpdate == null /* means: same date */) {
77 start = parseInt(document.forms[0]['startTime_time_hour'].value);
78 end = parseInt(document.forms[0]['endTime_time_hour'].value);
81 alert(labels.validate_endbeforestart);
84 else if (start == end) {
85 start = parseInt(document.forms[0]['startTime_time_minute'].value);
86 end = parseInt(document.forms[0]['endTime_time_minute'].value);
88 alert(labels.validate_endbeforestart);
97 function toggleDetails() {
98 var div = $("details");
99 var buttons = $("buttons");
100 var buttonsHeight = buttons.clientHeight * 3;
102 if (div.style.visibility) {
103 div.style.visibility = null;
104 window.resizeBy(0, -(div.clientHeight + buttonsHeight));
105 $("detailsButton").innerHTML = labels["Show Details"];
107 div.style.visibility = 'visible;';
108 window.resizeBy(0, (div.clientHeight + buttonsHeight));
109 $("detailsButton").innerHTML = labels["Hide Details"];
115 function toggleCycleVisibility(node, nodeName, hiddenValue) {
116 var spanNode = $(nodeName);
117 var newVisibility = ((node.value == hiddenValue) ? null : 'visible;');
118 spanNode.style.visibility = newVisibility;
120 if (nodeName == 'cycleSelectionFirstLevel') {
121 var otherSpanNode = $('cycleSelectionSecondLevel');
124 otherSpanNode.superVisibility = otherSpanNode.style.visibility;
125 otherSpanNode.style.visibility = null;
129 otherSpanNode.style.visibility = otherSpanNode.superVisibility;
130 otherSpanNode.superVisibility = null;
135 function addContact(tag, fullContactName, contactId, contactName, contactEmail) {
136 var uids = $('uixselector-participants-uidList');
140 var re = new RegExp("(^|,)" + contactId + "($|,)");
142 if (!re.test(uids.value))
144 if (uids.value.length > 0)
145 uids.value += ',' + contactId;
147 uids.value = contactId;
149 var names = $('uixselector-participants-display');
150 names.innerHTML += ('<li onmousedown="return false;"'
151 + ' onclick="onRowClick(event);"><img src="'
152 + ResourcesURL + '/abcard.gif" />'
153 + contactName + '</li>');
160 function saveEvent(sender) {
161 if (validateAptEditor())
162 document.forms['editform'].submit();
167 function startDayAsShortString() {
168 return $('startTime_date').valueAsShortDateString();
171 function endDayAsShortString() {
172 return $('endTime_date').valueAsShortDateString();
175 function _getDate(which) {
176 var date = window.timeWidgets[which]['date'].valueAsDate();
177 date.setHours( window.timeWidgets[which]['hour'].value );
178 date.setMinutes( window.timeWidgets[which]['minute'].value );
183 function _getShadowDate(which) {
184 var date = window.timeWidgets[which]['date'].getAttribute("shadow-value").asDate();
185 var intValue = parseInt(window.timeWidgets[which]['hour'].getAttribute("shadow-value"));
186 date.setHours(intValue);
187 intValue = parseInt(window.timeWidgets[which]['minute'].getAttribute("shadow-value"));
188 date.setMinutes(intValue);
193 function getStartDate() {
194 return this._getDate('start');
197 function getEndDate() {
198 return this._getDate('end');
201 function getShadowStartDate() {
202 return this._getShadowDate('start');
205 function getShadowEndDate() {
206 return this._getShadowDate('end');
209 function _setDate(which, newDate) {
210 window.timeWidgets[which]['date'].setValueAsDate(newDate);
211 window.timeWidgets[which]['hour'].value = newDate.getHours();
212 var minutes = newDate.getMinutes();
214 minutes += (15 - minutes % 15);
215 window.timeWidgets[which]['minute'].value = minutes;
218 function setStartDate(newStartDate) {
219 this._setDate('start', newStartDate);
222 function setEndDate(newEndDate) {
223 this._setDate('end', newEndDate);
226 function onAdjustTime(event) {
227 var endDate = window.getEndDate();
228 var startDate = window.getStartDate();
230 if ($(this).readAttribute("id").startsWith("start")) {
231 // Start date was changed
232 var delta = window.getShadowStartDate().valueOf() -
234 var newEndDate = new Date(endDate.valueOf() - delta);
235 window.setEndDate(newEndDate);
237 window.timeWidgets['end']['date'].updateShadowValue();
238 window.timeWidgets['end']['hour'].updateShadowValue();
239 window.timeWidgets['end']['minute'].updateShadowValue();
240 window.timeWidgets['start']['date'].updateShadowValue();
241 window.timeWidgets['start']['hour'].updateShadowValue();
242 window.timeWidgets['start']['minute'].updateShadowValue();
245 // End date was changed
246 var delta = endDate.valueOf() - startDate.valueOf();
248 alert(labels.validate_endbeforestart);
249 var oldEndDate = window.getShadowEndDate();
250 window.setEndDate(oldEndDate);
252 window.timeWidgets['end']['date'].updateShadowValue();
253 window.timeWidgets['end']['hour'].updateShadowValue();
254 window.timeWidgets['end']['minute'].updateShadowValue();
259 function onAllDayChanged(event) {
260 for (var type in window.timeWidgets) {
261 window.timeWidgets[type]['hour'].disabled = this.checked;
262 window.timeWidgets[type]['minute'].disabled = this.checked;
266 function initTimeWidgets(widgets) {
267 this.timeWidgets = widgets;
269 Event.observe(widgets['start']['date'], "change",
270 this.onAdjustTime, false);
271 Event.observe(widgets['start']['hour'], "change",
272 this.onAdjustTime, false);
273 Event.observe(widgets['start']['minute'], "change",
274 this.onAdjustTime, false);
276 Event.observe(widgets['end']['date'], "change",
277 this.onAdjustTime, false);
278 Event.observe(widgets['end']['hour'], "change",
279 this.onAdjustTime, false);
280 Event.observe(widgets['end']['minute'], "change",
281 this.onAdjustTime, false);
283 var allDayLabel = $("allDay");
284 var input = $(allDayLabel).childNodesWithTag("input")[0];
285 Event.observe(input, "change", onAllDayChanged.bindAsEventListener(input));
287 for (var type in widgets) {
288 widgets[type]['hour'].disabled = true;
289 widgets[type]['minute'].disabled = true;
294 function onAppointmentEditorLoad() {
295 assignCalendar('startTime_date');
296 assignCalendar('endTime_date');
298 var widgets = {'start': {'date': $("startTime_date"),
299 'hour': $("startTime_time_hour"),
300 'minute': $("startTime_time_minute")},
301 'end': {'date': $("endTime_date"),
302 'hour': $("endTime_time_hour"),
303 'minute': $("endTime_time_minute")}};
304 initTimeWidgets(widgets);
307 FastInit.addOnLoad(onAppointmentEditorLoad);