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 JSModalWindow : WODynamicElement
26 WOAssociation *action;
27 WOAssociation *pageName;
28 WOAssociation *href; /* non - WO API */
30 WOAssociation *height;
32 WOAssociation *windowName;
33 WOAssociation *isResizable;
34 WOAssociation *showLocation;
35 WOAssociation *showMenuBar;
36 WOAssociation *showScrollbars;
37 WOAssociation *showStatus;
38 WOAssociation *showToolbar;
43 WOAssociation *isCenter;
44 WOAssociation *filename;
45 WOAssociation *string;
46 WOAssociation *framework;
55 @implementation JSModalWindow
58 return [super version] + 0 /* v2 */;
61 NSAssert2([super version] == 2,
62 @"invalid superclass (%@) version %i !",
63 NSStringFromClass([self superclass]), [super version]);
66 - (id)initWithName:(NSString *)_name
67 associations:(NSDictionary *)_config
68 template:(WOElement *)_subs
70 if ((self = [super initWithName:_name associations:_config template:_subs])){
73 self->action = WOExtGetProperty(_config, @"action");
74 self->pageName = WOExtGetProperty(_config, @"pageName");
75 self->href = WOExtGetProperty(_config, @"href");
77 self->height = WOExtGetProperty(_config, @"height");
78 self->width = WOExtGetProperty(_config, @"width");
79 self->windowName = WOExtGetProperty(_config, @"windowName");
80 self->isResizable = WOExtGetProperty(_config, @"isResizable");
81 self->showLocation = WOExtGetProperty(_config, @"showLocation");
82 self->showMenuBar = WOExtGetProperty(_config, @"showMenuBar");
83 self->showScrollbars = WOExtGetProperty(_config, @"showScrollbars");
84 self->showStatus = WOExtGetProperty(_config, @"showStatus");
85 self->showToolbar = WOExtGetProperty(_config, @"showToolbar");
87 self->top = WOExtGetProperty(_config, @"top");
88 self->left = WOExtGetProperty(_config, @"left");
89 self->isCenter = WOExtGetProperty(_config, @"isCenter");
90 self->filename = WOExtGetProperty(_config, @"filename");
91 self->string = WOExtGetProperty(_config, @"string");
92 self->framework = WOExtGetProperty(_config, @"framework");
95 if (self->action) funcCount++;
96 if (self->pageName) funcCount++;
97 if (self->href) funcCount++;
100 NSLog(@"WARNING: JSModalWindow: choose only one of "
101 @"action | pageName | href");
103 NSLog(@"WARNING: JSModalWindow: no function declared - choose one of"
104 @"action | pageName | href");
106 #define SetAssociationValue(_assoc_, _value_) \
107 if (_assoc_ == nil) { \
108 _assoc_ = [WOAssociation associationWithValue:_value_]; \
112 SetAssociationValue(self->height, @"300");
113 SetAssociationValue(self->width, @"300");
114 SetAssociationValue(self->isResizable, @"Yes");
115 SetAssociationValue(self->showLocation, @"Yes");
116 SetAssociationValue(self->showMenuBar, @"Yes");
117 SetAssociationValue(self->showScrollbars, @"Yes");
118 SetAssociationValue(self->showStatus, @"Yes");
119 SetAssociationValue(self->showToolbar, @"Yes");
120 SetAssociationValue(self->top, @"500");
121 SetAssociationValue(self->left, @"500");
123 #undef SetAssociationValue
125 self->template = [_subs retain];
131 [self->action release];
132 [self->pageName release];
133 [self->href release];
135 [self->height release];
136 [self->width release];
137 [self->windowName release];
138 [self->isResizable release];
139 [self->showLocation release];
140 [self->showMenuBar release];
141 [self->showScrollbars release];
142 [self->showStatus release];
143 [self->showToolbar release];
146 [self->left release];
147 [self->isCenter release];
148 [self->filename release];
149 [self->string release];
150 [self->framework release];
152 [self->template release];
156 /* handling requests */
158 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
159 [self->template takeValuesFromRequest:_rq inContext:_ctx];
162 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
163 if (self->pageName != nil) {
166 name = [self->pageName stringValueInComponent: [_ctx component]];
167 return [[_ctx application] pageWithName:name inContext:_ctx];
170 if (self->action != nil)
171 return [self->action valueInComponent:[_ctx component]];
173 return [self->template invokeActionForRequest:_rq inContext:_ctx];
176 /* generating response */
178 - (void)appendToResponse:(WOResponse *)_resp inContext:(WOContext *)_ctx {
183 comp = [_ctx component];
186 [_resp appendContentString:
187 @"<a onclick=\"window.showModalDialog('"];
188 if (self->href != nil)
189 [_resp appendContentString:[self->href stringValueInComponent:comp]];
191 [_resp appendContentString:@"http://sope.opengroupware.org/"];
193 [_resp appendContentString:@"', 'a short text', '"];
195 /* configure modal panel */
196 if (self->height != nil) {
197 [_resp appendContentString:@" dialogHeight: "];
198 [_resp appendContentString:[self->height stringValueInComponent:comp]];
199 [_resp appendContentString:@"px;"];
201 if (self->width != nil) {
202 [_resp appendContentString:@" dialogWidth: "];
203 [_resp appendContentString:[self->width stringValueInComponent:comp]];
204 [_resp appendContentString:@"px;"];
206 if (self->top != nil) {
207 [_resp appendContentString:@" dialogTop: "];
208 [_resp appendContentString:[self->top stringValueInComponent:comp]];
209 [_resp appendContentString:@"px;"];
211 if (self->left != nil) {
212 [_resp appendContentString:@" dialogLeft: "];
213 [_resp appendContentString:[self->left stringValueInComponent:comp]];
214 [_resp appendContentString:@"px;"];
216 if (self->isResizable != nil) {
217 [_resp appendContentString:@" resizable: "];
218 [_resp appendContentString:
219 [self->isResizable stringValueInComponent:comp]];
220 [_resp appendContentCharacter:';'];
222 if (self->showStatus != nil) {
223 [_resp appendContentString:@" status: "];
224 [_resp appendContentString:[self->showStatus stringValueInComponent:comp]];
225 [_resp appendContentCharacter:';'];
227 if (self->isCenter != nil) {
228 [_resp appendContentString:@" center: "];
229 [_resp appendContentString:[self->isCenter stringValueInComponent:comp]];
230 [_resp appendContentCharacter:';'];
233 [_resp appendContentString:@"')\""];
235 [_resp appendContentString:@" href=\""];
236 [_resp appendContentString:[_ctx componentActionURL]];
237 [_resp appendContentString:@"\" "];
239 [self appendExtraAttributesToResponse:_resp inContext:_ctx];
240 [_resp appendContentString:@" >"];
243 if (self->filename != nil) {
244 WOResourceManager *rm;
245 NSString *frameworkName;
247 rm = [[_ctx application] resourceManager];
248 languages = [_ctx resourceLookupLanguages];
249 frameworkName = (self->framework != nil)
250 ? [self->framework stringValueInComponent:comp]
251 : [comp frameworkName];
253 tmp = [rm urlForResourceNamed:[self->filename stringValueInComponent:comp]
254 inFramework:frameworkName
256 request:[_ctx request]];
258 [_resp appendContentString:@"<img border=\"0\" src=\""];
259 [_resp appendContentString:tmp];
260 [_resp appendContentString:@"\" "];
262 [_resp appendContentString:
263 (_ctx->wcFlags.xmlStyleEmptyElements ? @" />" : @">")];
266 [self->template appendToResponse:_resp inContext:_ctx];
268 if (self->string != nil)
269 [_resp appendContentString:[self->string stringValueInComponent:comp]];
272 [_resp appendContentString:@"</a>"];
275 @end /* JSModalWindow */