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-09-29 20:10:07 +02:00
|
|
|
function openContactWindow(sender, url) {
|
2007-03-22 20:02:04 +01:00
|
|
|
var msgWin = window.open(url, null, "width=450,height=600,resizable=0");
|
2006-08-03 23:28:33 +02:00
|
|
|
msgWin.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2006-10-12 23:05:58 +02:00
|
|
|
alert(labels.error_validationfailed.decodeEntities() + ":\n"
|
|
|
|
+ errortext.decodeEntities());
|
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) {
|
|
|
|
if (contactsFolder != currentContactFolder || reload) {
|
|
|
|
currentContactFolder = contactsFolder;
|
|
|
|
var url = URLForFolderID(currentContactFolder) +
|
|
|
|
"/view?noframe=1";
|
|
|
|
|
|
|
|
var searchValue = search["value"];
|
|
|
|
if (searchValue && searchValue.length > 0)
|
|
|
|
url += ("&search=" + search["criteria"]
|
|
|
|
+ "&value=" + searchValue);
|
|
|
|
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();
|
|
|
|
else
|
|
|
|
window.alert("no contactsList");
|
|
|
|
}
|
|
|
|
else
|
2007-06-28 22:37:27 +02:00
|
|
|
selection = null;
|
|
|
|
|
|
|
|
if (document.contactsListAjaxRequest) {
|
|
|
|
document.contactsListAjaxRequest.aborted = true;
|
|
|
|
document.contactsListAjaxRequest.abort();
|
|
|
|
}
|
|
|
|
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-06-28 22:37:27 +02:00
|
|
|
function configureContactsListHeaders(cells) {
|
|
|
|
for (var i = 0; i < cells.length; i++) {
|
|
|
|
var currentCell = $(cells[i]);
|
|
|
|
Event.observe(currentCell, "click",
|
|
|
|
onHeaderClick.bindAsEventListener(currentCell));
|
|
|
|
Event.observe(currentCell, "mousedown", listRowMouseDownHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function contactsListCallback(http) {
|
2006-12-20 17:45:52 +01:00
|
|
|
var div = $("contactsListContent");
|
|
|
|
|
2006-12-20 23:53:58 +01:00
|
|
|
if (http.readyState == 4
|
|
|
|
&& http.status == 200) {
|
|
|
|
document.contactsListAjaxRequest = null;
|
|
|
|
div.innerHTML = http.responseText;
|
2007-06-28 22:37:27 +02:00
|
|
|
|
|
|
|
var table = $("contactsList");
|
|
|
|
if (table)
|
|
|
|
configureContactsListHeaders(table.tBodies[0].rows[0].cells);
|
|
|
|
|
|
|
|
if (sorting["attribute"] && sorting["attribute"].length > 0) {
|
|
|
|
var sortHeader;
|
|
|
|
if (sorting["attribute"] == "cn")
|
|
|
|
sortHeader = $("nameHeader");
|
|
|
|
else if (sorting["attribute"] == "mail")
|
|
|
|
sortHeader = $("mailHeader");
|
|
|
|
else if (sorting["attribute"] == "screenname")
|
|
|
|
sortHeader = $("screenNameHeader");
|
|
|
|
else if (sorting["attribute"] == "o")
|
|
|
|
sortHeader = $("orgHeader");
|
|
|
|
else if (sorting["attribute"] == "telephonenumber")
|
|
|
|
sortHeader = $("phoneHeader");
|
|
|
|
else
|
|
|
|
sortHeader = null;
|
|
|
|
|
|
|
|
if (sortHeader) {
|
|
|
|
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-06-12 17:39:47 +02:00
|
|
|
log ("ajax problem 1");
|
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-05-25 16:30:56 +02:00
|
|
|
Event.observe(menu, "hideMenu", 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++)
|
2006-12-20 23:53:58 +01:00
|
|
|
selectedNodes[i].deselect();
|
|
|
|
topNode.menuSelectedEntry = this;
|
|
|
|
this.select();
|
2006-11-03 20:40:12 +01:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onContactContextMenu(event, element) {
|
2006-11-03 20:40:12 +01:00
|
|
|
var menu = $("contactMenu");
|
2007-05-25 16:30:56 +02:00
|
|
|
Event.observe(menu, "hideMenu", 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++)
|
2006-12-20 23:53:58 +01:00
|
|
|
selectedNodes[i].deselect();
|
2006-08-03 23:28:33 +02:00
|
|
|
topNode.menuSelectedEntry = element;
|
2006-12-20 23:53:58 +01: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) {
|
2006-12-20 23:53:58 +01: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++)
|
2006-12-20 23:53:58 +01: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');
|
|
|
|
|
2006-09-29 20:10:07 +02:00
|
|
|
openContactWindow(null,
|
2007-03-29 20:05:23 +02:00
|
|
|
URLForFolderID(currentContactFolder)
|
2006-09-13 23:23:44 +02:00
|
|
|
+ "/" + contactId + "/edit");
|
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
|
|
|
|
2006-09-29 20:10:07 +02:00
|
|
|
openContactWindow(null,
|
2007-03-29 20:05:23 +02:00
|
|
|
URLForFolderID(currentContactFolder)
|
2006-08-03 23:28:33 +02:00
|
|
|
+ "/" + contactId + "/edit");
|
|
|
|
}
|
|
|
|
|
2007-05-22 16:54:46 +02:00
|
|
|
function onMenuWriteToContact(event) {
|
|
|
|
var contactId = document.menuTarget.getAttribute('id');
|
2006-08-03 23:28:33 +02:00
|
|
|
|
2007-05-22 16:54:46 +02:00
|
|
|
openMailComposeWindow(ApplicationBaseURL + currentContactFolder
|
|
|
|
+ "/" + contactId + "/write");
|
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++) {
|
2006-09-29 20:10:07 +02:00
|
|
|
openContactWindow(null,
|
2007-03-29 20:05:23 +02:00
|
|
|
URLForFolderID(currentContactFolder)
|
2006-08-03 23:28:33 +02:00
|
|
|
+ "/" + rows[i] + "/edit");
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2006-10-19 21:23:58 +02:00
|
|
|
for (var i = 0; i < rows.length; i++)
|
2007-03-29 20:05:23 +02:00
|
|
|
openMailComposeWindow(ApplicationBaseURL + currentContactFolder
|
2006-10-19 21:23:58 +02:00
|
|
|
+ "/" + rows[i] + "/write");
|
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)
|
|
|
|
{
|
|
|
|
w = window.open("compose?mailto=" + mailto,
|
|
|
|
"SOGo_compose",
|
|
|
|
"width=680,height=520,resizable=1,scrollbars=1,toolbar=0," +
|
|
|
|
"location=0,directories=0,status=0,menubar=0,copyhistory=0");
|
|
|
|
w.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
newSortAttribute = "cn";
|
|
|
|
else if (headerId == "mailHeader")
|
|
|
|
newSortAttribute = "mail";
|
|
|
|
else if (headerId == "screenNameHeader")
|
|
|
|
newSortAttribute = "screenname";
|
|
|
|
else if (headerId == "orgHeader")
|
|
|
|
newSortAttribute = "o";
|
|
|
|
else if (headerId == "phoneHeader")
|
|
|
|
newSortAttribute = "telephonenumber";
|
|
|
|
|
|
|
|
log("header: " + headerId);
|
|
|
|
|
|
|
|
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-06-28 22:37:27 +02:00
|
|
|
preventDefault(event);
|
2006-08-03 23:28:33 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function registerDraggableMessageNodes() {
|
2006-08-03 23:28:33 +02:00
|
|
|
log ("can we drag...");
|
|
|
|
}
|
|
|
|
|
|
|
|
function newContact(sender) {
|
2006-09-29 20:10:07 +02:00
|
|
|
openContactWindow(sender,
|
2007-03-29 20:05:23 +02:00
|
|
|
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");
|
|
|
|
div.innerHTML = "";
|
|
|
|
}
|
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-06-28 22:37:27 +02:00
|
|
|
function refreshCurrentFolder() {
|
|
|
|
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) {
|
|
|
|
var name = window.prompt(labels["Name of the Address Book"].decodeEntities());
|
|
|
|
if (name) {
|
|
|
|
if (document.newAbAjaxRequest) {
|
|
|
|
document.newAbAjaxRequest.aborted = true;
|
|
|
|
document.newAbAjaxRequest.abort();
|
|
|
|
}
|
|
|
|
var url = ApplicationBaseURL + "/newAb?name=" + name;
|
|
|
|
document.newAbAjaxRequest
|
|
|
|
= triggerAjaxRequest(url, newAbCallback, name);
|
|
|
|
}
|
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) {
|
|
|
|
var li = document.createElement("li");
|
2007-06-11 23:10:10 +02:00
|
|
|
$("contactFolders").appendChild(li);
|
2007-03-29 20:05:23 +02:00
|
|
|
li.setAttribute("id", folder);
|
|
|
|
li.appendChild(document.createTextNode(name));
|
2007-05-25 16:30:56 +02:00
|
|
|
setEventsOnContactFolder(li);
|
2007-03-29 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
2007-02-09 22:25:13 +01:00
|
|
|
function newAbCallback(http) {
|
|
|
|
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) {
|
|
|
|
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-03-21 15:54:15 +01:00
|
|
|
var label
|
|
|
|
= labels["Are you sure you want to delete the selected address book?"];
|
|
|
|
if (window.confirm(label.decodeEntities())) {
|
|
|
|
if (document.deletePersonalABAjaxRequest) {
|
|
|
|
document.deletePersonalABAjaxRequest.aborted = true;
|
|
|
|
document.deletePersonalABAjaxRequest.abort();
|
|
|
|
}
|
|
|
|
var url = ApplicationBaseURL + "/" + folderId + "/delete";
|
|
|
|
document.deletePersonalABAjaxRequest
|
|
|
|
= triggerAjaxRequest(url, deletePersonalAddressBookCallback,
|
|
|
|
folderId);
|
2007-03-21 15:29:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function deletePersonalAddressBookCallback(http) {
|
|
|
|
if (http.readyState == 4) {
|
|
|
|
if (http.status == 200) {
|
|
|
|
var ul = $("contactFolders");
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.deletePersonalABAjaxRequest = null;
|
|
|
|
}
|
|
|
|
else
|
2007-06-12 17:39:47 +02:00
|
|
|
log ("ajax problem");
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
2007-06-12 16:58:15 +02:00
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
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-05-19 03:12:23 +02:00
|
|
|
function onMenuSharing(event) {
|
|
|
|
var folders = $("contactFolders");
|
|
|
|
var selected = folders.getSelectedNodes()[0];
|
|
|
|
var title = this.innerHTML;
|
|
|
|
var url = URLForFolderID(selected.getAttribute("id"));
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2007-05-19 03:12:23 +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-05-22 17:19:52 +02:00
|
|
|
menus["contactFoldersMenu"] = new Array(null, "-", null,
|
|
|
|
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-06-12 16:58:15 +02:00
|
|
|
addEvent(window, 'load', initContacts);
|