2007-03-18 16:22:10 +01:00
|
|
|
// $Id: UIxCalView.m 1031 2007-03-07 22:52:32Z wolfgang $
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-10-05 01:15:25 +02:00
|
|
|
#import "common.h"
|
|
|
|
//#import <OGoContentStore/OCSFolder.h>
|
2006-12-19 18:06:07 +01:00
|
|
|
|
|
|
|
#import <NGObjWeb/SoSecurityManager.h>
|
2006-10-05 01:15:25 +02:00
|
|
|
#import <NGObjWeb/SoUser.h>
|
|
|
|
#import <NGExtensions/NGCalendarDateRange.h>
|
|
|
|
#import <NGCards/NGCards.h>
|
2006-12-19 18:06:07 +01:00
|
|
|
|
|
|
|
#import <SOGoUI/SOGoAptFormatter.h>
|
2006-10-05 01:15:25 +02:00
|
|
|
#import "UIxComponent+Agenor.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-12-19 18:06:07 +01:00
|
|
|
#import "SoObjects/Appointments/SOGoAppointmentFolder.h"
|
2007-02-08 17:30:29 +01:00
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
2006-12-19 18:06:07 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoObject.h>
|
|
|
|
|
|
|
|
#import "UIxCalView.h"
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@interface UIxCalView (PrivateAPI)
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSString *) _userFolderURI;
|
2006-06-15 21:34:10 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation UIxCalView
|
|
|
|
|
|
|
|
static BOOL shouldDisplayWeekend = NO;
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
static BOOL didInit = NO;
|
2006-06-15 21:34:10 +02:00
|
|
|
NSUserDefaults *ud;
|
|
|
|
|
|
|
|
if (didInit) return;
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
shouldDisplayWeekend = [ud boolForKey: @"SOGoShouldDisplayWeekend"];
|
|
|
|
didInit = YES;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
self = [super init];
|
2006-09-05 15:53:21 +02:00
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
NSTimeZone *tz;
|
|
|
|
|
2006-09-08 19:00:45 +02:00
|
|
|
tz = [[self clientObject] userTimeZone];
|
2006-10-11 20:19:42 +02:00
|
|
|
aptFormatter
|
2006-09-05 15:53:21 +02:00
|
|
|
= [[SOGoAptFormatter alloc] initWithDisplayTimeZone: tz];
|
2006-10-11 20:19:42 +02:00
|
|
|
aptTooltipFormatter
|
2006-09-05 15:53:21 +02:00
|
|
|
= [[SOGoAptFormatter alloc] initWithDisplayTimeZone: tz];
|
2006-10-11 20:19:42 +02:00
|
|
|
privateAptFormatter
|
2006-09-05 15:53:21 +02:00
|
|
|
= [[SOGoAptFormatter alloc] initWithDisplayTimeZone: tz];
|
2006-10-11 20:19:42 +02:00
|
|
|
privateAptTooltipFormatter
|
2006-09-05 15:53:21 +02:00
|
|
|
= [[SOGoAptFormatter alloc] initWithDisplayTimeZone: tz];
|
|
|
|
[self configureFormatters];
|
2006-12-19 18:06:07 +01:00
|
|
|
componentsData = [NSMutableDictionary new];
|
2006-09-05 15:53:21 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2006-12-19 18:06:07 +01:00
|
|
|
[componentsData release];
|
2006-10-11 20:19:42 +02:00
|
|
|
[appointments release];
|
|
|
|
[allDayApts release];
|
|
|
|
[appointment release];
|
|
|
|
[currentDay release];
|
|
|
|
[aptFormatter release];
|
|
|
|
[aptTooltipFormatter release];
|
|
|
|
[privateAptFormatter release];
|
|
|
|
[privateAptTooltipFormatter release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* subclasses should override this */
|
2006-09-05 15:53:21 +02:00
|
|
|
- (void) configureFormatters
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *title;
|
|
|
|
|
2006-10-11 20:19:42 +02:00
|
|
|
[aptFormatter setFullDetails];
|
|
|
|
[aptTooltipFormatter setTooltip];
|
|
|
|
[privateAptFormatter setPrivateDetails];
|
|
|
|
[privateAptTooltipFormatter setPrivateTooltip];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
title = [self labelForKey: @"empty title"];
|
2006-10-11 20:19:42 +02:00
|
|
|
[aptFormatter setTitlePlaceholder: title];
|
|
|
|
[aptTooltipFormatter setTitlePlaceholder: title];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
title = [self labelForKey: @"private appointment"];
|
2006-10-11 20:19:42 +02:00
|
|
|
[privateAptFormatter setPrivateTitle: title];
|
|
|
|
[privateAptTooltipFormatter setPrivateTitle: title];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSArray *) filterAppointments:(NSArray *) _apts
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSMutableArray *filtered;
|
2007-03-07 22:11:13 +01:00
|
|
|
unsigned i, count;
|
|
|
|
NSString *email;
|
|
|
|
NSDictionary *info;
|
|
|
|
NSArray *partmails;
|
|
|
|
unsigned p, pCount;
|
|
|
|
BOOL shouldAdd;
|
|
|
|
NSString *partmailsString;
|
|
|
|
NSArray *partstates;
|
|
|
|
NSString *state;
|
|
|
|
NSString *pEmail;
|
|
|
|
|
|
|
|
if ([self shouldDisplayRejectedAppointments])
|
|
|
|
return _apts;
|
|
|
|
{
|
|
|
|
count = [_apts count];
|
|
|
|
filtered = [[[NSMutableArray alloc] initWithCapacity: count] autorelease];
|
|
|
|
email = [self emailForUser];
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
shouldAdd = YES;
|
|
|
|
info = [_apts objectAtIndex: i];
|
|
|
|
partmailsString = [info objectForKey: @"partmails"];
|
|
|
|
if ([partmailsString isNotNull])
|
|
|
|
{
|
|
|
|
partmails = [partmailsString componentsSeparatedByString: @"\n"];
|
|
|
|
pCount = [partmails count];
|
|
|
|
for (p = 0; p < pCount; p++)
|
|
|
|
{
|
|
|
|
pEmail = [partmails objectAtIndex: p];
|
|
|
|
if ([pEmail isEqualToString: email])
|
|
|
|
{
|
|
|
|
partstates = [[info objectForKey: @"partstates"]
|
|
|
|
componentsSeparatedByString: @"\n"];
|
|
|
|
state = [partstates objectAtIndex: p];
|
|
|
|
if ([state intValue] == iCalPersonPartStatDeclined)
|
|
|
|
shouldAdd = NO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (shouldAdd)
|
|
|
|
[filtered addObject: info];
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
return filtered;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (void) setAppointments:(NSArray *) _apts
|
|
|
|
{
|
|
|
|
_apts = [self filterAppointments: _apts];
|
2006-10-11 20:19:42 +02:00
|
|
|
ASSIGN(appointments, _apts);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-10-11 20:19:42 +02:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSArray *) appointments
|
|
|
|
{
|
2006-10-11 20:19:42 +02:00
|
|
|
return appointments;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (void) setAppointment:(id) _apt
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *mailtoChunk;
|
|
|
|
NSString *myEmail;
|
|
|
|
|
2006-10-11 20:19:42 +02:00
|
|
|
ASSIGN(appointment, _apt);
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* cache some info about apt for faster access */
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
mailtoChunk = [_apt valueForKey: @"orgmail"];
|
|
|
|
myEmail = [self emailForUser];
|
|
|
|
if ([mailtoChunk rangeOfString: myEmail].length > 0)
|
|
|
|
{
|
2006-10-11 20:19:42 +02:00
|
|
|
aptFlags.isMyApt = YES;
|
|
|
|
aptFlags.canAccessApt = YES;
|
2006-09-05 15:53:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSString *partmails;
|
|
|
|
|
2006-10-11 20:19:42 +02:00
|
|
|
aptFlags.isMyApt = NO;
|
2006-09-05 15:53:21 +02:00
|
|
|
|
|
|
|
partmails = [_apt valueForKey: @"partmails"];
|
|
|
|
if ([partmails rangeOfString: myEmail].length)
|
2006-10-11 20:19:42 +02:00
|
|
|
aptFlags.canAccessApt = YES;
|
2006-09-05 15:53:21 +02:00
|
|
|
else
|
2007-03-05 23:35:41 +01:00
|
|
|
aptFlags.canAccessApt
|
|
|
|
= ([[_apt valueForKey: @"classification"] intValue]
|
|
|
|
== iCalAccessPublic);
|
2006-09-05 15:53:21 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-08-15 22:56:54 +02:00
|
|
|
|
2006-10-11 20:19:42 +02:00
|
|
|
- (void) setTasks: (NSArray *) _tasks
|
|
|
|
{
|
|
|
|
ASSIGN(tasks, _tasks);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) tasks
|
|
|
|
{
|
|
|
|
return tasks;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (id) appointment
|
|
|
|
{
|
2006-10-11 20:19:42 +02:00
|
|
|
return appointment;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) isMyApt
|
|
|
|
{
|
2006-10-11 20:19:42 +02:00
|
|
|
return aptFlags.isMyApt ? YES : NO;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) canAccessApt
|
|
|
|
{
|
2006-10-11 20:19:42 +02:00
|
|
|
return aptFlags.canAccessApt ? YES : NO;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) canNotAccessApt
|
|
|
|
{
|
2006-10-11 20:19:42 +02:00
|
|
|
return aptFlags.canAccessApt ? NO : YES;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSDictionary *) aptTypeDict
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return nil;
|
|
|
|
}
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSString *) aptTypeLabel
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return @"aptLabel";
|
|
|
|
}
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSString *) aptTypeIcon
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (SOGoAptFormatter *) aptFormatter
|
|
|
|
{
|
2006-10-11 20:19:42 +02:00
|
|
|
if (aptFlags.canAccessApt)
|
|
|
|
return aptFormatter;
|
|
|
|
return privateAptFormatter;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (SOGoAptFormatter *) aptTooltipFormatter
|
|
|
|
{
|
2006-10-11 20:19:42 +02:00
|
|
|
if (aptFlags.canAccessApt)
|
|
|
|
return aptTooltipFormatter;
|
|
|
|
return privateAptTooltipFormatter;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: remove this */
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSString *) shortTextForApt
|
|
|
|
{
|
|
|
|
[self warnWithFormat: @"%s IS DEPRECATED!", __PRETTY_FUNCTION__];
|
2006-06-15 21:34:10 +02:00
|
|
|
if (![self canAccessApt])
|
|
|
|
return @"";
|
2006-10-11 20:19:42 +02:00
|
|
|
return [[self aptFormatter] stringForObjectValue: appointment];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSString *) shortTitleForApt
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *title;
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
[self warnWithFormat: @"%s IS DEPRECATED!", __PRETTY_FUNCTION__];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
if (![self canAccessApt])
|
|
|
|
return @"";
|
2006-10-11 20:19:42 +02:00
|
|
|
title = [appointment valueForKey: @"title"];
|
2006-06-15 21:34:10 +02:00
|
|
|
if ([title length] > 12)
|
2006-09-05 15:53:21 +02:00
|
|
|
title = [[title substringToIndex: 11] stringByAppendingString: @"..."];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSString *) tooltipForApt
|
|
|
|
{
|
|
|
|
[self warnWithFormat: @"%s IS DEPRECATED!", __PRETTY_FUNCTION__];
|
2006-10-11 20:19:42 +02:00
|
|
|
return [[self aptTooltipFormatter] stringForObjectValue: appointment
|
2006-09-05 15:53:21 +02:00
|
|
|
referenceDate: [self currentDay]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSString *) aptStyle
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSCalendarDate *) referenceDateForFormatter
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self selectedDate];
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSCalendarDate *) thisMonth
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self selectedDate];
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSCalendarDate *) nextMonth
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSCalendarDate *date = [self thisMonth];
|
2006-09-05 15:53:21 +02:00
|
|
|
return [date dateByAddingYears: 0 months: 1 days: 0
|
|
|
|
hours: 0 minutes: 0 seconds: 0];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSCalendarDate *) prevMonth
|
|
|
|
{
|
2006-08-19 00:56:47 +02:00
|
|
|
NSCalendarDate *date = [self thisMonth];
|
2006-09-05 15:53:21 +02:00
|
|
|
return [date dateByAddingYears: 0 months:-1 days: 0
|
|
|
|
hours: 0 minutes: 0 seconds: 0];
|
2006-08-19 00:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) prevMonthAsString
|
|
|
|
{
|
|
|
|
return [self dateStringForDate: [self prevMonth]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) nextMonthAsString
|
|
|
|
{
|
|
|
|
return [self dateStringForDate: [self nextMonth]];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* current day related */
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (void) setCurrentDay:(NSCalendarDate *) _day
|
|
|
|
{
|
2006-09-08 19:00:45 +02:00
|
|
|
[_day setTimeZone: [[self clientObject] userTimeZone]];
|
2006-10-11 20:19:42 +02:00
|
|
|
ASSIGN(currentDay, _day);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-08-19 00:56:47 +02:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSCalendarDate *) currentDay
|
|
|
|
{
|
2006-10-11 20:19:42 +02:00
|
|
|
return currentDay;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-08-19 00:56:47 +02:00
|
|
|
- (NSString *) currentDayName
|
|
|
|
{
|
2006-10-11 20:19:42 +02:00
|
|
|
return [self localizedNameForDayOfWeek: [currentDay dayOfWeek]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (id) holidayInfo
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSArray *) allDayApts
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSArray *apts;
|
|
|
|
NSMutableArray *filtered;
|
|
|
|
unsigned i, count;
|
|
|
|
|
2006-10-11 20:19:42 +02:00
|
|
|
if (allDayApts)
|
|
|
|
return allDayApts;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
apts = [self appointments];
|
|
|
|
count = [apts count];
|
|
|
|
filtered = [[NSMutableArray alloc] initWithCapacity: 3];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
id apt;
|
|
|
|
NSNumber *bv;
|
|
|
|
|
|
|
|
apt = [apts objectAtIndex: i];
|
|
|
|
bv = [apt valueForKey: @"isallday"];
|
|
|
|
if ([bv boolValue])
|
|
|
|
[filtered addObject: apt];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-10-11 20:19:42 +02:00
|
|
|
ASSIGN(allDayApts, filtered);
|
2006-06-15 21:34:10 +02:00
|
|
|
[filtered release];
|
2006-10-11 20:19:42 +02:00
|
|
|
return allDayApts;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* special appointments */
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) hasDayInfo
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self hasHoldidayInfo] || [self hasAllDayApts];
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) hasHoldidayInfo
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self holidayInfo] != nil;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) hasAllDayApts
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self allDayApts] count] != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* defaults */
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) showFullNames
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) showAMPMDates
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (unsigned) dayStartHour
|
|
|
|
{
|
2006-10-04 00:58:00 +02:00
|
|
|
return 0;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (unsigned) dayEndHour
|
|
|
|
{
|
2007-02-09 22:24:58 +01:00
|
|
|
return 23;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) shouldDisplayWeekend
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return shouldDisplayWeekend;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) shouldHideWeekend
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return ![self shouldDisplayWeekend];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* URLs */
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSString *) appointmentViewURL
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
id pkey;
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
if (![(pkey = [[self appointment] valueForKey: @"uid"]) isNotNull])
|
2006-06-15 21:34:10 +02:00
|
|
|
return nil;
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
return [[[self clientObject] baseURLForAptWithUID: [pkey stringValue]
|
|
|
|
inContext: [self context]]
|
|
|
|
stringByAppendingString: @"/view"];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fetching */
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSCalendarDate *) startDate
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self selectedDate];
|
|
|
|
}
|
2006-11-02 23:03:09 +01:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSCalendarDate *) endDate
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self startDate] tomorrow];
|
|
|
|
}
|
|
|
|
|
2006-12-19 18:06:07 +01:00
|
|
|
- (NSArray *) activeCalendarFolders
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
NSEnumerator *calendarUIDs;
|
|
|
|
SOGoAppointmentFolder *currentFolder;
|
|
|
|
NSMutableArray *folders;
|
|
|
|
NSString *currentUID;
|
2007-01-04 15:37:07 +01:00
|
|
|
SoSecurityManager *securityManager;
|
|
|
|
|
|
|
|
securityManager = [SoSecurityManager sharedSecurityManager];
|
2006-12-19 18:06:07 +01:00
|
|
|
|
|
|
|
folders = [NSMutableArray array];
|
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
calendarUIDs = [[[ud stringForKey: @"calendaruids"]
|
|
|
|
componentsSeparatedByString: @","] objectEnumerator];
|
|
|
|
currentUID = [calendarUIDs nextObject];
|
|
|
|
while (currentUID)
|
|
|
|
{
|
|
|
|
if (![currentUID hasPrefix: @"-"])
|
|
|
|
{
|
2007-01-04 15:37:07 +01:00
|
|
|
currentFolder = [[self clientObject] lookupCalendarFolderForUID: currentUID];
|
|
|
|
if (currentFolder
|
|
|
|
&& ![securityManager validatePermission: SoPerm_AccessContentsInformation
|
|
|
|
onObject: currentFolder
|
|
|
|
inContext: context])
|
2006-12-19 18:06:07 +01:00
|
|
|
[folders addObject: currentFolder];
|
|
|
|
}
|
|
|
|
currentUID = [calendarUIDs nextObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
return folders;
|
|
|
|
}
|
|
|
|
|
2006-10-11 20:19:42 +02:00
|
|
|
- (NSArray *) _fetchCoreInfosForComponent: (NSString *) component
|
2006-09-05 15:53:21 +02:00
|
|
|
{
|
2006-12-19 18:06:07 +01:00
|
|
|
NSArray *currentInfos;
|
|
|
|
NSMutableArray *infos;
|
|
|
|
NSEnumerator *folders;
|
|
|
|
SOGoAppointmentFolder *currentFolder;
|
|
|
|
|
|
|
|
infos = [componentsData objectForKey: component];
|
|
|
|
if (!infos)
|
|
|
|
{
|
|
|
|
infos = [NSMutableArray array];
|
|
|
|
folders = [[self activeCalendarFolders] objectEnumerator];
|
|
|
|
currentFolder = [folders nextObject];
|
|
|
|
while (currentFolder)
|
|
|
|
{
|
|
|
|
currentInfos = [currentFolder fetchCoreInfosFrom: [[self startDate] beginOfDay]
|
|
|
|
to: [[self endDate] endOfDay]
|
|
|
|
component: component];
|
|
|
|
[currentInfos makeObjectsPerform: @selector (setObject:forKey:)
|
|
|
|
withObject: [currentFolder ownerInContext: nil]
|
|
|
|
withObject: @"owner"];
|
|
|
|
[infos addObjectsFromArray: currentInfos];
|
|
|
|
currentFolder = [folders nextObject];
|
|
|
|
}
|
|
|
|
[componentsData setObject: infos forKey: component];
|
|
|
|
}
|
|
|
|
|
|
|
|
return infos;
|
2006-10-11 20:19:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) fetchCoreAppointmentsInfos
|
|
|
|
{
|
|
|
|
if (!appointments)
|
|
|
|
[self setAppointments: [self _fetchCoreInfosForComponent: @"vevent"]];
|
|
|
|
|
|
|
|
return appointments;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) fetchCoreTasksInfos
|
|
|
|
{
|
|
|
|
if (!tasks)
|
|
|
|
[self setTasks: [self _fetchCoreInfosForComponent: @"vtodo"]];
|
|
|
|
|
|
|
|
return tasks;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* query parameters */
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) shouldDisplayRejectedAppointments
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *bv;
|
|
|
|
|
2006-08-14 22:43:55 +02:00
|
|
|
bv = [self queryParameterForKey: @"dr"];
|
2006-06-15 21:34:10 +02:00
|
|
|
if (!bv) return NO;
|
|
|
|
return [bv boolValue];
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSDictionary *) toggleShowRejectedAptsQueryParameters
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSMutableDictionary *qp;
|
|
|
|
BOOL shouldDisplay;
|
|
|
|
|
|
|
|
shouldDisplay = ![self shouldDisplayRejectedAppointments];
|
|
|
|
qp = [[[self queryParameters] mutableCopy] autorelease];
|
2006-09-05 15:53:21 +02:00
|
|
|
[qp setObject: shouldDisplay ? @"1" : @"0" forKey: @"dr"];
|
2006-06-15 21:34:10 +02:00
|
|
|
return qp;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSString *) toggleShowRejectedAptsLabel
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
if (![self shouldDisplayRejectedAppointments])
|
|
|
|
return @"show_rejected_apts";
|
|
|
|
return @"hide_rejected_apts";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* date selection & conversion */
|
|
|
|
|
2006-08-19 00:56:47 +02:00
|
|
|
- (NSDictionary *) _dateQueryParametersWithOffset: (int) daysOffset
|
|
|
|
{
|
|
|
|
NSCalendarDate *date;
|
|
|
|
|
|
|
|
date = [[self startDate] dateByAddingYears: 0 months: 0
|
|
|
|
days: daysOffset
|
2006-09-05 15:53:21 +02:00
|
|
|
hours: 0 minutes: 0 seconds: 0];
|
|
|
|
return [self queryParametersBySettingSelectedDate: date];
|
2006-08-19 00:56:47 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSDictionary *) todayQueryParameters
|
|
|
|
{
|
2006-09-05 20:44:34 +02:00
|
|
|
return [self queryParametersBySettingSelectedDate: [NSCalendarDate date]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSDictionary *) currentDayQueryParameters
|
|
|
|
{
|
2006-10-11 20:19:42 +02:00
|
|
|
return [self queryParametersBySettingSelectedDate: currentDay];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* calendarUIDs */
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSString *) formattedCalendarUIDs
|
|
|
|
{
|
|
|
|
return [[[self clientObject] calendarUIDs]
|
|
|
|
componentsJoinedByString: @", "];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Actions */
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSString *) _userFolderURI
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
WOContext *ctx;
|
|
|
|
id obj;
|
|
|
|
NSURL *url;
|
|
|
|
|
|
|
|
ctx = [self context];
|
2006-09-05 15:53:21 +02:00
|
|
|
obj = [[ctx objectTraversalStack] objectAtIndex: 1];
|
|
|
|
url = [NSURL URLWithString: [obj baseURLInContext: ctx]];
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[url path] stringByUnescapingURL];
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (id) redirectForUIDsAction
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSMutableString *uri;
|
2006-09-05 15:53:21 +02:00
|
|
|
NSString *uidsString, *loc, *prevMethod, *userFolderID;
|
2006-06-15 21:34:10 +02:00
|
|
|
id <WOActionResults> r;
|
|
|
|
BOOL useGroups;
|
|
|
|
unsigned index;
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
uidsString = [self queryParameterForKey: @"userUIDString"];
|
2007-02-13 16:58:52 +01:00
|
|
|
uidsString = [uidsString stringByTrimmingSpaces];
|
2006-08-14 22:43:55 +02:00
|
|
|
[self setQueryParameter: nil forKey: @"userUIDString"];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
prevMethod = [self queryParameterForKey: @"previousMethod"];
|
|
|
|
if (prevMethod == nil)
|
2006-06-15 21:34:10 +02:00
|
|
|
prevMethod = @"";
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
uri = [[NSMutableString alloc] initWithString: [self _userFolderURI]];
|
2006-06-15 21:34:10 +02:00
|
|
|
/* if we have more than one entry, use groups - otherwise don't */
|
2006-09-05 15:53:21 +02:00
|
|
|
useGroups = [uidsString rangeOfString: @","].length > 0;
|
2006-06-15 21:34:10 +02:00
|
|
|
userFolderID = [uri lastPathComponent];
|
2006-09-05 15:53:21 +02:00
|
|
|
if (useGroups)
|
|
|
|
{
|
|
|
|
NSArray *uids;
|
|
|
|
|
|
|
|
uids = [uidsString componentsSeparatedByString: @","];
|
|
|
|
/* guarantee that our id is the first */
|
|
|
|
if (((index = [uids indexOfObject: userFolderID]) != NSNotFound)
|
|
|
|
&& (index != 0))
|
|
|
|
{
|
|
|
|
uids = [[uids mutableCopy] autorelease];
|
|
|
|
[(NSMutableArray *) uids removeObjectAtIndex: index];
|
|
|
|
[(NSMutableArray *) uids insertObject: userFolderID atIndex: 0];
|
|
|
|
uidsString = [uids componentsJoinedByString: @","];
|
|
|
|
}
|
|
|
|
[uri appendString: @"Groups/_custom_"];
|
|
|
|
[uri appendString: uidsString];
|
|
|
|
[uri appendString: @"/"];
|
|
|
|
NSLog (@"Group URI = '%@'", uri);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-09-05 15:53:21 +02:00
|
|
|
else
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* check if lastPathComponent is the base that we want to have */
|
2006-09-05 15:53:21 +02:00
|
|
|
if ((([uidsString length] != 0)
|
|
|
|
&& (![userFolderID isEqualToString: uidsString])))
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSRange r;
|
|
|
|
|
|
|
|
/* uri ends with an '/', so we have to adjust the range a little */
|
|
|
|
r = NSMakeRange(0, [uri length] - 1);
|
2006-09-05 15:53:21 +02:00
|
|
|
r = [uri rangeOfString: @"/"
|
|
|
|
options: NSBackwardsSearch
|
|
|
|
range: r];
|
2006-06-15 21:34:10 +02:00
|
|
|
r = NSMakeRange(r.location + 1, [uri length] - r.location - 2);
|
2006-09-05 15:53:21 +02:00
|
|
|
[uri replaceCharactersInRange: r withString: uidsString];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[uri appendString: @"Calendar/"];
|
|
|
|
[uri appendString: prevMethod];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
NSLog(@"%s redirect uri:%@",
|
2006-09-05 15:53:21 +02:00
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
uri);
|
2006-06-15 21:34:10 +02:00
|
|
|
#endif
|
2006-09-05 15:53:21 +02:00
|
|
|
loc = [self completeHrefForMethod: uri]; /* this might return uri! */
|
|
|
|
r = [self redirectToLocation: loc];
|
2006-06-15 21:34:10 +02:00
|
|
|
[uri release];
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end /* UIxCalView */
|