02111-1307, USA.
*/
-#import <NGCards/NGVCard.h>
-#import <NGCards/NSArray+NGCards.h>
+#import <Foundation/NSDictionary.h>
+#import <Foundation/NSString.h>
+#import <NGObjWeb/NSException+HTTP.h>
#import <NGObjWeb/SoObject.h>
+#import <NGObjWeb/WORequest.h>
+#import <NGExtensions/NSNull+misc.h>
+
+#import <NGCards/NGVCard.h>
+#import <NGCards/NSArray+NGCards.h>
#import <Contacts/SOGoContactObject.h>
#import <Contacts/SOGoContactFolder.h>
-#import "common.h"
#import "UIxContactEditor.h"
/* load/store content format */
-- (void)_fixupSnapshot {
+- (void) _fixupSnapshot
+{
// TODO: perform sanity checking, eg build CN on demand
NSString *cn, *gn, *sn;
- cn = [snapshot objectForKey:@"cn"];
- gn = [snapshot objectForKey:@"givenName"];
- sn = [snapshot objectForKey:@"sn"];
+ cn = [snapshot objectForKey: @"cn"];
+ gn = [snapshot objectForKey: @"givenName"];
+ sn = [snapshot objectForKey: @"sn"];
if (![sn isNotNull] || [sn length] == 0)
sn = nil;
// TODO: need a better name parser here
NSRange r;
- r = [cn rangeOfString:@" "];
+ r = [cn rangeOfString: @" "];
sn = (r.length > 0)
? [cn substringFromIndex:(r.location + r.length)]
: cn;
}
- [snapshot setObject:sn forKey:@"sn"];
+ [snapshot setObject:sn forKey: @"sn"];
}
if (sn == nil && gn == nil)
cn = @"[noname]";
else if (gn == nil)
cn = sn;
else
- cn = [[gn stringByAppendingString:@" "] stringByAppendingString:sn];
- [snapshot setObject:cn forKey:@"cn"];
+ cn = [[gn stringByAppendingString: @" "] stringByAppendingString:sn];
+ [snapshot setObject:cn forKey: @"cn"];
}
/* helper */
uri = [[[self context] request] uri];
/* first: identify query parameters */
- r = [uri rangeOfString:@"?" options:NSBackwardsSearch];
+ r = [uri rangeOfString: @"?" options:NSBackwardsSearch];
if (r.length > 0)
uri = [uri substringToIndex:r.location];
/* next: append trailing slash */
- if (![uri hasSuffix:@"/"])
- uri = [uri stringByAppendingString:@"/"];
+ if (![uri hasSuffix: @"/"])
+ uri = [uri stringByAppendingString: @"/"];
/* next: append method */
uri = [uri stringByAppendingString:_method];
[self initSnapshot];
else
return [NSException exceptionWithHTTPStatus:404 /* Not Found */
- reason:@"could not open contact"];
+ reason: @"could not open contact"];
return self;
}
- (void) _saveSnapshot
{
CardElement *element;
+ NSArray *units;
[card setNWithFamily: [snapshot objectForKey: @"sn"]
given: [snapshot objectForKey: @"givenName"]
value: [snapshot objectForKey: @"calFBURL"]];
[card setUniqueChild: element];
+ units = [NSArray arrayWithObject: [snapshot objectForKey: @"workService"]];
+ [card setOrg: [snapshot objectForKey: @"workCompany"]
+ units: units];
+
[self _savePhoneValues];
[self _saveEmails];
+ [[self _elementWithTag: @"url" ofType: @"home"]
+ setValue: 0 to: [snapshot objectForKey: @"homeURL"]];
+ [[self _elementWithTag: @"url" ofType: @"work"]
+ setValue: 0 to: [snapshot objectForKey: @"workURL"]];
+
[[card uniqueChildWithTag: @"x-aim"]
- setValue: 0 to: [snapshot objectForKey: @"screenName"]];
+ setValue: 0
+ to: [snapshot objectForKey: @"screenName"]];
}
- (id <WOActionResults>) saveAction
- (id) writeAction
{
- NSString *email, *url;
+ NSString *email, *cn, *url;
+ NSMutableString *address;
card = [[self clientObject] vCard];
[self initSnapshot];
email = [snapshot objectForKey: @"workMail"];
if (email)
- url = [NSString stringWithFormat: @"Mail/compose?mailto=%@", email];
+ {
+ address = [NSMutableString string];
+ cn = [card fn];
+ if ([cn length] > 0)
+ [address appendFormat: @"%@ <%@>", cn, email];
+ else
+ [address appendString: email];
+
+ url = [NSString stringWithFormat: @"Mail/compose?mailto=%@", address];
+ }
else
url = @"Mail/compose";
[self redirectToLocation: [self relativePathToUserFolderSubPath: url]];
}
-- (id)newAction {
+- (id) newAction
+{
// TODO: this is almost a DUP of UIxAppointmentEditor
/*
This method creates a unique ID and redirects to the "edit" method on the
objectId = nil;
if ([objectId length] == 0)
- return [NSException exceptionWithHTTPStatus:500 /* Internal Error */
- reason:@"could not create a unique ID"];
+ return [NSException exceptionWithHTTPStatus: 500 /* Internal Error */
+ reason: @"could not create a unique ID"];
- nextMethod = [NSString stringWithFormat:@"../%@/%@",
- objectId, [self editActionName]];
- uri = [self _completeURIForMethod:nextMethod];
- return [self redirectToLocation:uri];
+ nextMethod = [NSString stringWithFormat: @"../%@/%@",
+ objectId, [self editActionName]];
+ uri = [self _completeURIForMethod: nextMethod];
+ return [self redirectToLocation: uri];
}
@end /* UIxContactEditor */