2006-08-05 00:51:42 +02:00
|
|
|
/* UIxContactFoldersView.m - this file is part of SOGo
|
|
|
|
*
|
2010-07-21 02:20:30 +02:00
|
|
|
* Copyright (C) 2006-2010 Inverse inc.
|
2006-08-05 00:51:42 +02: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.
|
|
|
|
*/
|
|
|
|
|
2008-07-09 04:01:32 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
2006-08-05 00:51:42 +02:00
|
|
|
#import <Foundation/NSString.h>
|
2006-11-01 21:37:02 +01:00
|
|
|
|
2006-10-26 02:15:12 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
#import <NGObjWeb/SoObject.h>
|
2007-08-06 16:46:38 +02:00
|
|
|
#import <NGObjWeb/SoSecurityManager.h>
|
2007-02-09 22:24:15 +01:00
|
|
|
#import <NGObjWeb/WOContext.h>
|
2007-08-06 16:46:38 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2006-08-05 00:51:42 +02:00
|
|
|
|
2008-08-13 23:29:18 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
|
2007-03-29 19:12:44 +02:00
|
|
|
#import <GDLContentStore/GCSFolder.h>
|
|
|
|
#import <GDLContentStore/GCSFolderManager.h>
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoPermissions.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
|
|
|
#import <SOGo/SOGoUserManager.h>
|
2010-04-21 16:35:58 +02:00
|
|
|
#import <SOGo/SOGoUserSettings.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
|
|
|
#import <SOGo/NSString+Utilities.h>
|
|
|
|
#import <Contacts/SOGoContactFolders.h>
|
|
|
|
#import <Contacts/SOGoContactFolder.h>
|
|
|
|
#import <Contacts/SOGoContactGCSFolder.h>
|
|
|
|
#import <Contacts/SOGoContactSourceFolder.h>
|
2006-09-19 23:05:18 +02:00
|
|
|
|
2006-08-05 00:51:42 +02:00
|
|
|
#import "UIxContactFoldersView.h"
|
|
|
|
|
|
|
|
@implementation UIxContactFoldersView
|
|
|
|
|
2010-02-08 18:17:28 +01:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
contextIsSetup = NO;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2008-02-04 23:22:14 +01:00
|
|
|
- (void) _setupContext
|
|
|
|
{
|
|
|
|
SOGoUser *activeUser;
|
|
|
|
NSString *module;
|
|
|
|
SOGoContactFolders *clientObject;
|
|
|
|
|
2010-02-08 18:17:28 +01:00
|
|
|
if (!contextIsSetup)
|
|
|
|
{
|
|
|
|
activeUser = [context activeUser];
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
|
|
|
|
module = [clientObject nameInContainer];
|
|
|
|
|
|
|
|
us = [activeUser userSettings];
|
|
|
|
moduleSettings = [us objectForKey: module];
|
|
|
|
if (!moduleSettings)
|
2010-05-05 20:49:29 +02:00
|
|
|
{
|
|
|
|
moduleSettings = [NSMutableDictionary new];
|
|
|
|
[us setObject: moduleSettings forKey: module];
|
|
|
|
[moduleSettings release];
|
|
|
|
}
|
2010-02-08 18:17:28 +01:00
|
|
|
contextIsSetup = YES;
|
|
|
|
}
|
2008-02-04 23:22:14 +01:00
|
|
|
}
|
|
|
|
|
2009-07-17 23:25:38 +02:00
|
|
|
- (id <WOActionResults>) mailerContactsAction
|
|
|
|
{
|
|
|
|
selectorComponentClass = @"UIxContactsMailerSelection";
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) selectorComponentClass
|
|
|
|
{
|
|
|
|
return selectorComponentClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOElement *) selectorComponent
|
|
|
|
{
|
|
|
|
WOElement *newComponent;
|
|
|
|
|
|
|
|
newComponent = [self pageWithName: selectorComponentClass];
|
|
|
|
|
|
|
|
return newComponent;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasContactSelectionButtons
|
|
|
|
{
|
|
|
|
return (selectorComponentClass != nil);
|
|
|
|
}
|
|
|
|
|
2008-07-04 11:43:28 +02:00
|
|
|
- (id <WOActionResults>) allContactSearchAction
|
|
|
|
{
|
|
|
|
id <WOActionResults> result;
|
2010-01-22 17:33:35 +01:00
|
|
|
SOGoFolder <SOGoContactFolder> *folder;
|
2008-08-09 21:09:02 +02:00
|
|
|
NSString *searchText, *mail;
|
2009-10-13 23:20:26 +02:00
|
|
|
NSDictionary *data;
|
2008-07-04 11:43:28 +02:00
|
|
|
NSArray *folders, *contacts, *descriptors, *sortedContacts;
|
2008-10-17 04:17:56 +02:00
|
|
|
NSMutableArray *sortedFolders;
|
2009-10-13 23:20:26 +02:00
|
|
|
NSMutableDictionary *contact, *uniqueContacts;
|
2010-05-05 20:49:29 +02:00
|
|
|
unsigned int i, j, max;
|
2009-02-17 15:30:49 +01:00
|
|
|
NSSortDescriptor *commonNameDescriptor;
|
2009-09-11 21:30:22 +02:00
|
|
|
BOOL excludeGroups, excludeLists;
|
2009-08-19 19:19:32 +02:00
|
|
|
|
2008-07-04 11:43:28 +02:00
|
|
|
searchText = [self queryParameterForKey: @"search"];
|
|
|
|
if ([searchText length] > 0)
|
|
|
|
{
|
2009-12-02 19:27:48 +01:00
|
|
|
// NSLog(@"Search all contacts: %@", searchText);
|
2009-09-10 20:31:20 +02:00
|
|
|
excludeGroups = [[self queryParameterForKey: @"excludeGroups"] boolValue];
|
2009-09-11 21:30:22 +02:00
|
|
|
excludeLists = [[self queryParameterForKey: @"excludeLists"] boolValue];
|
2009-03-20 22:37:07 +01:00
|
|
|
NS_DURING
|
2009-08-19 19:19:32 +02:00
|
|
|
folders = [[self clientObject] subFolders];
|
2009-03-20 22:37:07 +01:00
|
|
|
NS_HANDLER
|
2009-08-19 19:19:32 +02:00
|
|
|
/* We need to specifically test for @"SOGoDBException", which is
|
|
|
|
raised explicitly in SOGoParentFolder. Any other exception should
|
|
|
|
be re-raised. */
|
|
|
|
if ([[localException name] isEqualToString: @"SOGoDBException"])
|
|
|
|
folders = nil;
|
|
|
|
else
|
|
|
|
[localException raise];
|
2010-01-15 18:26:22 +01:00
|
|
|
NS_ENDHANDLER;
|
2010-05-05 20:49:29 +02:00
|
|
|
max = [folders count];
|
|
|
|
sortedFolders = [NSMutableArray arrayWithCapacity: max];
|
2008-07-09 04:01:32 +02:00
|
|
|
uniqueContacts = [NSMutableDictionary dictionary];
|
2010-05-05 20:49:29 +02:00
|
|
|
for (i = 0; i < max; i++)
|
2009-08-19 19:19:32 +02:00
|
|
|
{
|
|
|
|
folder = [folders objectAtIndex: i];
|
2009-11-18 23:54:12 +01:00
|
|
|
/* We first search in LDAP folders (in case of duplicated entries in GCS folders) */
|
2009-09-25 16:42:33 +02:00
|
|
|
if ([folder isKindOfClass: [SOGoContactSourceFolder class]])
|
2009-09-11 15:09:28 +02:00
|
|
|
[sortedFolders insertObject: folder atIndex: 0];
|
2009-08-19 19:19:32 +02:00
|
|
|
else
|
|
|
|
[sortedFolders addObject: folder];
|
|
|
|
}
|
2010-05-05 20:49:29 +02:00
|
|
|
for (i = 0; i < max; i++)
|
2009-08-19 19:19:32 +02:00
|
|
|
{
|
|
|
|
folder = [sortedFolders objectAtIndex: i];
|
|
|
|
//NSLog(@" Address book: %@ (%@)", [folder displayName], [folder class]);
|
|
|
|
contacts = [folder lookupContactsWithFilter: searchText
|
2010-10-26 22:19:37 +02:00
|
|
|
onCriteria: @"name_or_address"
|
2009-08-19 19:19:32 +02:00
|
|
|
sortBy: @"c_cn"
|
|
|
|
ordering: NSOrderedAscending];
|
|
|
|
for (j = 0; j < [contacts count]; j++)
|
|
|
|
{
|
|
|
|
contact = [contacts objectAtIndex: j];
|
|
|
|
mail = [contact objectForKey: @"c_mail"];
|
2009-09-11 21:30:22 +02:00
|
|
|
//NSLog(@" found %@ (%@) ? %@", [contact objectForKey: @"c_name"], mail,
|
|
|
|
// [contact description]);
|
2010-09-02 22:51:24 +02:00
|
|
|
if (!excludeLists && [[contact objectForKey: @"c_component"]
|
2010-05-05 20:49:29 +02:00
|
|
|
isEqualToString: @"vlist"])
|
2009-09-11 21:30:22 +02:00
|
|
|
{
|
|
|
|
[contact setObject: [folder nameInContainer]
|
|
|
|
forKey: @"container"];
|
|
|
|
[uniqueContacts setObject: contact
|
|
|
|
forKey: [contact objectForKey: @"c_name"]];
|
|
|
|
}
|
2010-09-02 22:51:24 +02:00
|
|
|
else if ([mail length]
|
|
|
|
&& [uniqueContacts objectForKey: mail] == nil
|
|
|
|
&& !(excludeGroups && [contact objectForKey: @"isGroup"]))
|
|
|
|
[uniqueContacts setObject: contact forKey: mail];
|
2009-08-19 19:19:32 +02:00
|
|
|
}
|
2010-05-05 20:49:29 +02:00
|
|
|
}
|
2008-07-09 04:01:32 +02:00
|
|
|
if ([uniqueContacts count] > 0)
|
2009-08-19 19:19:32 +02:00
|
|
|
{
|
|
|
|
// Sort the contacts by display name
|
2010-05-05 20:49:29 +02:00
|
|
|
commonNameDescriptor = [[NSSortDescriptor alloc] initWithKey: @"c_cn"
|
|
|
|
ascending:YES];
|
2009-08-19 19:19:32 +02:00
|
|
|
descriptors = [NSArray arrayWithObjects: commonNameDescriptor, nil];
|
2010-05-05 20:49:29 +02:00
|
|
|
[commonNameDescriptor release];
|
|
|
|
sortedContacts = [[uniqueContacts allValues]
|
|
|
|
sortedArrayUsingDescriptors: descriptors];
|
2009-08-19 19:19:32 +02:00
|
|
|
}
|
2008-10-15 22:06:38 +02:00
|
|
|
else
|
2009-08-19 19:19:32 +02:00
|
|
|
sortedContacts = [NSArray array];
|
2008-10-04 01:12:11 +02:00
|
|
|
data = [NSDictionary dictionaryWithObjectsAndKeys: searchText, @"searchText",
|
2010-04-20 15:24:17 +02:00
|
|
|
sortedContacts, @"contacts",
|
|
|
|
nil];
|
2009-02-19 23:20:21 +01:00
|
|
|
result = [self responseWithStatus: 200];
|
2010-05-05 20:49:29 +02:00
|
|
|
[(WOResponse*) result appendContentString: [data jsonRepresentation]];
|
2008-07-04 11:43:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
result = [NSException exceptionWithHTTPStatus: 400
|
2009-08-19 19:19:32 +02:00
|
|
|
reason: @"missing 'search' parameter"];
|
|
|
|
|
2008-07-04 11:43:28 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-08-19 19:19:32 +02:00
|
|
|
- (void) checkDefaultModulePreference
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2009-08-19 19:19:32 +02:00
|
|
|
|
|
|
|
if (![self isPopup])
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
if ([ud rememberLastModule])
|
2009-08-19 19:19:32 +02:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
[ud setLoginModule: @"Contacts"];
|
|
|
|
[ud synchronize];
|
2009-08-19 19:19:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-12-20 23:52:32 +01:00
|
|
|
|
2009-06-26 19:48:28 +02:00
|
|
|
- (BOOL) isPopup
|
|
|
|
{
|
|
|
|
return [[self queryParameterForKey: @"popup"] boolValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) contactFolders
|
|
|
|
{
|
|
|
|
SOGoContactFolders *folderContainer;
|
|
|
|
|
|
|
|
folderContainer = [self clientObject];
|
|
|
|
|
|
|
|
return [folderContainer subFolders];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentContactFolderId
|
|
|
|
{
|
2010-05-05 20:49:29 +02:00
|
|
|
return [NSString stringWithFormat: @"/%@", [currentFolder nameInContainer]];
|
2009-06-26 19:48:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentContactFolderName
|
|
|
|
{
|
|
|
|
return [currentFolder displayName];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentContactFolderOwner
|
|
|
|
{
|
|
|
|
return [currentFolder ownerInContext: context];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentContactFolderClass
|
|
|
|
{
|
2010-05-05 20:49:29 +02:00
|
|
|
return ([currentFolder isKindOfClass: [SOGoContactSourceFolder class]]
|
|
|
|
? @"remote" : @"local");
|
2009-06-26 19:48:28 +02:00
|
|
|
}
|
|
|
|
|
2010-02-08 18:17:28 +01:00
|
|
|
- (NSString *) verticalDragHandleStyle
|
|
|
|
{
|
|
|
|
NSString *vertical;
|
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
vertical = [moduleSettings objectForKey: @"DragHandleVertical"];
|
|
|
|
|
2010-05-05 20:49:29 +02:00
|
|
|
return ((vertical && [vertical intValue] > 0)
|
|
|
|
? (id)[vertical stringByAppendingFormat: @"px"] : nil);
|
2010-02-08 18:17:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) horizontalDragHandleStyle
|
|
|
|
{
|
|
|
|
NSString *horizontal;
|
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
horizontal = [moduleSettings objectForKey: @"DragHandleHorizontal"];
|
|
|
|
|
2010-05-05 20:49:29 +02:00
|
|
|
return ((horizontal && [horizontal intValue] > 0)
|
|
|
|
? (id)[horizontal stringByAppendingFormat: @"px"] : nil);
|
2010-02-08 18:17:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) contactsListContentStyle
|
|
|
|
{
|
|
|
|
NSString *height;
|
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
height = [moduleSettings objectForKey: @"DragHandleVertical"];
|
|
|
|
|
2010-05-05 20:49:29 +02:00
|
|
|
return ((height && [height intValue] > 0)
|
|
|
|
? [NSString stringWithFormat: @"%ipx", ([height intValue] - 27)] : nil);
|
2010-02-08 18:17:28 +01:00
|
|
|
}
|
|
|
|
|
2008-02-04 23:22:14 +01:00
|
|
|
- (WOResponse *) saveDragHandleStateAction
|
|
|
|
{
|
|
|
|
WORequest *request;
|
|
|
|
NSString *dragHandle;
|
2009-08-19 19:19:32 +02:00
|
|
|
|
2008-02-04 23:22:14 +01:00
|
|
|
[self _setupContext];
|
|
|
|
request = [context request];
|
2009-08-19 19:19:32 +02:00
|
|
|
|
2008-02-04 23:22:14 +01:00
|
|
|
if ((dragHandle = [request formValueForKey: @"vertical"]) != nil)
|
2010-04-20 15:24:17 +02:00
|
|
|
[moduleSettings setObject: dragHandle
|
|
|
|
forKey: @"DragHandleVertical"];
|
2008-02-04 23:22:14 +01:00
|
|
|
else if ((dragHandle = [request formValueForKey: @"horizontal"]) != nil)
|
2010-04-20 15:24:17 +02:00
|
|
|
[moduleSettings setObject: dragHandle
|
|
|
|
forKey: @"DragHandleHorizontal"];
|
2008-02-04 23:22:14 +01:00
|
|
|
else
|
|
|
|
return [self responseWithStatus: 400];
|
2009-08-19 19:19:32 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
[us synchronize];
|
2008-02-04 23:22:14 +01:00
|
|
|
|
|
|
|
return [self responseWithStatus: 204];
|
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (id) defaultAction
|
|
|
|
{
|
|
|
|
[self checkDefaultModulePreference];
|
|
|
|
|
|
|
|
return [super defaultAction];
|
|
|
|
}
|
|
|
|
|
2006-08-05 00:51:42 +02:00
|
|
|
@end
|