]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalInlineAptView.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1018 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 ownerIs%@ starts%d lasts%d",
213                    [appointment objectForKey: @"owner"],
214                    deltaStart, deltaLength, [startDate dayOfWeek]];
215 }
216
217 - (NSString *) innerDisplayClasses
218 {
219   return [NSString stringWithFormat: @"appointmentInside ownerIs%@",
220                    [appointment objectForKey: @"owner"]];
221 }
222
223 - (NSString *) displayStyle
224 {
225   NSCalendarDate *startDate, *endDate, *dayStart, *dayEnd;
226   int sSeconds, eSeconds, deltaMinutes;
227   unsigned int height;
228   NSTimeZone *uTZ;
229
230   uTZ = [referenceDate timeZone];
231   dayStart = [referenceDate beginOfDay];
232   dayEnd = [referenceDate endOfDay];
233
234   sSeconds = [[appointment objectForKey: @"startdate"] intValue];
235   eSeconds = [[appointment objectForKey: @"enddate"] intValue];
236   startDate = [NSCalendarDate dateWithTimeIntervalSince1970: sSeconds];
237   [startDate setTimeZone: uTZ];
238   if ([startDate earlierDate: dayStart] == startDate)
239     startDate = dayStart;
240   endDate = [NSCalendarDate dateWithTimeIntervalSince1970: eSeconds];
241   [endDate setTimeZone: uTZ];
242   if ([endDate earlierDate: dayEnd] == dayEnd)
243     endDate = dayEnd;
244
245   deltaMinutes = (([endDate hourOfDay] - [startDate hourOfDay]) * 60
246                   + [endDate minuteOfHour] - [startDate minuteOfHour]);
247   height = ceil(deltaMinutes / 15) * 25;
248
249   return [NSString stringWithFormat: @"height: %d%%;", height];
250 }
251
252 /* helpers */
253
254 - (NSString *) title
255 {
256   return [formatter stringForObjectValue: appointment
257                     referenceDate: [self referenceDate]];
258 }
259
260 - (NSString *) tooltip
261 {
262   return [tooltipFormatter stringForObjectValue: appointment
263                            referenceDate: [self referenceDate]];
264 }
265
266 @end