2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #import <NGObjWeb/WODynamicElement.h>
25 @interface JSConfirmPanel : WODynamicElement
27 WOAssociation *action;
28 WOAssociation *javaScriptFunction;
29 WOAssociation *pageName;
30 WOAssociation *confirmMessage;
31 WOAssociation *altTag;
32 WOAssociation *filename;
33 WOAssociation *targetWindow;
34 WOAssociation *string;
37 WOAssociation *showPanel;
45 @implementation JSConfirmPanel
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->confirmMessage = WOExtGetProperty(_config,@"confirmMessage");
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->showPanel = WOExtGetProperty(_config,@"showPanel");
75 if (self->action) funcCount++;
76 if (self->pageName) funcCount++;
77 if (self->javaScriptFunction) funcCount++;
80 NSLog(@"WARNING: JSConfirmPanel: choose only one of "
81 @"action | pageName | javaScriptFunction");
84 NSLog(@"WARNING: JSConfirmPanel: no function declared - choose one of"
85 @"action | pageName | javaScriptFunction");
87 if (!self->confirmMessage) {
88 NSLog(@"WARNING: JSConfirmPanel: no value for 'confirmMessage'"
92 self->template = [_subs retain];
98 [self->action release];
99 [self->javaScriptFunction release];
100 [self->pageName release];
101 [self->confirmMessage release];
102 [self->altTag release];
103 [self->filename release];
104 [self->targetWindow release];
105 [self->string release];
106 [self->template release];
107 [self->showPanel release];
111 /* request processing */
113 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
114 [self->template takeValuesFromRequest:_rq inContext:_ctx];
117 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx{
121 if (self->showPanel &&
122 ![self->showPanel boolValueInComponent:[_ctx component]]) {
126 if (self->pageName) {
127 name = [self->pageName stringValueInComponent: [_ctx component]];
128 result = [[_ctx application] pageWithName:name inContext:_ctx];
130 else if (self->action) {
131 result = [self->action valueInComponent:[_ctx component]];
134 result = [self->template invokeActionForRequest:_request inContext:_ctx];
139 /* response generation */
141 - (void)_appendPanelToResponse:(WOResponse *)_response
142 message:(NSString *)_msg
143 inContext:(WOContext *)_ctx
145 if (![self->showPanel boolValueInComponent:[_ctx component]])
148 [_response appendContentString:
149 @"<script language=\"javascript\">\nvar res = confirm(\""];
150 [_response appendContentHTMLString:_msg];
151 [_response appendContentString:@"\");\n if (res) {\n"];
153 if (self->javaScriptFunction) {
156 js = [self->javaScriptFunction stringValueInComponent:[_ctx component]];
157 [_response appendContentString:js];
159 else if (self->action || self->pageName) {
160 [_response appendContentString:@"document.location.href=\""];
161 [_response appendContentString:[_ctx componentActionURL]];
162 [_response appendContentString:@"\";"];
165 [_response appendContentString:@"}"];
166 [_response appendContentString:@"</script>"];
169 - (void)_appendLinkToResponse:(WOResponse *)_response
170 message:(NSString *)_msg
171 inContext:(WOContext *)_ctx
177 comp = [_ctx component];
179 [_response appendContentString:@"<a onclick=\"javascript:return confirm('"];
180 [_response appendContentHTMLString:_msg];
181 [_response appendContentString:@"');\""];
182 [_response appendContentString:@" href=\""];
184 if (self->javaScriptFunction) {
185 [_response appendContentString:@"javascript:"];
186 [_response appendContentHTMLAttributeValue:
187 [self->javaScriptFunction stringValueInComponent:comp]];
190 [_response appendContentString:[_ctx componentActionURL]];
192 [_response appendContentString:@"\" "];
193 if (self->targetWindow) {
194 [_response appendContentString:@" target=\""];
195 [_response appendContentHTMLAttributeValue:
196 [self->targetWindow stringValueInComponent: comp]];
197 [_response appendContentString:@"\" "];
199 [self appendExtraAttributesToResponse:_response inContext:_ctx];
200 [_response appendContentString:@" >"];
203 if (self->filename) { /* image */
204 WOResourceManager *rm;
206 rm = [[_ctx application] resourceManager];
208 languages = [_ctx hasSession]
209 ? [[_ctx session] languages]
210 : [[_ctx request] browserLanguages];
212 tmp = [rm urlForResourceNamed:[self->filename stringValueInComponent:comp]
213 inFramework:[comp frameworkName]
215 request:[_ctx request]];
217 [_response appendContentString:@"<img border=\"0\" src=\""];
218 [_response appendContentString:tmp];
219 [_response appendContentString:@"\" "];
222 [_response appendContentString:@"alt=\""];
223 [_response appendContentString:
224 [self->altTag stringValueInComponent:comp]];
225 [_response appendContentString:@"\" "];
227 [_response appendContentString:@" />"];
230 [self->template appendToResponse:_response inContext:_ctx];
233 [_response appendContentString:
234 [self->string stringValueInComponent:comp]];
238 [_response appendContentString:@"</a>"];
241 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
244 msg = (self->confirmMessage)
245 ? [self->confirmMessage stringValueInComponent:[_ctx component]]
249 [self _appendPanelToResponse:_response message:msg inContext:_ctx];
251 [self _appendLinkToResponse:_response message:msg inContext:_ctx];
254 @end /* JSConfirmPanel */