From e50a87cd67c6ce3bc1f353bcc48a3a13984bfc38 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 9 Mar 2010 20:28:24 +0000 Subject: [PATCH] Monotone-Parent: 07c2681e0251d505e6978723e5907b33527cf279 Monotone-Revision: 356dad69ed3731f29474c5f2e6359c928c942702 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-03-09T20:28:24 Monotone-Branch: ca.inverse.sogo --- UI/MainUI/SOGoUserHomePage.m | 34 ++++++++---------- .../UIxContactsUserFolders.js | 36 ++++++++----------- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/UI/MainUI/SOGoUserHomePage.m b/UI/MainUI/SOGoUserHomePage.m index 83b3c0d16..ed0c5e649 100644 --- a/UI/MainUI/SOGoUserHomePage.m +++ b/UI/MainUI/SOGoUserHomePage.m @@ -276,47 +276,43 @@ - (WOResponse *) _usersResponseForResults: (NSArray *) users { - WOResponse *response; NSString *uid; - NSMutableString *responseString; NSDictionary *contact; NSString *contactInfo, *login; + NSMutableArray *jsonResponse, *jsonLine; NSArray *allUsers; - int i; + int count, max; 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 // interface of SOGo. allUsers = [users 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"]; // We do NOT return the current authenticated user. 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"]; - if (!contactInfo) - contactInfo = @""; - [responseString appendFormat: @"%@:%@:%@:%@\n", uid, - [contact objectForKey: @"cn"], - [contact objectForKey: @"c_email"], - contactInfo]; + if (contactInfo) + [jsonLine addObject: contactInfo]; + [jsonResponse addObject: jsonLine]; } } - [response appendContentString: responseString]; - return response; + return [self responseWithStatus: 200 + andJSONRepresentation: jsonResponse]; } - (id ) usersSearchAction diff --git a/UI/WebServerResources/UIxContactsUserFolders.js b/UI/WebServerResources/UIxContactsUserFolders.js index 14914d4df..65a603db7 100644 --- a/UI/WebServerResources/UIxContactsUserFolders.js +++ b/UI/WebServerResources/UIxContactsUserFolders.js @@ -29,8 +29,8 @@ function usersSearchCallback(http) { document.userFoldersRequest = null; var div = $("folders"); if (http.status == 200) { - var response = http.responseText; - buildUsersTree(div, http.responseText); + var response = http.responseText.evalJSON(); + buildUsersTree(div, response); } else if (http.status == 404) div.update(); @@ -39,11 +39,10 @@ function usersSearchCallback(http) { function addUserLineToTree(tree, parent, line) { var icon = ResourcesURL + '/busy.gif'; - var userInfos = line.split(":"); - var email = userInfos[1] + " <" + userInfos[2] + ">"; - if (userInfos[3] && !userInfos[3].empty()) - email += ", " + userInfos[3]; // extra contact info - tree.add(parent, 0, email, 0, '#', userInfos[0], 'person', + var email = line[1] + " <" + line[2] + ">"; + if (line[3] && !line[3].empty()) + email += ", " + line[3].split("\n").join("; "); // extra contact info + tree.add(parent, 0, email, 0, '#', line[0], 'person', '', '', ResourcesURL + '/abcard.gif', ResourcesURL + '/abcard.gif'); @@ -76,23 +75,18 @@ function buildUsersTree(treeDiv, response) { var isUserDialog = (window.opener.userFolderType == "user"); var multiplier = ((isUserDialog) ? 1 : 2); - if (response.length) { - var lines = response.split("\n"); - for (var i = 0; i < lines.length; i++) { - if (lines[i].length > 0) - addUserLineToTree(d, 1 + i * multiplier, lines[i]); - } + if (response.length > 0) { + for (var i = 0; i < response.length; i++) + addUserLineToTree(d, 1 + i * multiplier, response[i]); treeDiv.appendChild(d.domObject ()); treeDiv.clean = false; - for (var i = 0; i < lines.length - 1; i++) { - if (lines[i].length > 0) { - if (!isUserDialog) { - var toggle = $("tgd" + (1 + i * 2)); - toggle.observe ("click", onUserNodeToggle); - } - var sd = $("sd" + (1 + i * multiplier)); - sd.observe("click", onTreeItemClick); + for (var i = 0; i < response.length; i++) { + if (!isUserDialog) { + var toggle = $("tgd" + (1 + i * 2)); + toggle.observe ("click", onUserNodeToggle); } + var sd = $("sd" + (1 + i * multiplier)); + sd.observe("click", onTreeItemClick); } } }