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