]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/UIxAppointmentEditor.js
initial sync
[scalable-opengroupware.org] / UI / WebServerResources / UIxAppointmentEditor.js
1 /*
2  Copyright (C) 2005 SKYRIX Software AG
3  
4  This file is part of OpenGroupware.org.
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.getYear()  < date2.getYear()) return date1;
28   if (date1.getYear()  > date2.getYear()) return date2;
29   // same year
30 //   cuicui += '/month';
31   if (date1.getMonth() < date2.getMonth()) return date1;
32   if (date1.getMonth() > date2.getMonth()) return date2;
33 //   // same month
34 //   cuicui += '/date';
35   if (date1.getDate() < date2.getDate()) return date1;
36   if (date1.getDate() > date2.getDate()) return date2;
37   // same day
38   return null;
39 }
40
41 function validateAptEditor() {
42   var e, startdate, enddate, tmpdate;
43
44   e = $('summary');
45   if (e.value.length == 0) {
46     if (!confirm(labels.validate_notitle.decodeEntities()))
47       return false;
48   }
49
50   e = $('startTime_date');
51   if (e.value.length != 10) {
52     alert(labels.validate_invalid_startdate.decodeEntities());
53     return false;
54   }
55   startdate = e.calendar.prs_date(e.value);
56   if (startdate == null) {
57     alert(labels.validate_invalid_startdate.decodeEntities());
58     return false;
59   }
60       
61   e = $('endTime_date');
62   if (e.value.length != 10) {
63     alert(labels.validate_invalid_enddate.decodeEntities());
64     return false;
65   }
66   enddate = e.calendar.prs_date(e.value);
67   if (enddate == null) {
68     alert(labels.validate_invalid_enddate.decodeEntities());
69     return false;
70   }
71 //   cuicui = '';
72   tmpdate = uixEarlierDate(startdate, enddate);
73   if (tmpdate == enddate) {
74 //     window.alert(cuicui);
75     alert(labels.validate_endbeforestart.decodeEntities());
76     return false;
77   }
78   else if (tmpdate == null /* means: same date */) {
79     // TODO: check time
80     var start, end;
81     
82     start = parseInt(document.forms[0]['startTime_time_hour'].value);
83     end = parseInt(document.forms[0]['endTime_time_hour'].value);
84
85     if (start > end) {
86       alert(labels.validate_endbeforestart.decodeEntities());
87       return false;
88     }
89     else if (start == end) {
90       start = parseInt(document.forms[0]['startTime_time_minute'].value);
91       end = parseInt(document.forms[0]['endTime_time_minute'].value);
92       if (start > end) {
93         alert(labels.validate_endbeforestart.decodeEntities());
94         return false;
95       }
96     }
97   }
98
99   return true;
100 }
101
102 function toggleDetails() {
103   var div = $("details");
104   var buttons = $("buttons");
105   var buttonsHeight = buttons.clientHeight * 3;
106
107   if (div.style.visibility) {
108     div.style.visibility = null;
109     window.resizeBy(0, -(div.clientHeight + buttonsHeight));
110     $("detailsButton").innerHTML = labels["Show Details"];
111   } else {
112     div.style.visibility = 'visible;';
113     window.resizeBy(0, (div.clientHeight + buttonsHeight));
114     $("detailsButton").innerHTML = labels["Hide Details"];
115   }
116
117   return false;
118 }
119
120 function toggleCycleVisibility(node, nodeName, hiddenValue) {
121   var spanNode = $(nodeName);
122   var newVisibility = ((node.value == hiddenValue) ? null : 'visible;');
123   spanNode.style.visibility = newVisibility;
124
125   if (nodeName == 'cycleSelectionFirstLevel') {
126     var otherSpanNode = $('cycleSelectionSecondLevel');
127     if (!newVisibility)
128       {
129         otherSpanNode.superVisibility = otherSpanNode.style.visibility;
130         otherSpanNode.style.visibility = null;
131       }
132     else
133       {
134         otherSpanNode.style.visibility = otherSpanNode.superVisibility;
135         otherSpanNode.superVisibility = null;
136       }
137   }
138 }
139
140 function addContact(tag, fullContactName, contactId, contactName, contactEmail)
141 {
142   var uids = $('uixselector-participants-uidList');
143   log ("contactId: " + contactId);
144   if (contactId)
145     {
146       var re = new RegExp("(^|,)" + contactId + "($|,)");
147
148       log ("uids: " + uids);
149       if (!re.test(uids.value))
150         {
151           log ("no match... realling adding");
152           if (uids.value.length > 0)
153             uids.value += ',' + contactId;
154           else
155             uids.value = contactId;
156
157           var names = $('uixselector-participants-display');
158           names.innerHTML += ('<li onmousedown="return false;"'
159                               + ' onclick="onRowClick(event);"><img src="'
160                               + ResourcesURL + '/abcard.gif" />'
161                               + contactName + '</li>');
162         }
163       else
164         log ("match... ignoring contact");
165     }
166
167   return false;
168 }
169
170 function saveEvent(sender) {
171   if (validateAptEditor())
172     document.forms['editform'].submit();
173
174   return false;
175 }
176
177 function startDayAsShortString() {
178   return $('startTime_date').valueAsShortDateString();
179 }
180
181 function endDayAsShortString() {
182   return $('endTime_date').valueAsShortDateString();
183 }
184
185 this._getDate = function(which) {
186   var date = window.timeWidgets[which]['date'].valueAsDate();
187   date.setHours( window.timeWidgets[which]['hour'].value );
188   date.setMinutes( window.timeWidgets[which]['minute'].value );
189
190   return date;
191 }
192
193 this._getShadowDate = function(which) {
194   var date = window.timeWidgets[which]['date'].getAttribute("shadow-value").asDate();
195   var intValue = parseInt(window.timeWidgets[which]['hour'].getAttribute("shadow-value"));
196   date.setHours(intValue);
197   intValue = parseInt(window.timeWidgets[which]['minute'].getAttribute("shadow-value"));
198   date.setMinutes(intValue);
199 //   window.alert("shadow: " + date);
200
201   return date;
202 }
203
204 this.getStartDate = function() {
205   return this._getDate('start');
206 }
207
208 this.getEndDate = function() {
209   return this._getDate('end');
210 }
211
212 this.getShadowStartDate = function() {
213   return this._getShadowDate('start');
214 }
215
216 this.getShadowEndDate = function() {
217   return this._getShadowDate('end');
218 }
219
220 this._setDate = function(which, newDate) {
221   window.timeWidgets[which]['date'].setValueAsDate(newDate);
222   window.timeWidgets[which]['hour'].value = newDate.getHours();
223   var minutes = newDate.getMinutes();
224   if (minutes % 15)
225     minutes += (15 - minutes % 15);
226   window.timeWidgets[which]['minute'].value = minutes;
227 }
228
229 this.setStartDate = function(newStartDate) {
230   this._setDate('start', newStartDate);
231 }
232
233 this.setEndDate = function(newEndDate) {
234 //   window.alert(newEndDate);
235   this._setDate('end', newEndDate);
236 }
237
238 this.onAdjustEndTime = function(event) {
239   var dateDelta = (window.getStartDate().valueOf()
240                    - window.getShadowStartDate().valueOf());
241 //   window.alert(window.getEndDate().valueOf() + '  ' + dateDelta);
242   var newEndDate = new Date(window.getEndDate().valueOf() + dateDelta);
243   window.setEndDate(newEndDate);
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   widgets['start']['date'].addEventListener("change", this.onAdjustEndTime, false);
253   widgets['start']['hour'].addEventListener("change", this.onAdjustEndTime, false);
254   widgets['start']['minute'].addEventListener("change", this.onAdjustEndTime, false);
255 }