2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004 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.
|
|
|
|
*/
|
|
|
|
|
2006-10-05 01:15:25 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/SoObjects.h>
|
|
|
|
#import <SOGo/NSCalendarDate+SOGo.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2006-08-31 01:08:15 +02:00
|
|
|
|
|
|
|
#import "UIxTimeDateControl.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation UIxTimeDateControl
|
|
|
|
|
|
|
|
- (id)init {
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
2006-08-31 01:08:15 +02:00
|
|
|
displayTimeControl = YES;
|
2006-10-19 16:38:25 +02:00
|
|
|
isDisabled = NO;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
2006-08-31 01:08:15 +02:00
|
|
|
[controlID release];
|
|
|
|
[label release];
|
|
|
|
[date release];
|
|
|
|
[hour release];
|
|
|
|
[minute release];
|
|
|
|
[second release];
|
|
|
|
[day release];
|
|
|
|
[month release];
|
|
|
|
[year release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
|
|
|
- (void)setControlID:(NSString *)_controlID {
|
2006-08-31 01:08:15 +02:00
|
|
|
ASSIGNCOPY(controlID, _controlID);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (NSString *)controlID {
|
2006-08-31 01:08:15 +02:00
|
|
|
return controlID;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (void)setLabel:(NSString *)_label {
|
2006-08-31 01:08:15 +02:00
|
|
|
ASSIGNCOPY(label, _label);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (NSString *)label {
|
2006-08-31 01:08:15 +02:00
|
|
|
return label;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-10-06 01:29:21 +02:00
|
|
|
|
2007-04-11 21:08:58 +02:00
|
|
|
- (void) setDate: (NSCalendarDate *) _date
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2006-11-07 17:14:19 +01:00
|
|
|
int minuteValue;
|
2007-04-11 21:08:58 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
2006-06-15 21:34:10 +02:00
|
|
|
if (!_date)
|
|
|
|
_date = [NSCalendarDate date];
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
[_date setTimeZone: [ud timeZone]];
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2006-10-06 01:29:21 +02:00
|
|
|
[self _setDate: _date];
|
2006-10-05 01:15:25 +02:00
|
|
|
|
2006-11-07 17:14:19 +01:00
|
|
|
minuteValue = [_date minuteOfHour];
|
|
|
|
if (minuteValue % 15)
|
|
|
|
minuteValue += 15 - (minuteValue % 15);
|
2006-10-06 01:29:21 +02:00
|
|
|
[self setHour: [NSNumber numberWithInt: [_date hourOfDay]]];
|
2006-11-07 17:14:19 +01:00
|
|
|
[self setMinute: [NSNumber numberWithInt: minuteValue]];
|
2006-10-06 01:29:21 +02:00
|
|
|
[self setYear: [NSNumber numberWithInt: [_date yearOfCommonEra]]];
|
|
|
|
[self setMonth: [NSNumber numberWithInt: [_date monthOfYear]]];
|
|
|
|
[self setDay: [NSNumber numberWithInt: [_date dayOfMonth]]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-10-06 01:29:21 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
- (void)_setDate:(NSCalendarDate *)_date {
|
2006-08-31 01:08:15 +02:00
|
|
|
ASSIGN(date, _date);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-10-12 23:45:43 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
- (NSCalendarDate *)date {
|
2006-08-31 01:08:15 +02:00
|
|
|
return date;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setHour:(id)_hour {
|
2006-08-31 01:08:15 +02:00
|
|
|
ASSIGN(hour, _hour);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-03-18 16:22:10 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
- (id)hour {
|
2006-08-31 01:08:15 +02:00
|
|
|
return hour;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (void)setMinute:(id)_minute {
|
2006-08-31 01:08:15 +02:00
|
|
|
ASSIGN(minute, _minute);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (id)minute {
|
2006-08-31 01:08:15 +02:00
|
|
|
return minute;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (void)setSecond:(id)_second {
|
2006-08-31 01:08:15 +02:00
|
|
|
ASSIGN(second, _second);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (id)second {
|
2006-08-31 01:08:15 +02:00
|
|
|
return second;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDay:(id)_day {
|
2006-08-31 01:08:15 +02:00
|
|
|
ASSIGN(day, _day);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (id)day {
|
2006-08-31 01:08:15 +02:00
|
|
|
return day;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (void)setMonth:(id)_month {
|
2006-08-31 01:08:15 +02:00
|
|
|
ASSIGN(month, _month);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (id)month {
|
2006-08-31 01:08:15 +02:00
|
|
|
return month;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (void)setYear:(id)_year {
|
2006-08-31 01:08:15 +02:00
|
|
|
ASSIGN(year, _year);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
- (id)year {
|
2006-08-31 01:08:15 +02:00
|
|
|
return year;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDayStartHour: (unsigned int) aStartHour
|
|
|
|
{
|
|
|
|
startHour = aStartHour;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDayEndHour: (unsigned int) anEndHour
|
|
|
|
{
|
|
|
|
endHour = anEndHour;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setHourOption: (NSNumber *) option
|
|
|
|
{
|
|
|
|
currentHour = option;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isCurrentHour
|
|
|
|
{
|
|
|
|
return [currentHour isEqual: hour];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isCurrentMinute
|
|
|
|
{
|
|
|
|
return [currentMinute isEqual: minute];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) hourValue
|
|
|
|
{
|
|
|
|
return [currentHour intValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) hourLabel
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%.2d", [currentHour intValue]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) selectableHours
|
|
|
|
{
|
|
|
|
NSMutableArray *hours;
|
|
|
|
unsigned int h;
|
|
|
|
|
2009-10-14 14:01:29 +02:00
|
|
|
hours = [NSMutableArray array];
|
2006-08-31 01:08:15 +02:00
|
|
|
for (h = startHour; h < (endHour + 1); h++)
|
|
|
|
[hours addObject: [NSNumber numberWithInt: h]];
|
|
|
|
|
|
|
|
return hours;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) hourSelectId
|
|
|
|
{
|
|
|
|
return [[self controlID] stringByAppendingString:@"_time_hour"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setMinuteOption: (NSNumber *) option
|
|
|
|
{
|
|
|
|
currentMinute = option;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) minuteValue
|
|
|
|
{
|
|
|
|
return [currentMinute intValue];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-08-31 01:08:15 +02:00
|
|
|
- (NSString *) minuteLabel
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%.2d", [currentMinute intValue]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) selectableMinutes
|
|
|
|
{
|
|
|
|
NSMutableArray *minutes;
|
|
|
|
unsigned int m;
|
|
|
|
|
2009-10-14 14:01:29 +02:00
|
|
|
minutes = [NSMutableArray array];
|
2006-08-31 01:08:15 +02:00
|
|
|
for (m = 0; m < 60; m += 15)
|
|
|
|
[minutes addObject: [NSNumber numberWithInt: m]];
|
|
|
|
|
|
|
|
return minutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) minuteSelectId
|
|
|
|
{
|
|
|
|
return [[self controlID] stringByAppendingString:@"_time_minute"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) timeID
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self controlID] stringByAppendingString:@"_time"];
|
|
|
|
}
|
2006-08-31 01:08:15 +02:00
|
|
|
|
|
|
|
- (NSString *) dateID
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self controlID] stringByAppendingString:@"_date"];
|
|
|
|
}
|
|
|
|
|
2006-08-31 01:08:15 +02:00
|
|
|
- (void) setDisplayTimeControl: (BOOL) _displayTimeControl
|
|
|
|
{
|
|
|
|
displayTimeControl = _displayTimeControl;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-08-31 01:08:15 +02:00
|
|
|
- (BOOL) displayTimeControl
|
|
|
|
{
|
|
|
|
return displayTimeControl;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* processing request */
|
|
|
|
|
2006-08-31 01:08:15 +02:00
|
|
|
- (void) takeValuesFromRequest: (WORequest *) _rq
|
|
|
|
inContext: (WOContext *) _ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSCalendarDate *d;
|
|
|
|
unsigned _year, _month, _day, _hour, _minute, _second;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
2009-10-15 20:43:28 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* call super, so that the form values are applied on the popups */
|
|
|
|
[super takeValuesFromRequest:_rq inContext:_ctx];
|
|
|
|
|
|
|
|
_year = [[self year] intValue];
|
2006-08-31 01:08:15 +02:00
|
|
|
if (_year > 0)
|
|
|
|
{
|
|
|
|
[self setHour: [_rq formValueForKey: [self hourSelectId]]];
|
|
|
|
[self setMinute: [_rq formValueForKey: [self minuteSelectId]]];
|
|
|
|
|
2006-10-05 01:15:25 +02:00
|
|
|
_month = [[self month] intValue];
|
|
|
|
_day = [[self day] intValue];
|
|
|
|
_hour = [[self hour] intValue];
|
2006-08-31 01:08:15 +02:00
|
|
|
_minute = [[self minute] intValue];
|
|
|
|
_second = [[self second] intValue];
|
2006-10-19 16:38:25 +02:00
|
|
|
|
2006-10-05 01:15:25 +02:00
|
|
|
d = [NSCalendarDate dateWithYear: _year month:_month day:_day
|
|
|
|
hour:_hour minute:_minute second:_second
|
2009-11-29 05:19:32 +01:00
|
|
|
timeZone: [ud timeZone]];
|
2006-10-06 01:29:21 +02:00
|
|
|
[self _setDate: d];
|
2006-08-31 01:08:15 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-10-19 16:38:25 +02:00
|
|
|
- (void) setDisabled: (BOOL) disabled
|
|
|
|
{
|
|
|
|
isDisabled = disabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) disabled
|
|
|
|
{
|
|
|
|
return isDisabled;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* UIxTimeDateControl */
|