]> err.no Git - scalable-opengroupware.org/blob - ZideStore/UI-X/Scheduler/UIxCalView.m
e68043df8d80065d0e4222b598be9242ca2e7d73
[scalable-opengroupware.org] / ZideStore / UI-X / Scheduler / UIxCalView.m
1 // $Id$
2
3 #include "UIxCalView.h"
4 #include "common.h"
5 #include <Backend/SxAptManager.h>
6 #include "UIxAppointmentFormatter.h"
7
8 @interface NSObject(UsedPrivates)
9 - (SxAptManager *)aptManagerInContext:(id)_ctx;
10 @end
11
12 @implementation UIxCalView
13
14 - (void)dealloc {
15   [self->appointment  release];
16   [self->appointments release];
17   [self->currentDay release];
18   [super dealloc];
19 }
20
21 /* accessors */
22
23
24 - (void)setAppointments:(NSArray *)_apts {
25   ASSIGN(self->appointments, _apts);
26 }
27 - (NSArray *)appointments {
28   return self->appointments;
29 }
30
31 - (void)setAppointment:(id)_apt {
32   ASSIGN(self->appointment, _apt);
33 }
34 - (id)appointment {
35   return self->appointment;
36 }
37
38 - (NSDictionary *)aptTypeDict {
39     return nil;
40 }
41
42 - (NSString *)aptTypeLabel {
43     return @"aptLabel";
44 }
45
46 - (NSString *)aptTypeIcon {
47     return @"";
48 }
49
50 - (NSString *)shortTextForApt {
51     UIxAppointmentFormatter *f;
52     
53     f = [UIxAppointmentFormatter formatterWithFormat:
54         @"%S - %E;\n%T;\n%L;\n%5P;\n%50R"];
55     [f setRelationDate:[self referenceDateForFormatter]];
56     [f setShowFullNames:[self showFullNames]];
57     if([self showAMPMDates])
58         [f switchToAMPMTimes:YES];
59     
60     return [NSString stringWithFormat:@"%@:\n%@",
61         [self aptTypeLabel],
62         [f stringForObjectValue:self->appointment]];
63 }
64
65 - (NSString *)shortTitleForApt {
66     NSString *title;
67     
68     title = [self->appointment valueForKey:@"title"];
69     if([title length] > 12) {
70         title = [NSString stringWithFormat:@"%@...",
71             [title substringToIndex:11]];
72     }
73     return title;
74 }
75
76 - (NSCalendarDate *)referenceDateForFormatter {
77     return [self selectedDate];
78 }
79
80 /* current day related */
81
82 - (void)setCurrentDay:(NSCalendarDate *)_day {
83     ASSIGN(self->currentDay, _day);
84 }
85 - (NSCalendarDate *)currentDay {
86     return self->currentDay;
87 }
88
89 - (NSString *)currentDayName {
90     // TODO: this is slow, use locale dictionary to speed this up
91     return [self->currentDay descriptionWithCalendarFormat:@"%A"];
92 }
93
94 - (BOOL)hasDayInfo {
95     return [self hasHoldidayInfo] || ([[self allDayApts] count] != 0);
96 }
97
98 - (BOOL)hasHoldidayInfo {
99     return NO;
100 }
101
102 - (NSArray *)allDayApts {
103     return [NSArray array];
104 }
105
106
107 /* defaults */
108
109
110 - (BOOL)showFullNames {
111     return YES;
112 }
113
114 - (BOOL)showAMPMDates {
115     return NO;
116 }
117
118
119 /* URLs */
120
121 - (NSString *)appointmentViewURL {
122   id pkey;
123   
124   if ((pkey = [[self appointment] valueForKey:@"dateId"]) == nil)
125     return nil;
126   
127   return [NSString stringWithFormat:@"%@/view", pkey];
128 }
129
130
131 /* backend */
132
133 - (SxAptManager *)aptManager {
134   return [[self clientObject] aptManagerInContext:[self context]];
135 }
136 - (SxAptSetIdentifier *)aptSetID {
137   return [[self clientObject] aptSetID];
138 }
139
140 /* resource URLs (TODO?) */
141
142 - (NSString *)resourcePath {
143   return @"/ZideStore.woa/WebServerResources/";
144 }
145
146 - (NSString *)favIconPath {
147   return [[self resourcePath] stringByAppendingPathComponent:@"favicon.ico"];
148 }
149 - (NSString *)cssPath {
150   NSString *path;
151   
152   // TODO: there should be reusable functionality for that!
153   path = @"ControlPanel/Products/ZideStoreUI/Resources/zidestoreui.css";
154   return [[self context] urlWithRequestHandlerKey:@"so"
155                          path:path
156                          queryString:nil];
157 }
158
159 - (NSString *)calCSSPath {
160   NSString *path;
161   
162   // TODO: there should be reusable functionality for that!
163   path = @"ControlPanel/Products/ZideStoreUI/Resources/calendar.css";
164   return [[self context] urlWithRequestHandlerKey:@"so"
165                          path:path
166                          queryString:nil];
167 }
168
169 /* date */
170
171 - (NSCalendarDate *)selectedDate {
172     NSString *s;
173     
174     s = [self queryParameterForKey:@"day"];
175     if(s) {
176         return [self dateForDateString:s];
177     }
178     return [NSCalendarDate date];
179 }
180
181 /* fetching */
182
183 - (NSCalendarDate *)startDate {
184   return [self selectedDate];
185 }
186 - (NSCalendarDate *)endDate {
187   return [[self startDate] tomorrow];
188 }
189
190 - (NSArray *)fetchGIDs {
191   return [[self aptManager] gidsOfAppointmentSet:[self aptSetID]
192                             from:[self startDate] to:[self endDate]];
193 }
194
195 - (NSArray *)fetchCoreInfos {
196   NSArray *gids;
197   
198   if (self->appointments)
199     return self->appointments;
200   
201   [self logWithFormat:@"fetching (%@ => %@) ...", 
202           [self startDate], [self endDate]];
203   gids = [self fetchGIDs];
204   [self logWithFormat:@"  %i GIDs ...", [gids count]];
205   
206   self->appointments = 
207     [[[self aptManager] coreInfoOfAppointmentsWithGIDs:gids
208                         inSet:[self aptSetID]] retain];
209   
210   [self logWithFormat:@"fetched %i records.", [self->appointments count]];
211   return self->appointments;
212 }
213
214
215 /* date selection & conversion */
216
217
218 - (NSDictionary *)todayQueryParameters {
219     NSCalendarDate *date;
220     
221     date = [NSCalendarDate date]; /* today */
222     return [self queryParametersBySettingSelectedDate:date];
223 }
224
225 - (NSDictionary *)currentDayQueryParameters {
226     return [self queryParametersBySettingSelectedDate:self->currentDay];
227 }
228
229 - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date {
230     NSMutableDictionary *qp;
231     
232     qp = [[self queryParameters] mutableCopy];
233     [self setSelectedDateQueryParameter:_date inDictionary:qp];
234     return [qp autorelease];
235 }
236
237 - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
238         inDictionary:(NSMutableDictionary *)_qp;
239 {
240     if(_newDate != nil)
241         [_qp setObject:[self dateStringForDate:_newDate]
242              forKey:@"day"];
243     else
244         [_qp removeObjectForKey:@"day"];
245 }
246
247 - (NSString *)dateStringForDate:(NSCalendarDate *)_date {
248   return [_date descriptionWithCalendarFormat:@"%Y%m%d"];
249 }
250
251 - (NSCalendarDate *)dateForDateString:(NSString *)_dateString {
252   return [NSCalendarDate dateWithString:_dateString calendarFormat:@"%Y%m%d"];
253 }
254
255 @end /* UIxCalView */