From 985349a871b66f0bd3efb0e6d0346da57d07b690 Mon Sep 17 00:00:00 2001 From: helge Date: Sun, 15 Aug 2004 19:28:26 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@234 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/UI/Scheduler/ChangeLog | 3 + SOGo/UI/Scheduler/UIxAppointmentEditor.m | 139 +++++++++++---------- SOGo/UI/Scheduler/UIxAppointmentEditor.wox | 7 ++ SOGo/UI/Scheduler/Version | 2 +- 4 files changed, 83 insertions(+), 68 deletions(-) diff --git a/SOGo/UI/Scheduler/ChangeLog b/SOGo/UI/Scheduler/ChangeLog index 732da32a..c26bcb01 100644 --- a/SOGo/UI/Scheduler/ChangeLog +++ b/SOGo/UI/Scheduler/ChangeLog @@ -1,5 +1,8 @@ 2004-08-15 Helge Hess + * UIxAppointmentEditor.m: more decoupling from iCal. Added some error + handling UI code (errorText), date selector is broken (v0.9.47) + * v0.9.46 * iCalPerson+UIx.m: changed -cnForDisplay method, znek needs to check diff --git a/SOGo/UI/Scheduler/UIxAppointmentEditor.m b/SOGo/UI/Scheduler/UIxAppointmentEditor.m index 8922837f..9d04485a 100644 --- a/SOGo/UI/Scheduler/UIxAppointmentEditor.m +++ b/SOGo/UI/Scheduler/UIxAppointmentEditor.m @@ -31,7 +31,7 @@ @interface UIxAppointmentEditor : UIxComponent { NSString *iCalString; - id appointment; + NSString *errorText; id item; /* individual values */ @@ -44,7 +44,6 @@ NSArray *resources; } -- (SOGoAppointment *)appointment; - (NSString *)iCalStringTemplate; - (NSString *)iCalString; @@ -73,6 +72,7 @@ @implementation UIxAppointmentEditor - (void)dealloc { + [self->errorText release]; [self->participants release]; [self->resources release]; [self->startDate release]; @@ -81,7 +81,6 @@ [self->location release]; [self->comment release]; [self->iCalString release]; - [self->appointment release]; [self->item release]; [super dealloc]; } @@ -95,6 +94,16 @@ return self->item; } +- (void)setErrorText:(NSString *)_txt { + ASSIGNCOPY(self->errorText, _txt); +} +- (NSString *)errorText { + return self->errorText; +} +- (BOOL)hasErrorText { + return [self->errorText length] > 0 ? YES : NO; +} + - (NSFormatter *)titleDateFormatter { SOGoDateFormatter *fmt; @@ -187,10 +196,6 @@ return template; } -- (SOGoAppointment *)appointment { - return self->appointment; -} - /* helper */ - (NSString *)_completeURIForMethod:(NSString *)_method { @@ -329,6 +334,47 @@ self->resources = [[_appointment resources] retain]; } +- (void)saveValuesIntoAppointment:(SOGoAppointment *)_appointment { + /* merge in form values */ + NSArray *attendees, *lResources; + +#warning TODO: broken for the new date/time selector! +#if 0 + NSCalendarDate *sd, *ed; + + sd = [self _dateFromString:[req formValueForKey:@"startDate"]]; + ed = [self _dateFromString:[req formValueForKey:@"endDate"]]; + if (sd == nil || ed == nil) { + [self setErrorText:@"missing startdate or enddate ..."]; // localize + return self; + } + [_appointment setStartDate:sd]; + [_appointment setEndDate:ed]; +#endif + + [_appointment setSummary:[self title]]; + [_appointment setLocation:[self location]]; + + attendees = [self participants]; + lResources = [self resources]; + if ([lResources count] > 0) { + attendees = ([attendees count] > 0) + ? [attendees arrayByAddingObjectsFromArray:lResources] + : lResources; + } + [_appointment setAttendees:attendees]; + + [_appointment setOrganizer:[self getOrganizer]]; +} + +- (void)loadValuesFromICalString:(NSString *)_ical { + SOGoAppointment *apt; + + apt = [[SOGoAppointment alloc] initWithICalString:_ical]; + [self loadValuesFromAppointment:apt]; + [apt release]; +} + /* actions */ - (BOOL)shouldTakeValuesFromRequest:(WORequest *)_rq inContext:(WOContext*)_c{ @@ -356,24 +402,16 @@ ical = [self iCalStringTemplate]; [self setICalString:ical]; - - /* parse */ - - self->appointment = - [[SOGoAppointment alloc] initWithICalString:[self iCalString]]; - - /* load values */ - - [self loadValuesFromAppointment:[self appointment]]; + [self loadValuesFromICalString:ical]; return self; } - (id)saveAction { - NSString *uri; - NSCalendarDate *sd, *ed; - NSArray *attendees, *lResources; - WORequest *req; + SOGoAppointment *apt; + NSString *uri; + NSException *ex; + NSString *content; if (![self isWriteableClientObject]) { /* return 400 == Bad Request */ @@ -382,58 +420,25 @@ @"the specified object"]; } - req = [[self context] request]; - - /* get iCalString from hidden input */ - [self setICalString:[req formValueForKey:@"ical"]]; - - self->appointment = - [[SOGoAppointment alloc] initWithICalString:[self iCalString]]; - - if (self->appointment == nil) { - return [NSException exceptionWithHTTPStatus:400 /* Bad Request */ - reason:@"invalid iCalendar form data in request"]; + apt = [[SOGoAppointment alloc] initWithICalString:[self iCalString]]; + if (apt == nil) { + [self setErrorText:@"Invalid iCalendar data ..."]; // localize + return self; } - /* merge in form values */ + [self saveValuesIntoAppointment:apt]; + content = [apt iCalString]; + [apt release]; apt = nil; - sd = [self _dateFromString:[req formValueForKey:@"startDate"]]; - ed = [self _dateFromString:[req formValueForKey:@"endDate"]]; - [self->appointment setStartDate:sd]; - [self->appointment setEndDate:ed]; - - [self->appointment setSummary:[req formValueForKey:@"summary"]]; - [self->appointment setLocation:[req formValueForKey:@"location"]]; - - attendees = [self getICalPersonsFromFormValues: - [req formValuesForKey:@"participants"] - treatAsResource:NO]; - lResources = [self getICalPersonsFromFormValues: - [req formValuesForKey:@"resources"] - treatAsResource:YES]; - if ([lResources count] > 0) { - attendees = ([attendees count] > 0) - ? [attendees arrayByAddingObjectsFromArray:lResources] - : lResources; + if (content == nil) { + [self setErrorText:@"Could not create iCalendar data ..."]; // localize + return self; } - [self->appointment setAttendees:attendees]; - - [self->appointment setOrganizer:[self getOrganizer]]; - /* receive current representation for save operation */ - { - NSException *ex; - NSString *content; - - content = [self->appointment iCalString]; - if (content == nil) { - return [NSException exceptionWithHTTPStatus:500 /* Internal Error */ - reason:@"failed to create iCal content for apt"]; - } - - ex = [[self clientObject] saveContentString:content]; - if (ex) return ex; - // TODO: add some error handling in form! (eg like in Zope) + ex = [[self clientObject] saveContentString:content]; + if (ex != nil) { + [self setErrorText:[ex reason]]; + return self; } uri = [self _completeURIForMethod:@".."]; diff --git a/SOGo/UI/Scheduler/UIxAppointmentEditor.wox b/SOGo/UI/Scheduler/UIxAppointmentEditor.wox index d32b0c0e..a0a9b405 100644 --- a/SOGo/UI/Scheduler/UIxAppointmentEditor.wox +++ b/SOGo/UI/Scheduler/UIxAppointmentEditor.wox @@ -25,6 +25,13 @@ + + + + +
+
+ diff --git a/SOGo/UI/Scheduler/Version b/SOGo/UI/Scheduler/Version index 3c9ce3a1..8846f04e 100644 --- a/SOGo/UI/Scheduler/Version +++ b/SOGo/UI/Scheduler/Version @@ -1,6 +1,6 @@ # $Id$ -SUBMINOR_VERSION:=46 +SUBMINOR_VERSION:=47 # v0.9.41 requires libNGObjWeb v4.2.431 # v0.9.31 requires libWEExtensions v4.2.52 -- 2.39.5