From 3b764322d77c71afbce94a04a50d32d24f07b33d Mon Sep 17 00:00:00 2001 From: znek Date: Tue, 29 Jun 2004 22:34:55 +0000 Subject: [PATCH] work in progress. some more refactoring and overall improvement of the editor. git-svn-id: http://svn.opengroupware.org/SOGo/trunk@84 d1b88da0-ebda-0310-925b-ed51d893ca5b --- ZideStore/UI-X/Common/UIxComponent.h | 7 + ZideStore/UI-X/Common/UIxComponent.m | 20 ++ ZideStore/UI-X/Common/UIxPageFrame.wox | 2 +- .../UI-X/Scheduler/UIxAppointmentEditor.m | 171 +++++++++++++++++- .../UI-X/Scheduler/UIxAppointmentEditor.wox | 68 ++++--- ZideStore/UI-X/Scheduler/UIxAppointmentView.m | 6 + .../UI-X/Scheduler/UIxAppointmentView.wox | 52 +++--- ZideStore/UI-X/Scheduler/UIxCalView.h | 4 - ZideStore/UI-X/Scheduler/UIxCalView.m | 20 -- ZideStore/UI-X/Scheduler/product.plist | 5 + 10 files changed, 266 insertions(+), 89 deletions(-) diff --git a/ZideStore/UI-X/Common/UIxComponent.h b/ZideStore/UI-X/Common/UIxComponent.h index b3b41f59..d9a0c6ff 100644 --- a/ZideStore/UI-X/Common/UIxComponent.h +++ b/ZideStore/UI-X/Common/UIxComponent.h @@ -26,6 +26,8 @@ #include +@class NSCalendarDate; + @interface UIxComponent : SoComponent { @@ -43,6 +45,11 @@ - (NSString *)ownMethodName; +/* date selection */ +- (NSCalendarDate *)selectedDate; +- (NSString *)dateStringForDate:(NSCalendarDate *)_date; +- (NSCalendarDate *)dateForDateString:(NSString *)_dateString; + @end #endif /* __UIxComponent_H_ */ diff --git a/ZideStore/UI-X/Common/UIxComponent.m b/ZideStore/UI-X/Common/UIxComponent.m index 0a1650e6..280bcd71 100644 --- a/ZideStore/UI-X/Common/UIxComponent.m +++ b/ZideStore/UI-X/Common/UIxComponent.m @@ -145,4 +145,24 @@ return [uri substringFromIndex:(r.location + 1)]; } +/* date */ + +- (NSCalendarDate *)selectedDate { + NSString *s; + + s = [self queryParameterForKey:@"day"]; + if(s) { + return [self dateForDateString:s]; + } + return [NSCalendarDate date]; +} + +- (NSString *)dateStringForDate:(NSCalendarDate *)_date { + return [_date descriptionWithCalendarFormat:@"%Y%m%d"]; +} + +- (NSCalendarDate *)dateForDateString:(NSString *)_dateString { + return [NSCalendarDate dateWithString:_dateString calendarFormat:@"%Y%m%d"]; +} + @end diff --git a/ZideStore/UI-X/Common/UIxPageFrame.wox b/ZideStore/UI-X/Common/UIxPageFrame.wox index 8a7f9d6d..efc1f4d9 100644 --- a/ZideStore/UI-X/Common/UIxPageFrame.wox +++ b/ZideStore/UI-X/Common/UIxPageFrame.wox @@ -240,7 +240,7 @@ - Logout + Logout diff --git a/ZideStore/UI-X/Scheduler/UIxAppointmentEditor.m b/ZideStore/UI-X/Scheduler/UIxAppointmentEditor.m index f2e19784..23860cf2 100644 --- a/ZideStore/UI-X/Scheduler/UIxAppointmentEditor.m +++ b/ZideStore/UI-X/Scheduler/UIxAppointmentEditor.m @@ -24,14 +24,55 @@ #include "common.h" #include #include +#include +/* TODO: CLEAN THIS MESS UP */ + + +@interface NSObject (AppointmentHack) +- (BOOL)isAppointment; +@end + +@implementation NSObject (AppointmentHack) +- (BOOL)isAppointment { + return NO; +} +@end + +@interface SxAppointment : NSObject +@end + +@implementation SxAppointment (AppointmentHack) +- (BOOL)isAppointment { + return YES; +} +@end + +@interface iCalPerson (Convenience) +- (NSString *)rfc822Email; +@end + +@implementation iCalPerson (Convenience) +- (NSString *)rfc822Email { + NSString *_email = [self email]; + NSRange colon = [_email rangeOfString:@":"]; + if(colon.location != NSNotFound) { + return [_email substringFromIndex:colon.location + 1]; + } + return _email; +} +@end + @interface UIxAppointmentEditor : UIxComponent { id appointment; + id participants; } - (SOGoAppointment *)appointment; +- (NSString *)iCalStringTemplate; +- (BOOL)isNewAppointment; @end @@ -39,6 +80,7 @@ - (void)dealloc { [self->appointment release]; + [self->participants release]; [super dealloc]; } @@ -54,6 +96,9 @@ return [date descriptionWithCalendarFormat:@"%A, %Y-%m-%d %H:%M %Z"]; } +- (BOOL)isNewAppointment { + return ! [[self clientObject] isAppointment]; +} /* backend */ @@ -61,11 +106,131 @@ - (SOGoAppointment *)appointment { if(self->appointment == nil) { NSString *iCalString; - - iCalString = [[self clientObject] valueForKey:@"iCalString"]; - self->appointment = [[SOGoAppointment alloc] initWithICalString:iCalString]; + + if([[self clientObject] isAppointment]) { + iCalString = [[self clientObject] valueForKey:@"iCalString"]; + } + else { + iCalString = [self iCalStringTemplate]; + } + self->appointment = [[SOGoAppointment alloc] + initWithICalString:iCalString]; } return self->appointment; } +- (id)participants { + if(self->participants == nil) { + NSArray *attendees; + NSMutableArray *emailAddresses; + unsigned i, count; + + attendees = [self->appointment attendees]; + count = [attendees count]; + emailAddresses = [[NSMutableArray alloc] initWithCapacity:count]; + for(i = 0; i < count; i++) { + NSString *email; + + email = [[attendees objectAtIndex:i] rfc822Email]; + if(email) + [emailAddresses addObject:email]; + } + self->participants = [[emailAddresses componentsJoinedByString:@"\n"] + retain]; + [emailAddresses release]; + } + return self->participants; +} + +- (NSString *)iCalStringTemplate { + static NSString *iCalStringTemplate = \ + @"BEGIN:VCALENDAR\nMETHOD:REQUEST\nPRODID:OpenGroupware.org ZideStore 1.2\n" \ + @"VERSION:2.0\nBEGIN:VEVENT\nCLASS:PRIVATE\nSTATUS:CONFIRMED\n" \ + @"DTSTART:%@\nDTEND:%@\n" \ + @"TRANSP:OPAQUE\n" \ + @"END:VEVENT\nEND:VCALENDAR"; + NSCalendarDate *startDate, *endDate; + NSString *template; + + startDate = [self selectedDate]; + endDate = [startDate dateByAddingYears:0 months:0 days:0 + hours:1 minutes:0 seconds:0]; + + + template = [NSString stringWithFormat:iCalStringTemplate, + [startDate icalString], + [endDate icalString]]; + + return template; +} + + +/* helper */ + +- (NSString *)uriAsFormat { + NSString *uri, *qp; + NSRange r; + + uri = [[[self context] request] uri]; + + /* first: identify query parameters */ + r = [uri rangeOfString:@"?" options:NSBackwardsSearch]; + if (r.length > 0) { + uri = [uri substringToIndex:r.location]; + qp = [uri substringFromIndex:r.location]; + } + else { + qp = nil; + } + + /* next: strip trailing slash */ + if([uri hasSuffix:@"/"]) + uri = [uri substringToIndex:([uri length] - 1)]; + r = [uri rangeOfString:@"/" options:NSBackwardsSearch]; + + /* then: cut of last path component */ + if(r.location == NSNotFound) { // no slash? are we at root? + uri = @"/"; + } + else { + uri = [uri substringToIndex:(r.location + 1)]; + } + /* next: append format token */ + uri = [uri stringByAppendingString:@"%@"]; + if(qp != nil) + uri = [uri stringByAppendingString:qp]; + return uri; +} + + +/* save */ + + +- (id)saveAction { + NSString *foo, *nextMethod, *uri, *uriFormat; + NSMutableArray *attendees; + WOResponse *r; + WORequest *req; + + req = [[self context] request]; + foo = [req formValueForKey:@"ical"]; + + if([self isNewAppointment]) + nextMethod = @"duhduh"; + else + nextMethod = @"view"; + + uriFormat = [self uriAsFormat]; + uri = [NSString stringWithFormat:uriFormat, nextMethod]; + NSLog(@"%s got foo:%@, redirecting to '%@'", + __PRETTY_FUNCTION__, + foo, + uri); + + r = [WOResponse responseWithRequest:req]; + [r setStatus:302 /* moved */]; + [r setHeader:uri forKey:@"location"]; + return r; +} + @end diff --git a/ZideStore/UI-X/Scheduler/UIxAppointmentEditor.wox b/ZideStore/UI-X/Scheduler/UIxAppointmentEditor.wox index 64da2f1c..12b699ea 100644 --- a/ZideStore/UI-X/Scheduler/UIxAppointmentEditor.wox +++ b/ZideStore/UI-X/Scheduler/UIxAppointmentEditor.wox @@ -7,6 +7,7 @@ title="name" > +
+ + + + + + + + + + + + @@ -54,11 +85,11 @@
@@ -36,7 +37,37 @@ - start time + + +
+ End time: + + + + +
+ Title: + + + + +
+ Location: + + +
- Start time: + Participants: - textarea +