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');
137 log ("contactId: " + contactId);
140 var re = new RegExp("(^|,)" + contactId + "($|,)");
142 log ("uids: " + uids);
143 if (!re.test(uids.value))
145 log ("no match... realling adding");
146 if (uids.value.length > 0)
147 uids.value += ',' + contactId;
149 uids.value = contactId;
151 var names = $('uixselector-participants-display');
152 names.innerHTML += ('<li onmousedown="return false;"'
153 + ' onclick="onRowClick(event);"><img src="'
154 + ResourcesURL + '/abcard.gif" />'
155 + contactName + '</li>');
158 log ("match... ignoring contact");
164 function saveEvent(sender) {
165 if (validateAptEditor())
166 document.forms['editform'].submit();
171 function startDayAsShortString() {
172 return $('startTime_date').valueAsShortDateString();
175 function endDayAsShortString() {
176 return $('endTime_date').valueAsShortDateString();
179 function _getDate(which) {
180 var date = window.timeWidgets[which]['date'].valueAsDate();
181 date.setHours( window.timeWidgets[which]['hour'].value );
182 date.setMinutes( window.timeWidgets[which]['minute'].value );
187 function _getShadowDate(which) {
188 var date = window.timeWidgets[which]['date'].getAttribute("shadow-value").asDate();
189 var intValue = parseInt(window.timeWidgets[which]['hour'].getAttribute("shadow-value"));
190 date.setHours(intValue);
191 intValue = parseInt(window.timeWidgets[which]['minute'].getAttribute("shadow-value"));
192 date.setMinutes(intValue);
193 // window.alert("shadow: " + date);
198 function getStartDate() {
199 return this._getDate('start');
202 function getEndDate() {
203 return this._getDate('end');
206 function getShadowStartDate() {
207 return this._getShadowDate('start');
210 function getShadowEndDate() {
211 return this._getShadowDate('end');
214 function _setDate(which, newDate) {
215 window.timeWidgets[which]['date'].setValueAsDate(newDate);
216 window.timeWidgets[which]['hour'].value = newDate.getHours();
217 var minutes = newDate.getMinutes();
219 minutes += (15 - minutes % 15);
220 window.timeWidgets[which]['minute'].value = minutes;
223 function setStartDate(newStartDate) {
224 this._setDate('start', newStartDate);
227 function setEndDate(newEndDate) {
228 // window.alert(newEndDate);
229 this._setDate('end', newEndDate);
232 function onAdjustEndTime(event) {
233 var dateDelta = (window.getStartDate().valueOf()
234 - window.getShadowStartDate().valueOf());
235 // window.alert(window.getEndDate().valueOf() + ' ' + dateDelta);
236 var newEndDate = new Date(window.getEndDate().valueOf() + dateDelta);
237 window.setEndDate(newEndDate);
238 window.timeWidgets['start']['date'].updateShadowValue();
239 window.timeWidgets['start']['hour'].updateShadowValue();
240 window.timeWidgets['start']['minute'].updateShadowValue();
243 function onAllDayChanged(event) {
244 for (var type in window.timeWidgets) {
245 window.timeWidgets[type]['hour'].disabled = this.checked;
246 window.timeWidgets[type]['minute'].disabled = this.checked;
250 function initTimeWidgets(widgets) {
251 this.timeWidgets = widgets;
253 Event.observe(widgets['start']['date'], "change",
254 this.onAdjustEndTime, false);
255 Event.observe(widgets['start']['hour'], "change",
256 this.onAdjustEndTime, false);
257 Event.observe(widgets['start']['minute'], "change",
258 this.onAdjustEndTime, false);
260 var allDayLabel = $("allDay");
261 var input = $(allDayLabel).childNodesWithTag("input")[0];
262 Event.observe(input, "change", onAllDayChanged.bindAsEventListener(input));
264 for (var type in widgets) {
265 widgets[type]['hour'].disabled = true;
266 widgets[type]['minute'].disabled = true;
271 function onAppointmentEditorLoad() {
272 assignCalendar('startTime_date');
273 assignCalendar('endTime_date');
275 var widgets = {'start': {'date': $("startTime_date"),
276 'hour': $("startTime_time_hour"),
277 'minute': $("startTime_time_minute")},
278 'end': {'date': $("endTime_date"),
279 'hour': $("endTime_time_hour"),
280 'minute': $("endTime_time_minute")}};
281 initTimeWidgets(widgets);
284 FastInit.addOnLoad(onAppointmentEditorLoad);