2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-07-12 17:37:14 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2010-01-06 20:21:15 +01:00
|
|
|
#import <Foundation/NSTimeZone.h>
|
2007-07-12 17:37:14 +02:00
|
|
|
|
2010-01-06 20:21:15 +01:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2007-07-12 17:37:14 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-01-06 20:21:15 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
|
|
|
|
2009-01-07 22:01:16 +01:00
|
|
|
#import "UIxDatePicker.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation UIxDatePicker
|
|
|
|
|
2006-10-19 16:37:13 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
isDisabled = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
- (void)dealloc {
|
|
|
|
[self->dateID release];
|
|
|
|
[self->day release];
|
|
|
|
[self->month release];
|
|
|
|
[self->year release];
|
|
|
|
[self->label release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Accessors */
|
|
|
|
|
|
|
|
- (void)setDateID:(NSString *)_dateID {
|
|
|
|
ASSIGNCOPY(self->dateID, _dateID);
|
|
|
|
}
|
|
|
|
- (NSString *)dateID {
|
|
|
|
return self->dateID;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDay:(id)_day {
|
|
|
|
ASSIGN(self->day, _day);
|
|
|
|
}
|
|
|
|
- (id)day {
|
|
|
|
return self->day;
|
|
|
|
}
|
|
|
|
- (void)setMonth:(id)_month {
|
|
|
|
ASSIGN(self->month, _month);
|
|
|
|
}
|
|
|
|
- (id)month {
|
|
|
|
return self->month;
|
|
|
|
}
|
|
|
|
- (void)setYear:(id)_year {
|
|
|
|
ASSIGN(self->year, _year);
|
|
|
|
}
|
|
|
|
- (id)year {
|
|
|
|
return self->year;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)setLabel:(NSString *)_label {
|
|
|
|
ASSIGNCOPY(self->label, _label);
|
|
|
|
}
|
|
|
|
- (NSString *)label {
|
|
|
|
return self->label;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* formats */
|
|
|
|
|
|
|
|
- (BOOL)useISOFormats {
|
|
|
|
WOContext *ctx;
|
|
|
|
NSNumber *useISOFormats;
|
|
|
|
|
|
|
|
ctx = [self context];
|
|
|
|
useISOFormats = [ctx valueForKey:@"useISOFormats"];
|
|
|
|
if (!useISOFormats) {
|
|
|
|
NSArray *languages = [ctx resourceLookupLanguages];
|
|
|
|
if (languages && [languages count] > 0) {
|
|
|
|
if ([[languages objectAtIndex:0] isEqualToString:@"French"]) {
|
|
|
|
useISOFormats = [NSNumber numberWithBool:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!useISOFormats)
|
|
|
|
useISOFormats = [NSNumber numberWithBool:YES];
|
|
|
|
[ctx takeValue:useISOFormats forKey:@"useISOFormats"];
|
|
|
|
}
|
|
|
|
return [useISOFormats boolValue];
|
|
|
|
}
|
2006-10-26 18:35:51 +02:00
|
|
|
|
|
|
|
- (NSString *) formattedDateString
|
|
|
|
{
|
2009-08-20 19:50:37 +02:00
|
|
|
char buf[22];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-08-20 19:50:37 +02:00
|
|
|
if ([self useISOFormats]) {
|
|
|
|
sprintf(buf, "%04d-%02d-%02d",
|
|
|
|
[[self year] intValue],
|
|
|
|
[[self month] intValue],
|
|
|
|
[[self day] intValue]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sprintf(buf, "%02d/%02d/%04d",
|
|
|
|
[[self day] intValue],
|
|
|
|
[[self month] intValue],
|
|
|
|
[[self year] intValue]);
|
|
|
|
}
|
|
|
|
return [NSString stringWithCString:buf];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-08-19 00:46:45 +02:00
|
|
|
- (NSString *) dateFormat
|
|
|
|
{
|
2009-08-20 19:50:37 +02:00
|
|
|
return [self useISOFormats] ? @"%Y-%m-%d" : @"%d/%m/%Y";
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-08-19 00:46:45 +02:00
|
|
|
- (NSString *) jsDateFormat
|
|
|
|
{
|
2009-08-20 19:50:37 +02:00
|
|
|
return [self useISOFormats] ? @"yyyy-mm-dd" : @"dd/mm/yyyy";
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* action */
|
|
|
|
|
2006-10-12 18:45:32 +02:00
|
|
|
- (void) takeValuesFromRequest: (WORequest *) _rq
|
|
|
|
inContext: (WOContext *)_ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *dateString;
|
|
|
|
NSCalendarDate *d;
|
2010-01-06 20:21:15 +01:00
|
|
|
NSInteger dateTZOffset, userTZOffset;
|
2011-02-14 19:02:39 +01:00
|
|
|
NSTimeZone *systemTZ, *userTZ;
|
2010-01-06 20:21:15 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
dateString = [_rq formValueForKey:[self dateID]];
|
|
|
|
if (dateString == nil) {
|
|
|
|
[self debugWithFormat:@"got no date string!"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = [NSCalendarDate dateWithString:dateString
|
|
|
|
calendarFormat:[self dateFormat]];
|
|
|
|
if (d == nil) {
|
|
|
|
[self warnWithFormat:@"Could not parse dateString: '%@'",
|
|
|
|
dateString];
|
|
|
|
}
|
2006-10-19 16:37:13 +02:00
|
|
|
|
2010-01-06 20:21:15 +01:00
|
|
|
/* we must adjust the date timezone because "dateWithString:..." uses the
|
|
|
|
system timezone, which can be different from the user's. */
|
|
|
|
ud = [[_ctx activeUser] userDefaults];
|
2011-02-14 19:02:39 +01:00
|
|
|
systemTZ = [d timeZone];
|
|
|
|
dateTZOffset = [systemTZ secondsFromGMTForDate: d];
|
2010-01-06 20:21:15 +01:00
|
|
|
userTZ = [ud timeZone];
|
2011-02-14 19:02:39 +01:00
|
|
|
userTZOffset = [userTZ secondsFromGMTForDate: d];
|
2010-01-06 20:21:15 +01:00
|
|
|
if (dateTZOffset != userTZOffset)
|
|
|
|
d = [d dateByAddingYears: 0 months: 0 days: 0
|
|
|
|
hours: 0 minutes: 0
|
|
|
|
seconds: (dateTZOffset - userTZOffset)];
|
|
|
|
[d setTimeZone: userTZ];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
[self setDay: [NSNumber numberWithInt:[d dayOfMonth]]];
|
|
|
|
[self setMonth:[NSNumber numberWithInt:[d monthOfYear]]];
|
|
|
|
[self setYear: [NSNumber numberWithInt:[d yearOfCommonEra]]];
|
|
|
|
|
|
|
|
[super takeValuesFromRequest:_rq inContext:_ctx];
|
|
|
|
}
|
|
|
|
|
2006-10-19 16:37:13 +02:00
|
|
|
- (void) setDisabled: (BOOL) disabled
|
|
|
|
{
|
|
|
|
isDisabled = disabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) disabled
|
|
|
|
{
|
|
|
|
return isDisabled;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* UIxDatePicker */
|