2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004 SKYRIX Software AG
|
2016-05-06 20:14:45 +02:00
|
|
|
Copyright (C) 2006-2016 Inverse inc.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2016-05-06 20:14:45 +02:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2006-06-15 21:34:10 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
2016-05-06 20:14:45 +02:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2006-06-15 21:34:10 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2016-05-06 20:14:45 +02:00
|
|
|
License along with SOGo; see the file COPYING. If not, write to the
|
2006-06-15 21:34:10 +02:00
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2006-08-22 21:23:58 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-08-22 21:23:58 +02:00
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-08-22 21:23:58 +02:00
|
|
|
#import "UIxCalDayView.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-03-29 20:13:17 +02:00
|
|
|
// @interface UIxCalDayView (PrivateAPI)
|
|
|
|
// - (BOOL)isCurrentDateInApt:(id)_apt;
|
|
|
|
// - (NSArray *)_getDatesFrom:(NSCalendarDate *)_from to:(NSCalendarDate *)_to;
|
|
|
|
// @end
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation UIxCalDayView
|
|
|
|
|
2007-03-29 20:13:17 +02:00
|
|
|
// - (void) dealloc
|
|
|
|
// {
|
|
|
|
// [self->currentDate release];
|
|
|
|
// [super dealloc];
|
|
|
|
// }
|
|
|
|
|
2009-06-09 23:25:41 +02:00
|
|
|
- (id <WOActionResults>) defaultAction
|
|
|
|
{
|
|
|
|
[super setCurrentView: @"dayview"];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-03-29 20:13:17 +02:00
|
|
|
// - (void) setCurrentDate: (NSCalendarDate *) _date
|
|
|
|
// {
|
|
|
|
// ASSIGN(self->currentDate, _date);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSCalendarDate *) currentDate
|
|
|
|
// {
|
|
|
|
// return self->currentDate;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (BOOL) isCurrentDateInApt
|
|
|
|
// {
|
|
|
|
// return [self isCurrentDateInApt: [self appointment]];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (BOOL) isCurrentDateInApt: (id) _apt
|
|
|
|
// {
|
|
|
|
// NSCalendarDate *dateStart, *dateEnd, *aptStart, *aptEnd;
|
|
|
|
// NGCalendarDateRange *dateRange, *aptRange;
|
2016-05-06 20:14:45 +02:00
|
|
|
|
2007-03-29 20:13:17 +02:00
|
|
|
// dateStart = self->currentDate;
|
|
|
|
// dateEnd = [dateStart dateByAddingYears:0 months:0 days:0
|
|
|
|
// hours:1 minutes:0 seconds:0];
|
|
|
|
// dateRange = [NGCalendarDateRange calendarDateRangeWithStartDate:dateStart
|
|
|
|
// endDate:dateEnd];
|
|
|
|
// aptStart = [self->appointment valueForKey:@"startDate"];
|
|
|
|
// aptEnd = [self->appointment valueForKey:@"endDate"];
|
|
|
|
// aptRange = [NGCalendarDateRange calendarDateRangeWithStartDate:aptStart
|
|
|
|
// endDate:aptEnd];
|
|
|
|
|
|
|
|
// return [dateRange doesIntersectWithDateRange:aptRange];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSArray *) dateRange
|
|
|
|
// {
|
|
|
|
// /* default range is from dayStartHour to dayEndHour. Any values before
|
|
|
|
// or after are also fine */
|
|
|
|
|
|
|
|
// NSCalendarDate *min, *max;
|
|
|
|
// NSArray *aptDateRanges;
|
|
|
|
|
|
|
|
// min = [[self startDate] hour:[self dayStartHour] minute:0];
|
|
|
|
// max = [[self startDate] hour:[self dayEndHour] minute:0];
|
|
|
|
|
|
|
|
// aptDateRanges = [[self appointments] valueForKey: @"startDate"];
|
|
|
|
// if([aptDateRanges count] != 0) {
|
|
|
|
// NSCalendarDate *d;
|
|
|
|
|
|
|
|
// aptDateRanges
|
|
|
|
// = [aptDateRanges sortedArrayUsingSelector: @selector(compareAscending:)];
|
|
|
|
// d = [aptDateRanges objectAtIndex:0];
|
|
|
|
// if ([d isDateOnSameDay:min])
|
|
|
|
// min = (NSCalendarDate *)[d earlierDate:min];
|
|
|
|
// d = [aptDateRanges objectAtIndex:[aptDateRanges count] - 1];
|
|
|
|
// if ([d isDateOnSameDay:max])
|
|
|
|
// max = (NSCalendarDate *)[d laterDate:max];
|
|
|
|
// }
|
2016-05-06 20:14:45 +02:00
|
|
|
|
2007-03-29 20:13:17 +02:00
|
|
|
// return [self _getDatesFrom:min to:max];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSArray *) _getDatesFrom: (NSCalendarDate *) _from
|
|
|
|
// to: (NSCalendarDate *) _to
|
|
|
|
// {
|
|
|
|
// NSMutableArray *dates;
|
|
|
|
// unsigned i, count, offset;
|
|
|
|
|
|
|
|
// offset = [_from hourOfDay];
|
|
|
|
// count = ([_to hourOfDay] + 1) - offset;
|
|
|
|
// dates = [[NSMutableArray alloc] initWithCapacity:count];
|
|
|
|
// for(i = 0; i < count; i++) {
|
|
|
|
// NSCalendarDate *date;
|
2016-05-06 20:14:45 +02:00
|
|
|
|
2007-03-29 20:13:17 +02:00
|
|
|
// date = [_from hour:offset + i minute:0];
|
|
|
|
// [dates addObject:date];
|
|
|
|
// }
|
|
|
|
// return [dates autorelease];
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* URLs */
|
|
|
|
|
2006-08-19 00:56:47 +02:00
|
|
|
- (NSDictionary *) dayBeforePrevDayQueryParameters
|
|
|
|
{
|
|
|
|
return [self _dateQueryParametersWithOffset: -2];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-08-19 00:56:47 +02:00
|
|
|
- (NSDictionary *) prevDayQueryParameters
|
|
|
|
{
|
2016-05-06 20:14:45 +02:00
|
|
|
return [self _dateQueryParametersWithOffset: [self _nextValidOffset: -1]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-08-19 00:56:47 +02:00
|
|
|
- (NSDictionary *) nextDayQueryParameters
|
|
|
|
{
|
2016-05-06 20:14:45 +02:00
|
|
|
return [self _dateQueryParametersWithOffset: [self _nextValidOffset: +1]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-08-19 00:56:47 +02:00
|
|
|
- (NSDictionary *) dayAfterNextDayQueryParameters
|
|
|
|
{
|
|
|
|
return [self _dateQueryParametersWithOffset: 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) currentDateQueryParameters
|
|
|
|
{
|
|
|
|
NSMutableDictionary *qp;
|
|
|
|
NSString *hmString;
|
|
|
|
NSCalendarDate *date;
|
2016-05-06 20:14:45 +02:00
|
|
|
|
2007-03-29 20:13:17 +02:00
|
|
|
date = [self selectedDate];
|
2006-10-12 23:45:24 +02:00
|
|
|
hmString = [NSString stringWithFormat:@"%.2d%.2d",
|
2015-10-31 07:10:03 +01:00
|
|
|
(int)[date hourOfDay], (int)[date minuteOfHour]];
|
2006-08-19 00:56:47 +02:00
|
|
|
qp = [[self queryParameters] mutableCopy];
|
|
|
|
[self setSelectedDateQueryParameter:date inDictionary:qp];
|
2007-03-29 20:13:17 +02:00
|
|
|
[qp setObject: hmString forKey:@"hm"];
|
2006-08-19 00:56:47 +02:00
|
|
|
return [qp autorelease];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* fetching */
|
|
|
|
|
2006-08-22 21:23:58 +02:00
|
|
|
- (NSCalendarDate *) startDate
|
|
|
|
{
|
2006-08-19 00:56:47 +02:00
|
|
|
return [[self selectedDate] beginOfDay];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* appointments */
|
|
|
|
|
2007-03-29 20:13:17 +02:00
|
|
|
// - (NSArray *)allDayApts {
|
|
|
|
// NSCalendarDate *start;
|
|
|
|
// NSArray *apts;
|
|
|
|
// NSMutableArray *filtered;
|
|
|
|
// unsigned i, count;
|
2016-05-06 20:14:45 +02:00
|
|
|
|
2007-03-29 20:13:17 +02:00
|
|
|
// if (self->allDayApts)
|
|
|
|
// return self->allDayApts;
|
|
|
|
|
|
|
|
// start = [self startDate];
|
|
|
|
// apts = [self appointments];
|
|
|
|
// filtered = [[NSMutableArray alloc] initWithCapacity:1];
|
|
|
|
// count = [apts count];
|
|
|
|
// for (i = 0; i < count; i++) {
|
|
|
|
// id apt;
|
|
|
|
// NSNumber *bv;
|
2016-05-06 20:14:45 +02:00
|
|
|
|
2007-03-29 20:13:17 +02:00
|
|
|
// apt = [apts objectAtIndex:i];
|
|
|
|
// bv = [apt valueForKey:@"isallday"];
|
|
|
|
// if ([bv boolValue]) {
|
|
|
|
// [filtered addObject:apt];
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// NSCalendarDate *aptStartDate;
|
|
|
|
|
|
|
|
// aptStartDate = [apt valueForKey:@"startDate"];
|
|
|
|
// if([aptStartDate isLessThan:start]) {
|
|
|
|
// [filtered addObject:apt];
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2016-05-06 20:14:45 +02:00
|
|
|
|
2007-03-29 20:13:17 +02:00
|
|
|
// ASSIGN(self->allDayApts, filtered);
|
|
|
|
// [filtered release];
|
|
|
|
// return self->allDayApts;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (BOOL) hasAptsForCurrentDate
|
|
|
|
// {
|
|
|
|
// return [[self aptsForCurrentDate] count] != 0;
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-08-19 00:56:47 +02:00
|
|
|
- (NSString *) _dayNameWithOffsetFromToday: (int) offset
|
|
|
|
{
|
|
|
|
NSCalendarDate *date;
|
|
|
|
|
|
|
|
date = [[self selectedDate] dateByAddingYears: 0
|
2016-05-06 20:14:45 +02:00
|
|
|
months: 0
|
|
|
|
days: offset];
|
2006-08-19 00:56:47 +02:00
|
|
|
|
|
|
|
return [self localizedNameForDayOfWeek: [date dayOfWeek]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) dayBeforeYesterdayName
|
|
|
|
{
|
|
|
|
return [self _dayNameWithOffsetFromToday: -2];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) yesterdayName
|
|
|
|
{
|
2016-05-06 20:14:45 +02:00
|
|
|
return [self _dayNameWithOffsetFromToday: [self _nextValidOffset: -1]];
|
2006-08-19 00:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentDayName
|
|
|
|
{
|
|
|
|
return [self _dayNameWithOffsetFromToday: 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) tomorrowName
|
|
|
|
{
|
2016-05-06 20:14:45 +02:00
|
|
|
return [self _dayNameWithOffsetFromToday: [self _nextValidOffset: +1]];
|
2006-08-19 00:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) dayAfterTomorrowName
|
|
|
|
{
|
|
|
|
return [self _dayNameWithOffsetFromToday: 2];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end
|