3 #include "UIxCalView.h"
5 #include <Backend/SxAptManager.h>
6 #include "UIxAppointmentFormatter.h"
8 @interface NSObject(UsedPrivates)
9 - (SxAptManager *)aptManagerInContext:(id)_ctx;
12 @implementation UIxCalView
15 [self->appointment release];
16 [self->appointments release];
17 [self->currentDay release];
24 - (void)setAppointments:(NSArray *)_apts {
25 ASSIGN(self->appointments, _apts);
27 - (NSArray *)appointments {
28 return self->appointments;
31 - (void)setAppointment:(id)_apt {
32 ASSIGN(self->appointment, _apt);
35 return self->appointment;
38 - (NSDictionary *)aptTypeDict {
42 - (NSString *)aptTypeLabel {
46 - (NSString *)aptTypeIcon {
50 - (NSString *)shortTextForApt {
51 UIxAppointmentFormatter *f;
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];
60 return [NSString stringWithFormat:@"%@:\n%@",
62 [f stringForObjectValue:self->appointment]];
65 - (NSString *)shortTitleForApt {
68 title = [self->appointment valueForKey:@"title"];
69 if([title length] > 12) {
70 title = [NSString stringWithFormat:@"%@...",
71 [title substringToIndex:11]];
76 - (NSCalendarDate *)referenceDateForFormatter {
77 return [self selectedDate];
80 /* current day related */
82 - (void)setCurrentDay:(NSCalendarDate *)_day {
83 ASSIGN(self->currentDay, _day);
85 - (NSCalendarDate *)currentDay {
86 return self->currentDay;
89 - (NSString *)currentDayName {
90 // TODO: this is slow, use locale dictionary to speed this up
91 return [self->currentDay descriptionWithCalendarFormat:@"%A"];
95 return [self hasHoldidayInfo] || ([[self allDayApts] count] != 0);
98 - (BOOL)hasHoldidayInfo {
102 - (NSArray *)allDayApts {
103 return [NSArray array];
110 - (BOOL)showFullNames {
114 - (BOOL)showAMPMDates {
121 - (NSString *)appointmentViewURL {
124 if ((pkey = [[self appointment] valueForKey:@"dateId"]) == nil)
127 return [NSString stringWithFormat:@"%@/view", pkey];
133 - (SxAptManager *)aptManager {
134 return [[self clientObject] aptManagerInContext:[self context]];
136 - (SxAptSetIdentifier *)aptSetID {
137 return [[self clientObject] aptSetID];
140 /* resource URLs (TODO?) */
142 - (NSString *)resourcePath {
143 return @"/ZideStore.woa/WebServerResources/";
146 - (NSString *)favIconPath {
147 return [[self resourcePath] stringByAppendingPathComponent:@"favicon.ico"];
149 - (NSString *)cssPath {
152 // TODO: there should be reusable functionality for that!
153 path = @"ControlPanel/Products/ZideStoreUI/Resources/zidestoreui.css";
154 return [[self context] urlWithRequestHandlerKey:@"so"
159 - (NSString *)calCSSPath {
162 // TODO: there should be reusable functionality for that!
163 path = @"ControlPanel/Products/ZideStoreUI/Resources/calendar.css";
164 return [[self context] urlWithRequestHandlerKey:@"so"
171 - (NSCalendarDate *)selectedDate {
174 s = [self queryParameterForKey:@"day"];
176 return [self dateForDateString:s];
178 return [NSCalendarDate date];
183 - (NSCalendarDate *)startDate {
184 return [self selectedDate];
186 - (NSCalendarDate *)endDate {
187 return [[self startDate] tomorrow];
190 - (NSArray *)fetchGIDs {
191 return [[self aptManager] gidsOfAppointmentSet:[self aptSetID]
192 from:[self startDate] to:[self endDate]];
195 - (NSArray *)fetchCoreInfos {
198 if (self->appointments)
199 return self->appointments;
201 [self logWithFormat:@"fetching (%@ => %@) ...",
202 [self startDate], [self endDate]];
203 gids = [self fetchGIDs];
204 [self logWithFormat:@" %i GIDs ...", [gids count]];
207 [[[self aptManager] coreInfoOfAppointmentsWithGIDs:gids
208 inSet:[self aptSetID]] retain];
210 [self logWithFormat:@"fetched %i records.", [self->appointments count]];
211 return self->appointments;
215 /* date selection & conversion */
218 - (NSDictionary *)todayQueryParameters {
219 NSCalendarDate *date;
221 date = [NSCalendarDate date]; /* today */
222 return [self queryParametersBySettingSelectedDate:date];
225 - (NSDictionary *)currentDayQueryParameters {
226 return [self queryParametersBySettingSelectedDate:self->currentDay];
229 - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date {
230 NSMutableDictionary *qp;
232 qp = [[self queryParameters] mutableCopy];
233 [self setSelectedDateQueryParameter:_date inDictionary:qp];
234 return [qp autorelease];
237 - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
238 inDictionary:(NSMutableDictionary *)_qp;
241 [_qp setObject:[self dateStringForDate:_newDate]
244 [_qp removeObjectForKey:@"day"];
247 - (NSString *)dateStringForDate:(NSCalendarDate *)_date {
248 return [_date descriptionWithCalendarFormat:@"%Y%m%d"];
251 - (NSCalendarDate *)dateForDateString:(NSString *)_dateString {
252 return [NSCalendarDate dateWithString:_dateString calendarFormat:@"%Y%m%d"];
255 @end /* UIxCalView */