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 <NGObjWeb/WODynamicElement.h>
24 @interface WOTabPanel : WODynamicElement
27 WOAssociation *selectedTab;
28 WOAssociation *tabNameKey;
29 WOAssociation *nonSelectedBgColor;
30 WOAssociation *bgcolor;
31 WOAssociation *textColor;
32 WOAssociation *submitActionName;
40 @interface WOContext(NGPrivates)
41 - (void)addActiveFormElement:(WOElement *)_element;
44 @implementation WOTabPanel
46 - (id)initWithName:(NSString *)_name
47 associations:(NSDictionary *)_config
48 template:(WOElement *)_c
50 if ((self = [super initWithName:_name associations:_config template:_c])) {
51 self->tabs = WOExtGetProperty(_config, @"tabs");
52 self->selectedTab = WOExtGetProperty(_config, @"selectedTab");
53 self->tabNameKey = WOExtGetProperty(_config, @"tabNameKey");
55 self->nonSelectedBgColor =
56 WOExtGetProperty(_config, @"nonSelectedBgColor");
57 self->bgcolor = WOExtGetProperty(_config, @"bgcolor");
58 self->textColor = WOExtGetProperty(_config, @"textColor");
60 self->submitActionName = WOExtGetProperty(_config, @"submitActionName");
62 self->template = [_c retain];
68 [self->submitActionName release];
69 [self->textColor release];
70 [self->bgcolor release];
71 [self->nonSelectedBgColor release];
72 [self->tabNameKey release];
73 [self->selectedTab release];
75 [self->template release];
79 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
80 /* check whether a (form) tab was clicked */
81 [_ctx appendElementIDComponent:@"tab"];
83 WOComponent *sComponent;
87 sComponent = [_ctx component];
88 ttabs = [self->tabs valueInComponent:sComponent];
90 [_ctx appendZeroElementIDComponent];
92 for (i = 0; i < [ttabs count]; i++) {
93 if ([_req formValueForKey:[_ctx elementID]]) {
94 /* found active tab */
95 [self->selectedTab setValue:[ttabs objectAtIndex:i]
96 inComponent:sComponent];
97 [_ctx addActiveFormElement:self];
100 [_ctx incrementLastElementIDComponent];
103 [_ctx deleteLastElementIDComponent];
105 [_ctx deleteLastElementIDComponent];
107 /* let content take values */
108 [_ctx appendElementIDComponent:@"content"];
109 [self->template takeValuesFromRequest:_req inContext:_ctx];
110 [_ctx deleteLastElementIDComponent];
113 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
117 section = [_ctx currentElementID];
118 if ([section isEqualToString:@"tab"]) {
119 WOComponent *sComponent;
123 [_ctx consumeElementID]; // consume 'tab'
125 sComponent = [_ctx component];
126 ttabs = [self->tabs valueInComponent:sComponent];
128 idx = [[_ctx currentElementID] intValue];
129 [_ctx consumeElementID]; // consume index
131 if (idx >= (int)[ttabs count]) {
132 /* index out of range */
136 [self->selectedTab setValue:[ttabs objectAtIndex:idx]
137 inComponent:sComponent];
139 result = [_ctx page];
141 else if ([section isEqualToString:@"content"]) {
142 [_ctx consumeElementID]; // consume 'content'
144 [_ctx appendElementIDComponent:@"content"];
145 result = [self->template invokeActionForRequest:_req inContext:_ctx];
146 [_ctx deleteLastElementIDComponent];
149 NSLog(@"%s: missing section id !", __PRETTY_FUNCTION__);
150 result = [_ctx page];
155 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
156 WOComponent *sComponent;
160 NSString *selColor, *unselColor, *s;
162 sComponent = [_ctx component];
163 ttabs = [self->tabs valueInComponent:sComponent];
165 selColor = self->bgcolor
166 ? [self->bgcolor stringValueInComponent:sComponent]
167 : (NSString *)@"#CCCCCC";
169 unselColor = self->nonSelectedBgColor
170 ? [self->nonSelectedBgColor stringValueInComponent:sComponent]
171 : (NSString *)@"#AAAAAA";
173 if ([ttabs count] < 1) {
174 /* no tabs configured .. */
175 [self->template appendToResponse:_response inContext:_ctx];
179 [_response appendContentString:@"<table border='0'>"];
180 [_response appendContentString:@"<tr>"];
182 isInForm = [_ctx isInForm];
184 /* cannot use -indexOfObjectIdenticalTo:, since this doesn't work
185 with language bridges (base types crossing a bridge aren't
186 enforced to be identical ... */
187 selIdx = [ttabs indexOfObject:
188 [self->selectedTab valueInComponent:sComponent]];
189 if (selIdx == NSNotFound)
192 [_ctx appendElementIDComponent:@"tab"];
193 [_ctx appendZeroElementIDComponent];
195 for (i = 0; i < [ttabs count]; i++) {
197 BOOL isCurrentSelected;
200 tab = [ttabs objectAtIndex:i];
201 isCurrentSelected = i == selIdx;
203 [self->selectedTab setValue:tab inComponent:sComponent];
205 title = (self->tabNameKey)
206 ? [self->tabNameKey stringValueInComponent:sComponent]
209 [_response appendContentString:@"<td"];
210 [_response appendContentString:@" bgcolor=\""];
211 [_response appendContentString:isCurrentSelected ? selColor : unselColor];
212 [_response appendContentString:@"\""];
213 [_response appendContentString:@">"];
216 /* gen submit button */
217 [_response appendContentString:@"<input type='submit' name=\""];
218 [_response appendContentHTMLAttributeValue:[_ctx elementID]];
219 [_response appendContentString:@"\" value=\""];
220 [_response appendContentString:title];
221 [_response appendContentString:
222 (_ctx->wcFlags.xmlStyleEmptyElements ? @" />" : @">")];
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 != nil) {
233 [_response appendContentString:@"<font color=\""];
234 [_response appendContentHTMLAttributeValue:
235 [self->textColor stringValueInComponent:sComponent]];
236 [_response appendContentString:@"\">"];
239 [_response appendContentHTMLString:title];
241 if (self->textColor != nil)
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 */