1 var contactSelectorAction = 'calendars-contacts';
3 addEvent(window, 'DOMContentLoaded', onTaskEditorLoad);
5 function uixEarlierDate(date1, date2) {
6 // can this be done in a sane way?
9 if (date1.getYear() < date2.getYear()) return date1;
10 if (date1.getYear() > date2.getYear()) return date2;
12 // cuicui += '/month';
13 if (date1.getMonth() < date2.getMonth()) return date1;
14 if (date1.getMonth() > date2.getMonth()) return date2;
17 if (date1.getDate() < date2.getDate()) return date1;
18 if (date1.getDate() > date2.getDate()) return date2;
24 function validateDate(date, label) {
25 var result, dateValue;
27 dateValue = date.calendar.prs_date(date.value);
28 if (date.value.length != 10 || !dateValue) {
29 alert(label.decodeEntities());
37 function validateTaskEditor() {
38 var e, startdate, enddate, tmpdate;
40 e = document.getElementById('summary');
41 if (e.value.length == 0
42 && !confirm(labels.validate_notitle.decodeEntities()))
45 e = document.getElementById('startTime_date');
47 startdate = validateDate(e, labels.validate_invalid_startdate);
52 e = document.getElementById('dueTime_date');
54 enddate = validateDate(e, labels.validate_invalid_enddate);
59 if (startdate && enddate) {
60 tmpdate = uixEarlierDate(startdate, enddate);
61 if (tmpdate == enddate) {
62 // window.alert(cuicui);
63 alert(labels.validate_endbeforestart.decodeEntities());
66 else if (tmpdate == null /* means: same date */) {
70 start = parseInt(document.forms[0]['startTime_time_hour'].value);
71 end = parseInt(document.forms[0]['dueTime_time_hour'].value);
74 alert(labels.validate_endbeforestart.decodeEntities());
77 else if (start == end) {
78 start = parseInt(document.forms[0]['startTime_time_minute'].value);
79 end = parseInt(document.forms[0]['dueTime_time_minute'].value);
81 alert(labels.validate_endbeforestart.decodeEntities());
91 function toggleDetails() {
92 var div = $("details");
93 var buttons = $("buttons");
94 var buttonsHeight = buttons.clientHeight * 3;
96 if (div.style.visibility) {
97 div.style.visibility = null;
98 window.resizeBy(0, -(div.clientHeight + buttonsHeight));
99 $("detailsButton").innerHTML = labels["Show Details"];
101 div.style.visibility = 'visible;';
102 window.resizeBy(0, (div.clientHeight + buttonsHeight));
103 $("detailsButton").innerHTML = labels["Hide Details"];
109 function toggleCycleVisibility(node, nodeName, hiddenValue) {
110 var spanNode = $(nodeName);
111 var newVisibility = ((node.value == hiddenValue) ? null : 'visible;');
112 spanNode.style.visibility = newVisibility;
114 if (nodeName == 'cycleSelectionFirstLevel') {
115 var otherSpanNode = $('cycleSelectionSecondLevel');
118 otherSpanNode.superVisibility = otherSpanNode.style.visibility;
119 otherSpanNode.style.visibility = null;
123 otherSpanNode.style.visibility = otherSpanNode.superVisibility;
124 otherSpanNode.superVisibility = null;
129 function addContact(tag, fullContactName, contactId, contactName, contactEmail) {
130 var uids = $('uixselector-participants-uidList');
131 log ("contactId: " + contactId);
134 var re = new RegExp("(^|,)" + contactId + "($|,)");
136 log ("uids: " + uids);
137 if (!re.test(uids.value))
139 log ("no match... realling adding");
140 if (uids.value.length > 0)
141 uids.value += ',' + contactId;
143 uids.value = contactId;
145 var names = $('uixselector-participants-display');
146 names.innerHTML += ('<li onmousedown="return false;"'
147 + ' onclick="onRowClick(event);"><img src="'
148 + ResourcesURL + '/abcard.gif" />'
149 + contactName + '</li>');
152 log ("match... ignoring contact");
158 function onTimeControlCheck(checkBox) {
159 var inputs = checkBox.parentNode.getElementsByTagName("input");
160 var selects = checkBox.parentNode.getElementsByTagName("select");
161 for (var i = 0; i < inputs.length; i++)
162 if (inputs[i] != checkBox)
163 inputs[i].disabled = !checkBox.checked;
164 for (var i = 0; i < selects.length; i++)
165 if (selects[i] != checkBox)
166 selects[i].disabled = !checkBox.checked;
169 function saveEvent(sender) {
170 if (validateTaskEditor())
171 document.forms['editform'].submit();
176 function startDayAsShortString() {
177 return dayAsShortDateString($('startTime_date'));
180 function dueDayAsShortString() {
181 return dayAsShortDateString($('dueTime_date'));
184 this._getDate = function(which) {
185 var date = window.timeWidgets[which]['date'].valueAsDate();
186 date.setHours( window.timeWidgets[which]['hour'].value );
187 date.setMinutes( window.timeWidgets[which]['minute'].value );
192 this._getShadowDate = function(which) {
193 var date = window.timeWidgets[which]['date'].getAttribute("shadow-value").asDate();
194 var intValue = parseInt(window.timeWidgets[which]['hour'].getAttribute("shadow-value"));
195 date.setHours(intValue);
196 intValue = parseInt(window.timeWidgets[which]['minute'].getAttribute("shadow-value"));
197 date.setMinutes(intValue);
198 // window.alert("shadow: " + date);
203 this.getStartDate = function() {
204 return this._getDate('start');
207 this.getDueDate = function() {
208 return this._getDate('due');
211 this.getShadowStartDate = function() {
212 return this._getShadowDate('start');
215 this.getShadowDueDate = function() {
216 return this._getShadowDate('due');
219 this._setDate = function(which, newDate) {
220 window.timeWidgets[which]['date'].setValueAsDate(newDate);
221 window.timeWidgets[which]['hour'].value = newDate.getHours();
222 var minutes = newDate.getMinutes();
224 minutes += (15 - minutes % 15);
225 window.timeWidgets[which]['minute'].value = minutes;
228 this.setStartDate = function(newStartDate) {
229 this._setDate('start', newStartDate);
232 this.setDueDate = function(newDueDate) {
233 // window.alert(newDueDate);
234 this._setDate('due', newDueDate);
237 this.onAdjustDueTime = function(event) {
238 if (!window.timeWidgets['due']['date'].disabled) {
239 var dateDelta = (window.getStartDate().valueOf()
240 - window.getShadowStartDate().valueOf());
241 var newDueDate = new Date(window.getDueDate().valueOf() + dateDelta);
242 window.setDueDate(newDueDate);
244 window.timeWidgets['start']['date'].updateShadowValue();
245 window.timeWidgets['start']['hour'].updateShadowValue();
246 window.timeWidgets['start']['minute'].updateShadowValue();
249 this.initTimeWidgets = function (widgets) {
250 this.timeWidgets = widgets;
252 Event.observe(widgets['start']['date'], "change", this.onAdjustDueTime, false);
253 Event.observe(widgets['start']['hour'], "change", this.onAdjustDueTime, false);
254 Event.observe(widgets['start']['minute'], "change", this.onAdjustDueTime, false);
257 function onStatusListChange(event) {
258 var value = $("statusList").value;
259 var statusTimeDate = $("statusTime_date");
260 var statusPercent = $("statusPercent");
262 if (value == "WONoSelectionString") {
263 statusTimeDate.disabled = true;
264 statusPercent.disabled = true;
265 statusPercent.value = "";
267 else if (value == "0") {
268 statusTimeDate.disabled = true;
269 statusPercent.disabled = false;
271 else if (value == "1") {
272 statusTimeDate.disabled = true;
273 statusPercent.disabled = false;
275 else if (value == "2") {
276 statusTimeDate.disabled = false;
277 statusPercent.disabled = false;
278 statusPercent.value = "100";
280 else if (value == "3") {
281 statusTimeDate.disabled = true;
282 statusPercent.disabled = true;
285 statusTimeDate.disabled = true;
289 function initializeStatusLine() {
290 var statusList = $("statusList");
291 Event.observe(statusList, "mouseup", onStatusListChange, false);
294 function onTaskEditorLoad() {
295 initializeStatusLine();