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 #include <NGObjWeb/WODynamicElement.h>
24 @interface JSTextFlyover : WODynamicElement
26 WOAssociation *action;
27 WOAssociation *pageName;
28 WOAssociation *selectedColor;
29 WOAssociation *unselectedColor;
30 WOAssociation *targetWindow;
31 /* additional, not in api */
32 WOAssociation *string;
41 @implementation JSTextFlyover
44 return [super version] + 0 /* v2 */;
47 NSAssert2([super version] == 2,
48 @"invalid superclass (%@) version %i !",
49 NSStringFromClass([self superclass]), [super version]);
52 - (id)initWithName:(NSString *)_name
53 associations:(NSDictionary *)_config
54 template:(WOElement *)_subs
56 if ((self = [super initWithName:_name associations:_config template:_subs])){
57 self->action = WOExtGetProperty(_config,@"action");
58 self->pageName = WOExtGetProperty(_config,@"pageName");
59 self->selectedColor = WOExtGetProperty(_config,@"selectedColor");
60 self->unselectedColor = WOExtGetProperty(_config,@"unselectedColor");
61 self->targetWindow = WOExtGetProperty(_config,@"targetWindow");
62 self->string = WOExtGetProperty(_config,@"string");
64 if ((self->action) && (self->pageName))
65 NSLog(@"WARNING: JSTextFlyover: choose only one of "
66 @"action | pageName ");
67 if (!((self->action) || (self->pageName)))
68 NSLog(@"WARNING: JSTextFlyover: no function declared - choose one of"
69 @"action | pageName | javaScriptFunction");
70 if (!self->selectedColor)
71 NSLog(@"WARNING: JSTextFlyover: no value for 'selectedColor'");
72 if (!self->unselectedColor)
73 NSLog(@"WARNING: JSTextFlyover: no value for 'unselectedColor'");
75 self->template = [_subs retain];
81 [self->action release];
82 [self->pageName release];
83 [self->selectedColor release];
84 [self->unselectedColor release];
85 [self->targetWindow release];
86 [self->string release];
87 [self->template release];
91 /* processing requests */
93 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
94 [self->template takeValuesFromRequest:_rq inContext:_ctx];
97 - (id)invokeActionForRequest:(WORequest *)_request
98 inContext:(WOContext *)_ctx
100 if (self->pageName) {
103 name = [self->pageName stringValueInComponent: [_ctx component]];
104 return [[_ctx application] pageWithName:name inContext:_ctx];
107 return [self->action valueInComponent:[_ctx component]];
109 return [self->template invokeActionForRequest:_request inContext:_ctx];
112 /* generating response */
114 - (void)appendToResponse:(WOResponse *)_response
115 inContext:(WOContext *)_ctx
120 NSString *normalColor;
125 comp = [_ctx component];
126 userAgent = [[_ctx request] headerForKey:@"user-agent"];
127 normalColor = [self->unselectedColor stringValueInComponent:comp];
128 rollColor = [self->selectedColor stringValueInComponent:comp];
130 /* link containing onMouseOver, onMouseOut, STYLE and HREF */
131 r = [userAgent rangeOfString: @"MSIE"];
132 obj = (r.length == 0)
134 : @"this.style.color";
135 [_response appendContentString:@"<a onmouseover=\""];
136 tmp = [[NSString alloc] initWithFormat:@"%@='%@'",obj,rollColor];
137 [_response appendContentString:tmp];
139 [_response appendContentString:@"\" onmouseout=\""];
140 tmp = [[NSString alloc] initWithFormat:@"%@='%@'",obj,normalColor];
141 [_response appendContentString:tmp];
144 [_response appendContentString:@"\" style=\"color: "];
145 [_response appendContentString:normalColor];
146 [_response appendContentString:@"\" "];
148 [_response appendContentString:@" href=\""];
149 [_response appendContentString:[_ctx componentActionURL]];
150 [_response appendContentString:@"\" "];
152 if (self->targetWindow) {
153 [_response appendContentString:@" target=\""];
154 [_response appendContentHTMLAttributeValue:
155 [self->targetWindow stringValueInComponent: comp]];
156 [_response appendContentString:@"\" "];
158 [self appendExtraAttributesToResponse:_response inContext:_ctx];
159 [_response appendContentString:@" >"];
162 [self->template appendToResponse:_response inContext:_ctx];
164 [_response appendContentString:[self->string stringValueInComponent:comp]];
167 [_response appendContentString:@"</a>"];
170 @end /* JSTextFlyover */