]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/UIxTaskEditor.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1017 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / UIxTaskEditor.js
1 /*
2   Copyright (C) 2005 SKYRIX Software AG
3  
4   This file is part of SOGo.
5  
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
9   later version.
10  
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.
15  
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
19   02111-1307, USA.
20 */
21
22 var contactSelectorAction = 'calendars-contacts';
23
24 function uixEarlierDate(date1, date2) {
25   // can this be done in a sane way?
26   //   cuicui = 'year';
27   if (date1 && date2) {
28     if (date1.getYear()  < date2.getYear()) return date1;
29     if (date1.getYear()  > date2.getYear()) return date2;
30   // same year
31   //   cuicui += '/month';
32     if (date1.getMonth() < date2.getMonth()) return date1;
33     if (date1.getMonth() > date2.getMonth()) return date2;
34   //   // same month
35   //   cuicui += '/date';
36     if (date1.getDate() < date2.getDate()) return date1;
37     if (date1.getDate() > date2.getDate()) return date2;
38   }
39   // same day
40   return null;
41 }
42
43 function validateDate(date, label) {
44   var result, dateValue;
45
46   dateValue = date.calendar.prs_date(date.value);
47   if (date.value.length != 10 || !dateValue) {
48     alert(label.decodeEntities());
49     result = false;
50   } else
51     result = dateValue;
52
53   return result;
54 }
55
56 function validateTaskEditor() {
57   var e, startdate, enddate, tmpdate;
58
59   e = document.getElementById('summary');
60   if (e.value.length == 0
61       && !confirm(labels.validate_notitle.decodeEntities()))
62     return false;
63
64   e = document.getElementById('startTime_date');
65   if (!e.disabled) {
66     startdate = validateDate(e, labels.validate_invalid_startdate);
67     if (!startdate)
68       return false;
69   }
70
71   e = document.getElementById('dueTime_date');
72   if (!e.disabled) {
73     enddate = validateDate(e, labels.validate_invalid_enddate);
74     if (!enddate)
75       return false;
76   }
77
78   if (startdate && enddate) {
79     tmpdate = uixEarlierDate(startdate, enddate);
80     if (tmpdate == enddate) {
81       //     window.alert(cuicui);
82       alert(labels.validate_endbeforestart.decodeEntities());
83       return false;
84     }
85     else if (tmpdate == null /* means: same date */) {
86       // TODO: check time
87       var start, end;
88       
89       start = parseInt(document.forms[0]['startTime_time_hour'].value);
90       end = parseInt(document.forms[0]['dueTime_time_hour'].value);
91       
92       if (start > end) {
93         alert(labels.validate_endbeforestart.decodeEntities());
94         return false;
95       }
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);
99         if (start > end) {
100           alert(labels.validate_endbeforestart.decodeEntities());
101           return false;
102         }
103       }
104     }
105   }
106
107   return true;
108 }
109
110 function toggleDetails() {
111   var div = $("details");
112   var buttons = $("buttons");
113   var buttonsHeight = buttons.clientHeight * 3;
114
115   if (div.style.visibility) {
116     div.style.visibility = null;
117     window.resizeBy(0, -(div.clientHeight + buttonsHeight));
118     $("detailsButton").innerHTML = labels["Show Details"];
119   } else {
120     div.style.visibility = 'visible;';
121     window.resizeBy(0, (div.clientHeight + buttonsHeight));
122     $("detailsButton").innerHTML = labels["Hide Details"];
123   }
124
125   return false;
126 }
127
128 function toggleCycleVisibility(node, nodeName, hiddenValue) {
129   var spanNode = $(nodeName);
130   var newVisibility = ((node.value == hiddenValue) ? null : 'visible;');
131   spanNode.style.visibility = newVisibility;
132
133   if (nodeName == 'cycleSelectionFirstLevel') {
134     var otherSpanNode = $('cycleSelectionSecondLevel');
135     if (!newVisibility)
136       {
137         otherSpanNode.superVisibility = otherSpanNode.style.visibility;
138         otherSpanNode.style.visibility = null;
139       }
140     else
141       {
142         otherSpanNode.style.visibility = otherSpanNode.superVisibility;
143         otherSpanNode.superVisibility = null;
144       }
145   }
146 }
147
148 function addContact(tag, fullContactName, contactId, contactName, contactEmail)
149 {
150   var uids = $('uixselector-participants-uidList');
151   log ("contactId: " + contactId);
152   if (contactId)
153     {
154       var re = new RegExp("(^|,)" + contactId + "($|,)");
155
156       log ("uids: " + uids);
157       if (!re.test(uids.value))
158         {
159           log ("no match... realling adding");
160           if (uids.value.length > 0)
161             uids.value += ',' + contactId;
162           else
163             uids.value = contactId;
164
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>');
170         }
171       else
172         log ("match... ignoring contact");
173     }
174
175   return false;
176 }
177
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;
187 }
188
189 function saveEvent(sender) {
190   if (validateTaskEditor())
191     document.forms['editform'].submit();
192
193   return false;
194 }
195
196 function startDayAsShortString() {
197   return dayAsShortDateString($('startTime_date'));
198 }
199
200 function dueDayAsShortString() {
201   return dayAsShortDateString($('dueTime_date'));
202 }
203
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 );
208
209   return date;
210 }
211
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);
219
220   return date;
221 }
222
223 this.getStartDate = function() {
224   return this._getDate('start');
225 }
226
227 this.getDueDate = function() {
228   return this._getDate('due');
229 }
230
231 this.getShadowStartDate = function() {
232   return this._getShadowDate('start');
233 }
234
235 this.getShadowDueDate = function() {
236   return this._getShadowDate('due');
237 }
238
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();
243   if (minutes % 15)
244     minutes += (15 - minutes % 15);
245   window.timeWidgets[which]['minute'].value = minutes;
246 }
247
248 this.setStartDate = function(newStartDate) {
249   this._setDate('start', newStartDate);
250 }
251
252 this.setDueDate = function(newDueDate) {
253 //   window.alert(newDueDate);
254   this._setDate('due', newDueDate);
255 }
256
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);
263   }
264   window.timeWidgets['start']['date'].updateShadowValue();
265   window.timeWidgets['start']['hour'].updateShadowValue();
266   window.timeWidgets['start']['minute'].updateShadowValue();
267 }
268
269 this.initTimeWidgets = function (widgets) {
270   this.timeWidgets = widgets;
271
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);
275 }