2 Copyright (C) 2004-2005 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
22 #include <NGObjWeb/WOComponent.h>
26 @interface UIxDatePicker : WOComponent
36 - (NSString *)dateFormat;
37 - (NSString *)jsDateFormat;
38 - (BOOL)useISOFormats;
43 @implementation UIxDatePicker
46 [self->dateID release];
48 [self->month release];
50 [self->label release];
56 - (void)setDateID:(NSString *)_dateID {
57 ASSIGNCOPY(self->dateID, _dateID);
59 - (NSString *)dateID {
63 - (void)setDay:(id)_day {
64 ASSIGN(self->day, _day);
69 - (void)setMonth:(id)_month {
70 ASSIGN(self->month, _month);
75 - (void)setYear:(id)_year {
76 ASSIGN(self->year, _year);
83 - (void)setLabel:(NSString *)_label {
84 ASSIGNCOPY(self->label, _label);
93 - (BOOL)useISOFormats {
95 NSNumber *useISOFormats;
98 useISOFormats = [ctx valueForKey:@"useISOFormats"];
100 NSArray *languages = [ctx resourceLookupLanguages];
101 if (languages && [languages count] > 0) {
102 if ([[languages objectAtIndex:0] isEqualToString:@"French"]) {
103 useISOFormats = [NSNumber numberWithBool:NO];
107 useISOFormats = [NSNumber numberWithBool:YES];
108 [ctx takeValue:useISOFormats forKey:@"useISOFormats"];
110 return [useISOFormats boolValue];
112 - (NSString *)formattedDateString {
115 if ([self useISOFormats]) {
116 sprintf(buf, "%04d-%02d-%02d",
117 [[self year] intValue],
118 [[self month] intValue],
119 [[self day] intValue]);
122 sprintf(buf, "%02d/%02d/%04d",
123 [[self day] intValue],
124 [[self month] intValue],
125 [[self year] intValue]);
127 return [NSString stringWithCString:buf];
130 - (NSString *)dateFormat {
131 return [self useISOFormats] ? @"%Y-%m-%d" : @"%d/%m/%Y";
134 - (NSString *)jsDateFormat {
135 return [self useISOFormats] ? @"yyyy-mm-dd" : @"dd/mm/yyyy";
141 - (NSString *)calendarPageURL {
142 WOResourceManager *rm;
146 if ((rm = [self resourceManager]) == nil)
147 rm = [[WOApplication application] resourceManager];
149 [self warnWithFormat:@"missing resource manager!"];
151 ctx = [self context];
153 languages = [ctx resourceLookupLanguages];
155 #warning !! FIX SoProduct to enable localizable resource, then disable this!
159 return [rm urlForResourceNamed:@"skycalendar.html" inFramework:nil
160 languages:languages request:[ctx request]];
165 - (NSString *)jsPopup {
166 return [NSString stringWithFormat:@"javascript:calendar_%@.popup()",
170 - (NSString *)jsCode {
171 static NSString *code = \
172 @"var calendar_%@ = new skycalendar(document.getElementById('%@'));\n"
173 @"calendar_%@.setCalendarPage('%@');\n"
174 @"calendar_%@.setDateFormat('%@');\n";
176 return [NSString stringWithFormat:code,
180 [self calendarPageURL],
182 [self jsDateFormat]];
187 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
188 NSString *dateString;
191 dateString = [_rq formValueForKey:[self dateID]];
192 if (dateString == nil) {
193 [self debugWithFormat:@"got no date string!"];
197 d = [NSCalendarDate dateWithString:dateString
198 calendarFormat:[self dateFormat]];
200 [self warnWithFormat:@"Could not parse dateString: '%@'",
203 [self setDay: [NSNumber numberWithInt:[d dayOfMonth]]];
204 [self setMonth:[NSNumber numberWithInt:[d monthOfYear]]];
205 [self setYear: [NSNumber numberWithInt:[d yearOfCommonEra]]];
207 [super takeValuesFromRequest:_rq inContext:_ctx];
210 @end /* UIxDatePicker */