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/NGObjWeb.h>
23 #import <Foundation/Foundation.h>
25 # import <NGObjWeb/WEClientCapabilities.h>
27 # import <WEExtensions/WEClientCapabilities.h>
29 #import "JSMenuItem.h"
31 @implementation JSMenuItem
33 - (id)initWithName:(NSString *)_name
34 associations:(NSDictionary *)_config
35 template:(WOElement *)_subs
37 if ((self = [super initWithName:_name associations:_config template:_subs]))
39 self->action = OWGetProperty(_config,@"action");
40 self->href = OWGetProperty(_config,@"href");
41 self->string = OWGetProperty(_config,@"string");
43 self->template = [_subs retain];
49 [self->action release];
51 [self->string release];
52 [self->template release];
56 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
57 if (![[_ctx elementID] isEqualToString:[_ctx senderID]]) {
58 NSLog(@"ERROR: elementID %@ and senderID %@ do not match.",
59 [_ctx elementID], [_ctx senderID]);
62 return [self->action valueInComponent:[_ctx component]];
65 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
69 WEClientCapabilities *ccaps;
73 comp = [_ctx component];
74 ccaps = [[_ctx request] clientCapabilities];
75 ie = [ccaps isJavaScriptBrowser] && [ccaps isInternetExplorer];
76 ns = [ccaps isJavaScriptBrowser] && [ccaps isNetscape];
77 eid = [_ctx objectForKey:@"eid"];
79 NSAssert(self->action != nil || self->href != nil,
80 @"ERROR: no action or href defined...");
81 if (self->action != nil)
82 url = [_ctx componentActionURL];
83 else if (self->href != nil)
84 url = [self->href stringValueInComponent:comp];
87 tmp = [[NSString alloc] initWithFormat:
88 @"<div align=\"left\" class=\"menuItem\" url=\"%@\">"
90 url, [self->string stringValueInComponent:comp]];
94 tmp = [[NSString alloc] initWithFormat:
95 @"m%@.addMenuItem(\"%@\",\"top.window.location='%@'\");",
96 //@"m%@.addMenuItem(\"%@\",\"alert('%@')\");",
97 eid, [self->string stringValueInComponent:comp], url];
102 tmp = [[NSString alloc] initWithFormat:
103 @"<a href=\"%@\">%@</a>", url,
104 [self->string stringValueInComponent:[_ctx component]]];
108 [_response appendContentString:tmp];
112 @end /* JSMenuItem */