]> err.no Git - scalable-opengroupware.org/blob - UI/Contacts/UIxContactsListView.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1036 d1b88da0-ebda-0310...
[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 "common.h"
30
31 #import "UIxContactsListView.h"
32
33 @implementation UIxContactsListView
34
35 - (id) init
36 {
37   if ((self = [super init]))
38     {
39       selectorComponentClass = nil;
40     }
41
42   return self;
43 }
44
45 - (void) dealloc
46 {
47   if (searchText)
48     [searchText release];
49   [super dealloc];
50 }
51
52 /* accessors */
53
54 - (void) setCurrentContact: (NSDictionary *) _contact
55 {
56   currentContact = _contact;
57 }
58
59 - (NSDictionary *) currentContact
60 {
61   return currentContact;
62 }
63
64 - (void) setSearchText: (NSString *) _txt
65 {
66   ASSIGNCOPY (searchText, _txt);
67 }
68
69 - (id) searchText
70 {
71   if (!searchText)
72     [self setSearchText: [self queryParameterForKey:@"search"]];
73
74   return searchText;
75 }
76
77 - (id <WOActionResults>) mailerContactsAction
78 {
79   selectorComponentClass = @"UIxContactsMailerSelection";
80
81   return self;
82 }
83
84 - (id <WOActionResults>) deleteAction
85 {
86   id <WOActionResults> result;
87   NSException <WOActionResults> *ex;
88   WOResponse *response;
89
90   ex = [[self clientObject] delete];
91   if (ex)
92     result = ex;
93   else
94     {
95       response = [context response];
96       [response setStatus: 200];
97       result = response;
98     }
99
100   return result;
101 }
102
103 - (NSString *) defaultSortKey
104 {
105   return @"fn";
106 }
107
108 - (NSString *) displayName
109 {
110   NSString *displayName;
111
112   displayName = [currentContact objectForKey: @"displayName"];
113   if (!(displayName && [displayName length] > 0))
114     displayName = [currentContact objectForKey: @"cn"];
115
116   return displayName;
117 }
118
119 - (NSString *) sortKey
120 {
121   NSString *s;
122   
123   s = [self queryParameterForKey: @"sort"];
124   if ([s length] == 0)
125     s = [self defaultSortKey];
126
127   return s;
128 }
129
130 - (NSComparisonResult) sortOrdering
131 {
132   return ([[self queryParameterForKey:@"desc"] boolValue]
133           ? NSOrderedDescending
134           : NSOrderedAscending);
135 }
136
137 - (NSArray *) contactInfos
138 {
139   id <SOGoContactFolder> folder;
140
141   folder = [self clientObject];
142
143   return [folder lookupContactsWithFilter: [self searchText]
144                  sortBy: [self sortKey]
145                  ordering: [self sortOrdering]];
146 }
147
148 /* notifications */
149
150 - (void) sleep
151 {
152   if (searchText)
153     {
154       [searchText release];
155       searchText = nil;
156     }
157   currentContact = nil;
158 //   [allRecords release];
159 //   allRecords = nil;
160 //   [filteredRecords release];
161 //   filteredRecords = nil;
162   [super sleep];
163 }
164
165 /* actions */
166
167 - (BOOL) shouldTakeValuesFromRequest: (WORequest *) _rq
168                            inContext: (WOContext*) _c
169 {
170   return YES;
171 }
172
173 - (WOResponse *) canAccessContentAction
174 {
175   WOResponse *response;
176   NSString *clientClass;
177
178   clientClass = NSStringFromClass([[self clientObject] class]);
179
180   response = [context response];
181   [response setStatus: 200];
182   [response setHeader: @"text/plain; charset=\"ascii\""
183             forKey: @"content-type"];
184   [response
185     appendContentString:
186       ([clientClass isEqualToString: @"SOGoContactLDAPFolder"])
187     ? @"1" : @"0"];
188
189   return response;
190 }
191
192 @end /* UIxContactsListView */