2 Copyright (C) 2005 SKYRIX Software AG
4 This file is part of SOGo.
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?
28 if (date1.getYear() < date2.getYear()) return date1;
29 if (date1.getYear() > date2.getYear()) return date2;
31 // cuicui += '/month';
32 if (date1.getMonth() < date2.getMonth()) return date1;
33 if (date1.getMonth() > date2.getMonth()) return date2;
36 if (date1.getDate() < date2.getDate()) return date1;
37 if (date1.getDate() > date2.getDate()) return date2;
43 function validateDate(date, label) {
44 var result, dateValue;
46 dateValue = date.calendar.prs_date(date.value);
47 if (date.value.length != 10 || !dateValue) {
48 alert(label.decodeEntities());
56 function validateTaskEditor() {
57 var e, startdate, enddate, tmpdate;
59 e = document.getElementById('summary');
60 if (e.value.length == 0
61 && !confirm(labels.validate_notitle.decodeEntities()))
64 e = document.getElementById('startTime_date');
66 startdate = validateDate(e, labels.validate_invalid_startdate);
71 e = document.getElementById('dueTime_date');
73 enddate = validateDate(e, labels.validate_invalid_enddate);
78 if (startdate && enddate) {
79 tmpdate = uixEarlierDate(startdate, enddate);
80 if (tmpdate == enddate) {
81 // window.alert(cuicui);
82 alert(labels.validate_endbeforestart.decodeEntities());
85 else if (tmpdate == null /* means: same date */) {
89 start = parseInt(document.forms[0]['startTime_time_hour'].value);
90 end = parseInt(document.forms[0]['dueTime_time_hour'].value);
93 alert(labels.validate_endbeforestart.decodeEntities());
96 else if (start == end) {
97 start = parseInt(document.forms[0]['startTime_time_minute'].value);
98 end = parseInt(document.forms[0]['dueTime_time_minute'].value);
100 alert(labels.validate_endbeforestart.decodeEntities());
110 function toggleDetails() {
111 var div = $("details");
112 var buttons = $("buttons");
113 var buttonsHeight = buttons.clientHeight * 3;
115 if (div.style.visibility) {
116 div.style.visibility = null;
117 window.resizeBy(0, -(div.clientHeight + buttonsHeight));
118 $("detailsButton").innerHTML = labels["Show Details"];
120 div.style.visibility = 'visible;';
121 window.resizeBy(0, (div.clientHeight + buttonsHeight));
122 $("detailsButton").innerHTML = labels["Hide Details"];
128 function toggleCycleVisibility(node, nodeName, hiddenValue) {
129 var spanNode = $(nodeName);
130 var newVisibility = ((node.value == hiddenValue) ? null : 'visible;');
131 spanNode.style.visibility = newVisibility;
133 if (nodeName == 'cycleSelectionFirstLevel') {
134 var otherSpanNode = $('cycleSelectionSecondLevel');
137 otherSpanNode.superVisibility = otherSpanNode.style.visibility;
138 otherSpanNode.style.visibility = null;
142 otherSpanNode.style.visibility = otherSpanNode.superVisibility;
143 otherSpanNode.superVisibility = null;
148 function addContact(tag, fullContactName, contactId, contactName, contactEmail)
150 var uids = $('uixselector-participants-uidList');
151 log ("contactId: " + contactId);
154 var re = new RegExp("(^|,)" + contactId + "($|,)");
156 log ("uids: " + uids);
157 if (!re.test(uids.value))
159 log ("no match... realling adding");
160 if (uids.value.length > 0)
161 uids.value += ',' + contactId;
163 uids.value = contactId;
165 var names = $('uixselector-participants-display');
166 names.innerHTML += ('<li onmousedown="return false;"'
167 + ' onclick="onRowClick(event);"><img src="'
168 + ResourcesURL + '/abcard.gif" />'
169 + contactName + '</li>');
172 log ("match... ignoring contact");
178 function onTimeControlCheck(checkBox) {
179 var inputs = checkBox.parentNode.getElementsByTagName("input");
180 var selects = checkBox.parentNode.getElementsByTagName("select");
181 for (var i = 0; i < inputs.length; i++)
182 if (inputs[i] != checkBox)
183 inputs[i].disabled = !checkBox.checked;
184 for (var i = 0; i < selects.length; i++)
185 if (selects[i] != checkBox)
186 selects[i].disabled = !checkBox.checked;
189 function saveEvent(sender) {
190 if (validateTaskEditor())
191 document.forms['editform'].submit();
196 function startDayAsShortString() {
197 return dayAsShortDateString($('startTime_date'));
200 function dueDayAsShortString() {
201 return dayAsShortDateString($('dueTime_date'));
204 this._getDate = function(which) {
205 var date = window.timeWidgets[which]['date'].valueAsDate();
206 date.setHours( window.timeWidgets[which]['hour'].value );
207 date.setMinutes( window.timeWidgets[which]['minute'].value );
212 this._getShadowDate = function(which) {
213 var date = window.timeWidgets[which]['date'].getAttribute("shadow-value").asDate();
214 var intValue = parseInt(window.timeWidgets[which]['hour'].getAttribute("shadow-value"));
215 date.setHours(intValue);
216 intValue = parseInt(window.timeWidgets[which]['minute'].getAttribute("shadow-value"));
217 date.setMinutes(intValue);
218 // window.alert("shadow: " + date);
223 this.getStartDate = function() {
224 return this._getDate('start');
227 this.getDueDate = function() {
228 return this._getDate('due');
231 this.getShadowStartDate = function() {
232 return this._getShadowDate('start');
235 this.getShadowDueDate = function() {
236 return this._getShadowDate('due');
239 this._setDate = function(which, newDate) {
240 window.timeWidgets[which]['date'].setValueAsDate(newDate);
241 window.timeWidgets[which]['hour'].value = newDate.getHours();
242 var minutes = newDate.getMinutes();
244 minutes += (15 - minutes % 15);
245 window.timeWidgets[which]['minute'].value = minutes;
248 this.setStartDate = function(newStartDate) {
249 this._setDate('start', newStartDate);
252 this.setDueDate = function(newDueDate) {
253 // window.alert(newDueDate);
254 this._setDate('due', newDueDate);
257 this.onAdjustDueTime = function(event) {
258 if (!window.timeWidgets['due']['date'].disabled) {
259 var dateDelta = (window.getStartDate().valueOf()
260 - window.getShadowStartDate().valueOf());
261 var newDueDate = new Date(window.getDueDate().valueOf() + dateDelta);
262 window.setDueDate(newDueDate);
264 window.timeWidgets['start']['date'].updateShadowValue();
265 window.timeWidgets['start']['hour'].updateShadowValue();
266 window.timeWidgets['start']['minute'].updateShadowValue();
269 this.initTimeWidgets = function (widgets) {
270 this.timeWidgets = widgets;
272 widgets['start']['date'].addEventListener("change", this.onAdjustDueTime, false);
273 widgets['start']['hour'].addEventListener("change", this.onAdjustDueTime, false);
274 widgets['start']['minute'].addEventListener("change", this.onAdjustDueTime, false);