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/NGObjWeb.h>
25 @interface WOCollapsibleComponentContent : WODynamicElement
28 WOAssociation *condition;
29 WOAssociation *visibility;
30 WOAssociation *openedImageFileName;
31 WOAssociation *closedImageFileName;
32 WOAssociation *framework;
33 WOAssociation *openedLabel;
34 WOAssociation *closedLabel;
35 WOAssociation *submitActionName;
41 @interface WOContext(WOExtensionsPrivate)
42 - (void)addActiveFormElement:(WOElement *)_element;
45 @implementation WOCollapsibleComponentContent
47 - (id)initWithName:(NSString *)_name
48 associations:(NSDictionary *)_config
49 template:(WOElement *)_temp
51 if ((self = [super initWithName:_name associations:_config template:_temp])) {
52 self->condition = WOExtGetProperty(_config, @"condition");
53 self->visibility = WOExtGetProperty(_config, @"visibility");
54 self->openedImageFileName =
55 WOExtGetProperty(_config, @"openedImageFileName");
56 self->closedImageFileName =
57 WOExtGetProperty(_config, @"closedImageFileName");
58 self->framework = WOExtGetProperty(_config, @"framework");
59 self->openedLabel = WOExtGetProperty(_config, @"openedLabel");
60 self->closedLabel = WOExtGetProperty(_config, @"closedLabel");
61 self->submitActionName = WOExtGetProperty(_config, @"submitActionName");
63 if (WOExtGetProperty(_config, @"condition"))
64 NSLog(@"WARNING: WOCollapsibleComponent does not support 'condition'");
66 if (self->visibility == nil)
67 NSLog(@"WARNING: WOCollapsibleComponent 'visibility' not set");
69 if (self->visibility && ![self->visibility isValueSettable])
70 NSLog(@"WARNING: WOCollapsibleComponent 'visibility' is not settable");
72 ASSIGN(self->template, _temp);
78 RELEASE(self->condition);
79 RELEASE(self->visibility);
80 RELEASE(self->openedImageFileName);
81 RELEASE(self->closedImageFileName);
82 RELEASE(self->framework);
83 RELEASE(self->openedLabel);
84 RELEASE(self->closedLabel);
85 RELEASE(self->submitActionName);
87 RELEASE(self->template);
94 - (void)takeValuesFromRequest:(WORequest *)_request
95 inContext:(WOContext *)_ctx
99 eid = [_ctx elementID];
101 if ([self->visibility boolValueInComponent:[_ctx component]]) {
102 [_ctx appendZeroElementIDComponent];
103 [self->template takeValuesFromRequest:_request inContext:_ctx];
104 [_ctx deleteLastElementIDComponent];
107 if ([_request formValueForKey:[eid stringByAppendingString:@".c.x"]]) {
108 [_ctx addActiveFormElement:self];
109 [_ctx setRequestSenderID:[[_ctx senderID] stringByAppendingString:@".c"]];
111 else if ([_request formValueForKey:[eid stringByAppendingString:@".e.x"]]) {
112 [_ctx addActiveFormElement:self];
113 [_ctx setRequestSenderID:[[_ctx senderID] stringByAppendingString:@".e"]];
117 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
121 state = [[_ctx currentElementID] stringValue];
123 eid = [_ctx elementID];
128 [_ctx consumeElementID]; // consume state-id (on or off)
130 doForm = ([_ctx isInForm] && self->submitActionName);
132 if ([state isEqualToString:@"e"]) {
133 if ([self->visibility isValueSettable])
134 [self->visibility setBoolValue:NO inComponent:[_ctx component]];
136 [self->submitActionName valueInComponent:[_ctx component]];
138 else if ([state isEqualToString:@"c"]) {
139 if ([self->visibility isValueSettable])
140 [self->visibility setBoolValue:YES inComponent:[_ctx component]];
142 [self->submitActionName valueInComponent:[_ctx component]];
147 [_ctx appendElementIDComponent:state];
148 result = [self->template invokeActionForRequest:_request inContext:_ctx];
149 [_ctx deleteLastElementIDComponent];
157 - (void)appendToResponse:(WOResponse *)_resp inContext:(WOContext *)_ctx {
164 comp = [_ctx component];
166 if ([self->visibility valueInComponent:comp] == nil) {
167 isCollapsed = ![self->condition boolValueInComponent:comp];
168 if ([self->visibility isValueSettable])
169 [self->visibility setBoolValue:!isCollapsed inComponent:comp];
172 isCollapsed = ![self->visibility boolValueInComponent:comp];
175 ? [self->closedImageFileName stringValueInComponent:comp]
176 : [self->openedImageFileName stringValueInComponent:comp];
178 label = (isCollapsed)
179 ? [self->closedLabel stringValueInComponent:comp]
180 : [self->openedLabel stringValueInComponent:comp];
182 img = WOUriOfResource(img, _ctx);
185 [_resp appendContentString:@" "];
187 doForm = ([_ctx isInForm] && self->submitActionName && img);
189 [_ctx appendElementIDComponent:(isCollapsed) ? @"c" : @"e"];
191 [_resp appendContentString:@"<INPUT TYPE=\"image\" BORDER=\"0\" NAME=\""];
192 [_resp appendContentString:[_ctx elementID]];
193 [_resp appendContentString:@"\" SRC=\""];
194 [_resp appendContentString:img];
195 [_resp appendContentString:@"\">"];
198 [_resp appendContentString:@"<A HREF=\""];
199 [_resp appendContentString:[_ctx componentActionURL]];
200 [_resp appendContentString:@"\">"];
203 [_resp appendContentString:@"<IMG BORDER=0 SRC=\""];
204 [_resp appendContentString:img];
205 [_resp appendContentString:@"\""];
207 [_resp appendContentString:@" NAME=\""];
208 [_resp appendContentString:label];
209 [_resp appendContentString:@"\""];
211 [_resp appendContentString:@">"];
214 [_resp appendContentString:(isCollapsed) ? @"[+]" : @"[-]"];
215 [_resp appendContentString:@"</A> "];
220 [_resp appendContentString:@"<A HREF=\""];
221 [_resp appendContentString:[_ctx componentActionURL]];
222 [_resp appendContentString:@"\">"];
225 [_resp appendContentString:label];
228 [_resp appendContentString:@"</A>"];
230 [_ctx deleteLastElementIDComponent];
232 [_resp appendContentString:@"<BR>"];
235 [_ctx appendZeroElementIDComponent];
236 [self->template appendToResponse:_resp inContext:_ctx];
237 [_ctx deleteLastElementIDComponent];
241 @end /* WOComponentContent */