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
24 @interface WORadioButtonList : WOInput
26 // WODynamicElement: extraAttributes
27 // WODynamicElement: otherTagString
35 WOAssociation *selection;
36 WOAssociation *prefix;
37 WOAssociation *suffix;
40 @end /* WORadioButtonList */
44 // TODO: add support for template? (does WO provide this?)
46 @implementation WORadioButtonList
48 - (id)initWithName:(NSString *)_name
49 associations:(NSDictionary *)_config
50 template:(WOElement *)_c
52 if ((self = [super initWithName:_name associations:_config template:_c])) {
53 self->list = OWGetProperty(_config, @"list");
54 self->item = OWGetProperty(_config, @"item");
55 self->index = OWGetProperty(_config, @"index");
56 self->selection = OWGetProperty(_config, @"selection");
57 self->prefix = OWGetProperty(_config, @"prefix");
58 self->suffix = OWGetProperty(_config, @"suffix");
66 [self->index release];
67 [self->selection release];
68 [self->prefix release];
69 [self->suffix release];
73 /* processing requests */
75 - (void)takeValuesFromRequest:(WORequest *)_request
76 inContext:(WOContext *)_ctx
78 WOComponent *sComponent = [_ctx component];
83 if ([self->disabled boolValueInComponent:sComponent])
86 formValue = [_request formValueForKey:OWFormElementName(self, _ctx)];
90 idx = [formValue unsignedIntValue];
91 array = [self->list valueInComponent:sComponent];
93 if ([self->index isValueSettable])
94 [self->index setUnsignedIntValue:idx inComponent:sComponent];
96 if ([self->item isValueSettable])
97 [self->item setValue:[array objectAtIndex:idx] inComponent:sComponent];
99 if ([self->selection isValueSettable]) {
100 [self->selection setValue:[array objectAtIndex:idx]
101 inComponent:sComponent];
105 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
109 /* generating response */
111 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
112 WOComponent *sComponent;
119 sComponent = [_ctx component];
120 array = [self->list valueInComponent:sComponent];
121 goCount = [array count];
126 n = OWFormElementName(self, _ctx);
127 sel = [self->selection valueInComponent:sComponent];
129 for (cnt = 0; cnt < goCount; cnt++) {
130 id object = [array objectAtIndex:cnt];
132 if ([self->index isValueSettable])
133 [self->index setUnsignedIntValue:cnt inComponent:sComponent];
135 if ([self->item isValueSettable])
136 [self->item setValue:object inComponent:sComponent];
139 WOResponse_AddString(_response,
140 [self->prefix stringValueInComponent:sComponent]);
143 /* add radio button */
145 WOResponse_AddCString(_response, "<input type=\"radio\" name=\"");
146 [_response appendContentHTMLAttributeValue:n];
147 WOResponse_AddCString(_response, "\" value=\"");
148 WOResponse_AddInt(_response, cnt);
149 WOResponse_AddCString(_response, "\"");
151 if ([sel isEqual:object])
152 WOResponse_AddCString(_response, " checked=\"checked\"");
153 [self appendExtraAttributesToResponse:_response inContext:_ctx];
154 if (self->otherTagString) {
155 WOResponse_AddChar(_response, ' ');
156 WOResponse_AddString(_response,
157 [self->otherTagString stringValueInComponent:
160 WOResponse_AddCString(_response, " />");
162 // the value in a radio list is the string besides the button
166 s = [self->value stringValueInComponent:sComponent];
167 WOResponse_AddHtmlString(_response, s);
172 WOResponse_AddString(_response,
173 [self->suffix stringValueInComponent:sComponent]);
180 - (NSString *)associationDescription {
181 NSMutableString *str;
183 str = [NSMutableString stringWithCapacity:128];
184 [str appendString:[super associationDescription]];
185 if (self->list) [str appendFormat:@" list=%@", self->list];
186 if (self->item) [str appendFormat:@" item=%@", self->item];
187 if (self->index) [str appendFormat:@" index=%@", self->index];
188 if (self->prefix) [str appendFormat:@" prefix=%@", self->prefix];
189 if (self->suffix) [str appendFormat:@" suffix=%@", self->suffix];
190 if (self->selection) [str appendFormat:@" selection=%@", self->selection];
195 @end /* WORadioButtonList */