diff --git a/UI/Contacts/UIxContactEditorBase.m b/UI/Contacts/UIxContactEditorBase.m index 779302c0a..3d8872281 100644 --- a/UI/Contacts/UIxContactEditorBase.m +++ b/UI/Contacts/UIxContactEditorBase.m @@ -199,11 +199,6 @@ return self; } -- (BOOL)isWriteableClientObject { - return [[self clientObject] - respondsToSelector:@selector(saveContentString:)]; -} - - (NSString *)viewActionName { /* this is overridden in the mail based contacts UI to redirect to tb.edit */ return @""; @@ -213,41 +208,55 @@ return @"edit"; } -- (id)saveAction { +- (id) saveAction +{ NSException *ex; - NSString *recstr, *uri; - id record; + NSString *uri; + NSDictionary *record; + NSMutableDictionary *newRecord; - if (![self isWriteableClientObject]) { - return [NSException exceptionWithHTTPStatus:400 /* Bad Request */ - reason:@"method cannot be invoked on " - @"the specified object"]; - } - - if ((record = [self contentString]) == nil) { - [self setErrorText:@"Missing object content!"]; // localize - return self; - } - record = [[[record propertyList] mutableCopy] autorelease]; - if (record == nil) { - [self setErrorText:@"Invalid property list data ..."]; // localize - return self; - } - - [self saveValuesIntoRecord:record]; - - // TODO: directly hacking the content, hm, not so nice or reasonable? - recstr = [record description]; // make plist - ex = [[self clientObject] saveContentString:recstr]; - if (ex != nil) { - [self setErrorText:[ex reason]]; - return self; - } - - uri = ([(uri = [self viewActionName]) length] > 0) - ? [self viewActionName] : @".."; - uri = [self _completeURIForMethod:uri]; - return [self redirectToLocation:uri]; + if ([[self clientObject] + respondsToSelector: @selector (saveContentString:)]) + { + if (contentString) + { + record = [contentString propertyList]; + if (record) + { + newRecord = [[record mutableCopy] autorelease]; + [self saveValuesIntoRecord: newRecord]; + ex = [[self clientObject] saveRecord: newRecord]; + if (ex) + { + [self setErrorText: [ex reason]]; + + return self; + } + else + { + uri = [self viewActionName]; + if ([uri length] <= 0) + uri = @".."; + + return [self redirectToLocation: [self _completeURIForMethod: uri]]; + } + } + else + { + [self setErrorText: @"Invalid property list data ..."]; // localize + return self; + } + } + else + { + [self setErrorText: @"Missing object content!"]; // localize + return self; + } + } + else + return [NSException exceptionWithHTTPStatus: 400 /* Bad Request */ + reason: @"method cannot be invoked on " + @"the specified object"]; } - (id)testAction {