From 0915484b8aa0b7c34d552c8edac18102e7100e42 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Wed, 2 Aug 2006 20:04:23 +0000 Subject: [PATCH] Monotone-Parent: bacf416c77fa06cce947c93f090428795613d178 Monotone-Revision: 7f4d04c212fb046155310ec6e6fc96cc8c263d9f Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2006-08-02T20:04:23 Monotone-Branch: ca.inverse.sogo --- UI/Contacts/UIxContactEditorBase.m | 85 +++++++++++++++++------------- 1 file changed, 47 insertions(+), 38 deletions(-) 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 {