2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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 #include <NGObjDOM/ODNodeRenderer.h>
31 value - string in format %Y-%m-%d
34 <var:datefield value="fromDate"/><br/>
35 <var:datefield value="toDate"/><br/>
38 @interface ODR_bind_datefield : ODNodeRenderer
43 @implementation ODR_bind_datefield
45 - (BOOL)requiresFormForNode:(id)_domNode inContext:(WOContext *)_ctx {
49 - (void)takeValuesForNode:(id)_node
50 fromRequest:(WORequest *)_req
51 inContext:(WOContext *)_ctx
56 [_ctx appendElementIDComponent:@"d"];
57 d = [[_req formValueForKey:[_ctx elementID]] intValue];
58 [_ctx deleteLastElementIDComponent];
60 [_ctx appendElementIDComponent:@"m"];
61 m = [[_req formValueForKey:[_ctx elementID]] intValue];
62 [_ctx deleteLastElementIDComponent];
64 [_ctx appendElementIDComponent:@"y"];
65 y = [[_req formValueForKey:[_ctx elementID]] intValue];
66 [_ctx deleteLastElementIDComponent];
68 if (y < 100) y += 2000;
70 if ([self isSettable:@"value" node:_node ctx:_ctx]) {
71 s = [NSString stringWithFormat:@"%i-%02i-%02i", y, m, d];
72 [self setString:s for:@"value" node:_node ctx:_ctx];
75 if ([self isSettable:@"day" node:_node ctx:_ctx])
76 [self setInt:d for:@"day" node:_node ctx:_ctx];
77 if ([self isSettable:@"month" node:_node ctx:_ctx])
78 [self setInt:m for:@"month" node:_node ctx:_ctx];
79 if ([self isSettable:@"year" node:_node ctx:_ctx])
80 [self setInt:y for:@"year" node:_node ctx:_ctx];
83 - (void)appendNode:(id)_node
84 toResponse:(WOResponse *)_response
85 inContext:(WOContext *)_ctx
92 d = [self stringFor:@"day" node:_node ctx:_ctx];
93 m = [self stringFor:@"month" node:_node ctx:_ctx];
94 y = [self stringFor:@"year" node:_node ctx:_ctx];
96 date = [self valueFor:@"value" node:_node ctx:_ctx];
98 if ([date isKindOfClass:[NSCalendarDate class]]) {
99 s = [date descriptionWithCalendarFormat:@"%Y-%m-%s"];
101 d = [NSString stringWithFormat:@"%i", [date dayOfMonth]];
102 m = [NSString stringWithFormat:@"%i", [date monthOfYear]];
103 y = [NSString stringWithFormat:@"%i", [date yearOfCommonEra]];
106 s = [date stringValue];
109 if ([s length] > 0) {
113 comps = [s componentsSeparatedByString:@"-"];
114 count = [comps count];
116 if (count > 0) y = [comps objectAtIndex:0];
117 if (count > 1) m = [comps objectAtIndex:1];
118 if (count > 2) d = [comps objectAtIndex:2];
122 [_ctx appendElementIDComponent:@"d"];
124 [_response appendContentString:@"<select name=\""];
125 [_response appendContentHTMLAttributeValue:[_ctx elementID]];
126 [_response appendContentString:@"\" value=\""];
127 [_response appendContentHTMLAttributeValue:d];
128 [_response appendContentString:@"\">\n"];
130 [_response appendContentString:@"<option value=\"\">-"];
132 for (i = 1; i <= 31; i++) {
133 s = [NSString stringWithFormat:@"%d", i];
134 [_response appendContentString:@"<option value=\""];
135 [_response appendContentString:s];
136 if ((int)i == [d intValue])
137 [_response appendContentString:@"\" selected=\"selected\" />"];
139 [_response appendContentString:@"\" />"];
140 [_response appendContentString:s];
145 [_response appendContentString:@"</select>"];
147 [_ctx deleteLastElementIDComponent];
149 [_ctx appendElementIDComponent:@"m"];
151 static NSString *months[12] = {
152 @"Jan", @"Feb", @"Mar", @"Apr", @"May", @"Jun",
153 @"Jul", @"Aug", @"Sep", @"Oct", @"Nov", @"Dec"
155 [_response appendContentString:@"<select name=\""];
156 [_response appendContentHTMLAttributeValue:[_ctx elementID]];
157 [_response appendContentString:@"\" value=\""];
158 [_response appendContentHTMLAttributeValue:m];
159 [_response appendContentString:@"\">\n"];
161 [_response appendContentString:@"<option value=\"\">-"];
163 for (i = 1; i <= 12; i++) {
164 s = [NSString stringWithFormat:@"%d", i];
165 [_response appendContentString:@"<option value=\""];
166 [_response appendContentString:s];
167 if ((int)i == [m intValue])
168 [_response appendContentString:@"\" selected=\"selected\" />"];
170 [_response appendContentString:@"\" />"];
171 [_response appendContentString:months[i - 1]];
176 [_response appendContentString:@"</select>"];
178 [_ctx deleteLastElementIDComponent];
180 [_ctx appendElementIDComponent:@"y"];
182 [_response appendContentString:@"<select name=\""];
183 [_response appendContentHTMLAttributeValue:[_ctx elementID]];
184 [_response appendContentString:@"\" value=\""];
185 [_response appendContentHTMLAttributeValue:y];
186 [_response appendContentString:@"\">\n"];
188 [_response appendContentString:@"<option value=\"\">-"];
190 for (i = 2001; i <= 2010; i++) {
191 s = [NSString stringWithFormat:@"%d", i];
192 [_response appendContentString:@"<option value=\""];
193 [_response appendContentString:s];
194 if ((int)i == [y intValue])
195 [_response appendContentString:@"\" selected=\"selected\" />"];
197 [_response appendContentString:@"\" />"];
198 [_response appendContentString:s];
203 [_response appendContentString:@"</select>"];
205 [_ctx deleteLastElementIDComponent];
208 @end /* ODR_bind_datefield */