2008-03-07 23:09:33 +01:00
|
|
|
/* UIxListView.m - this file is part of SOGo
|
|
|
|
*
|
2008-09-27 03:13:41 +02:00
|
|
|
* Copyright (C) 2008 Inverse inc.
|
2008-03-07 23:09:33 +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.
|
|
|
|
*/
|
|
|
|
|
2009-08-21 16:25:42 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGCards/NGVList.h>
|
|
|
|
#import <NGCards/NGVCard.h>
|
2009-08-21 19:41:52 +02:00
|
|
|
#import <NGCards/NGVCardReference.h>
|
2009-08-21 16:25:42 +02:00
|
|
|
|
2008-03-07 23:09:33 +01:00
|
|
|
#import "UIxListView.h"
|
|
|
|
|
|
|
|
@implementation UIxListView
|
|
|
|
|
2009-08-21 16:25:42 +02:00
|
|
|
|
|
|
|
- (NSString *) listName
|
|
|
|
{
|
|
|
|
return [list fn];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasNickname
|
|
|
|
{
|
|
|
|
return [list nickname] != nil;
|
|
|
|
}
|
|
|
|
- (NSString *) listNickname
|
|
|
|
{
|
|
|
|
return [list nickname];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasDescription
|
|
|
|
{
|
|
|
|
return [list description] != nil;
|
|
|
|
}
|
|
|
|
- (NSString *) listDescription
|
|
|
|
{
|
|
|
|
return [list description];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) components
|
|
|
|
{
|
|
|
|
return [list cardReferences];
|
|
|
|
}
|
|
|
|
- (NSString *) itemText
|
|
|
|
{
|
|
|
|
NSString *rc;
|
|
|
|
|
2009-08-21 19:41:52 +02:00
|
|
|
rc = [NSString stringWithFormat: @"%@ <%@>",
|
|
|
|
[item fn], [item email]];
|
2009-08-21 16:25:42 +02:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-08-21 19:41:52 +02:00
|
|
|
- (void) checkListReferences
|
|
|
|
{
|
|
|
|
NSMutableArray *invalid;
|
|
|
|
NGVCardReference *card;
|
|
|
|
int i, count;
|
|
|
|
id test;
|
|
|
|
|
|
|
|
invalid = [NSMutableArray array];
|
|
|
|
|
|
|
|
count = [[list cardReferences] count];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
card = [[list cardReferences] objectAtIndex: i];
|
|
|
|
test = [[co container] lookupName: [card reference]
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
if ([test isKindOfClass: [NSException class]])
|
|
|
|
{
|
|
|
|
NSLog (@"%@ not found", [card reference]);
|
|
|
|
[invalid addObject: [card copy]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
count = [invalid count];
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
[list deleteCardReference: [invalid objectAtIndex: i]];
|
|
|
|
[co save];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-21 16:25:42 +02:00
|
|
|
- (id <WOActionResults>) defaultAction
|
|
|
|
{
|
|
|
|
id rc;
|
|
|
|
|
2009-08-21 19:41:52 +02:00
|
|
|
co = [self clientObject];
|
|
|
|
list = [co vList];
|
2009-08-21 16:25:42 +02:00
|
|
|
|
|
|
|
if (list)
|
2009-08-21 19:41:52 +02:00
|
|
|
{
|
|
|
|
[self checkListReferences];
|
|
|
|
rc = self;
|
|
|
|
}
|
2009-08-21 16:25:42 +02:00
|
|
|
else
|
|
|
|
rc = [NSException exceptionWithHTTPStatus: 404 /* Not Found */
|
|
|
|
reason: @"could not locate contact"];
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-09-10 23:00:38 +02:00
|
|
|
- (WOResponse *) propertiesAction
|
|
|
|
{
|
|
|
|
NSMutableArray *data;
|
|
|
|
NGVCardReference *card;
|
|
|
|
WOResponse *rc;
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
data = [NSMutableArray array];
|
|
|
|
co = [self clientObject];
|
|
|
|
list = [co vList];
|
|
|
|
|
|
|
|
count = [[list cardReferences] count];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
card = [[list cardReferences] objectAtIndex: i];
|
|
|
|
[data addObject: [NSArray arrayWithObjects: [card reference], [card fn],
|
|
|
|
[card email], nil]];
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = [context response];
|
|
|
|
[rc setHeader: @"text/plain; charset=utf-8"
|
|
|
|
forKey: @"content-type"];
|
|
|
|
[rc appendContentString: [data jsonRepresentation]];
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-03-07 23:09:33 +01:00
|
|
|
@end
|