]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Contacts/UIxContactsListView.m
work on tableview reloading DHTML
[scalable-opengroupware.org] / SOGo / 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 #include "UIxContactsListView.h"
23 #include <Contacts/SOGoContactFolder.h>
24 #include "common.h"
25
26 @implementation UIxContactsListView
27
28 - (void)dealloc {
29   [self->allRecords      release];
30   [self->filteredRecords release];
31   [self->searchText release];
32   [self->contact    release];
33   [super dealloc];
34 }
35
36 /* accessors */
37
38 - (void)setContact:(id)_contact {
39   ASSIGN(self->contact, _contact);
40 }
41 - (id)contact {
42   return self->contact;
43 }
44
45 - (void)setSearchText:(NSString *)_txt {
46   ASSIGNCOPY(self->searchText, _txt);
47 }
48 - (id)searchText {
49   if (self->searchText == nil)
50     [self setSearchText:[[[self context] request] formValueForKey:@"search"]];
51   return self->searchText;
52 }
53
54 - (EOQualifier *)qualifier {
55   NSString *qs, *s;
56   
57   s = [self searchText];
58   if ([s length] == 0)
59     return nil;
60   
61   // TODO: just use qualifier vars
62   qs = [NSString stringWithFormat:
63                    @"(sn isCaseInsensitiveLike: '%@*') OR "
64                    @"(givenname isCaseInsensitiveLike: '%@*') OR "
65                    @"(mail isCaseInsensitiveLike: '*%@*') OR "
66                    @"(telephonenumber isCaseInsensitiveLike: '*%@*')",
67                    s, s, s, s];
68   return [EOQualifier qualifierWithQualifierFormat:qs];
69 }
70
71 - (NSString *)defaultSortKey {
72   return @"sn";
73 }
74 - (NSString *)sortKey {
75   NSString *s;
76   
77   s = [[[self context] request] formValueForKey:@"sort"];
78   return [s length] > 0 ? s : [self defaultSortKey];
79 }
80 - (EOSortOrdering *)sortOrdering {
81   SEL sel;
82
83   sel = [[[[self context] request] formValueForKey:@"desc"] boolValue]
84     ? EOCompareCaseInsensitiveDescending
85     : EOCompareCaseInsensitiveAscending;
86   
87   return [EOSortOrdering sortOrderingWithKey:[self sortKey] selector:sel];
88 }
89 - (NSArray *)sortOrderings {
90   return [NSArray arrayWithObjects:[self sortOrdering], nil];
91 }
92
93 - (NSArray *)contactInfos {
94   // TODO: should be done in the backend, but for Agenor AB its OK here
95   NSArray     *records;
96   EOQualifier *q;
97   
98   if (self->filteredRecords != nil)
99     return self->filteredRecords;
100   
101   records = [[self clientObject] fetchCoreInfos];
102   self->allRecords = 
103     [[records sortedArrayUsingKeyOrderArray:[self sortOrderings]] retain];
104   
105   if ((q = [self qualifier]) != nil) {
106   [self debugWithFormat:@"qs: %@", q];
107     self->filteredRecords = 
108       [[self->allRecords filteredArrayUsingQualifier:q] retain];
109   }
110   else
111     self->filteredRecords = [self->allRecords retain];
112   
113   return self->filteredRecords;
114 }
115
116 /* notifications */
117
118 - (void)sleep {
119   [self->contact         release]; self->contact         = nil;
120   [self->allRecords      release]; self->allRecords      = nil;
121   [self->filteredRecords release]; self->filteredRecords = nil;
122   [super sleep];
123 }
124
125 /* actions */
126
127 - (BOOL)shouldTakeValuesFromRequest:(WORequest *)_rq inContext:(WOContext*)_c{
128   return YES;
129 }
130
131 @end /* UIxContactsListView */