2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004 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-04-03 15:41:51 +02:00
|
|
|
// $Id: UIxContactView.m 1040 2007-04-02 21:29:40Z wolfgang $
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-19 16:09:03 +02:00
|
|
|
#import <Contacts/SOGoContactObject.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
#import <NGCards/NGVCard.h>
|
|
|
|
#import <NGCards/CardElement.h>
|
|
|
|
#import <NGCards/NSArray+NGCards.h>
|
2006-09-19 16:09:03 +02:00
|
|
|
#import <NGExtensions/NSString+Ext.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
#import "common.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
#import "UIxContactView.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation UIxContactView
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
|
|
|
- (NSString *)tabSelection {
|
|
|
|
NSString *selection;
|
|
|
|
|
|
|
|
selection = [self queryParameterForKey:@"tab"];
|
|
|
|
if (selection == nil)
|
|
|
|
selection = @"attributes";
|
|
|
|
return selection;
|
|
|
|
}
|
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
- (NSString *) _cardStringWithLabel: (NSString *) label
|
|
|
|
value: (NSString *) value
|
|
|
|
{
|
|
|
|
NSMutableString *cardString;
|
|
|
|
|
|
|
|
cardString = [NSMutableString new];
|
|
|
|
[cardString autorelease];
|
|
|
|
|
|
|
|
if (value && [value length] > 0)
|
|
|
|
{
|
|
|
|
if (label)
|
2007-03-22 20:02:45 +01:00
|
|
|
[cardString appendFormat: @"%@ %@<br />\n",
|
2006-09-13 23:30:37 +02:00
|
|
|
[self labelForKey: label], value];
|
|
|
|
else
|
|
|
|
[cardString appendFormat: @"%@<br />\n", value];
|
|
|
|
}
|
|
|
|
|
|
|
|
return cardString;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) contactCardTitle
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:
|
|
|
|
[self labelForKey: @"Card for %@"],
|
|
|
|
[card fn]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) displayName
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Display Name:"
|
2006-09-13 23:30:37 +02:00
|
|
|
value: [card fn]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) nickName
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Nickname:"
|
2006-09-13 23:30:37 +02:00
|
|
|
value: [card nickname]];
|
|
|
|
}
|
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
- (NSString *) primaryEmail
|
2006-09-13 23:30:37 +02:00
|
|
|
{
|
2006-09-16 00:25:43 +02:00
|
|
|
NSString *email, *mailTo;
|
|
|
|
|
|
|
|
email = [card preferredEMail];
|
2007-03-22 20:02:45 +01:00
|
|
|
if ([email length] > 0)
|
2006-09-16 00:25:43 +02:00
|
|
|
mailTo = [NSString stringWithFormat: @"<a href=\"mailto:%@\""
|
|
|
|
@" onclick=\"return onContactMailTo(this);\">"
|
|
|
|
@"%@</a>", email, email];
|
|
|
|
else
|
|
|
|
mailTo = nil;
|
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Email:"
|
2006-09-16 00:25:43 +02:00
|
|
|
value: mailTo];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
- (NSString *) secondaryEmail
|
|
|
|
{
|
|
|
|
NSString *email, *mailTo;
|
|
|
|
NSMutableArray *emails;
|
|
|
|
|
|
|
|
emails = [NSMutableArray new];
|
|
|
|
[emails addObjectsFromArray: [card childrenWithTag: @"email"]];
|
|
|
|
[emails removeObjectsInArray: [card childrenWithTag: @"email"
|
|
|
|
andAttribute: @"type"
|
|
|
|
havingValue: @"pref"]];
|
|
|
|
|
|
|
|
if ([emails count] > 1)
|
|
|
|
{
|
|
|
|
email = [[emails objectAtIndex: 0] value: 0];
|
|
|
|
mailTo = [NSString stringWithFormat: @"<a href=\"mailto:%@\""
|
|
|
|
@" onclick=\"return onContactMailTo(this);\">"
|
|
|
|
@"%@</a>", email, email];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mailTo = nil;
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: @"Additional Email:"
|
|
|
|
value: mailTo];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) screenName
|
|
|
|
{
|
|
|
|
NSString *screenName, *goim;
|
|
|
|
|
|
|
|
screenName = [[card uniqueChildWithTag: @"x-aim"] value: 0];
|
|
|
|
if ([screenName length] > 0)
|
|
|
|
goim = [NSString stringWithFormat: @"<a href=\"aim:goim?screenname=%@\""
|
|
|
|
@">%@</a>", screenName, screenName];
|
|
|
|
else
|
|
|
|
goim = nil;
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: @"Screen Name:" value: goim];
|
|
|
|
}
|
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
- (NSString *) preferredTel
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Phone Number:"
|
2006-09-13 23:30:37 +02:00
|
|
|
value: [card preferredTel]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) preferredAddress
|
|
|
|
{
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasTelephones
|
|
|
|
{
|
|
|
|
if (!phones)
|
|
|
|
phones = [card childrenWithTag: @"tel"];
|
|
|
|
|
|
|
|
return ([phones count] > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _phoneOfType: (NSString *) aType
|
|
|
|
withLabel: (NSString *) aLabel
|
|
|
|
{
|
|
|
|
NSArray *elements;
|
|
|
|
NSString *phone;
|
|
|
|
|
|
|
|
elements = [phones cardElementsWithAttribute: @"type"
|
|
|
|
havingValue: aType];
|
|
|
|
|
|
|
|
if ([elements count] > 0)
|
|
|
|
phone = [[elements objectAtIndex: 0] value: 0];
|
|
|
|
else
|
|
|
|
phone = nil;
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: aLabel value: phone];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workPhone
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _phoneOfType: @"work" withLabel: @"Work:"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homePhone
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _phoneOfType: @"home" withLabel: @"Home:"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) fax
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _phoneOfType: @"fax" withLabel: @"Fax:"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) mobile
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _phoneOfType: @"cell" withLabel: @"Mobile:"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) pager
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _phoneOfType: @"pager" withLabel: @"Pager:"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasHomeInfos
|
|
|
|
{
|
|
|
|
BOOL result;
|
|
|
|
NSArray *elements;
|
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"adr"
|
|
|
|
andAttribute: @"type"
|
|
|
|
havingValue: @"home"];
|
|
|
|
if ([elements count] > 0)
|
|
|
|
{
|
|
|
|
result = YES;
|
|
|
|
homeAdr = [elements objectAtIndex: 0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = ([[card childrenWithTag: @"url"
|
|
|
|
andAttribute: @"type"
|
|
|
|
havingValue: @"home"] count] > 0);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homePobox
|
|
|
|
{
|
|
|
|
return [self _cardStringWithLabel: nil value: [homeAdr value: 0]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homeExtendedAddress
|
|
|
|
{
|
|
|
|
return [self _cardStringWithLabel: nil value: [homeAdr value: 1]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homeStreetAddress
|
|
|
|
{
|
|
|
|
return [self _cardStringWithLabel: nil value: [homeAdr value: 2]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homeCityAndProv
|
|
|
|
{
|
|
|
|
NSString *city, *prov;
|
|
|
|
NSMutableString *data;
|
|
|
|
|
|
|
|
city = [homeAdr value: 3];
|
|
|
|
prov = [homeAdr value: 4];
|
|
|
|
|
|
|
|
data = [NSMutableString new];
|
|
|
|
[data autorelease];
|
|
|
|
[data appendString: city];
|
|
|
|
if ([city length] > 0 && [prov length] > 0)
|
|
|
|
[data appendString: @", "];
|
|
|
|
[data appendString: prov];
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: data];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) homePostalCodeAndCountry
|
|
|
|
{
|
|
|
|
NSString *postalCode, *country;
|
|
|
|
NSMutableString *data;
|
|
|
|
|
|
|
|
postalCode = [homeAdr value: 5];
|
|
|
|
country = [homeAdr value: 6];
|
|
|
|
|
|
|
|
data = [NSMutableString new];
|
|
|
|
[data autorelease];
|
|
|
|
[data appendString: postalCode];
|
|
|
|
if ([postalCode length] > 0 && [country length] > 0)
|
|
|
|
[data appendFormat: @", ", country];
|
|
|
|
[data appendString: country];
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: data];
|
|
|
|
}
|
|
|
|
|
2006-09-16 00:25:43 +02:00
|
|
|
- (NSString *) _urlOfType: (NSString *) aType
|
2006-09-13 23:30:37 +02:00
|
|
|
{
|
|
|
|
NSArray *elements;
|
2006-09-16 00:25:43 +02:00
|
|
|
NSString *data, *url;
|
2006-09-13 23:30:37 +02:00
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"url"
|
|
|
|
andAttribute: @"type"
|
2006-09-16 00:25:43 +02:00
|
|
|
havingValue: aType];
|
2006-09-13 23:30:37 +02:00
|
|
|
if ([elements count] > 0)
|
2006-09-16 00:25:43 +02:00
|
|
|
{
|
|
|
|
url = [[elements objectAtIndex: 0] value: 0];
|
|
|
|
data = [NSString stringWithFormat:
|
2006-09-19 23:05:32 +02:00
|
|
|
@"<a href=\"%@\">%@</a>",
|
2006-09-16 00:25:43 +02:00
|
|
|
url, url];
|
|
|
|
}
|
2006-09-13 23:30:37 +02:00
|
|
|
else
|
|
|
|
data = nil;
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: data];
|
|
|
|
}
|
|
|
|
|
2006-09-16 00:25:43 +02:00
|
|
|
- (NSString *) homeUrl
|
|
|
|
{
|
|
|
|
return [self _urlOfType: @"home"];
|
|
|
|
}
|
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
- (BOOL) hasWorkInfos
|
|
|
|
{
|
|
|
|
BOOL result;
|
|
|
|
NSArray *elements;
|
|
|
|
|
|
|
|
elements = [card childrenWithTag: @"adr"
|
|
|
|
andAttribute: @"type"
|
|
|
|
havingValue: @"work"];
|
|
|
|
if ([elements count] > 0)
|
|
|
|
{
|
|
|
|
result = YES;
|
|
|
|
workAdr = [elements objectAtIndex: 0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = (([[card childrenWithTag: @"url"
|
|
|
|
andAttribute: @"type"
|
|
|
|
havingValue: @"work"] count] > 0)
|
|
|
|
|| [[card childrenWithTag: @"org"] count] > 0);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workTitle
|
|
|
|
{
|
|
|
|
return [self _cardStringWithLabel: nil value: [card title]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workService
|
|
|
|
{
|
|
|
|
NSArray *org, *orgServices;
|
|
|
|
NSRange aRange;
|
|
|
|
NSString *services;
|
|
|
|
|
|
|
|
org = [card org];
|
|
|
|
if (org && [org count] > 1)
|
|
|
|
{
|
2006-09-16 00:25:43 +02:00
|
|
|
aRange = NSMakeRange (1, [org count] - 1);
|
2006-09-13 23:30:37 +02:00
|
|
|
orgServices = [org subarrayWithRange: aRange];
|
|
|
|
services = [orgServices componentsJoinedByString: @", "];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
services = nil;
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: services];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workCompany
|
|
|
|
{
|
|
|
|
NSArray *org;
|
|
|
|
NSString *company;
|
|
|
|
|
|
|
|
org = [card org];
|
|
|
|
if (org && [org count] > 0)
|
|
|
|
company = [org objectAtIndex: 0];
|
2006-09-19 16:50:11 +02:00
|
|
|
else
|
|
|
|
company = nil;
|
2006-09-13 23:30:37 +02:00
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: company];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workPobox
|
|
|
|
{
|
|
|
|
return [self _cardStringWithLabel: nil value: [workAdr value: 0]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workExtendedAddress
|
|
|
|
{
|
|
|
|
return [self _cardStringWithLabel: nil value: [workAdr value: 1]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workStreetAddress
|
|
|
|
{
|
|
|
|
return [self _cardStringWithLabel: nil value: [workAdr value: 2]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workCityAndProv
|
|
|
|
{
|
|
|
|
NSString *city, *prov;
|
|
|
|
NSMutableString *data;
|
|
|
|
|
|
|
|
city = [workAdr value: 3];
|
|
|
|
prov = [workAdr value: 4];
|
|
|
|
|
|
|
|
data = [NSMutableString new];
|
|
|
|
[data autorelease];
|
|
|
|
[data appendString: city];
|
|
|
|
if ([city length] > 0 && [prov length] > 0)
|
|
|
|
[data appendString: @", "];
|
|
|
|
[data appendString: prov];
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: data];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workPostalCodeAndCountry
|
|
|
|
{
|
|
|
|
NSString *postalCode, *country;
|
|
|
|
NSMutableString *data;
|
|
|
|
|
|
|
|
postalCode = [workAdr value: 5];
|
|
|
|
country = [workAdr value: 6];
|
|
|
|
|
|
|
|
data = [NSMutableString new];
|
|
|
|
[data autorelease];
|
|
|
|
[data appendString: postalCode];
|
|
|
|
if ([postalCode length] > 0 && [country length] > 0)
|
|
|
|
[data appendFormat: @", ", country];
|
|
|
|
[data appendString: country];
|
|
|
|
|
|
|
|
return [self _cardStringWithLabel: nil value: data];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) workUrl
|
|
|
|
{
|
2007-04-02 23:14:53 +02:00
|
|
|
return [self _urlOfType: @"work"];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasOtherInfos
|
|
|
|
{
|
2006-09-18 17:29:06 +02:00
|
|
|
return ([[card note] length] > 0
|
|
|
|
|| [[card bday] length] > 0
|
|
|
|
|| [[card tz] length] > 0);
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) bday
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Birthday:" value: [card bday]];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) tz
|
|
|
|
{
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Timezone:" value: [card tz]];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) note
|
|
|
|
{
|
2006-09-19 16:09:03 +02:00
|
|
|
NSString *note;
|
|
|
|
|
|
|
|
note = [card note];
|
|
|
|
if (note)
|
|
|
|
{
|
|
|
|
note = [note stringByReplacingString: @"\r\n"
|
|
|
|
withString: @"<br />"];
|
|
|
|
note = [note stringByReplacingString: @"\n"
|
|
|
|
withString: @"<br />"];
|
|
|
|
}
|
|
|
|
|
2007-03-22 20:02:45 +01:00
|
|
|
return [self _cardStringWithLabel: @"Note:" value: note];
|
2006-09-13 23:30:37 +02:00
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* hrefs */
|
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
- (NSString *) completeHrefForMethod: (NSString *) _method
|
|
|
|
withParameter: (NSString *) _param
|
|
|
|
forKey: (NSString *) _key
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
|
|
|
NSString *href;
|
|
|
|
|
|
|
|
[self setQueryParameter:_param forKey:_key];
|
|
|
|
href = [self completeHrefForMethod:[self ownMethodName]];
|
|
|
|
[self setQueryParameter:nil forKey:_key];
|
2006-09-19 16:50:11 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return href;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)attributesTabLink {
|
|
|
|
return [self completeHrefForMethod:[self ownMethodName]
|
|
|
|
withParameter:@"attributes"
|
|
|
|
forKey:@"tab"];
|
|
|
|
}
|
|
|
|
- (NSString *)debugTabLink {
|
|
|
|
return [self completeHrefForMethod:[self ownMethodName]
|
|
|
|
withParameter:@"debug"
|
|
|
|
forKey:@"tab"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* action */
|
|
|
|
|
2006-09-13 23:30:37 +02:00
|
|
|
- (id <WOActionResults>) vcardAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
card = [[self clientObject] vCard];
|
2006-09-16 00:25:43 +02:00
|
|
|
if (card)
|
2006-09-13 23:30:37 +02:00
|
|
|
{
|
|
|
|
response = [WOResponse new];
|
|
|
|
[response autorelease];
|
|
|
|
[response setHeader: @"text/vcard" forKey: @"Content-type"];
|
|
|
|
[response appendContentString: [card versitString]];
|
|
|
|
}
|
2006-09-16 00:25:43 +02:00
|
|
|
else
|
|
|
|
return [NSException exceptionWithHTTPStatus: 404 /* Not Found */
|
|
|
|
reason:@"could not locate contact"];
|
2006-09-13 23:30:37 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) defaultAction
|
|
|
|
{
|
|
|
|
card = [[self clientObject] vCard];
|
2006-09-16 00:25:43 +02:00
|
|
|
if (card)
|
|
|
|
{
|
|
|
|
phones = nil;
|
|
|
|
homeAdr = nil;
|
|
|
|
workAdr = nil;
|
|
|
|
}
|
|
|
|
else
|
2006-09-19 16:50:11 +02:00
|
|
|
return [NSException exceptionWithHTTPStatus: 404 /* Not Found */
|
|
|
|
reason: @"could not locate contact"];
|
2006-09-13 23:30:37 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-08-09 23:37:35 +02:00
|
|
|
- (BOOL) isDeletableClientObject
|
|
|
|
{
|
|
|
|
return [[self clientObject] respondsToSelector: @selector(delete)];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-08-09 23:37:35 +02:00
|
|
|
- (id) deleteAction
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSException *ex;
|
|
|
|
id url;
|
|
|
|
|
2006-09-19 16:50:11 +02:00
|
|
|
if (![self isDeletableClientObject])
|
2006-06-15 21:34:10 +02:00
|
|
|
/* return 400 == Bad Request */
|
|
|
|
return [NSException exceptionWithHTTPStatus:400
|
|
|
|
reason:@"method cannot be invoked on "
|
2006-09-19 16:50:11 +02:00
|
|
|
@"the specified object"];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-19 16:50:11 +02:00
|
|
|
ex = [[self clientObject] delete];
|
|
|
|
if (ex)
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
// TODO: improve error handling
|
2006-09-19 16:50:11 +02:00
|
|
|
[self debugWithFormat:@"failed to delete: %@", ex];
|
|
|
|
|
|
|
|
return ex;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
url = [[[self clientObject] container] baseURLInContext:[self context]];
|
2006-09-19 16:50:11 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self redirectToLocation:url];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end /* UIxContactView */
|