@interface UIxContactsListView : UIxComponent
{
+ NSArray *allRecords;
+ NSArray *filteredRecords;
+ NSString *searchText;
id contact;
}
@implementation UIxContactsListView
- (void)dealloc {
- [self->contact release];
+ [self->allRecords release];
+ [self->filteredRecords release];
+ [self->searchText release];
+ [self->contact release];
[super dealloc];
}
return self->contact;
}
+- (void)setSearchText:(NSString *)_txt {
+ ASSIGNCOPY(self->searchText, _txt);
+}
+- (id)searchText {
+ return self->searchText;
+}
+- (EOQualifier *)qualifier {
+ NSString *qs, *s;
+
+ s = [self searchText];
+ if ([s length] == 0)
+ return nil;
+
+ qs = [NSString stringWithFormat:
+ @"(sn isCaseInsensitiveLike: '%@*') OR "
+ @"(givenname isCaseInsensitiveLike: '%@*') OR "
+ @"(mail isCaseInsensitiveLike: '*%@*') OR "
+ @"(telephonenumber isCaseInsensitiveLike: '*%@*')",
+ s, s, s, s];
+ return [EOQualifier qualifierWithQualifierFormat:qs];
+}
+
- (NSString *)defaultSortKey {
return @"sn";
}
s = [[[self context] request] formValueForKey:@"sort"];
return [s length] > 0 ? s : [self defaultSortKey];
}
-
-static int sortDicts(id left, id right, void *ctx) {
- id v1, v2;
-
- v1 = [left valueForKey:ctx];
- v2 = [right valueForKey:ctx];
- return [v1 caseInsensitiveCompare:v2];
+- (EOSortOrdering *)sortOrdering {
+ return [EOSortOrdering sortOrderingWithKey:[self sortKey]
+ selector:EOCompareCaseInsensitiveAscending];
+}
+- (NSArray *)sortOrderings {
+ return [NSArray arrayWithObjects:[self sortOrdering], nil];
}
- (NSArray *)contactInfos {
- NSString *sort;
- NSArray *records;
-
// TODO: should be done in the backend, but for Agenor AB its OK here
- sort = [self sortKey];
+ NSArray *records;
+ EOQualifier *q;
+
+ if (self->filteredRecords)
+ return self->filteredRecords;
records = [[self clientObject] fetchCoreInfos];
- if ([sort length] > 0)
- records = [records sortedArrayUsingFunction:sortDicts context:sort];
- return records;
+ self->allRecords =
+ [[records sortedArrayUsingKeyOrderArray:[self sortOrderings]] retain];
+
+ if ((q = [self qualifier]) != nil) {
+ [self logWithFormat:@"qs: %@", q];
+ self->filteredRecords =
+ [[self->allRecords filteredArrayUsingQualifier:q] retain];
+ }
+ else
+ self->filteredRecords = [self->allRecords retain];
+
+ return self->filteredRecords;
}
/* notifications */
- (void)sleep {
- [self->contact release]; self->contact = nil;
+ [self->contact release]; self->contact = nil;
+ [self->allRecords release]; self->allRecords = nil;
+ [self->filteredRecords release]; self->filteredRecords = nil;
[super sleep];
}
+/* actions */
+
+- (BOOL)shouldTakeValuesFromRequest:(WORequest *)_rq inContext:(WOContext*)_c{
+ return YES;
+}
+
@end /* UIxContactsListView */
table.contacttableview th {
text-align: left;
}
+ input.searchfield {
+ font-size: 8pt;
+ }
</style>
<table id="skywintable"
</tr>
<tr>
<td id="skywinbodycell" class="wincontent">
+ <form name="searchform" var:href="view" var:_sort="sortKey"
+ method="GET">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
- <table border="0" cellpadding="4" width="100%" cellspacing="2">
- <tr>
- <td align="right" bgcolor="#e8e8e0">
+ <table border="0" cellpadding="4" width="100%" cellspacing="0">
+ <tr bgcolor="#e8e8e0">
+ <td align="left">
+ <input type="text" name="search" class="searchfield"
+ var:value="searchText" />
+ </td>
+ <td align="right">
<table border="0" cellpadding="0" cellspacing="1">
<tr>
<td class="button_auto_env"
<th>
<var:if condition="sortKey" const:value="sn"
const:negate="YES">
- <a href="?sort=sn">Lastname</a>
+ <a href="view" _sort="sn"
+ var:_search="searchText">Lastname</a>
</var:if>
<var:if condition="sortKey" const:value="sn">
<i>Lastname</i>
<th>
<var:if condition="sortKey" const:value="givenname"
const:negate="YES">
- <a href="?sort=givenname">Firstname</a>
+ <a href="view" _sort="givenname"
+ var:_search="searchText">Firstname</a>
</var:if>
<var:if condition="sortKey" const:value="givenname">
<i>Firstname</i>
<th>
<var:if condition="sortKey" const:value="mail"
const:negate="YES">
- <a href="?sort=mail">EMail</a>
+ <a href="view" _sort="mail"
+ var:_search="searchText">EMail</a>
</var:if>
<var:if condition="sortKey" const:value="mail">
<i>Email</i>
</td>
</tr>
</table>
+ </form>
</td>
</tr>
</table>
+
+<!-- todo: need onload for this to work ...
+ <script language="JavaScript">
+ document.searchform.search.select();
+ document.searchform.search.focus();
+ </script>
+-->
<var:if condition="isUIxDebugEnabled">
<hr />