]> err.no Git - sope/blob - sope-appserver/WEExtensions/JSMenuItem.m
added strict OSX bundle dependencies
[sope] / sope-appserver / WEExtensions / JSMenuItem.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 #import <NGObjWeb/NGObjWeb.h>
23 #import <Foundation/Foundation.h>
24 #ifdef __APPLE__
25 #  import <NGObjWeb/WEClientCapabilities.h>
26 #else
27 #  import <WEExtensions/WEClientCapabilities.h>
28 #endif
29 #import "JSMenuItem.h"
30
31 @implementation JSMenuItem
32
33 - (id)initWithName:(NSString *)_name
34   associations:(NSDictionary *)_config
35   template:(WOElement *)_subs
36 {
37   if ((self = [super initWithName:_name associations:_config template:_subs]))
38   {
39     self->action = OWGetProperty(_config,@"action");
40     self->href   = OWGetProperty(_config,@"href");
41     self->string = OWGetProperty(_config,@"string");
42
43     self->template = [_subs retain];
44   }
45   return self;
46 }
47
48 - (void)dealloc {
49   [self->action   release];
50   [self->href     release];
51   [self->string   release];
52   [self->template release];
53   [super dealloc];
54 }
55
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]);
60     return nil;
61   }
62   return [self->action valueInComponent:[_ctx component]];
63 }
64
65 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
66   WOComponent          *comp;
67   NSString             *tmp;
68   NSString             *url = nil;
69   WEClientCapabilities *ccaps;
70   BOOL                 ie, ns;
71   NSString             *eid;
72   
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"];
78
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];
85   
86   if (ie) {
87     tmp  = [[NSString alloc] initWithFormat:
88                      @"<div align=\"left\" class=\"menuItem\" url=\"%@\">"
89                      @"%@</div>",
90                      url, [self->string stringValueInComponent:comp]];
91   }
92 #if 0
93   else if (ns)
94     tmp = [[NSString alloc] initWithFormat:
95                     @"m%@.addMenuItem(\"%@\",\"top.window.location='%@'\");",
96                     //@"m%@.addMenuItem(\"%@\",\"alert('%@')\");",
97                     eid, [self->string stringValueInComponent:comp], url];
98 #endif
99   else {
100     return;
101 #if 0
102     tmp = [[NSString alloc] initWithFormat:
103                     @"<a href=\"%@\">%@</a>", url,
104                     [self->string stringValueInComponent:[_ctx component]]];
105 #endif
106   }
107   
108   [_response appendContentString:tmp];
109   [tmp release];
110 }
111
112 @end /* JSMenuItem */