2006-11-02 22:50:12 +01:00
|
|
|
/* UIxCalMonthView.m - this file is part of SOGo
|
|
|
|
*
|
2007-03-13 00:06:48 +01:00
|
|
|
* Copyright (C) 2006, 2007 Inverse groupe conseil
|
2006-11-02 22:50:12 +01:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSCalendarDate.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
|
|
|
#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
|
|
|
|
|
|
|
|
#import <SOGoUI/SOGoAptFormatter.h>
|
|
|
|
#import <SOGoUI/SOGoDateFormatter.h>
|
|
|
|
|
|
|
|
#import "UIxCalMonthView.h"
|
|
|
|
|
|
|
|
@implementation UIxCalMonthView
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
NSTimeZone *tz;
|
|
|
|
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
tz = [[self clientObject] userTimeZone];
|
|
|
|
|
|
|
|
monthAptFormatter
|
|
|
|
= [[SOGoAptFormatter alloc] initWithDisplayTimeZone: tz];
|
|
|
|
[monthAptFormatter setShortMonthTitleOnly];
|
|
|
|
dateFormatter = [[SOGoDateFormatter alloc]
|
|
|
|
initWithLocale: [self locale]];
|
|
|
|
sortedAppointments = [NSMutableDictionary new];
|
2007-03-13 00:06:48 +01:00
|
|
|
daysToDisplay = nil;
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SOGoAptFormatter *) monthAptFormatter
|
|
|
|
{
|
|
|
|
return monthAptFormatter;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-03-13 00:06:48 +01:00
|
|
|
[daysToDisplay release];
|
2006-11-02 22:50:12 +01:00
|
|
|
[monthAptFormatter release];
|
|
|
|
[dateFormatter release];
|
|
|
|
[sortedAppointments release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _addEventToSortedEvents: (NSDictionary *) newEvent
|
|
|
|
{
|
|
|
|
NSMutableArray *eventArray;
|
|
|
|
NSString *dayId;
|
|
|
|
|
|
|
|
dayId = [[newEvent objectForKey: @"startDate"] shortDateString];
|
|
|
|
eventArray = [sortedAppointments objectForKey: dayId];
|
|
|
|
if (!eventArray)
|
|
|
|
{
|
|
|
|
eventArray = [NSMutableArray new];
|
|
|
|
[eventArray autorelease];
|
|
|
|
[sortedAppointments setObject: eventArray forKey: dayId];
|
|
|
|
}
|
|
|
|
[eventArray addObject: newEvent];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) defaultAction
|
|
|
|
{
|
|
|
|
NSEnumerator *events;
|
|
|
|
NSDictionary *currentEvent;
|
|
|
|
|
|
|
|
events = [[self fetchCoreAppointmentsInfos] objectEnumerator];
|
|
|
|
currentEvent = [events nextObject];
|
|
|
|
while (currentEvent)
|
|
|
|
{
|
|
|
|
[self _addEventToSortedEvents: currentEvent];
|
|
|
|
currentEvent = [events nextObject];
|
2006-11-03 20:39:54 +01:00
|
|
|
// NSLog (@"event:\n'%@'", currentEvent);
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-03-13 00:06:48 +01:00
|
|
|
- (NSArray *) headerDaysToDisplay
|
|
|
|
{
|
|
|
|
NSMutableArray *headerDaysToDisplay;
|
|
|
|
unsigned int counter;
|
|
|
|
|
|
|
|
headerDaysToDisplay = [NSMutableArray arrayWithCapacity: 7];
|
|
|
|
currentTableDay = [[self selectedDate] mondayOfWeek];
|
|
|
|
for (counter = 0; counter < 7; counter++)
|
|
|
|
{
|
|
|
|
[headerDaysToDisplay addObject: currentTableDay];
|
|
|
|
currentTableDay = [currentTableDay tomorrow];
|
|
|
|
}
|
|
|
|
|
|
|
|
return headerDaysToDisplay;
|
|
|
|
}
|
|
|
|
|
2006-11-02 22:50:12 +01:00
|
|
|
- (NSArray *) daysToDisplay
|
|
|
|
{
|
2007-03-13 00:06:48 +01:00
|
|
|
NSMutableArray *days[7];
|
|
|
|
unsigned int counter;
|
|
|
|
NSCalendarDate *firstOfAllDays, *lastDayOfMonth;
|
2006-11-02 22:50:12 +01:00
|
|
|
|
2007-03-13 00:06:48 +01:00
|
|
|
if (!daysToDisplay)
|
2006-11-02 22:50:12 +01:00
|
|
|
{
|
2007-03-13 00:06:48 +01:00
|
|
|
firstOfAllDays = [[[self selectedDate] firstDayOfMonth] mondayOfWeek];
|
|
|
|
lastDayOfMonth = [[self selectedDate] lastDayOfMonth];
|
|
|
|
for (counter = 0; counter < 7; counter++)
|
|
|
|
{
|
|
|
|
days[counter] = [NSMutableArray new];
|
|
|
|
[days[counter] autorelease];
|
|
|
|
}
|
|
|
|
currentTableDay = firstOfAllDays;
|
|
|
|
while ([currentTableDay earlierDate: lastDayOfMonth] == currentTableDay)
|
|
|
|
for (counter = 0; counter < 7; counter++)
|
|
|
|
{
|
|
|
|
[days[counter] addObject: currentTableDay];
|
|
|
|
currentTableDay = [currentTableDay tomorrow];
|
|
|
|
}
|
|
|
|
daysToDisplay = [NSArray arrayWithObjects: days count: 7];
|
|
|
|
[daysToDisplay retain];
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return daysToDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) labelForCurrentDayToDisplay
|
|
|
|
{
|
|
|
|
return [dateFormatter fullDayOfWeek: [currentTableDay dayOfWeek]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) _dateQueryParametersWithOffset: (int) monthsOffset
|
|
|
|
{
|
|
|
|
NSCalendarDate *date;
|
|
|
|
|
|
|
|
date = [[self selectedDate] dateByAddingYears: 0 months: monthsOffset
|
|
|
|
days: 0 hours: 0 minutes: 0 seconds: 0];
|
|
|
|
|
|
|
|
return [self queryParametersBySettingSelectedDate: date];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) monthBeforePrevMonthQueryParameters
|
|
|
|
{
|
|
|
|
return [self _dateQueryParametersWithOffset: -2];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) prevMonthQueryParameters
|
|
|
|
{
|
|
|
|
return [self _dateQueryParametersWithOffset: -1];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) nextMonthQueryParameters
|
|
|
|
{
|
|
|
|
return [self _dateQueryParametersWithOffset: 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) monthAfterNextMonthQueryParameters
|
|
|
|
{
|
|
|
|
return [self _dateQueryParametersWithOffset: 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _monthNameWithOffsetFromThisMonth: (int) offset
|
|
|
|
{
|
|
|
|
NSCalendarDate *date;
|
|
|
|
|
|
|
|
date = [[self selectedDate] dateByAddingYears: 0 months: offset days: 0];
|
|
|
|
|
|
|
|
return [self localizedNameForMonthOfYear: [date monthOfYear]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) monthNameOfTwoMonthAgo
|
|
|
|
{
|
|
|
|
return [self _monthNameWithOffsetFromThisMonth: -2];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) monthNameOfOneMonthAgo
|
|
|
|
{
|
|
|
|
return [self _monthNameWithOffsetFromThisMonth: -1];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) monthNameOfThisMonth
|
|
|
|
{
|
|
|
|
return [self _monthNameWithOffsetFromThisMonth: 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) monthNameOfNextMonth
|
|
|
|
{
|
|
|
|
return [self _monthNameWithOffsetFromThisMonth: 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) monthNameOfTheMonthAfterNextMonth
|
|
|
|
{
|
|
|
|
return [self _monthNameWithOffsetFromThisMonth: 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* template accessors */
|
|
|
|
- (void) setCurrentTableDay: (NSCalendarDate *) newCurrentTableDay
|
|
|
|
{
|
|
|
|
currentTableDay = newCurrentTableDay;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) currentTableDay
|
|
|
|
{
|
|
|
|
return currentTableDay;
|
|
|
|
}
|
|
|
|
|
2007-03-13 00:06:48 +01:00
|
|
|
- (void) setCurrentTableColumn: (NSArray *) newCurrentTableColumn
|
2006-11-02 22:50:12 +01:00
|
|
|
{
|
2007-03-13 00:06:48 +01:00
|
|
|
currentTableColumn = newCurrentTableColumn;
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
2007-03-13 00:06:48 +01:00
|
|
|
- (NSArray *) currentTableColumn
|
2006-11-02 22:50:12 +01:00
|
|
|
{
|
2007-03-13 00:06:48 +01:00
|
|
|
return currentTableColumn;
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) labelForCurrentDayCell
|
|
|
|
{
|
|
|
|
NSCalendarDate *lastDayOfMonth;
|
|
|
|
NSString *label, *monthOfYear;
|
|
|
|
int dayOfMonth;
|
|
|
|
|
|
|
|
dayOfMonth = [currentTableDay dayOfMonth];
|
|
|
|
lastDayOfMonth = [currentTableDay lastDayOfMonth];
|
|
|
|
if (dayOfMonth == 1
|
|
|
|
|| [currentTableDay isDateOnSameDay: lastDayOfMonth])
|
|
|
|
{
|
|
|
|
monthOfYear
|
|
|
|
= [dateFormatter shortMonthOfYear: [currentTableDay monthOfYear]];
|
|
|
|
label = [NSString stringWithFormat: @"%d %@", dayOfMonth, monthOfYear];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
label = [NSString stringWithFormat: @"%d", dayOfMonth];
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2007-03-13 00:06:48 +01:00
|
|
|
- (NSString *) headerDayCellClasses
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"headerDay day%d",
|
|
|
|
[currentTableDay dayOfWeek]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) dayHeaderNumber
|
|
|
|
{
|
|
|
|
NSString *nameOfMonth, *dayHeaderNumber;
|
|
|
|
unsigned int dayOfMonth;
|
|
|
|
|
|
|
|
dayOfMonth = [currentTableDay dayOfMonth];
|
|
|
|
if (dayOfMonth == 1
|
|
|
|
|| [currentTableDay isDateOnSameDay: [currentTableDay lastDayOfMonth]])
|
|
|
|
{
|
|
|
|
nameOfMonth
|
|
|
|
= [self localizedNameForMonthOfYear: [currentTableDay monthOfYear]];
|
|
|
|
dayHeaderNumber = [NSString stringWithFormat: @"%d %@", dayOfMonth,
|
|
|
|
nameOfMonth];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dayHeaderNumber = [NSString stringWithFormat: @"%d", dayOfMonth];
|
|
|
|
|
|
|
|
return dayHeaderNumber;
|
|
|
|
}
|
|
|
|
|
2006-11-02 22:50:12 +01:00
|
|
|
- (NSString *) dayCellClasses
|
|
|
|
{
|
|
|
|
NSMutableString *classes;
|
|
|
|
NSCalendarDate *selectedDate;
|
2007-03-13 00:06:48 +01:00
|
|
|
int dayOfWeek, numberOfWeeks;
|
2006-11-02 22:50:12 +01:00
|
|
|
|
|
|
|
classes = [NSMutableString new];
|
|
|
|
[classes autorelease];
|
2007-03-13 00:06:48 +01:00
|
|
|
|
2006-11-02 22:50:12 +01:00
|
|
|
dayOfWeek = [currentTableDay dayOfWeek];
|
2007-03-13 00:06:48 +01:00
|
|
|
numberOfWeeks = [currentTableColumn count];
|
|
|
|
|
|
|
|
[classes appendFormat: @"day weekOf%d week%dof%d day%d",
|
|
|
|
numberOfWeeks,
|
|
|
|
[currentTableColumn indexOfObject: currentTableDay],
|
|
|
|
numberOfWeeks, dayOfWeek];
|
2006-11-02 22:50:12 +01:00
|
|
|
if (dayOfWeek == 0 || dayOfWeek == 6)
|
|
|
|
[classes appendString: @" weekEndDay"];
|
|
|
|
selectedDate = [self selectedDate];
|
|
|
|
if (![[currentTableDay firstDayOfMonth]
|
|
|
|
isDateOnSameDay: [selectedDate firstDayOfMonth]])
|
|
|
|
[classes appendString: @" dayOfAnotherMonth"];
|
|
|
|
if ([currentTableDay isToday])
|
|
|
|
[classes appendString: @" dayOfToday"];
|
|
|
|
if ([selectedDate isDateOnSameDay: currentTableDay])
|
|
|
|
[classes appendString: @" selectedDay"];
|
|
|
|
|
|
|
|
return classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) _rangeOf7DaysForWeekStartingOn: (NSCalendarDate *) weekStart
|
|
|
|
{
|
|
|
|
unsigned int count;
|
|
|
|
NSMutableArray *range;
|
|
|
|
NSCalendarDate *currentDate;
|
|
|
|
|
|
|
|
range = [NSMutableArray arrayWithCapacity: 7];
|
|
|
|
currentDate = weekStart;
|
|
|
|
for (count = 0; count < 7; count++)
|
|
|
|
{
|
|
|
|
[range addObject: currentDate];
|
|
|
|
currentDate = [currentDate dateByAddingYears: 0 months: 0 days: 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) startDate
|
|
|
|
{
|
|
|
|
NSCalendarDate *firstDayOfMonth;
|
|
|
|
|
|
|
|
firstDayOfMonth = [[self selectedDate] firstDayOfMonth];
|
|
|
|
|
|
|
|
return [firstDayOfMonth mondayOfWeek];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) endDate
|
|
|
|
{
|
|
|
|
NSCalendarDate *lastDayOfMonth;
|
|
|
|
|
|
|
|
lastDayOfMonth = [[self selectedDate] lastDayOfMonth];
|
|
|
|
|
|
|
|
return [[lastDayOfMonth mondayOfWeek] dateByAddingYears: 0 months: 0 days: 6];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) aptsForCurrentDate
|
|
|
|
{
|
|
|
|
return [sortedAppointments objectForKey: [currentTableDay shortDateString]];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|