@interface UIxAppointmentEditor : UIxComponent
{
NSString *iCalString;
- id appointment;
+ NSString *errorText;
id item;
/* individual values */
NSArray *resources;
}
-- (SOGoAppointment *)appointment;
- (NSString *)iCalStringTemplate;
- (NSString *)iCalString;
@implementation UIxAppointmentEditor
- (void)dealloc {
+ [self->errorText release];
[self->participants release];
[self->resources release];
[self->startDate release];
[self->location release];
[self->comment release];
[self->iCalString release];
- [self->appointment release];
[self->item release];
[super dealloc];
}
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;
return template;
}
-- (SOGoAppointment *)appointment {
- return self->appointment;
-}
-
/* helper */
- (NSString *)_completeURIForMethod:(NSString *)_method {
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{
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 */
@"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:@".."];