2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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 <NGObjWeb/WOComponent.h>
25 @class NSString, NSCalendarDate;
27 @interface UIxDatePicker : WOComponent
37 - (NSString *)dateFormat;
38 - (NSString *)jsDateFormat;
39 - (BOOL)useISOFormats;
44 @implementation UIxDatePicker
47 [self->dateID release];
49 [self->month release];
51 [self->label release];
57 - (void)setDateID:(NSString *)_dateID {
58 ASSIGNCOPY(self->dateID, _dateID);
60 - (NSString *)dateID {
64 - (void)setDay:(id)_day {
65 ASSIGN(self->day, _day);
70 - (void)setMonth:(id)_month {
71 ASSIGN(self->month, _month);
76 - (void)setYear:(id)_year {
77 ASSIGN(self->year, _year);
84 - (void)setLabel:(NSString *)_label {
85 ASSIGNCOPY(self->label, _label);
94 - (BOOL)useISOFormats {
96 NSNumber *useISOFormats;
99 useISOFormats = [ctx valueForKey:@"useISOFormats"];
100 if (!useISOFormats) {
101 NSArray *languages = [ctx resourceLookupLanguages];
102 if (languages && [languages count] > 0) {
103 if ([[languages objectAtIndex:0] isEqualToString:@"French"]) {
104 useISOFormats = [NSNumber numberWithBool:NO];
108 useISOFormats = [NSNumber numberWithBool:YES];
109 [ctx takeValue:useISOFormats forKey:@"useISOFormats"];
111 return [useISOFormats boolValue];
113 - (NSString *)formattedDateString {
114 if ([self useISOFormats]) {
115 return [NSString stringWithFormat:@"%d-%02d-%02d",
116 [[self year] intValue],
117 [[self month] intValue],
118 [[self day] intValue]];
121 return [NSString stringWithFormat:@"%02d/%02d/%04d",
122 [[self day] intValue],
123 [[self month] intValue],
124 [[self year] intValue]];
128 - (NSString *)dateFormat {
129 if ([self useISOFormats]) {
137 - (NSString *)jsDateFormat {
138 if ([self useISOFormats]) {
139 return @"yyyy-mm-dd";
142 return @"dd/mm/yyyy";
149 - (NSString *)calendarPageURL {
150 WOResourceManager *rm;
154 if ((rm = [self resourceManager]) == nil)
155 rm = [[WOApplication application] resourceManager];
157 [self warnWithFormat:@"missing resource manager!"];
159 ctx = [self context];
161 languages = [ctx resourceLookupLanguages];
163 #warning !! FIX SoProduct to enable localizable resource, then disable this!
167 return [rm urlForResourceNamed:@"skycalendar.html"
170 request:[ctx request]];
175 - (NSString *)jsPopup {
176 return [NSString stringWithFormat:@"javascript:calendar_%@.popup()",
180 - (NSString *)jsCode {
181 static NSString *code = \
182 @"var calendar_%@ = new skycalendar(document.getElementById('%@'));\n"
183 @"calendar_%@.setCalendarPage('%@');\n"
184 @"calendar_%@.setDateFormat('%@');\n";
186 return [NSString stringWithFormat:code,
190 [self calendarPageURL],
192 [self jsDateFormat]];
197 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
198 NSString *dateString;
201 dateString = [_rq formValueForKey:[self dateID]];
202 if (dateString == nil) {
203 [self debugWithFormat:@"got no date string!"];
207 d = [NSCalendarDate dateWithString:dateString
208 calendarFormat:[self dateFormat]];
210 [self warnWithFormat:@"Could not parse dateString: '%@'",
212 [self setDay:[NSNumber numberWithInt:[d dayOfMonth]]];
213 [self setMonth:[NSNumber numberWithInt:[d monthOfYear]]];
214 [self setYear:[NSNumber numberWithInt:[d yearOfCommonEra]]];
216 [super takeValuesFromRequest:_rq inContext:_ctx];
219 @end /* UIxDatePicker */