2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
23 #include <NGObjDOM/ODNodeRenderer.h>
37 var list = [ "1", "2", "3", "4" ];
40 <wo:popupbutton list="list" item="item" selection="selection"/>
44 @interface ODR_bind_popupbutton : ODNodeRenderer
50 @implementation ODR_bind_popupbutton
52 - (BOOL)requiresFormForNode:(id)_domNode inContext:(WOContext *)_ctx {
56 - (void)takeValuesForNode:(id)_node
57 fromRequest:(WORequest *)_req
58 inContext:(WOContext *)_ctx
63 name = [self stringFor:@"name" node:_node ctx:_ctx];
64 name = (name) ? name : [_ctx elementID];
66 formValue = [_req formValueForKey:name];
68 if ([self isSettable:@"value" node:_node ctx:_ctx])
69 [self setValue:formValue for:@"value" node:_node ctx:_ctx];
75 objects = [self valueFor:@"list" node:_node ctx:_ctx];
78 if ([self hasAttribute:@"value" node:_node ctx:_ctx]) {
79 /* has a value binding, walk list to find object */
82 for (i = 0, toGo = [objects count]; i < toGo; i++) {
85 object = [objects objectAtIndex:i];
87 if ([self isSettable:@"item" node:_node ctx:_ctx])
88 [self setValue:object for:@"item" node:_node ctx:_ctx];
90 cv = [self stringFor:@"value" node:_node ctx:_ctx];
92 if ([cv isEqualToString:formValue])
96 else if (![formValue isEqualToString:@"$"]) {
97 /* an index binding */
100 idx = [formValue intValue];
101 if (idx >= (int)[objects count]) {
102 [[_ctx page] logWithFormat:@"popup-index %i out of range 0-%i",
103 idx, [objects count] - 1];
107 object = [objects objectAtIndex:idx];
110 if ([self isSettable:@"selection" node:_node ctx:_ctx]) {
111 if ([self isSettable:@"item" node:_node ctx:_ctx])
112 [self setValue:object for:@"item" node:_node ctx:_ctx];
114 if ([self isSettable:@"selection" node:_node ctx:_ctx])
115 [self setValue:object for:@"selection" node:_node ctx:_ctx];
120 if ([self isSettable:@"item" node:_node ctx:_ctx])
121 [self setValue:nil for:@"item" node:_node ctx:_ctx];
122 if ([self isSettable:@"selection" node:_node ctx:_ctx])
123 [self setValue:nil for:@"selection" node:_node ctx:_ctx];
127 - (void)appendOptions:(id)_node
128 toResponse:(WOResponse *)_response
129 inContext:(WOContext *)_ctx
131 NSString *nilStr = nil;
132 NSArray *array = nil;
136 nilStr = [self stringFor:@"noselectionstring" node:_node ctx:_ctx];
138 nilStr = [self stringFor:@"noSelectionString" node:_node ctx:_ctx];
139 array = [self valueFor:@"list" node:_node ctx:_ctx];
140 selection = [self valueFor:@"selection" node:_node ctx:_ctx];
144 [_response appendContentString:@" <option value=\"$\">"];
145 [_response appendContentHTMLString:nilStr];
146 [_response appendContentString:@"\n"];
149 for (i = 0; i < cnt; i++) {
151 NSString *displayV = nil;
152 id object = [array objectAtIndex:i];
155 if ([self isSettable:@"item" node:_node ctx:_ctx])
156 [self setValue:object for:@"item" node:_node ctx:_ctx];
158 isSelected = (selection) ? [selection isEqual:object] : NO;
160 v = ([self hasAttribute:@"value" node:_node ctx:_ctx])
161 ? [self stringFor:@"value" node:_node ctx:_ctx]
162 : [NSString stringWithFormat:@"%i", i];
164 displayV = ([self hasAttribute:@"string" node:_node ctx:_ctx])
165 ? [self stringFor:@"string" node:_node ctx:_ctx]
166 : [object stringValue];
168 if (displayV == nil) displayV = @"<nil>";
170 [_response appendContentString:@" <option value=\""];
171 [_response appendContentString:v];
172 [_response appendContentString:(isSelected) ? @"\" selected>" : @"\">"];
173 [_response appendContentHTMLString:displayV];
174 [_response appendContentString:@"\n"];
178 - (void)appendNode:(id)_node
179 toResponse:(WOResponse *)_response
180 inContext:(WOContext *)_ctx
184 name = [self stringFor:@"name" node:_node ctx:_ctx];
185 name = (name) ? name : [_ctx elementID];
187 [_response appendContentString:@"<select name=\""];
188 [_response appendContentHTMLAttributeValue:name];
189 [_response appendContentString:@"\">\n"];
191 [self appendOptions:_node toResponse:_response inContext:_ctx];
193 [_response appendContentString:@"</select>"];
196 @end /* ODR_bind_popupbutton */
199 @interface ODR_bind_popup : ODR_bind_popupbutton
202 @implementation ODR_bind_popup