]> err.no Git - scalable-opengroupware.org/blob - UI/Contacts/UIxContactsListView.m
940cbaa55d58c17fa91e31e57f9d246aeda09418
[scalable-opengroupware.org] / UI / Contacts / UIxContactsListView.m
1 /*
2   Copyright (C) 2004-2005 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
22 #import <NGObjWeb/WOContext.h>
23 #import <NGObjWeb/WOResponse.h>
24
25 #import <Contacts/SOGoContactObject.h>
26 #import <Contacts/SOGoContactFolder.h>
27 #import <Contacts/SOGoContactFolders.h>
28
29 #import "UIxContactsListView.h"
30
31 @implementation UIxContactsListView
32
33 - (id) init
34 {
35   if ((self = [super init]))
36     {
37       selectorComponentClass = nil;
38       contactInfos = nil;
39     }
40
41   return self;
42 }
43
44 - (void) dealloc
45 {
46   [contactInfos release];
47   [super dealloc];
48 }
49
50 /* accessors */
51
52 - (void) setCurrentContact: (NSDictionary *) _contact
53 {
54   currentContact = _contact;
55 }
56
57 - (NSDictionary *) currentContact
58 {
59   return currentContact;
60 }
61
62 - (id <WOActionResults>) mailerContactsAction
63 {
64   selectorComponentClass = @"UIxContactsMailerSelection";
65
66   return self;
67 }
68
69 - (NSString *) selectorComponentClass
70 {
71   return selectorComponentClass;
72 }
73
74 - (id <WOActionResults>) deleteAction
75 {
76   id <WOActionResults> result;
77   NSException <WOActionResults> *ex;
78   WOResponse *response;
79
80   ex = [[self clientObject] delete];
81   if (ex)
82     result = ex;
83   else
84     {
85       response = [context response];
86       [response setStatus: 200];
87       result = response;
88     }
89
90   return result;
91 }
92
93 - (NSString *) defaultSortKey
94 {
95   return @"displayName";
96 }
97
98 - (NSString *) sortKey
99 {
100   NSString *s;
101   
102   s = [self queryParameterForKey: @"sort"];
103   if (![s length])
104     s = [self defaultSortKey];
105
106   return s;
107 }
108
109 - (NSArray *) contactInfos
110 {
111   id <SOGoContactFolder> folder;
112   NSString *ascending, *searchText, *valueText;
113   NSComparisonResult ordering;
114
115   if (!contactInfos)
116     {
117       folder = [self clientObject];
118
119       ascending = [self queryParameterForKey: @"asc"];
120       ordering = ((![ascending length] || [ascending boolValue])
121                   ? NSOrderedAscending : NSOrderedDescending);
122
123       searchText = [self queryParameterForKey: @"search"];
124       if ([searchText length] > 0)
125         valueText = [self queryParameterForKey: @"value"];
126       else
127         valueText = nil;
128
129       [contactInfos release];
130       contactInfos = [folder lookupContactsWithFilter: valueText
131                              sortBy: [self sortKey]
132                              ordering: ordering];
133       [contactInfos retain];
134     }
135
136   return contactInfos;
137 }
138
139 /* actions */
140
141 - (BOOL) shouldTakeValuesFromRequest: (WORequest *) _rq
142                            inContext: (WOContext*) _c
143 {
144   return YES;
145 }
146
147 @end /* UIxContactsListView */