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 "WOElement+private.h"
26 @implementation WOInput
28 static BOOL takeValueDebugOn = YES;
31 return [super version] + 0 /* v2 */;
35 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
37 NSAssert2([super version] == 2,
38 @"invalid superclass (%@) version %i !",
39 NSStringFromClass([self superclass]), [super version]);
41 if ((takeValueDebugOn = [ud boolForKey:@"WODebugTakeValues"]))
42 NSLog(@"WOInput: WODebugTakeValues on.");
45 - (id)initWithName:(NSString *)_name
46 associations:(NSDictionary *)_associations
47 template:(WOElement *)_rootChild
49 self = [super initWithName:_name associations:_associations
52 self->containsForm = YES;
53 self->name = OWGetProperty(_associations, @"name");
54 self->value = OWGetProperty(_associations, @"value");
55 self->disabled = OWGetProperty(_associations, @"disabled");
57 /* type is defined by the element itself ... */
58 [(NSMutableDictionary *)_associations removeObjectForKey:@"type"];
60 if ([_associations objectForKey:@"NAME"]) {
61 NSLog(@"WARNING: found 'NAME' association in element %@, "
62 @"'name' is probably the right thing ..",
71 [self->value release];
72 [self->disabled release];
78 NSString *OWFormElementName(WOInput *self, WOContext *_ctx) {
81 if (self->name == nil)
82 return [_ctx elementID];
84 if ((name = [self->name stringValueInComponent:[_ctx component]]) != nil)
89 @"WARNING: in element %@, 'name' attribute configured (%@),"
90 @"but no name assigned (using elementID as name) !",
92 return [_ctx elementID];
95 /* taking form values */
97 - (id)parseFormValue:(id)_value inContext:(WOContext *)_ctx {
98 /* redefined in subclasses */
102 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
106 if ([self->disabled boolValueInComponent:[_ctx component]])
109 formName = OWFormElementName(self, _ctx);
110 if ((formValue = [_req formValueForKey:formName]) == nil)
111 // TODO: is this correct?
114 if (takeValueDebugOn) {
116 @"%s(%@): form=%@ ctx=%@ value=%@ ..", __PRETTY_FUNCTION__,
117 [_ctx elementID], formName, [_ctx contextID], formValue];
120 if ([self->value isValueSettable]) {
121 formValue = [self parseFormValue:formValue inContext:_ctx];
122 [self->value setStringValue:formValue inComponent:[_ctx component]];
124 else if (self->value != nil) {
126 @"%s: form value is not settable: %@", __PRETTY_FUNCTION__,
133 - (NSString *)associationDescription {
134 NSMutableString *str;
136 str = [NSMutableString stringWithCapacity:128];
137 if (self->value) [str appendFormat:@" value=%@", self->value];
138 if (self->name) [str appendFormat:@" name=%@", self->name];
139 if (self->disabled) [str appendFormat:@" disabled=%@", self->disabled];