1 /* UIxFreeBusyUserSelectorTable.m - this file is part of SOGo
3 * Copyright (C) 2006 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
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)
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.
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.
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSCalendarDate.h>
25 #import <Foundation/NSValue.h>
26 #import <Foundation/NSString.h>
28 #import <NGCards/iCalPerson.h>
29 #import <NGExtensions/NSCalendarDate+misc.h>
31 #import <SoObjects/Appointments/SOGoFreeBusyObject.h>
32 #import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
33 #import <SOGoUI/SOGoDateFormatter.h>
35 #import "UIxComponent+Agenor.h"
36 #import "UIxFreeBusyUserSelectorTable.h"
38 @implementation UIxFreeBusyUserSelectorTable
42 if ((self = [super init]))
51 = [[SOGoDateFormatter alloc] initWithLocale: [self locale]];
59 [dateFormatter release];
61 [hoursToDisplay release];
63 [daysToDisplay release];
76 - (void) setContacts: (NSArray *) newContacts
78 contacts = newContacts;
81 - (NSArray *) contacts
86 - (void) setStartDate: (NSCalendarDate *) newStartDate
88 startDate = newStartDate;
91 [daysToDisplay release];
96 - (NSCalendarDate *) startDate
101 - (void) setEndDate: (NSCalendarDate *) newEndDate
103 endDate = newEndDate;
106 [daysToDisplay release];
111 - (NSCalendarDate *) endDate
116 - (void) setDayStartHour: (NSNumber *) newDayStartHour
118 dayStartHour = newDayStartHour;
121 [hoursToDisplay release];
122 hoursToDisplay = nil;
126 - (NSNumber *) dayStartHour
131 - (void) setDayEndHour: (NSNumber *) newDayEndHour
133 dayEndHour = newDayEndHour;
136 [hoursToDisplay release];
137 hoursToDisplay = nil;
141 - (NSNumber *) dayEndHour
146 /* template operations */
147 - (NSArray *) daysToDisplay
149 NSCalendarDate *currentDay, *finalDay;
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])
159 currentDay = [currentDay dateByAddingYears: 0
162 [daysToDisplay addObject: currentDay];
166 return daysToDisplay;
169 - (NSArray *) hoursToDisplay
171 NSNumber *currentHour;
175 hoursToDisplay = [NSMutableArray new];
176 currentHour = dayStartHour;
177 [hoursToDisplay addObject: currentHour];
178 while (![currentHour isEqual: dayEndHour])
180 currentHour = [NSNumber numberWithInt: [currentHour intValue] + 1];
181 [hoursToDisplay addObject: currentHour];
185 return hoursToDisplay;
188 - (void) setCurrentContact: (iCalPerson *) newCurrentContact
190 currentContact = newCurrentContact;
193 - (iCalPerson *) currentContact
195 return currentContact;
198 - (BOOL) currentContactHasStatus
200 return ([currentContact participationStatus] != 0);
203 - (NSString *) currentContactStatusImage
207 basename = [[currentContact partStatWithDefault] lowercaseString];
209 return [self urlForResourceFilename: [NSString stringWithFormat: @"%@.png", basename]];;
212 - (NSString *) currentContactId
214 return [currentContact cn];
217 - (NSString *) currentContactName
219 return [currentContact cn];
222 - (void) setCurrentDayToDisplay: (NSCalendarDate *) newCurrentDayToDisplay
224 currentDayToDisplay = newCurrentDayToDisplay;
227 - (void) setCurrentHourToDisplay: (NSNumber *) newCurrentHourToDisplay
229 currentHourToDisplay = newCurrentHourToDisplay;
232 - (NSCalendarDate *) currentDayToDisplay
234 return currentDayToDisplay;
237 - (NSNumber *) currentHourToDisplay
239 return currentHourToDisplay;
242 - (NSString *) currentFormattedDay
244 return [NSString stringWithFormat: @"%@, %.4d-%.2d-%.2d",
245 [dateFormatter shortDayOfWeek: [currentDayToDisplay dayOfWeek]],
246 [currentDayToDisplay yearOfCommonEra],
247 [currentDayToDisplay monthOfYear],
248 [currentDayToDisplay dayOfMonth]];
251 /* as stand-alone component... */
253 - (id <WOActionResults>) defaultAction
255 SOGoFreeBusyObject *co;
256 NSString *queryParam;
259 co = [self clientObject];
260 uTZ = [co userTimeZone];
262 queryParam = [self queryParameterForKey: @"sday"];
263 if ([queryParam length] > 0)
265 [self setStartDate: [NSCalendarDate dateFromShortDateString: queryParam
266 andShortTimeString: @"0000"
270 queryParam = [self queryParameterForKey: @"eday"];
271 if ([queryParam length] > 0)
273 [self setEndDate: [NSCalendarDate dateFromShortDateString: queryParam
274 andShortTimeString: @"0000"
278 queryParam = [self queryParameterForKey: @"attendees"];
279 if ([queryParam length] > 0)
281 [self setContacts: [self getICalPersonsFromValue: queryParam]];
284 dayStartHour = [NSNumber numberWithInt: 8];
285 dayEndHour = [NSNumber numberWithInt: 18];