2006-11-02 22:50:12 +01:00
|
|
|
/* UIxCalMonthView.m - this file is part of SOGo
|
|
|
|
*
|
2015-10-02 21:13:30 +02:00
|
|
|
* Copyright (C) 2006-2015 Inverse inc.
|
2006-11-02 22:50:12 +01:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
2010-06-23 20:13:48 +02:00
|
|
|
#import <NGObjWeb/WOApplication.h>
|
|
|
|
|
2006-11-02 22:50:12 +01:00
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
|
|
|
#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
|
|
|
|
|
|
|
|
#import <SOGoUI/SOGoAptFormatter.h>
|
2011-02-03 17:12:22 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
|
|
|
#import <SOGo/WOResourceManager+SOGo.h>
|
2006-11-02 22:50:12 +01:00
|
|
|
|
|
|
|
#import "UIxCalMonthView.h"
|
|
|
|
|
|
|
|
@implementation UIxCalMonthView
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2007-06-19 21:42:25 +02:00
|
|
|
// monthAptFormatter
|
|
|
|
// = [[SOGoAptFormatter alloc] initWithDisplayTimeZone: timeZone];
|
|
|
|
// [monthAptFormatter setShortMonthTitleOnly];
|
|
|
|
// dateFormatter = [[SOGoDateFormatter alloc]
|
|
|
|
// initWithLocale: [self locale]];
|
|
|
|
dayNames = [locale objectForKey: NSWeekDayNameArray];
|
|
|
|
[dayNames retain];
|
|
|
|
monthNames = [locale objectForKey: NSMonthNameArray];
|
|
|
|
[monthNames retain];
|
2008-07-18 04:06:31 +02:00
|
|
|
weeksToDisplay = nil;
|
|
|
|
currentTableDay = nil;
|
|
|
|
currentWeek = nil;
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-06-19 21:42:25 +02:00
|
|
|
[monthNames release];
|
|
|
|
[dayNames release];
|
2008-07-18 04:06:31 +02:00
|
|
|
[weeksToDisplay release];
|
|
|
|
[currentTableDay release];
|
|
|
|
[currentWeek release];
|
2006-11-02 22:50:12 +01:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2009-06-09 23:25:41 +02:00
|
|
|
- (id <WOActionResults>) defaultAction
|
|
|
|
{
|
|
|
|
[super setCurrentView: @"monthview"];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-03-13 00:06:48 +01:00
|
|
|
- (NSArray *) headerDaysToDisplay
|
|
|
|
{
|
|
|
|
NSMutableArray *headerDaysToDisplay;
|
|
|
|
unsigned int counter;
|
2008-07-18 04:06:31 +02:00
|
|
|
NSCalendarDate *currentDate;
|
2007-03-13 00:06:48 +01:00
|
|
|
|
|
|
|
headerDaysToDisplay = [NSMutableArray arrayWithCapacity: 7];
|
2008-07-18 21:25:26 +02:00
|
|
|
currentDate
|
|
|
|
= [[context activeUser] firstDayOfWeekForDate: [self selectedDate]];
|
2007-03-13 00:06:48 +01:00
|
|
|
for (counter = 0; counter < 7; counter++)
|
|
|
|
{
|
2008-07-18 04:06:31 +02:00
|
|
|
[headerDaysToDisplay addObject: currentDate];
|
|
|
|
currentDate = [currentDate tomorrow];
|
2007-03-13 00:06:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return headerDaysToDisplay;
|
|
|
|
}
|
|
|
|
|
2008-07-18 04:06:31 +02:00
|
|
|
- (NSArray *) weeksToDisplay
|
2006-11-02 22:50:12 +01:00
|
|
|
{
|
2008-07-18 04:06:31 +02:00
|
|
|
NSMutableArray *week;
|
|
|
|
unsigned int counter, day;
|
|
|
|
NSCalendarDate *currentDate, *selectedDate, *lastDayOfMonth, *firstOfAllDays;
|
|
|
|
unsigned int firstToLast, weeks;
|
2006-11-02 22:50:12 +01:00
|
|
|
|
2008-07-18 04:06:31 +02:00
|
|
|
if (!weeksToDisplay)
|
2006-11-02 22:50:12 +01:00
|
|
|
{
|
2008-07-18 04:06:31 +02:00
|
|
|
selectedDate = [self selectedDate];
|
2008-07-18 21:25:26 +02:00
|
|
|
firstOfAllDays
|
|
|
|
= [[context activeUser] firstDayOfWeekForDate:
|
|
|
|
[selectedDate firstDayOfMonth]];
|
2008-07-18 04:06:31 +02:00
|
|
|
lastDayOfMonth = [selectedDate lastDayOfMonth];
|
|
|
|
firstToLast = ([lastDayOfMonth timeIntervalSinceDate: firstOfAllDays]
|
2008-07-28 23:22:43 +02:00
|
|
|
/ 86400) + 1;
|
2008-07-18 04:06:31 +02:00
|
|
|
weeks = firstToLast / 7;
|
|
|
|
if ((firstToLast % 7))
|
|
|
|
weeks++;
|
|
|
|
weeksToDisplay = [NSMutableArray arrayWithCapacity: weeks];
|
|
|
|
currentDate = firstOfAllDays;
|
|
|
|
for (counter = 0; counter < weeks; counter++)
|
|
|
|
{
|
|
|
|
week = [NSMutableArray arrayWithCapacity: 7];
|
|
|
|
for (day = 0; day < 7; day++)
|
|
|
|
{
|
|
|
|
[week addObject: currentDate];
|
|
|
|
currentDate = [currentDate tomorrow];
|
|
|
|
}
|
|
|
|
[weeksToDisplay addObject: week];
|
|
|
|
}
|
|
|
|
[weeksToDisplay retain];
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
2008-07-18 04:06:31 +02:00
|
|
|
return weeksToDisplay;
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) labelForCurrentDayToDisplay
|
|
|
|
{
|
2007-06-19 21:42:25 +02:00
|
|
|
return [dayNames objectAtIndex: [currentTableDay dayOfWeek]];
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) _dateQueryParametersWithOffset: (int) monthsOffset
|
|
|
|
{
|
2008-07-18 21:25:26 +02:00
|
|
|
NSCalendarDate *date, *firstDay;
|
2006-11-02 22:50:12 +01:00
|
|
|
|
2008-07-18 21:25:26 +02:00
|
|
|
firstDay = [[self selectedDate] firstDayOfMonth];
|
|
|
|
date = [firstDay dateByAddingYears: 0 months: monthsOffset
|
|
|
|
days: 0 hours: 0 minutes: 0 seconds: 0];
|
2006-11-02 22:50:12 +01:00
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2008-08-15 06:41:06 +02:00
|
|
|
- (NSString *) _monthNameWithOffsetFromThisMonth: (int) monthsOffset
|
2006-11-02 22:50:12 +01:00
|
|
|
{
|
2008-08-15 06:41:06 +02:00
|
|
|
NSCalendarDate *date, *firstDay;
|
2006-11-02 22:50:12 +01:00
|
|
|
|
2008-08-15 06:41:06 +02:00
|
|
|
firstDay = [[self selectedDate] firstDayOfMonth];
|
|
|
|
date = [firstDay dateByAddingYears: 0 months: monthsOffset
|
|
|
|
days: 0 hours: 0 minutes: 0 seconds: 0];
|
2006-11-02 22:50:12 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2008-07-18 04:06:31 +02:00
|
|
|
ASSIGN (currentTableDay, newCurrentTableDay);
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) currentTableDay
|
|
|
|
{
|
|
|
|
return currentTableDay;
|
|
|
|
}
|
|
|
|
|
2010-02-13 00:24:24 +01:00
|
|
|
- (NSString *) currentDayId
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"day%@", [currentTableDay shortDateString]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) currentDayNumber
|
|
|
|
{
|
|
|
|
return ([currentWeek indexOfObject: currentTableDay]
|
|
|
|
+ [weeksToDisplay indexOfObject: currentWeek] * 7);
|
|
|
|
}
|
|
|
|
|
2008-07-18 04:06:31 +02:00
|
|
|
- (void) setCurrentWeek: (NSArray *) newCurrentWeek
|
2006-11-02 22:50:12 +01:00
|
|
|
{
|
2008-07-18 04:06:31 +02:00
|
|
|
ASSIGN (currentWeek, newCurrentWeek);
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
2008-07-18 04:06:31 +02:00
|
|
|
- (NSArray *) currentWeek
|
2006-11-02 22:50:12 +01:00
|
|
|
{
|
2008-07-18 04:06:31 +02:00
|
|
|
return currentWeek;
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
2007-03-13 00:06:48 +01:00
|
|
|
- (NSString *) headerDayCellClasses
|
|
|
|
{
|
2008-07-18 21:25:26 +02:00
|
|
|
unsigned int dayOfWeek;
|
|
|
|
|
|
|
|
dayOfWeek = [[context activeUser] dayOfWeekForDate: currentTableDay];
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"headerDay day%d", dayOfWeek];
|
2007-03-13 00:06:48 +01:00
|
|
|
}
|
|
|
|
|
2015-10-02 21:13:30 +02:00
|
|
|
- (NSString *) dayHeaderMonth
|
2007-03-13 00:06:48 +01:00
|
|
|
{
|
2015-10-02 21:13:30 +02:00
|
|
|
NSString *nameOfMonth = nil;
|
2007-03-13 00:06:48 +01:00
|
|
|
unsigned int dayOfMonth;
|
|
|
|
|
|
|
|
dayOfMonth = [currentTableDay dayOfMonth];
|
|
|
|
if (dayOfMonth == 1
|
|
|
|
|| [currentTableDay isDateOnSameDay: [currentTableDay lastDayOfMonth]])
|
|
|
|
{
|
2015-10-02 21:13:30 +02:00
|
|
|
nameOfMonth = [self localizedNameForMonthOfYear: [currentTableDay monthOfYear]];
|
2007-03-13 00:06:48 +01:00
|
|
|
}
|
|
|
|
|
2015-10-02 21:13:30 +02:00
|
|
|
return nameOfMonth;
|
2007-03-13 00:06:48 +01:00
|
|
|
}
|
|
|
|
|
2006-11-02 22:50:12 +01:00
|
|
|
- (NSString *) dayCellClasses
|
|
|
|
{
|
|
|
|
NSMutableString *classes;
|
|
|
|
NSCalendarDate *selectedDate;
|
2008-07-18 21:25:26 +02:00
|
|
|
unsigned int realDayOfWeek, dayOfWeek, numberOfWeeks;
|
2006-11-02 22:50:12 +01:00
|
|
|
|
2008-07-18 04:06:31 +02:00
|
|
|
classes = [NSMutableString string];
|
2007-03-13 00:06:48 +01:00
|
|
|
|
2008-07-18 21:25:26 +02:00
|
|
|
dayOfWeek = [[context activeUser] dayOfWeekForDate: currentTableDay];
|
|
|
|
realDayOfWeek = [currentTableDay dayOfWeek];
|
2008-07-18 04:06:31 +02:00
|
|
|
numberOfWeeks = [weeksToDisplay count];
|
2007-03-13 00:06:48 +01:00
|
|
|
|
|
|
|
[classes appendFormat: @"day weekOf%d week%dof%d day%d",
|
|
|
|
numberOfWeeks,
|
2008-07-18 04:06:31 +02:00
|
|
|
[weeksToDisplay indexOfObject: currentWeek],
|
2007-03-13 00:06:48 +01:00
|
|
|
numberOfWeeks, dayOfWeek];
|
2008-07-18 21:25:26 +02:00
|
|
|
if (realDayOfWeek == 0 || realDayOfWeek == 6)
|
2006-11-02 22:50:12 +01:00
|
|
|
[classes appendString: @" weekEndDay"];
|
|
|
|
selectedDate = [self selectedDate];
|
|
|
|
if (![[currentTableDay firstDayOfMonth]
|
|
|
|
isDateOnSameDay: [selectedDate firstDayOfMonth]])
|
|
|
|
[classes appendString: @" dayOfAnotherMonth"];
|
|
|
|
if ([currentTableDay isToday])
|
|
|
|
[classes appendString: @" dayOfToday"];
|
|
|
|
|
|
|
|
return classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) startDate
|
|
|
|
{
|
|
|
|
NSCalendarDate *firstDayOfMonth;
|
|
|
|
|
|
|
|
firstDayOfMonth = [[self selectedDate] firstDayOfMonth];
|
|
|
|
|
2008-07-18 21:25:26 +02:00
|
|
|
return [[context activeUser] firstDayOfWeekForDate: firstDayOfMonth];
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) endDate
|
|
|
|
{
|
2008-07-18 21:25:26 +02:00
|
|
|
NSCalendarDate *lastDayOfMonth, *firstDay;
|
2006-11-02 22:50:12 +01:00
|
|
|
|
|
|
|
lastDayOfMonth = [[self selectedDate] lastDayOfMonth];
|
2008-07-18 21:25:26 +02:00
|
|
|
firstDay = [[context activeUser] firstDayOfWeekForDate: lastDayOfMonth];
|
2006-11-02 22:50:12 +01:00
|
|
|
|
2008-07-18 21:25:26 +02:00
|
|
|
return [firstDay dateByAddingYears: 0 months: 0 days: 6];
|
2006-11-02 22:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|