2007-06-07 22:49:06 +02:00
|
|
|
/* UIxCalListingActions.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* 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/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
|
|
|
#import <Foundation/NSNull.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
|
|
|
|
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2007-06-19 20:08:16 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoDateFormatter.h>
|
2007-06-07 22:49:06 +02:00
|
|
|
#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
|
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SoObjects/SOGo/NSObject+Utilities.h>
|
|
|
|
#import <SoObjects/Appointments/SOGoAppointmentFolder.h>
|
|
|
|
|
2007-09-11 21:36:40 +02:00
|
|
|
#import <UI/Common/WODirectAction+SOGo.h>
|
|
|
|
|
2007-06-13 21:33:31 +02:00
|
|
|
#import "NSArray+Scheduler.h"
|
2007-06-11 23:28:28 +02:00
|
|
|
|
2007-06-07 22:49:06 +02:00
|
|
|
#import "UIxCalListingActions.h"
|
|
|
|
|
|
|
|
@implementation UIxCalListingActions
|
|
|
|
|
2007-06-11 23:43:37 +02:00
|
|
|
- (id) initWithRequest: (WORequest *) newRequest
|
2007-06-07 22:49:06 +02:00
|
|
|
{
|
2007-06-19 20:08:16 +02:00
|
|
|
SOGoUser *user;
|
2007-06-11 23:28:28 +02:00
|
|
|
|
2007-06-11 23:43:37 +02:00
|
|
|
if ((self = [super initWithRequest: newRequest]))
|
2007-06-07 22:49:06 +02:00
|
|
|
{
|
|
|
|
componentsData = [NSMutableDictionary new];
|
|
|
|
startDate = nil;
|
|
|
|
endDate = nil;
|
2007-06-11 23:43:37 +02:00
|
|
|
ASSIGN (request, newRequest);
|
2007-06-19 20:08:16 +02:00
|
|
|
user = [[self context] activeUser];
|
|
|
|
dateFormatter = [user dateFormatterInContext: context];
|
|
|
|
ASSIGN (userTimeZone, [user timeZone]);
|
2007-06-11 23:43:37 +02:00
|
|
|
}
|
2007-06-07 22:49:06 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-06-11 23:28:28 +02:00
|
|
|
[dateFormatter release];
|
2007-06-11 23:43:37 +02:00
|
|
|
[request release];
|
2007-06-07 22:49:06 +02:00
|
|
|
[componentsData release];
|
|
|
|
[startDate release];
|
|
|
|
[endDate release];
|
2007-06-19 20:08:16 +02:00
|
|
|
[userTimeZone release];
|
2007-06-07 22:49:06 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-06-08 01:22:14 +02:00
|
|
|
- (void) _setupDatesWithPopup: (NSString *) popupValue
|
|
|
|
andUserTZ: (NSTimeZone *) userTZ
|
|
|
|
{
|
|
|
|
NSCalendarDate *newDate;
|
|
|
|
NSString *param;
|
|
|
|
|
|
|
|
if ([popupValue isEqualToString: @"view_today"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
|
|
|
endDate = [newDate endOfDay];
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_all"])
|
|
|
|
{
|
|
|
|
startDate = nil;
|
|
|
|
endDate = nil;
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_next7"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
|
|
|
endDate = [[startDate dateByAddingYears: 0 months: 0 days: 6] endOfDay];
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_next14"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
|
|
|
endDate = [[startDate dateByAddingYears: 0 months: 0 days: 13] endOfDay];
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_next31"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
|
|
|
endDate = [[startDate dateByAddingYears: 0 months: 0 days: 30] endOfDay];
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_thismonth"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [[newDate firstDayOfMonth] beginOfDay];
|
|
|
|
endDate = [[newDate lastDayOfMonth] endOfDay];
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_future"])
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
|
|
|
endDate = [NSCalendarDate distantFuture];
|
|
|
|
}
|
|
|
|
else if ([popupValue isEqualToString: @"view_selectedday"])
|
|
|
|
{
|
|
|
|
param = [request formValueForKey: @"day"];
|
|
|
|
if ([param length] > 0)
|
|
|
|
startDate = [[NSCalendarDate dateFromShortDateString: param
|
|
|
|
andShortTimeString: nil
|
|
|
|
inTimeZone: userTZ] beginOfDay];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newDate = [NSCalendarDate calendarDate];
|
|
|
|
[newDate setTimeZone: userTZ];
|
|
|
|
startDate = [newDate beginOfDay];
|
|
|
|
}
|
|
|
|
endDate = [startDate endOfDay];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-07 22:49:06 +02:00
|
|
|
- (void) _setupContext
|
|
|
|
{
|
|
|
|
SOGoUser *user;
|
|
|
|
NSTimeZone *userTZ;
|
|
|
|
NSString *param;
|
|
|
|
|
|
|
|
user = [context activeUser];
|
|
|
|
userLogin = [user login];
|
|
|
|
userTZ = [user timeZone];
|
|
|
|
|
2007-06-08 01:22:14 +02:00
|
|
|
param = [request formValueForKey: @"filterpopup"];
|
2007-06-07 22:49:06 +02:00
|
|
|
if ([param length] > 0)
|
2007-06-08 01:22:14 +02:00
|
|
|
[self _setupDatesWithPopup: param andUserTZ: userTZ];
|
2007-06-07 22:49:06 +02:00
|
|
|
else
|
2007-06-08 01:22:14 +02:00
|
|
|
{
|
|
|
|
param = [request formValueForKey: @"sd"];
|
|
|
|
if ([param length] > 0)
|
|
|
|
startDate = [[NSCalendarDate dateFromShortDateString: param
|
|
|
|
andShortTimeString: nil
|
|
|
|
inTimeZone: userTZ] beginOfDay];
|
|
|
|
else
|
|
|
|
startDate = nil;
|
|
|
|
|
2007-06-11 23:28:28 +02:00
|
|
|
param = [request formValueForKey: @"ed"];
|
2007-06-08 01:22:14 +02:00
|
|
|
if ([param length] > 0)
|
|
|
|
endDate = [[NSCalendarDate dateFromShortDateString: param
|
|
|
|
andShortTimeString: nil
|
|
|
|
inTimeZone: userTZ] endOfDay];
|
|
|
|
else
|
|
|
|
endDate = nil;
|
|
|
|
}
|
2007-06-07 22:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _updatePrivacyInComponent: (NSMutableDictionary *) component
|
|
|
|
fromFolder: (SOGoAppointmentFolder *) folder
|
|
|
|
{
|
|
|
|
int privacyFlag;
|
|
|
|
NSString *roleString;
|
|
|
|
|
|
|
|
privacyFlag = [[component objectForKey: @"classification"] intValue];
|
|
|
|
roleString = [folder roleForComponentsWithAccessClass: privacyFlag
|
|
|
|
forUser: userLogin];
|
|
|
|
if ([roleString isEqualToString: @"ComponentDAndTViewer"])
|
|
|
|
{
|
2007-07-24 20:45:52 +02:00
|
|
|
[component setObject: @"" forKey: @"c_title"];
|
|
|
|
[component setObject: @"" forKey: @"c_location"];
|
2007-06-07 22:49:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SOGoAppointmentFolder *) _aptFolder: (NSString *) folder
|
|
|
|
withClientObject: (SOGoAppointmentFolder *) clientObject
|
|
|
|
{
|
|
|
|
SOGoAppointmentFolder *aptFolder;
|
|
|
|
NSArray *folderParts;
|
|
|
|
|
|
|
|
if ([folder isEqualToString: @"/"])
|
|
|
|
aptFolder = clientObject;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
folderParts = [folder componentsSeparatedByString: @":"];
|
|
|
|
aptFolder
|
|
|
|
= [clientObject lookupCalendarFolderForUID:
|
|
|
|
[folderParts objectAtIndex: 0]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return aptFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) _activeCalendarFolders
|
|
|
|
{
|
|
|
|
NSMutableArray *activeFolders;
|
|
|
|
NSEnumerator *folders;
|
|
|
|
NSDictionary *currentFolderDict;
|
|
|
|
SOGoAppointmentFolder *currentFolder, *clientObject;
|
|
|
|
|
|
|
|
activeFolders = [NSMutableArray new];
|
|
|
|
[activeFolders autorelease];
|
|
|
|
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
|
|
|
|
folders = [[clientObject calendarFolders] objectEnumerator];
|
|
|
|
currentFolderDict = [folders nextObject];
|
|
|
|
while (currentFolderDict)
|
|
|
|
{
|
|
|
|
if ([[currentFolderDict objectForKey: @"active"] boolValue])
|
|
|
|
{
|
|
|
|
currentFolder
|
|
|
|
= [self _aptFolder: [currentFolderDict objectForKey: @"folder"]
|
|
|
|
withClientObject: clientObject];
|
|
|
|
[activeFolders addObject: currentFolder];
|
|
|
|
}
|
|
|
|
|
|
|
|
currentFolderDict = [folders nextObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
return activeFolders;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) _fetchFields: (NSArray *) fields
|
|
|
|
forComponentOfType: (NSString *) component
|
|
|
|
{
|
|
|
|
NSEnumerator *folders, *currentInfos;
|
|
|
|
SOGoAppointmentFolder *currentFolder;
|
|
|
|
NSMutableDictionary *infos, *currentInfo, *newInfo;
|
|
|
|
NSString *owner, *uid;
|
|
|
|
NSNull *marker;
|
|
|
|
|
|
|
|
marker = [NSNull null];
|
|
|
|
|
|
|
|
infos = [NSMutableDictionary dictionary];
|
|
|
|
folders = [[self _activeCalendarFolders] objectEnumerator];
|
|
|
|
currentFolder = [folders nextObject];
|
|
|
|
while (currentFolder)
|
|
|
|
{
|
|
|
|
owner = [currentFolder ownerInContext: context];
|
|
|
|
currentInfos = [[currentFolder fetchCoreInfosFrom: startDate
|
|
|
|
to: endDate
|
|
|
|
component: component] objectEnumerator];
|
|
|
|
newInfo = [currentInfos nextObject];
|
|
|
|
while (newInfo)
|
|
|
|
{
|
2007-07-24 20:45:52 +02:00
|
|
|
uid = [newInfo objectForKey: @"c_uid"];
|
2007-06-07 22:49:06 +02:00
|
|
|
currentInfo = [infos objectForKey: uid];
|
|
|
|
if (!currentInfo
|
|
|
|
|| [owner isEqualToString: userLogin])
|
|
|
|
{
|
|
|
|
[self _updatePrivacyInComponent: newInfo
|
|
|
|
fromFolder: currentFolder];
|
2007-07-24 20:45:52 +02:00
|
|
|
[newInfo setObject: owner forKey: @"c_owner"];
|
2007-06-07 22:49:06 +02:00
|
|
|
[infos setObject: [newInfo objectsForKeys: fields
|
|
|
|
notFoundMarker: marker]
|
|
|
|
forKey: uid];
|
|
|
|
}
|
|
|
|
newInfo = [currentInfos nextObject];
|
|
|
|
}
|
|
|
|
currentFolder = [folders nextObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [infos allValues];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) _responseWithData: (NSArray *) data
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
2007-09-11 21:36:40 +02:00
|
|
|
response = [self responseWithStatus: 200];
|
2007-06-07 22:49:06 +02:00
|
|
|
[response setHeader: @"text/plain; charset=utf-8"
|
|
|
|
forKey: @"content-type"];
|
|
|
|
[response appendContentString: [data jsonRepresentation]];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-06-19 20:08:16 +02:00
|
|
|
- (NSString *) _formattedDateForSeconds: (unsigned int) seconds
|
|
|
|
forAllDay: (BOOL) forAllDay
|
|
|
|
{
|
|
|
|
NSCalendarDate *date;
|
|
|
|
NSString *formattedDate;
|
|
|
|
|
|
|
|
date = [NSCalendarDate dateWithTimeIntervalSince1970: seconds];
|
|
|
|
[date setTimeZone: userTimeZone];
|
|
|
|
if (forAllDay)
|
|
|
|
formattedDate = [dateFormatter formattedDate: date];
|
|
|
|
else
|
|
|
|
formattedDate = [dateFormatter formattedDateAndTime: date];
|
|
|
|
|
|
|
|
return formattedDate;
|
|
|
|
}
|
|
|
|
|
2007-06-07 22:49:06 +02:00
|
|
|
- (WOResponse *) eventsListAction
|
|
|
|
{
|
2007-06-11 23:28:28 +02:00
|
|
|
NSArray *fields, *oldEvent;
|
|
|
|
NSEnumerator *events;
|
|
|
|
NSMutableArray *newEvents, *newEvent;
|
|
|
|
unsigned int interval;
|
2007-06-19 20:08:16 +02:00
|
|
|
BOOL isAllDay;
|
2007-06-07 22:49:06 +02:00
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
|
2007-06-11 23:28:28 +02:00
|
|
|
newEvents = [NSMutableArray array];
|
2007-07-24 20:45:52 +02:00
|
|
|
fields = [NSArray arrayWithObjects: @"c_name", @"c_owner", @"c_status",
|
|
|
|
@"c_title", @"c_startdate", @"c_enddate", @"c_location",
|
|
|
|
@"c_isallday", nil];
|
2007-06-11 23:28:28 +02:00
|
|
|
events = [[self _fetchFields: fields
|
|
|
|
forComponentOfType: @"vevent"] objectEnumerator];
|
|
|
|
oldEvent = [events nextObject];
|
|
|
|
while (oldEvent)
|
|
|
|
{
|
|
|
|
newEvent = [NSMutableArray arrayWithArray: oldEvent];
|
2007-06-19 20:08:16 +02:00
|
|
|
isAllDay = [[oldEvent objectAtIndex: 7] boolValue];
|
2007-06-11 23:28:28 +02:00
|
|
|
interval = [[oldEvent objectAtIndex: 4] intValue];
|
2007-06-19 20:08:16 +02:00
|
|
|
[newEvent addObject: [self _formattedDateForSeconds: interval
|
|
|
|
forAllDay: isAllDay]];
|
2007-06-11 23:28:28 +02:00
|
|
|
interval = [[oldEvent objectAtIndex: 5] intValue];
|
2007-06-19 20:08:16 +02:00
|
|
|
[newEvent addObject: [self _formattedDateForSeconds: interval
|
|
|
|
forAllDay: isAllDay]];
|
2007-06-11 23:28:28 +02:00
|
|
|
[newEvents addObject: newEvent];
|
|
|
|
|
|
|
|
oldEvent = [events nextObject];
|
|
|
|
}
|
2007-06-13 21:33:31 +02:00
|
|
|
[newEvents sortUsingSelector: @selector (compareEventsAscending:)];
|
2007-06-07 22:49:06 +02:00
|
|
|
|
2007-06-11 23:28:28 +02:00
|
|
|
return [self _responseWithData: newEvents];
|
2007-06-07 22:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _getStatusClassForStatusCode: (int) statusCode
|
|
|
|
andEndDateStamp: (unsigned int) endDateStamp
|
|
|
|
{
|
|
|
|
NSCalendarDate *taskDate, *now;
|
|
|
|
NSString *statusClass;
|
|
|
|
|
|
|
|
if (statusCode == 1)
|
|
|
|
statusClass = @"completed";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (endDateStamp)
|
|
|
|
{
|
|
|
|
now = [NSCalendarDate calendarDate];
|
|
|
|
taskDate
|
|
|
|
= [NSCalendarDate dateWithTimeIntervalSince1970: endDateStamp];
|
|
|
|
if ([taskDate earlierDate: now] == taskDate)
|
|
|
|
statusClass = @"overdue";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([taskDate isToday])
|
|
|
|
statusClass = @"duetoday";
|
|
|
|
else
|
|
|
|
statusClass = @"duelater";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
statusClass = @"duelater";
|
|
|
|
}
|
|
|
|
|
|
|
|
return statusClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) tasksListAction
|
|
|
|
{
|
|
|
|
NSEnumerator *tasks;
|
|
|
|
NSMutableArray *filteredTasks, *filteredTask;
|
|
|
|
BOOL showCompleted;
|
|
|
|
NSArray *fields, *task;
|
|
|
|
int statusCode;
|
|
|
|
unsigned int endDateStamp;
|
|
|
|
NSString *statusFlag;
|
|
|
|
|
|
|
|
filteredTasks = [NSMutableArray array];
|
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
|
2007-07-24 20:45:52 +02:00
|
|
|
fields = [NSArray arrayWithObjects: @"c_name", @"c_owner", @"c_status",
|
|
|
|
@"c_title", @"c_enddate", nil];
|
2007-06-07 22:49:06 +02:00
|
|
|
|
|
|
|
tasks = [[self _fetchFields: fields
|
|
|
|
forComponentOfType: @"vtodo"] objectEnumerator];
|
|
|
|
showCompleted = [[request formValueForKey: @"show-completed"] intValue];
|
|
|
|
|
|
|
|
task = [tasks nextObject];
|
|
|
|
while (task)
|
|
|
|
{
|
|
|
|
statusCode = [[task objectAtIndex: 2] intValue];
|
|
|
|
if (statusCode != 1 || showCompleted)
|
|
|
|
{
|
|
|
|
filteredTask = [NSMutableArray arrayWithArray: task];
|
|
|
|
endDateStamp = [[task objectAtIndex: 4] intValue];
|
|
|
|
statusFlag = [self _getStatusClassForStatusCode: statusCode
|
|
|
|
andEndDateStamp: endDateStamp];
|
|
|
|
[filteredTask addObject: statusFlag];
|
|
|
|
[filteredTasks addObject: filteredTask];
|
|
|
|
}
|
|
|
|
task = [tasks nextObject];
|
|
|
|
}
|
2007-06-13 21:33:31 +02:00
|
|
|
[filteredTasks sortUsingSelector: @selector (compareTasksAscending:)];
|
2007-06-07 22:49:06 +02:00
|
|
|
|
|
|
|
return [self _responseWithData: filteredTasks];
|
|
|
|
}
|
|
|
|
|
|
|
|
// - (BOOL) shouldDisplayCurrentTask
|
|
|
|
// {
|
|
|
|
// if (!knowsToShow)
|
|
|
|
// {
|
|
|
|
// showCompleted
|
|
|
|
// = [[self queryParameterForKey: @"show-completed"] intValue];
|
|
|
|
// knowsToShow = YES;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return ([[currentTask objectForKey: @"status"] intValue] != 1
|
|
|
|
// || showCompleted);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (BOOL) shouldShowCompletedTasks
|
|
|
|
// {
|
|
|
|
// if (!knowsToShow)
|
|
|
|
// {
|
|
|
|
// showCompleted
|
|
|
|
// = [[self queryParameterForKey: @"show-completed"] intValue];
|
|
|
|
// knowsToShow = YES;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return showCompleted;
|
|
|
|
// }
|
|
|
|
|
|
|
|
@end
|