3 #include "UIxCalView.h"
5 #include "UIxAppointmentFormatter.h"
6 #include <OGoContentStore/OCSFolder.h>
7 #include "SoObjects/Appointments/SOGoAppointmentFolder.h"
8 #include <NGObjWeb/SoUser.h>
9 #include <SOGoUI/SOGoAptFormatter.h>
10 #include <SOGoLogic/AgenorUserManager.h>
11 #include "UIxComponent+Agenor.h"
13 @interface UIxCalView (PrivateAPI)
14 - (NSString *)_userFolderURI;
17 @implementation UIxCalView
19 static BOOL shouldDisplayWeekend = NO;
22 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
23 shouldDisplayWeekend = [ud boolForKey:@"SOGoShouldDisplayWeekend"];
27 [self->appointments release];
28 [self->allDayApts release];
29 [self->appointment release];
30 [self->currentDay release];
31 [self->aptFormatter release];
32 [self->aptTooltipFormatter release];
38 - (void)setAppointments:(NSArray *)_apts {
39 ASSIGN(self->appointments, _apts);
41 - (NSArray *)appointments {
42 return self->appointments;
45 - (void)setAppointment:(id)_apt {
46 ASSIGN(self->appointment, _apt);
49 return self->appointment;
52 - (NSDictionary *)aptTypeDict {
55 - (NSString *)aptTypeLabel {
58 - (NSString *)aptTypeIcon {
62 - (SOGoAptFormatter *)aptFormatter {
63 if (self->aptFormatter)
64 return self->aptFormatter;
66 self->aptFormatter = [[SOGoAptFormatter alloc]
67 initWithDisplayTimeZone:[self viewTimeZone]];
68 [self->aptFormatter setFullDetails];
69 return self->aptFormatter;
72 - (SOGoAptFormatter *)aptTooltipFormatter {
73 if (self->aptTooltipFormatter)
74 return self->aptTooltipFormatter;
75 self->aptTooltipFormatter = [[SOGoAptFormatter alloc]
76 initWithDisplayTimeZone:[self viewTimeZone]];
77 [self->aptTooltipFormatter setTooltip];
78 return self->aptTooltipFormatter;
81 /* TODO: remove this */
82 - (NSString *)shortTextForApt {
83 return [[self aptFormatter] stringForObjectValue:self->appointment];
86 - (NSString *)shortTitleForApt {
89 title = [self->appointment valueForKey:@"title"];
90 if ([title length] > 12)
91 title = [[title substringToIndex:11] stringByAppendingString:@"..."];
96 - (NSString *)tooltipForApt {
97 return [[self aptTooltipFormatter] stringForObjectValue:self->appointment];
101 NSString *mailtoChunk;
104 mailtoChunk = [self->appointment valueForKey:@"partmails"];
105 myEmail = [self emailForUser];
106 if ([mailtoChunk rangeOfString:myEmail].length > 0)
111 - (NSString *)aptStyle {
117 - (NSCalendarDate *)referenceDateForFormatter {
118 return [self selectedDate];
121 - (NSCalendarDate *)thisMonth {
122 return [self selectedDate];
125 - (NSCalendarDate *)nextMonth {
126 NSCalendarDate *date = [self thisMonth];
127 return [date dateByAddingYears:0 months:1 days:0
128 hours:0 minutes:0 seconds:0];
132 /* current day related */
134 - (void)setCurrentDay:(NSCalendarDate *)_day {
135 [_day setTimeZone:[self viewTimeZone]];
136 ASSIGN(self->currentDay, _day);
138 - (NSCalendarDate *)currentDay {
139 return self->currentDay;
142 - (NSString *)currentDayName {
143 return [self localizedNameForDayOfWeek:[self->currentDay dayOfWeek]];
150 - (NSArray *)allDayApts {
152 NSMutableArray *filtered;
155 if (self->allDayApts)
156 return self->allDayApts;
158 apts = [self appointments];
159 count = [apts count];
160 filtered = [[NSMutableArray alloc] initWithCapacity:3];
161 for (i = 0; i < count; i++) {
165 apt = [apts objectAtIndex:i];
166 #warning !! check if isAllDay is correct
167 bv = [apt valueForKey:@"isAllDay"];
169 [filtered addObject:apt];
172 ASSIGN(self->allDayApts, filtered);
174 return self->allDayApts;
178 /* special appointments */
181 return [self hasHoldidayInfo] || [self hasAllDayApts];
184 - (BOOL)hasHoldidayInfo {
185 return [self holidayInfo] != nil;
188 - (BOOL)hasAllDayApts {
189 return [[self allDayApts] count] != 0;
195 - (BOOL)showFullNames {
199 - (BOOL)showAMPMDates {
203 - (unsigned)dayStartHour {
207 - (unsigned)dayEndHour {
211 - (BOOL)shouldDisplayWeekend {
212 return shouldDisplayWeekend;
215 - (BOOL)shouldHideWeekend {
216 return ![self shouldDisplayWeekend];
222 - (NSString *)appointmentViewURL {
225 if (![(pkey = [[self appointment] valueForKey:@"uid"]) isNotNull])
228 return [[[self clientObject] baseURLForAptWithUID:[pkey stringValue]
229 inContext:[self context]]
230 stringByAppendingString:@"/view"];
235 /* resource URLs (TODO?) */
237 - (NSString *)resourcePath {
239 // TODO: where is this used?
240 return @"/sogod.woa/WebServerResources/";
243 - (NSString *)favIconPath {
244 return [[self resourcePath] stringByAppendingPathComponent:@"favicon.ico"];
246 - (NSString *)cssPath {
249 // TODO: there should be reusable functionality for that!
250 #warning ZideStore specific?
251 path = @"ControlPanel/Products/ZideStoreUI/Resources/uix.css";
252 return [[self context] urlWithRequestHandlerKey:@"so"
257 - (NSString *)calCSSPath {
260 // TODO: there should be reusable functionality for that!
261 #warning ZideStore specific?
262 path = @"ControlPanel/Products/ZideStoreUI/Resources/calendar.css";
263 return [[self context] urlWithRequestHandlerKey:@"so"
270 - (NSCalendarDate *)startDate {
271 return [self selectedDate];
273 - (NSCalendarDate *)endDate {
274 return [[self startDate] tomorrow];
277 - (NSArray *)_fetchCoreInfosForUIDs:(NSArray *)_uids
278 uniqueWithSet:(NSMutableSet *)_uniquer
283 count = [_uids count];
284 ma = [NSMutableArray arrayWithCapacity:count * 10];
286 for (i = 0; i < count; i++) {
292 uid = [_uids objectAtIndex:i];
293 if ([uid length] == 0) continue;
295 path = [[@"/Users/" stringByAppendingString:uid]
296 stringByAppendingString:@"/Calendar"];
298 if ((folder = [[self clientObject] ocsFolderForPath:path]) == nil) {
299 [self logWithFormat:@"ERROR: did not find user: %@", uid];
303 res = [[self clientObject] fetchCoreInfosFromFolder:folder
304 from:[self startDate] to:[self endDate]];
306 [self logWithFormat:@"ERROR: fetch failed for user: %@", uid];
310 /* perform uniquing */
314 for (j = 0, rcount = [res count]; j < rcount; j++) {
315 NSDictionary *record;
317 record = [res objectAtIndex:j];
319 if ([_uniquer containsObject:[record valueForKey:@"uid"]])
322 [ma addObject:record];
323 [_uniquer addObject:[record valueForKey:@"uid"]];
330 - (NSArray *)fetchCoreInfos {
335 if (self->appointments)
336 return self->appointments;
338 aptFolder = [self clientObject];
340 [[aptFolder fetchCoreInfosFrom:[self startDate] to:[self endDate]] retain];
342 uids = [[[[self context] request] formValueForKey:@"uids"] stringValue];
343 uids = [uids length] > 0 ? [uids componentsSeparatedByString:@","] : nil;
344 if ([uids count] > 0) {
345 NSMutableSet *availUIDs;
348 /* make appointments unique, prefer the own "versions" */
349 tmp = [self->appointments valueForKey:@"uid"];
350 availUIDs = [[NSMutableSet alloc] initWithArray:tmp];
352 more = [self _fetchCoreInfosForUIDs:uids uniqueWithSet:availUIDs];
356 tmp = self->appointments;
357 self->appointments = [[tmp arrayByAddingObjectsFromArray:more] retain];
364 return self->appointments;
367 /* date selection & conversion */
369 - (NSDictionary *)todayQueryParameters {
370 NSCalendarDate *date;
372 date = [NSCalendarDate date]; /* today */
373 return [self queryParametersBySettingSelectedDate:date];
376 - (NSDictionary *)currentDayQueryParameters {
377 return [self queryParametersBySettingSelectedDate:self->currentDay];
382 - (NSString *)formattedCalendarUIDs {
383 return [[[self clientObject] calendarUIDs]
384 componentsJoinedByString:@", "];
389 - (NSString *)_userFolderURI {
394 ctx = [self context];
395 obj = [[ctx objectTraversalStack] objectAtIndex:1];
396 url = [NSURL URLWithString:[obj baseURLInContext:ctx]];
397 return [[url path] stringByUnescapingURL];
400 - (id)redirectForUIDsAction {
401 NSMutableString *uri;
402 NSString *uidsString, *loc, *prevMethod, *userFolderID;
404 id <WOActionResults> r;
408 req = [[self context] request];
410 uidsString = [req formValueForKey:@"anaisUIDString"];
411 uidsString = [uidsString stringByTrimmingWhiteSpaces];
413 prevMethod = [req formValueForKey:@"previousMethod"];
414 if(prevMethod == nil)
417 uri = [[NSMutableString alloc] initWithString:[self _userFolderURI]];
418 /* if we have more than one entry, use groups - otherwise don't */
419 useGroups = [uidsString rangeOfString:@","].length > 0;
420 userFolderID = [uri lastPathComponent];
424 uids = [uidsString componentsSeparatedByString:@","];
425 /* guarantee that our id is the first */
426 if(((index = [uids indexOfObject:userFolderID]) != NSNotFound) &&
428 uids = [[uids mutableCopy] autorelease];
429 [(NSMutableArray *)uids removeObjectAtIndex:index];
430 [(NSMutableArray *)uids insertObject:userFolderID atIndex:0];
431 uidsString = [uids componentsJoinedByString:@","];
433 [uri appendString:@"Groups/_custom_"];
434 [uri appendString:uidsString];
435 [uri appendString:@"/"];
438 /* check if lastPathComponent is the base that we want to have */
439 if((([uidsString length] != 0) &&
440 (![userFolderID isEqualToString:uidsString]))) {
443 /* uri ends with an '/', so we have to adjust the range a little */
444 r = NSMakeRange(0, [uri length] - 1);
445 r = [uri rangeOfString:@"/"
446 options:NSBackwardsSearch
448 r = NSMakeRange(r.location + 1, [uri length] - r.location - 2);
449 [uri replaceCharactersInRange:r withString:uidsString];
452 [uri appendString:@"Calendar/"];
453 [uri appendString:prevMethod];
456 NSLog(@"%s redirect uri:%@",
460 loc = [self completeHrefForMethod:uri]; /* this might return uri! */
461 r = [self redirectToLocation:loc];
466 @end /* UIxCalView */