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 *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 <WOActionResults>) usersSearchAction

View File

@ -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] + " &lt;" + userInfos[2] + "&gt;";
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] + " &lt;" + line[2] + "&gt;";
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);
}
}
}