]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalYearOverview.m
207a151e7cbc6936bce9aad0e18c99c94288d594
[scalable-opengroupware.org] / UI / Scheduler / UIxCalYearOverview.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 #include <SOGoUI/UIxComponent.h>
24
25 @interface UIxCalYearOverview : UIxComponent
26 {
27   NSArray        *row;
28   NSCalendarDate *month;
29 }
30
31 - (NSCalendarDate *)startDate;
32
33 - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date;
34
35 - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
36   inDictionary:(NSMutableDictionary *)_qp;
37
38 @end
39
40 #include "common.h"
41
42 @implementation UIxCalYearOverview
43
44 - (void)dealloc {
45     [self->row release];
46     [self->month release];
47     [super dealloc];
48 }
49
50 /* accessors */
51
52 - (void)setRow:(NSArray *)_row {
53   ASSIGN(self->row, _row);
54 }
55 - (NSArray *)row {
56   return self->row;
57 }
58
59 - (void)setMonth:(NSCalendarDate *)_date {
60   ASSIGN(self->month, _date);
61 }
62 - (NSCalendarDate *)month {
63   return self->month;
64 }
65
66 - (int)year {
67   return [[self selectedDate] yearOfCommonEra];
68 }
69
70 - (NSArray *)arrayOfDateArrays {
71   NSCalendarDate *startDate;
72   NSMutableArray *result, *tmp;
73   unsigned       rowIdx, columnIdx;
74   int            monthOffset = 0;
75   
76   startDate = [self startDate];
77   result    = [NSMutableArray arrayWithCapacity:3];
78   
79   for (rowIdx = 0; rowIdx < 3; rowIdx++) {
80     tmp = [[NSMutableArray alloc] initWithCapacity:4];
81     
82     for (columnIdx = 0; columnIdx < 4; columnIdx++) {
83       NSCalendarDate *date;
84       
85       date = [startDate dateByAddingYears:0 months:monthOffset days:0];
86       [tmp addObject:date];
87       monthOffset++;
88     }
89     [result addObject:tmp];
90     [tmp release];
91   }
92   return result;
93 }
94
95
96 /* date ranges */
97
98 - (NSCalendarDate *)startDate {
99   return [[[NSCalendarDate alloc] initWithYear:[self year] month:1 day:1
100                                   hour:0 minute:0 second:0
101                                   timeZone:[self viewTimeZone]] autorelease];
102 }
103 - (NSCalendarDate *)endDate {
104   return nil;
105 }
106
107 /* URLs */
108
109 - (NSDictionary *)todayQueryParameters {
110   NSCalendarDate *date;
111     
112   date = [NSCalendarDate date]; /* today */
113   return [self queryParametersBySettingSelectedDate:date];
114 }
115
116 - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date{
117   NSMutableDictionary *qp;
118     
119   qp = [[self queryParameters] mutableCopy];
120   [self setSelectedDateQueryParameter:_date inDictionary:qp];
121   return [qp autorelease];
122 }
123
124 - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
125   inDictionary:(NSMutableDictionary *)_qp;
126 {
127   if (_newDate != nil)
128     [_qp setObject:[self dateStringForDate:_newDate] forKey:@"day"];
129   else
130     [_qp removeObjectForKey:@"day"];
131 }
132
133 - (NSDictionary *)prevYearQueryParameters {
134   NSCalendarDate *date;
135     
136   date = [[self startDate] dateByAddingYears:-1 months:0 days:0
137                            hours:0 minutes:0 seconds:0];
138   return [self queryParametersBySettingSelectedDate:date];
139 }
140
141 - (NSDictionary *)nextYearQueryParameters {
142   NSCalendarDate *date;
143    
144   date = [[self startDate] dateByAddingYears:1 months:0 days:0
145                            hours:0 minutes:0 seconds:0];
146   return [self queryParametersBySettingSelectedDate:date];
147 }
148
149 @end /* UIxCalYearOverview */