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;
42 @implementation JSAlertPanel
45 return [super version] + 0 /* v2 */;
48 NSAssert2([super version] == 2,
49 @"invalid superclass (%@) version %i !",
50 NSStringFromClass([self superclass]), [super version]);
53 - (id)initWithName:(NSString *)_name
54 associations:(NSDictionary *)_config
55 template:(WOElement *)_subs
57 if ((self = [super initWithName:_name associations:_config template:_subs]))
61 self->action = WOExtGetProperty(_config,@"action");
62 self->javaScriptFunction = WOExtGetProperty(_config,@"javaScriptFunction");
63 self->pageName = WOExtGetProperty(_config,@"pageName");
64 self->alertMessage = WOExtGetProperty(_config,@"alertMessage");
65 self->altTag = WOExtGetProperty(_config,@"altTag");
66 self->filename = WOExtGetProperty(_config,@"filename");
67 self->targetWindow = WOExtGetProperty(_config,@"targetWindow");
68 self->string = WOExtGetProperty(_config,@"string");
71 if (self->action) funcCount++;
72 if (self->pageName) funcCount++;
73 if (self->javaScriptFunction) funcCount++;
76 NSLog(@"WARNING: JSAlertPanel: choose only one of "
77 @"action | pageName | javaScriptFunction");
80 NSLog(@"WARNING: JSAlertPanel: no function declared - choose one of"
81 @"action | pageName | javaScriptFunction");
83 if (!self->alertMessage) {
84 NSLog(@"WARNING: JSAlertPanel: no value for 'alertMessage'"
88 self->template = RETAIN(_subs);
94 RELEASE(self->action);
95 RELEASE(self->javaScriptFunction);
96 RELEASE(self->pageName);
97 RELEASE(self->alertMessage);
98 RELEASE(self->altTag);
99 RELEASE(self->filename);
100 RELEASE(self->targetWindow);
101 RELEASE(self->string);
102 RELEASE(self->template);
106 /* processing requests */
108 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
109 [self->template takeValuesFromRequest:_rq inContext:_ctx];
112 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
113 if (self->pageName) {
116 name = [self->pageName stringValueInComponent: [_ctx component]];
117 return [[_ctx application] pageWithName:name inContext:_ctx];
120 return [self->action valueInComponent:[_ctx component]];
122 return [self->template invokeActionForRequest:_rq inContext:_ctx];
126 - (void)appendToResponse:(WOResponse *)_response
127 inContext:(WOContext *)_ctx
133 comp = [_ctx component];
136 [_response appendContentString:@"<a onClick=\"javascript:alert('"];
137 tmp = (self->alertMessage)
138 ? [self->alertMessage stringValueInComponent: comp]
140 [_response appendContentHTMLString:tmp];
141 [_response appendContentString:@"');\""];
142 [_response appendContentString:@" href=\""];
144 if (self->javaScriptFunction) {
145 [_response appendContentString:@"javascript:"];
146 [_response appendContentHTMLAttributeValue:
147 [self->javaScriptFunction stringValueInComponent:comp]];
150 [_response appendContentString:[_ctx componentActionURL]];
152 [_response appendContentString:@"\" "];
153 if (self->targetWindow) {
154 [_response appendContentString:@" target=\""];
155 [_response appendContentHTMLAttributeValue:
156 [self->targetWindow stringValueInComponent: comp]];
157 [_response appendContentString:@"\" "];
159 [self appendExtraAttributesToResponse:_response inContext:_ctx];
160 [_response appendContentString:@" >"];
163 if (self->filename) {
164 WOResourceManager *rm;
166 rm = [[_ctx application] resourceManager];
168 languages = [_ctx hasSession]
169 ? [[_ctx session] languages]
170 : [[_ctx request] browserLanguages];
172 tmp = [rm urlForResourceNamed:[self->filename stringValueInComponent:comp]
173 inFramework:[comp frameworkName]
175 request:[_ctx request]];
177 [_response appendContentString:@"<img border=\"0\" src=\""];
178 [_response appendContentString:tmp];
179 [_response appendContentString:@"\""];
182 [_response appendContentString:@" alt=\""];
183 [_response appendContentString:
184 [self->altTag stringValueInComponent:comp]];
185 [_response appendContentString:@"\" "];
187 [_response appendContentString:@" />"];
189 [self->template appendToResponse:_response inContext:_ctx];
191 [_response appendContentString:[self->string stringValueInComponent:comp]];
194 [_response appendContentString:@"</a>"];
197 @end /* JSAlertPanel */