2006-06-15 21:34:10 +02:00
|
|
|
// $Id: UIxCalView.m 885 2005-07-21 16:41:34Z znek $
|
|
|
|
|
|
|
|
#include "UIxCalView.h"
|
|
|
|
#include "common.h"
|
|
|
|
//#include <OGoContentStore/OCSFolder.h>
|
|
|
|
#include "SoObjects/Appointments/SOGoAppointmentFolder.h"
|
|
|
|
#include <NGObjWeb/SoUser.h>
|
|
|
|
#include <SOGoUI/SOGoAptFormatter.h>
|
|
|
|
#include <NGExtensions/NGCalendarDateRange.h>
|
|
|
|
#include <NGiCal/NGiCal.h>
|
|
|
|
#include "UIxComponent+Agenor.h"
|
|
|
|
|
|
|
|
@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;
|
|
|
|
|
|
|
|
tz = [self viewTimeZone];
|
|
|
|
self->aptFormatter
|
|
|
|
= [[SOGoAptFormatter alloc] initWithDisplayTimeZone: tz];
|
|
|
|
self->aptTooltipFormatter
|
|
|
|
= [[SOGoAptFormatter alloc] initWithDisplayTimeZone: tz];
|
|
|
|
self->privateAptFormatter
|
|
|
|
= [[SOGoAptFormatter alloc] initWithDisplayTimeZone: tz];
|
|
|
|
self->privateAptTooltipFormatter
|
|
|
|
= [[SOGoAptFormatter alloc] initWithDisplayTimeZone: tz];
|
|
|
|
[self configureFormatters];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
[self->appointments release];
|
|
|
|
[self->allDayApts release];
|
|
|
|
[self->appointment release];
|
|
|
|
[self->currentDay release];
|
|
|
|
[self->aptFormatter release];
|
|
|
|
[self->aptTooltipFormatter release];
|
|
|
|
[self->privateAptFormatter release];
|
|
|
|
[self->privateAptTooltipFormatter release];
|
|
|
|
[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;
|
|
|
|
|
|
|
|
[self->aptFormatter setFullDetails];
|
|
|
|
[self->aptTooltipFormatter setTooltip];
|
|
|
|
[self->privateAptFormatter setPrivateDetails];
|
|
|
|
[self->privateAptTooltipFormatter setPrivateTooltip];
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
title = [self labelForKey: @"empty title"];
|
|
|
|
[self->aptFormatter setTitlePlaceholder: title];
|
|
|
|
[self->aptTooltipFormatter setTitlePlaceholder: title];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
title = [self labelForKey: @"private appointment"];
|
|
|
|
[self->privateAptFormatter setPrivateTitle: title];
|
|
|
|
[self->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;
|
|
|
|
unsigned i, count;
|
|
|
|
NSString *email;
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
count = [_apts count];
|
2006-06-15 21:34:10 +02:00
|
|
|
if (!count) return _apts;
|
|
|
|
if ([self shouldDisplayRejectedAppointments]) return _apts;
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
filtered = [[[NSMutableArray alloc] initWithCapacity: count] autorelease];
|
|
|
|
email = [self emailForUser];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
NSDictionary *info;
|
|
|
|
NSArray *partmails;
|
|
|
|
unsigned p, pCount;
|
|
|
|
BOOL shouldAdd;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
shouldAdd = YES;
|
|
|
|
info = [_apts objectAtIndex: i];
|
|
|
|
partmails = [[info objectForKey: @"partmails"]
|
|
|
|
componentsSeparatedByString: @"\n"];
|
|
|
|
pCount = [partmails count];
|
|
|
|
for (p = 0; p < pCount; p++)
|
|
|
|
{
|
|
|
|
NSString *pEmail;
|
|
|
|
|
|
|
|
pEmail = [partmails objectAtIndex: p];
|
|
|
|
if ([pEmail isEqualToString: email])
|
|
|
|
{
|
|
|
|
NSArray *partstates;
|
|
|
|
NSString *state;
|
|
|
|
|
|
|
|
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-06-15 21:34:10 +02:00
|
|
|
ASSIGN(self->appointments, _apts);
|
|
|
|
}
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSArray *) appointments
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->appointments;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (void) setAppointment:(id) _apt
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *mailtoChunk;
|
|
|
|
NSString *myEmail;
|
|
|
|
|
|
|
|
ASSIGN(self->appointment, _apt);
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
self->aptFlags.isMyApt = YES;
|
2006-06-15 21:34:10 +02:00
|
|
|
self->aptFlags.canAccessApt = YES;
|
2006-09-05 15:53:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSString *partmails;
|
|
|
|
|
|
|
|
self->aptFlags.isMyApt = NO;
|
|
|
|
|
|
|
|
partmails = [_apt valueForKey: @"partmails"];
|
|
|
|
if ([partmails rangeOfString: myEmail].length)
|
|
|
|
self->aptFlags.canAccessApt = YES;
|
|
|
|
else
|
|
|
|
self->aptFlags.canAccessApt = [[_apt valueForKey: @"ispublic"] boolValue];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-08-15 22:56:54 +02:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (id) appointment
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->appointment;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) isMyApt
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->aptFlags.isMyApt ? YES : NO;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) canAccessApt
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->aptFlags.canAccessApt ? YES : NO;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (BOOL) canNotAccessApt
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->aptFlags.canAccessApt ? NO : YES;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
if (self->aptFlags.canAccessApt)
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->aptFormatter;
|
|
|
|
return self->privateAptFormatter;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (SOGoAptFormatter *) aptTooltipFormatter
|
|
|
|
{
|
|
|
|
if (self->aptFlags.canAccessApt)
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->aptTooltipFormatter;
|
|
|
|
return self->privateAptTooltipFormatter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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-09-05 15:53:21 +02:00
|
|
|
return [[self aptFormatter] stringForObjectValue: self->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-09-05 15:53:21 +02:00
|
|
|
title = [self->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__];
|
|
|
|
return [[self aptTooltipFormatter] stringForObjectValue: self->appointment
|
|
|
|
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
|
|
|
|
{
|
|
|
|
[_day setTimeZone: [self viewTimeZone]];
|
2006-06-15 21:34:10 +02:00
|
|
|
ASSIGN(self->currentDay, _day);
|
|
|
|
}
|
2006-08-19 00:56:47 +02:00
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSCalendarDate *) currentDay
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->currentDay;
|
|
|
|
}
|
|
|
|
|
2006-08-19 00:56:47 +02:00
|
|
|
- (NSString *) currentDayName
|
|
|
|
{
|
|
|
|
return [self localizedNameForDayOfWeek: [self->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;
|
|
|
|
|
|
|
|
if (self->allDayApts)
|
|
|
|
return self->allDayApts;
|
|
|
|
|
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
|
|
|
|
|
|
|
ASSIGN(self->allDayApts, filtered);
|
|
|
|
[filtered release];
|
|
|
|
return self->allDayApts;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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-06-15 21:34:10 +02:00
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (unsigned) dayEndHour
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return 18;
|
|
|
|
}
|
|
|
|
|
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-09-05 15:53:21 +02:00
|
|
|
- (NSCalendarDate *) endDate
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self startDate] tomorrow];
|
|
|
|
}
|
|
|
|
|
2006-09-05 15:53:21 +02:00
|
|
|
- (NSArray *) fetchCoreInfos
|
|
|
|
{
|
2006-09-05 22:13:16 +02:00
|
|
|
SOGoAppointmentFolder *folder;
|
|
|
|
NSCalendarDate *sd, *ed;
|
|
|
|
|
|
|
|
if (!self->appointments)
|
2006-09-05 15:53:21 +02:00
|
|
|
{
|
|
|
|
folder = [self clientObject];
|
|
|
|
sd = [self startDate];
|
|
|
|
ed = [self endDate];
|
|
|
|
[self setAppointments: [folder fetchOverviewInfosFrom: sd to: ed]];
|
|
|
|
}
|
2006-08-19 00:56:47 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->appointments;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
{
|
|
|
|
return [self queryParametersBySettingSelectedDate: self->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"];
|
2006-06-15 21:34:10 +02:00
|
|
|
uidsString = [uidsString stringByTrimmingWhiteSpaces];
|
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 */
|