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
23 #include <NGObjWeb/WOApplication.h>
26 @interface WOSubmitButton : WOInput
32 WOAssociation *action;
33 WOAssociation *pageName;
36 WOAssociation *queryDictionary;
37 NSDictionary *queryParameters; // associations beginning with ?
38 WOAssociation *actionClass;
39 WOAssociation *directActionName;
43 @end /* WOSubmitButton */
45 @implementation WOSubmitButton
51 - (id)initWithName:(NSString *)_name
52 associations:(NSDictionary *)_config
53 template:(WOElement *)_t
55 if ((self = [super initWithName:_name associations:_config template:_t])) {
56 WOAssociation *sidInUrlAssoc;
58 sidInUrlAssoc = OWGetProperty(_config, @"?wosid");
59 self->action = OWGetProperty(_config, @"action");
60 self->pageName = OWGetProperty(_config, @"pageName");
62 self->queryDictionary = OWGetProperty(_config, @"queryDictionary");
63 self->queryParameters = OWExtractQueryParameters(_config);
64 self->actionClass = OWGetProperty(_config, @"actionClass");
65 self->directActionName = OWGetProperty(_config, @"directActionName");
67 self->sidInUrl = (sidInUrlAssoc)
68 ? [sidInUrlAssoc boolValueInComponent:nil]
74 #if !LIB_FOUNDATION_BOEHM_GC
76 RELEASE(self->actionClass);
77 RELEASE(self->directActionName);
78 RELEASE(self->queryDictionary);
79 RELEASE(self->queryParameters);
80 RELEASE(self->action);
81 RELEASE(self->pageName);
88 - (void)takeValuesFromRequest:(WORequest *)_request
89 inContext:(WOContext *)_ctx
94 if ([self->disabled boolValueInComponent:[_ctx component]])
98 if ((formValue = [_request formValueForKey:OWFormElementName(self, _ctx)])) {
99 //NSLog(@"%@: value=%@ ..", [self elementID], formValue);
101 if ([self->value isValueSettable]) {
102 [self->value setStringValue:formValue
103 inComponent:[_ctx component]];
105 if ((self->action != nil) || (self->pageName != nil))
106 [_ctx addActiveFormElement:self];
110 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
111 if (self->disabled) {
112 if ([self->disabled boolValueInComponent:[_ctx component]])
116 /* check whether this is the active form element (determined in take-values) */
117 if (![[_ctx elementID] isEqualToString:[_ctx senderID]]) {
118 NSLog(@"SUBMITBUTTON is not active (%@ vs %@) !",
119 [_ctx elementID], [_ctx senderID]);
124 return [self executeAction:self->action inContext:_ctx];
126 if (self->pageName) {
127 NSString *pname = nil;
128 WOComponent *page = nil;
130 pname = [self->pageName stringValueInComponent:[_ctx component]];
131 page = [[_ctx application] pageWithName:pname inContext:_ctx];
134 [[_ctx session] logWithFormat:
135 @"%@[0x%08X]: did not find page with name %@ !",
136 NSStringFromClass([self class]), self, pname];
138 NSLog(@"%@: showing page %@", self, page);
145 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
146 NSString *v = [self->value stringValueInComponent:[_ctx component]];
148 WOResponse_AddCString(_response, "<input type=\"submit\" name=\"");
149 [_response appendContentHTMLAttributeValue:OWFormElementName(self, _ctx)];
150 WOResponse_AddCString(_response, "\" value=\"");
151 [_response appendContentHTMLAttributeValue:v];
152 WOResponse_AddChar(_response, '"');
153 [self appendExtraAttributesToResponse:_response inContext:_ctx];
154 if (self->otherTagString) {
155 WOResponse_AddChar(_response, ' ');
156 WOResponse_AddString(_response,
157 [self->otherTagString stringValueInComponent:
160 WOResponse_AddCString(_response, " />");
165 - (NSString *)associationDescription {
166 NSMutableString *str = [NSMutableString stringWithCapacity:128];
167 [str appendString:[super associationDescription]];
168 if (self->action) [str appendFormat:@" action=%@", self->action];
169 if (self->pageName) [str appendFormat:@" page=%@", self->pageName];
171 if (self->actionClass)
172 [str appendFormat:@" actionClass=%@", self->actionClass];
173 if (self->directActionName)
174 [str appendFormat:@" directAction=%@", self->directActionName];
178 @end /* WOSubmitButton */