1 var contactSelectorAction = 'calendars-contacts';
3 function uixEarlierDate(date1, date2) {
4 // can this be done in a sane way?
7 if (date1.getYear() < date2.getYear()) return date1;
8 if (date1.getYear() > date2.getYear()) return date2;
10 // cuicui += '/month';
11 if (date1.getMonth() < date2.getMonth()) return date1;
12 if (date1.getMonth() > date2.getMonth()) return date2;
15 if (date1.getDate() < date2.getDate()) return date1;
16 if (date1.getDate() > date2.getDate()) return date2;
22 function validateDate(date, label) {
23 var result, dateValue;
25 dateValue = date.calendar.prs_date(date.value);
26 if (date.value.length != 10 || !dateValue) {
27 alert(label.decodeEntities());
35 function validateTaskEditor() {
36 var e, startdate, enddate, tmpdate;
38 e = document.getElementById('summary');
39 if (e.value.length == 0
40 && !confirm(labels.validate_notitle.decodeEntities()))
43 e = document.getElementById('startTime_date');
45 startdate = validateDate(e, labels.validate_invalid_startdate);
50 e = document.getElementById('dueTime_date');
52 enddate = validateDate(e, labels.validate_invalid_enddate);
57 if (startdate && enddate) {
58 tmpdate = uixEarlierDate(startdate, enddate);
59 if (tmpdate == enddate) {
60 // window.alert(cuicui);
61 alert(labels.validate_endbeforestart.decodeEntities());
64 else if (tmpdate == null /* means: same date */) {
68 start = parseInt(document.forms[0]['startTime_time_hour'].value);
69 end = parseInt(document.forms[0]['dueTime_time_hour'].value);
72 alert(labels.validate_endbeforestart.decodeEntities());
75 else if (start == end) {
76 start = parseInt(document.forms[0]['startTime_time_minute'].value);
77 end = parseInt(document.forms[0]['dueTime_time_minute'].value);
79 alert(labels.validate_endbeforestart.decodeEntities());
89 function toggleDetails() {
90 var div = $("details");
91 var buttons = $("buttons");
92 var buttonsHeight = buttons.clientHeight * 3;
94 if (div.style.visibility) {
95 div.style.visibility = null;
96 window.resizeBy(0, -(div.clientHeight + buttonsHeight));
97 $("detailsButton").innerHTML = labels["Show Details"];
99 div.style.visibility = 'visible;';
100 window.resizeBy(0, (div.clientHeight + buttonsHeight));
101 $("detailsButton").innerHTML = labels["Hide Details"];
107 function toggleCycleVisibility(node, nodeName, hiddenValue) {
108 var spanNode = $(nodeName);
109 var newVisibility = ((node.value == hiddenValue) ? null : 'visible;');
110 spanNode.style.visibility = newVisibility;
112 if (nodeName == 'cycleSelectionFirstLevel') {
113 var otherSpanNode = $('cycleSelectionSecondLevel');
116 otherSpanNode.superVisibility = otherSpanNode.style.visibility;
117 otherSpanNode.style.visibility = null;
121 otherSpanNode.style.visibility = otherSpanNode.superVisibility;
122 otherSpanNode.superVisibility = null;
127 function addContact(tag, fullContactName, contactId, contactName, contactEmail) {
128 var uids = $('uixselector-participants-uidList');
129 log ("contactId: " + contactId);
132 var re = new RegExp("(^|,)" + contactId + "($|,)");
134 log ("uids: " + uids);
135 if (!re.test(uids.value))
137 log ("no match... realling adding");
138 if (uids.value.length > 0)
139 uids.value += ',' + contactId;
141 uids.value = contactId;
143 var names = $('uixselector-participants-display');
144 names.innerHTML += ('<li onmousedown="return false;"'
145 + ' onclick="onRowClick(event);"><img src="'
146 + ResourcesURL + '/abcard.gif" />'
147 + contactName + '</li>');
150 log ("match... ignoring contact");
156 function onTimeControlCheck(checkBox) {
157 var inputs = checkBox.parentNode.getElementsByTagName("input");
158 var selects = checkBox.parentNode.getElementsByTagName("select");
159 for (var i = 0; i < inputs.length; i++)
160 if (inputs[i] != checkBox)
161 inputs[i].disabled = !checkBox.checked;
162 for (var i = 0; i < selects.length; i++)
163 if (selects[i] != checkBox)
164 selects[i].disabled = !checkBox.checked;
167 function saveEvent(sender) {
168 if (validateTaskEditor())
169 document.forms['editform'].submit();
174 function startDayAsShortString() {
175 return dayAsShortDateString($('startTime_date'));
178 function dueDayAsShortString() {
179 return dayAsShortDateString($('dueTime_date'));
182 this._getDate = function(which) {
183 var date = window.timeWidgets[which]['date'].valueAsDate();
184 date.setHours( window.timeWidgets[which]['hour'].value );
185 date.setMinutes( window.timeWidgets[which]['minute'].value );
190 this._getShadowDate = function(which) {
191 var date = window.timeWidgets[which]['date'].getAttribute("shadow-value").asDate();
192 var intValue = parseInt(window.timeWidgets[which]['hour'].getAttribute("shadow-value"));
193 date.setHours(intValue);
194 intValue = parseInt(window.timeWidgets[which]['minute'].getAttribute("shadow-value"));
195 date.setMinutes(intValue);
196 // window.alert("shadow: " + date);
201 this.getStartDate = function() {
202 return this._getDate('start');
205 this.getDueDate = function() {
206 return this._getDate('due');
209 this.getShadowStartDate = function() {
210 return this._getShadowDate('start');
213 this.getShadowDueDate = function() {
214 return this._getShadowDate('due');
217 this._setDate = function(which, newDate) {
218 window.timeWidgets[which]['date'].setValueAsDate(newDate);
219 window.timeWidgets[which]['hour'].value = newDate.getHours();
220 var minutes = newDate.getMinutes();
222 minutes += (15 - minutes % 15);
223 window.timeWidgets[which]['minute'].value = minutes;
226 this.setStartDate = function(newStartDate) {
227 this._setDate('start', newStartDate);
230 this.setDueDate = function(newDueDate) {
231 // window.alert(newDueDate);
232 this._setDate('due', newDueDate);
235 this.onAdjustDueTime = function(event) {
236 if (!window.timeWidgets['due']['date'].disabled) {
237 var dateDelta = (window.getStartDate().valueOf()
238 - window.getShadowStartDate().valueOf());
239 var newDueDate = new Date(window.getDueDate().valueOf() + dateDelta);
240 window.setDueDate(newDueDate);
242 window.timeWidgets['start']['date'].updateShadowValue();
243 window.timeWidgets['start']['hour'].updateShadowValue();
244 window.timeWidgets['start']['minute'].updateShadowValue();
247 this.initTimeWidgets = function (widgets) {
248 this.timeWidgets = widgets;
250 Event.observe(widgets['start']['date'], "change", this.onAdjustDueTime, false);
251 Event.observe(widgets['start']['hour'], "change", this.onAdjustDueTime, false);
252 Event.observe(widgets['start']['minute'], "change", this.onAdjustDueTime, false);
255 function onStatusListChange(event) {
256 var value = $("statusList").value;
257 var statusTimeDate = $("statusTime_date");
258 var statusPercent = $("statusPercent");
260 if (value == "WONoSelectionString") {
261 statusTimeDate.disabled = true;
262 statusPercent.disabled = true;
263 statusPercent.value = "";
265 else if (value == "0") {
266 statusTimeDate.disabled = true;
267 statusPercent.disabled = false;
269 else if (value == "1") {
270 statusTimeDate.disabled = true;
271 statusPercent.disabled = false;
273 else if (value == "2") {
274 statusTimeDate.disabled = false;
275 statusPercent.disabled = false;
276 statusPercent.value = "100";
278 else if (value == "3") {
279 statusTimeDate.disabled = true;
280 statusPercent.disabled = true;
283 statusTimeDate.disabled = true;
287 function initializeStatusLine() {
288 var statusList = $("statusList");
289 Event.observe(statusList, "mouseup", onStatusListChange, false);
292 function onTaskEditorLoad() {
293 initializeStatusLine();
296 addEvent(window, 'load', onTaskEditorLoad);