]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalInlineAptView.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1029 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Scheduler / UIxCalInlineAptView.m
1 /*
2  Copyright (C) 2000-2004 SKYRIX Software AG
3  
4  This file is part of OGo
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 // $Id$
22
23 #import <math.h>
24
25 #import <Foundation/NSDictionary.h>
26
27 #import <NGObjWeb/NGObjWeb.h>
28
29 @interface UIxCalInlineAptView : WOComponent
30 {
31   NSDictionary *appointment;
32   id formatter;
33   id tooltipFormatter;
34   id url;
35   id style;
36   id queryDictionary;
37   id referenceDate;
38   int dayStartHour;
39   int dayEndHour;
40   BOOL canAccess;
41 }
42
43 @end
44
45 #include "common.h"
46 #include <SOGoUI/SOGoAptFormatter.h>
47 #include <SOGo/SOGoUser.h>
48 #include <NGObjWeb/WOContext+SoObjects.h>
49
50 @implementation UIxCalInlineAptView
51
52 - (id) init
53 {
54   if ((self = [super init]))
55     {
56       dayStartHour = 0;
57       dayEndHour = 24;
58       appointment = nil;
59     }
60
61   return self;
62 }
63
64 - (void) dealloc
65 {
66   [appointment release];
67   [formatter release];
68   [tooltipFormatter release];
69   [url release];
70   [style release];
71   [queryDictionary release];
72   [referenceDate release];
73   [super dealloc];
74 }
75
76 - (void) setAppointment: (NSDictionary *) _appointment
77 {
78   ASSIGN(appointment, _appointment);
79 }
80
81 - (NSDictionary *) appointment
82 {
83   return appointment;
84 }
85
86 - (void) setDayStartHour: (unsigned int) anHour
87 {
88   dayStartHour = anHour;
89 }
90
91 - (void) setDayEndHour: (unsigned int) anHour
92 {
93   dayEndHour = anHour;
94 }
95
96 - (void) setFormatter: (id) _formatter
97 {
98   ASSIGN(formatter, _formatter);
99 }
100
101 - (id) formatter
102 {
103   return formatter;
104 }
105
106 - (void) setTooltipFormatter: (id) _tooltipFormatter
107 {
108   ASSIGN(tooltipFormatter, _tooltipFormatter);
109 }
110
111 - (id) tooltipFormatter
112 {
113   return tooltipFormatter;
114 }
115
116 - (void) setUrl: (id) _url
117 {
118   ASSIGN(url, _url);
119 }
120
121 - (id) url
122 {
123   return url;
124 }
125
126 - (void) setStyle: (id) _style 
127 {
128   NSMutableString *ms;
129   NSNumber *prio;
130   NSString *s;
131   NSString *email;
132
133   if (_style)
134     ms = [NSMutableString stringWithString: _style];
135   else
136     ms = (NSMutableString *)[NSMutableString string];
137
138   if ((prio = [appointment valueForKey:@"priority"])) {
139     [ms appendFormat:@" apt_prio%@", prio];
140   }
141   email = [[[self context] activeUser] email];
142   if ((s = [appointment valueForKey:@"orgmail"])) {
143     if ([s rangeOfString:email].length > 0) {
144       [ms appendString:@" apt_organizer"];
145     }
146     else {
147       [ms appendString:@" apt_other"];
148     }
149   }
150   if ((s = [appointment valueForKey:@"partmails"])) {
151     if ([s rangeOfString:email].length > 0) {
152       [ms appendString:@" apt_participant"];
153     }
154     else {
155       [ms appendString:@" apt_nonparticipant"];
156     }
157   }
158   ASSIGNCOPY(style, ms);
159 }
160
161 - (id)style {
162   return style;
163 }
164
165 - (void) setQueryDictionary: (id) _queryDictionary
166 {
167   ASSIGN(queryDictionary, _queryDictionary);
168 }
169
170 - (id) queryDictionary
171 {
172   return queryDictionary;
173 }
174
175 - (void) setReferenceDate: (id) _referenceDate
176 {
177   ASSIGN(referenceDate, _referenceDate);
178 }
179
180 - (id) referenceDate
181 {
182   return referenceDate;
183 }
184
185 - (void) setCanAccess: (BOOL) _canAccess
186 {
187   canAccess = _canAccess;
188 }
189
190 - (BOOL) canAccess
191 {
192   return canAccess;
193 }
194
195 - (NSString *) displayClasses
196 {
197   NSTimeInterval secondsStart, secondsEnd, delta;
198   NSCalendarDate *startDate;
199   int deltaStart, deltaLength;
200
201   startDate = [appointment objectForKey: @"startDate"];
202   secondsStart = [startDate timeIntervalSince1970];
203   secondsEnd = [[appointment objectForKey: @"endDate"] timeIntervalSince1970];
204   delta = (secondsEnd - [startDate timeIntervalSince1970]) / 60;
205   deltaLength = delta / 15;
206   if (((int) delta % 15) > 0)
207     deltaLength += 1;
208
209   deltaStart = (([startDate hourOfDay] * 60 + [startDate minuteOfHour]
210                  - dayStartHour * 60) / 15);
211
212   return [NSString stringWithFormat: @"appointment starts%d lasts%d",
213                    deltaStart, deltaLength, [startDate dayOfWeek]];
214 }
215
216 - (NSString *) innerDisplayClasses
217 {
218   return [NSString stringWithFormat: @"appointmentInside ownerIs%@",
219                    [appointment objectForKey: @"owner"]];
220 }
221
222 - (NSString *) displayStyle
223 {
224   NSCalendarDate *startDate, *endDate, *dayStart, *dayEnd;
225   int sSeconds, eSeconds, deltaMinutes;
226   unsigned int height;
227   NSTimeZone *uTZ;
228
229   uTZ = [referenceDate timeZone];
230   dayStart = [referenceDate beginOfDay];
231   dayEnd = [referenceDate endOfDay];
232
233   sSeconds = [[appointment objectForKey: @"startdate"] intValue];
234   eSeconds = [[appointment objectForKey: @"enddate"] intValue];
235   startDate = [NSCalendarDate dateWithTimeIntervalSince1970: sSeconds];
236   [startDate setTimeZone: uTZ];
237   if ([startDate earlierDate: dayStart] == startDate)
238     startDate = dayStart;
239   endDate = [NSCalendarDate dateWithTimeIntervalSince1970: eSeconds];
240   [endDate setTimeZone: uTZ];
241   if ([endDate earlierDate: dayEnd] == dayEnd)
242     endDate = dayEnd;
243
244   deltaMinutes = (([endDate hourOfDay] - [startDate hourOfDay]) * 60
245                   + [endDate minuteOfHour] - [startDate minuteOfHour]);
246   height = ceil(deltaMinutes / 15) * 25;
247
248   return [NSString stringWithFormat: @"height: %d%%;", height];
249 }
250
251 /* helpers */
252
253 - (NSString *) title
254 {
255   return [formatter stringForObjectValue: appointment
256                     referenceDate: [self referenceDate]];
257 }
258
259 - (NSString *) tooltip
260 {
261   return [tooltipFormatter stringForObjectValue: appointment
262                            referenceDate: [self referenceDate]];
263 }
264
265 @end