sogo/UI/Contacts/UIxListView.m
C Robert 1c7e5b8680 Improvement for list display
Monotone-Parent: 08fdc5d0a9471051564e0739b2dd3367c1e5143a
Monotone-Revision: de4013a540009902497a1085be5975e4ff6c3a83

Monotone-Author: crobert@inverse.ca
Monotone-Date: 2009-08-21T17:41:52
Monotone-Branch: ca.inverse.sogo
2009-08-21 17:41:52 +00:00

123 lines
2.7 KiB
Objective-C

/* UIxListView.m - this file is part of SOGo
*
* Copyright (C) 2008 Inverse inc.
*
* 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 <NGObjWeb/NSException+HTTP.h>
#import <NGObjWeb/WOResponse.h>
#import <NGCards/NGVList.h>
#import <NGCards/NGVCard.h>
#import <NGCards/NGVCardReference.h>
#import "UIxListView.h"
@implementation UIxListView
- (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;
rc = [NSString stringWithFormat: @"%@ <%@>",
[item fn], [item email]];
return rc;
}
- (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];
}
}
- (id <WOActionResults>) defaultAction
{
id rc;
co = [self clientObject];
list = [co vList];
if (list)
{
[self checkListReferences];
rc = self;
}
else
rc = [NSException exceptionWithHTTPStatus: 404 /* Not Found */
reason: @"could not locate contact"];
return rc;
}
@end