]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxFreeBusyUserSelectorTable.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1032 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Scheduler / UIxFreeBusyUserSelectorTable.m
1 /* UIxFreeBusyUserSelectorTable.m - this file is part of SOGo
2  *
3  * Copyright (C) 2006 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
7  * This file is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This file is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSCalendarDate.h>
25 #import <Foundation/NSValue.h>
26 #import <Foundation/NSString.h>
27
28 #import <NGCards/iCalPerson.h>
29 #import <NGExtensions/NSCalendarDate+misc.h>
30
31 #import <SoObjects/Appointments/SOGoFreeBusyObject.h>
32 #import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
33 #import <SOGoUI/SOGoDateFormatter.h>
34
35 #import "UIxComponent+Agenor.h"
36 #import "UIxFreeBusyUserSelectorTable.h"
37
38 @implementation UIxFreeBusyUserSelectorTable
39
40 - (id) init
41 {
42   if ((self = [super init]))
43     {
44       standAlone = NO;
45       startDate = nil;
46       endDate = nil;
47       contacts = nil;
48       hoursToDisplay = nil;
49       daysToDisplay = nil;
50       dateFormatter
51         = [[SOGoDateFormatter alloc] initWithLocale: [self locale]];
52     }
53
54   return self;
55 }
56
57 - (void) dealloc
58 {
59   [dateFormatter release];
60   if (hoursToDisplay)
61     [hoursToDisplay release];
62   if (daysToDisplay)
63     [daysToDisplay release];
64   if (standAlone)
65     {
66       if (startDate)
67         [startDate release];
68       if (endDate)
69         [endDate release];
70       if (contacts)
71         [contacts release];
72     }
73   [super dealloc];
74 }
75
76 - (void) setContacts: (NSArray *) newContacts
77 {
78   contacts = newContacts;
79 }
80
81 - (NSArray *) contacts
82 {
83   return contacts;
84 }
85
86 - (void) setStartDate: (NSCalendarDate *) newStartDate
87 {
88   startDate = newStartDate;
89   if (daysToDisplay)
90     {
91       [daysToDisplay release];
92       daysToDisplay = nil;
93     }
94 }
95
96 - (NSCalendarDate *) startDate
97 {
98   return startDate;
99 }
100
101 - (void) setEndDate: (NSCalendarDate *) newEndDate
102 {
103   endDate = newEndDate;
104   if (daysToDisplay)
105     {
106       [daysToDisplay release];
107       daysToDisplay = nil;
108     }
109 }
110
111 - (NSCalendarDate *) endDate
112 {
113   return endDate;
114 }
115
116 - (void) setDayStartHour: (NSNumber *) newDayStartHour
117 {
118   dayStartHour = newDayStartHour;
119   if (hoursToDisplay)
120     {
121       [hoursToDisplay release];
122       hoursToDisplay = nil;
123     }
124 }
125
126 - (NSNumber *) dayStartHour
127 {
128   return dayStartHour;
129 }
130
131 - (void) setDayEndHour: (NSNumber *) newDayEndHour
132 {
133   dayEndHour = newDayEndHour;
134   if (hoursToDisplay)
135     {
136       [hoursToDisplay release];
137       hoursToDisplay = nil;
138     }
139 }
140
141 - (NSNumber *) dayEndHour
142 {
143   return dayEndHour;
144 }
145
146 /* template operations */
147 - (NSArray *) daysToDisplay
148 {
149   NSCalendarDate *currentDay, *finalDay;
150
151   if (!daysToDisplay)
152     {
153       daysToDisplay = [NSMutableArray new];
154       finalDay = [endDate dateByAddingYears: 0 months: 0 days: 2];
155       currentDay = startDate;
156       [daysToDisplay addObject: currentDay];
157       while (![currentDay isDateOnSameDay: finalDay])
158         {
159           currentDay = [currentDay dateByAddingYears: 0
160                                    months: 0
161                                    days: 1];
162           [daysToDisplay addObject: currentDay];
163         }
164     }
165
166   return daysToDisplay;
167 }
168
169 - (NSArray *) hoursToDisplay
170 {
171   NSNumber *currentHour;
172
173   if (!hoursToDisplay)
174     {
175       hoursToDisplay = [NSMutableArray new];
176       currentHour = dayStartHour;
177       [hoursToDisplay addObject: currentHour];
178       while (![currentHour isEqual: dayEndHour])
179         {
180           currentHour = [NSNumber numberWithInt: [currentHour intValue] + 1];
181           [hoursToDisplay addObject: currentHour];
182         }
183     }
184
185   return hoursToDisplay;
186 }
187
188 - (void) setCurrentContact: (iCalPerson *) newCurrentContact
189 {
190   currentContact = newCurrentContact;
191 }
192
193 - (iCalPerson *) currentContact
194 {
195   return currentContact;
196 }
197
198 - (BOOL) currentContactHasStatus
199 {
200   return ([currentContact participationStatus] != 0);
201 }
202
203 - (NSString *) currentContactStatusImage
204 {
205   NSString *basename;
206
207   basename = [[currentContact partStatWithDefault] lowercaseString];
208                        
209   return [self urlForResourceFilename: [NSString stringWithFormat: @"%@.png", basename]];;
210 }
211
212 - (NSString *) currentContactId
213 {
214   return [currentContact cn];
215 }
216
217 - (NSString *) currentContactName
218 {
219   return [currentContact cn];
220 }
221
222 - (void) setCurrentDayToDisplay: (NSCalendarDate *) newCurrentDayToDisplay
223 {
224   currentDayToDisplay = newCurrentDayToDisplay;
225 }
226
227 - (void) setCurrentHourToDisplay: (NSNumber *) newCurrentHourToDisplay
228 {
229   currentHourToDisplay = newCurrentHourToDisplay;
230 }
231
232 - (NSCalendarDate *) currentDayToDisplay
233 {
234   return currentDayToDisplay;
235 }
236
237 - (NSNumber *) currentHourToDisplay
238 {
239   return currentHourToDisplay;
240 }
241
242 - (NSString *) currentFormattedDay
243 {
244   return [NSString stringWithFormat: @"%@, %.4d-%.2d-%.2d",
245                    [dateFormatter shortDayOfWeek: [currentDayToDisplay dayOfWeek]],
246                    [currentDayToDisplay yearOfCommonEra],
247                    [currentDayToDisplay monthOfYear],
248                    [currentDayToDisplay dayOfMonth]];
249 }
250
251 /* as stand-alone component... */
252
253 - (id <WOActionResults>) defaultAction
254 {
255   SOGoFreeBusyObject *co;
256   NSString *queryParam;
257   NSTimeZone *uTZ;
258
259   co = [self clientObject];
260   uTZ = [co userTimeZone];
261
262   queryParam = [self queryParameterForKey: @"sday"];
263   if ([queryParam length] > 0)
264     {
265       [self setStartDate: [NSCalendarDate dateFromShortDateString: queryParam
266                                           andShortTimeString: @"0000"
267                                           inTimeZone: uTZ]];
268       [startDate retain];
269     }
270   queryParam = [self queryParameterForKey: @"eday"];
271   if ([queryParam length] > 0)
272     {
273       [self setEndDate: [NSCalendarDate dateFromShortDateString: queryParam
274                                         andShortTimeString: @"0000"
275                                         inTimeZone: uTZ]];
276       [endDate retain];
277     }
278   queryParam = [self queryParameterForKey: @"attendees"];
279   if ([queryParam length] > 0)
280     {
281       [self setContacts: [self getICalPersonsFromValue: queryParam]];
282       [contacts retain];
283     }
284   dayStartHour = [NSNumber numberWithInt: 8];
285   dayEndHour = [NSNumber numberWithInt: 18];
286
287   standAlone = YES;
288
289   return self;
290 }
291
292 @end