]> err.no Git - scalable-opengroupware.org/blob - ZideStore/UI-X/Scheduler/UIxCalView.m
work in progress. some more refactoring and overall improvement of the editor.
[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 /* fetching */
170
171 - (NSCalendarDate *)startDate {
172   return [self selectedDate];
173 }
174 - (NSCalendarDate *)endDate {
175   return [[self startDate] tomorrow];
176 }
177
178 - (NSArray *)fetchGIDs {
179   return [[self aptManager] gidsOfAppointmentSet:[self aptSetID]
180                             from:[self startDate] to:[self endDate]];
181 }
182
183 - (NSArray *)fetchCoreInfos {
184   NSArray *gids;
185   
186   if (self->appointments)
187     return self->appointments;
188   
189   [self logWithFormat:@"fetching (%@ => %@) ...", 
190           [self startDate], [self endDate]];
191   gids = [self fetchGIDs];
192   [self logWithFormat:@"  %i GIDs ...", [gids count]];
193   
194   self->appointments = 
195     [[[self aptManager] coreInfoOfAppointmentsWithGIDs:gids
196                         inSet:[self aptSetID]] retain];
197   
198   [self logWithFormat:@"fetched %i records.", [self->appointments count]];
199   return self->appointments;
200 }
201
202
203 /* date selection & conversion */
204
205
206 - (NSDictionary *)todayQueryParameters {
207     NSCalendarDate *date;
208     
209     date = [NSCalendarDate date]; /* today */
210     return [self queryParametersBySettingSelectedDate:date];
211 }
212
213 - (NSDictionary *)currentDayQueryParameters {
214     return [self queryParametersBySettingSelectedDate:self->currentDay];
215 }
216
217 - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date {
218     NSMutableDictionary *qp;
219     
220     qp = [[self queryParameters] mutableCopy];
221     [self setSelectedDateQueryParameter:_date inDictionary:qp];
222     return [qp autorelease];
223 }
224
225 - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
226         inDictionary:(NSMutableDictionary *)_qp;
227 {
228     if(_newDate != nil)
229         [_qp setObject:[self dateStringForDate:_newDate]
230              forKey:@"day"];
231     else
232         [_qp removeObjectForKey:@"day"];
233 }
234
235 @end /* UIxCalView */