2010-03-09 14:45:52 +01:00
|
|
|
/* -*- Mode: java; tab-width: 2; c-label-minimum-indentation: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2009-06-13 01:39:02 +02:00
|
|
|
|
|
|
|
var d;
|
2008-08-28 16:48:45 +02:00
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
function onSearchFormSubmit() {
|
2010-03-08 22:42:10 +01:00
|
|
|
startAnimation($("pageContent"), $("filterPanel"));
|
|
|
|
|
2010-03-09 14:45:52 +01:00
|
|
|
var searchValue = $("searchValue");
|
|
|
|
var encodedValue = encodeURI(searchValue.value);
|
|
|
|
|
|
|
|
if (encodedValue.blank()) {
|
|
|
|
checkAjaxRequestsState();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var url = (UserFolderURL
|
|
|
|
+ "usersSearch?search=" + encodedValue);
|
|
|
|
if (document.userFoldersRequest) {
|
|
|
|
document.userFoldersRequest.aborted = true;
|
|
|
|
document.userFoldersRequest.abort();
|
|
|
|
}
|
|
|
|
document.userFoldersRequest
|
|
|
|
= triggerAjaxRequest(url, usersSearchCallback);
|
2009-06-15 17:58:47 +02:00
|
|
|
}
|
2010-03-09 14:45:52 +01:00
|
|
|
|
|
|
|
return false;
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
2008-11-24 05:10:38 +01:00
|
|
|
function usersSearchCallback(http) {
|
2009-09-04 23:32:53 +02:00
|
|
|
document.userFoldersRequest = null;
|
|
|
|
var div = $("folders");
|
|
|
|
if (http.status == 200) {
|
2010-03-09 21:28:24 +01:00
|
|
|
var response = http.responseText.evalJSON();
|
|
|
|
buildUsersTree(div, response);
|
2009-09-04 23:32:53 +02:00
|
|
|
}
|
|
|
|
else if (http.status == 404)
|
|
|
|
div.update();
|
2008-11-24 05:10:38 +01:00
|
|
|
}
|
2008-08-28 16:48:45 +02:00
|
|
|
|
2008-11-24 05:10:38 +01:00
|
|
|
function addUserLineToTree(tree, parent, line) {
|
2010-03-09 14:45:52 +01:00
|
|
|
var icon = ResourcesURL + '/busy.gif';
|
|
|
|
|
2010-03-09 21:28:24 +01:00
|
|
|
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',
|
2010-03-09 14:45:52 +01:00
|
|
|
'', '',
|
|
|
|
ResourcesURL + '/abcard.gif',
|
|
|
|
ResourcesURL + '/abcard.gif');
|
|
|
|
if (window.opener.userFolderType != "user") {
|
|
|
|
tree.add(parent + 1, parent, getLabel("Please wait..."), 0, '#', null,
|
|
|
|
null, '', '', icon, icon);
|
|
|
|
}
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
2009-06-13 01:39:02 +02:00
|
|
|
function buildUsersTree(treeDiv, response) {
|
2010-03-09 14:45:52 +01:00
|
|
|
d = new dTree("d");
|
|
|
|
d.config.hideRoot = true;
|
|
|
|
d.icon.root = ResourcesURL + '/tbtv_account_17x17.gif';
|
|
|
|
d.icon.folder = ResourcesURL + '/tbtv_leaf_corner_17x17.png';
|
|
|
|
d.icon.folderOpen = ResourcesURL + '/tbtv_leaf_corner_17x17.png';
|
|
|
|
d.icon.node = ResourcesURL + '/tbtv_leaf_corner_17x17.png';
|
|
|
|
d.icon.line = ResourcesURL + '/tbtv_line_17x17.gif';
|
|
|
|
d.icon.join = ResourcesURL + '/tbtv_junction_17x17.gif';
|
|
|
|
d.icon.joinBottom = ResourcesURL + '/tbtv_corner_17x17.gif';
|
|
|
|
d.icon.plus = ResourcesURL + '/tbtv_plus_17x17.gif';
|
|
|
|
d.icon.plusBottom = ResourcesURL + '/tbtv_corner_plus_17x17.gif';
|
|
|
|
d.icon.minus = ResourcesURL + '/tbtv_minus_17x17.gif';
|
|
|
|
d.icon.minusBottom = ResourcesURL + '/tbtv_corner_minus_17x17.gif';
|
|
|
|
d.icon.nlPlus = ResourcesURL + '/tbtv_corner_plus_17x17.gif';
|
|
|
|
d.icon.nlMinus = ResourcesURL + '/tbtv_corner_minus_17x17.gif';
|
|
|
|
d.icon.empty = ResourcesURL + '/empty.gif';
|
|
|
|
d.preload ();
|
|
|
|
d.add(0, -1, '');
|
|
|
|
|
|
|
|
var isUserDialog = (window.opener.userFolderType == "user");
|
|
|
|
var multiplier = ((isUserDialog) ? 1 : 2);
|
|
|
|
|
2010-03-09 21:28:24 +01:00
|
|
|
if (response.length > 0) {
|
|
|
|
for (var i = 0; i < response.length; i++)
|
|
|
|
addUserLineToTree(d, 1 + i * multiplier, response[i]);
|
2010-03-09 14:45:52 +01:00
|
|
|
treeDiv.appendChild(d.domObject ());
|
|
|
|
treeDiv.clean = false;
|
2010-03-09 21:28:24 +01:00
|
|
|
for (var i = 0; i < response.length; i++) {
|
|
|
|
if (!isUserDialog) {
|
|
|
|
var toggle = $("tgd" + (1 + i * 2));
|
|
|
|
toggle.observe ("click", onUserNodeToggle);
|
2010-03-09 14:45:52 +01:00
|
|
|
}
|
2010-03-09 21:28:24 +01:00
|
|
|
var sd = $("sd" + (1 + i * multiplier));
|
|
|
|
sd.observe("click", onTreeItemClick);
|
2010-03-09 14:45:52 +01:00
|
|
|
}
|
|
|
|
}
|
2008-11-24 05:10:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onUserNodeToggle(event) {
|
2010-03-09 14:45:52 +01:00
|
|
|
this.stopObserving("click", onUserNodeToggle);
|
|
|
|
|
|
|
|
var person = this.parentNode.getAttribute("dataname");
|
|
|
|
|
|
|
|
var url = (UserFolderURLForUser(person) + "foldersSearch"
|
|
|
|
+ "?type=" + window.opener.userFolderType);
|
|
|
|
var nodeId = this.getAttribute("id").substr(3);
|
|
|
|
triggerAjaxRequest(url, foldersSearchCallback,
|
|
|
|
{ nodeId: nodeId, user: person });
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
2008-11-24 15:53:48 +01:00
|
|
|
function onTreeItemClick(event) {
|
2009-11-04 23:13:20 +01:00
|
|
|
preventDefault(event);
|
2010-03-09 14:45:52 +01:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
var topNode = $("d");
|
|
|
|
if (topNode.selectedEntry)
|
|
|
|
topNode.selectedEntry.deselect();
|
|
|
|
this.selectElement();
|
|
|
|
topNode.selectedEntry = this;
|
2010-03-09 14:45:52 +01:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
if (window.opener.userFolderType == "user")
|
|
|
|
$("addButton").removeClassName("disabled");
|
|
|
|
else {
|
|
|
|
var dataname = this.parentNode.getAttribute("dataname");
|
|
|
|
if (!dataname)
|
|
|
|
dataname = "";
|
|
|
|
if (dataname.indexOf(":") == -1)
|
|
|
|
$("addButton").addClassName("disabled");
|
|
|
|
else
|
|
|
|
$("addButton").removeClassName("disabled");
|
|
|
|
};
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
2008-11-24 05:10:38 +01:00
|
|
|
function foldersSearchCallback(http) {
|
2010-03-09 14:45:52 +01:00
|
|
|
if (http.status == 200) {
|
|
|
|
var response = http.responseText;
|
|
|
|
var nodeId = parseInt(http.callbackData["nodeId"]);
|
|
|
|
|
|
|
|
var dd = $("dd" + (nodeId + 2));
|
|
|
|
var indentValue = (dd ? 1 : 0);
|
|
|
|
d.aIndent.push(indentValue);
|
|
|
|
|
|
|
|
var dd = $("dd" + nodeId);
|
|
|
|
if (response.length) {
|
|
|
|
var folders = response.split(";");
|
|
|
|
var user = http.callbackData["user"];
|
|
|
|
|
|
|
|
dd.innerHTML = '';
|
|
|
|
for (var i = 1; i < folders.length - 1; i++)
|
|
|
|
dd.appendChild (addFolderBranchToTree (d, user, folders[i], nodeId, i, false));
|
|
|
|
dd.appendChild (addFolderBranchToTree (d, user, folders[folders.length-1], nodeId,
|
|
|
|
(folders.length - 1), true));
|
|
|
|
//dd.update(str);
|
|
|
|
for (var i = 1; i < folders.length; i++) {
|
|
|
|
var sd = $("sd" + (nodeId + i));
|
|
|
|
sd.observe("click", onTreeItemClick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dd.innerHTML = '';
|
|
|
|
dd.appendChild(addFolderNotFoundNode (d, nodeId, null));
|
|
|
|
var sd = $("sd" + (nodeId + 1));
|
|
|
|
sd.observe("click", onTreeItemClick);
|
|
|
|
}
|
|
|
|
|
|
|
|
d.aIndent.pop();
|
|
|
|
}
|
2008-11-24 05:10:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function addFolderBranchToTree(tree, user, folder, nodeId, subId, isLast) {
|
2010-03-09 14:45:52 +01:00
|
|
|
var folderInfos = folder.split(":");
|
|
|
|
var icon = ResourcesURL + '/';
|
|
|
|
if (folderInfos[2] == 'Contact')
|
|
|
|
icon += 'tb-mail-addressbook-flat-16x16.png';
|
|
|
|
else
|
|
|
|
icon += 'calendar-folder-16x16.png';
|
|
|
|
var folderId = user + ":" + folderInfos[1];
|
|
|
|
var name = folderInfos[0]; // name has the format "Folername (Firstname Lastname <email>)"
|
|
|
|
var pos = name.lastIndexOf(' (');
|
|
|
|
if (pos > -1)
|
|
|
|
name = name.substring(0, pos); // strip the part with fullname and email
|
|
|
|
var node = new Node(subId, nodeId, name, 0, '#', folderId,
|
|
|
|
folderInfos[2] + '-folder', '', '', icon, icon);
|
|
|
|
node._ls = isLast;
|
|
|
|
var content = tree.node(node, (nodeId + subId), null);
|
|
|
|
|
|
|
|
return content;
|
2008-11-24 05:10:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function addFolderNotFoundNode (tree, nodeId) {
|
2010-03-09 14:45:52 +01:00
|
|
|
var icon = ResourcesURL + '/icon_unread.gif';
|
|
|
|
var node = new Node(1, nodeId, getLabel("No possible subscription"), 0, '#',
|
|
|
|
null, null, '', '', icon, icon);
|
|
|
|
node._ls = true;
|
|
|
|
return tree.node(node, (nodeId + 1));
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onConfirmFolderSelection(event) {
|
2009-11-04 23:13:20 +01:00
|
|
|
if (!this.hasClassName("disabled")) {
|
|
|
|
var topNode = $("d");
|
|
|
|
if (topNode && topNode.selectedEntry) {
|
|
|
|
var node = topNode.selectedEntry.parentNode;
|
|
|
|
var folder = node.getAttribute("dataname");
|
2010-03-09 14:45:52 +01:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
var folderName;
|
|
|
|
if (window.opener.userFolderType == "user") {
|
|
|
|
var span = $(topNode.selectedEntry).down("SPAN.nodeName");
|
|
|
|
var email = (span.innerHTML
|
|
|
|
.replace("<", "<", "g")
|
|
|
|
.replace(">", ">", "g"));
|
|
|
|
folderName = email;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var resource = $(topNode.selectedEntry).down("SPAN.nodeName");
|
|
|
|
var user = $(node.parentNode.previousSibling).down("SPAN.nodeName");
|
|
|
|
var email = (user.innerHTML
|
|
|
|
.replace("<", "<", "g")
|
|
|
|
.replace(">", ">", "g"));
|
|
|
|
folderName = resource.innerHTML + ' (' + email + ')';
|
|
|
|
}
|
|
|
|
folderName = folderName.replace(/>,.*(\))?$/, ">)$1", "g");
|
2010-03-09 14:45:52 +01:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
var data = { folderName: folderName, folder: folder, window: window };
|
|
|
|
if (parent$(accessToSubscribedFolder(folder)))
|
|
|
|
window.alert(getLabel("You have already subscribed to that folder!"));
|
|
|
|
else
|
|
|
|
window.opener.subscribeToFolder(window.opener.userFolderCallback, data);
|
|
|
|
this.blur(); // required by IE
|
|
|
|
}
|
2008-02-07 22:51:20 +01:00
|
|
|
}
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
2007-12-05 22:05:04 +01:00
|
|
|
function onFolderSearchKeyDown(event) {
|
2010-03-09 14:45:19 +01:00
|
|
|
if (event.keyCode == Event.KEY_BACKSPACE
|
|
|
|
|| IsCharacterKey(event.keyCode)) {
|
|
|
|
var div = $("folders");
|
2009-09-04 23:32:53 +02:00
|
|
|
|
2010-03-09 14:45:19 +01:00
|
|
|
if (!div.clean) {
|
|
|
|
var oldD = $("d"); // the folders tree
|
|
|
|
if (oldD) {
|
|
|
|
oldD.remove();
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
div.clean = true;
|
|
|
|
$("addButton").addClassName("disabled");
|
|
|
|
}
|
|
|
|
}
|
2007-12-05 22:05:04 +01:00
|
|
|
}
|
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
function initUserFoldersWindow() {
|
2010-03-09 14:45:52 +01:00
|
|
|
var searchValue = $("searchValue");
|
|
|
|
searchValue.observe("keydown", onFolderSearchKeyDown);
|
|
|
|
var addButton = $("addButton");
|
|
|
|
addButton.observe("click", onConfirmFolderSelection);
|
|
|
|
searchValue.focus();
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initUserFoldersWindow);
|