2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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
11 SOPE 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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "WOHTMLDynamicElement.h"
23 #include "WOElement+private.h"
26 @interface WONestedList : WOHTMLDynamicElement
28 // WODynamicElement: extraAttributes
29 // WODynamicElement: otherTagString
34 WOAssociation *sublist;
35 WOAssociation *action;
36 WOAssociation *selection;
39 WOAssociation *isOrdered;
40 WOAssociation *prefix;
41 WOAssociation *suffix;
44 @end /* WONestedList */
46 @implementation WONestedList
48 - (id)initWithName:(NSString *)_name
49 associations:(NSDictionary *)_config
50 template:(WOElement *)_root
52 if ((self = [super initWithName:_name associations:_config template:_root])) {
53 self->action = OWGetProperty(_config, @"action");
54 self->list = OWGetProperty(_config, @"list");
55 self->item = OWGetProperty(_config, @"item");
56 self->index = OWGetProperty(_config, @"index");
57 self->selection = OWGetProperty(_config, @"selection");
58 self->prefix = OWGetProperty(_config, @"prefix");
59 self->suffix = OWGetProperty(_config, @"suffix");
60 self->sublist = OWGetProperty(_config, @"sublist");
61 self->value = OWGetProperty(_config, @"value");
62 self->isOrdered = OWGetProperty(_config, @"isOrdered");
63 self->level = OWGetProperty(_config, @"level");
70 RELEASE(self->isOrdered);
72 RELEASE(self->sublist);
76 RELEASE(self->selection);
77 RELEASE(self->prefix);
78 RELEASE(self->suffix);
79 RELEASE(self->action);
83 /* processing requests */
85 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
89 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
90 WOComponent *sComponent = [_ctx component];
96 array = [self->list valueInComponent:sComponent];
97 if ([array count] < 1) return nil;
99 idxId = [_ctx currentElementID]; // top level index
100 while ((idxId != nil) && (array != nil)) {
101 unsigned idx = [idxId unsignedIntValue];
103 object = [array objectAtIndex:idx];
105 if ([self->level isValueSettable])
106 [self->level setUnsignedIntValue:nesting inComponent:sComponent];
107 if ([self->index isValueSettable])
108 [self->index setUnsignedIntValue:idx inComponent:sComponent];
109 if ([self->item isValueSettable])
110 [self->item setValue:object inComponent:sComponent];
112 array = [self->sublist valueInComponent:sComponent];
113 idxId = [_ctx consumeElementID]; // sub level index
117 if ([self->selection isValueSettable])
118 [self->selection setValue:object inComponent:sComponent];
120 return [self executeAction:self->action inContext:_ctx];
123 /* generating response */
125 - (void)appendList:(NSArray *)_list atLevel:(unsigned int)_level
126 toResponse:(WOResponse *)_response inContext:(WOContext *)_ctx
128 WOComponent *sComponent = [_ctx component];
129 unsigned count = [_list count];
135 if ([self->level isValueSettable])
136 [self->level setUnsignedIntValue:_level inComponent:sComponent];
138 ordered = [self->isOrdered boolValueInComponent:sComponent];
140 WOResponse_AddString(_response, ordered ? @"<ol>" : @"<ul>");
142 [_ctx appendZeroElementIDComponent];
143 for (cnt = 0; cnt < count; cnt++) {
144 id object = [_list objectAtIndex:cnt];
146 if ([self->index isValueSettable])
147 [self->index setUnsignedIntValue:cnt inComponent:sComponent];
149 if ([self->item isValueSettable])
150 [self->item setValue:object inComponent:sComponent];
153 WOResponse_AddCString(_response, "<li>");
155 NSArray *sl = [self->sublist valueInComponent:sComponent];
160 ps = [self->prefix stringValueInComponent:sComponent];
161 WOResponse_AddString(_response, ps);
166 WOResponse_AddCString(_response, "<a href=\"");
167 WOResponse_AddString(_response, [_ctx componentActionURL]);
168 [_response appendContentCharacter:'"'];
169 [self appendExtraAttributesToResponse:_response inContext:_ctx];
170 [_response appendContentCharacter:'>'];
173 WOResponse_AddHtmlString(_response,
174 [self->value stringValueInComponent:sComponent]);
176 WOResponse_AddCString(_response, "</a>");
182 ss = [self->suffix stringValueInComponent:sComponent];
183 WOResponse_AddString(_response, ss);
186 if ([sl count] > 0) { // not a leaf
191 if ([self->level isValueSettable])
192 [self->level setUnsignedIntValue:_level inComponent:sComponent];
195 WOResponse_AddCString(_response, "</li>\n");
197 [_ctx incrementLastElementIDComponent];
199 [_ctx deleteLastElementIDComponent]; // list index
201 WOResponse_AddString(_response, ordered ? @"</ol>" : @"</ul>");
203 if ([self->level isValueSettable])
204 [self->level setUnsignedIntValue:_level inComponent:sComponent];
208 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
211 top = [self->list valueInComponent:[_ctx component]];
212 if ([top count] > 0) {
222 - (NSString *)associationDescription {
223 NSMutableString *str;
225 str = [NSMutableString stringWithCapacity:64];
226 if (self->action) [str appendFormat:@" action=%@", self->action];
227 if (self->list) [str appendFormat:@" list=%@", self->list];
228 if (self->sublist) [str appendFormat:@" sublist=%@", self->sublist];
229 if (self->item) [str appendFormat:@" item=%@", self->item];
230 if (self->index) [str appendFormat:@" index=%@", self->index];
231 if (self->prefix) [str appendFormat:@" prefix=%@", self->prefix];
232 if (self->suffix) [str appendFormat:@" suffix=%@", self->suffix];
233 if (self->selection) [str appendFormat:@" selection=%@", self->selection];
234 if (self->value) [str appendFormat:@" value=%@", self->value];
235 if (self->isOrdered) [str appendFormat:@" isOrdered=%@", self->isOrdered];
236 if (self->level) [str appendFormat:@" level=%@", self->level];
240 @end /* WONestedList */