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 *)_rq inContext:(WOContext *)_ctx {
76 WOComponent *sComponent = [_ctx component];
81 formValue = [_rq formValueForKey:OWFormElementName(self, _ctx)];
85 idx = [formValue unsignedIntValue];
86 array = [self->list valueInComponent:sComponent];
88 /* setup item/index */
90 if ([self->index isValueSettable])
91 [self->index setUnsignedIntValue:idx inComponent:sComponent];
93 if ([self->item isValueSettable])
94 [self->item setValue:[array objectAtIndex:idx] inComponent:sComponent];
96 /* now check whether the item is disabled/allowed as the selection */
98 if ([self->disabled boolValueInComponent:sComponent])
101 /* set selection if possible */
103 if ([self->selection isValueSettable]) {
104 [self->selection setValue:[array objectAtIndex:idx]
105 inComponent:sComponent];
109 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
113 /* generating response */
115 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
116 WOComponent *sComponent;
122 BOOL canSetIndex, canSetItem;
124 sComponent = [_ctx component];
125 array = [self->list valueInComponent:sComponent];
126 goCount = [array count];
131 n = OWFormElementName(self, _ctx);
132 sel = [self->selection valueInComponent:sComponent];
134 canSetIndex = [self->index isValueSettable];
135 canSetItem = [self->item isValueSettable];
137 for (cnt = 0; cnt < goCount; cnt++) {
140 object = [array objectAtIndex:cnt];
143 [self->index setUnsignedIntValue:cnt inComponent:sComponent];
146 [self->item setValue:object inComponent:sComponent];
148 if (self->prefix != nil) {
149 WOResponse_AddString(_response,
150 [self->prefix stringValueInComponent:sComponent]);
153 /* add radio button */
155 WOResponse_AddCString(_response, "<input type=\"radio\" name=\"");
156 [_response appendContentHTMLAttributeValue:n];
157 WOResponse_AddCString(_response, "\" value=\"");
158 WOResponse_AddInt(_response, cnt);
159 WOResponse_AddCString(_response, "\"");
161 if (sel == object || [sel isEqual:object]) {
162 WOResponse_AddCString(_response,
163 (_ctx->wcFlags.allowEmptyAttributes
164 ? " checked" : " checked=\"checked\""));
167 if ([self->disabled boolValueInComponent:sComponent]) {
168 WOResponse_AddCString(_response,
169 (_ctx->wcFlags.allowEmptyAttributes
170 ? " disabled" : " disabled=\"disabled\""));
173 [self appendExtraAttributesToResponse:_response inContext:_ctx];
174 if (self->otherTagString != nil) {
177 s = [self->otherTagString stringValueInComponent:sComponent];
178 WOResponse_AddChar(_response, ' ');
179 WOResponse_AddString(_response, s);
181 WOResponse_AddEmptyCloseParens(_response, _ctx);
183 // the value in a radio list is the string besides the button
184 if (self->value != nil) {
187 s = [self->value stringValueInComponent:sComponent];
188 WOResponse_AddHtmlString(_response, s);
192 if (self->suffix != nil) {
193 WOResponse_AddString(_response,
194 [self->suffix stringValueInComponent:sComponent]);
201 - (NSString *)associationDescription {
202 NSMutableString *str;
204 str = [NSMutableString stringWithCapacity:128];
205 [str appendString:[super associationDescription]];
206 if (self->list) [str appendFormat:@" list=%@", self->list];
207 if (self->item) [str appendFormat:@" item=%@", self->item];
208 if (self->index) [str appendFormat:@" index=%@", self->index];
209 if (self->prefix) [str appendFormat:@" prefix=%@", self->prefix];
210 if (self->suffix) [str appendFormat:@" suffix=%@", self->suffix];
211 if (self->selection) [str appendFormat:@" selection=%@", self->selection];
216 @end /* WORadioButtonList */