mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-05 08:34:30 +00:00
Move setAttributes from NGVCard to UIx*Editors
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
/*
|
||||
Copyright (C) 2004-2005 SKYRIX Software AG
|
||||
Copyright (C) 2006-2014 Inverse inc.
|
||||
|
||||
This file is part of OpenGroupware.org.
|
||||
This file is part of SOGo
|
||||
|
||||
OGo is free software; you can redistribute it and/or modify it under
|
||||
SOGo 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
|
||||
SOGo 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
|
||||
License along with SOGo; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
02111-1307, USA.
|
||||
*/
|
||||
@@ -32,6 +33,7 @@
|
||||
@interface UIxContactEditor : UIxComponent
|
||||
{
|
||||
id addressBookItem;
|
||||
NGVCard *card;
|
||||
NSString *item;
|
||||
NSMutableDictionary *ldifRecord; /* contains the values for editing */
|
||||
id <SOGoContactFolder> componentAddressBook;
|
||||
|
||||
+151
-13
@@ -15,7 +15,7 @@
|
||||
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
|
||||
License along with SOGo; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
02111-1307, USA.
|
||||
*/
|
||||
@@ -42,6 +42,7 @@
|
||||
#import <SOGo/SOGoUser.h>
|
||||
#import <SOGo/SOGoUserDefaults.h>
|
||||
|
||||
#import <Contacts/NGVCard+SOGo.h>
|
||||
#import <Contacts/SOGoContactFolder.h>
|
||||
#import <Contacts/SOGoContactFolders.h>
|
||||
#import <Contacts/SOGoContactObject.h>
|
||||
@@ -113,12 +114,6 @@ static Class SOGoContactGCSEntryK = Nil;
|
||||
return addressBookItem;
|
||||
}
|
||||
|
||||
- (NSString *) saveURL
|
||||
{
|
||||
return [NSString stringWithFormat: @"%@/saveAsContact",
|
||||
[[self clientObject] baseURL]];
|
||||
}
|
||||
|
||||
- (NSArray *) htmlMailFormatList
|
||||
{
|
||||
static NSArray *htmlMailFormatItems = nil;
|
||||
@@ -346,24 +341,167 @@ static Class SOGoContactGCSEntryK = Nil;
|
||||
return [NSString stringWithFormat: @"%@/photo", [soURL absoluteString]];
|
||||
}
|
||||
|
||||
- (void) setAttributes: (NSDictionary *) attributes
|
||||
{
|
||||
CardElement *element;
|
||||
NSArray *elements, *values;
|
||||
NSMutableArray *units, *categories;
|
||||
id o;
|
||||
unsigned int i;
|
||||
|
||||
[card setNWithFamily: [attributes objectForKey: @"sn"]
|
||||
given: [attributes objectForKey: @"givenname"]
|
||||
additional: nil prefixes: nil suffixes: nil];
|
||||
[card setNickname: [attributes objectForKey: @"nickname"]];
|
||||
[card setFn: [attributes objectForKey: @"fn"]];
|
||||
[card setTitle: [attributes objectForKey: @"title"]];
|
||||
[card setBday: [attributes objectForKey: @"birthday"]];
|
||||
|
||||
if ([[attributes objectForKey: @"addresses"] isKindOfClass: [NSArray class]])
|
||||
{
|
||||
elements = [card childrenWithTag: @"adr"];
|
||||
[card removeChildren: elements];
|
||||
values = [attributes objectForKey: @"addresses"];
|
||||
for (i = 0; i < [values count]; i++)
|
||||
{
|
||||
o = [values objectAtIndex: i];
|
||||
if ([o isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
element = [card elementWithTag: @"adr" ofType: [o objectForKey: @"type"]];
|
||||
[element setSingleValue: [o objectForKey: @"postoffice"]
|
||||
atIndex: 0 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"street2"]
|
||||
atIndex: 1 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"street"]
|
||||
atIndex: 2 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"locality"]
|
||||
atIndex: 3 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"region"]
|
||||
atIndex: 4 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"postalcode"]
|
||||
atIndex: 5 forKey: @""];
|
||||
[element setSingleValue: [o objectForKey: @"country"]
|
||||
atIndex: 6 forKey: @""];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([[attributes objectForKey: @"orgUnits"] isKindOfClass: [NSArray class]])
|
||||
{
|
||||
elements = [card childrenWithTag: @"org"];
|
||||
[card removeChildren: elements];
|
||||
values = [attributes objectForKey: @"orgUnits"];
|
||||
units = [NSMutableArray arrayWithCapacity: [values count]];
|
||||
for (i = 0; i < [values count]; i++)
|
||||
{
|
||||
o = [values objectAtIndex: i];
|
||||
if ([o isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
[units addObject: [o objectForKey: @"value"]];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
units = nil;
|
||||
}
|
||||
[card setOrg: [attributes objectForKey: @"org"]
|
||||
units: units];
|
||||
|
||||
elements = [card childrenWithTag: @"tel"];
|
||||
[card removeChildren: elements];
|
||||
values = [attributes objectForKey: @"phones"];
|
||||
if ([values isKindOfClass: [NSArray class]])
|
||||
{
|
||||
NSEnumerator *list = [values objectEnumerator];
|
||||
id attrs;
|
||||
while ((attrs = [list nextObject]))
|
||||
{
|
||||
if ([attrs isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
element = [card elementWithTag: @"tel" ofType: [attrs objectForKey: @"type"]];
|
||||
[element setSingleValue: [attrs objectForKey: @"value"] forKey: @""];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([[attributes objectForKey: @"emails"] isKindOfClass: [NSArray class]])
|
||||
{
|
||||
elements = [card childrenWithTag: @"email"];
|
||||
[card removeChildren: elements];
|
||||
values = [attributes objectForKey: @"emails"];
|
||||
if (values)
|
||||
{
|
||||
NSEnumerator *list = [values objectEnumerator];
|
||||
while ((o = [list nextObject]))
|
||||
{
|
||||
if ([o isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
element = [card elementWithTag: @"email" ofType: [o objectForKey: @"type"]];
|
||||
[element setSingleValue: [o objectForKey: @"value"] forKey: @""];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
elements = [card childrenWithTag: @"url"];
|
||||
[card removeChildren: elements];
|
||||
values = [attributes objectForKey: @"urls"];
|
||||
if ([values isKindOfClass: [NSArray class]])
|
||||
{
|
||||
NSEnumerator *list = [values objectEnumerator];
|
||||
id attrs;
|
||||
while ((attrs = [list nextObject]))
|
||||
{
|
||||
if ([attrs isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
element = [card elementWithTag: @"url" ofType: [attrs objectForKey: @"type"]];
|
||||
[element setSingleValue: [attrs objectForKey: @"value"] forKey: @""];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[card setNote: [attributes objectForKey: @"note"]];
|
||||
|
||||
if ([[attributes objectForKey: @"categories"] isKindOfClass: [NSArray class]])
|
||||
{
|
||||
elements = [card childrenWithTag: @"categories"];
|
||||
[card removeChildren: elements];
|
||||
values = [attributes objectForKey: @"categories"];
|
||||
categories = [NSMutableArray arrayWithCapacity: [values count]];
|
||||
for (i = 0; i < [values count]; i++)
|
||||
{
|
||||
o = [values objectAtIndex: i];
|
||||
if ([o isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
[categories addObject: [o objectForKey: @"value"]];
|
||||
}
|
||||
}
|
||||
[card setCategories: categories];
|
||||
}
|
||||
|
||||
[card cleanupEmptyChildren];
|
||||
}
|
||||
|
||||
- (id <WOActionResults>) saveAction
|
||||
{
|
||||
SOGoContentObject <SOGoContactObject> *contact;
|
||||
SOGoContentObject <SOGoContactObject> *co;
|
||||
WORequest *request;
|
||||
WOResponse *response;
|
||||
NSDictionary *params, *data;
|
||||
|
||||
contact = [self clientObject];
|
||||
co = [self clientObject];
|
||||
card = [co vCard];
|
||||
request = [context request];
|
||||
params = [[request contentAsString] objectFromJSONString];
|
||||
[contact setAttributes: params];
|
||||
|
||||
[contact save];
|
||||
[self setAttributes: params];
|
||||
[co save];
|
||||
|
||||
// Return card UID and addressbook ID in a JSON payload
|
||||
data = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[[contact container] nameInContainer], @"pid",
|
||||
[contact nameInContainer], @"id",
|
||||
[[co container] nameInContainer], @"pid",
|
||||
[co nameInContainer], @"id",
|
||||
nil];
|
||||
response = [self responseWithStatus: 200
|
||||
andString: [data jsonRepresentation]];
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
{
|
||||
NGVList *list;
|
||||
SOGoContactGCSList *co;
|
||||
id reference;
|
||||
}
|
||||
|
||||
- (BOOL) cardReferences: (NSArray *) references contain: (NSString *) ref;
|
||||
|
||||
+137
-108
@@ -29,6 +29,7 @@
|
||||
#import <NGCards/NGVCardReference.h>
|
||||
#import <NGCards/NGVList.h>
|
||||
|
||||
#import <SOGo/NSDictionary+Utilities.h>
|
||||
#import <SOGo/NSString+Utilities.h>
|
||||
|
||||
#import <Contacts/SOGoContactGCSEntry.h>
|
||||
@@ -54,36 +55,6 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *) listName
|
||||
{
|
||||
return [list fn];
|
||||
}
|
||||
|
||||
- (void) setListName: (NSString *) newName
|
||||
{
|
||||
[list setFn: newName];
|
||||
}
|
||||
|
||||
- (NSString *) nickname
|
||||
{
|
||||
return [list nickname];
|
||||
}
|
||||
|
||||
- (void) setNickname: (NSString *) newName
|
||||
{
|
||||
[list setNickname: newName];
|
||||
}
|
||||
|
||||
- (NSString *) description
|
||||
{
|
||||
return [list description];
|
||||
}
|
||||
|
||||
- (void) setDescription: (NSString *) newDescription
|
||||
{
|
||||
[list setDescription: newDescription];
|
||||
}
|
||||
|
||||
- (NSArray *) references
|
||||
{
|
||||
NSArray *references;
|
||||
@@ -123,7 +94,7 @@
|
||||
int i, count;
|
||||
NGVCardReference *cardReference;
|
||||
SOGoContactGCSFolder *folder;
|
||||
|
||||
|
||||
references = [value componentsSeparatedByString: @","];
|
||||
if ([references count])
|
||||
{
|
||||
@@ -142,11 +113,11 @@
|
||||
|
||||
// Add new cards
|
||||
count = [references count];
|
||||
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
currentReference = [references objectAtIndex: i];
|
||||
if (![self cardReferences: [list cardReferences]
|
||||
if (![self cardReferences: [list cardReferences]
|
||||
contain: currentReference])
|
||||
{
|
||||
// Search contact by vCard UID
|
||||
@@ -157,7 +128,7 @@
|
||||
[cardReference setFn: [values objectForKey: @"c_cn"]];
|
||||
[cardReference setEmail: [values objectForKey: @"c_mail"]];
|
||||
[cardReference setReference: currentReference];
|
||||
|
||||
|
||||
[list addCardReference: cardReference];
|
||||
}
|
||||
else
|
||||
@@ -168,7 +139,7 @@
|
||||
NGVCard *newCard;
|
||||
CardElement *newWorkMail;
|
||||
SOGoContactGCSEntry *newContact;
|
||||
|
||||
|
||||
contactInfo = [currentReference componentsSeparatedByString: @"|"];
|
||||
if ([contactInfo count] > 1)
|
||||
{
|
||||
@@ -196,38 +167,131 @@
|
||||
[cardReference setFn: fn];
|
||||
[cardReference setEmail: workMail];
|
||||
[cardReference setReference: newUID];
|
||||
|
||||
|
||||
[list addCardReference: cardReference];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setReferences: (NSArray *) references
|
||||
{
|
||||
NSDictionary *values;
|
||||
NSArray *initialReferences;
|
||||
NSDictionary *currentReference;
|
||||
NSString *uid, *workMail, *fn, *newUID;
|
||||
int i, count;
|
||||
NGVCardReference *cardReference;
|
||||
SOGoContactGCSFolder *folder;
|
||||
|
||||
folder = [co container];
|
||||
|
||||
// Remove from the list the cards that were deleted
|
||||
initialReferences = [list cardReferences];
|
||||
count = [initialReferences count];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
cardReference = [initialReferences objectAtIndex: i];
|
||||
if (![references containsObject: [cardReference reference]])
|
||||
[list deleteCardReference: cardReference];
|
||||
}
|
||||
|
||||
// TODO: update existing cards?
|
||||
|
||||
// Add new cards
|
||||
count = [references count];
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if ([[references objectAtIndex: i] isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
currentReference = [references objectAtIndex: i];
|
||||
uid = [currentReference objectForKey: @"reference"];
|
||||
if (![self cardReferences: [list cardReferences]
|
||||
contain: uid])
|
||||
{
|
||||
// Search contact by vCard UID
|
||||
values = [folder lookupContactWithName: uid];
|
||||
if (values)
|
||||
{
|
||||
cardReference = [NGVCardReference elementWithTag: @"card"];
|
||||
[cardReference setFn: [values objectForKey: @"c_cn"]];
|
||||
[cardReference setEmail: [values objectForKey: @"c_mail"]];
|
||||
[cardReference setReference: uid];
|
||||
|
||||
[list addCardReference: cardReference];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid UID or no UID
|
||||
NGVCard *newCard;
|
||||
CardElement *newWorkMail;
|
||||
SOGoContactGCSEntry *newContact;
|
||||
|
||||
workMail = [currentReference objectForKey: @"email"];
|
||||
fn = [currentReference objectForKey: @"fn"];
|
||||
|
||||
// Create a new vCard
|
||||
newUID = [NSString stringWithFormat: @"%@.vcf", [co globallyUniqueObjectId]];
|
||||
newCard = [NGVCard cardWithUid: newUID];
|
||||
newWorkMail = [CardElement new];
|
||||
[newWorkMail autorelease];
|
||||
[newWorkMail setTag: @"email"];
|
||||
[newWorkMail addType: @"work"];
|
||||
[newCard addChild: newWorkMail];
|
||||
[newWorkMail setSingleValue: workMail forKey: @""];
|
||||
[newCard setFn: fn];
|
||||
|
||||
// Add vCard to current folder
|
||||
newContact = [SOGoContactGCSEntry objectWithName: newUID
|
||||
inContainer: folder];
|
||||
[newContact saveContentString: [newCard versitString]];
|
||||
|
||||
// Create card reference for the list
|
||||
cardReference = [NGVCardReference elementWithTag: @"card"];
|
||||
[cardReference setFn: fn];
|
||||
[cardReference setEmail: workMail];
|
||||
[cardReference setReference: newUID];
|
||||
|
||||
[list addCardReference: cardReference];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) cardReferences: (NSArray *) references
|
||||
contain: (NSString *) ref
|
||||
contain: (NSString *) reference
|
||||
{
|
||||
int i, count;
|
||||
BOOL rc = NO;
|
||||
|
||||
count = [references count];
|
||||
for (i = 0; i < count; i++)
|
||||
if (reference)
|
||||
{
|
||||
if ([ref isEqualToString: [[references objectAtIndex: i] reference]])
|
||||
count = [references count];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
rc = YES;
|
||||
break;
|
||||
if ([reference isEqualToString: [[references objectAtIndex: i] reference]])
|
||||
{
|
||||
rc = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
- (NSString *) saveURL
|
||||
/**
|
||||
*
|
||||
*/
|
||||
- (void) setAttributes: (NSDictionary *) attributes
|
||||
{
|
||||
return [NSString stringWithFormat: @"%@/saveAsList",
|
||||
[co baseURLInContext: context]];
|
||||
[list setNickname: [attributes objectForKey: @"nickname"]];
|
||||
[list setFn: [attributes objectForKey: @"fn"]];
|
||||
[list setDescription: [attributes objectForKey: @"description"]];
|
||||
}
|
||||
|
||||
- (BOOL) canCreateOrModify
|
||||
@@ -236,71 +300,36 @@
|
||||
&& [super canCreateOrModify]);
|
||||
}
|
||||
|
||||
- (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
|
||||
inContext: (WOContext*) context
|
||||
{
|
||||
NSString *actionName;
|
||||
BOOL rc;
|
||||
|
||||
co = [self clientObject];
|
||||
actionName = [[request requestHandlerPath] lastPathComponent];
|
||||
if ([co isKindOfClass: [SOGoContactGCSList class]]
|
||||
&& [actionName hasPrefix: @"save"])
|
||||
{
|
||||
list = [co vList];
|
||||
[list retain];
|
||||
rc = YES;
|
||||
}
|
||||
else
|
||||
rc = NO;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#warning Could this be part of a common parent with UIxAppointment/UIxTaskEditor/UIxListEditor ?
|
||||
- (id) newAction
|
||||
{
|
||||
NSString *objectId, *method, *uri;
|
||||
id <WOActionResults> result;
|
||||
|
||||
co = [self clientObject];
|
||||
objectId = [co globallyUniqueObjectId];
|
||||
if ([objectId length] > 0)
|
||||
{
|
||||
method = [NSString stringWithFormat:@"%@/%@.vlf/editAsList",
|
||||
[co soURL], objectId];
|
||||
uri = [self completeHrefForMethod: method];
|
||||
result = [self redirectToLocation: uri];
|
||||
}
|
||||
else
|
||||
result = [NSException exceptionWithHTTPStatus: 500 /* Internal Error */
|
||||
reason: @"could not create a unique ID"];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (id <WOActionResults>) saveAction
|
||||
{
|
||||
id result;
|
||||
NSString *jsRefreshMethod;
|
||||
WORequest *request;
|
||||
WOResponse *response;
|
||||
NSDictionary *params, *data;
|
||||
id o;
|
||||
|
||||
if (co)
|
||||
{
|
||||
[co save];
|
||||
if ([[[[self context] request] formValueForKey: @"nojs"] intValue])
|
||||
result = [self redirectToLocation: [self modulePath]];
|
||||
else
|
||||
{
|
||||
jsRefreshMethod = [NSString stringWithFormat: @"refreshContacts('%@')",
|
||||
[co nameInContainer]];
|
||||
result = [self jsCloseWithRefreshMethod: jsRefreshMethod];
|
||||
}
|
||||
}
|
||||
else
|
||||
result = [NSException exceptionWithHTTPStatus: 400 /* Bad Request */
|
||||
reason: @"method cannot be invoked on "
|
||||
@"the specified object"];
|
||||
return result;
|
||||
co = [self clientObject];
|
||||
list = [co vList];
|
||||
[list retain];
|
||||
|
||||
request = [context request];
|
||||
params = [[request contentAsString] objectFromJSONString];
|
||||
|
||||
o = [params objectForKey: @"refs"];
|
||||
if (![o isKindOfClass: [NSArray class]])
|
||||
o = nil;
|
||||
[self setReferences: (NSArray *) o];
|
||||
[self setAttributes: params];
|
||||
[co save];
|
||||
|
||||
// Return list UID and addressbook ID in a JSON payload
|
||||
data = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[[co container] nameInContainer], @"pid",
|
||||
[co nameInContainer], @"id",
|
||||
nil];
|
||||
response = [self responseWithStatus: 200
|
||||
andString: [data jsonRepresentation]];
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user