]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/UIxTaskEditor.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1071 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / UIxTaskEditor.js
1 var contactSelectorAction = 'calendars-contacts';
2
3 addEvent(window, 'DOMContentLoaded', onTaskEditorLoad);
4
5 function uixEarlierDate(date1, date2) {
6   // can this be done in a sane way?
7   //   cuicui = 'year';
8   if (date1 && date2) {
9     if (date1.getYear()  < date2.getYear()) return date1;
10     if (date1.getYear()  > date2.getYear()) return date2;
11   // same year
12   //   cuicui += '/month';
13     if (date1.getMonth() < date2.getMonth()) return date1;
14     if (date1.getMonth() > date2.getMonth()) return date2;
15   //   // same month
16   //   cuicui += '/date';
17     if (date1.getDate() < date2.getDate()) return date1;
18     if (date1.getDate() > date2.getDate()) return date2;
19   }
20   // same day
21   return null;
22 }
23
24 function validateDate(date, label) {
25   var result, dateValue;
26
27   dateValue = date.calendar.prs_date(date.value);
28   if (date.value.length != 10 || !dateValue) {
29     alert(label.decodeEntities());
30     result = false;
31   } else
32     result = dateValue;
33
34   return result;
35 }
36
37 function validateTaskEditor() {
38   var e, startdate, enddate, tmpdate;
39
40   e = document.getElementById('summary');
41   if (e.value.length == 0
42       && !confirm(labels.validate_notitle.decodeEntities()))
43     return false;
44
45   e = document.getElementById('startTime_date');
46   if (!e.disabled) {
47     startdate = validateDate(e, labels.validate_invalid_startdate);
48     if (!startdate)
49       return false;
50   }
51
52   e = document.getElementById('dueTime_date');
53   if (!e.disabled) {
54     enddate = validateDate(e, labels.validate_invalid_enddate);
55     if (!enddate)
56       return false;
57   }
58
59   if (startdate && enddate) {
60     tmpdate = uixEarlierDate(startdate, enddate);
61     if (tmpdate == enddate) {
62       //     window.alert(cuicui);
63       alert(labels.validate_endbeforestart.decodeEntities());
64       return false;
65     }
66     else if (tmpdate == null /* means: same date */) {
67       // TODO: check time
68       var start, end;
69       
70       start = parseInt(document.forms[0]['startTime_time_hour'].value);
71       end = parseInt(document.forms[0]['dueTime_time_hour'].value);
72       
73       if (start > end) {
74         alert(labels.validate_endbeforestart.decodeEntities());
75         return false;
76       }
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);
80         if (start > end) {
81           alert(labels.validate_endbeforestart.decodeEntities());
82           return false;
83         }
84       }
85     }
86   }
87
88   return true;
89 }
90
91 function toggleDetails() {
92   var div = $("details");
93   var buttons = $("buttons");
94   var buttonsHeight = buttons.clientHeight * 3;
95
96   if (div.style.visibility) {
97     div.style.visibility = null;
98     window.resizeBy(0, -(div.clientHeight + buttonsHeight));
99     $("detailsButton").innerHTML = labels["Show Details"];
100   } else {
101     div.style.visibility = 'visible;';
102     window.resizeBy(0, (div.clientHeight + buttonsHeight));
103     $("detailsButton").innerHTML = labels["Hide Details"];
104   }
105
106   return false;
107 }
108
109 function toggleCycleVisibility(node, nodeName, hiddenValue) {
110   var spanNode = $(nodeName);
111   var newVisibility = ((node.value == hiddenValue) ? null : 'visible;');
112   spanNode.style.visibility = newVisibility;
113
114   if (nodeName == 'cycleSelectionFirstLevel') {
115     var otherSpanNode = $('cycleSelectionSecondLevel');
116     if (!newVisibility)
117       {
118         otherSpanNode.superVisibility = otherSpanNode.style.visibility;
119         otherSpanNode.style.visibility = null;
120       }
121     else
122       {
123         otherSpanNode.style.visibility = otherSpanNode.superVisibility;
124         otherSpanNode.superVisibility = null;
125       }
126   }
127 }
128
129 function addContact(tag, fullContactName, contactId, contactName, contactEmail) {
130   var uids = $('uixselector-participants-uidList');
131   log ("contactId: " + contactId);
132   if (contactId)
133     {
134       var re = new RegExp("(^|,)" + contactId + "($|,)");
135
136       log ("uids: " + uids);
137       if (!re.test(uids.value))
138         {
139           log ("no match... realling adding");
140           if (uids.value.length > 0)
141             uids.value += ',' + contactId;
142           else
143             uids.value = contactId;
144
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>');
150         }
151       else
152         log ("match... ignoring contact");
153     }
154
155   return false;
156 }
157
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;
167 }
168
169 function saveEvent(sender) {
170   if (validateTaskEditor())
171     document.forms['editform'].submit();
172
173   return false;
174 }
175
176 function startDayAsShortString() {
177   return dayAsShortDateString($('startTime_date'));
178 }
179
180 function dueDayAsShortString() {
181   return dayAsShortDateString($('dueTime_date'));
182 }
183
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 );
188
189   return date;
190 }
191
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);
199
200   return date;
201 }
202
203 this.getStartDate = function() {
204   return this._getDate('start');
205 }
206
207 this.getDueDate = function() {
208   return this._getDate('due');
209 }
210
211 this.getShadowStartDate = function() {
212   return this._getShadowDate('start');
213 }
214
215 this.getShadowDueDate = function() {
216   return this._getShadowDate('due');
217 }
218
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();
223   if (minutes % 15)
224     minutes += (15 - minutes % 15);
225   window.timeWidgets[which]['minute'].value = minutes;
226 }
227
228 this.setStartDate = function(newStartDate) {
229   this._setDate('start', newStartDate);
230 }
231
232 this.setDueDate = function(newDueDate) {
233 //   window.alert(newDueDate);
234   this._setDate('due', newDueDate);
235 }
236
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);
243   }
244   window.timeWidgets['start']['date'].updateShadowValue();
245   window.timeWidgets['start']['hour'].updateShadowValue();
246   window.timeWidgets['start']['minute'].updateShadowValue();
247 }
248
249 this.initTimeWidgets = function (widgets) {
250   this.timeWidgets = widgets;
251
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);
255 }
256
257 function onStatusListChange(event) {
258    var value = $("statusList").value;
259    var statusTimeDate = $("statusTime_date");
260    var statusPercent = $("statusPercent");
261
262    if (value == "WONoSelectionString") {
263       statusTimeDate.disabled = true;
264       statusPercent.disabled = true;
265       statusPercent.value = "";
266    }
267    else if (value == "0") {
268       statusTimeDate.disabled = true;
269       statusPercent.disabled = false;
270    }
271    else if (value == "1") {
272       statusTimeDate.disabled = true;
273       statusPercent.disabled = false;
274    }
275    else if (value == "2") {
276       statusTimeDate.disabled = false;
277       statusPercent.disabled = false;
278       statusPercent.value = "100";
279    }
280    else if (value == "3") {
281       statusTimeDate.disabled = true;
282       statusPercent.disabled = true;
283    }
284    else {
285       statusTimeDate.disabled = true;
286    }
287 }
288
289 function initializeStatusLine() {
290    var statusList = $("statusList");
291    Event.observe(statusList, "mouseup", onStatusListChange, false);
292 }
293
294 function onTaskEditorLoad() {
295    initializeStatusLine();
296 }