2006-10-26 01:58:29 +02:00
|
|
|
/* UIxFreeBusyUserSelector.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
|
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
2006-10-26 18:36:59 +02:00
|
|
|
#import <NGCards/iCalPerson.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
2006-10-26 01:58:29 +02:00
|
|
|
|
|
|
|
#import <SOGoUI/SOGoDateFormatter.h>
|
2006-10-26 18:36:59 +02:00
|
|
|
#import <SoObjects/SOGo/AgenorUserManager.h>
|
2006-10-26 01:58:29 +02:00
|
|
|
|
|
|
|
#import "UIxFreeBusyUserSelector.h"
|
|
|
|
|
|
|
|
@implementation UIxFreeBusyUserSelector
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2006-10-26 18:36:59 +02:00
|
|
|
startDate = nil;
|
|
|
|
endDate = nil;
|
2006-10-26 01:58:29 +02:00
|
|
|
dayStartHour = [NSNumber numberWithInt: 8];
|
|
|
|
[dayStartHour retain];
|
|
|
|
dayEndHour = [NSNumber numberWithInt: 18];
|
|
|
|
[dayEndHour retain];
|
2006-10-26 18:36:59 +02:00
|
|
|
contacts = nil;
|
|
|
|
selectorId = nil;
|
2006-10-26 01:58:29 +02:00
|
|
|
daysToDisplay = nil;
|
|
|
|
hoursToDisplay = nil;
|
|
|
|
dateFormatter = [[SOGoDateFormatter alloc]
|
|
|
|
initWithLocale: [self locale]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[dayStartHour release];
|
|
|
|
[dayEndHour release];
|
|
|
|
if (daysToDisplay)
|
|
|
|
[daysToDisplay release];
|
|
|
|
if (hoursToDisplay)
|
|
|
|
[hoursToDisplay release];
|
2006-10-26 18:36:59 +02:00
|
|
|
if (contacts)
|
|
|
|
[contacts release];
|
|
|
|
if (selectorId)
|
|
|
|
[selectorId release];
|
2006-10-26 01:58:29 +02:00
|
|
|
[dateFormatter release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setStartDate: (NSCalendarDate *) newStartDate
|
|
|
|
{
|
2006-10-26 18:36:59 +02:00
|
|
|
startDate = newStartDate;
|
2006-10-26 01:58:29 +02:00
|
|
|
if (daysToDisplay)
|
|
|
|
{
|
|
|
|
[daysToDisplay release];
|
|
|
|
daysToDisplay = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-26 18:36:59 +02:00
|
|
|
- (NSCalendarDate *) startDate
|
|
|
|
{
|
|
|
|
return startDate;
|
|
|
|
}
|
|
|
|
|
2006-10-26 01:58:29 +02:00
|
|
|
- (void) setEndDate: (NSCalendarDate *) newEndDate
|
|
|
|
{
|
2006-10-26 18:36:59 +02:00
|
|
|
endDate = newEndDate;
|
2006-10-26 01:58:29 +02:00
|
|
|
if (daysToDisplay)
|
|
|
|
{
|
|
|
|
[daysToDisplay release];
|
|
|
|
daysToDisplay = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-26 18:36:59 +02:00
|
|
|
- (NSCalendarDate *) endDate
|
|
|
|
{
|
|
|
|
return endDate;
|
|
|
|
}
|
|
|
|
|
2006-10-26 01:58:29 +02:00
|
|
|
- (void) setDayStartHour: (NSNumber *) newDayStartHour
|
|
|
|
{
|
|
|
|
ASSIGN (dayStartHour, newDayStartHour);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDayEndHour: (NSNumber *) newDayEndHour
|
|
|
|
{
|
|
|
|
ASSIGN (dayEndHour, newDayEndHour);
|
|
|
|
}
|
|
|
|
|
2006-10-26 18:36:59 +02:00
|
|
|
- (void) setSelectorId: (NSString *) newSelectorId
|
|
|
|
{
|
|
|
|
ASSIGN (selectorId, newSelectorId);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) selectorId
|
|
|
|
{
|
|
|
|
return selectorId;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setContacts: (NSArray *) newContacts
|
|
|
|
{
|
|
|
|
ASSIGN (contacts, newContacts);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) contacts
|
|
|
|
{
|
|
|
|
return contacts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
- (NSArray *) getICalPersonsFromValue: (NSString *) selectorValue
|
|
|
|
{
|
|
|
|
NSMutableArray *persons;
|
|
|
|
NSEnumerator *uids;
|
|
|
|
NSString *uid;
|
|
|
|
AgenorUserManager *um;
|
|
|
|
|
|
|
|
um = [AgenorUserManager sharedUserManager];
|
|
|
|
|
|
|
|
persons = [NSMutableArray new];
|
|
|
|
[persons autorelease];
|
|
|
|
|
|
|
|
if ([selectorValue length] > 0)
|
|
|
|
{
|
|
|
|
uids = [[selectorValue componentsSeparatedByString: @","]
|
|
|
|
objectEnumerator];
|
|
|
|
uid = [uids nextObject];
|
|
|
|
while (uid)
|
|
|
|
{
|
|
|
|
[persons addObject: [um iCalPersonWithUid: uid]];
|
|
|
|
uid = [uids nextObject];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return persons;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) takeValuesFromRequest: (WORequest *) request
|
|
|
|
inContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
NSArray *newContacts;
|
|
|
|
|
|
|
|
newContacts
|
|
|
|
= [self getICalPersonsFromValue: [request formValueForKey: selectorId]];
|
|
|
|
ASSIGN (contacts, newContacts);
|
|
|
|
if ([contacts count] > 0)
|
|
|
|
NSLog (@"got %i attendees: %@", [contacts count], contacts);
|
|
|
|
else
|
|
|
|
NSLog (@"got no attendees!");
|
|
|
|
}
|
|
|
|
|
2006-10-26 01:58:29 +02:00
|
|
|
/* in-template operations */
|
2006-10-26 18:36:59 +02:00
|
|
|
- (NSString *) initialContactsAsString
|
|
|
|
{
|
|
|
|
NSEnumerator *persons;
|
|
|
|
iCalPerson *person;
|
|
|
|
NSMutableArray *participants;
|
|
|
|
|
|
|
|
participants = [NSMutableArray arrayWithCapacity: [contacts count]];
|
|
|
|
persons = [contacts objectEnumerator];
|
|
|
|
person = [persons nextObject];
|
|
|
|
while (person)
|
|
|
|
{
|
|
|
|
[participants addObject: [person cn]];
|
|
|
|
person = [persons nextObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [participants componentsJoinedByString: @","];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setCurrentContact: (iCalPerson *) newCurrentContact
|
|
|
|
{
|
|
|
|
currentContact = newCurrentContact;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (iCalPerson *) currentContact
|
|
|
|
{
|
|
|
|
return currentContact;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentContactId
|
|
|
|
{
|
|
|
|
return [currentContact cn];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentContactName
|
|
|
|
{
|
|
|
|
return [currentContact cn];
|
|
|
|
}
|
|
|
|
|
2006-10-26 01:58:29 +02:00
|
|
|
- (NSArray *) daysToDisplay
|
|
|
|
{
|
|
|
|
NSCalendarDate *currentDay, *finalDay;
|
|
|
|
|
|
|
|
if (!daysToDisplay)
|
|
|
|
{
|
|
|
|
daysToDisplay = [NSMutableArray new];
|
|
|
|
finalDay = [endDate dateByAddingYears: 0 months: 0 days: 2];
|
|
|
|
currentDay = startDate;
|
|
|
|
[daysToDisplay addObject: currentDay];
|
|
|
|
while (![currentDay isDateOnSameDay: finalDay])
|
|
|
|
{
|
|
|
|
currentDay = [currentDay dateByAddingYears: 0 months: 0 days: 1];
|
|
|
|
[daysToDisplay addObject: currentDay];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return daysToDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) hoursToDisplay
|
|
|
|
{
|
|
|
|
NSNumber *currentHour;
|
|
|
|
|
|
|
|
if (!hoursToDisplay)
|
|
|
|
{
|
|
|
|
hoursToDisplay = [NSMutableArray new];
|
|
|
|
currentHour = dayStartHour;
|
|
|
|
[hoursToDisplay addObject: currentHour];
|
|
|
|
while (![currentHour isEqual: dayEndHour])
|
|
|
|
{
|
|
|
|
currentHour = [NSNumber numberWithInt: [currentHour intValue] + 1];
|
|
|
|
[hoursToDisplay addObject: currentHour];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hoursToDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setCurrentDayToDisplay: (NSCalendarDate *) newCurrentDayToDisplay
|
|
|
|
{
|
|
|
|
currentDayToDisplay = newCurrentDayToDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setCurrentHourToDisplay: (NSNumber *) newCurrentHourToDisplay
|
|
|
|
{
|
|
|
|
currentHourToDisplay = newCurrentHourToDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) currentDayToDisplay
|
|
|
|
{
|
|
|
|
return currentDayToDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *) currentHourToDisplay
|
|
|
|
{
|
|
|
|
return currentHourToDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentFormattedDay
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%@, %.4d-%.2d-%.2d",
|
|
|
|
[dateFormatter shortDayOfWeek: [currentDayToDisplay dayOfWeek]],
|
|
|
|
[currentDayToDisplay yearOfCommonEra],
|
|
|
|
[currentDayToDisplay monthOfYear],
|
|
|
|
[currentDayToDisplay dayOfMonth]];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|