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/NGObjWeb.h>
24 #import <Foundation/Foundation.h>
26 # import <NGObjWeb/WEClientCapabilities.h>
28 # import <WEExtensions/WEClientCapabilities.h>
30 #import "JSMenuItem.h"
32 @implementation JSMenuItem
34 - (id)initWithName:(NSString *)_name
35 associations:(NSDictionary *)_config
36 template:(WOElement *)_subs
38 if ((self = [super initWithName:_name associations:_config template:_subs]))
40 self->action = OWGetProperty(_config,@"action");
41 self->href = OWGetProperty(_config,@"href");
42 self->string = OWGetProperty(_config,@"string");
44 self->template = [_subs retain];
50 [self->action release];
52 [self->string release];
53 [self->template release];
57 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
58 if (![[_ctx elementID] isEqualToString:[_ctx senderID]]) {
59 NSLog(@"ERROR: elementID %@ and senderID %@ do not match.",
60 [_ctx elementID], [_ctx senderID]);
63 return [self->action valueInComponent:[_ctx component]];
66 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
70 WEClientCapabilities *ccaps;
74 comp = [_ctx component];
75 ccaps = [[_ctx request] clientCapabilities];
76 ie = [ccaps isJavaScriptBrowser] && [ccaps isInternetExplorer];
77 ns = [ccaps isJavaScriptBrowser] && [ccaps isNetscape];
78 eid = [_ctx objectForKey:@"eid"];
80 NSAssert(self->action != nil || self->href != nil,
81 @"ERROR: no action or href defined...");
82 if (self->action != nil)
83 url = [_ctx componentActionURL];
84 else if (self->href != nil)
85 url = [self->href stringValueInComponent:comp];
88 tmp = [[NSString alloc] initWithFormat:
89 @"<div align=\"left\" class=\"menuItem\" url=\"%@\">"
91 url, [self->string stringValueInComponent:comp]];
95 tmp = [[NSString alloc] initWithFormat:
96 @"m%@.addMenuItem(\"%@\",\"top.window.location='%@'\");",
97 //@"m%@.addMenuItem(\"%@\",\"alert('%@')\");",
98 eid, [self->string stringValueInComponent:comp], url];
103 tmp = [[NSString alloc] initWithFormat:
104 @"<a href=\"%@\">%@</a>", url,
105 [self->string stringValueInComponent:[_ctx component]]];
109 [_response appendContentString:tmp];
113 @end /* JSMenuItem */