Monotone-Parent: 07c2681e0251d505e6978723e5907b33527cf279

Monotone-Revision: 356dad69ed3731f29474c5f2e6359c928c942702

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2010-03-09T20:28:24
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2010-03-09 20:28:24 +00:00
parent 0c1f4cc40a
commit e50a87cd67
2 changed files with 30 additions and 40 deletions

View File

@ -276,47 +276,43 @@
- (WOResponse *) _usersResponseForResults: (NSArray *) users - (WOResponse *) _usersResponseForResults: (NSArray *) users
{ {
WOResponse *response;
NSString *uid; NSString *uid;
NSMutableString *responseString;
NSDictionary *contact; NSDictionary *contact;
NSString *contactInfo, *login; NSString *contactInfo, *login;
NSMutableArray *jsonResponse, *jsonLine;
NSArray *allUsers; NSArray *allUsers;
int i; int count, max;
login = [[context activeUser] login]; login = [[context activeUser] login];
response = [context response];
[response setStatus: 200];
[response setHeader: @"text/plain; charset=utf-8"
forKey: @"Content-Type"];
responseString = [NSMutableString string];
// We sort our array - this is pretty useful for the Web // We sort our array - this is pretty useful for the Web
// interface of SOGo. // interface of SOGo.
allUsers = [users allUsers = [users
sortedArrayUsingSelector: @selector (caseInsensitiveDisplayNameCompare:)]; sortedArrayUsingSelector: @selector (caseInsensitiveDisplayNameCompare:)];
for (i = 0; i < [allUsers count]; i++) max = [allUsers count];
jsonResponse = [NSMutableArray arrayWithCapacity: max];
for (count = 0; count < max; count++)
{ {
contact = [allUsers objectAtIndex: i]; contact = [allUsers objectAtIndex: count];
uid = [contact objectForKey: @"c_uid"]; uid = [contact objectForKey: @"c_uid"];
// We do NOT return the current authenticated user. // We do NOT return the current authenticated user.
if (![uid isEqualToString: login]) if (![uid isEqualToString: login])
{ {
jsonLine = [NSMutableArray arrayWithCapacity: 4];
[jsonLine addObject: uid];
[jsonLine addObject: [contact objectForKey: @"cn"]];
[jsonLine addObject: [contact objectForKey: @"c_email"]];
contactInfo = [contact objectForKey: @"c_info"]; contactInfo = [contact objectForKey: @"c_info"];
if (!contactInfo) if (contactInfo)
contactInfo = @""; [jsonLine addObject: contactInfo];
[responseString appendFormat: @"%@:%@:%@:%@\n", uid, [jsonResponse addObject: jsonLine];
[contact objectForKey: @"cn"],
[contact objectForKey: @"c_email"],
contactInfo];
} }
} }
[response appendContentString: responseString];
return response; return [self responseWithStatus: 200
andJSONRepresentation: jsonResponse];
} }
- (id <WOActionResults>) usersSearchAction - (id <WOActionResults>) usersSearchAction

View File

@ -29,8 +29,8 @@ function usersSearchCallback(http) {
document.userFoldersRequest = null; document.userFoldersRequest = null;
var div = $("folders"); var div = $("folders");
if (http.status == 200) { if (http.status == 200) {
var response = http.responseText; var response = http.responseText.evalJSON();
buildUsersTree(div, http.responseText); buildUsersTree(div, response);
} }
else if (http.status == 404) else if (http.status == 404)
div.update(); div.update();
@ -39,11 +39,10 @@ function usersSearchCallback(http) {
function addUserLineToTree(tree, parent, line) { function addUserLineToTree(tree, parent, line) {
var icon = ResourcesURL + '/busy.gif'; var icon = ResourcesURL + '/busy.gif';
var userInfos = line.split(":"); var email = line[1] + " &lt;" + line[2] + "&gt;";
var email = userInfos[1] + " &lt;" + userInfos[2] + "&gt;"; if (line[3] && !line[3].empty())
if (userInfos[3] && !userInfos[3].empty()) email += ", " + line[3].split("\n").join("; "); // extra contact info
email += ", " + userInfos[3]; // extra contact info tree.add(parent, 0, email, 0, '#', line[0], 'person',
tree.add(parent, 0, email, 0, '#', userInfos[0], 'person',
'', '', '', '',
ResourcesURL + '/abcard.gif', ResourcesURL + '/abcard.gif',
ResourcesURL + '/abcard.gif'); ResourcesURL + '/abcard.gif');
@ -76,23 +75,18 @@ function buildUsersTree(treeDiv, response) {
var isUserDialog = (window.opener.userFolderType == "user"); var isUserDialog = (window.opener.userFolderType == "user");
var multiplier = ((isUserDialog) ? 1 : 2); var multiplier = ((isUserDialog) ? 1 : 2);
if (response.length) { if (response.length > 0) {
var lines = response.split("\n"); for (var i = 0; i < response.length; i++)
for (var i = 0; i < lines.length; i++) { addUserLineToTree(d, 1 + i * multiplier, response[i]);
if (lines[i].length > 0)
addUserLineToTree(d, 1 + i * multiplier, lines[i]);
}
treeDiv.appendChild(d.domObject ()); treeDiv.appendChild(d.domObject ());
treeDiv.clean = false; treeDiv.clean = false;
for (var i = 0; i < lines.length - 1; i++) { for (var i = 0; i < response.length; i++) {
if (lines[i].length > 0) { if (!isUserDialog) {
if (!isUserDialog) { var toggle = $("tgd" + (1 + i * 2));
var toggle = $("tgd" + (1 + i * 2)); toggle.observe ("click", onUserNodeToggle);
toggle.observe ("click", onUserNodeToggle);
}
var sd = $("sd" + (1 + i * multiplier));
sd.observe("click", onTreeItemClick);
} }
var sd = $("sd" + (1 + i * multiplier));
sd.observe("click", onTreeItemClick);
} }
} }
} }