]> err.no Git - scalable-opengroupware.org/blob - UI/Contacts/UIxContactView.m
removed libContactsUI
[scalable-opengroupware.org] / UI / Contacts / UIxContactView.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23
24 #include <SOGoUI/UIxComponent.h>
25
26 @interface UIxContactView : UIxComponent
27 {
28 }
29
30 - (BOOL)isDeletableClientObject;
31
32 @end
33
34 #include <Contacts/SOGoContactObject.h>
35 #include "common.h"
36
37 @implementation UIxContactView
38
39 /* accessors */
40
41 - (NSString *)tabSelection {
42   NSString *selection;
43     
44   selection = [self queryParameterForKey:@"tab"];
45   if (selection == nil)
46     selection = @"attributes";
47   return selection;
48 }
49
50 /* hrefs */
51
52 - (NSString *)completeHrefForMethod:(NSString *)_method
53   withParameter:(NSString *)_param
54   forKey:(NSString *)_key
55 {
56   NSString *href;
57
58   [self setQueryParameter:_param forKey:_key];
59   href = [self completeHrefForMethod:[self ownMethodName]];
60   [self setQueryParameter:nil forKey:_key];
61   return href;
62 }
63
64 - (NSString *)attributesTabLink {
65   return [self completeHrefForMethod:[self ownMethodName]
66                withParameter:@"attributes"
67                forKey:@"tab"];
68 }
69 - (NSString *)debugTabLink {
70   return [self completeHrefForMethod:[self ownMethodName]
71                withParameter:@"debug"
72                forKey:@"tab"];
73 }
74
75 /* action */
76
77 - (id<WOActionResults>)defaultAction {
78   if ([[self clientObject] record] == nil) {
79     return [NSException exceptionWithHTTPStatus:404 /* Not Found */
80                         reason:@"could not locate contact"];
81   }
82   return self;
83 }
84
85 - (BOOL)isDeletableClientObject {
86   return [[self clientObject] respondsToSelector:@selector(delete)];
87 }
88
89 - (id)deleteAction {
90   NSException *ex;
91   id url;
92
93   if (![self isDeletableClientObject]) {
94     /* return 400 == Bad Request */
95     return [NSException exceptionWithHTTPStatus:400
96                         reason:@"method cannot be invoked on "
97                                @"the specified object"];
98   }
99
100   if ((ex = [[self clientObject] delete]) != nil) {
101     // TODO: improve error handling
102     [self debugWithFormat:@"failed to delete: %@", ex];
103     return ex;
104   }
105
106   url = [[[self clientObject] container] baseURLInContext:[self context]];
107   return [self redirectToLocation:url];
108 }
109
110 @end /* UIxContactView */