2010-06-25 21:58:30 +02:00
|
|
|
/* -*- Mode: js2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-08-28 16:48:45 +02:00
|
|
|
|
2007-03-29 20:05:23 +02:00
|
|
|
/* JavaScript for SOGoMail */
|
2010-08-03 20:52:49 +02:00
|
|
|
var accounts = [];
|
2007-05-25 23:12:46 +02:00
|
|
|
var mailboxTree;
|
2007-10-18 23:54:24 +02:00
|
|
|
var mailAccounts;
|
2007-11-02 20:02:24 +01:00
|
|
|
if (typeof textMailAccounts != 'undefined') {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (textMailAccounts.length > 0)
|
|
|
|
mailAccounts = textMailAccounts.evalJSON(true);
|
|
|
|
else
|
|
|
|
mailAccounts = new Array();
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2007-11-21 19:58:03 +01:00
|
|
|
var Mailer = {
|
2009-07-20 23:06:33 +02:00
|
|
|
currentMailbox: null,
|
|
|
|
currentMailboxType: "",
|
|
|
|
currentMessages: {},
|
|
|
|
maxCachedMessages: 20,
|
|
|
|
cachedMessages: new Array(),
|
|
|
|
foldersStateTimer: false,
|
|
|
|
popups: new Array(),
|
2010-05-27 16:41:59 +02:00
|
|
|
quotas: null,
|
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
dataTable: null,
|
|
|
|
dataSources: new Hash()
|
2007-11-21 19:58:03 +01:00
|
|
|
};
|
2007-05-19 03:12:23 +02:00
|
|
|
|
2007-05-22 20:34:02 +02:00
|
|
|
var usersRightsWindowHeight = 320;
|
|
|
|
var usersRightsWindowWidth = 400;
|
2007-05-19 03:12:23 +02:00
|
|
|
|
2007-10-18 00:29:51 +02:00
|
|
|
var pageContent;
|
|
|
|
|
2007-10-24 17:52:08 +02:00
|
|
|
var deleteMessageRequestCount = 0;
|
|
|
|
|
2007-10-26 17:35:51 +02:00
|
|
|
var messageCheckTimer;
|
|
|
|
|
2009-06-16 00:20:01 +02:00
|
|
|
/* We need to override this method since it is adapted to GCS-based folder
|
2009-07-20 23:06:33 +02:00
|
|
|
references, which we do not use here */
|
2009-06-16 00:20:01 +02:00
|
|
|
function URLForFolderID(folderID) {
|
2010-01-05 23:34:35 +01:00
|
|
|
var url = ApplicationBaseURL + encodeURI(folderID.substr(1));
|
2009-06-16 00:20:01 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (url[url.length-1] == '/')
|
|
|
|
url = url.substr(0, url.length-1);
|
2009-06-16 00:20:01 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return url;
|
2009-06-16 00:20:01 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
/* mail list */
|
|
|
|
|
2006-10-03 18:27:02 +02:00
|
|
|
function openMessageWindow(msguid, url) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var wId = '';
|
|
|
|
if (msguid) {
|
|
|
|
wId += "SOGo_msg" + msguid;
|
|
|
|
markMailReadInWindow(window, msguid);
|
|
|
|
}
|
|
|
|
var msgWin = openMailComposeWindow(url, wId);
|
|
|
|
msgWin.focus();
|
|
|
|
Mailer.popups.push(msgWin);
|
2007-07-30 17:55:28 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return false;
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2006-11-09 23:55:04 +01:00
|
|
|
function onMessageDoubleClick(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var action;
|
2007-08-15 22:34:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (Mailer.currentMailboxType == "draft")
|
|
|
|
action = "edit";
|
|
|
|
else
|
|
|
|
action = "popupview";
|
2007-08-15 22:34:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return openMessageWindowsForSelection(action, true);
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleMailSelect(sender) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var row;
|
|
|
|
row = $(sender.name);
|
|
|
|
row.className = sender.checked ? "tableview_selected" : "tableview";
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function openAddressbook(sender) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var urlstr;
|
2007-11-08 16:59:45 +01:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
urlstr = ApplicationBaseURL + "../Contacts/?popup=YES";
|
|
|
|
var w = window.open(urlstr, "Addressbook",
|
|
|
|
"width=640,height=400,resizable=1,scrollbars=1,toolbar=0,"
|
|
|
|
+ "location=no,directories=0,status=0,menubar=0,copyhistory=0");
|
|
|
|
w.focus();
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return false;
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2007-05-19 03:12:23 +02:00
|
|
|
function onMenuSharing(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var folderID = document.menuTarget.getAttribute("dataname");
|
|
|
|
var type = document.menuTarget.getAttribute("datatype");
|
2007-10-25 21:22:07 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (type == "additional")
|
|
|
|
window.alert(clabels["The user rights cannot be"
|
|
|
|
+ " edited for this object!"]);
|
|
|
|
else {
|
|
|
|
var urlstr = URLForFolderID(folderID) + "/acls";
|
|
|
|
openAclWindow(urlstr);
|
|
|
|
}
|
2007-05-19 03:12:23 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
/* mail list DOM changes */
|
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
/* Update the messages list when flagging/unflagging a message.
|
|
|
|
* No AJAX is triggered here. */
|
2009-08-19 21:47:31 +02:00
|
|
|
function flagMailInWindow (win, msguid, flagged) {
|
|
|
|
var row = win.$("row_" + msguid);
|
|
|
|
|
|
|
|
if (row) {
|
2010-05-27 16:41:59 +02:00
|
|
|
var col = row.down("TD.messageFlag");
|
|
|
|
var img = col.down("img");
|
2009-08-19 21:47:31 +02:00
|
|
|
if (flagged) {
|
2009-09-01 22:20:08 +02:00
|
|
|
img.setAttribute("src", ResourcesURL + "/flag.png");
|
|
|
|
img.addClassName("messageIsFlagged");
|
2009-08-19 21:47:31 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-09-01 22:20:08 +02:00
|
|
|
img.setAttribute("src", ResourcesURL + "/dot.png");
|
2009-08-19 21:47:31 +02:00
|
|
|
img.removeClassName ("messageIsFlagged");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
/* Update the messages list when setting the unread/read flag of a message.
|
|
|
|
* No AJAX is triggered here. */
|
2006-07-29 00:59:11 +02:00
|
|
|
function markMailInWindow(win, msguid, markread) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var row = win.$("row_" + msguid);
|
|
|
|
var unseenCount = 0;
|
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
if (row) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (markread) {
|
|
|
|
if (row.hasClassName("mailer_unreadmail")) {
|
|
|
|
row.removeClassName("mailer_unreadmail");
|
2010-05-27 16:41:59 +02:00
|
|
|
var img = win.$("readdiv_" + msguid);
|
2009-07-20 23:06:33 +02:00
|
|
|
if (img) {
|
2009-09-01 22:20:08 +02:00
|
|
|
img.setAttribute("src", ResourcesURL + "/dot.png");
|
2009-07-20 23:06:33 +02:00
|
|
|
var title = img.getAttribute("title-markunread");
|
|
|
|
if (title)
|
|
|
|
img.setAttribute("title", title);
|
|
|
|
}
|
2010-05-27 16:41:59 +02:00
|
|
|
else {
|
|
|
|
log ("No IMG found for " + msguid);
|
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
unseenCount = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!row.hasClassName("mailer_unreadmail")) {
|
|
|
|
row.addClassName("mailer_unreadmail");
|
|
|
|
var img = win.$("readdiv_" + msguid);
|
|
|
|
if (img) {
|
|
|
|
img.setAttribute("src", ResourcesURL + "/icon_unread.gif");
|
|
|
|
var title = img.getAttribute("title-markread");
|
|
|
|
if (title)
|
|
|
|
img.setAttribute("title", title);
|
|
|
|
}
|
2010-06-25 21:58:30 +02:00
|
|
|
else {
|
|
|
|
log ("No IMG found for " + msguid);
|
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
unseenCount = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
if (unseenCount != 0) {
|
|
|
|
// Update unseen count only if it's the inbox
|
|
|
|
for (var i = 0; i < mailboxTree.aNodes.length; i++)
|
|
|
|
if (mailboxTree.aNodes[i].datatype == "inbox") break;
|
|
|
|
if (i != mailboxTree.aNodes.length && Mailer.currentMailbox == mailboxTree.aNodes[i].dataname)
|
|
|
|
updateStatusFolders(unseenCount, true);
|
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (unseenCount != 0);
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2008-08-28 23:44:49 +02:00
|
|
|
function markMailReadInWindow(win, msguid) {
|
2009-07-20 23:06:33 +02:00
|
|
|
/* this is called by UIxMailView with window.opener */
|
|
|
|
return markMailInWindow(win, msguid, true);
|
2008-08-28 23:44:49 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
/* mail list reply */
|
|
|
|
|
2007-08-15 22:34:11 +02:00
|
|
|
function openMessageWindowsForSelection(action, firstOnly) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if ($(document.body).hasClassName("popup")) {
|
|
|
|
var url = window.location.href;
|
|
|
|
var parts = url.split("/");
|
|
|
|
parts[parts.length-1] = action;
|
|
|
|
window.location.href = parts.join("/");
|
|
|
|
}
|
|
|
|
else {
|
2010-05-27 16:41:59 +02:00
|
|
|
var messageList = $("messageListBody");
|
2009-07-20 23:06:33 +02:00
|
|
|
var rows = messageList.getSelectedRowsId();
|
|
|
|
if (rows.length > 0) {
|
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
openMessageWindow(Mailer.currentMailbox + "/" + rows[i].substr(4),
|
|
|
|
ApplicationBaseURL + encodeURI(Mailer.currentMailbox)
|
|
|
|
+ "/" + rows[i].substr(4)
|
|
|
|
+ "/" + action);
|
|
|
|
if (firstOnly)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2010-06-02 21:11:15 +02:00
|
|
|
window.alert(_("Please select a message."));
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
2007-08-15 22:34:11 +02:00
|
|
|
}
|
2007-07-30 17:55:28 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return false;
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
/* Triggered when clicking on the read/unread dot of a message row */
|
2006-11-09 23:55:04 +01:00
|
|
|
function mailListMarkMessage(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var msguid = this.id.split('_')[1];
|
2010-06-25 21:58:30 +02:00
|
|
|
var row = $(this).up('TR');
|
2009-07-20 23:06:33 +02:00
|
|
|
var action;
|
|
|
|
var markread;
|
2010-06-25 21:58:30 +02:00
|
|
|
if (row.hasClassName("mailer_unreadmail")) {
|
2009-07-20 23:06:33 +02:00
|
|
|
action = 'markMessageRead';
|
|
|
|
markread = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
action = 'markMessageUnread';
|
|
|
|
markread = false;
|
|
|
|
}
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
markMailInWindow(window, msguid, markread);
|
|
|
|
|
2010-08-03 20:52:49 +02:00
|
|
|
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/"
|
2009-08-19 21:47:31 +02:00
|
|
|
+ msguid + "/" + action;
|
2009-07-20 23:06:33 +02:00
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
var data = { "msguid": msguid };
|
2009-07-20 23:06:33 +02:00
|
|
|
triggerAjaxRequest(url, mailListMarkMessageCallback, data);
|
|
|
|
|
|
|
|
preventDefault(event);
|
|
|
|
return false;
|
2007-11-05 22:19:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function mailListMarkMessageCallback(http) {
|
2010-06-25 21:58:30 +02:00
|
|
|
var data = http.callbackData;
|
2010-05-27 16:41:59 +02:00
|
|
|
if (isHttpStatus204(http.status)
|
|
|
|
|| http.status == 304) { // In some cases, Safari returns a 304 even
|
|
|
|
// though SOGo returns a 204!
|
2010-06-25 21:58:30 +02:00
|
|
|
Mailer.dataTable.invalidate(data["msguid"], true);
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
|
|
|
else {
|
2010-06-25 21:58:30 +02:00
|
|
|
log("Message Mark Failed (" + http.status + "): " + http.statusText);
|
|
|
|
Mailer.dataTable.invalidate(data["msguid"], false);
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-08-19 21:47:31 +02:00
|
|
|
|
|
|
|
function mailListFlagMessageToggle (e) {
|
|
|
|
var msguid = this.ancestors ().first ().id.split ("_")[1];
|
|
|
|
var img = this.childElements ().first ();
|
|
|
|
|
|
|
|
var action = "markMessageFlagged";
|
|
|
|
var flagged = true;
|
|
|
|
if (img.hasClassName ("messageIsFlagged")) {
|
|
|
|
action = "markMessageUnflagged";
|
|
|
|
flagged = false;
|
|
|
|
}
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
flagMailInWindow(window, msguid, flagged);
|
2010-08-03 20:52:49 +02:00
|
|
|
|
|
|
|
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/"
|
2009-08-19 21:47:31 +02:00
|
|
|
+ msguid + "/" + action;
|
2010-06-25 21:58:30 +02:00
|
|
|
var data = { "msguid": msguid };
|
2009-08-19 21:47:31 +02:00
|
|
|
|
|
|
|
triggerAjaxRequest(url, mailListFlagMessageToggleCallback, data);
|
|
|
|
}
|
2010-05-27 16:41:59 +02:00
|
|
|
|
2009-08-19 21:47:31 +02:00
|
|
|
function mailListFlagMessageToggleCallback (http) {
|
|
|
|
if (isHttpStatus204(http.status)) {
|
|
|
|
var data = http.callbackData;
|
2010-06-25 21:58:30 +02:00
|
|
|
Mailer.dataTable.invalidate(data["msguid"], true);
|
2009-08-19 21:47:31 +02:00
|
|
|
}
|
|
|
|
else {
|
2010-06-25 21:58:30 +02:00
|
|
|
log("Message Mark Failed (" + http.status + "): " + http.statusText);
|
|
|
|
Mailer.dataTable.invalidate(data["msguid"], true);
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2008-10-14 19:36:04 +02:00
|
|
|
function onUnload(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/expunge";
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
new Ajax.Request(url, {
|
|
|
|
asynchronous: false,
|
|
|
|
method: 'get',
|
|
|
|
onFailure: function(transport) {
|
|
|
|
log("Can't expunge current folder: " + transport.status);
|
|
|
|
}
|
|
|
|
});
|
2008-10-14 19:36:04 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return true;
|
2008-10-14 19:36:04 +02:00
|
|
|
}
|
|
|
|
|
2008-09-03 02:59:16 +02:00
|
|
|
function onDocumentKeydown(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var target = Event.element(event);
|
|
|
|
if (target.tagName != "INPUT")
|
|
|
|
if (event.keyCode == Event.KEY_DELETE ||
|
|
|
|
event.keyCode == Event.KEY_BACKSPACE && isMac()) {
|
|
|
|
deleteSelectedMessages();
|
|
|
|
Event.stop(event);
|
|
|
|
}
|
|
|
|
else if (event.keyCode == Event.KEY_DOWN ||
|
|
|
|
event.keyCode == Event.KEY_UP) {
|
|
|
|
if (Mailer.currentMessages[Mailer.currentMailbox]) {
|
|
|
|
var row = $("row_" + Mailer.currentMessages[Mailer.currentMailbox]);
|
|
|
|
var nextRow;
|
|
|
|
if (event.keyCode == Event.KEY_DOWN)
|
|
|
|
nextRow = row.next("tr");
|
|
|
|
else
|
|
|
|
nextRow = row.previous("tr");
|
2010-05-27 16:41:59 +02:00
|
|
|
if (nextRow && nextRow.id != 'rowTop' && nextRow.id != 'rowBottom') {
|
2009-07-20 23:06:33 +02:00
|
|
|
Mailer.currentMessages[Mailer.currentMailbox] = nextRow.getAttribute("id").substr(4);
|
|
|
|
row.up().deselectAll();
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
// Adjust the scollbar
|
2010-06-30 01:41:24 +02:00
|
|
|
var viewPort = $("mailboxList");
|
2009-07-20 23:06:33 +02:00
|
|
|
var divDimensions = viewPort.getDimensions();
|
2010-06-30 01:41:24 +02:00
|
|
|
var centerOffset = divDimensions.height/2;
|
2009-07-20 23:06:33 +02:00
|
|
|
var rowScrollOffset = nextRow.cumulativeScrollOffset();
|
2010-06-30 01:41:24 +02:00
|
|
|
var divBottom = divDimensions.height + rowScrollOffset.top;
|
|
|
|
var rowBottom = nextRow.offsetTop + nextRow.getHeight();
|
2009-07-20 23:06:33 +02:00
|
|
|
|
|
|
|
if (divBottom < rowBottom)
|
2010-06-30 01:41:24 +02:00
|
|
|
viewPort.scrollTop += rowBottom - divBottom + centerOffset;
|
|
|
|
else if (viewPort.scrollTop > nextRow.offsetTop)
|
|
|
|
viewPort.scrollTop -= rowScrollOffset.top - nextRow.offsetTop + centerOffset;
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
// Select and load the next message
|
|
|
|
nextRow.selectElement();
|
|
|
|
loadMessage(Mailer.currentMessages[Mailer.currentMailbox]);
|
|
|
|
}
|
|
|
|
Event.stop(event);
|
|
|
|
}
|
|
|
|
}
|
2008-09-03 02:59:16 +02:00
|
|
|
}
|
|
|
|
|
2009-03-26 21:55:57 +01:00
|
|
|
/* bulk delete of messages */
|
|
|
|
|
2007-10-24 17:52:08 +02:00
|
|
|
function deleteSelectedMessages(sender) {
|
2010-05-27 16:41:59 +02:00
|
|
|
var messageList = $("messageListBody").down("TBODY");
|
2009-07-20 23:06:33 +02:00
|
|
|
var rows = messageList.getSelectedNodes();
|
|
|
|
var uids = new Array(); // message IDs
|
|
|
|
var paths = new Array(); // row IDs
|
2010-05-27 16:41:59 +02:00
|
|
|
var unseenCount = 0;
|
2008-09-05 04:12:56 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (rows.length > 0) {
|
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
var uid = rows[i].readAttribute("id").substr(4);
|
|
|
|
var path = Mailer.currentMailbox + "/" + uid;
|
|
|
|
deleteMessageRequestCount++;
|
|
|
|
rows[i].hide();
|
|
|
|
uids.push(uid);
|
|
|
|
paths.push(path);
|
2010-05-27 16:41:59 +02:00
|
|
|
if (rows[i].hasClassName("mailer_unreadmail"))
|
|
|
|
unseenCount--;
|
|
|
|
}
|
|
|
|
messageList.deselectAll();
|
|
|
|
updateMessageListCounter(0 - rows.length, true);
|
|
|
|
if (unseenCount < 0) {
|
|
|
|
// Update unseen count only if it's the inbox
|
|
|
|
for (var i = 0; i < mailboxTree.aNodes.length; i++)
|
|
|
|
if (mailboxTree.aNodes[i].datatype == "inbox") break;
|
|
|
|
if (i != mailboxTree.aNodes.length && Mailer.currentMailbox == mailboxTree.aNodes[i].dataname)
|
|
|
|
updateStatusFolders(unseenCount, true);
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
|
|
|
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/batchDelete";
|
|
|
|
var parameters = "uid=" + uids.join(",");
|
|
|
|
var data = { "id": uids, "mailbox": Mailer.currentMailbox, "path": paths };
|
|
|
|
triggerAjaxRequest(url, deleteSelectedMessagesCallback, data, parameters,
|
|
|
|
{ "Content-type": "application/x-www-form-urlencoded" });
|
|
|
|
}
|
|
|
|
else
|
2010-06-02 21:11:15 +02:00
|
|
|
window.alert(_("Please select a message."));
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return false;
|
2007-10-24 17:52:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSelectedMessagesCallback(http) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (isHttpStatus204(http.status)) {
|
|
|
|
var data = http.callbackData;
|
|
|
|
for (var i = 0; i < data["path"].length; i++) {
|
|
|
|
deleteCachedMessage(data["path"][i]);
|
|
|
|
deleteMessageRequestCount--;
|
|
|
|
if (Mailer.currentMailbox == data["mailbox"]) {
|
|
|
|
var div = $('messageContent');
|
|
|
|
if (Mailer.currentMessages[Mailer.currentMailbox] == data["id"][i]) {
|
|
|
|
div.update();
|
2010-05-27 16:41:59 +02:00
|
|
|
Mailer.currentMessages[Mailer.currentMailbox] = null;
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
|
|
|
if (deleteMessageRequestCount == 0) {
|
2010-05-27 16:41:59 +02:00
|
|
|
var row = $("row_" + data["id"][i]);
|
|
|
|
if (row) {
|
|
|
|
var nextRow = row.next("tr");
|
|
|
|
if (!nextRow.id.startsWith('row_'))
|
|
|
|
nextRow = row.previous("tr");
|
|
|
|
// row.addClassName("deleted"); // when we'll offer "mark as deleted"
|
|
|
|
if (nextRow.id.startsWith('row_')) {
|
|
|
|
Mailer.currentMessages[Mailer.currentMailbox] = nextRow.getAttribute("id").substr(4);
|
|
|
|
nextRow.selectElement();
|
|
|
|
loadMessage(Mailer.currentMessages[Mailer.currentMailbox]);
|
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
div.update();
|
|
|
|
}
|
2010-05-27 16:41:59 +02:00
|
|
|
Mailer.dataTable.remove(data["id"][i]);
|
|
|
|
Mailer.dataTable.render();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Mailer.dataTable.remove(data["id"][i]);
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-04 21:39:45 +02:00
|
|
|
else {
|
2009-07-20 23:06:33 +02:00
|
|
|
log ("deleteSelectedMessagesCallback: problem during ajax request " + http.status);
|
2010-05-04 21:39:45 +02:00
|
|
|
refreshCurrentFolder();
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2006-11-10 00:11:50 +01:00
|
|
|
function onMenuDeleteMessage(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
deleteSelectedMessages();
|
|
|
|
preventDefault(event);
|
2007-12-10 16:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteMessage(url, id, mailbox, messageId) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var data = { "id": new Array(id), "mailbox": mailbox, "path": new Array(messageId) };
|
|
|
|
var parameters = "uid=" + id;
|
|
|
|
deleteMessageRequestCount++;
|
|
|
|
triggerAjaxRequest(url, deleteSelectedMessagesCallback, data, parameters,
|
|
|
|
{ "Content-type": "application/x-www-form-urlencoded" });
|
2007-12-10 16:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteMessageWithDelay(url, id, mailbox, messageId) {
|
2009-07-20 23:06:33 +02:00
|
|
|
/* this is called by UIxMailPopupView with window.opener */
|
|
|
|
var row = $("row_" + id);
|
|
|
|
if (row) row.hide();
|
|
|
|
setTimeout("deleteMessage('" +
|
|
|
|
url + "', '" +
|
|
|
|
id + "', '" +
|
|
|
|
mailbox + "', '" +
|
|
|
|
messageId + "')",
|
|
|
|
50);
|
2006-11-10 00:11:50 +01:00
|
|
|
}
|
|
|
|
|
2007-08-08 23:36:17 +02:00
|
|
|
function onPrintCurrentMessage(event) {
|
2010-07-20 19:30:54 +02:00
|
|
|
var messageList = $("messageListBody").down("TBODY");
|
|
|
|
var rowIds = messageList.getSelectedNodes();
|
2009-07-20 23:06:33 +02:00
|
|
|
if (rowIds.length == 0) {
|
2010-06-02 21:11:15 +02:00
|
|
|
window.alert(_("Please select a message to print."));
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
|
|
|
else if (rowIds.length > 1) {
|
2010-06-02 21:11:15 +02:00
|
|
|
window.alert(_("Please select only one message to print."));
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
window.print();
|
2007-08-08 23:36:17 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
preventDefault(event);
|
2007-08-08 23:36:17 +02:00
|
|
|
}
|
|
|
|
|
2006-12-22 17:48:11 +01:00
|
|
|
function onMailboxTreeItemClick(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var topNode = $("mailboxTree");
|
|
|
|
var mailbox = this.parentNode.getAttribute("dataname");
|
|
|
|
if (topNode.selectedEntry)
|
|
|
|
topNode.selectedEntry.deselect();
|
|
|
|
this.selectElement();
|
|
|
|
topNode.selectedEntry = this;
|
|
|
|
|
|
|
|
search = {};
|
|
|
|
$("searchValue").value = "";
|
|
|
|
initCriteria();
|
|
|
|
|
|
|
|
Mailer.currentMailboxType = this.parentNode.getAttribute("datatype");
|
|
|
|
if (Mailer.currentMailboxType == "account" || Mailer.currentMailboxType == "additional") {
|
|
|
|
Mailer.currentMailbox = mailbox;
|
|
|
|
$("messageContent").update();
|
|
|
|
var table = $("messageList");
|
|
|
|
var head = table.tHead;
|
|
|
|
var body = table.tBodies[0];
|
2009-08-31 21:52:47 +02:00
|
|
|
if (body.deselectAll) body.deselectAll ();
|
2009-07-20 23:06:33 +02:00
|
|
|
for (var i = body.rows.length; i > 0; i--)
|
|
|
|
body.deleteRow(i-1);
|
|
|
|
if (head.rows[1])
|
|
|
|
head.rows[1].firstChild.update();
|
|
|
|
}
|
2010-05-27 16:41:59 +02:00
|
|
|
else {
|
|
|
|
var datatype = this.parentNode.getAttribute("datatype");
|
|
|
|
if (datatype == 'draft' || datatype == 'sent')
|
|
|
|
toggleAddressColumn("from", "to");
|
|
|
|
else
|
|
|
|
toggleAddressColumn("to", "from");
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
openMailbox(mailbox);
|
2010-05-27 16:41:59 +02:00
|
|
|
}
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
Event.stop(event);
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
function toggleAddressColumn(search, replace) {
|
|
|
|
var header = $(search + "Header");
|
|
|
|
if (header) {
|
|
|
|
header.id = replace + "Header";
|
2010-06-02 21:11:15 +02:00
|
|
|
header.update(_(replace.capitalize()));
|
2010-05-27 16:41:59 +02:00
|
|
|
var i = UserDefaults["SOGoMailListViewColumnsOrder"].indexOf(search.capitalize());
|
|
|
|
if (i >= 0)
|
|
|
|
UserDefaults["SOGoMailListViewColumnsOrder"][i] = replace.capitalize();
|
|
|
|
}
|
2010-05-28 21:18:52 +02:00
|
|
|
if (sorting["attribute"] == search)
|
|
|
|
sorting["attribute"] = replace;
|
2010-05-27 16:41:59 +02:00
|
|
|
}
|
|
|
|
|
2008-10-03 21:01:29 +02:00
|
|
|
function onMailboxMenuMove(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var targetMailbox;
|
2010-05-27 16:41:59 +02:00
|
|
|
var messageList = $("messageListBody").down("TBODY");
|
2009-07-20 23:06:33 +02:00
|
|
|
var rows = messageList.getSelectedNodes();
|
|
|
|
var uids = new Array(); // message IDs
|
|
|
|
var paths = new Array(); // row IDs
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
Mailer.currentMessages[Mailer.currentMailbox] = null;
|
|
|
|
$('messageContent').update();
|
|
|
|
|
|
|
|
if (this.tagName == 'LI') // from contextual menu
|
|
|
|
targetMailbox = this.mailbox.fullName();
|
|
|
|
else // from DnD
|
|
|
|
targetMailbox = this.readAttribute("dataname");
|
|
|
|
|
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
var uid = rows[i].readAttribute("id").substr(4);
|
|
|
|
var path = Mailer.currentMailbox + "/" + uid;
|
|
|
|
rows[i].hide();
|
|
|
|
uids.push(uid);
|
|
|
|
paths.push(path);
|
2009-09-10 20:31:20 +02:00
|
|
|
// Remove references to closed popups
|
|
|
|
for (var j = Mailer.popups.length - 1; j > -1; j--)
|
|
|
|
if (!Mailer.popups[j].open || Mailer.popups[j].closed)
|
|
|
|
Mailer.popups.splice(j,1);
|
|
|
|
// Close message popup if opened
|
2009-07-20 23:06:33 +02:00
|
|
|
for (var j = 0; j < Mailer.popups.length; j++)
|
|
|
|
if (Mailer.popups[j].messageUID == path) {
|
|
|
|
Mailer.popups[j].close();
|
2009-09-10 20:31:20 +02:00
|
|
|
Mailer.popups.splice(j,1);
|
2009-07-20 23:06:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-25 22:43:23 +02:00
|
|
|
|
|
|
|
// Remove cache of target data source
|
2010-07-28 23:17:57 +02:00
|
|
|
deleteCachedMailbox(targetMailbox);
|
2010-06-25 22:43:23 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/moveMessages";
|
|
|
|
var parameters = "uid=" + uids.join(",") + "&folder=" + targetMailbox;
|
|
|
|
var data = { "id": uids, "mailbox": Mailer.currentMailbox, "path": paths, "folder": targetMailbox, "refresh": true };
|
|
|
|
triggerAjaxRequest(url, folderRefreshCallback, data, parameters,
|
|
|
|
{ "Content-type": "application/x-www-form-urlencoded" });
|
|
|
|
|
|
|
|
return false;
|
2007-05-25 23:12:46 +02:00
|
|
|
}
|
|
|
|
|
2007-10-18 00:29:51 +02:00
|
|
|
function onMailboxMenuCopy(event) {
|
2010-05-27 16:41:59 +02:00
|
|
|
var messageList = $("messageListBody").down("TBODY");
|
2009-07-20 23:06:33 +02:00
|
|
|
var rows = messageList.getSelectedNodes();
|
|
|
|
var uids = new Array(); // message IDs
|
|
|
|
var paths = new Array(); // row IDs
|
|
|
|
|
2010-01-05 23:34:35 +01:00
|
|
|
var targetMailbox;
|
2009-07-20 23:06:33 +02:00
|
|
|
if (this.tagName == 'LI') // from contextual menu
|
|
|
|
targetMailbox = this.mailbox.fullName();
|
|
|
|
else // from DnD
|
|
|
|
targetMailbox = this.readAttribute("dataname");
|
2010-01-05 23:34:35 +01:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
var uid = rows[i].readAttribute("id").substr(4);
|
|
|
|
var path = Mailer.currentMailbox + "/" + uid;
|
|
|
|
uids.push(uid);
|
|
|
|
paths.push(path);
|
|
|
|
}
|
2010-06-25 22:43:23 +02:00
|
|
|
|
|
|
|
// Remove cache of target data source
|
2010-07-28 23:17:57 +02:00
|
|
|
deleteCachedMailbox(targetMailbox);
|
2010-06-25 22:43:23 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/copyMessages";
|
|
|
|
var parameters = "uid=" + uids.join(",") + "&folder=" + targetMailbox;
|
|
|
|
var data = { "id": uids, "mailbox": Mailer.currentMailbox, "path": paths, "folder": targetMailbox, "refresh": false };
|
|
|
|
triggerAjaxRequest(url, folderRefreshCallback, data, parameters,
|
|
|
|
{ "Content-type": "application/x-www-form-urlencoded" });
|
2008-10-03 21:01:29 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return false;
|
2007-05-25 23:12:46 +02:00
|
|
|
}
|
|
|
|
|
2007-05-04 17:57:23 +02:00
|
|
|
function refreshMailbox() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var topWindow = getTopWindow();
|
|
|
|
if (topWindow)
|
|
|
|
topWindow.refreshCurrentFolder();
|
2007-05-25 23:12:46 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return false;
|
2006-11-13 23:29:31 +01:00
|
|
|
}
|
|
|
|
|
2007-08-15 22:34:11 +02:00
|
|
|
function onComposeMessage() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var topWindow = getTopWindow();
|
|
|
|
if (topWindow)
|
|
|
|
topWindow.composeNewMessage();
|
2007-08-15 22:34:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return false;
|
2007-08-15 22:34:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function composeNewMessage() {
|
2010-01-22 22:34:39 +01:00
|
|
|
var account;
|
|
|
|
if (Mailer.currentMailbox)
|
|
|
|
account = Mailer.currentMailbox.split("/")[1];
|
|
|
|
else if (mailAccounts.length)
|
2010-08-03 20:52:49 +02:00
|
|
|
account = "0";
|
2010-01-22 22:34:39 +01:00
|
|
|
else
|
|
|
|
account = null;
|
|
|
|
if (account) {
|
2010-08-03 20:52:49 +02:00
|
|
|
var url = ApplicationBaseURL + encodeURI(account) + "/compose";
|
2010-01-22 22:34:39 +01:00
|
|
|
openMailComposeWindow(url);
|
|
|
|
}
|
2007-08-15 22:34:11 +02:00
|
|
|
}
|
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
function openMailbox(mailbox, reload, updateStatus) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (mailbox != Mailer.currentMailbox || reload) {
|
2010-05-27 16:41:59 +02:00
|
|
|
var url = ApplicationBaseURL + encodeURI(mailbox);
|
|
|
|
var urlParams = new Hash();
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
if (!reload) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var messageContent = $("messageContent");
|
|
|
|
messageContent.update();
|
2010-05-28 21:18:52 +02:00
|
|
|
$("messageCountHeader").down().update(' ');
|
2009-07-20 23:06:33 +02:00
|
|
|
lastClickedRow = -1; // from generic.js
|
|
|
|
}
|
|
|
|
|
|
|
|
var searchValue = search["value"];
|
2010-05-27 16:41:59 +02:00
|
|
|
if (searchValue && searchValue.length > 0) {
|
|
|
|
urlParams.set("search", search["criteria"]);
|
|
|
|
urlParams.set("value", escape(searchValue.utf8encode()));
|
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
var sortAttribute = sorting["attribute"];
|
2010-05-27 16:41:59 +02:00
|
|
|
if (sortAttribute && sortAttribute.length > 0) {
|
|
|
|
urlParams.set("sort", sorting["attribute"]);
|
|
|
|
urlParams.set("asc", sorting["ascending"]);
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
var sortHeader = $(sorting["attribute"] + "Header");
|
|
|
|
if (sortHeader) {
|
|
|
|
var sortImages = sortHeader.up('THEAD').select(".sortImage");
|
|
|
|
$(sortImages).each(function(item) {
|
|
|
|
item.remove();
|
|
|
|
});
|
|
|
|
var sortImage = createElement("img", "messageSortImage", "sortImage");
|
|
|
|
sortHeader.insertBefore(sortImage, sortHeader.firstChild);
|
|
|
|
if (sorting["ascending"])
|
|
|
|
sortImage.src = ResourcesURL + "/arrow-down.png";
|
|
|
|
else
|
|
|
|
sortImage.src = ResourcesURL + "/arrow-up.png";
|
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
// TODO : refresh mailbox without removing all rows.
|
|
|
|
var messageList = $("messageListBody").down('TBODY');
|
2010-06-25 21:58:30 +02:00
|
|
|
var key = mailbox;
|
|
|
|
if (urlParams.keys().length > 0) {
|
|
|
|
var p = urlParams.keys().collect(function(key) { return key + "=" + urlParams.get(key); }).join("&");
|
|
|
|
key += "?" + p;
|
|
|
|
}
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
var dataSource = Mailer.dataSources.get(key);
|
|
|
|
if (!dataSource || reload) {
|
|
|
|
dataSource = new SOGoMailDataSource(Mailer.dataTable, url);
|
|
|
|
if (inboxData[key]) {
|
|
|
|
dataSource.init(inboxData[key][0], inboxData[key][1]);
|
|
|
|
inboxData = []; // invalidate this initial lookup
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dataSource.load(urlParams);
|
|
|
|
Mailer.dataSources.set(key, dataSource);
|
|
|
|
}
|
|
|
|
Mailer.dataTable.setSource(dataSource);
|
2010-05-27 16:41:59 +02:00
|
|
|
messageList.deselectAll();
|
|
|
|
Mailer.dataTable.render();
|
|
|
|
configureDraggables();
|
|
|
|
Mailer.currentMailbox = mailbox;
|
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
// Restore previous selection
|
2010-05-27 16:41:59 +02:00
|
|
|
var currentMessage = Mailer.currentMessages[mailbox];
|
|
|
|
if (currentMessage) {
|
2010-06-25 21:58:30 +02:00
|
|
|
if (!reload) {
|
2010-05-27 16:41:59 +02:00
|
|
|
loadMessage(currentMessage);
|
2010-06-25 21:58:30 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
|
|
|
|
if (updateStatus != false)
|
|
|
|
getStatusFolders();
|
2007-07-30 17:55:28 +02:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
/*
|
|
|
|
* Called from SOGoDataTable.render()
|
|
|
|
*/
|
|
|
|
function messageListCallback(row, data, isNew) {
|
2010-06-25 21:58:30 +02:00
|
|
|
var currentMessage = Mailer.currentMessages[Mailer.currentMailbox];
|
|
|
|
|
|
|
|
row.id = data['rowID'];
|
|
|
|
row.writeAttribute('labels', (data['labels']?data['labels']:""));
|
|
|
|
row.className = data['rowClasses'];
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
// Restore previous selection
|
|
|
|
if (data['uid'] == currentMessage)
|
|
|
|
row.addClassName('_selected');
|
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
if (isNew) {
|
|
|
|
row.observe("mousedown", onRowClick);
|
|
|
|
row.observe("selectstart", listRowMouseDownHandler);
|
|
|
|
row.observe("contextmenu", onMessageContextMenu);
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
var columnsOrder = UserDefaults["SOGoMailListViewColumnsOrder"];
|
2010-05-27 16:41:59 +02:00
|
|
|
var cells;
|
|
|
|
if (Prototype.Browser.IE)
|
|
|
|
cells = row.childNodes;
|
|
|
|
else
|
|
|
|
cells = row.cells;
|
2009-07-20 23:06:33 +02:00
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
for (var j = 0; j < cells.length; j++) {
|
|
|
|
var cell = $(cells[j]);
|
|
|
|
var cellType = columnsOrder[j];
|
|
|
|
|
|
|
|
if (data[cellType]) cell.update(data[cellType]);
|
2010-06-07 18:31:51 +02:00
|
|
|
else if (Prototype.Browser.IE) cell.update(' ');
|
2010-05-27 16:41:59 +02:00
|
|
|
|
|
|
|
cell.observe("mousedown", listRowMouseDownHandler);
|
|
|
|
if (cellType == "Subject" || cellType == "From" || cellType == "To" || cellType == "Date")
|
|
|
|
cell.observe("dblclick", onMessageDoubleClick.bindAsEventListener(cell));
|
|
|
|
else if (cellType == "Unread") {
|
|
|
|
var img = cell.down('img');
|
|
|
|
if (img)
|
|
|
|
img.observe("click", mailListMarkMessage.bindAsEventListener(img));
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
2010-05-27 16:41:59 +02:00
|
|
|
else if (cellType == 'Flagged' && isNew)
|
|
|
|
cell.observe("click", mailListFlagMessageToggle.bindAsEventListener(cell));
|
2007-09-24 23:26:23 +02:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 21:27:37 +02:00
|
|
|
function getStatusFolders() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var account = Mailer.currentMailbox.split("/")[1];
|
|
|
|
var url = ApplicationBaseURL + encodeURI(account) + '/statusFolders';
|
|
|
|
if (document.statusFoldersAjaxRequest) {
|
|
|
|
document.statusFoldersAjaxRequest.aborted = true;
|
|
|
|
document.statusFoldersAjaxRequest.abort();
|
|
|
|
}
|
|
|
|
document.statusFoldersAjaxRequest = triggerAjaxRequest(url, statusFoldersCallback);
|
2008-10-09 21:27:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function statusFoldersCallback(http) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var div = $('mailboxContent');
|
|
|
|
var table = $('messageList');
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (http.status == 200) {
|
|
|
|
document.statusFoldersAjaxRequest = null;
|
|
|
|
var data = http.responseText.evalJSON(true);
|
|
|
|
updateStatusFolders(data.unseen, false);
|
|
|
|
}
|
2008-10-09 21:27:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateStatusFolders(count, isDelta) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var span = $("unseenCount");
|
|
|
|
var counter = null;
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (span)
|
|
|
|
counter = span.select("SPAN").first();
|
|
|
|
|
|
|
|
if (counter && span) {
|
|
|
|
if (typeof count == "undefined")
|
|
|
|
count = parseInt(counter.innerHTML);
|
|
|
|
else if (isDelta)
|
|
|
|
count += parseInt(counter.innerHTML);
|
|
|
|
counter.update(count);
|
2009-07-01 17:09:45 +02:00
|
|
|
if (count > 0) {
|
2009-07-20 23:06:33 +02:00
|
|
|
span.setStyle({ display: "inline" });
|
|
|
|
span.up("SPAN").addClassName("unseen");
|
2009-07-01 17:09:45 +02:00
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
else {
|
|
|
|
span.setStyle({ display: "none" });
|
|
|
|
span.up("SPAN").removeClassName("unseen");
|
|
|
|
}
|
|
|
|
}
|
2008-10-09 21:27:37 +02:00
|
|
|
}
|
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
function updateMessageListCounter(count, isDelta) {
|
|
|
|
var cell = $("messageCountHeader").down();
|
|
|
|
|
|
|
|
if (isDelta) {
|
|
|
|
var value = parseInt(cell.innerHTML);
|
|
|
|
count += value;
|
|
|
|
}
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
if (count > 0)
|
2010-06-02 21:11:15 +02:00
|
|
|
cell.update(count + " " + _("messages"));
|
2010-05-27 16:41:59 +02:00
|
|
|
else
|
2010-06-02 21:11:15 +02:00
|
|
|
cell.update(_("No message"));
|
2010-05-27 16:41:59 +02:00
|
|
|
}
|
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
/* Function is called when the event datatable:rendered is fired from SOGoDataTable. */
|
2010-05-27 16:41:59 +02:00
|
|
|
function onMessageListRender(event) {
|
2010-06-25 21:58:30 +02:00
|
|
|
// Restore previous selection
|
|
|
|
var currentMessage = Mailer.currentMessages[Mailer.currentMailbox];
|
|
|
|
if (currentMessage) {
|
|
|
|
var rows = this.select("TR#row_" + currentMessage);
|
|
|
|
if (rows.length == 1)
|
|
|
|
rows[0].selectElement();
|
|
|
|
}
|
|
|
|
// Update message counter in folder name
|
2010-05-27 16:41:59 +02:00
|
|
|
updateMessageListCounter(event.memo, false);
|
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onMessageContextMenu(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var menu = $('messageListMenu');
|
2010-05-27 16:41:59 +02:00
|
|
|
var topNode = $('messageListBody');
|
2009-07-20 23:06:33 +02:00
|
|
|
var selectedNodes = topNode.getSelectedRows();
|
2007-11-23 21:36:49 +01:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
menu.observe("hideMenu", onMessageContextMenuHide);
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (selectedNodes.length > 1)
|
|
|
|
popupMenu(event, "messagesListMenu", selectedNodes);
|
|
|
|
else
|
2010-08-03 20:52:49 +02:00
|
|
|
popupMenu(event, "messageListMenu", this);
|
2006-08-01 22:03:50 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onMessageContextMenuHide(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var topNode = $('messageList');
|
2006-08-02 22:04:46 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (topNode.menuSelectedEntry) {
|
|
|
|
topNode.menuSelectedEntry.deselect();
|
|
|
|
topNode.menuSelectedEntry = null;
|
|
|
|
}
|
|
|
|
if (topNode.menuSelectedRows) {
|
|
|
|
var nodes = topNode.menuSelectedRows;
|
|
|
|
for (var i = 0; i < nodes.length; i++)
|
|
|
|
nodes[i].selectElement();
|
|
|
|
topNode.menuSelectedRows = null;
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onFolderMenuClick(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var onhide, menuName;
|
|
|
|
|
|
|
|
var menutype = this.parentNode.getAttribute("datatype");
|
|
|
|
if (menutype) {
|
|
|
|
if (menutype == "inbox") {
|
|
|
|
menuName = "inboxIconMenu";
|
|
|
|
} else if (menutype == "account") {
|
|
|
|
menuName = "accountIconMenu";
|
|
|
|
} else if (menutype == "trash") {
|
|
|
|
menuName = "trashIconMenu";
|
|
|
|
} else {
|
|
|
|
menuName = "mailboxIconMenu";
|
|
|
|
}
|
2007-07-30 17:55:28 +02:00
|
|
|
} else {
|
2009-07-20 23:06:33 +02:00
|
|
|
menuName = "mailboxIconMenu";
|
2007-07-30 17:55:28 +02:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
var menu = $(menuName);
|
|
|
|
menu.observe("hideMenu", onFolderMenuHide);
|
|
|
|
popupMenu(event, menuName, this.parentNode);
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
var topNode = $("mailboxTree");
|
|
|
|
if (topNode.selectedEntry)
|
|
|
|
topNode.selectedEntry.deselect();
|
|
|
|
if (topNode.menuSelectedEntry)
|
|
|
|
topNode.menuSelectedEntry.deselect();
|
|
|
|
topNode.menuSelectedEntry = this;
|
|
|
|
this.selectElement();
|
2007-05-25 23:12:46 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
preventDefault(event);
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onFolderMenuHide(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var topNode = $("mailboxTree");
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (topNode.menuSelectedEntry) {
|
|
|
|
topNode.menuSelectedEntry.deselect();
|
|
|
|
topNode.menuSelectedEntry = null;
|
|
|
|
}
|
|
|
|
if (topNode.selectedEntry)
|
|
|
|
topNode.selectedEntry.selectElement();
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2010-07-28 23:17:57 +02:00
|
|
|
function deleteCachedMailboxByType(type) {
|
|
|
|
var nodes = $("mailboxTree").select("DIV[datatype=" + type + "]");
|
|
|
|
if (nodes.length == 1)
|
|
|
|
deleteCachedMailbox(nodes[0].readAttribute("dataname"));
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2010-07-28 23:17:57 +02:00
|
|
|
if (Mailer.currentMailboxType == type)
|
|
|
|
refreshCurrentFolder();
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteCachedMailbox(mailboxPath) {
|
|
|
|
var keys = Mailer.dataSources.keys();
|
|
|
|
for (var i = 0; i < keys.length; i++) {
|
|
|
|
if (keys[i] == mailboxPath || keys[i].startsWith(mailboxPath + "?"))
|
|
|
|
Mailer.dataSources.unset(keys[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-10 23:59:39 +01:00
|
|
|
function deleteCachedMessage(messageId) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var done = false;
|
|
|
|
var counter = 0;
|
2007-07-30 17:55:28 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
while (counter < Mailer.cachedMessages.length
|
|
|
|
&& !done)
|
|
|
|
if (Mailer.cachedMessages[counter]
|
|
|
|
&& Mailer.cachedMessages[counter]['idx'] == messageId) {
|
|
|
|
Mailer.cachedMessages.splice(counter, 1);
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
counter++;
|
2006-11-10 23:59:39 +01:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function getCachedMessage(idx) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var message = null;
|
|
|
|
var counter = 0;
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
while (counter < Mailer.cachedMessages.length
|
|
|
|
&& message == null)
|
|
|
|
if (Mailer.cachedMessages[counter]
|
|
|
|
&& Mailer.cachedMessages[counter]['idx'] == Mailer.currentMailbox + '/' + idx)
|
|
|
|
message = Mailer.cachedMessages[counter];
|
|
|
|
else
|
|
|
|
counter++;
|
|
|
|
|
|
|
|
return message;
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function storeCachedMessage(cachedMessage) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var oldest = -1;
|
|
|
|
var timeOldest = -1;
|
|
|
|
var counter = 0;
|
2007-07-30 17:55:28 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (Mailer.cachedMessages.length < Mailer.maxCachedMessages)
|
|
|
|
oldest = Mailer.cachedMessages.length;
|
|
|
|
else {
|
|
|
|
while (Mailer.cachedMessages[counter]) {
|
|
|
|
if (oldest == -1
|
|
|
|
|| Mailer.cachedMessages[counter]['time'] < timeOldest) {
|
|
|
|
oldest = counter;
|
|
|
|
timeOldest = Mailer.cachedMessages[counter]['time'];
|
|
|
|
}
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldest == -1)
|
|
|
|
oldest = 0;
|
2007-07-30 17:55:28 +02:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
Mailer.cachedMessages[oldest] = cachedMessage;
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2007-10-02 17:29:16 +02:00
|
|
|
function onMessageSelectionChange() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var rows = this.getSelectedRowsId();
|
|
|
|
|
|
|
|
if (rows.length == 1) {
|
|
|
|
var idx = rows[0].substr(4);
|
|
|
|
if (Mailer.currentMessages[Mailer.currentMailbox] != idx) {
|
|
|
|
Mailer.currentMessages[Mailer.currentMailbox] = idx;
|
|
|
|
loadMessage(idx);
|
|
|
|
}
|
2007-07-30 17:55:28 +02:00
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
else if (rows.length > 1)
|
|
|
|
$('messageContent').update();
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
function loadMessage(msguid) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (document.messageAjaxRequest) {
|
|
|
|
document.messageAjaxRequest.aborted = true;
|
|
|
|
document.messageAjaxRequest.abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
var div = $('messageContent');
|
2010-06-25 21:58:30 +02:00
|
|
|
var cachedMessage = getCachedMessage(msguid);
|
|
|
|
var row = $("row_" + msguid);
|
|
|
|
var seenStateHasChanged = row && row.hasClassName('mailer_unreadmail');
|
2009-07-20 23:06:33 +02:00
|
|
|
if (cachedMessage == null) {
|
|
|
|
var url = (ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/"
|
2010-06-25 21:58:30 +02:00
|
|
|
+ msguid + "/view?noframe=1");
|
2009-07-20 23:06:33 +02:00
|
|
|
div.update();
|
2010-06-25 21:58:30 +02:00
|
|
|
document.messageAjaxRequest = triggerAjaxRequest(url,
|
|
|
|
loadMessageCallback,
|
|
|
|
{ 'msguid': msguid, 'seenStateHasChanged': seenStateHasChanged });
|
|
|
|
// Warning: We assume the user can set the read/unread flag of the message.
|
|
|
|
markMailInWindow(window, msguid, true);
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
div.update(cachedMessage['text']);
|
|
|
|
cachedMessage['time'] = (new Date()).getTime();
|
|
|
|
document.messageAjaxRequest = null;
|
|
|
|
configureLinksInMessage();
|
|
|
|
resizeMailContent();
|
2010-06-25 21:58:30 +02:00
|
|
|
if (seenStateHasChanged) {
|
2009-07-20 23:06:33 +02:00
|
|
|
// Mark message as read on server
|
2010-06-25 21:58:30 +02:00
|
|
|
var img = row.select("IMG.mailerReadIcon").first();
|
2009-07-20 23:06:33 +02:00
|
|
|
var fcnMarkRead = mailListMarkMessage.bind(img);
|
|
|
|
fcnMarkRead();
|
|
|
|
}
|
|
|
|
}
|
2008-09-30 21:34:31 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
configureLoadImagesButton();
|
2009-09-14 19:44:39 +02:00
|
|
|
configureSignatureFlagImage();
|
2008-09-30 21:34:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function configureLoadImagesButton() {
|
2009-07-20 23:06:33 +02:00
|
|
|
// We show/hide the "Load Images" button
|
|
|
|
var loadImagesButton = $("loadImagesButton");
|
2009-09-15 01:05:45 +02:00
|
|
|
var content = $("messageContent");
|
|
|
|
var hiddenImgs = [];
|
|
|
|
var imgs = content.select("IMG");
|
|
|
|
$(imgs).each(function(img) {
|
|
|
|
var unsafeSrc = img.getAttribute("unsafe-src");
|
2010-04-20 19:45:17 +02:00
|
|
|
if (unsafeSrc) {
|
2009-09-15 01:05:45 +02:00
|
|
|
hiddenImgs.push(img);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
content.hiddenImgs = hiddenImgs;
|
2008-10-06 19:17:43 +02:00
|
|
|
|
2010-04-20 19:45:17 +02:00
|
|
|
var hiddenObjects = [];
|
|
|
|
var objects = content.select("OBJECT");
|
|
|
|
$(objects).each(function(obj) {
|
|
|
|
if (obj.getAttribute("unsafe-data")
|
|
|
|
|| obj.getAttribute("unsafe-classid")) {
|
|
|
|
hiddenObjects.push(obj);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
content.hiddenObjects = hiddenObjects;
|
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (typeof(loadImagesButton) == "undefined" ||
|
|
|
|
loadImagesButton == null ) {
|
|
|
|
return;
|
|
|
|
}
|
2010-04-20 19:45:17 +02:00
|
|
|
if ((hiddenImgs.length + hiddenObjects.length) == 0) {
|
2009-07-20 23:06:33 +02:00
|
|
|
loadImagesButton.setStyle({ display: 'none' });
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-09-14 19:44:39 +02:00
|
|
|
function configureSignatureFlagImage() {
|
|
|
|
var signedPart = $("signedMessage");
|
|
|
|
if (signedPart) {
|
|
|
|
var loadImagesButton = $("loadImagesButton");
|
|
|
|
var parentNode = loadImagesButton.parentNode;
|
|
|
|
var valid = parseInt(signedPart.getAttribute("valid"));
|
|
|
|
var flagImage;
|
2009-09-25 22:53:00 +02:00
|
|
|
|
|
|
|
if (valid)
|
|
|
|
flagImage = "signature-ok.png";
|
|
|
|
else
|
|
|
|
flagImage = "signature-not-ok.png";
|
|
|
|
|
|
|
|
var error = signedPart.getAttribute("error");
|
|
|
|
var newImg = createElement("img", "signedImage", null, null,
|
|
|
|
{ src: ResourcesURL + "/" + flagImage });
|
|
|
|
|
|
|
|
var msgDiv = $("signatureFlagMessage");
|
|
|
|
if (msgDiv && error) {
|
2009-09-25 23:16:03 +02:00
|
|
|
// First line in a h1, others each in a p
|
|
|
|
var formattedMessage = "<h1>" + error.replace(/\n/, "</h1><p>");
|
|
|
|
formattedMessage = formattedMessage.replace(/\n/g, "</p><p>") + "</p>";
|
2009-09-25 22:53:00 +02:00
|
|
|
msgDiv.innerHTML = "<div>" + formattedMessage + "</div>";
|
|
|
|
newImg.observe("mouseover", showSignatureMessage);
|
|
|
|
newImg.observe("mouseout", hideSignatureMessage);
|
2009-09-14 19:44:39 +02:00
|
|
|
}
|
|
|
|
loadImagesButton.parentNode.insertBefore(newImg, loadImagesButton.nextSibling);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-25 22:53:00 +02:00
|
|
|
function showSignatureMessage () {
|
|
|
|
var div = $("signatureFlagMessage");
|
|
|
|
if (div) {
|
|
|
|
var node = $("signedImage");
|
|
|
|
var cellPosition = node.cumulativeOffset();
|
|
|
|
var divDimensions = div.getDimensions();
|
|
|
|
var left = cellPosition[0] - divDimensions['width'];
|
|
|
|
var top = cellPosition[1];
|
2009-09-25 23:16:03 +02:00
|
|
|
div.style.top = (top + 5) + "px";
|
|
|
|
div.style.left = (left + 5) + "px";
|
2009-09-25 22:53:00 +02:00
|
|
|
div.style.display = "block";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function hideSignatureMessage () {
|
|
|
|
var div = $("signatureFlagMessage");
|
|
|
|
if (div)
|
|
|
|
div.style.display = "none";
|
|
|
|
}
|
|
|
|
|
2007-05-16 18:35:09 +02:00
|
|
|
function configureLinksInMessage() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var messageDiv = $('messageContent');
|
|
|
|
var mailContentDiv = document.getElementsByClassName('mailer_mailcontent',
|
|
|
|
messageDiv)[0];
|
|
|
|
if (!$(document.body).hasClassName("popup"))
|
|
|
|
mailContentDiv.observe("contextmenu", onMessageContentMenu);
|
|
|
|
|
|
|
|
var anchors = messageDiv.getElementsByTagName('a');
|
|
|
|
for (var i = 0; i < anchors.length; i++)
|
|
|
|
if (anchors[i].href.substring(0,7) == "mailto:") {
|
|
|
|
$(anchors[i]).observe("click", onEmailTo);
|
|
|
|
$(anchors[i]).observe("contextmenu", onEmailAddressClick);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$(anchors[i]).observe("click", onMessageAnchorClick);
|
|
|
|
|
|
|
|
var attachments = messageDiv.select ("DIV.linked_attachment_body");
|
|
|
|
for (var i = 0; i < attachments.length; i++)
|
|
|
|
$(attachments[i]).observe("contextmenu", onAttachmentClick);
|
|
|
|
|
|
|
|
var images = messageDiv.select("IMG.mailer_imagecontent");
|
|
|
|
for (var i = 0; i < images.length; i++)
|
|
|
|
$(images[i]).observe("contextmenu", onImageClick);
|
|
|
|
|
|
|
|
var editDraftButton = $("editDraftButton");
|
|
|
|
if (editDraftButton)
|
|
|
|
editDraftButton.observe("click",
|
|
|
|
onMessageEditDraft.bindAsEventListener(editDraftButton));
|
|
|
|
|
|
|
|
var loadImagesButton = $("loadImagesButton");
|
|
|
|
if (loadImagesButton)
|
2009-09-15 01:05:45 +02:00
|
|
|
$(loadImagesButton).observe("click", onMessageLoadImages);
|
2009-07-20 23:06:33 +02:00
|
|
|
|
|
|
|
configureiCalLinksInMessage();
|
2007-11-10 01:02:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function configureiCalLinksInMessage() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var buttons = { "iCalendarAccept": "accept",
|
|
|
|
"iCalendarDecline": "decline",
|
|
|
|
"iCalendarTentative": "tentative",
|
|
|
|
"iCalendarUpdateUserStatus": "updateUserStatus",
|
|
|
|
"iCalendarAddToCalendar": "addToCalendar",
|
|
|
|
"iCalendarDeleteFromCalendar": "deleteFromCalendar" };
|
|
|
|
|
|
|
|
for (var key in buttons) {
|
|
|
|
var button = $(key);
|
|
|
|
if (button) {
|
|
|
|
button.action = buttons[key];
|
2009-11-04 23:13:20 +01:00
|
|
|
button.stopObserving("click");
|
2009-07-20 23:06:33 +02:00
|
|
|
button.observe("click",
|
|
|
|
onICalendarButtonClick.bindAsEventListener(button));
|
|
|
|
}
|
2007-11-10 01:02:30 +01:00
|
|
|
}
|
2009-09-10 20:31:20 +02:00
|
|
|
|
|
|
|
var button = $("iCalendarDelegate");
|
|
|
|
if (button) {
|
2009-11-04 23:13:20 +01:00
|
|
|
button.stopObserving("click");
|
2009-09-10 20:31:20 +02:00
|
|
|
button.observe("click", onICalendarDelegate);
|
|
|
|
var delegatedTo = $("delegatedTo");
|
|
|
|
delegatedTo.addInterface(SOGoAutoCompletionInterface);
|
|
|
|
delegatedTo.uidField = "c_mail";
|
|
|
|
delegatedTo.excludeGroups = true;
|
2009-10-28 18:48:22 +01:00
|
|
|
delegatedTo.excludeLists = true;
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-09-10 20:31:20 +02:00
|
|
|
var editDelegate = $("editDelegate");
|
2009-11-04 23:13:20 +01:00
|
|
|
if (editDelegate) {
|
2009-09-10 20:31:20 +02:00
|
|
|
// The user delegates the invitation
|
2009-11-04 23:13:20 +01:00
|
|
|
editDelegate.stopObserving("click");
|
2009-09-10 20:31:20 +02:00
|
|
|
editDelegate.observe("click", function(event) {
|
|
|
|
$("delegateEditor").show();
|
|
|
|
$("delegatedTo").focus();
|
|
|
|
this.hide();
|
|
|
|
});
|
2009-11-04 23:13:20 +01:00
|
|
|
}
|
2009-09-10 20:31:20 +02:00
|
|
|
|
|
|
|
var delegatedToLink = $("delegatedToLink");
|
|
|
|
if (delegatedToLink) {
|
|
|
|
// The user already delegated the invitation and wants
|
|
|
|
// to change the delegated attendee
|
|
|
|
delegatedToLink.stopObserving("click");
|
|
|
|
delegatedToLink.observe("click", function(event) {
|
|
|
|
$("delegatedTo").show();
|
2009-10-13 21:14:21 +02:00
|
|
|
$("iCalendarDelegate").show();
|
2009-09-10 20:31:20 +02:00
|
|
|
$("delegatedTo").focus();
|
|
|
|
this.hide();
|
|
|
|
Event.stop(event);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onICalendarDelegate(event) {
|
|
|
|
var link = $("iCalendarAttachment").value;
|
|
|
|
if (link) {
|
2009-10-13 21:14:21 +02:00
|
|
|
var currentMsg;
|
|
|
|
if ($(document.body).hasClassName("popup"))
|
|
|
|
currentMsg = mailboxName + "/" + messageName;
|
|
|
|
else
|
|
|
|
currentMsg = Mailer.currentMailbox + "/"
|
|
|
|
+ Mailer.currentMessages[Mailer.currentMailbox];
|
2009-09-10 20:31:20 +02:00
|
|
|
delegateInvitation(link, ICalendarButtonCallback, currentMsg);
|
|
|
|
}
|
2009-11-04 23:13:20 +01:00
|
|
|
this.blur(); // required by IE
|
|
|
|
Event.stop(event);
|
2007-11-10 01:02:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onICalendarButtonClick(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var link = $("iCalendarAttachment").value;
|
|
|
|
if (link) {
|
|
|
|
var urlstr = link + "/" + this.action;
|
|
|
|
var currentMsg;
|
|
|
|
currentMsg = Mailer.currentMailbox + "/"
|
|
|
|
+ Mailer.currentMessages[Mailer.currentMailbox];
|
|
|
|
triggerAjaxRequest(urlstr, ICalendarButtonCallback, currentMsg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
log("no link");
|
2009-11-04 23:13:20 +01:00
|
|
|
|
|
|
|
this.blur(); // Required by IE
|
|
|
|
Event.stop(event);
|
2007-11-10 01:02:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function ICalendarButtonCallback(http) {
|
2009-10-13 21:14:21 +02:00
|
|
|
if ($(document.body).hasClassName("popup")) {
|
|
|
|
if (window.opener && window.opener.open && !window.opener.closed)
|
|
|
|
window.opener.ICalendarButtonCallback(http);
|
|
|
|
else
|
|
|
|
window.location.reload();
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
2009-10-13 21:14:21 +02:00
|
|
|
else {
|
2009-11-04 23:13:20 +01:00
|
|
|
var oldMsg = http.callbackData;
|
2009-10-13 21:14:21 +02:00
|
|
|
if (isHttpStatus204(http.status)) {
|
2009-10-15 00:39:53 +02:00
|
|
|
var msg = Mailer.currentMailbox + "/" + Mailer.currentMessages[Mailer.currentMailbox];
|
2009-10-13 21:14:21 +02:00
|
|
|
deleteCachedMessage(oldMsg);
|
|
|
|
if (oldMsg == msg) {
|
|
|
|
loadMessage(Mailer.currentMessages[Mailer.currentMailbox]);
|
|
|
|
}
|
|
|
|
for (var i = 0; i < Mailer.popups.length; i++) {
|
|
|
|
if (Mailer.popups[i].messageUID == oldMsg) {
|
2009-11-04 23:13:20 +01:00
|
|
|
// Don't reload, just close;
|
|
|
|
// Reloading the popup would disconnect the popup from the parent
|
|
|
|
//Mailer.popups[i].location.reload();
|
|
|
|
Mailer.popups[i].close();
|
|
|
|
Mailer.popups.splice(i,1);
|
2009-10-13 21:14:21 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (http.status == 403) {
|
|
|
|
var data = http.responseText;
|
|
|
|
var msg = data.replace(/^(.*\n)*.*<p>((.*\n)*.*)<\/p>(.*\n)*.*$/, "$2");
|
2009-11-04 23:13:20 +01:00
|
|
|
for (var i = 0; i < Mailer.popups.length; i++) {
|
|
|
|
if (Mailer.popups[i].messageUID == oldMsg) {
|
|
|
|
// Show the alert in the proper popup window
|
2010-06-02 21:11:15 +02:00
|
|
|
Mailer.popups[i].alert(_(msg));
|
2009-11-04 23:13:20 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == Mailer.popups.length)
|
2010-06-02 21:11:15 +02:00
|
|
|
window.alert(_(msg));
|
2009-10-13 21:14:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
window.alert("received code: " + http.status + "\nerror: " + http.responseText);
|
2009-09-10 20:31:20 +02:00
|
|
|
}
|
2007-05-16 23:42:47 +02:00
|
|
|
}
|
|
|
|
|
2007-10-25 22:36:08 +02:00
|
|
|
function resizeMailContent() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var headerTable = document.getElementsByClassName('mailer_fieldtable')[0];
|
|
|
|
var contentDiv = document.getElementsByClassName('mailer_mailcontent')[0];
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
contentDiv.setStyle({ 'top':
|
|
|
|
(Element.getHeight(headerTable) + headerTable.offsetTop) + 'px' });
|
|
|
|
|
|
|
|
// Show expand buttons if necessary
|
|
|
|
var spans = $$("TABLE TR.mailer_fieldrow TD.mailer_fieldvalue SPAN");
|
|
|
|
spans.each(function(span) {
|
|
|
|
var row = span.up("TR");
|
|
|
|
if (span.getWidth() > row.getWidth()) {
|
|
|
|
var cell = row.select("TD.mailer_fieldname").first();
|
|
|
|
var link = cell.down("img");
|
|
|
|
link.show();
|
|
|
|
link.observe("click", toggleDisplayHeader);
|
|
|
|
}
|
|
|
|
});
|
2008-03-26 19:58:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleDisplayHeader(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var row = this.up("TR");
|
|
|
|
var span = row.down("SPAN");
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (this.hasClassName("collapse")) {
|
|
|
|
this.writeAttribute("src", ResourcesURL + '/minus.png');
|
|
|
|
this.writeAttribute("class", "expand");
|
|
|
|
span.writeAttribute("class", "expand");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.writeAttribute("src", ResourcesURL + '/plus.png');
|
|
|
|
this.writeAttribute("class", "collapse");
|
|
|
|
span.writeAttribute("class", "collapse");
|
|
|
|
}
|
|
|
|
resizeMailContent();
|
|
|
|
|
|
|
|
preventDefault(event);
|
|
|
|
return false;
|
2007-10-25 22:36:08 +02:00
|
|
|
}
|
|
|
|
|
2007-05-17 19:25:45 +02:00
|
|
|
function onMessageContentMenu(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var element = getTarget(event);
|
|
|
|
if ((element.tagName == 'A' && element.href.substring(0,7) == "mailto:")
|
|
|
|
|| element.tagName == 'IMG')
|
2010-08-03 20:52:49 +02:00
|
|
|
// Don't show the default contextual menu; let the click propagate to
|
2009-07-20 23:06:33 +02:00
|
|
|
// other observers
|
|
|
|
return true;
|
|
|
|
popupMenu(event, 'messageContentMenu', this);
|
2007-05-18 19:25:58 +02:00
|
|
|
}
|
2007-05-17 19:25:45 +02:00
|
|
|
|
2007-08-15 22:34:11 +02:00
|
|
|
function onMessageEditDraft(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
return openMessageWindowsForSelection("edit", true);
|
2007-08-15 22:34:11 +02:00
|
|
|
}
|
|
|
|
|
2008-09-30 21:34:31 +02:00
|
|
|
function onMessageLoadImages(event) {
|
2009-09-15 01:05:45 +02:00
|
|
|
var content = $("messageContent");
|
|
|
|
$(content.hiddenImgs).each(function(img) {
|
|
|
|
var unSafeSrc = img.getAttribute("unsafe-src");
|
|
|
|
log ("unsafesrc: " + unSafeSrc);
|
|
|
|
img.src = img.getAttribute("unsafe-src");
|
|
|
|
});
|
2009-09-15 01:16:05 +02:00
|
|
|
content.hiddenImgs = null;
|
2010-04-20 19:45:17 +02:00
|
|
|
$(content.hiddenObjects).each(function(obj) {
|
|
|
|
var unSafeData = obj.getAttribute("unsafe-data");
|
|
|
|
if (unSafeData) {
|
|
|
|
obj.setAttribute("data", unSafeData);
|
|
|
|
}
|
|
|
|
var unSafeClassId = obj.getAttribute("unsafe-classid");
|
|
|
|
if (unSafeClassId) {
|
|
|
|
obj.setAttribute("classid", unSafeClassId);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
content.hiddenObjects = null;
|
|
|
|
|
|
|
|
|
2009-09-15 01:05:45 +02:00
|
|
|
var loadImagesButton = $("loadImagesButton");
|
|
|
|
loadImagesButton.setStyle({ display: 'none' });
|
|
|
|
|
|
|
|
Event.stop(event);
|
2008-09-30 21:34:31 +02:00
|
|
|
}
|
|
|
|
|
2007-05-16 23:42:47 +02:00
|
|
|
function onEmailAddressClick(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
popupMenu(event, 'addressMenu', this);
|
|
|
|
preventDefault(event);
|
|
|
|
return false;
|
2007-05-15 22:52:38 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 17:54:44 +02:00
|
|
|
function onMessageAnchorClick(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
window.open(this.href);
|
|
|
|
preventDefault(event);
|
2007-05-15 22:52:38 +02:00
|
|
|
}
|
|
|
|
|
2007-11-26 22:16:00 +01:00
|
|
|
function onImageClick(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
popupMenu(event, 'imageMenu', this);
|
|
|
|
preventDefault(event);
|
|
|
|
return false;
|
2007-11-26 22:16:00 +01:00
|
|
|
}
|
|
|
|
|
2009-07-09 17:27:11 +02:00
|
|
|
function onAttachmentClick (event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
popupMenu (event, 'attachmentMenu', this);
|
|
|
|
preventDefault (event);
|
|
|
|
return false;
|
2009-07-09 17:27:11 +02:00
|
|
|
}
|
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
function loadMessageCallback(http) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var div = $('messageContent');
|
2007-05-18 19:25:58 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (http.status == 200) {
|
|
|
|
document.messageAjaxRequest = null;
|
|
|
|
div.update(http.responseText);
|
|
|
|
configureLinksInMessage();
|
|
|
|
resizeMailContent();
|
|
|
|
configureLoadImagesButton();
|
2009-09-14 19:44:39 +02:00
|
|
|
configureSignatureFlagImage();
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (http.callbackData) {
|
|
|
|
var cachedMessage = new Array();
|
2010-06-25 21:58:30 +02:00
|
|
|
var msguid = http.callbackData.msguid;
|
|
|
|
// Warning: If the user can't set the read/unread flag, it won't
|
|
|
|
// be reflected in the view unless we force the refresh.
|
|
|
|
Mailer.dataTable.invalidate(msguid, true);
|
|
|
|
cachedMessage['idx'] = Mailer.currentMailbox + '/' + msguid;
|
2009-07-20 23:06:33 +02:00
|
|
|
cachedMessage['time'] = (new Date()).getTime();
|
|
|
|
cachedMessage['text'] = http.responseText;
|
|
|
|
if (cachedMessage['text'].length < 30000)
|
|
|
|
storeCachedMessage(cachedMessage);
|
|
|
|
}
|
2007-07-30 17:55:28 +02:00
|
|
|
}
|
2009-08-19 22:32:58 +02:00
|
|
|
else if (http.status == 404) {
|
2010-06-02 21:11:15 +02:00
|
|
|
alert (_("The message you have selected doesn't exist anymore."));
|
2010-06-25 21:58:30 +02:00
|
|
|
Mailer.dataTable.remove(http.callbackData.msguid);
|
2009-08-19 22:32:58 +02:00
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
else
|
|
|
|
log("messageCallback: problem during ajax request: " + http.status);
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function processMailboxMenuAction(mailbox) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var currentNode, upperNode;
|
|
|
|
var mailboxName;
|
|
|
|
var action;
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
mailboxName = mailbox.getAttribute('mailboxname');
|
|
|
|
currentNode = mailbox;
|
|
|
|
upperNode = null;
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
while (currentNode
|
|
|
|
&& !currentNode.hasAttribute('mailboxaction'))
|
|
|
|
currentNode = currentNode.parentNode.parentNode.parentMenuItem;
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (currentNode)
|
|
|
|
{
|
|
|
|
action = currentNode.getAttribute('mailboxaction');
|
|
|
|
// var rows = collectSelectedRows();
|
|
|
|
// var rString = rows.join(', ');
|
|
|
|
// alert("performing '" + action + "' on " + rString
|
|
|
|
// + " to " + mailboxName);
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var rowSelectionCount = 0;
|
|
|
|
|
|
|
|
validateControls();
|
|
|
|
|
|
|
|
function showElement(e, shouldShow) {
|
2009-07-20 23:06:33 +02:00
|
|
|
e.style.display = shouldShow ? "" : "none";
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function enableElement(e, shouldEnable) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if(!e)
|
|
|
|
return;
|
|
|
|
if(shouldEnable) {
|
|
|
|
if(e.hasAttribute("disabled"))
|
|
|
|
e.removeAttribute("disabled");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
e.setAttribute("disabled", "1");
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function validateControls() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var e = $("moveto");
|
|
|
|
this.enableElement(e, rowSelectionCount > 0);
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function moveTo(uri) {
|
2009-07-20 23:06:33 +02:00
|
|
|
alert("MoveTo: " + uri);
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* message menu entries */
|
2007-03-19 15:31:49 +01:00
|
|
|
function onMenuOpenMessage(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
return openMessageWindowsForSelection('popupview');
|
2007-05-04 05:12:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuReplyToSender(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
return openMessageWindowsForSelection('reply');
|
2007-05-04 05:12:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuReplyToAll(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
return openMessageWindowsForSelection('replyall');
|
2007-05-04 05:12:24 +02:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2007-05-04 05:12:24 +02:00
|
|
|
function onMenuForwardMessage(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
return openMessageWindowsForSelection('forward');
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2007-07-04 17:40:22 +02:00
|
|
|
function onMenuViewMessageSource(event) {
|
2010-05-27 16:41:59 +02:00
|
|
|
var messageList = $("messageListBody");
|
2009-07-20 23:06:33 +02:00
|
|
|
var rows = messageList.getSelectedRowsId();
|
2007-07-30 17:55:28 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (rows.length > 0) {
|
|
|
|
var url = (ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/"
|
|
|
|
+ rows[0].substr(4) + "/viewsource");
|
|
|
|
openMailComposeWindow(url);
|
|
|
|
}
|
2007-07-04 17:40:22 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
preventDefault(event);
|
2007-07-04 17:40:22 +02:00
|
|
|
}
|
|
|
|
|
2007-12-10 23:34:12 +01:00
|
|
|
function saveImage(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var img = document.menuTarget;
|
|
|
|
var url = img.getAttribute("src");
|
|
|
|
var urlAsAttachment = url.replace(/(\/[^\/]*)$/,"/asAttachment$1");
|
2007-12-10 23:34:12 +01:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
window.location.href = urlAsAttachment;
|
2007-11-26 22:16:00 +01:00
|
|
|
}
|
|
|
|
|
2009-07-09 17:27:11 +02:00
|
|
|
function saveAttachment(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var div = document.menuTarget;
|
|
|
|
var link = div.select ("a").first ();
|
|
|
|
var url = link.getAttribute("href");
|
|
|
|
var urlAsAttachment = url.replace(/(\/[^\/]*)$/,"/asAttachment$1");
|
2009-07-09 17:27:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
window.location.href = urlAsAttachment;
|
2009-07-09 17:27:11 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
/* contacts */
|
2007-05-18 19:25:58 +02:00
|
|
|
function newContactFromEmail(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var mailto = document.menuTarget.innerHTML;
|
|
|
|
|
|
|
|
var email = extractEmailAddress(mailto);
|
|
|
|
var c_name = extractEmailName(mailto);
|
|
|
|
if (email.length > 0) {
|
|
|
|
var url = (UserFolderURL + "Contacts/personal/newcontact?contactEmail="
|
|
|
|
+ encodeURI(email));
|
|
|
|
if (c_name)
|
|
|
|
url += "&contactFN=" + c_name;
|
|
|
|
openContactWindow(url);
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return false; /* stop following the link */
|
2007-07-11 07:05:03 +02:00
|
|
|
}
|
2007-11-20 15:53:19 +01:00
|
|
|
|
|
|
|
function onEmailTo(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
openMailTo(this.innerHTML.strip());
|
|
|
|
Event.stop(event);
|
|
|
|
return false;
|
2007-11-20 15:53:19 +01:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
function newEmailTo(sender) {
|
2009-07-20 23:06:33 +02:00
|
|
|
return openMailTo(document.menuTarget.innerHTML);
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function expandUpperTree(node) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var currentNode = node.parentNode;
|
|
|
|
|
|
|
|
while (currentNode.className != "dtree") {
|
|
|
|
if (currentNode.className == 'clip') {
|
|
|
|
var id = currentNode.getAttribute("id");
|
|
|
|
var number = parseInt(id.substr(2));
|
|
|
|
if (number > 0) {
|
|
|
|
var cn = mailboxTree.aNodes[number];
|
|
|
|
mailboxTree.nodeStatus(1, number, cn._ls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentNode = currentNode.parentNode;
|
2007-07-30 17:55:28 +02:00
|
|
|
}
|
2006-07-31 22:24:50 +02:00
|
|
|
}
|
|
|
|
|
2007-03-19 15:31:49 +01:00
|
|
|
function onHeaderClick(event) {
|
2010-05-27 16:41:59 +02:00
|
|
|
if (SOGoResizableTable._onHandle)
|
2009-07-20 23:06:33 +02:00
|
|
|
return;
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
var headerId = this.getAttribute("id");
|
|
|
|
var newSortAttribute;
|
|
|
|
if (headerId == "subjectHeader")
|
|
|
|
newSortAttribute = "subject";
|
|
|
|
else if (headerId == "fromHeader")
|
|
|
|
newSortAttribute = "from";
|
|
|
|
else if (headerId == "toHeader")
|
|
|
|
newSortAttribute = "to";
|
|
|
|
else if (headerId == "dateHeader")
|
|
|
|
newSortAttribute = "date";
|
|
|
|
else if (headerId == "sizeHeader")
|
|
|
|
newSortAttribute = "size";
|
|
|
|
else
|
|
|
|
newSortAttribute = "arrival";
|
|
|
|
|
|
|
|
if (sorting["attribute"] == newSortAttribute)
|
|
|
|
sorting["ascending"] = !sorting["ascending"];
|
|
|
|
else {
|
|
|
|
sorting["attribute"] = newSortAttribute;
|
|
|
|
sorting["ascending"] = true;
|
|
|
|
}
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
refreshCurrentFolder();
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
Event.stop(event);
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
2006-08-31 01:13:28 +02:00
|
|
|
|
2007-06-28 22:35:09 +02:00
|
|
|
function refreshCurrentFolder() {
|
2009-07-20 23:06:33 +02:00
|
|
|
openMailbox(Mailer.currentMailbox, true);
|
2006-08-31 01:13:28 +02:00
|
|
|
}
|
2006-10-23 16:56:32 +02:00
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
/* Called after sending an email */
|
|
|
|
function refreshMessage(mailbox, messageUID) {
|
|
|
|
if (mailbox == Mailer.currentMailbox) {
|
|
|
|
Mailer.dataTable.invalidate(messageUID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
function configureMessageListEvents(headerTable, dataTable) {
|
|
|
|
if (headerTable)
|
2009-07-20 23:06:33 +02:00
|
|
|
// Sortable columns
|
2010-05-27 16:41:59 +02:00
|
|
|
configureSortableTableHeaders(headerTable);
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
if (dataTable) {
|
|
|
|
dataTable.multiselect = true;
|
|
|
|
// Each body row can load a message
|
|
|
|
dataTable.observe("mousedown",
|
|
|
|
onMessageSelectionChange.bindAsEventListener(dataTable));
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
2006-11-09 23:55:04 +01:00
|
|
|
}
|
|
|
|
|
2006-12-22 17:48:11 +01:00
|
|
|
function configureDragHandles() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var handle = $("verticalDragHandle");
|
|
|
|
if (handle) {
|
|
|
|
handle.addInterface(SOGoDragHandlesInterface);
|
|
|
|
handle.leftMargin = 50;
|
|
|
|
handle.leftBlock=$("leftPanel");
|
|
|
|
handle.rightBlock=$("rightPanel");
|
|
|
|
}
|
|
|
|
|
|
|
|
handle = $("rightDragHandle");
|
|
|
|
if (handle) {
|
|
|
|
handle.addInterface(SOGoDragHandlesInterface);
|
|
|
|
handle.upperBlock=$("mailboxContent");
|
|
|
|
handle.lowerBlock=$("messageContent");
|
2010-05-27 16:41:59 +02:00
|
|
|
handle.upperBlock.observe("handle:resize", onMessageListResize);
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
2006-12-22 17:48:11 +01:00
|
|
|
}
|
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
function onMessageListResize(event) {
|
|
|
|
var h = $("mailboxContent").getHeight() - $("messageListHeader").getHeight();
|
|
|
|
$("mailboxList").setStyle({'height': h + 'px'});
|
|
|
|
}
|
|
|
|
|
2008-09-18 20:03:59 +02:00
|
|
|
function onWindowResize(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var handle = $("verticalDragHandle");
|
|
|
|
if (handle)
|
|
|
|
handle.adjust();
|
|
|
|
handle = $("rightDragHandle");
|
|
|
|
if (handle)
|
|
|
|
handle.adjust();
|
2008-09-18 20:03:59 +02:00
|
|
|
}
|
|
|
|
|
2006-11-09 00:49:09 +01:00
|
|
|
/* dnd */
|
|
|
|
function initDnd() {
|
2009-07-20 23:06:33 +02:00
|
|
|
// log("MailerUI initDnd");
|
|
|
|
|
|
|
|
var tree = $("mailboxTree");
|
|
|
|
if (tree) {
|
|
|
|
var images = tree.getElementsByTagName("img");
|
|
|
|
for (var i = 0; i < images.length; i++) {
|
|
|
|
if (images[i].id[0] == 'j') {
|
|
|
|
images[i].dndAcceptType = mailboxSpanAcceptType;
|
|
|
|
images[i].dndEnter = plusSignEnter;
|
|
|
|
images[i].dndExit = plusSignExit;
|
|
|
|
document.DNDManager.registerDestination(images[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var nodes = document.getElementsByClassName("nodeName", tree);
|
|
|
|
for (var i = 0; i < nodes.length; i++) {
|
|
|
|
nodes[i].dndAcceptType = mailboxSpanAcceptType;
|
|
|
|
nodes[i].dndEnter = mailboxSpanEnter;
|
|
|
|
nodes[i].dndExit = mailboxSpanExit;
|
|
|
|
nodes[i].dndDrop = mailboxSpanDrop;
|
|
|
|
document.DNDManager.registerDestination(nodes[i]);
|
|
|
|
}
|
|
|
|
}
|
2006-11-09 00:49:09 +01:00
|
|
|
}
|
|
|
|
|
2006-10-23 16:56:32 +02:00
|
|
|
/* stub */
|
|
|
|
|
|
|
|
function refreshContacts() {
|
|
|
|
}
|
|
|
|
|
2006-12-22 23:13:53 +01:00
|
|
|
function openInbox(node) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var done = false;
|
|
|
|
openMailbox(node.parentNode.getAttribute("dataname"), null, null, false);
|
|
|
|
var tree = $("mailboxTree");
|
|
|
|
tree.selectedEntry = node;
|
|
|
|
node.selectElement();
|
|
|
|
mailboxTree.o(1);
|
2006-12-22 23:13:53 +01:00
|
|
|
}
|
|
|
|
|
2007-11-16 21:48:52 +01:00
|
|
|
function initMailer(event) {
|
2010-05-28 21:18:52 +02:00
|
|
|
// Restore sorting from user settings
|
|
|
|
if (UserSettings["Mail"] && UserSettings["Mail"]["SortingState"]) {
|
|
|
|
sorting["attribute"] = UserSettings["Mail"]["SortingState"][0];
|
|
|
|
sorting["ascending"] = parseInt(UserSettings["Mail"]["SortingState"][1]) > 0;
|
|
|
|
if (sorting["attribute"] == 'to') sorting["attribute"] = 'from'; // initial mailbox is always the inbox
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sorting["attribute"] = "date";
|
|
|
|
sorting["ascending"] = false;
|
|
|
|
}
|
2010-05-27 16:41:59 +02:00
|
|
|
|
|
|
|
// Define columns order
|
|
|
|
if (typeof UserDefaults["SOGoMailListViewColumnsOrder"] == "undefined") {
|
|
|
|
var defaultColumnsOrder;
|
|
|
|
if (typeof textDefaultColumnsOrder != 'undefined') {
|
|
|
|
if (textDefaultColumnsOrder.length > 0)
|
|
|
|
defaultColumnsOrder = textDefaultColumnsOrder.evalJSON(true);
|
|
|
|
else
|
|
|
|
defaultColumnsOrder = new Array();
|
|
|
|
}
|
|
|
|
UserDefaults["SOGoMailListViewColumnsOrder"] = defaultColumnsOrder;
|
|
|
|
}
|
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (!$(document.body).hasClassName("popup")) {
|
|
|
|
//initDnd();
|
2010-06-25 21:58:30 +02:00
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
Mailer.dataTable = $("mailboxList");
|
|
|
|
Mailer.dataTable.addInterface(SOGoDataTableInterface);
|
|
|
|
Mailer.dataTable.setRowRenderCallback(messageListCallback);
|
|
|
|
Mailer.dataTable.observe("datatable:rendered", onMessageListRender);
|
|
|
|
|
|
|
|
var messageListHeader = $("messageListHeader");
|
|
|
|
messageListHeader.addInterface(SOGoResizableTableInterface);
|
2010-05-28 21:18:52 +02:00
|
|
|
if (UserSettings["Mail"] && UserSettings["Mail"]["ColumnsState"]) {
|
|
|
|
messageListHeader.restore($H(UserSettings["Mail"]["ColumnsState"]));
|
|
|
|
}
|
|
|
|
|
2010-05-27 16:41:59 +02:00
|
|
|
configureMessageListEvents($("messageListHeader"), $("messageListBody"));
|
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
initMailboxTree();
|
|
|
|
initMessageCheckTimer();
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (Prototype.Browser.Gecko)
|
|
|
|
Event.observe(document, "keypress", onDocumentKeydown); // for FF2
|
|
|
|
else
|
|
|
|
Event.observe(document, "keydown", onDocumentKeydown);
|
|
|
|
|
|
|
|
/* Perform an expunge when leaving the webmail */
|
|
|
|
if (isSafari()) {
|
|
|
|
$('calendarBannerLink').observe("click", onUnload);
|
|
|
|
$('contactsBannerLink').observe("click", onUnload);
|
|
|
|
$('logoff').observe("click", onUnload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Event.observe(window, "beforeunload", onUnload);
|
2010-06-16 22:18:43 +02:00
|
|
|
|
|
|
|
onMessageListResize();
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
onWindowResize.defer();
|
|
|
|
Event.observe(window, "resize", onWindowResize);
|
2007-10-26 17:35:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function initMessageCheckTimer() {
|
2009-11-29 05:19:32 +01:00
|
|
|
var messageCheck = UserDefaults["SOGoMailMessageCheck"];
|
2009-07-20 23:06:33 +02:00
|
|
|
if (messageCheck && messageCheck != "manually") {
|
|
|
|
var interval;
|
|
|
|
if (messageCheck == "once_per_hour")
|
|
|
|
interval = 3600;
|
|
|
|
else if (messageCheck == "every_minute")
|
|
|
|
interval = 60;
|
|
|
|
else {
|
|
|
|
interval = parseInt(messageCheck.substr(6)) * 60;
|
|
|
|
}
|
|
|
|
messageCheckTimer = window.setInterval(onMessageCheckCallback,
|
|
|
|
interval * 1000);
|
2007-10-26 17:35:51 +02:00
|
|
|
}
|
2007-05-25 23:12:46 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 17:35:51 +02:00
|
|
|
function onMessageCheckCallback(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
refreshMailbox();
|
2007-10-26 17:35:51 +02:00
|
|
|
}
|
|
|
|
|
2007-05-25 23:12:46 +02:00
|
|
|
function initMailboxTree() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var node = $("mailboxTree");
|
|
|
|
if (node)
|
|
|
|
node.parentNode.removeChild(node);
|
|
|
|
mailboxTree = new dTree("mailboxTree");
|
|
|
|
mailboxTree.config.hideRoot = true;
|
|
|
|
mailboxTree.icon.root = ResourcesURL + "/tbtv_account_17x17.gif";
|
|
|
|
mailboxTree.icon.folder = ResourcesURL + "/tbtv_leaf_corner_17x17.png";
|
|
|
|
mailboxTree.icon.folderOpen = ResourcesURL + "/tbtv_leaf_corner_17x17.png";
|
|
|
|
mailboxTree.icon.node = ResourcesURL + "/tbtv_leaf_corner_17x17.png";
|
|
|
|
mailboxTree.icon.line = ResourcesURL + "/tbtv_line_17x17.gif";
|
|
|
|
mailboxTree.icon.join = ResourcesURL + "/tbtv_junction_17x17.gif";
|
|
|
|
mailboxTree.icon.joinBottom = ResourcesURL + "/tbtv_corner_17x17.gif";
|
|
|
|
mailboxTree.icon.plus = ResourcesURL + "/tbtv_plus_17x17.gif";
|
|
|
|
mailboxTree.icon.plusBottom = ResourcesURL + "/tbtv_corner_plus_17x17.gif";
|
|
|
|
mailboxTree.icon.minus = ResourcesURL + "/tbtv_minus_17x17.gif";
|
|
|
|
mailboxTree.icon.minusBottom = ResourcesURL + "/tbtv_corner_minus_17x17.gif";
|
|
|
|
mailboxTree.icon.nlPlus = ResourcesURL + "/tbtv_corner_plus_17x17.gif";
|
|
|
|
mailboxTree.icon.nlMinus = ResourcesURL + "/tbtv_corner_minus_17x17.gif";
|
|
|
|
mailboxTree.icon.empty = ResourcesURL + "/empty.gif";
|
2009-08-31 21:52:47 +02:00
|
|
|
mailboxTree.preload ();
|
2009-07-20 23:06:33 +02:00
|
|
|
|
|
|
|
mailboxTree.add(0, -1, '');
|
|
|
|
|
|
|
|
mailboxTree.pendingRequests = mailAccounts.length;
|
|
|
|
activeAjaxRequests += mailAccounts.length;
|
|
|
|
for (var i = 0; i < mailAccounts.length; i++) {
|
2010-08-03 20:52:49 +02:00
|
|
|
var url = ApplicationBaseURL + i + "/mailboxes";
|
|
|
|
triggerAjaxRequest(url, onLoadMailboxesCallback, i);
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
2007-05-25 23:12:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateMailboxTreeInPage() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var treeContent = $("folderTreeContent");
|
2009-08-31 21:52:47 +02:00
|
|
|
//treeContent.update(mailboxTree.toString ());
|
|
|
|
treeContent.appendChild(mailboxTree.domObject ());
|
2009-07-20 23:06:33 +02:00
|
|
|
|
|
|
|
var inboxFound = false;
|
|
|
|
var tree = $("mailboxTree");
|
|
|
|
var nodes = document.getElementsByClassName("node", tree);
|
|
|
|
for (i = 0; i < nodes.length; i++) {
|
|
|
|
nodes[i].observe("click",
|
|
|
|
onMailboxTreeItemClick.bindAsEventListener(nodes[i]));
|
|
|
|
nodes[i].observe("contextmenu",
|
|
|
|
onFolderMenuClick.bindAsEventListener(nodes[i]));
|
|
|
|
if (!inboxFound
|
|
|
|
&& nodes[i].parentNode.getAttribute("datatype") == "inbox") {
|
|
|
|
Mailer.currentMailboxType = "inbox";
|
|
|
|
openInbox(nodes[i]);
|
|
|
|
inboxFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Mailer.quotas && parseInt(Mailer.quotas.maxQuota) > 0) {
|
2009-09-21 18:17:02 +02:00
|
|
|
var quotaDiv = $("quotaIndicator");
|
|
|
|
if (quotaDiv) {
|
|
|
|
treeContent.removeChild(quotaDiv);
|
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
// Build quota indicator, show values in MB
|
|
|
|
var percents = (Math.round(Mailer.quotas.usedSpace * 10000
|
|
|
|
/ Mailer.quotas.maxQuota)
|
|
|
|
/ 100);
|
|
|
|
var level = (percents > 85)? "alert" : (percents > 70)? "warn" : "ok";
|
2010-06-02 21:11:15 +02:00
|
|
|
var format = _("quotasFormat");
|
2009-07-20 23:06:33 +02:00
|
|
|
var text = format.formatted(percents,
|
|
|
|
Math.round(Mailer.quotas.maxQuota/10.24)/100);
|
2009-09-21 18:17:02 +02:00
|
|
|
quotaDiv = new Element('div', { 'id': 'quotaIndicator',
|
|
|
|
'class': 'quota',
|
|
|
|
'info': text });
|
2009-07-20 23:06:33 +02:00
|
|
|
var levelDiv = new Element('div', { 'class': 'level' });
|
|
|
|
var valueDiv = new Element('div', { 'class': 'value ' + level, 'style': 'width: ' + ((percents > 100)?100:percents) + '%' });
|
|
|
|
var marksDiv = new Element('div', { 'class': 'marks' });
|
|
|
|
var textP = new Element('p').update(text);
|
|
|
|
marksDiv.insert(new Element('div'));
|
|
|
|
marksDiv.insert(new Element('div'));
|
|
|
|
marksDiv.insert(new Element('div'));
|
|
|
|
levelDiv.insert(valueDiv);
|
|
|
|
levelDiv.insert(marksDiv);
|
|
|
|
levelDiv.insert(textP);
|
|
|
|
quotaDiv.insert(levelDiv);
|
|
|
|
treeContent.insertBefore(quotaDiv, tree);
|
|
|
|
}
|
2008-09-17 21:44:11 +02:00
|
|
|
}
|
|
|
|
|
2010-01-05 23:34:35 +01:00
|
|
|
function mailboxMenuNode(type, displayName) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var newNode = document.createElement("li");
|
|
|
|
var icon = MailerUIdTreeExtension.folderIcons[type];
|
|
|
|
if (!icon)
|
|
|
|
icon = "tbtv_leaf_corner_17x17.png";
|
|
|
|
var image = document.createElement("img");
|
|
|
|
image.src = ResourcesURL + "/" + icon;
|
|
|
|
newNode.appendChild(image);
|
2010-01-05 23:34:35 +01:00
|
|
|
var dnOverride = MailerUIdTreeExtension.folderNames[type];
|
|
|
|
if (dnOverride)
|
|
|
|
displayName = dnOverride;
|
2009-07-20 23:06:33 +02:00
|
|
|
newNode.appendChild(document.createTextNode(" " + displayName));
|
2007-05-25 23:12:46 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return newNode;
|
2007-05-25 23:12:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function generateMenuForMailbox(mailbox, prefix, callback) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var menuDIV = document.createElement("div");
|
|
|
|
$(menuDIV).addClassName("menu");
|
|
|
|
var menuID = prefix + "Submenu";
|
|
|
|
var previousMenuDIV = $(menuID);
|
|
|
|
if (previousMenuDIV)
|
|
|
|
previousMenuDIV.parentNode.removeChild(previousMenuDIV);
|
|
|
|
menuDIV.setAttribute("id", menuID);
|
|
|
|
var menu = document.createElement("ul");
|
|
|
|
menu.style.cssFloat="left";
|
|
|
|
menu.style.styleFloat="left";
|
|
|
|
menuDIV.appendChild(menu);
|
|
|
|
pageContent.appendChild(menuDIV);
|
|
|
|
|
|
|
|
var windowHeight = 0;
|
|
|
|
if ( typeof(window.innerHeight) != "undefined" && window.innerHeight != 0 ) {
|
|
|
|
windowHeight = window.innerHeight;
|
2007-07-30 17:55:28 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-07-20 23:06:33 +02:00
|
|
|
windowHeight = document.body.clientHeight;
|
|
|
|
}
|
|
|
|
var offset = 70;
|
|
|
|
if ( navigator.appVersion.indexOf("Safari") >= 0 ) {
|
|
|
|
offset = 140;
|
2007-07-30 17:55:28 +02:00
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
|
|
|
|
var callbacks = new Array();
|
|
|
|
if (mailbox.type != "account") {
|
|
|
|
var newNode = document.createElement("li");
|
|
|
|
newNode.mailbox = mailbox;
|
2010-06-02 21:11:15 +02:00
|
|
|
newNode.appendChild(document.createTextNode(_("This Folder")));
|
2009-07-20 23:06:33 +02:00
|
|
|
menu.appendChild(newNode);
|
|
|
|
menu.appendChild(document.createElement("li"));
|
|
|
|
callbacks.push(callback);
|
|
|
|
callbacks.push("-");
|
|
|
|
}
|
|
|
|
|
|
|
|
var submenuCount = 0;
|
|
|
|
var newNode;
|
|
|
|
for (var i = 0; i < mailbox.children.length; i++) {
|
2010-01-05 23:34:35 +01:00
|
|
|
if (menu.offsetHeight > windowHeight-offset) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var menuWidth = parseInt(menu.offsetWidth) + 15
|
|
|
|
menuWidth = menuWidth + "px";
|
|
|
|
menu.style.width = menuWidth;
|
|
|
|
menu = document.createElement("ul");
|
|
|
|
menu.style.cssFloat="left";
|
|
|
|
menu.style.styleFloat="left";
|
|
|
|
menuDIV.appendChild(menu);
|
|
|
|
}
|
|
|
|
var child = mailbox.children[i];
|
2010-01-05 23:34:35 +01:00
|
|
|
newNode = mailboxMenuNode(child.type, child.displayName);
|
2009-07-20 23:06:33 +02:00
|
|
|
newNode.style.width = "auto";
|
|
|
|
menu.appendChild(newNode);
|
|
|
|
if (child.children.length > 0) {
|
|
|
|
var newPrefix = prefix + submenuCount;
|
|
|
|
var newSubmenuId = generateMenuForMailbox(child, newPrefix, callback);
|
|
|
|
callbacks.push(newSubmenuId);
|
|
|
|
submenuCount++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newNode.mailbox = child;
|
|
|
|
callbacks.push(callback);
|
|
|
|
}
|
|
|
|
}
|
2010-08-03 20:52:49 +02:00
|
|
|
menu.style.width = (parseInt(menu.offsetWidth) + 15) + "px";
|
2010-01-05 23:34:35 +01:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
initMenu(menuDIV, callbacks);
|
2007-05-25 23:12:46 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return menuDIV.getAttribute("id");
|
2007-05-25 23:12:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateMailboxMenus() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var mailboxActions = { move: onMailboxMenuMove,
|
|
|
|
copy: onMailboxMenuCopy };
|
|
|
|
|
|
|
|
for (key in mailboxActions) {
|
|
|
|
var menuId = key + "MailboxMenu";
|
|
|
|
var menuDIV = $(menuId);
|
|
|
|
if (menuDIV)
|
|
|
|
menuDIV.parentNode.removeChild(menuDIV);
|
|
|
|
|
|
|
|
menuDIV = document.createElement("div");
|
|
|
|
pageContent = $("pageContent");
|
|
|
|
pageContent.appendChild(menuDIV);
|
|
|
|
|
|
|
|
var menu = document.createElement("ul");
|
|
|
|
menuDIV.appendChild(menu);
|
|
|
|
|
|
|
|
$(menuDIV).addClassName("menu");
|
|
|
|
menuDIV.setAttribute("id", menuId);
|
|
|
|
|
|
|
|
var submenuIds = new Array();
|
|
|
|
for (var i = 0; i < mailAccounts.length; i++) {
|
2010-08-03 20:52:49 +02:00
|
|
|
var menuEntry = mailboxMenuNode("account", mailAccounts[i]);
|
2009-07-20 23:06:33 +02:00
|
|
|
menu.appendChild(menuEntry);
|
2010-08-03 20:52:49 +02:00
|
|
|
var mailbox = accounts[i];
|
2009-07-20 23:06:33 +02:00
|
|
|
var newSubmenuId = generateMenuForMailbox(mailbox,
|
|
|
|
key, mailboxActions[key]);
|
|
|
|
submenuIds.push(newSubmenuId);
|
|
|
|
}
|
|
|
|
initMenu(menuDIV, submenuIds);
|
2007-07-30 17:55:28 +02:00
|
|
|
}
|
2007-05-25 23:12:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onLoadMailboxesCallback(http) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (http.status == 200) {
|
|
|
|
checkAjaxRequestsState();
|
|
|
|
if (http.responseText.length > 0) {
|
2010-08-03 20:52:49 +02:00
|
|
|
var accountIdx = parseInt(http.callbackData);
|
|
|
|
var newAccount = buildMailboxes(accountIdx, http.responseText);
|
|
|
|
accounts[accountIdx] = newAccount;
|
2009-07-20 23:06:33 +02:00
|
|
|
mailboxTree.addMailAccount(newAccount);
|
|
|
|
mailboxTree.pendingRequests--;
|
|
|
|
activeAjaxRequests--;
|
|
|
|
if (!mailboxTree.pendingRequests) {
|
|
|
|
updateMailboxTreeInPage();
|
|
|
|
updateMailboxMenus();
|
|
|
|
checkAjaxRequestsState();
|
|
|
|
getFoldersState();
|
|
|
|
updateStatusFolders();
|
|
|
|
configureDroppables();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
log ("onLoadMailboxesCallback " + http.status);
|
|
|
|
}
|
|
|
|
|
|
|
|
// var tree = $("mailboxTree");
|
|
|
|
// var treeNodes = document.getElementsByClassName("dTreeNode", tree);
|
|
|
|
// var i = 0;
|
|
|
|
// while (i < treeNodes.length
|
|
|
|
// && treeNodes[i].getAttribute("dataname") != Mailer.currentMailbox)
|
|
|
|
// i++;
|
|
|
|
// if (i < treeNodes.length) {
|
|
|
|
// // log("found mailbox");
|
|
|
|
// var links = document.getElementsByClassName("node", treeNodes[i]);
|
|
|
|
// if (tree.selectedEntry)
|
|
|
|
// tree.selectedEntry.deselect();
|
|
|
|
// links[0].selectElement();
|
|
|
|
// tree.selectedEntry = links[0];
|
|
|
|
// expandUpperTree(links[0]);
|
|
|
|
// }
|
2007-05-25 23:12:46 +02:00
|
|
|
}
|
|
|
|
|
2010-08-03 20:52:49 +02:00
|
|
|
function buildMailboxes(accountIdx, encoded) {
|
|
|
|
var account = new Mailbox("account", "" + accountIdx,
|
2009-09-30 17:21:10 +02:00
|
|
|
undefined, //necessary, null will cause issues
|
2010-08-03 20:52:49 +02:00
|
|
|
mailAccounts[accountIdx]);
|
2009-07-20 23:06:33 +02:00
|
|
|
var data = encoded.evalJSON(true);
|
|
|
|
var mailboxes = data.mailboxes;
|
|
|
|
var unseen = (data.status? data.status.unseen : 0);
|
|
|
|
|
|
|
|
if (data.quotas)
|
|
|
|
Mailer.quotas = data.quotas;
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
for (var i = 0; i < mailboxes.length; i++) {
|
|
|
|
var currentNode = account;
|
|
|
|
var names = mailboxes[i].path.split("/");
|
|
|
|
for (var j = 1; j < (names.length - 1); j++) {
|
2010-01-05 23:34:35 +01:00
|
|
|
var name = names[j];
|
|
|
|
var node = currentNode.findMailboxByName(name);
|
2009-07-20 23:06:33 +02:00
|
|
|
if (!node) {
|
2010-01-05 23:34:35 +01:00
|
|
|
node = new Mailbox("additional", name);
|
2009-07-20 23:06:33 +02:00
|
|
|
currentNode.addMailbox(node);
|
|
|
|
}
|
|
|
|
currentNode = node;
|
|
|
|
}
|
|
|
|
var basename = names[names.length-1];
|
|
|
|
var leaf = currentNode.findMailboxByName(basename);
|
|
|
|
if (leaf)
|
|
|
|
leaf.type = mailboxes[i].type;
|
|
|
|
else {
|
|
|
|
if (mailboxes[i].type == 'inbox')
|
|
|
|
leaf = new Mailbox(mailboxes[i].type, basename, unseen);
|
|
|
|
else
|
|
|
|
leaf = new Mailbox(mailboxes[i].type, basename);
|
|
|
|
currentNode.addMailbox(leaf);
|
|
|
|
}
|
2007-07-30 17:55:28 +02:00
|
|
|
}
|
2007-05-25 23:12:46 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return account;
|
2006-11-09 00:49:09 +01:00
|
|
|
}
|
|
|
|
|
2007-12-13 22:07:09 +01:00
|
|
|
function getFoldersState() {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (mailAccounts.length > 0) {
|
|
|
|
var urlstr = ApplicationBaseURL + "foldersState";
|
|
|
|
triggerAjaxRequest(urlstr, getFoldersStateCallback);
|
|
|
|
}
|
2007-12-13 22:07:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function getFoldersStateCallback(http) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (http.status == 200) {
|
|
|
|
if (http.responseText.length > 0) {
|
|
|
|
// The response text is a JSON array
|
|
|
|
// of the folders that were left opened.
|
|
|
|
var data = http.responseText.evalJSON(true);
|
|
|
|
for (var i = 1; i < mailboxTree.aNodes.length; i++) {
|
|
|
|
if ($(data).indexOf(mailboxTree.aNodes[i].dataname) > 0)
|
|
|
|
// If the folder is found, open it
|
|
|
|
mailboxTree.o(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mailboxTree.autoSync();
|
2007-12-13 22:07:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveFoldersState() {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (mailAccounts.length > 0) {
|
|
|
|
var foldersState = mailboxTree.getFoldersState();
|
|
|
|
var urlstr = ApplicationBaseURL + "saveFoldersState";
|
|
|
|
var parameters = "expandedFolders=" + foldersState;
|
|
|
|
triggerAjaxRequest(urlstr, saveFoldersStateCallback, null, parameters,
|
|
|
|
{ "Content-type": "application/x-www-form-urlencoded" });
|
|
|
|
}
|
2007-12-13 22:07:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveFoldersStateCallback(http) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (isHttpStatus204(http.status)) {
|
|
|
|
log ("folders state saved");
|
|
|
|
}
|
2007-12-13 22:07:09 +01:00
|
|
|
}
|
|
|
|
|
2007-10-27 00:17:29 +02:00
|
|
|
function onMenuCreateFolder(event) {
|
2010-06-02 21:11:15 +02:00
|
|
|
var name = window.prompt(_("Name :"), "");
|
2009-07-20 23:06:33 +02:00
|
|
|
if (name && name.length > 0) {
|
|
|
|
var folderID = document.menuTarget.getAttribute("dataname");
|
|
|
|
var urlstr = URLForFolderID(folderID) + "/createFolder?name=" + encodeURIComponent(name);
|
|
|
|
var errorLabel = labels["The folder with name \"%{0}\" could not be created."];
|
|
|
|
triggerAjaxRequest(urlstr, folderOperationCallback,
|
|
|
|
errorLabel.formatted(name));
|
|
|
|
}
|
2007-05-28 15:18:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuRenameFolder(event) {
|
2010-06-02 21:11:15 +02:00
|
|
|
var name = window.prompt(_("Enter the new name of your folder :"),
|
2009-07-20 23:06:33 +02:00
|
|
|
"");
|
|
|
|
if (name && name.length > 0) {
|
|
|
|
var folderID = document.menuTarget.getAttribute("dataname");
|
|
|
|
var urlstr = URLForFolderID(folderID) + "/renameFolder?name=" + name;
|
|
|
|
var errorLabel = labels["This folder could not be renamed to \"%{0}\"."];
|
|
|
|
triggerAjaxRequest(urlstr, folderOperationCallback,
|
|
|
|
errorLabel.formatted(name));
|
|
|
|
}
|
2007-05-28 15:18:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuDeleteFolder(event) {
|
2010-06-02 21:11:15 +02:00
|
|
|
var answer = window.confirm(_("Do you really want to move this folder into the trash ?"));
|
2009-07-20 23:06:33 +02:00
|
|
|
if (answer) {
|
|
|
|
var folderID = document.menuTarget.getAttribute("dataname");
|
|
|
|
var urlstr = URLForFolderID(folderID) + "/delete";
|
2010-06-02 21:11:15 +02:00
|
|
|
var errorLabel = _("The folder could not be deleted.");
|
2009-07-20 23:06:33 +02:00
|
|
|
triggerAjaxRequest(urlstr, folderOperationCallback, errorLabel);
|
|
|
|
}
|
2007-05-28 15:18:31 +02:00
|
|
|
}
|
|
|
|
|
2007-08-16 23:49:59 +02:00
|
|
|
function onMenuExpungeFolder(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var folderID = document.menuTarget.getAttribute("dataname");
|
|
|
|
var urlstr = URLForFolderID(folderID) + "/expunge";
|
|
|
|
triggerAjaxRequest(urlstr, folderRefreshCallback, { "mailbox": folderID, "refresh": false });
|
2007-08-16 23:49:59 +02:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:05:00 +02:00
|
|
|
function onMenuEmptyTrash(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var folderID = document.menuTarget.getAttribute("dataname");
|
|
|
|
var urlstr = URLForFolderID(folderID) + "/emptyTrash";
|
2010-06-02 21:11:15 +02:00
|
|
|
var errorLabel = _("The trash could not be emptied.");
|
2009-07-20 23:06:33 +02:00
|
|
|
triggerAjaxRequest(urlstr, folderOperationCallback, errorLabel);
|
2007-09-10 17:50:43 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (folderID == Mailer.currentMailbox) {
|
|
|
|
var div = $('messageContent');
|
|
|
|
for (var i = div.childNodes.length - 1; i > -1; i--)
|
|
|
|
div.removeChild(div.childNodes[i]);
|
|
|
|
refreshCurrentFolder();
|
|
|
|
}
|
|
|
|
var msgID = Mailer.currentMessages[folderID];
|
|
|
|
if (msgID)
|
|
|
|
deleteCachedMessage(folderID + "/" + msgID);
|
2007-05-28 21:05:00 +02:00
|
|
|
}
|
|
|
|
|
2007-10-17 23:03:39 +02:00
|
|
|
function _onMenuChangeToXXXFolder(event, folder) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var type = document.menuTarget.getAttribute("datatype");
|
|
|
|
if (type == "additional")
|
2010-06-02 21:11:15 +02:00
|
|
|
window.alert(_("You need to choose a non-virtual folder!"));
|
2009-07-20 23:06:33 +02:00
|
|
|
else {
|
|
|
|
var folderID = document.menuTarget.getAttribute("dataname");
|
|
|
|
var urlstr = URLForFolderID(folderID) + "/setAs" + folder + "Folder";
|
2010-06-02 21:11:15 +02:00
|
|
|
var errorLabel = _("The folder functionality could not be changed.");
|
2009-07-20 23:06:33 +02:00
|
|
|
triggerAjaxRequest(urlstr, folderOperationCallback, errorLabel);
|
|
|
|
}
|
2007-10-17 23:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuChangeToDraftsFolder(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
return _onMenuChangeToXXXFolder(event, "Drafts");
|
2007-10-17 23:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuChangeToSentFolder(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
return _onMenuChangeToXXXFolder(event, "Sent");
|
2007-10-17 23:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuChangeToTrashFolder(event) {
|
2009-07-20 23:06:33 +02:00
|
|
|
return _onMenuChangeToXXXFolder(event, "Trash");
|
2007-10-17 23:03:39 +02:00
|
|
|
}
|
|
|
|
|
2007-10-22 23:59:20 +02:00
|
|
|
function onMenuLabelNone() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var messages = new Array();
|
|
|
|
|
|
|
|
if (document.menuTarget.tagName == "DIV")
|
|
|
|
// Menu called from message content view
|
|
|
|
messages.push(Mailer.currentMessages[Mailer.currentMailbox]);
|
|
|
|
else if (Object.isArray(document.menuTarget))
|
|
|
|
// Menu called from multiple selection in messages list view
|
|
|
|
$(document.menuTarget).collect(function(row) {
|
|
|
|
messages.push(row.getAttribute("id").substr(4));
|
|
|
|
});
|
|
|
|
else
|
|
|
|
// Menu called from one selection in messages list view
|
|
|
|
messages.push(document.menuTarget.getAttribute("id").substr(4));
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/";
|
|
|
|
messages.each(function(id) {
|
|
|
|
triggerAjaxRequest(url + id + "/removeAllLabels",
|
|
|
|
messageFlagCallback,
|
|
|
|
{ mailbox: Mailer.currentMailbox, msg: id, label: null } );
|
2010-08-03 20:52:49 +02:00
|
|
|
});
|
2007-10-22 23:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function _onMenuLabelFlagX(flag) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var messages = new Hash();
|
|
|
|
|
|
|
|
if (document.menuTarget.tagName == "DIV")
|
|
|
|
// Menu called from message content view
|
|
|
|
messages.set(Mailer.currentMessages[Mailer.currentMailbox],
|
|
|
|
$('row_' + Mailer.currentMessages[Mailer.currentMailbox]).getAttribute("labels"));
|
|
|
|
else if (Object.isArray(document.menuTarget))
|
|
|
|
// Menu called from multiple selection in messages list view
|
|
|
|
$(document.menuTarget).collect(function(row) {
|
|
|
|
messages.set(row.getAttribute("id").substr(4),
|
|
|
|
row.getAttribute("labels"));
|
|
|
|
});
|
|
|
|
else
|
|
|
|
// Menu called from one selection in messages list view
|
|
|
|
messages.set(document.menuTarget.getAttribute("id").substr(4),
|
|
|
|
document.menuTarget.getAttribute("labels"));
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/";
|
|
|
|
messages.keys().each(function(id) {
|
|
|
|
var flags = messages.get(id).split(" ");
|
|
|
|
var operation = "add";
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (flags.indexOf("label" + flag) > -1)
|
|
|
|
operation = "remove";
|
2007-10-22 23:59:20 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
triggerAjaxRequest(url + id + "/" + operation + "Label" + flag,
|
|
|
|
messageFlagCallback,
|
|
|
|
{ mailbox: Mailer.currentMailbox, msg: id,
|
|
|
|
label: operation + flag } );
|
|
|
|
});
|
2007-10-22 23:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuLabelFlag1() {
|
2009-07-20 23:06:33 +02:00
|
|
|
_onMenuLabelFlagX(1);
|
2007-10-22 23:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuLabelFlag2() {
|
2009-07-20 23:06:33 +02:00
|
|
|
_onMenuLabelFlagX(2);
|
2007-10-22 23:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuLabelFlag3() {
|
2009-07-20 23:06:33 +02:00
|
|
|
_onMenuLabelFlagX(3);
|
2007-10-22 23:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuLabelFlag4() {
|
2009-07-20 23:06:33 +02:00
|
|
|
_onMenuLabelFlagX(4);
|
2007-10-22 23:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMenuLabelFlag5() {
|
2009-07-20 23:06:33 +02:00
|
|
|
_onMenuLabelFlagX(5);
|
2007-10-22 23:59:20 +02:00
|
|
|
}
|
|
|
|
|
2007-05-28 15:18:31 +02:00
|
|
|
function folderOperationCallback(http) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (http.readyState == 4
|
|
|
|
&& isHttpStatus204(http.status))
|
|
|
|
initMailboxTree();
|
|
|
|
else
|
|
|
|
window.alert(http.callbackData);
|
2007-05-28 15:18:31 +02:00
|
|
|
}
|
|
|
|
|
2007-08-16 23:49:59 +02:00
|
|
|
function folderRefreshCallback(http) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (http.readyState == 4
|
|
|
|
&& isHttpStatus204(http.status)) {
|
|
|
|
var oldMailbox = http.callbackData.mailbox;
|
|
|
|
if (http.callbackData.refresh
|
2010-05-27 16:41:59 +02:00
|
|
|
&& oldMailbox == Mailer.currentMailbox) {
|
|
|
|
if (http.callbackData.id) {
|
|
|
|
var s = http.callbackData.id + "";
|
|
|
|
var uids = s.split(",");
|
|
|
|
for (var i = 0; i < uids.length; i++)
|
|
|
|
Mailer.dataTable.remove(uids[i]);
|
|
|
|
Mailer.dataTable.render();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
refreshCurrentFolder();
|
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (http.callbackData.id) {
|
|
|
|
// Display hidden rows from move operation
|
|
|
|
var s = http.callbackData.id + "";
|
|
|
|
var uids = s.split(",");
|
|
|
|
for (var i = 0; i < uids.length; i++) {
|
|
|
|
var row = $("row_" + uids[i]);
|
|
|
|
row.show();
|
|
|
|
}
|
|
|
|
}
|
2010-06-02 21:11:15 +02:00
|
|
|
window.alert(_("Operation failed"));
|
2009-07-20 23:06:33 +02:00
|
|
|
}
|
2007-08-16 23:49:59 +02:00
|
|
|
}
|
|
|
|
|
2007-10-22 23:59:20 +02:00
|
|
|
function messageFlagCallback(http) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (http.readyState == 4
|
|
|
|
&& isHttpStatus204(http.status)) {
|
|
|
|
var data = http.callbackData;
|
|
|
|
if (data["mailbox"] == Mailer.currentMailbox) {
|
|
|
|
var row = $("row_" + data["msg"]);
|
|
|
|
var operation = data["label"];
|
|
|
|
if (operation) {
|
|
|
|
var labels = row.getAttribute("labels");
|
|
|
|
var flags;
|
|
|
|
if (labels.length > 0)
|
|
|
|
flags = labels.split(" ");
|
|
|
|
else
|
|
|
|
flags = new Array();
|
|
|
|
if (operation.substr(0, 3) == "add")
|
|
|
|
flags.push("label" + operation.substr(3));
|
|
|
|
else {
|
|
|
|
var flag = "label" + operation.substr(6);
|
|
|
|
var idx = flags.indexOf(flag);
|
|
|
|
flags.splice(idx, 1);
|
|
|
|
}
|
|
|
|
row.writeAttribute("labels", flags.join(" "));
|
|
|
|
row.toggleClassName("_selected");
|
|
|
|
row.toggleClassName("_selected");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
row.writeAttribute("labels", "");
|
|
|
|
}
|
|
|
|
}
|
2007-10-22 23:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onLabelMenuPrepareVisibility() {
|
2010-05-27 16:41:59 +02:00
|
|
|
var messageList = $("messageListBody");
|
2009-07-20 23:06:33 +02:00
|
|
|
var flags = {};
|
|
|
|
|
|
|
|
if (messageList) {
|
|
|
|
var rows = messageList.getSelectedRows();
|
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
$w(rows[i].getAttribute("labels")).each(function(flag) {
|
|
|
|
flags[flag] = true;
|
|
|
|
});
|
|
|
|
}
|
2007-10-27 00:17:29 +02:00
|
|
|
}
|
2007-10-22 23:59:20 +02:00
|
|
|
|
2010-06-25 22:43:23 +02:00
|
|
|
var lis = this.childNodesWithTag("ul")[0].childNodesWithTag("li");
|
|
|
|
var isFlagged = false;
|
2009-07-20 23:06:33 +02:00
|
|
|
for (var i = 1; i < 6; i++) {
|
|
|
|
if (flags["label" + i]) {
|
|
|
|
isFlagged = true;
|
|
|
|
lis[1 + i].addClassName("_chosen");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
lis[1 + i].removeClassName("_chosen");
|
2007-10-22 23:59:20 +02:00
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
if (isFlagged)
|
|
|
|
lis[0].removeClassName("_chosen");
|
2007-10-22 23:59:20 +02:00
|
|
|
else
|
2009-07-20 23:06:33 +02:00
|
|
|
lis[0].addClassName("_chosen");
|
2007-10-22 23:59:20 +02:00
|
|
|
}
|
|
|
|
|
2008-09-30 17:00:28 +02:00
|
|
|
function saveAs(event) {
|
2010-05-27 16:41:59 +02:00
|
|
|
var messageList = $("messageListBody").down("TBODY");
|
2009-07-20 23:06:33 +02:00
|
|
|
var rows = messageList.getSelectedNodes();
|
|
|
|
var uids = new Array(); // message IDs
|
|
|
|
var paths = new Array(); // row IDs
|
2008-09-30 15:10:15 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (rows.length > 0) {
|
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
var uid = rows[i].readAttribute("id").substr(4);
|
|
|
|
var path = Mailer.currentMailbox + "/" + uid;
|
|
|
|
uids.push(uid);
|
|
|
|
paths.push(path);
|
|
|
|
}
|
|
|
|
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/saveMessages";
|
2010-04-15 20:27:08 +02:00
|
|
|
window.location.href = (url+"?id="+uids+"&uid="+uids+"&mailbox="+Mailer.currentMailbox+"&path="+paths);
|
2008-09-30 15:10:15 +02:00
|
|
|
}
|
2009-07-20 23:06:33 +02:00
|
|
|
else
|
2010-06-02 21:11:15 +02:00
|
|
|
window.alert(_("Please select a message."));
|
2008-09-30 15:10:15 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
return false;
|
2008-09-30 15:10:15 +02:00
|
|
|
}
|
|
|
|
|
2010-04-15 20:27:08 +02:00
|
|
|
function onMenuArchiveFolder(event) {
|
|
|
|
var folderID = document.menuTarget.getAttribute("dataname");
|
|
|
|
var url = URLForFolderID(folderID) + "/exportFolder";
|
|
|
|
window.location.href = url;
|
|
|
|
|
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
2007-05-28 21:19:17 +02:00
|
|
|
function getMenus() {
|
2009-07-20 23:06:33 +02:00
|
|
|
var menus = {}
|
|
|
|
menus["accountIconMenu"] = new Array(null, null, onMenuCreateFolder, null,
|
|
|
|
null, null);
|
|
|
|
menus["inboxIconMenu"] = new Array(null, null, null, "-", null,
|
|
|
|
onMenuCreateFolder, onMenuExpungeFolder,
|
2010-04-15 20:27:08 +02:00
|
|
|
onMenuArchiveFolder, "-", null,
|
2009-07-20 23:06:33 +02:00
|
|
|
onMenuSharing);
|
|
|
|
menus["trashIconMenu"] = new Array(null, null, null, "-", null,
|
|
|
|
onMenuCreateFolder, onMenuExpungeFolder,
|
2010-04-15 20:27:08 +02:00
|
|
|
onMenuArchiveFolder, onMenuEmptyTrash,
|
|
|
|
"-", null,
|
2009-07-20 23:06:33 +02:00
|
|
|
onMenuSharing);
|
|
|
|
menus["mailboxIconMenu"] = new Array(null, null, null, "-", null,
|
|
|
|
onMenuCreateFolder,
|
|
|
|
onMenuRenameFolder,
|
|
|
|
onMenuExpungeFolder,
|
2010-04-15 20:27:08 +02:00
|
|
|
onMenuArchiveFolder,
|
2009-07-20 23:06:33 +02:00
|
|
|
onMenuDeleteFolder,
|
|
|
|
"folderTypeMenu",
|
|
|
|
"-", null,
|
|
|
|
onMenuSharing);
|
|
|
|
menus["addressMenu"] = new Array(newContactFromEmail, newEmailTo, null);
|
|
|
|
menus["messageListMenu"] = new Array(onMenuOpenMessage, "-",
|
|
|
|
onMenuReplyToSender,
|
|
|
|
onMenuReplyToAll,
|
|
|
|
onMenuForwardMessage, null,
|
|
|
|
"-", "moveMailboxMenu",
|
|
|
|
"copyMailboxMenu", "label-menu",
|
|
|
|
"mark-menu", "-", saveAs,
|
|
|
|
onMenuViewMessageSource, null,
|
|
|
|
null, onMenuDeleteMessage);
|
|
|
|
menus["messagesListMenu"] = new Array(onMenuForwardMessage,
|
|
|
|
"-", "moveMailboxMenu",
|
|
|
|
"copyMailboxMenu", "label-menu",
|
|
|
|
"mark-menu", "-",
|
|
|
|
saveAs, null,
|
|
|
|
onMenuDeleteMessage);
|
|
|
|
menus["imageMenu"] = new Array(saveImage);
|
|
|
|
menus["attachmentMenu"] = new Array (saveAttachment);
|
|
|
|
menus["messageContentMenu"] = new Array(onMenuReplyToSender,
|
|
|
|
onMenuReplyToAll,
|
|
|
|
onMenuForwardMessage,
|
|
|
|
null, "moveMailboxMenu",
|
|
|
|
"copyMailboxMenu",
|
|
|
|
"-", "label-menu", "mark-menu",
|
|
|
|
"-",
|
|
|
|
saveAs, onMenuViewMessageSource,
|
|
|
|
null, onPrintCurrentMessage,
|
|
|
|
onMenuDeleteMessage);
|
|
|
|
menus["folderTypeMenu"] = new Array(onMenuChangeToSentFolder,
|
|
|
|
onMenuChangeToDraftsFolder,
|
|
|
|
onMenuChangeToTrashFolder);
|
|
|
|
|
|
|
|
menus["label-menu"] = new Array(onMenuLabelNone, "-", onMenuLabelFlag1,
|
|
|
|
onMenuLabelFlag2, onMenuLabelFlag3,
|
|
|
|
onMenuLabelFlag4, onMenuLabelFlag5);
|
|
|
|
menus["mark-menu"] = new Array(null, null, null, null, "-", null, "-",
|
|
|
|
null, null, null);
|
|
|
|
menus["searchMenu"] = new Array(setSearchCriteria, setSearchCriteria,
|
|
|
|
setSearchCriteria, setSearchCriteria,
|
|
|
|
setSearchCriteria);
|
|
|
|
var labelMenu = $("label-menu");
|
|
|
|
if (labelMenu)
|
|
|
|
labelMenu.prepareVisibility = onLabelMenuPrepareVisibility;
|
|
|
|
|
|
|
|
return menus;
|
2007-05-18 19:25:58 +02:00
|
|
|
}
|
|
|
|
|
2009-03-06 22:12:42 +01:00
|
|
|
document.observe("dom:loaded", initMailer);
|
2007-05-25 23:12:46 +02:00
|
|
|
|
2009-09-29 22:39:23 +02:00
|
|
|
function Mailbox(type, name, unseen, displayName) {
|
2009-07-20 23:06:33 +02:00
|
|
|
this.type = type;
|
2009-09-29 22:39:23 +02:00
|
|
|
if (displayName)
|
|
|
|
this.displayName = displayName;
|
|
|
|
else
|
|
|
|
this.displayName = name;
|
2010-01-05 23:34:35 +01:00
|
|
|
// log("name: " + name + "; dn: " + displayName);
|
|
|
|
this.name = name.asCSSIdentifier();
|
2009-07-20 23:06:33 +02:00
|
|
|
this.unseen = unseen;
|
|
|
|
this.parentFolder = null;
|
|
|
|
this.children = new Array();
|
|
|
|
return this;
|
2007-05-25 23:12:46 +02:00
|
|
|
}
|
|
|
|
|
2008-04-15 22:12:51 +02:00
|
|
|
Mailbox.prototype = {
|
2009-07-20 23:06:33 +02:00
|
|
|
dump: function(indent) {
|
|
|
|
if (!indent)
|
|
|
|
indent = 0;
|
|
|
|
log(" ".repeat(indent) + this.name);
|
|
|
|
for (var i = 0; i < this.children.length; i++) {
|
|
|
|
this.children[i].dump(indent + 2);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fullName: function() {
|
|
|
|
var fullName = "";
|
|
|
|
|
|
|
|
var currentFolder = this;
|
|
|
|
while (currentFolder.parentFolder) {
|
|
|
|
fullName = "/folder" + currentFolder.name + fullName;
|
|
|
|
currentFolder = currentFolder.parentFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "/" + currentFolder.name + fullName;
|
|
|
|
},
|
|
|
|
findMailboxByName: function(name) {
|
|
|
|
var mailbox = null;
|
|
|
|
|
2010-01-05 23:34:35 +01:00
|
|
|
var searchName = name.asCSSIdentifier();
|
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
var i = 0;
|
|
|
|
while (!mailbox && i < this.children.length)
|
2010-01-05 23:34:35 +01:00
|
|
|
if (this.children[i].name == searchName
|
2009-09-29 22:13:36 +02:00
|
|
|
|| this.children[i].displayName == name)
|
2009-07-20 23:06:33 +02:00
|
|
|
mailbox = this.children[i];
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
|
|
|
|
return mailbox;
|
|
|
|
},
|
|
|
|
addMailbox: function(mailbox) {
|
|
|
|
mailbox.parentFolder = this;
|
|
|
|
this.children.push(mailbox);
|
|
|
|
}
|
2008-04-15 22:12:51 +02:00
|
|
|
};
|
2007-05-25 23:12:46 +02:00
|
|
|
|
2009-06-30 19:54:13 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
function configureDraggables () {
|
|
|
|
var mainElement = $("dragDropVisual");
|
|
|
|
Draggables.empty ();
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if (mainElement == null) {
|
|
|
|
mainElement = new Element ("div", {id: "dragDropVisual"});
|
|
|
|
document.body.appendChild(mainElement);
|
|
|
|
mainElement.absolutize ();
|
|
|
|
}
|
|
|
|
mainElement.hide();
|
2010-08-03 20:52:49 +02:00
|
|
|
|
|
|
|
new Draggable ("dragDropVisual",
|
|
|
|
{ handle: "messageListBody",
|
2009-07-20 23:06:33 +02:00
|
|
|
onStart: startDragging,
|
|
|
|
onEnd: stopDragging,
|
|
|
|
onDrag: whileDragging,
|
|
|
|
scroll: "folderTreeContent" });
|
|
|
|
}
|
2009-06-30 19:54:13 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
function configureDroppables () {
|
|
|
|
var drops = $$("div#dmailboxTree1 div.dTreeNode a.node span.nodeName");
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
Droppables.empty ();
|
|
|
|
drops.each (function (drop) {
|
|
|
|
drop.identify ()
|
2010-08-03 20:52:49 +02:00
|
|
|
Droppables.add (drop.id,
|
2009-07-20 23:06:33 +02:00
|
|
|
{ hoverclass: "genericHoverClass",
|
|
|
|
onDrop: dropAction });
|
|
|
|
});
|
2009-06-30 19:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function startDragging (itm, e) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var target = Event.element(e);
|
2010-05-27 16:41:59 +02:00
|
|
|
if (target.up('TBODY') == undefined)
|
2009-07-20 23:06:33 +02:00
|
|
|
return false;
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
var handle = $("dragDropVisual");
|
2010-05-27 16:41:59 +02:00
|
|
|
var count = $("messageListBody").getSelectedRowsId().length;
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
handle.update (count);
|
|
|
|
if (e.shiftKey)
|
|
|
|
handle.addClassName ("copy");
|
|
|
|
handle.show();
|
2009-06-30 19:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function whileDragging (itm, e) {
|
2009-07-20 23:06:33 +02:00
|
|
|
if (e) {
|
|
|
|
var handle = $("dragDropVisual");
|
|
|
|
if (e.shiftKey)
|
|
|
|
handle.addClassName ("copy");
|
|
|
|
else if (handle.hasClassName ("copy"))
|
|
|
|
handle.removeClassName ("copy");
|
|
|
|
}
|
2009-06-30 19:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function stopDragging () {
|
2009-07-20 23:06:33 +02:00
|
|
|
var handle = $("dragDropVisual");
|
|
|
|
handle.hide();
|
|
|
|
if (handle.hasClassName ("copy"))
|
|
|
|
handle.removeClassName ("copy");
|
2009-06-30 19:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function dropAction (dropped, zone, e) {
|
2009-07-20 23:06:33 +02:00
|
|
|
var destination = zone.up("div.dTreeNode");
|
|
|
|
var f;
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
if ($("dragDropVisual").hasClassName("copy")) {
|
|
|
|
// Message(s) copied
|
|
|
|
f = onMailboxMenuCopy.bind(destination);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Message(s) moved
|
|
|
|
f = onMailboxMenuMove.bind(destination);
|
|
|
|
}
|
2010-08-03 20:52:49 +02:00
|
|
|
|
2009-07-20 23:06:33 +02:00
|
|
|
f();
|
2009-07-09 17:27:11 +02:00
|
|
|
}
|