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 *)startDate {
172 return [self selectedDate];
174 - (NSCalendarDate *)endDate {
175 return [[self startDate] tomorrow];
178 - (NSArray *)fetchGIDs {
179 return [[self aptManager] gidsOfAppointmentSet:[self aptSetID]
180 from:[self startDate] to:[self endDate]];
183 - (NSArray *)fetchCoreInfos {
186 if (self->appointments)
187 return self->appointments;
189 [self logWithFormat:@"fetching (%@ => %@) ...",
190 [self startDate], [self endDate]];
191 gids = [self fetchGIDs];
192 [self logWithFormat:@" %i GIDs ...", [gids count]];
195 [[[self aptManager] coreInfoOfAppointmentsWithGIDs:gids
196 inSet:[self aptSetID]] retain];
198 [self logWithFormat:@"fetched %i records.", [self->appointments count]];
199 return self->appointments;
203 /* date selection & conversion */
206 - (NSDictionary *)todayQueryParameters {
207 NSCalendarDate *date;
209 date = [NSCalendarDate date]; /* today */
210 return [self queryParametersBySettingSelectedDate:date];
213 - (NSDictionary *)currentDayQueryParameters {
214 return [self queryParametersBySettingSelectedDate:self->currentDay];
217 - (NSDictionary *)queryParametersBySettingSelectedDate:(NSCalendarDate *)_date {
218 NSMutableDictionary *qp;
220 qp = [[self queryParameters] mutableCopy];
221 [self setSelectedDateQueryParameter:_date inDictionary:qp];
222 return [qp autorelease];
225 - (void)setSelectedDateQueryParameter:(NSCalendarDate *)_newDate
226 inDictionary:(NSMutableDictionary *)_qp;
229 [_qp setObject:[self dateStringForDate:_newDate]
232 [_qp removeObjectForKey:@"day"];
235 @end /* UIxCalView */