]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Scheduler/UIxCalView.m
fe0b42a520cfe4bfad1fa97c425de88f9220f5d1
[scalable-opengroupware.org] / SOGo / UI / Scheduler / UIxCalView.m
1 // $Id$
2
3 #include "UIxCalView.h"
4 #include "common.h"
5 #include "UIxAppointmentFormatter.h"
6
7 @implementation UIxCalView
8
9 - (void)dealloc {
10   [self->appointment  release];
11   [self->appointments release];
12   [self->currentDay   release];
13   [super dealloc];
14 }
15
16 /* accessors */
17
18 - (void)setAppointments:(NSArray *)_apts {
19   ASSIGN(self->appointments, _apts);
20 }
21 - (NSArray *)appointments {
22   return self->appointments;
23 }
24
25 - (void)setAppointment:(id)_apt {
26   ASSIGN(self->appointment, _apt);
27 }
28 - (id)appointment {
29   return self->appointment;
30 }
31
32 - (NSDictionary *)aptTypeDict {
33     return nil;
34 }
35
36 - (NSString *)aptTypeLabel {
37     return @"aptLabel";
38 }
39
40 - (NSString *)aptTypeIcon {
41     return @"";
42 }
43
44 - (NSString *)shortTextForApt {
45   NSCalendarDate *startDate;
46   NSString *ms;
47   
48   startDate = [[self appointment] valueForKey:@"startDate"];
49   ms = [NSString stringWithFormat:@"%02i:%02i %@",
50                  [startDate hourOfDay],
51                  [startDate minuteOfHour],
52                  [[self appointment] valueForKey:@"title"]];
53   return ms;
54 }
55
56 - (NSString *)shortTitleForApt {
57   NSString *title;
58     
59   title = [self->appointment valueForKey:@"title"];
60   if([title length] > 12) {
61         title = [NSString stringWithFormat:@"%@...",
62             [title substringToIndex:11]];
63   }
64   return title;
65 }
66
67 - (NSCalendarDate *)referenceDateForFormatter {
68     return [self selectedDate];
69 }
70
71 /* current day related */
72
73 - (void)setCurrentDay:(NSCalendarDate *)_day {
74     ASSIGN(self->currentDay, _day);
75 }
76 - (NSCalendarDate *)currentDay {
77     return self->currentDay;
78 }
79
80 - (NSString *)currentDayName {
81     // TODO: this is slow, use locale dictionary to speed this up
82     return [self->currentDay descriptionWithCalendarFormat:@"%A"];
83 }
84
85 - (BOOL)hasDayInfo {
86     return [self hasHoldidayInfo] || ([[self allDayApts] count] != 0);
87 }
88
89 - (BOOL)hasHoldidayInfo {
90     return NO;
91 }
92
93 - (NSArray *)allDayApts {
94     return [NSArray array];
95 }
96
97
98 /* defaults */
99
100
101 - (BOOL)showFullNames {
102     return YES;
103 }
104
105 - (BOOL)showAMPMDates {
106     return NO;
107 }
108
109
110 /* URLs */
111
112 - (NSString *)appointmentViewURL {
113   id pkey;
114   
115   if ((pkey = [[self appointment] valueForKey:@"uid"]) == nil)
116     return nil;
117   
118   return [NSString stringWithFormat:@"%@/view", pkey];
119 }
120
121
122 /* backend */
123
124 /* resource URLs (TODO?) */
125
126 - (NSString *)resourcePath {
127   return @"/sogod.woa/WebServerResources/";
128 }
129
130 - (NSString *)favIconPath {
131   return [[self resourcePath] stringByAppendingPathComponent:@"favicon.ico"];
132 }
133 - (NSString *)cssPath {
134   NSString *path;
135   
136   // TODO: there should be reusable functionality for that!
137 #warning ZideStore specific?
138   path = @"ControlPanel/Products/ZideStoreUI/Resources/zidestoreui.css";
139   return [[self context] urlWithRequestHandlerKey:@"so"
140                          path:path
141                          queryString:nil];
142 }
143
144 - (NSString *)calCSSPath {
145   NSString *path;
146   
147   // TODO: there should be reusable functionality for that!
148 #warning ZideStore specific?
149   path = @"ControlPanel/Products/ZideStoreUI/Resources/calendar.css";
150   return [[self context] urlWithRequestHandlerKey:@"so"
151                          path:path
152                          queryString:nil];
153 }
154
155 /* fetching */
156
157 - (NSCalendarDate *)startDate {
158   return [self selectedDate];
159 }
160 - (NSCalendarDate *)endDate {
161   return [[self startDate] tomorrow];
162 }
163
164 - (NSArray *)fetchCoreInfos {
165   if (self->appointments)
166     return self->appointments;
167
168   self->appointments =
169     [[[self clientObject] fetchCoreInfosFrom:[self startDate] 
170                           to:[self endDate]] retain];
171   return self->appointments;
172 }
173
174 /* date selection & conversion */
175
176
177 - (NSDictionary *)todayQueryParameters {
178     NSCalendarDate *date;
179     
180     date = [NSCalendarDate date]; /* today */
181     return [self queryParametersBySettingSelectedDate:date];
182 }
183
184 - (NSDictionary *)currentDayQueryParameters {
185     return [self queryParametersBySettingSelectedDate:self->currentDay];
186 }
187
188 - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date {
189     NSMutableDictionary *qp;
190     
191     qp = [[self queryParameters] mutableCopy];
192     [self setSelectedDateQueryParameter:_date inDictionary:qp];
193     return [qp autorelease];
194 }
195
196 - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
197         inDictionary:(NSMutableDictionary *)_qp;
198 {
199     if(_newDate != nil)
200         [_qp setObject:[self dateStringForDate:_newDate]
201              forKey:@"day"];
202     else
203         [_qp removeObjectForKey:@"day"];
204 }
205
206 @end /* UIxCalView */