]> err.no Git - sope/blob - sope-appserver/WEExtensions/JSMenuItem.m
added svn:keywords and svn:ignore where appropriate. removed CVS artifacts.
[sope] / sope-appserver / WEExtensions / JSMenuItem.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #import <NGObjWeb/NGObjWeb.h>
24 #import <Foundation/Foundation.h>
25 #ifdef __APPLE__
26 #  import <NGObjWeb/WEClientCapabilities.h>
27 #else
28 #  import <WEExtensions/WEClientCapabilities.h>
29 #endif
30 #import "JSMenuItem.h"
31
32 @implementation JSMenuItem
33
34 - (id)initWithName:(NSString *)_name
35   associations:(NSDictionary *)_config
36   template:(WOElement *)_subs
37 {
38   if ((self = [super initWithName:_name associations:_config template:_subs]))
39   {
40     self->action = OWGetProperty(_config,@"action");
41     self->href   = OWGetProperty(_config,@"href");
42     self->string = OWGetProperty(_config,@"string");
43
44     self->template = [_subs retain];
45   }
46   return self;
47 }
48
49 - (void)dealloc {
50   [self->action   release];
51   [self->href     release];
52   [self->string   release];
53   [self->template release];
54   [super dealloc];
55 }
56
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]);
61     return nil;
62   }
63   return [self->action valueInComponent:[_ctx component]];
64 }
65
66 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
67   WOComponent          *comp;
68   NSString             *tmp;
69   NSString             *url = nil;
70   WEClientCapabilities *ccaps;
71   BOOL                 ie, ns;
72   NSString             *eid;
73   
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"];
79
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];
86   
87   if (ie) {
88     tmp  = [[NSString alloc] initWithFormat:
89                      @"<div align=\"left\" class=\"menuItem\" url=\"%@\">"
90                      @"%@</div>",
91                      url, [self->string stringValueInComponent:comp]];
92   }
93 #if 0
94   else if (ns)
95     tmp = [[NSString alloc] initWithFormat:
96                     @"m%@.addMenuItem(\"%@\",\"top.window.location='%@'\");",
97                     //@"m%@.addMenuItem(\"%@\",\"alert('%@')\");",
98                     eid, [self->string stringValueInComponent:comp], url];
99 #endif
100   else {
101     return;
102 #if 0
103     tmp = [[NSString alloc] initWithFormat:
104                     @"<a href=\"%@\">%@</a>", url,
105                     [self->string stringValueInComponent:[_ctx component]]];
106 #endif
107   }
108   
109   [_response appendContentString:tmp];
110   [tmp release];
111 }
112
113 @end /* JSMenuItem */