2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-05-10 16:59:17 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2007-05-09 21:23:45 +02:00
|
|
|
#import <Foundation/NSString.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-09 21:23:45 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2006-10-20 23:15:26 +02:00
|
|
|
#import <NGObjWeb/SoObject.h>
|
2007-05-09 21:23:45 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2008-03-07 23:09:33 +01:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2007-05-09 21:23:45 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
|
|
|
|
#import <NGCards/NGVCard.h>
|
|
|
|
#import <NGCards/NSArray+NGCards.h>
|
2006-10-20 23:15:26 +02:00
|
|
|
|
2006-09-16 00:23:29 +02:00
|
|
|
#import <Contacts/SOGoContactObject.h>
|
2008-03-07 23:09:33 +01:00
|
|
|
#import <Contacts/SOGoContactGCSEntry.h>
|
|
|
|
#import <Contacts/SOGoContactGCSFolder.h>
|
2006-09-16 00:23:29 +02:00
|
|
|
|
|
|
|
#import "UIxContactEditor.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation UIxContactEditor
|
2006-09-16 00:23:29 +02:00
|
|
|
|
2006-09-19 23:03:12 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2007-02-02 21:48:56 +01:00
|
|
|
snapshot = [[NSMutableDictionary alloc] initWithCapacity: 16];
|
2006-09-19 23:03:12 +02:00
|
|
|
preferredEmail = nil;
|
|
|
|
}
|
|
|
|
|
2006-09-16 00:23:29 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-09-19 23:03:12 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-12-21 22:49:05 +01:00
|
|
|
[snapshot release];
|
2007-03-22 20:02:45 +01:00
|
|
|
[preferredEmail release];
|
2006-09-16 00:23:29 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
2008-03-07 23:09:33 +01:00
|
|
|
- (NSString *) saveURL
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%@/saveAsContact",
|
|
|
|
[[self clientObject] baseURL]];
|
|
|
|
}
|
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
- (NSArray *) htmlMailFormatList
|
2006-09-16 00:23:29 +02:00
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
static NSArray *htmlMailFormatItems = nil;
|
|
|
|
|
|
|
|
if (!htmlMailFormatItems)
|
|
|
|
{
|
|
|
|
htmlMailFormatItems = [NSArray arrayWithObjects: @"FALSE", @"TRUE", nil];
|
|
|
|
[htmlMailFormatItems retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return htmlMailFormatItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) itemHtmlMailFormatText
|
|
|
|
{
|
|
|
|
return [self labelForKey:
|
|
|
|
[NSString stringWithFormat: @"htmlMailFormat_%@", item]];
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
- (void) setItem: (NSString *) newItem
|
2006-09-19 23:03:12 +02:00
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
item = newItem;
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
- (NSString *) item
|
2006-09-19 23:03:12 +02:00
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return item;
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* load/store content format */
|
|
|
|
|
2007-12-21 22:49:05 +01:00
|
|
|
// - (void) _fixupSnapshot
|
|
|
|
// {
|
|
|
|
// NSString *currentKey, *currentString;
|
|
|
|
// NSMutableString *newString;
|
|
|
|
// NSArray *keys;
|
|
|
|
// unsigned int count, max;
|
|
|
|
|
|
|
|
// keys = [snapshot allKeys];
|
|
|
|
// max = [keys count];
|
|
|
|
// for (count = 0; count < max; count++)
|
|
|
|
// {
|
|
|
|
// currentKey = [keys objectAtIndex: count];
|
|
|
|
// currentString = [snapshot objectForKey: currentKey];
|
|
|
|
// newString = [currentString mutableCopy];
|
|
|
|
// [newString autorelease];
|
|
|
|
// [newString replaceString: @";" withString: @"\\;"];
|
|
|
|
// if (![newString isEqualToString: currentString])
|
|
|
|
// [snapshot setObject: newString forKey: currentKey];
|
|
|
|
// }
|
|
|
|
// }
|
2006-09-16 00:23:29 +02:00
|
|
|
|
|
|
|
/* helper */
|
|
|
|
|
|
|
|
- (NSString *)_completeURIForMethod:(NSString *)_method {
|
|
|
|
// TODO: this is a DUP of UIxAppointmentEditor
|
|
|
|
NSString *uri;
|
|
|
|
NSRange r;
|
|
|
|
|
|
|
|
uri = [[[self context] request] uri];
|
|
|
|
|
|
|
|
/* first: identify query parameters */
|
2007-04-02 23:13:57 +02:00
|
|
|
r = [uri rangeOfString: @"?" options:NSBackwardsSearch];
|
2006-09-16 00:23:29 +02:00
|
|
|
if (r.length > 0)
|
|
|
|
uri = [uri substringToIndex:r.location];
|
|
|
|
|
|
|
|
/* next: append trailing slash */
|
2007-04-02 23:13:57 +02:00
|
|
|
if (![uri hasSuffix: @"/"])
|
|
|
|
uri = [uri stringByAppendingString: @"/"];
|
2006-09-16 00:23:29 +02:00
|
|
|
|
|
|
|
/* next: append method */
|
|
|
|
uri = [uri stringByAppendingString:_method];
|
|
|
|
|
|
|
|
/* next: append query parameters */
|
|
|
|
return [self completeHrefForMethod:uri];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* actions */
|
|
|
|
|
2008-03-07 23:09:33 +01:00
|
|
|
- (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
|
|
|
|
inContext: (WOContext*) context
|
2006-09-16 00:23:29 +02:00
|
|
|
{
|
2008-03-07 23:09:33 +01:00
|
|
|
NSString *actionName;
|
|
|
|
|
|
|
|
actionName = [[request requestHandlerPath] lastPathComponent];
|
|
|
|
|
|
|
|
return ([[self clientObject] isKindOfClass: [SOGoContactGCSEntry class]]
|
|
|
|
&& [actionName hasPrefix: @"save"]);
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setSnapshotValue: (NSString *) key
|
|
|
|
to: (NSString *) aValue
|
|
|
|
{
|
|
|
|
if (!aValue)
|
|
|
|
aValue = @"";
|
|
|
|
|
|
|
|
[snapshot setObject: aValue forKey: key];
|
|
|
|
}
|
|
|
|
|
2006-09-19 23:03:12 +02:00
|
|
|
- (NSMutableDictionary *) snapshot
|
|
|
|
{
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
2006-09-16 00:23:29 +02:00
|
|
|
- (NSString *) _simpleValueForType: (NSString *) aType
|
|
|
|
inArray: (NSArray *) anArray
|
|
|
|
{
|
|
|
|
NSArray *elements;
|
|
|
|
NSString *value;
|
|
|
|
|
|
|
|
elements = [anArray cardElementsWithAttribute: @"type"
|
|
|
|
havingValue: aType];
|
|
|
|
if ([elements count] > 0)
|
|
|
|
value = [[elements objectAtIndex: 0] value: 0];
|
|
|
|
else
|
|
|
|
value = nil;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setupEmailFields
|
|
|
|
{
|
|
|
|
NSArray *elements;
|
|
|
|
NSString *workMail, *homeMail, *prefMail, *potential;
|
|
|
|
unsigned int max;
|
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"email"];
|
|
|
|
max = [elements count];
|
|
|
|
workMail = [self _simpleValueForType: @"work"
|
|
|
|
inArray: elements];
|
|
|
|
homeMail = [self _simpleValueForType: @"home"
|
|
|
|
inArray: elements];
|
|
|
|
prefMail = [self _simpleValueForType: @"pref"
|
|
|
|
inArray: elements];
|
|
|
|
|
|
|
|
if (max > 0)
|
|
|
|
{
|
|
|
|
potential = [[elements objectAtIndex: 0] value: 0];
|
|
|
|
if (!workMail)
|
|
|
|
{
|
|
|
|
if (homeMail && homeMail == potential && max > 1)
|
|
|
|
workMail = [[elements objectAtIndex: 1] value: 0];
|
|
|
|
else
|
|
|
|
workMail = potential;
|
|
|
|
}
|
2006-09-19 23:03:12 +02:00
|
|
|
if (!homeMail && max > 1)
|
2006-09-16 00:23:29 +02:00
|
|
|
{
|
2006-09-19 23:03:12 +02:00
|
|
|
if (workMail && workMail == potential)
|
|
|
|
homeMail = [[elements objectAtIndex: 1] value: 0];
|
2006-09-16 00:23:29 +02:00
|
|
|
else
|
|
|
|
homeMail = potential;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prefMail)
|
|
|
|
{
|
|
|
|
if (prefMail == workMail)
|
|
|
|
preferredEmail = @"work";
|
|
|
|
else if (prefMail == homeMail)
|
|
|
|
preferredEmail = @"home";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self _setSnapshotValue: @"workMail" to: workMail];
|
|
|
|
[self _setSnapshotValue: @"homeMail" to: homeMail];
|
2007-03-22 20:02:45 +01:00
|
|
|
|
|
|
|
[self _setSnapshotValue: @"mozillaUseHtmlMail"
|
|
|
|
to: [[card uniqueChildWithTag: @"x-mozilla-html"] value: 0]];
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setupOrgFields
|
|
|
|
{
|
|
|
|
NSArray *org, *orgServices;
|
|
|
|
NSRange aRange;
|
|
|
|
unsigned int max;
|
|
|
|
|
|
|
|
org = [card org];
|
|
|
|
max = [org count];
|
|
|
|
if (max > 0)
|
|
|
|
{
|
|
|
|
[self _setSnapshotValue: @"workCompany" to: [org objectAtIndex: 0]];
|
|
|
|
if (max > 1)
|
|
|
|
{
|
|
|
|
aRange = NSMakeRange (1, max - 1);
|
|
|
|
orgServices = [org subarrayWithRange: aRange];
|
|
|
|
[self _setSnapshotValue: @"workService"
|
|
|
|
to: [orgServices componentsJoinedByString: @", "]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) preferredEmail
|
|
|
|
{
|
|
|
|
return preferredEmail;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPreferredEmail: (NSString *) aString
|
|
|
|
{
|
|
|
|
preferredEmail = aString;
|
|
|
|
}
|
|
|
|
|
2006-09-19 23:03:12 +02:00
|
|
|
- (void) _retrieveQueryParameter: (NSString *) queryKey
|
|
|
|
intoSnapshotValue: (NSString *) snapshotKey
|
|
|
|
{
|
|
|
|
NSString *queryValue;
|
|
|
|
|
|
|
|
queryValue = [self queryParameterForKey: queryKey];
|
|
|
|
if (queryValue && [queryValue length] > 0)
|
|
|
|
[self _setSnapshotValue: snapshotKey to: queryValue];
|
|
|
|
}
|
|
|
|
|
2006-09-16 00:23:29 +02:00
|
|
|
- (void) initSnapshot
|
|
|
|
{
|
|
|
|
NSArray *n, *elements;
|
|
|
|
CardElement *element;
|
2006-09-26 20:41:05 +02:00
|
|
|
unsigned int max;
|
2006-09-16 00:23:29 +02:00
|
|
|
|
|
|
|
n = [card n];
|
2006-09-26 20:41:05 +02:00
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
max = [n count];
|
|
|
|
if (max > 0)
|
|
|
|
{
|
|
|
|
[self _setSnapshotValue: @"sn" to: [n objectAtIndex: 0]];
|
|
|
|
if (max > 1)
|
|
|
|
[self _setSnapshotValue: @"givenName" to: [n objectAtIndex: 1]];
|
|
|
|
}
|
|
|
|
}
|
2006-09-16 00:23:29 +02:00
|
|
|
[self _setSnapshotValue: @"fn" to: [card fn]];
|
|
|
|
[self _setSnapshotValue: @"nickname" to: [card nickname]];
|
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"tel"];
|
|
|
|
[self _setSnapshotValue: @"telephoneNumber"
|
|
|
|
to: [self _simpleValueForType: @"work" inArray: elements]];
|
|
|
|
[self _setSnapshotValue: @"homeTelephoneNumber"
|
|
|
|
to: [self _simpleValueForType: @"home" inArray: elements]];
|
|
|
|
[self _setSnapshotValue: @"mobile"
|
|
|
|
to: [self _simpleValueForType: @"cell" inArray: elements]];
|
|
|
|
[self _setSnapshotValue: @"facsimileTelephoneNumber"
|
|
|
|
to: [self _simpleValueForType: @"fax" inArray: elements]];
|
|
|
|
[self _setSnapshotValue: @"pager"
|
|
|
|
to: [self _simpleValueForType: @"pager" inArray: elements]];
|
|
|
|
|
|
|
|
[self _setupEmailFields];
|
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
[self _setSnapshotValue: @"screenName"
|
|
|
|
to: [[card uniqueChildWithTag: @"x-aim"] value: 0]];
|
|
|
|
|
2006-09-16 00:23:29 +02:00
|
|
|
elements = [card childrenWithTag: @"adr"
|
|
|
|
andAttribute: @"type" havingValue: @"work"];
|
|
|
|
if (elements && [elements count] > 0)
|
|
|
|
{
|
|
|
|
element = [elements objectAtIndex: 0];
|
|
|
|
[self _setSnapshotValue: @"workStreetAddress"
|
|
|
|
to: [element value: 2]];
|
|
|
|
[self _setSnapshotValue: @"workCity"
|
|
|
|
to: [element value: 3]];
|
|
|
|
[self _setSnapshotValue: @"workState"
|
|
|
|
to: [element value: 4]];
|
|
|
|
[self _setSnapshotValue: @"workPostalCode"
|
|
|
|
to: [element value: 5]];
|
|
|
|
[self _setSnapshotValue: @"workCountry"
|
|
|
|
to: [element value: 6]];
|
|
|
|
}
|
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"adr"
|
|
|
|
andAttribute: @"type" havingValue: @"home"];
|
|
|
|
if (elements && [elements count] > 0)
|
|
|
|
{
|
|
|
|
element = [elements objectAtIndex: 0];
|
|
|
|
[self _setSnapshotValue: @"homeStreetAddress"
|
|
|
|
to: [element value: 2]];
|
|
|
|
[self _setSnapshotValue: @"homeCity"
|
|
|
|
to: [element value: 3]];
|
|
|
|
[self _setSnapshotValue: @"homeState"
|
|
|
|
to: [element value: 4]];
|
|
|
|
[self _setSnapshotValue: @"homePostalCode"
|
|
|
|
to: [element value: 5]];
|
|
|
|
[self _setSnapshotValue: @"homeCountry"
|
|
|
|
to: [element value: 6]];
|
|
|
|
}
|
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"url"];
|
|
|
|
[self _setSnapshotValue: @"workURL"
|
|
|
|
to: [self _simpleValueForType: @"work" inArray: elements]];
|
|
|
|
[self _setSnapshotValue: @"homeURL"
|
|
|
|
to: [self _simpleValueForType: @"home" inArray: elements]];
|
2007-02-02 21:48:56 +01:00
|
|
|
[self _setSnapshotValue: @"calFBURL"
|
|
|
|
to: [[card uniqueChildWithTag: @"FBURL"] value: 0]];
|
2006-09-16 00:23:29 +02:00
|
|
|
|
|
|
|
[self _setSnapshotValue: @"title" to: [card title]];
|
|
|
|
[self _setupOrgFields];
|
|
|
|
|
|
|
|
[self _setSnapshotValue: @"bday" to: [card bday]];
|
|
|
|
[self _setSnapshotValue: @"tz" to: [card tz]];
|
|
|
|
[self _setSnapshotValue: @"note" to: [card note]];
|
2006-09-19 23:03:12 +02:00
|
|
|
|
2007-02-02 21:48:56 +01:00
|
|
|
[self _retrieveQueryParameter: @"contactEmail"
|
|
|
|
intoSnapshotValue: @"workMail"];
|
|
|
|
[self _retrieveQueryParameter: @"contactFN"
|
|
|
|
intoSnapshotValue: @"fn"];
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) defaultAction
|
|
|
|
{
|
|
|
|
card = [[self clientObject] vCard];
|
|
|
|
if (card)
|
|
|
|
[self initSnapshot];
|
|
|
|
else
|
|
|
|
return [NSException exceptionWithHTTPStatus:404 /* Not Found */
|
2007-04-02 23:13:57 +02:00
|
|
|
reason: @"could not open contact"];
|
2006-09-16 00:23:29 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) viewActionName
|
|
|
|
{
|
|
|
|
/* this is overridden in the mail based contacts UI to redirect to tb.edit */
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) editActionName
|
|
|
|
{
|
|
|
|
/* this is overridden in the mail based contacts UI to redirect to tb.edit */
|
2008-03-07 23:09:33 +01:00
|
|
|
return @"editAsContact";
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (CardElement *) _elementWithTag: (NSString *) tag
|
|
|
|
ofType: (NSString *) type
|
|
|
|
{
|
|
|
|
NSArray *elements;
|
|
|
|
CardElement *element;
|
|
|
|
|
|
|
|
elements = [card childrenWithTag: tag
|
|
|
|
andAttribute: @"type" havingValue: type];
|
|
|
|
if ([elements count] > 0)
|
|
|
|
element = [elements objectAtIndex: 0];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
element = [CardElement new];
|
|
|
|
[element autorelease];
|
|
|
|
[element setTag: tag];
|
|
|
|
[element addType: type];
|
|
|
|
[card addChild: element];
|
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _savePhoneValues
|
|
|
|
{
|
|
|
|
CardElement *phone;
|
|
|
|
|
|
|
|
phone = [self _elementWithTag: @"tel" ofType: @"work"];
|
|
|
|
[phone setValue: 0 to: [snapshot objectForKey: @"telephoneNumber"]];
|
|
|
|
phone = [self _elementWithTag: @"tel" ofType: @"home"];
|
|
|
|
[phone setValue: 0 to: [snapshot objectForKey: @"homeTelephoneNumber"]];
|
|
|
|
phone = [self _elementWithTag: @"tel" ofType: @"cell"];
|
|
|
|
[phone setValue: 0 to: [snapshot objectForKey: @"mobile"]];
|
|
|
|
phone = [self _elementWithTag: @"tel" ofType: @"fax"];
|
|
|
|
[phone setValue: 0
|
|
|
|
to: [snapshot objectForKey: @"facsimileTelephoneNumber"]];
|
|
|
|
phone = [self _elementWithTag: @"tel" ofType: @"pager"];
|
|
|
|
[phone setValue: 0
|
|
|
|
to: [snapshot objectForKey: @"pager"]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _saveEmails
|
|
|
|
{
|
|
|
|
CardElement *workMail, *homeMail;
|
|
|
|
|
|
|
|
workMail = [self _elementWithTag: @"email" ofType: @"work"];
|
|
|
|
[workMail setValue: 0 to: [snapshot objectForKey: @"workMail"]];
|
|
|
|
homeMail = [self _elementWithTag: @"email" ofType: @"home"];
|
|
|
|
[homeMail setValue: 0 to: [snapshot objectForKey: @"homeMail"]];
|
|
|
|
if (preferredEmail)
|
|
|
|
{
|
|
|
|
if ([preferredEmail isEqualToString: @"work"])
|
|
|
|
[card setPreferred: workMail];
|
|
|
|
else
|
|
|
|
[card setPreferred: homeMail];
|
|
|
|
}
|
2007-03-22 20:02:45 +01:00
|
|
|
|
|
|
|
[[card uniqueChildWithTag: @"x-mozilla-html"]
|
|
|
|
setValue: 0
|
|
|
|
to: [snapshot objectForKey: @"mozillaUseHtmlMail"]];
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _saveSnapshot
|
|
|
|
{
|
|
|
|
CardElement *element;
|
2007-04-02 22:06:53 +02:00
|
|
|
NSArray *units;
|
2006-09-16 00:23:29 +02:00
|
|
|
|
|
|
|
[card setNWithFamily: [snapshot objectForKey: @"sn"]
|
|
|
|
given: [snapshot objectForKey: @"givenName"]
|
|
|
|
additional: nil
|
|
|
|
prefixes: nil
|
|
|
|
suffixes: nil];
|
|
|
|
[card setNickname: [snapshot objectForKey: @"nickname"]];
|
|
|
|
[card setFn: [snapshot objectForKey: @"fn"]];
|
|
|
|
[card setTitle: [snapshot objectForKey: @"title"]];
|
|
|
|
[card setBday: [snapshot objectForKey: @"bday"]];
|
|
|
|
[card setNote: [snapshot objectForKey: @"note"]];
|
|
|
|
[card setTz: [snapshot objectForKey: @"tz"]];
|
|
|
|
|
|
|
|
element = [self _elementWithTag: @"adr" ofType: @"home"];
|
|
|
|
[element setValue: 2 to: [snapshot objectForKey: @"homeStreetAddress"]];
|
|
|
|
[element setValue: 3 to: [snapshot objectForKey: @"homeCity"]];
|
|
|
|
[element setValue: 4 to: [snapshot objectForKey: @"homeState"]];
|
|
|
|
[element setValue: 5 to: [snapshot objectForKey: @"homePostalCode"]];
|
|
|
|
[element setValue: 6 to: [snapshot objectForKey: @"homeCountry"]];
|
|
|
|
|
|
|
|
element = [self _elementWithTag: @"adr" ofType: @"work"];
|
|
|
|
[element setValue: 2 to: [snapshot objectForKey: @"workStreetAddress"]];
|
|
|
|
[element setValue: 3 to: [snapshot objectForKey: @"workCity"]];
|
|
|
|
[element setValue: 4 to: [snapshot objectForKey: @"workState"]];
|
|
|
|
[element setValue: 5 to: [snapshot objectForKey: @"workPostalCode"]];
|
|
|
|
[element setValue: 6 to: [snapshot objectForKey: @"workCountry"]];
|
|
|
|
|
2007-02-02 21:48:56 +01:00
|
|
|
element = [CardElement simpleElementWithTag: @"fburl"
|
|
|
|
value: [snapshot objectForKey: @"calFBURL"]];
|
|
|
|
[card setUniqueChild: element];
|
|
|
|
|
2007-04-02 22:06:53 +02:00
|
|
|
units = [NSArray arrayWithObject: [snapshot objectForKey: @"workService"]];
|
|
|
|
[card setOrg: [snapshot objectForKey: @"workCompany"]
|
|
|
|
units: units];
|
|
|
|
|
2006-09-16 00:23:29 +02:00
|
|
|
[self _savePhoneValues];
|
|
|
|
[self _saveEmails];
|
2007-04-02 23:13:57 +02:00
|
|
|
[[self _elementWithTag: @"url" ofType: @"home"]
|
|
|
|
setValue: 0 to: [snapshot objectForKey: @"homeURL"]];
|
|
|
|
[[self _elementWithTag: @"url" ofType: @"work"]
|
|
|
|
setValue: 0 to: [snapshot objectForKey: @"workURL"]];
|
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
[[card uniqueChildWithTag: @"x-aim"]
|
2007-04-02 23:13:57 +02:00
|
|
|
setValue: 0
|
|
|
|
to: [snapshot objectForKey: @"screenName"]];
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
2006-10-12 18:42:59 +02:00
|
|
|
- (id <WOActionResults>) saveAction
|
2006-09-16 00:23:29 +02:00
|
|
|
{
|
2008-03-07 23:09:33 +01:00
|
|
|
SOGoContactGCSEntry *contact;
|
2006-09-18 17:28:15 +02:00
|
|
|
id result;
|
2006-10-12 18:42:59 +02:00
|
|
|
NSString *jsRefreshMethod;
|
2006-09-16 00:23:29 +02:00
|
|
|
|
|
|
|
contact = [self clientObject];
|
|
|
|
card = [contact vCard];
|
|
|
|
if (card)
|
|
|
|
{
|
2007-12-21 22:49:05 +01:00
|
|
|
// [self _fixupSnapshot];
|
2006-09-16 00:23:29 +02:00
|
|
|
[self _saveSnapshot];
|
|
|
|
[contact save];
|
2006-09-29 20:12:00 +02:00
|
|
|
|
2006-10-12 18:42:59 +02:00
|
|
|
if ([[[[self context] request] formValueForKey: @"nojs"] intValue])
|
|
|
|
result = [self redirectToLocation: [self applicationPath]];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jsRefreshMethod
|
|
|
|
= [NSString stringWithFormat: @"refreshContacts(\"%@\")",
|
|
|
|
[contact nameInContainer]];
|
|
|
|
result = [self jsCloseWithRefreshMethod: jsRefreshMethod];
|
|
|
|
}
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
2006-09-18 17:28:15 +02:00
|
|
|
else
|
|
|
|
result = [NSException exceptionWithHTTPStatus: 400 /* Bad Request */
|
|
|
|
reason: @"method cannot be invoked on "
|
|
|
|
@"the specified object"];
|
|
|
|
|
|
|
|
return result;
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) writeAction
|
|
|
|
{
|
2007-05-09 21:23:45 +02:00
|
|
|
NSString *email, *cn, *url;
|
|
|
|
NSMutableString *address;
|
2006-09-16 00:23:29 +02:00
|
|
|
|
2006-10-19 19:35:28 +02:00
|
|
|
card = [[self clientObject] vCard];
|
2006-09-16 00:23:29 +02:00
|
|
|
[self initSnapshot];
|
2006-10-19 19:35:28 +02:00
|
|
|
if ([preferredEmail isEqualToString: @"home"])
|
|
|
|
email = [snapshot objectForKey: @"homeMail"];
|
|
|
|
else
|
|
|
|
email = [snapshot objectForKey: @"workMail"];
|
|
|
|
|
2006-09-16 00:23:29 +02:00
|
|
|
if (email)
|
2007-05-09 21:23:45 +02:00
|
|
|
{
|
|
|
|
address = [NSMutableString string];
|
|
|
|
cn = [card fn];
|
|
|
|
if ([cn length] > 0)
|
|
|
|
[address appendFormat: @"%@ <%@>", cn, email];
|
|
|
|
else
|
|
|
|
[address appendString: email];
|
|
|
|
|
2007-11-16 21:48:52 +01:00
|
|
|
url = [NSString stringWithFormat: @"%@/Mail/compose?mailto=%@",
|
|
|
|
[self userFolderPath], address];
|
2007-05-09 21:23:45 +02:00
|
|
|
}
|
2006-09-16 00:23:29 +02:00
|
|
|
else
|
2007-11-16 21:48:52 +01:00
|
|
|
url = [NSString stringWithFormat: @"%@/Mail/compose", [self userFolderPath]];
|
|
|
|
|
|
|
|
return [self redirectToLocation: url];
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
2008-03-07 23:09:33 +01:00
|
|
|
#warning Could this be part of a common parent with UIxAppointment/UIxTaskEditor/UIxListEditor ?
|
2007-04-02 23:13:57 +02:00
|
|
|
- (id) newAction
|
|
|
|
{
|
2008-03-07 23:09:33 +01:00
|
|
|
NSString *objectId, *method, *uri;
|
|
|
|
id <WOActionResults> result;
|
|
|
|
SOGoContactGCSFolder *co;
|
2006-10-27 20:12:13 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
2008-03-07 23:09:33 +01:00
|
|
|
objectId = [co globallyUniqueObjectId];
|
|
|
|
if ([objectId length] > 0)
|
|
|
|
{
|
|
|
|
method = [NSString stringWithFormat:@"%@/%@.vcf/editAsContact",
|
|
|
|
[co soURL], objectId];
|
|
|
|
uri = [self completeHrefForMethod: method];
|
|
|
|
result = [self redirectToLocation: uri];
|
|
|
|
}
|
2006-10-27 20:12:13 +02:00
|
|
|
else
|
2008-03-07 23:09:33 +01:00
|
|
|
result = [NSException exceptionWithHTTPStatus: 500 /* Internal Error */
|
|
|
|
reason: @"could not create a unique ID"];
|
2006-10-27 20:12:13 +02:00
|
|
|
|
2008-03-07 23:09:33 +01:00
|
|
|
return result;
|
2006-09-16 00:23:29 +02:00
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* UIxContactEditor */
|