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 <NGObjWeb/WODynamicElement.h>
25 @interface WOTabPanel : WODynamicElement
28 WOAssociation *selectedTab;
29 WOAssociation *tabNameKey;
30 WOAssociation *nonSelectedBgColor;
31 WOAssociation *bgcolor;
32 WOAssociation *textColor;
33 WOAssociation *submitActionName;
41 @interface WOContext(NGPrivates)
42 - (void)addActiveFormElement:(WOElement *)_element;
45 @implementation WOTabPanel
47 - (id)initWithName:(NSString *)_name
48 associations:(NSDictionary *)_config
49 template:(WOElement *)_c
51 if ((self = [super initWithName:_name associations:_config template:_c])) {
52 self->tabs = WOExtGetProperty(_config, @"tabs");
53 self->selectedTab = WOExtGetProperty(_config, @"selectedTab");
54 self->tabNameKey = WOExtGetProperty(_config, @"tabNameKey");
56 self->nonSelectedBgColor =
57 WOExtGetProperty(_config, @"nonSelectedBgColor");
58 self->bgcolor = WOExtGetProperty(_config, @"bgcolor");
59 self->textColor = WOExtGetProperty(_config, @"textColor");
61 self->submitActionName = WOExtGetProperty(_config, @"submitActionName");
63 self->template = [_c retain];
69 [self->submitActionName release];
70 [self->textColor release];
71 [self->bgcolor release];
72 [self->nonSelectedBgColor release];
73 [self->tabNameKey release];
74 [self->selectedTab release];
76 [self->template release];
80 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
81 /* check whether a (form) tab was clicked */
82 [_ctx appendElementIDComponent:@"tab"];
84 WOComponent *sComponent;
88 sComponent = [_ctx component];
89 ttabs = [self->tabs valueInComponent:sComponent];
91 [_ctx appendZeroElementIDComponent];
93 for (i = 0; i < [ttabs count]; i++) {
94 if ([_req formValueForKey:[_ctx elementID]]) {
95 /* found active tab */
96 [self->selectedTab setValue:[ttabs objectAtIndex:i]
97 inComponent:sComponent];
98 [_ctx addActiveFormElement:self];
101 [_ctx incrementLastElementIDComponent];
104 [_ctx deleteLastElementIDComponent];
106 [_ctx deleteLastElementIDComponent];
108 /* let content take values */
109 [_ctx appendElementIDComponent:@"content"];
110 [self->template takeValuesFromRequest:_req inContext:_ctx];
111 [_ctx deleteLastElementIDComponent];
114 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
118 section = [_ctx currentElementID];
119 if ([section isEqualToString:@"tab"]) {
120 WOComponent *sComponent;
124 [_ctx consumeElementID]; // consume 'tab'
126 sComponent = [_ctx component];
127 ttabs = [self->tabs valueInComponent:sComponent];
129 idx = [[_ctx currentElementID] intValue];
130 [_ctx consumeElementID]; // consume index
132 if (idx >= (int)[ttabs count]) {
133 /* index out of range */
137 [self->selectedTab setValue:[ttabs objectAtIndex:idx]
138 inComponent:sComponent];
140 result = [_ctx page];
142 else if ([section isEqualToString:@"content"]) {
143 [_ctx consumeElementID]; // consume 'content'
145 [_ctx appendElementIDComponent:@"content"];
146 result = [self->template invokeActionForRequest:_req inContext:_ctx];
147 [_ctx deleteLastElementIDComponent];
150 NSLog(@"%s: missing section id !", __PRETTY_FUNCTION__);
151 result = [_ctx page];
156 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
157 WOComponent *sComponent;
161 NSString *selColor, *unselColor, *s;
163 sComponent = [_ctx component];
164 ttabs = [self->tabs valueInComponent:sComponent];
166 selColor = self->bgcolor
167 ? [self->bgcolor stringValueInComponent:sComponent]
170 unselColor = self->nonSelectedBgColor
171 ? [self->nonSelectedBgColor stringValueInComponent:sComponent]
174 if ([ttabs count] < 1) {
175 /* no tabs configured .. */
176 [self->template appendToResponse:_response inContext:_ctx];
180 [_response appendContentString:@"<table border='0'>"];
181 [_response appendContentString:@"<tr>"];
183 isInForm = [_ctx isInForm];
185 /* cannot use -indexOfObjectIdenticalTo:, since this doesn't work
186 with language bridges (base types crossing a bridge aren't
187 enforced to be identical ... */
188 selIdx = [ttabs indexOfObject:
189 [self->selectedTab valueInComponent:sComponent]];
190 if (selIdx == NSNotFound)
193 [_ctx appendElementIDComponent:@"tab"];
194 [_ctx appendZeroElementIDComponent];
196 for (i = 0; i < [ttabs count]; i++) {
198 BOOL isCurrentSelected;
201 tab = [ttabs objectAtIndex:i];
202 isCurrentSelected = i == selIdx;
204 [self->selectedTab setValue:tab inComponent:sComponent];
206 title = (self->tabNameKey)
207 ? [self->tabNameKey stringValueInComponent:sComponent]
210 [_response appendContentString:@"<td"];
211 [_response appendContentString:@" bgcolor=\""];
212 [_response appendContentString:isCurrentSelected ? selColor : unselColor];
213 [_response appendContentString:@"\""];
214 [_response appendContentString:@">"];
217 /* gen submit button */
218 [_response appendContentString:@"<input type='submit' name=\""];
219 [_response appendContentHTMLAttributeValue:[_ctx elementID]];
220 [_response appendContentString:@"\" value=\""];
221 [_response appendContentString:title];
222 [_response appendContentString:@"\" />"];
226 [_response appendContentString:@"<a href=\""];
227 [_response appendContentHTMLAttributeValue:[_ctx componentActionURL]];
228 [_response appendContentString:@"\" title=\""];
229 [_response appendContentHTMLAttributeValue:title];
230 [_response appendContentString:@"\">"];
232 if (self->textColor) {
233 [_response appendContentString:@"<font color=\""];
234 [_response appendContentHTMLAttributeValue:
235 [self->textColor stringValueInComponent:sComponent]];
236 [_response appendContentString:@"\">"];
239 [_response appendContentHTMLString:title];
242 [_response appendContentString:@"</font>"];
243 [_response appendContentString:@"</a>"];
246 [_response appendContentString:@"</td>"];
248 [_ctx incrementLastElementIDComponent]; /* increment index */
250 [_ctx deleteLastElementIDComponent]; /* del index */
251 [_ctx deleteLastElementIDComponent]; /* del 'tab' */
253 [self->selectedTab setValue:[ttabs objectAtIndex:selIdx]
254 inComponent:sComponent];
256 [_response appendContentString:@"</tr><tr><td colspan=\""];
257 s = [[NSString alloc] initWithFormat:@"%d",[ttabs count]];
258 [_response appendContentString:s];
260 [_response appendContentString:@"\" bgcolor=\""];
261 [_response appendContentString:selColor];
262 [_response appendContentString:@"\">"];
264 [_ctx appendElementIDComponent:@"content"];
265 [self->template appendToResponse:_response inContext:_ctx];
266 [_ctx deleteLastElementIDComponent];
268 [_response appendContentString:@"</td></tr></table>"];
271 @end /* WOTabPanel */