2007-03-29 20:05:23 +02:00
|
|
|
/* JavaScript for SOGoContacts */
|
2006-08-03 23:28:33 +02:00
|
|
|
|
|
|
|
var cachedContacts = new Array();
|
2007-06-28 22:37:27 +02:00
|
|
|
var currentContactFolder = null;
|
2006-08-03 23:28:33 +02:00
|
|
|
|
2007-06-01 22:35:51 +02:00
|
|
|
var usersRightsWindowHeight = 200;
|
2007-04-28 00:06:58 +02:00
|
|
|
var usersRightsWindowWidth = 450;
|
|
|
|
|
2006-08-03 23:28:33 +02:00
|
|
|
function validateEditorInput(sender) {
|
|
|
|
var errortext = "";
|
|
|
|
var field;
|
|
|
|
|
|
|
|
field = document.pageform.subject;
|
|
|
|
if (field.value == "")
|
|
|
|
errortext = errortext + labels.error_missingsubject + "\n";
|
|
|
|
|
|
|
|
if (!UIxRecipientSelectorHasRecipients())
|
|
|
|
errortext = errortext + labels.error_missingrecipients + "\n";
|
|
|
|
|
|
|
|
if (errortext.length > 0) {
|
2007-09-15 00:01:02 +02:00
|
|
|
alert(labels.error_validationfailed + ":\n"
|
|
|
|
+ errortext);
|
2006-08-03 23:28:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-06-28 22:37:27 +02:00
|
|
|
function openContactsFolder(contactsFolder, reload, idx) {
|
2007-08-01 21:21:02 +02:00
|
|
|
if ((contactsFolder && contactsFolder != currentContactFolder)
|
2007-07-31 23:14:14 +02:00
|
|
|
|| reload) {
|
2007-08-15 00:09:20 +02:00
|
|
|
currentContactFolder = contactsFolder;
|
2007-06-28 22:37:27 +02:00
|
|
|
var url = URLForFolderID(currentContactFolder) +
|
|
|
|
"/view?noframe=1";
|
|
|
|
|
|
|
|
var searchValue = search["value"];
|
|
|
|
if (searchValue && searchValue.length > 0)
|
|
|
|
url += ("&search=" + search["criteria"]
|
2007-09-06 23:41:19 +02:00
|
|
|
+ "&value=" + escape(searchValue.utf8encode()));
|
2007-06-28 22:37:27 +02:00
|
|
|
var sortAttribute = sorting["attribute"];
|
|
|
|
if (sortAttribute && sortAttribute.length > 0)
|
|
|
|
url += ("&sort=" + sorting["attribute"]
|
|
|
|
+ "&asc=" + sorting["ascending"]);
|
|
|
|
|
|
|
|
var selection;
|
2007-02-12 14:52:22 +01:00
|
|
|
if (contactsFolder == currentContactFolder) {
|
|
|
|
var contactsList = $("contactsList");
|
|
|
|
if (contactsList)
|
|
|
|
selection = contactsList.getSelectedRowsId();
|
2007-10-09 19:57:27 +02:00
|
|
|
// else
|
|
|
|
// window.alert("no contactsList");
|
2007-02-12 14:52:22 +01:00
|
|
|
}
|
|
|
|
else
|
2007-06-28 22:37:27 +02:00
|
|
|
selection = null;
|
|
|
|
|
|
|
|
if (document.contactsListAjaxRequest) {
|
|
|
|
document.contactsListAjaxRequest.aborted = true;
|
|
|
|
document.contactsListAjaxRequest.abort();
|
2007-09-26 00:10:44 +02:00
|
|
|
}
|
2007-06-28 22:37:27 +02:00
|
|
|
document.contactsListAjaxRequest
|
|
|
|
= triggerAjaxRequest(url, contactsListCallback, selection);
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function openContactsFolderAtIndex(element) {
|
|
|
|
var idx = element.getAttribute("idx");
|
2007-03-29 20:05:23 +02:00
|
|
|
var url = URLForFolderID(currentContactFolder) + "/view?noframe=1&idx=" + idx;
|
2006-08-03 23:28:33 +02:00
|
|
|
|
|
|
|
if (document.contactsListAjaxRequest) {
|
|
|
|
document.contactsListAjaxRequest.aborted = true;
|
|
|
|
document.contactsListAjaxRequest.abort();
|
|
|
|
}
|
|
|
|
document.contactsListAjaxRequest
|
|
|
|
= triggerAjaxRequest(url, contactsListCallback);
|
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function contactsListCallback(http) {
|
2006-12-20 23:53:58 +01:00
|
|
|
if (http.readyState == 4
|
|
|
|
&& http.status == 200) {
|
|
|
|
document.contactsListAjaxRequest = null;
|
2007-06-28 22:37:27 +02:00
|
|
|
|
|
|
|
var table = $("contactsList");
|
2007-09-14 20:20:51 +02:00
|
|
|
if (table) {
|
2007-09-24 23:26:23 +02:00
|
|
|
// Update table
|
|
|
|
var data = http.responseText;
|
|
|
|
var html = data.replace(/^(.*\n)*.*(<table(.*\n)*)$/, "$2");
|
|
|
|
var tbody = table.tBodies[0];
|
|
|
|
var tmp = document.createElement('div');
|
|
|
|
$(tmp).update(html);
|
|
|
|
table.replaceChild(tmp.firstChild.tBodies[0], tbody);
|
2007-09-14 20:20:51 +02:00
|
|
|
}
|
2007-09-24 23:26:23 +02:00
|
|
|
else {
|
|
|
|
// Add table (doesn't happen .. yet)
|
|
|
|
var div = $("contactsListContent");
|
|
|
|
div.update(http.responseText);
|
|
|
|
table = $("contactsList");
|
|
|
|
configureSortableTableHeaders(table);
|
|
|
|
TableKit.Resizable.init(table, {'trueResize' : true, 'keepWidth' : true});
|
|
|
|
}
|
|
|
|
|
2007-06-28 22:37:27 +02:00
|
|
|
if (sorting["attribute"] && sorting["attribute"].length > 0) {
|
|
|
|
var sortHeader;
|
2007-09-07 00:10:24 +02:00
|
|
|
if (sorting["attribute"] == "displayName")
|
2007-06-28 22:37:27 +02:00
|
|
|
sortHeader = $("nameHeader");
|
|
|
|
else if (sorting["attribute"] == "mail")
|
|
|
|
sortHeader = $("mailHeader");
|
2007-09-07 00:10:24 +02:00
|
|
|
else if (sorting["attribute"] == "screenName")
|
2007-06-28 22:37:27 +02:00
|
|
|
sortHeader = $("screenNameHeader");
|
2007-09-07 00:10:24 +02:00
|
|
|
else if (sorting["attribute"] == "org")
|
2007-06-28 22:37:27 +02:00
|
|
|
sortHeader = $("orgHeader");
|
2007-09-07 00:10:24 +02:00
|
|
|
else if (sorting["attribute"] == "phone")
|
2007-06-28 22:37:27 +02:00
|
|
|
sortHeader = $("phoneHeader");
|
|
|
|
else
|
|
|
|
sortHeader = null;
|
|
|
|
|
|
|
|
if (sortHeader) {
|
2007-09-24 23:26:23 +02:00
|
|
|
var sortImages = $(table.tHead).getElementsByClassName("sortImage");
|
|
|
|
$(sortImages).each(function(item) {
|
|
|
|
item.remove();
|
|
|
|
});
|
|
|
|
|
2007-06-28 22:37:27 +02:00
|
|
|
var sortImage = createElement("img", "messageSortImage", "sortImage");
|
|
|
|
sortHeader.insertBefore(sortImage, sortHeader.firstChild);
|
|
|
|
if (sorting["ascending"])
|
|
|
|
sortImage.src = ResourcesURL + "/title_sortdown_12x12.png";
|
|
|
|
else
|
|
|
|
sortImage.src = ResourcesURL + "/title_sortup_12x12.png";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-20 23:53:58 +01:00
|
|
|
var selected = http.callbackData;
|
|
|
|
if (selected) {
|
2007-06-28 22:37:27 +02:00
|
|
|
for (var i = 0; i < selected.length; i++) {
|
|
|
|
var row = $(selected[i]);
|
|
|
|
if (row)
|
|
|
|
row.select();
|
|
|
|
}
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2007-07-13 20:03:02 +02:00
|
|
|
log ("ajax problem 1: status = " + http.status);
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onContactFoldersContextMenu(event) {
|
2006-11-03 20:40:12 +01:00
|
|
|
var menu = $("contactFoldersMenu");
|
2007-08-15 00:09:20 +02:00
|
|
|
//Event.observe(menu, "hideMenu", onContactFoldersContextMenuHide, false);
|
|
|
|
Event.observe(menu, "mousedown", onContactFoldersContextMenuHide, false);
|
2007-05-22 16:54:46 +02:00
|
|
|
popupMenu(event, "contactFoldersMenu", this);
|
2006-11-03 20:40:12 +01:00
|
|
|
|
|
|
|
var topNode = $("contactFolders");
|
|
|
|
var selectedNodes = topNode.getSelectedRows();
|
|
|
|
topNode.menuSelectedRows = selectedNodes;
|
|
|
|
for (var i = 0; i < selectedNodes.length; i++)
|
2007-08-15 00:09:20 +02:00
|
|
|
$(selectedNodes[i]).deselect();
|
2006-12-20 23:53:58 +01:00
|
|
|
topNode.menuSelectedEntry = this;
|
2007-08-15 00:09:20 +02:00
|
|
|
$(this).select();
|
2006-11-03 20:40:12 +01:00
|
|
|
}
|
|
|
|
|
2007-09-14 20:20:51 +02:00
|
|
|
function onContactContextMenu(event, element) { log ("onContactContextMenu");
|
2006-11-03 20:40:12 +01:00
|
|
|
var menu = $("contactMenu");
|
2007-09-14 20:20:51 +02:00
|
|
|
|
2007-08-15 00:09:20 +02:00
|
|
|
Event.observe(menu, "mousedown", onContactContextMenuHide, false);
|
2007-05-22 16:54:46 +02:00
|
|
|
popupMenu(event, "contactMenu", element);
|
2006-08-03 23:28:33 +02:00
|
|
|
|
2006-11-03 20:40:12 +01:00
|
|
|
var topNode = $("contactsList");
|
2006-08-19 00:40:04 +02:00
|
|
|
var selectedNodes = topNode.getSelectedRows();
|
|
|
|
topNode.menuSelectedRows = selectedNodes;
|
|
|
|
for (var i = 0; i < selectedNodes.length; i++)
|
2007-08-15 00:09:20 +02:00
|
|
|
$(selectedNodes[i]).deselect();
|
2006-08-03 23:28:33 +02:00
|
|
|
topNode.menuSelectedEntry = element;
|
2007-08-15 00:09:20 +02:00
|
|
|
$(element).select();
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onContactContextMenuHide(event) {
|
2006-11-03 20:40:12 +01:00
|
|
|
var topNode = $("contactsList");
|
|
|
|
|
|
|
|
if (topNode.menuSelectedEntry) {
|
2007-08-15 00:09:20 +02:00
|
|
|
$(topNode.menuSelectedEntry).deselect();
|
2006-11-03 20:40:12 +01:00
|
|
|
topNode.menuSelectedEntry = null;
|
|
|
|
}
|
|
|
|
if (topNode.menuSelectedRows) {
|
|
|
|
var nodes = topNode.menuSelectedRows;
|
|
|
|
for (var i = 0; i < nodes.length; i++)
|
2007-08-15 00:09:20 +02:00
|
|
|
$(nodes[i]).select();
|
2006-11-03 20:40:12 +01:00
|
|
|
topNode.menuSelectedRows = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onContactFoldersContextMenuHide(event) {
|
2006-11-03 20:40:12 +01:00
|
|
|
var topNode = $("contactFolders");
|
2006-08-03 23:28:33 +02:00
|
|
|
|
|
|
|
if (topNode.menuSelectedEntry) {
|
2006-12-20 23:53:58 +01:00
|
|
|
topNode.menuSelectedEntry.deselect();
|
2006-08-03 23:28:33 +02:00
|
|
|
topNode.menuSelectedEntry = null;
|
|
|
|
}
|
|
|
|
if (topNode.menuSelectedRows) {
|
2006-08-19 00:40:04 +02:00
|
|
|
var nodes = topNode.menuSelectedRows;
|
|
|
|
for (var i = 0; i < nodes.length; i++)
|
2006-12-20 23:53:58 +01:00
|
|
|
nodes[i].select();
|
2006-08-03 23:28:33 +02:00
|
|
|
topNode.menuSelectedRows = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onFolderMenuHide(event) {
|
2006-09-19 23:14:02 +02:00
|
|
|
var topNode = $('d');
|
2006-08-03 23:28:33 +02:00
|
|
|
|
|
|
|
if (topNode.menuSelectedEntry) {
|
2006-12-20 23:53:58 +01:00
|
|
|
topNode.menuSelectedEntry.deselect();
|
2006-08-03 23:28:33 +02:00
|
|
|
topNode.menuSelectedEntry = null;
|
|
|
|
}
|
|
|
|
if (topNode.selectedEntry)
|
2006-12-20 23:53:58 +01:00
|
|
|
topNode.selectedEntry.select();
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function loadContact(idx) {
|
2006-09-13 23:23:44 +02:00
|
|
|
if (document.contactAjaxRequest) {
|
|
|
|
document.contactAjaxRequest.aborted = true;
|
|
|
|
document.contactAjaxRequest.abort();
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
2006-09-19 15:50:19 +02:00
|
|
|
if (cachedContacts[currentContactFolder + "/" + idx]) {
|
|
|
|
var div = $('contactView');
|
|
|
|
div.innerHTML = cachedContacts[currentContactFolder + "/" + idx];
|
|
|
|
}
|
|
|
|
else {
|
2007-03-29 20:05:23 +02:00
|
|
|
var url = (URLForFolderID(currentContactFolder)
|
|
|
|
+ "/" + idx + "/view?noframe=1");
|
2006-09-19 15:50:19 +02:00
|
|
|
document.contactAjaxRequest
|
|
|
|
= triggerAjaxRequest(url, contactLoadCallback, idx);
|
|
|
|
}
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function contactLoadCallback(http) {
|
2006-09-13 23:23:44 +02:00
|
|
|
var div = $('contactView');
|
2006-08-03 23:28:33 +02:00
|
|
|
|
|
|
|
if (http.readyState == 4
|
|
|
|
&& http.status == 200) {
|
2006-09-13 23:23:44 +02:00
|
|
|
document.contactAjaxRequest = null;
|
2006-09-19 15:50:19 +02:00
|
|
|
var content = http.responseText;
|
|
|
|
cachedContacts[currentContactFolder + "/" + http.callbackData] = content;
|
|
|
|
div.innerHTML = content;
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
else
|
2007-06-12 17:39:47 +02:00
|
|
|
log ("ajax problem 2: " + http.status);
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var rowSelectionCount = 0;
|
|
|
|
|
|
|
|
validateControls();
|
|
|
|
|
|
|
|
function showElement(e, shouldShow) {
|
|
|
|
e.style.display = shouldShow ? "" : "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableElement(e, shouldEnable) {
|
|
|
|
if(!e)
|
|
|
|
return;
|
|
|
|
if(shouldEnable) {
|
|
|
|
if(e.hasAttribute("disabled"))
|
|
|
|
e.removeAttribute("disabled");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
e.setAttribute("disabled", "1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateControls() {
|
2006-09-19 23:14:02 +02:00
|
|
|
var e = $("moveto");
|
2006-08-03 23:28:33 +02:00
|
|
|
this.enableElement(e, rowSelectionCount > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveTo(uri) {
|
|
|
|
alert("MoveTo: " + uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* contact menu entries */
|
2007-03-19 15:31:49 +01:00
|
|
|
function onContactRowClick(event, node) {
|
2006-10-03 18:27:02 +02:00
|
|
|
loadContact(node.getAttribute('id'));
|
2006-09-13 23:23:44 +02:00
|
|
|
|
|
|
|
return onRowClick(event);
|
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onContactRowDblClick(event, node) {
|
2006-08-03 23:28:33 +02:00
|
|
|
var contactId = node.getAttribute('id');
|
|
|
|
|
2007-08-21 18:00:25 +02:00
|
|
|
openContactWindow(URLForFolderID(currentContactFolder)
|
|
|
|
+ "/" + contactId + "/edit", contactId);
|
2006-08-03 23:28:33 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-05-22 16:54:46 +02:00
|
|
|
function onMenuEditContact(event) {
|
|
|
|
var contactId = document.menuTarget.getAttribute('id');
|
2006-08-03 23:28:33 +02:00
|
|
|
|
2007-08-21 18:00:25 +02:00
|
|
|
openContactWindow(URLForFolderID(currentContactFolder)
|
|
|
|
+ "/" + contactId + "/edit", contactId);
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
2007-05-22 16:54:46 +02:00
|
|
|
function onMenuWriteToContact(event) {
|
|
|
|
var contactId = document.menuTarget.getAttribute('id');
|
2007-09-14 20:20:51 +02:00
|
|
|
var contactRow = $(contactId);
|
|
|
|
var emailCell = contactRow.down('td', 1);
|
|
|
|
|
|
|
|
if (!emailCell.firstChild) { // .nodeValue is the contact email address
|
|
|
|
window.alert(labels["The selected contact has no email address."].decodeEntities());
|
|
|
|
return false;
|
|
|
|
}
|
2006-08-03 23:28:33 +02:00
|
|
|
|
2007-05-22 16:54:46 +02:00
|
|
|
openMailComposeWindow(ApplicationBaseURL + currentContactFolder
|
|
|
|
+ "/" + contactId + "/write");
|
2007-09-14 20:20:51 +02:00
|
|
|
|
|
|
|
if (document.body.hasClassName("popup"))
|
|
|
|
window.close();
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
2007-05-22 16:54:46 +02:00
|
|
|
function onMenuDeleteContact(event) {
|
|
|
|
uixDeleteSelectedContacts(this);
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onToolbarEditSelectedContacts(event) {
|
2006-09-19 23:14:02 +02:00
|
|
|
var contactsList = $('contactsList');
|
2006-08-19 00:40:04 +02:00
|
|
|
var rows = contactsList.getSelectedRowsId();
|
|
|
|
|
2006-08-03 23:28:33 +02:00
|
|
|
for (var i = 0; i < rows.length; i++) {
|
2007-08-21 18:00:25 +02:00
|
|
|
openContactWindow(URLForFolderID(currentContactFolder)
|
|
|
|
+ "/" + rows[i] + "/edit", rows[i]);
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onToolbarWriteToSelectedContacts(event) {
|
2006-09-19 23:14:02 +02:00
|
|
|
var contactsList = $('contactsList');
|
2006-08-19 00:40:04 +02:00
|
|
|
var rows = contactsList.getSelectedRowsId();
|
2007-09-14 20:20:51 +02:00
|
|
|
var rowsWithEmail = 0;
|
2006-08-19 00:40:04 +02:00
|
|
|
|
2007-09-14 20:20:51 +02:00
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
var emailCell = $(rows[i]).down('td', 1);
|
|
|
|
if (emailCell.firstChild) { // .nodeValue is the contact email address
|
|
|
|
rowsWithEmail++;
|
|
|
|
openMailComposeWindow(ApplicationBaseURL + currentContactFolder
|
|
|
|
+ "/" + rows[i] + "/write");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rowsWithEmail == 0) {
|
|
|
|
window.alert(labels["The selected contact has no email address."].decodeEntities());
|
|
|
|
}
|
|
|
|
else if (document.body.hasClassName("popup"))
|
|
|
|
window.close();
|
2006-08-03 23:28:33 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function uixDeleteSelectedContacts(sender) {
|
2006-08-03 23:28:33 +02:00
|
|
|
var failCount = 0;
|
2006-09-19 23:14:02 +02:00
|
|
|
var contactsList = $('contactsList');
|
2006-08-19 00:40:04 +02:00
|
|
|
var rows = contactsList.getSelectedRowsId();
|
|
|
|
|
2006-09-19 23:14:02 +02:00
|
|
|
var contactView = $('contactView');
|
|
|
|
contactView.innerHTML = '';
|
|
|
|
|
2006-08-03 23:28:33 +02:00
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
var url, http, rowElem;
|
|
|
|
|
|
|
|
/* send AJAX request (synchronously) */
|
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
url = (URLForFolderID(currentContactFolder) + "/"
|
2006-08-03 23:28:33 +02:00
|
|
|
+ rows[i] + "/delete");
|
|
|
|
http = createHTTPClient();
|
|
|
|
http.open("POST", url, false /* not async */);
|
|
|
|
http.send("");
|
|
|
|
if (http.status != 200) { /* request failed */
|
|
|
|
failCount++;
|
|
|
|
http = null;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
http = null;
|
|
|
|
|
|
|
|
/* remove from page */
|
|
|
|
|
|
|
|
/* line-through would be nicer, but hiding is OK too */
|
2006-09-19 23:14:02 +02:00
|
|
|
rowElem = $(rows[i]);
|
2006-08-03 23:28:33 +02:00
|
|
|
rowElem.parentNode.removeChild(rowElem);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failCount > 0)
|
2007-03-29 20:05:23 +02:00
|
|
|
alert("Could not delete the selected contacts!");
|
2006-08-03 23:28:33 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function newEmailTo(sender) {
|
|
|
|
var mailto = sanitizeMailTo(sender.parentNode.parentNode.menuTarget.innerHTML);
|
|
|
|
|
|
|
|
if (mailto.length > 0)
|
2007-08-21 18:00:25 +02:00
|
|
|
openMailComposeWindow("compose?mailto=" + mailto);
|
2006-08-03 23:28:33 +02:00
|
|
|
|
|
|
|
return false; /* stop following the link */
|
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onHeaderClick(event) {
|
2007-06-28 22:37:27 +02:00
|
|
|
var headerId = this.getAttribute("id");
|
|
|
|
var newSortAttribute;
|
|
|
|
if (headerId == "nameHeader")
|
2007-09-07 00:10:24 +02:00
|
|
|
newSortAttribute = "displayName";
|
2007-06-28 22:37:27 +02:00
|
|
|
else if (headerId == "mailHeader")
|
|
|
|
newSortAttribute = "mail";
|
|
|
|
else if (headerId == "screenNameHeader")
|
2007-09-07 00:10:24 +02:00
|
|
|
newSortAttribute = "screenName";
|
2007-06-28 22:37:27 +02:00
|
|
|
else if (headerId == "orgHeader")
|
2007-09-07 00:10:24 +02:00
|
|
|
newSortAttribute = "org";
|
2007-06-28 22:37:27 +02:00
|
|
|
else if (headerId == "phoneHeader")
|
2007-09-07 00:10:24 +02:00
|
|
|
newSortAttribute = "phone";
|
2007-06-28 22:37:27 +02:00
|
|
|
|
|
|
|
if (sorting["attribute"] == newSortAttribute)
|
|
|
|
sorting["ascending"] = !sorting["ascending"];
|
|
|
|
else {
|
|
|
|
sorting["attribute"] = newSortAttribute;
|
|
|
|
sorting["ascending"] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshCurrentFolder();
|
2006-08-03 23:28:33 +02:00
|
|
|
|
2007-09-24 23:26:23 +02:00
|
|
|
Event.stop(event);
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function newContact(sender) {
|
2007-08-21 18:00:25 +02:00
|
|
|
openContactWindow(URLForFolderID(currentContactFolder) + "/new");
|
2006-08-03 23:28:33 +02:00
|
|
|
|
|
|
|
return false; /* stop following the link */
|
|
|
|
}
|
2006-08-09 23:36:35 +02:00
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onFolderSelectionChange() {
|
2007-03-29 20:05:23 +02:00
|
|
|
var folderList = $("contactFolders");
|
|
|
|
var nodes = folderList.getSelectedNodes();
|
|
|
|
$("contactView").innerHTML = '';
|
|
|
|
|
|
|
|
if (nodes[0].hasClassName("denied")) {
|
|
|
|
var div = $("contactsListContent");
|
2007-09-24 23:26:23 +02:00
|
|
|
div.update();
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
2007-06-28 22:37:27 +02:00
|
|
|
else {
|
|
|
|
search = {};
|
|
|
|
sorting = {};
|
|
|
|
$("searchValue").value = "";
|
|
|
|
initCriteria();
|
|
|
|
openContactsFolder(nodes[0].getAttribute("id"));
|
|
|
|
}
|
2006-08-09 23:36:35 +02:00
|
|
|
}
|
|
|
|
|
2007-08-15 00:09:20 +02:00
|
|
|
function refreshCurrentFolder() {
|
2007-06-28 22:37:27 +02:00
|
|
|
openContactsFolder(currentContactFolder, true);
|
2006-08-09 23:36:35 +02:00
|
|
|
}
|
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
function onConfirmContactSelection(event) {
|
|
|
|
var tag = this.getAttribute("name");
|
|
|
|
var folderLi = $(currentContactFolder);
|
|
|
|
var currentContactFolderName = folderLi.innerHTML;
|
|
|
|
var selectorList = null;
|
|
|
|
var initialValues = null;
|
2006-10-14 01:36:15 +02:00
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
if (selector) {
|
2006-10-14 01:36:15 +02:00
|
|
|
var selectorId = selector.getAttribute("id");
|
|
|
|
selectorList = opener.window.document.getElementById('uixselector-'
|
|
|
|
+ selectorId
|
|
|
|
+ '-uidList');
|
|
|
|
initialValues = selectorList.value;
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
2006-11-01 21:33:03 +01:00
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
var contactsList = $("contactsList");
|
|
|
|
var rows = contactsList.getSelectedRows();
|
|
|
|
for (i = 0; i < rows.length; i++) {
|
|
|
|
var cid = rows[i].getAttribute("contactid");
|
|
|
|
var cname = '' + rows[i].getAttribute("contactname");
|
|
|
|
var email = '' + rows[i].cells[1].innerHTML;
|
|
|
|
opener.window.addContact(tag, currentContactFolderName + '/' + cname,
|
|
|
|
cid, cname, email);
|
|
|
|
}
|
2006-11-01 21:33:03 +01:00
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
if (selector && selector.changeNotification
|
|
|
|
&& selectorList.value != initialValues)
|
|
|
|
selector.changeNotification("addition");
|
2006-11-01 21:33:03 +01:00
|
|
|
|
2007-06-28 22:37:27 +02:00
|
|
|
preventDefault(event);
|
2006-11-01 21:33:03 +01:00
|
|
|
}
|
|
|
|
|
2006-09-16 00:27:59 +02:00
|
|
|
function onContactMailTo(node) {
|
|
|
|
return openMailTo(node.innerHTML);
|
|
|
|
}
|
2006-09-19 15:50:19 +02:00
|
|
|
|
|
|
|
function refreshContacts(contactId) {
|
2007-06-28 22:37:27 +02:00
|
|
|
refreshCurrentFolder();
|
|
|
|
cachedContacts[currentContactFolder + "/" + contactId] = null;
|
|
|
|
loadContact(contactId);
|
2006-09-19 15:50:19 +02:00
|
|
|
|
2007-06-28 22:37:27 +02:00
|
|
|
return false;
|
2006-09-19 15:50:19 +02:00
|
|
|
}
|
2006-11-01 21:33:03 +01:00
|
|
|
|
2007-02-09 22:25:13 +01:00
|
|
|
function onAddressBookNew(event) {
|
2007-09-15 00:01:02 +02:00
|
|
|
createFolder(window.prompt(labels["Name of the Address Book"]),
|
|
|
|
appendAddressBook);
|
2007-06-11 23:10:10 +02:00
|
|
|
preventDefault(event);
|
2007-02-09 22:25:13 +01:00
|
|
|
}
|
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
function appendAddressBook(name, folder) {
|
2007-09-15 00:01:02 +02:00
|
|
|
if (folder)
|
|
|
|
folder = accessToSubscribedFolder(folder);
|
|
|
|
else
|
|
|
|
folder = "/" + name;
|
2007-09-15 03:54:23 +02:00
|
|
|
if ($(folder))
|
|
|
|
window.alert(clabels["You have already subscribed to that folder!"]);
|
|
|
|
else {
|
|
|
|
var li = document.createElement("li");
|
|
|
|
$("contactFolders").appendChild(li);
|
|
|
|
li.setAttribute("id", folder);
|
|
|
|
li.appendChild(document.createTextNode(name));
|
|
|
|
setEventsOnContactFolder(li);
|
|
|
|
}
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
function newFolderCallback(http) {
|
2007-02-09 22:25:13 +01:00
|
|
|
if (http.readyState == 4
|
|
|
|
&& http.status == 201) {
|
|
|
|
var name = http.callbackData;
|
2007-03-29 20:05:23 +02:00
|
|
|
appendAddressBook(name, "/" + name);
|
2007-02-09 22:25:13 +01:00
|
|
|
}
|
|
|
|
else
|
2007-06-12 17:39:47 +02:00
|
|
|
log ("ajax problem 4:" + http.status);
|
2007-02-09 22:25:13 +01:00
|
|
|
}
|
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
function newUserFolderCallback(folderData) {
|
|
|
|
var folder = $(folderData["folder"]);
|
|
|
|
if (!folder)
|
|
|
|
appendAddressBook(folderData["folderName"], folderData["folder"]);
|
|
|
|
}
|
|
|
|
|
2007-02-09 22:25:13 +01:00
|
|
|
function onAddressBookAdd(event) {
|
2007-03-29 20:05:23 +02:00
|
|
|
openUserFolderSelector(newUserFolderCallback, "contact");
|
2006-11-01 21:33:03 +01:00
|
|
|
|
2007-06-28 22:37:27 +02:00
|
|
|
preventDefault(event);
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onFolderUnsubscribeCB(folderId) {
|
|
|
|
var node = $(folderId);
|
|
|
|
node.parentNode.removeChild(node);
|
|
|
|
var personal = $("/personal");
|
|
|
|
personal.select();
|
|
|
|
onFolderSelectionChange();
|
2006-11-01 21:33:03 +01:00
|
|
|
}
|
|
|
|
|
2007-02-09 22:25:13 +01:00
|
|
|
function onAddressBookRemove(event) {
|
2006-11-01 21:33:03 +01:00
|
|
|
var selector = $("contactFolders");
|
|
|
|
var nodes = selector.getSelectedNodes();
|
2007-03-29 20:05:23 +02:00
|
|
|
if (nodes.length > 0) {
|
2007-09-15 00:01:02 +02:00
|
|
|
nodes[0].deselect();
|
|
|
|
var folderId = nodes[0].getAttribute("id");
|
|
|
|
var folderIdElements = folderId.split("_");
|
|
|
|
if (folderIdElements.length > 1)
|
|
|
|
unsubscribeFromFolder(folderId, onFolderUnsubscribeCB, folderId);
|
|
|
|
else {
|
|
|
|
var abId = folderIdElements[0].substr(1);
|
|
|
|
deletePersonalAddressBook(abId);
|
|
|
|
var personal = $("/personal");
|
|
|
|
personal.select();
|
|
|
|
onFolderSelectionChange();
|
|
|
|
}
|
2006-11-01 21:33:03 +01:00
|
|
|
}
|
|
|
|
|
2007-06-28 22:37:27 +02:00
|
|
|
preventDefault(event);
|
2006-11-01 21:33:03 +01:00
|
|
|
}
|
2006-11-09 23:55:04 +01:00
|
|
|
|
2007-03-21 15:29:09 +01:00
|
|
|
function deletePersonalAddressBook(folderId) {
|
2007-09-15 00:01:02 +02:00
|
|
|
var label
|
|
|
|
= labels["Are you sure you want to delete the selected address book?"];
|
|
|
|
if (window.confirm(label)) {
|
|
|
|
if (document.deletePersonalABAjaxRequest) {
|
|
|
|
document.deletePersonalABAjaxRequest.aborted = true;
|
|
|
|
document.deletePersonalABAjaxRequest.abort();
|
|
|
|
}
|
|
|
|
var url = ApplicationBaseURL + "/" + folderId + "/deleteFolder";
|
|
|
|
document.deletePersonalABAjaxRequest
|
|
|
|
= triggerAjaxRequest(url, deletePersonalAddressBookCallback,
|
|
|
|
folderId);
|
|
|
|
}
|
2007-03-21 15:29:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function deletePersonalAddressBookCallback(http) {
|
|
|
|
if (http.readyState == 4) {
|
2007-09-15 00:01:02 +02:00
|
|
|
if (isHttpStatus204(http.status)) {
|
|
|
|
var ul = $("contactFolders");
|
2007-03-21 15:29:09 +01:00
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
var children = ul.childNodesWithTag("li");
|
|
|
|
var i = 0;
|
|
|
|
var done = false;
|
|
|
|
while (!done && i < children.length) {
|
|
|
|
var currentFolderId = children[i].getAttribute("id").substr(1);
|
|
|
|
if (currentFolderId == http.callbackData) {
|
|
|
|
ul.removeChild(children[i]);
|
|
|
|
done = true;
|
2007-03-21 15:29:09 +01:00
|
|
|
}
|
2007-09-15 00:01:02 +02:00
|
|
|
else
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.deletePersonalABAjaxRequest = null;
|
2007-03-21 15:29:09 +01:00
|
|
|
}
|
|
|
|
else
|
2007-09-15 00:01:02 +02:00
|
|
|
log ("ajax problem 5: " + http.status);
|
2007-03-21 15:29:09 +01:00
|
|
|
}
|
|
|
|
|
2006-11-09 23:55:04 +01:00
|
|
|
function configureDragHandles() {
|
|
|
|
var handle = $("dragHandle");
|
|
|
|
if (handle) {
|
|
|
|
handle.addInterface(SOGoDragHandlesInterface);
|
|
|
|
handle.leftBlock=$("contactFoldersList");
|
|
|
|
handle.rightBlock=$("rightPanel");
|
2007-09-17 23:29:08 +02:00
|
|
|
handle.leftMargin = 100;
|
2006-11-09 23:55:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handle = $("rightDragHandle");
|
|
|
|
if (handle) {
|
|
|
|
handle.addInterface(SOGoDragHandlesInterface);
|
|
|
|
handle.upperBlock=$("contactsListContent");
|
|
|
|
handle.lowerBlock=$("contactView");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-20 23:53:58 +01:00
|
|
|
function lookupDeniedFolders() {
|
2007-03-29 20:05:23 +02:00
|
|
|
var list = $("contactFolders").childNodesWithTag("li");
|
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
|
|
var folderID = list[i].getAttribute("id");
|
|
|
|
var url = URLForFolderID(folderID) + "/canAccessContent";
|
|
|
|
triggerAjaxRequest(url, deniedFoldersLookupCallback, folderID);
|
2006-12-20 23:53:58 +01:00
|
|
|
}
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function deniedFoldersLookupCallback(http) {
|
2007-06-12 16:58:15 +02:00
|
|
|
if (http.readyState == 4) {
|
|
|
|
var denied = ! isHttpStatus204(http.status);
|
2007-03-29 20:05:23 +02:00
|
|
|
var entry = $(http.callbackData);
|
|
|
|
if (denied)
|
|
|
|
entry.addClassName("denied");
|
|
|
|
else
|
|
|
|
entry.removeClassName("denied");
|
|
|
|
}
|
2006-12-20 23:53:58 +01:00
|
|
|
}
|
|
|
|
|
2007-02-09 22:25:13 +01:00
|
|
|
function configureAbToolbar() {
|
|
|
|
var toolbar = $("abToolbar");
|
|
|
|
var links = toolbar.childNodesWithTag("a");
|
2007-05-25 16:30:56 +02:00
|
|
|
Event.observe(links[0], "click", onAddressBookNew, false);
|
|
|
|
Event.observe(links[1], "click", onAddressBookAdd, false);
|
|
|
|
Event.observe(links[2], "click", onAddressBookRemove, false);
|
2007-02-09 22:25:13 +01:00
|
|
|
}
|
|
|
|
|
2006-11-09 23:55:04 +01:00
|
|
|
function configureContactFolders() {
|
|
|
|
var contactFolders = $("contactFolders");
|
2006-12-20 23:53:58 +01:00
|
|
|
if (contactFolders) {
|
2007-06-12 16:27:40 +02:00
|
|
|
Event.observe(contactFolders, "mousedown", listRowMouseDownHandler);
|
|
|
|
Event.observe(contactFolders, "click", onFolderSelectionChange);
|
2006-12-20 23:53:58 +01:00
|
|
|
var lis = contactFolders.childNodesWithTag("li");
|
2007-05-25 17:46:07 +02:00
|
|
|
for (var i = 0; i < lis.length; i++)
|
2007-05-25 16:30:56 +02:00
|
|
|
setEventsOnContactFolder(lis[i]);
|
2006-12-20 23:53:58 +01:00
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
lookupDeniedFolders();
|
2007-06-12 16:58:15 +02:00
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
var personalFolder = $("/personal");
|
|
|
|
personalFolder.select();
|
2007-06-28 22:37:27 +02:00
|
|
|
openContactsFolder("/personal");
|
2006-12-20 23:53:58 +01:00
|
|
|
}
|
2006-12-14 22:20:13 +01:00
|
|
|
}
|
|
|
|
|
2007-05-25 16:30:56 +02:00
|
|
|
function setEventsOnContactFolder(node) {
|
2007-06-28 22:37:27 +02:00
|
|
|
Event.observe(node, "mousedown", listRowMouseDownHandler, false);
|
|
|
|
Event.observe(node, "click", onRowClick, false);
|
|
|
|
Event.observe(node, "contextmenu",
|
|
|
|
onContactFoldersContextMenu.bindAsEventListener(node), false);
|
2007-05-25 16:30:56 +02:00
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
function onMenuModify(event) {
|
|
|
|
var folders = $("contactFolders");
|
|
|
|
var selected = folders.getSelectedNodes()[0];
|
|
|
|
|
|
|
|
if (UserLogin == selected.getAttribute("owner")) {
|
|
|
|
var currentName = selected.innerHTML;
|
|
|
|
var newName = window.prompt(labels["Address Book Name"],
|
|
|
|
currentName);
|
|
|
|
if (newName && newName.length > 0
|
|
|
|
&& newName != currentName) {
|
|
|
|
var url = (URLForFolderID(selected.getAttribute("id"))
|
|
|
|
+ "/renameFolder?name=" + escape(newName.utf8encode()));
|
|
|
|
triggerAjaxRequest(url, folderRenameCallback,
|
|
|
|
{node: selected, name: newName});
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
window.alert(clabels["Unable to rename that folder!"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function folderRenameCallback(http) {
|
|
|
|
if (http.readyState == 4) {
|
|
|
|
if (isHttpStatus204(http.status)) {
|
|
|
|
var dict = http.callbackData;
|
|
|
|
dict["node"].innerHTML = dict["name"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-19 03:12:23 +02:00
|
|
|
function onMenuSharing(event) {
|
|
|
|
var folders = $("contactFolders");
|
|
|
|
var selected = folders.getSelectedNodes()[0];
|
2007-10-17 00:14:50 +02:00
|
|
|
var owner = selected.getAttribute("owner");
|
|
|
|
if (owner == "nobody")
|
|
|
|
window.alert(clabels["The user rights cannot be"
|
|
|
|
+ " edited for this object!"]);
|
|
|
|
else {
|
|
|
|
var title = this.innerHTML;
|
|
|
|
var url = URLForFolderID(selected.getAttribute("id"));
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2007-10-17 00:14:50 +02:00
|
|
|
openAclWindow(url + "/acls", title);
|
|
|
|
}
|
2006-12-14 22:20:13 +01:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:19:17 +02:00
|
|
|
function getMenus() {
|
|
|
|
var menus = {};
|
2007-09-15 00:01:02 +02:00
|
|
|
menus["contactFoldersMenu"] = new Array(onMenuModify, "-", null,
|
2007-05-22 17:19:52 +02:00
|
|
|
null, "-", null, "-",
|
|
|
|
onMenuSharing);
|
2007-05-22 16:54:46 +02:00
|
|
|
menus["contactMenu"] = new Array(onMenuEditContact, "-",
|
|
|
|
onMenuWriteToContact, null, "-",
|
|
|
|
onMenuDeleteContact);
|
|
|
|
menus["searchMenu"] = new Array(setSearchCriteria);
|
|
|
|
|
2007-05-28 21:19:17 +02:00
|
|
|
return menus;
|
2006-11-09 23:55:04 +01:00
|
|
|
}
|
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
function configureSelectionButtons() {
|
|
|
|
var container = $("contactSelectionButtons");
|
|
|
|
if (container) {
|
|
|
|
var buttons = container.childNodesWithTag("input");
|
|
|
|
for (var i = 0; i < buttons.length; i++)
|
2007-06-28 22:37:27 +02:00
|
|
|
Event.observe(buttons[i], "click",
|
|
|
|
onConfirmContactSelection.bindAsEventListener(buttons[i]));
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-12 16:58:15 +02:00
|
|
|
function initContacts(event) {
|
|
|
|
if (!document.body.hasClassName("popup")) {
|
|
|
|
configureAbToolbar();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
configureSelectionButtons();
|
|
|
|
configureContactFolders();
|
2006-11-09 23:55:04 +01:00
|
|
|
// initDnd();
|
2007-09-24 23:26:23 +02:00
|
|
|
|
|
|
|
var table = $("contactsList");
|
|
|
|
if (table) {
|
|
|
|
// Initialize contacts table
|
|
|
|
configureSortableTableHeaders(table);
|
|
|
|
TableKit.Resizable.init(table, {'trueResize' : true, 'keepWidth' : true});
|
|
|
|
}
|
2006-11-09 23:55:04 +01:00
|
|
|
}
|
|
|
|
|
2007-06-12 16:58:15 +02:00
|
|
|
addEvent(window, 'load', initContacts);
|