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 JSAlertPanel : WODynamicElement
26 WOAssociation *action;
27 WOAssociation *javaScriptFunction;
28 WOAssociation *pageName;
29 WOAssociation *alertMessage;
30 WOAssociation *altTag;
31 WOAssociation *filename;
32 WOAssociation *targetWindow;
33 WOAssociation *string;
37 WOAssociation *escapeJS;
38 WOAssociation *framework;
45 @implementation JSAlertPanel
48 return [super version] + 0 /* v2 */;
51 NSAssert2([super version] == 2,
52 @"invalid superclass (%@) version %i !",
53 NSStringFromClass([self superclass]), [super version]);
56 - (id)initWithName:(NSString *)_name
57 associations:(NSDictionary *)_config
58 template:(WOElement *)_subs
60 if ((self = [super initWithName:_name associations:_config template:_subs]))
64 self->action = WOExtGetProperty(_config,@"action");
65 self->javaScriptFunction = WOExtGetProperty(_config,@"javaScriptFunction");
66 self->pageName = WOExtGetProperty(_config,@"pageName");
67 self->alertMessage = WOExtGetProperty(_config,@"alertMessage");
68 self->altTag = WOExtGetProperty(_config,@"altTag");
69 self->filename = WOExtGetProperty(_config,@"filename");
70 self->targetWindow = WOExtGetProperty(_config,@"targetWindow");
71 self->string = WOExtGetProperty(_config,@"string");
72 self->escapeJS = WOExtGetProperty(_config,@"escapeJS");
73 self->framework = WOExtGetProperty(_config,@"framework");
76 if (self->action) funcCount++;
77 if (self->pageName) funcCount++;
78 if (self->javaScriptFunction) funcCount++;
81 NSLog(@"WARNING: JSAlertPanel: choose only one of "
82 @"action | pageName | javaScriptFunction");
85 NSLog(@"WARNING: JSAlertPanel: no function declared - choose one of"
86 @"action | pageName | javaScriptFunction");
88 if (!self->alertMessage) {
89 NSLog(@"WARNING: JSAlertPanel: no value for 'alertMessage'"
93 self->template = RETAIN(_subs);
99 RELEASE(self->action);
100 RELEASE(self->javaScriptFunction);
101 RELEASE(self->pageName);
102 RELEASE(self->alertMessage);
103 RELEASE(self->altTag);
104 RELEASE(self->filename);
105 RELEASE(self->targetWindow);
106 RELEASE(self->string);
107 RELEASE(self->template);
108 RELEASE(self->escapeJS);
109 RELEASE(self->framework);
113 /* processing requests */
115 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
116 [self->template takeValuesFromRequest:_rq inContext:_ctx];
119 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
120 if (self->pageName) {
123 name = [self->pageName stringValueInComponent: [_ctx component]];
124 return [[_ctx application] pageWithName:name inContext:_ctx];
127 return [self->action valueInComponent:[_ctx component]];
129 return [self->template invokeActionForRequest:_rq inContext:_ctx];
133 - (void)appendToResponse:(WOResponse *)_response
134 inContext:(WOContext *)_ctx
140 if ([_ctx isRenderingDisabled]) {
141 [self->template appendToResponse:_response inContext:_ctx];
145 comp = [_ctx component];
148 [_response appendContentString:@"<a onclick=\"javascript:alert('"];
149 tmp = (self->alertMessage)
150 ? [self->alertMessage stringValueInComponent: comp]
151 : (NSString *)@"Press OK.";
152 if (self->escapeJS != nil && [self->escapeJS boolValueInComponent: comp]) {
153 tmp = [tmp stringByApplyingJavaScriptEscaping];
155 [_response appendContentHTMLString:tmp];
156 [_response appendContentString:@"');\""];
157 [_response appendContentString:@" href=\""];
159 if (self->javaScriptFunction) {
160 [_response appendContentString:@"javascript:"];
161 [_response appendContentHTMLAttributeValue:
162 [self->javaScriptFunction stringValueInComponent:comp]];
165 [_response appendContentString:[_ctx componentActionURL]];
167 [_response appendContentString:@"\" "];
168 if (self->targetWindow) {
169 [_response appendContentString:@" target=\""];
170 [_response appendContentHTMLAttributeValue:
171 [self->targetWindow stringValueInComponent: comp]];
172 [_response appendContentString:@"\" "];
174 [self appendExtraAttributesToResponse:_response inContext:_ctx];
175 [_response appendContentString:@" >"];
178 if (self->filename != nil) {
179 WOResourceManager *rm;
180 NSString *frameworkName;
182 frameworkName = (self->framework != nil)
183 ? [self->framework stringValueInComponent:comp]
184 : [comp frameworkName];
186 rm = [[_ctx application] resourceManager];
187 languages = [_ctx resourceLookupLanguages];
189 tmp = [rm urlForResourceNamed:[self->filename stringValueInComponent:comp]
190 inFramework:frameworkName
192 request:[_ctx request]];
194 [_response appendContentString:@"<img border=\"0\" src=\""];
195 [_response appendContentString:tmp];
196 [_response appendContentString:@"\""];
198 if (self->altTag != nil) {
199 [_response appendContentString:@" alt=\""];
200 [_response appendContentString:
201 [self->altTag stringValueInComponent:comp]];
202 [_response appendContentString:@"\" "];
205 [_response appendContentString:
206 (_ctx->wcFlags.xmlStyleEmptyElements ? @" />" : @">")];
209 [self->template appendToResponse:_response inContext:_ctx];
211 if (self->string != nil)
212 [_response appendContentString:[self->string stringValueInComponent:comp]];
215 [_response appendContentString:@"</a>"];
218 @end /* JSAlertPanel */