]> err.no Git - sope/blob - sope-appserver/WOExtensions/JSTextFlyover.m
prepared for OSX frameworks (not finished)
[sope] / sope-appserver / WOExtensions / JSTextFlyover.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include <NGObjWeb/WODynamicElement.h>
23
24 @interface JSTextFlyover : WODynamicElement
25 {
26   WOAssociation *action;
27   WOAssociation *pageName;
28   WOAssociation *selectedColor;
29   WOAssociation *unselectedColor;
30   WOAssociation *targetWindow;
31   /* additional, not in api */
32   WOAssociation *string;
33   
34   WOElement     *template;
35 }
36
37 @end
38
39 #include "common.h"
40
41 @implementation JSTextFlyover
42
43 + (int)version {
44   return [super version] + 0 /* v2 */;
45 }
46 + (void)initialize {
47   NSAssert2([super version] == 2,
48             @"invalid superclass (%@) version %i !",
49             NSStringFromClass([self superclass]), [super version]);
50 }
51
52 - (id)initWithName:(NSString *)_name
53   associations:(NSDictionary *)_config
54   template:(WOElement *)_subs
55 {
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");
63     
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'");
74
75     self->template = [_subs retain];
76   }
77   return self;
78 }
79
80 - (void)dealloc {
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];
88   [super dealloc];
89 }
90
91 /* processing requests */
92
93 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
94   [self->template takeValuesFromRequest:_rq inContext:_ctx];
95 }
96
97 - (id)invokeActionForRequest:(WORequest *)_request
98   inContext:(WOContext *)_ctx
99 {
100   if (self->pageName) {
101     NSString *name;
102     
103     name = [self->pageName stringValueInComponent: [_ctx component]];
104     return [[_ctx application] pageWithName:name inContext:_ctx];
105   }
106   if (self->action)
107     return [self->action valueInComponent:[_ctx component]];
108
109   return [self->template invokeActionForRequest:_request inContext:_ctx];
110 }
111
112 /* generating response */
113
114 - (void)appendToResponse:(WOResponse *)_response
115   inContext:(WOContext *)_ctx
116 {
117   WOComponent *comp;
118   NSString    *tmp;
119   NSString    *userAgent;
120   NSString    *normalColor;
121   NSString    *rollColor;
122   NSString    *obj;
123   NSRange     r;
124   
125   comp        = [_ctx component];
126   userAgent   = [[_ctx request] headerForKey:@"user-agent"];
127   normalColor = [self->unselectedColor stringValueInComponent:comp];
128   rollColor   = [self->selectedColor   stringValueInComponent:comp];
129   
130   /* link containing onMouseOver, onMouseOut, STYLE and HREF */
131   r = [userAgent rangeOfString: @"MSIE"];
132   obj = (r.length == 0)
133     ? @"this.textcolor"
134     : @"this.style.color";
135   [_response appendContentString:@"<a onmouseover=\""];
136   tmp = [[NSString alloc] initWithFormat:@"%@='%@'",obj,rollColor];
137   [_response appendContentString:tmp];
138   [tmp release];
139   [_response appendContentString:@"\" onmouseout=\""];
140   tmp = [[NSString alloc] initWithFormat:@"%@='%@'",obj,normalColor];
141   [_response appendContentString:tmp];
142   [tmp release];
143
144   [_response appendContentString:@"\" style=\"color: "];
145   [_response appendContentString:normalColor];
146   [_response appendContentString:@"\" "];
147
148   [_response appendContentString:@" href=\""];
149   [_response appendContentString:[_ctx componentActionURL]];
150   [_response appendContentString:@"\" "];
151
152   if (self->targetWindow) {
153     [_response appendContentString:@" target=\""];
154     [_response appendContentHTMLAttributeValue:
155                  [self->targetWindow stringValueInComponent: comp]];
156     [_response appendContentString:@"\" "];
157   }
158   [self appendExtraAttributesToResponse:_response inContext:_ctx];
159   [_response appendContentString:@" >"];
160
161   /* text itself */
162   [self->template appendToResponse:_response inContext:_ctx];
163   if (self->string)
164     [_response appendContentString:[self->string stringValueInComponent:comp]];
165
166   /* close link */
167   [_response appendContentString:@"</a>"];
168 }
169
170 @end /* JSTextFlyover */