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 #import <NGObjWeb/WODynamicElement.h>
24 @interface JSConfirmPanel : WODynamicElement
26 WOAssociation *action;
27 WOAssociation *javaScriptFunction;
28 WOAssociation *pageName;
29 WOAssociation *confirmMessage;
30 WOAssociation *altTag;
31 WOAssociation *filename;
32 WOAssociation *targetWindow;
33 WOAssociation *string;
36 WOAssociation *showPanel;
38 WOAssociation *escapeJS;
39 WOAssociation *framework;
46 @implementation JSConfirmPanel
49 return [super version] + 0 /* v2 */;
52 NSAssert2([super version] == 2,
53 @"invalid superclass (%@) version %i !",
54 NSStringFromClass([self superclass]), [super version]);
57 - (id)initWithName:(NSString *)_name
58 associations:(NSDictionary *)_config
59 template:(WOElement *)_subs
61 if ((self = [super initWithName:_name associations:_config template:_subs]))
65 self->action = WOExtGetProperty(_config,@"action");
66 self->javaScriptFunction = WOExtGetProperty(_config,@"javaScriptFunction");
67 self->pageName = WOExtGetProperty(_config,@"pageName");
68 self->confirmMessage = WOExtGetProperty(_config,@"confirmMessage");
69 self->altTag = WOExtGetProperty(_config,@"altTag");
70 self->filename = WOExtGetProperty(_config,@"filename");
71 self->targetWindow = WOExtGetProperty(_config,@"targetWindow");
72 self->string = WOExtGetProperty(_config,@"string");
73 self->showPanel = WOExtGetProperty(_config,@"showPanel");
74 self->escapeJS = WOExtGetProperty(_config,@"escapeJS");
75 self->framework = WOExtGetProperty(_config,@"framework");
78 if (self->action) funcCount++;
79 if (self->pageName) funcCount++;
80 if (self->javaScriptFunction) funcCount++;
83 NSLog(@"WARNING: JSConfirmPanel: choose only one of "
84 @"action | pageName | javaScriptFunction");
87 NSLog(@"WARNING: JSConfirmPanel: no function declared - choose one of"
88 @"action | pageName | javaScriptFunction");
90 if (!self->confirmMessage) {
91 NSLog(@"WARNING: JSConfirmPanel: no value for 'confirmMessage'"
95 self->template = [_subs retain];
101 [self->action release];
102 [self->javaScriptFunction release];
103 [self->pageName release];
104 [self->confirmMessage release];
105 [self->altTag release];
106 [self->filename release];
107 [self->targetWindow release];
108 [self->string release];
109 [self->template release];
110 [self->showPanel release];
111 [self->escapeJS release];
112 [self->framework release];
116 /* request processing */
118 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
119 [self->template takeValuesFromRequest:_rq inContext:_ctx];
122 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx{
126 if (self->showPanel &&
127 ![self->showPanel boolValueInComponent:[_ctx component]]) {
131 if (self->pageName != nil) {
132 name = [self->pageName stringValueInComponent: [_ctx component]];
133 result = [[_ctx application] pageWithName:name inContext:_ctx];
135 else if (self->action != nil) {
136 result = [self->action valueInComponent:[_ctx component]];
139 result = [self->template invokeActionForRequest:_request inContext:_ctx];
144 /* response generation */
146 - (void)_appendPanelToResponse:(WOResponse *)_response
147 message:(NSString *)_msg
148 inContext:(WOContext *)_ctx
150 if (![self->showPanel boolValueInComponent:[_ctx component]])
153 [_response appendContentString:
154 @"<script type=\"text/javascript\">\nvar res = confirm(\""];
155 [_response appendContentHTMLString:_msg];
156 [_response appendContentString:@"\");\n if (res) {\n"];
158 if (self->javaScriptFunction) {
161 js = [self->javaScriptFunction stringValueInComponent:[_ctx component]];
162 [_response appendContentString:js];
164 else if (self->action || self->pageName) {
165 [_response appendContentString:@"document.location.href=\""];
166 [_response appendContentString:[_ctx componentActionURL]];
167 [_response appendContentString:@"\";"];
170 [_response appendContentString:@"}"];
171 [_response appendContentString:@"</script>"];
174 - (void)_appendLinkToResponse:(WOResponse *)_response
175 message:(NSString *)_msg
176 inContext:(WOContext *)_ctx
182 comp = [_ctx component];
184 [_response appendContentString:@"<a onclick=\"javascript:return confirm('"];
185 [_response appendContentHTMLString:_msg];
186 [_response appendContentString:@"');\""];
187 [_response appendContentString:@" href=\""];
189 if (self->javaScriptFunction) {
190 [_response appendContentString:@"javascript:"];
191 [_response appendContentHTMLAttributeValue:
192 [self->javaScriptFunction stringValueInComponent:comp]];
195 [_response appendContentString:[_ctx componentActionURL]];
197 [_response appendContentString:@"\" "];
198 if (self->targetWindow) {
199 [_response appendContentString:@" target=\""];
200 [_response appendContentHTMLAttributeValue:
201 [self->targetWindow stringValueInComponent: comp]];
202 [_response appendContentString:@"\" "];
204 [self appendExtraAttributesToResponse:_response inContext:_ctx];
205 [_response appendContentString:@" >"];
208 if (self->filename != nil) { /* image */
209 WOResourceManager *rm;
210 NSString *frameworkName;
212 frameworkName = (self->framework != nil)
213 ? [self->framework stringValueInComponent:comp]
214 : [comp frameworkName];
216 rm = [[_ctx application] resourceManager];
217 languages = [_ctx resourceLookupLanguages];
219 tmp = [rm urlForResourceNamed:[self->filename stringValueInComponent:comp]
220 inFramework:frameworkName
222 request:[_ctx request]];
224 [_response appendContentString:@"<img border=\"0\" src=\""];
225 [_response appendContentString:tmp];
226 [_response appendContentString:@"\" "];
228 if (self->altTag != nil) {
229 [_response appendContentString:@"alt=\""];
230 [_response appendContentString:
231 [self->altTag stringValueInComponent:comp]];
232 [_response appendContentString:@"\" "];
235 [_response appendContentString:
236 (_ctx->wcFlags.xmlStyleEmptyElements ? @" />" : @">")];
239 [self->template appendToResponse:_response inContext:_ctx];
241 if (self->string != nil) {
242 [_response appendContentString:
243 [self->string stringValueInComponent:comp]];
247 [_response appendContentString:@"</a>"];
250 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
254 comp = [_ctx component];
255 msg = (self->confirmMessage)
256 ? [self->confirmMessage stringValueInComponent:comp]
258 if (self->escapeJS != nil && [self->escapeJS boolValueInComponent:comp]) {
259 msg = [msg stringByApplyingJavaScriptEscaping];
263 [self _appendPanelToResponse:_response message:msg inContext:_ctx];
265 [self _appendLinkToResponse:_response message:msg inContext:_ctx];
268 @end /* JSConfirmPanel */