2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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 JSAlertPanel : WODynamicElement
27 WOAssociation *action;
28 WOAssociation *javaScriptFunction;
29 WOAssociation *pageName;
30 WOAssociation *alertMessage;
31 WOAssociation *altTag;
32 WOAssociation *filename;
33 WOAssociation *targetWindow;
34 WOAssociation *string;
43 @implementation JSAlertPanel
46 return [super version] + 0 /* v2 */;
49 NSAssert2([super version] == 2,
50 @"invalid superclass (%@) version %i !",
51 NSStringFromClass([self superclass]), [super version]);
54 - (id)initWithName:(NSString *)_name
55 associations:(NSDictionary *)_config
56 template:(WOElement *)_subs
58 if ((self = [super initWithName:_name associations:_config template:_subs]))
62 self->action = WOExtGetProperty(_config,@"action");
63 self->javaScriptFunction = WOExtGetProperty(_config,@"javaScriptFunction");
64 self->pageName = WOExtGetProperty(_config,@"pageName");
65 self->alertMessage = WOExtGetProperty(_config,@"alertMessage");
66 self->altTag = WOExtGetProperty(_config,@"altTag");
67 self->filename = WOExtGetProperty(_config,@"filename");
68 self->targetWindow = WOExtGetProperty(_config,@"targetWindow");
69 self->string = WOExtGetProperty(_config,@"string");
72 if (self->action) funcCount++;
73 if (self->pageName) funcCount++;
74 if (self->javaScriptFunction) funcCount++;
77 NSLog(@"WARNING: JSAlertPanel: choose only one of "
78 @"action | pageName | javaScriptFunction");
81 NSLog(@"WARNING: JSAlertPanel: no function declared - choose one of"
82 @"action | pageName | javaScriptFunction");
84 if (!self->alertMessage) {
85 NSLog(@"WARNING: JSAlertPanel: no value for 'alertMessage'"
89 self->template = RETAIN(_subs);
95 RELEASE(self->action);
96 RELEASE(self->javaScriptFunction);
97 RELEASE(self->pageName);
98 RELEASE(self->alertMessage);
99 RELEASE(self->altTag);
100 RELEASE(self->filename);
101 RELEASE(self->targetWindow);
102 RELEASE(self->string);
103 RELEASE(self->template);
107 /* processing requests */
109 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
110 [self->template takeValuesFromRequest:_rq inContext:_ctx];
113 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
114 if (self->pageName) {
117 name = [self->pageName stringValueInComponent: [_ctx component]];
118 return [[_ctx application] pageWithName:name inContext:_ctx];
121 return [self->action valueInComponent:[_ctx component]];
123 return [self->template invokeActionForRequest:_rq inContext:_ctx];
127 - (void)appendToResponse:(WOResponse *)_response
128 inContext:(WOContext *)_ctx
134 comp = [_ctx component];
137 [_response appendContentString:@"<a onClick=\"javascript:alert('"];
138 tmp = (self->alertMessage)
139 ? [self->alertMessage stringValueInComponent: comp]
141 [_response appendContentHTMLString:tmp];
142 [_response appendContentString:@"');\""];
143 [_response appendContentString:@" href=\""];
145 if (self->javaScriptFunction) {
146 [_response appendContentString:@"javascript:"];
147 [_response appendContentHTMLAttributeValue:
148 [self->javaScriptFunction stringValueInComponent:comp]];
151 [_response appendContentString:[_ctx componentActionURL]];
153 [_response appendContentString:@"\" "];
154 if (self->targetWindow) {
155 [_response appendContentString:@" target=\""];
156 [_response appendContentHTMLAttributeValue:
157 [self->targetWindow stringValueInComponent: comp]];
158 [_response appendContentString:@"\" "];
160 [self appendExtraAttributesToResponse:_response inContext:_ctx];
161 [_response appendContentString:@" >"];
164 if (self->filename) {
165 WOResourceManager *rm;
167 rm = [[_ctx application] resourceManager];
169 languages = [_ctx hasSession]
170 ? [[_ctx session] languages]
171 : [[_ctx request] browserLanguages];
173 tmp = [rm urlForResourceNamed:[self->filename stringValueInComponent:comp]
174 inFramework:[comp frameworkName]
176 request:[_ctx request]];
178 [_response appendContentString:@"<img border=\"0\" src=\""];
179 [_response appendContentString:tmp];
180 [_response appendContentString:@"\""];
183 [_response appendContentString:@" alt=\""];
184 [_response appendContentString:
185 [self->altTag stringValueInComponent:comp]];
186 [_response appendContentString:@"\" "];
188 [_response appendContentString:@" />"];
190 [self->template appendToResponse:_response inContext:_ctx];
192 [_response appendContentString:[self->string stringValueInComponent:comp]];
195 [_response appendContentString:@"</a>"];
198 @end /* JSAlertPanel */