]> err.no Git - scalable-opengroupware.org/blob - UI/Common/UIxSortableTableHeader.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1036 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Common / UIxSortableTableHeader.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 <NGObjWeb/SoComponent.h>
23
24 /*
25   UIxSortableTableHeader
26
27   TODO: document.
28
29   Note: needs to inherit from SoComponent so that resource lookup properly
30         works!
31 */
32
33 @interface UIxSortableTableHeader : SoComponent
34 {
35   NSString     *label;
36   NSString     *sortKey;
37   NSString     *href;
38   NSDictionary *queryDictionary;
39   BOOL         isDefault;
40 }
41
42 @end
43
44 #include "common.h"
45
46 @implementation UIxSortableTableHeader
47
48 - (void)dealloc {
49   [self->label           release];
50   [self->sortKey         release];
51   [self->href            release];
52   [self->queryDictionary release];
53   [super dealloc];
54 }
55
56 /* Accessors */
57
58 - (void)setLabel:(NSString *)_label {
59   ASSIGNCOPY(self->label, _label);
60 }
61 - (NSString *)label {
62   return self->label;
63 }
64
65 - (void)setSortKey:(NSString *)_sortKey {
66   ASSIGNCOPY(self->sortKey, _sortKey);
67 }
68
69 - (NSString *)sortKey {
70   return self->sortKey;
71 }
72
73 - (void)setHref:(NSString *)_href {
74   ASSIGNCOPY(self->href, _href);
75 }
76 - (NSString *)href {
77   return self->href;
78 }
79
80 - (void)setQueryDictionary:(NSDictionary *)_queryDictionary {
81   ASSIGN(self->queryDictionary, _queryDictionary);
82 }
83 - (NSDictionary *)queryDictionary {
84   return self->queryDictionary;
85 }
86
87 - (id)singleQueryValueForKey:(NSString *)_key {
88   id so;
89   
90   so = [self->queryDictionary objectForKey:_key];
91   if (![so isNotNull]) return nil;
92   
93   if (![so isKindOfClass:[NSArray class]])
94     return so;
95   
96   return ([so count] > 0) ? [so objectAtIndex:0] : nil;
97 }
98
99 - (void)setIsDefault:(BOOL)_isDefault {
100   self->isDefault = _isDefault;
101 }
102 - (BOOL)isDefault {
103   return self->isDefault;
104 }
105
106 /* derived accessors */
107
108 - (BOOL) isSelected
109 {
110   NSString *so;
111  
112   so = [self singleQueryValueForKey:@"sort"];
113
114   return ((so)
115           ? [so isEqualToString:self->sortKey]
116           : isDefault);
117 }
118
119 - (BOOL)isSortedDescending
120 {
121   NSString *desc;
122
123   desc = [[[self context] request] formValueForKey:@"desc"];
124
125   return ((desc)
126           ? [desc boolValue]
127           : YES);
128 }
129
130 @end /* UIxSortableTableHeader */