]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxTimeDateControl.m
initial sync
[scalable-opengroupware.org] / UI / Scheduler / UIxTimeDateControl.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSString.h>
25 #import <Foundation/NSValue.h>
26
27 #import <NGObjWeb/SoObjects.h>
28
29 #import <SOGo/NSCalendarDate+SOGo.h>
30
31 #import "UIxTimeDateControl.h"
32
33 @implementation UIxTimeDateControl
34
35 - (id)init {
36   self = [super init];
37   if (self) {
38     displayTimeControl = YES;
39     isDisabled = NO;
40   }
41   return self;
42 }
43
44 - (void)dealloc {
45   [controlID release];
46   [label     release];
47   [date      release];
48   [hour      release];
49   [minute    release];
50   [second    release];
51   [day       release];
52   [month     release];
53   [year      release];
54   [super dealloc];
55 }
56
57 /* accessors */
58
59 - (void)setControlID:(NSString *)_controlID {
60   ASSIGNCOPY(controlID, _controlID);
61 }
62 - (NSString *)controlID {
63   return controlID;
64 }
65 - (void)setLabel:(NSString *)_label {
66   ASSIGNCOPY(label, _label);
67 }
68 - (NSString *)label {
69   return label;
70 }
71
72 - (void)setDate:(NSCalendarDate *)_date {
73   int minuteValue;
74   if (!_date)
75     _date = [NSCalendarDate date];
76   [_date setTimeZone: [[self clientObject] userTimeZone]];
77   [self _setDate: _date];
78
79   minuteValue = [_date minuteOfHour];
80   if (minuteValue % 15)
81     minuteValue += 15 - (minuteValue % 15);
82   [self setHour: [NSNumber numberWithInt: [_date hourOfDay]]];
83   [self setMinute: [NSNumber numberWithInt: minuteValue]];
84   [self setYear: [NSNumber numberWithInt: [_date yearOfCommonEra]]];
85   [self setMonth: [NSNumber numberWithInt: [_date monthOfYear]]];
86   [self setDay: [NSNumber numberWithInt: [_date dayOfMonth]]];
87 }
88
89 - (void)_setDate:(NSCalendarDate *)_date {
90   ASSIGN(date, _date);
91 }
92
93 - (NSCalendarDate *)date {
94   return date;
95 }
96
97 - (void)setHour:(id)_hour {
98   ASSIGN(hour, _hour);
99 }
100 - (id)hour {
101   return hour;
102 }
103 - (void)setMinute:(id)_minute {
104   ASSIGN(minute, _minute);
105 }
106 - (id)minute {
107   return minute;
108 }
109 - (void)setSecond:(id)_second {
110   ASSIGN(second, _second);
111 }
112 - (id)second {
113   return second;
114 }
115
116 - (void)setDay:(id)_day {
117   ASSIGN(day, _day);
118 }
119 - (id)day {
120   return day;
121 }
122 - (void)setMonth:(id)_month {
123   ASSIGN(month, _month);
124 }
125 - (id)month {
126   return month;
127 }
128 - (void)setYear:(id)_year {
129   ASSIGN(year, _year);
130 }
131 - (id)year {
132   return year;
133 }
134
135 - (void) setDayStartHour: (unsigned int) aStartHour
136 {
137   startHour = aStartHour;
138 }
139
140 - (void) setDayEndHour: (unsigned int) anEndHour
141 {
142   endHour = anEndHour;
143 }
144
145 - (void) setHourOption: (NSNumber *) option
146 {
147   currentHour = option;
148 }
149
150 - (BOOL) isCurrentHour
151 {
152   return [currentHour isEqual: hour];
153 }
154
155 - (BOOL) isCurrentMinute
156 {
157   return [currentMinute isEqual: minute];
158 }
159
160 - (int) hourValue
161 {
162   return [currentHour intValue];
163 }
164
165 - (NSString *) hourLabel
166 {
167   return [NSString stringWithFormat: @"%.2d", [currentHour intValue]];
168 }
169
170 - (NSArray *) selectableHours
171 {
172   NSMutableArray *hours;
173   unsigned int h;
174
175   hours = [NSMutableArray new];
176   [hours autorelease];
177
178   for (h = startHour; h < (endHour + 1); h++)
179     [hours addObject: [NSNumber numberWithInt: h]];
180
181   return hours;
182 }
183
184 - (NSString *) hourSelectId
185 {
186   return [[self controlID] stringByAppendingString:@"_time_hour"];
187 }
188
189 - (void) setMinuteOption: (NSNumber *) option
190 {
191   currentMinute = option;
192 }
193
194 - (int) minuteValue
195 {
196   return [currentMinute intValue];
197 }
198
199 - (NSString *) minuteLabel
200 {
201   return [NSString stringWithFormat: @"%.2d", [currentMinute intValue]];
202 }
203
204 - (NSArray *) selectableMinutes
205 {
206   NSMutableArray *minutes;
207   unsigned int m;
208
209   minutes = [NSMutableArray new];
210   [minutes autorelease];
211
212   for (m = 0; m < 60; m += 15)
213     [minutes addObject: [NSNumber numberWithInt: m]];
214
215   return minutes;
216 }
217
218 - (NSString *) minuteSelectId
219 {
220   return [[self controlID] stringByAppendingString:@"_time_minute"];
221 }
222
223 - (NSString *) timeID
224 {
225   return [[self controlID] stringByAppendingString:@"_time"];
226 }
227
228 - (NSString *) dateID
229 {
230   return [[self controlID] stringByAppendingString:@"_date"];
231 }
232
233 - (void) setDisplayTimeControl: (BOOL) _displayTimeControl
234 {
235   displayTimeControl = _displayTimeControl;
236 }
237
238 - (BOOL) displayTimeControl
239 {
240   return displayTimeControl;
241 }
242
243 /* processing request */
244
245 - (void) takeValuesFromRequest: (WORequest *) _rq
246                      inContext: (WOContext *) _ctx
247 {
248   NSCalendarDate *d;
249   unsigned _year, _month, _day, _hour, _minute, _second;
250
251   /* call super, so that the form values are applied on the popups */
252   [super takeValuesFromRequest:_rq inContext:_ctx];
253
254   _year  = [[self year] intValue];
255   if (_year > 0)
256     {
257       [self setHour: [_rq formValueForKey: [self hourSelectId]]];
258       [self setMinute: [_rq formValueForKey: [self minuteSelectId]]];
259
260       _month  = [[self month] intValue];
261       _day    = [[self day] intValue];
262       _hour   = [[self hour] intValue];
263       _minute = [[self minute] intValue];
264       _second = [[self second] intValue];
265       
266       d = [NSCalendarDate dateWithYear: _year month:_month day:_day
267                           hour:_hour minute:_minute second:_second
268                           timeZone: [[self clientObject] userTimeZone]];
269       [self _setDate: d];
270     }
271 }
272
273 - (void) setDisabled: (BOOL) disabled
274 {
275   isDisabled = disabled;
276 }
277
278 - (BOOL) disabled
279 {
280   return isDisabled;
281 }
282
283 @end /* UIxTimeDateControl */