2010-03-02 20:57:30 +01:00
|
|
|
var isSieveScriptsEnabled = false;
|
|
|
|
var filters = [];
|
2010-08-06 17:34:05 +02:00
|
|
|
var mailAccounts = null;
|
|
|
|
var dialogs = {};
|
2008-08-28 16:48:45 +02:00
|
|
|
|
2007-06-19 19:59:59 +02:00
|
|
|
function savePreferences(sender) {
|
2009-09-22 22:54:09 +02:00
|
|
|
var sendForm = true;
|
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
var sigList = $("signaturePlacementList");
|
|
|
|
if (sigList)
|
2009-09-22 22:54:09 +02:00
|
|
|
sigList.disabled = false;
|
2009-07-02 17:40:45 +02:00
|
|
|
|
2009-09-18 15:36:40 +02:00
|
|
|
if ($("categoriesList")) {
|
2010-05-16 19:27:25 +02:00
|
|
|
serializeCategories();
|
2009-09-18 15:36:40 +02:00
|
|
|
}
|
2007-06-19 19:59:59 +02:00
|
|
|
|
2009-09-22 22:54:09 +02:00
|
|
|
if ($("dayStartTime")) {
|
|
|
|
var start = $("dayStartTime");
|
|
|
|
var selectedStart = parseInt(start.options[start.selectedIndex].value);
|
|
|
|
var end = $("dayEndTime");
|
|
|
|
var selectedEnd = parseInt(end.options[end.selectedIndex].value);
|
|
|
|
if (selectedStart >= selectedEnd) {
|
2010-06-02 21:11:15 +02:00
|
|
|
alert (_("Day start time must be prior to day end time."));
|
2009-09-22 22:54:09 +02:00
|
|
|
sendForm = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-09 22:30:42 +02:00
|
|
|
if ($("enableVacation") && $("enableVacation").checked) {
|
|
|
|
if ($("autoReplyText").value.strip().length == 0
|
|
|
|
|| $("autoReplyEmailAddresses").value.strip().length == 0) {
|
2010-06-02 21:11:15 +02:00
|
|
|
alert(_("Please specify your message and your email addresses for which you want to enable auto reply."));
|
2009-10-09 22:30:42 +02:00
|
|
|
sendForm = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($("enableForward") && $("enableForward").checked) {
|
2010-06-30 19:26:06 +02:00
|
|
|
if (!emailRE.test($("forwardAddress").value)) {
|
2010-06-02 21:11:15 +02:00
|
|
|
alert(_("Please specify an address to which you want to forward your messages."));
|
2009-10-09 22:30:42 +02:00
|
|
|
sendForm = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-02 20:57:30 +01:00
|
|
|
if (isSieveScriptsEnabled) {
|
|
|
|
var jsonFilters = prototypeIfyFilters();
|
|
|
|
$("sieveFilters").setValue(jsonFilters.toJSON());
|
|
|
|
}
|
|
|
|
|
2010-08-06 17:34:05 +02:00
|
|
|
saveMailAccounts();
|
|
|
|
|
2009-09-22 22:54:09 +02:00
|
|
|
if (sendForm)
|
2010-03-02 20:57:30 +01:00
|
|
|
$("mainForm").submit();
|
2009-09-18 15:36:40 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
return false;
|
2007-06-19 19:59:59 +02:00
|
|
|
}
|
2008-07-25 20:44:31 +02:00
|
|
|
|
2010-03-02 20:57:30 +01:00
|
|
|
function prototypeIfyFilters() {
|
|
|
|
var newFilters = $([]);
|
|
|
|
for (var i = 0; i < filters.length; i++) {
|
|
|
|
var filter = filters[i];
|
|
|
|
var newFilter = $({});
|
|
|
|
newFilter.name = filter.name;
|
|
|
|
newFilter.match = filter.match;
|
|
|
|
newFilter.active = filter.active;
|
|
|
|
|
2010-04-06 17:41:08 +02:00
|
|
|
if (filter.rules) {
|
|
|
|
newFilter.rules = $([]);
|
|
|
|
for (var j = 0; j < filter.rules.length; j++) {
|
|
|
|
newFilter.rules.push($(filter.rules[j]));
|
|
|
|
}
|
2010-03-02 20:57:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
newFilter.actions = $([]);
|
|
|
|
for (var j = 0; j < filter.actions.length; j++) {
|
|
|
|
newFilter.actions.push($(filter.actions[j]));
|
|
|
|
}
|
|
|
|
newFilters.push(newFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return newFilters;
|
|
|
|
}
|
|
|
|
|
2010-08-06 17:34:05 +02:00
|
|
|
function _setupEvents() {
|
2010-03-25 21:17:50 +01:00
|
|
|
var widgets = [ "timezone", "shortDateFormat", "longDateFormat",
|
|
|
|
"timeFormat", "weekStartDay", "dayStartTime", "dayEndTime",
|
|
|
|
"firstWeek", "messageCheck", "subscribedFoldersOnly",
|
2010-05-16 19:27:25 +02:00
|
|
|
"language" ];
|
2010-03-25 21:17:50 +01:00
|
|
|
for (var i = 0; i < widgets.length; i++) {
|
|
|
|
var widget = $(widgets[i]);
|
|
|
|
if (widget) {
|
2010-08-06 17:34:05 +02:00
|
|
|
widget.observe("change", onChoiceChanged);
|
2010-03-25 21:17:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-16 19:27:25 +02:00
|
|
|
// Note: we also monitor changes to the calendar categories.
|
|
|
|
// See functions endEditable and onColorPickerChoice.
|
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
$("replyPlacementList").observe ("change", onReplyPlacementListChange);
|
|
|
|
$("composeMessagesType").observe ("change", onComposeMessagesTypeChange);
|
2009-11-06 14:53:52 +01:00
|
|
|
|
|
|
|
var categoriesValue = $("categoriesValue");
|
|
|
|
if (categoriesValue)
|
|
|
|
categoriesValue.value = "";
|
2008-07-25 20:44:31 +02:00
|
|
|
}
|
|
|
|
|
2010-03-25 21:17:50 +01:00
|
|
|
function onChoiceChanged(event) {
|
|
|
|
var hasChanged = $("hasChanged");
|
|
|
|
hasChanged.value = "1";
|
|
|
|
}
|
|
|
|
|
2010-03-08 16:18:05 +01:00
|
|
|
function addDefaultEmailAddresses(event) {
|
2009-10-15 00:11:13 +02:00
|
|
|
var defaultAddresses = $("defaultEmailAddresses").value.split(/, */);
|
2009-10-30 20:37:04 +01:00
|
|
|
var addresses = $("autoReplyEmailAddresses").value.trim();
|
2010-08-06 17:34:05 +02:00
|
|
|
|
2009-10-30 20:37:04 +01:00
|
|
|
if (addresses) addresses = addresses.split(/, */);
|
|
|
|
else addresses = new Array();
|
2009-10-15 00:11:13 +02:00
|
|
|
|
|
|
|
defaultAddresses.each(function(adr) {
|
|
|
|
for (var i = 0; i < addresses.length; i++)
|
|
|
|
if (adr == addresses[i])
|
|
|
|
break;
|
|
|
|
if (i == addresses.length)
|
|
|
|
addresses.push(adr);
|
|
|
|
});
|
2010-08-06 17:34:05 +02:00
|
|
|
|
2009-10-15 00:11:13 +02:00
|
|
|
$("autoReplyEmailAddresses").value = addresses.join(", ");
|
2010-03-08 16:18:05 +01:00
|
|
|
|
|
|
|
event.stop();
|
2009-10-15 00:11:13 +02:00
|
|
|
}
|
|
|
|
|
2008-07-25 20:44:31 +02:00
|
|
|
function initPreferences() {
|
2010-04-12 19:51:59 +02:00
|
|
|
var tabsContainer = $("preferencesTabs");
|
|
|
|
var controller = new SOGoTabsController();
|
|
|
|
controller.attachToTabsContainer(tabsContainer);
|
|
|
|
|
2010-03-02 20:57:30 +01:00
|
|
|
var filtersListWrapper = $("filtersListWrapper");
|
|
|
|
if (filtersListWrapper) {
|
|
|
|
isSieveScriptsEnabled = true;
|
|
|
|
}
|
2010-08-06 17:34:05 +02:00
|
|
|
_setupEvents();
|
2009-08-04 21:29:38 +02:00
|
|
|
if (typeof (initAdditionalPreferences) != "undefined")
|
|
|
|
initAdditionalPreferences();
|
|
|
|
|
|
|
|
var table = $("categoriesList");
|
2009-09-18 15:36:40 +02:00
|
|
|
if (table) {
|
2009-10-15 00:11:13 +02:00
|
|
|
resetCategoriesColors(null);
|
2009-09-18 15:36:40 +02:00
|
|
|
var r = $$("TABLE#categoriesList tbody tr");
|
2009-10-15 00:11:13 +02:00
|
|
|
for (var i= 0; i < r.length; i++)
|
|
|
|
r[i].identify();
|
2009-09-18 15:36:40 +02:00
|
|
|
table.multiselect = true;
|
2009-10-15 00:11:13 +02:00
|
|
|
resetTableActions();
|
|
|
|
$("categoryAdd").observe("click", onCategoryAdd);
|
|
|
|
$("categoryDelete").observe("click", onCategoryDelete);
|
2009-09-18 15:36:40 +02:00
|
|
|
}
|
2009-09-10 20:19:12 +02:00
|
|
|
|
|
|
|
// Disable placement (after) if composing in HTML
|
|
|
|
if ($("composeMessagesType")) {
|
|
|
|
if ($("composeMessagesType").value == 1) {
|
|
|
|
$("replyPlacementList").selectedIndex = 0;
|
|
|
|
$("replyPlacementList").disabled = 1;
|
|
|
|
}
|
2009-10-06 20:12:07 +02:00
|
|
|
onReplyPlacementListChange ();
|
2009-09-10 20:19:12 +02:00
|
|
|
}
|
2009-10-15 00:11:13 +02:00
|
|
|
|
2010-03-08 16:18:05 +01:00
|
|
|
var button = $("addDefaultEmailAddresses");
|
|
|
|
if (button)
|
|
|
|
button.observe("click", addDefaultEmailAddresses);
|
|
|
|
|
2010-08-06 17:34:05 +02:00
|
|
|
button = $("changePasswordBtn");
|
2010-03-08 16:18:05 +01:00
|
|
|
if (button)
|
|
|
|
button.observe("click", onChangePasswordClick);
|
2010-03-02 20:57:30 +01:00
|
|
|
|
|
|
|
initSieveFilters();
|
2010-08-06 17:34:05 +02:00
|
|
|
initMailAccounts();
|
2010-03-02 20:57:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function initSieveFilters() {
|
|
|
|
var table = $("filtersList");
|
|
|
|
if (table) {
|
|
|
|
var filtersValue = $("sieveFilters").getValue();
|
|
|
|
if (filtersValue && filtersValue.length) {
|
|
|
|
filters = $(filtersValue.evalJSON(false));
|
|
|
|
for (var i = 0; i < filters.length; i++) {
|
|
|
|
appendSieveFilterRow(table, i, filters[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$("filterAdd").observe("click", onFilterAdd);
|
|
|
|
$("filterDelete").observe("click", onFilterDelete);
|
|
|
|
$("filterMoveUp").observe("click", onFilterMoveUp);
|
|
|
|
$("filterMoveDown").observe("click", onFilterMoveDown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function appendSieveFilterRow(filterTable, number, filter) {
|
|
|
|
var row = createElement("tr");
|
|
|
|
row.observe("mousedown", onRowClick);
|
|
|
|
row.observe("dblclick", onFilterEdit.bindAsEventListener(row));
|
|
|
|
|
|
|
|
var nameColumn = createElement("td");
|
|
|
|
nameColumn.appendChild(document.createTextNode(filter["name"]));
|
|
|
|
row.appendChild(nameColumn);
|
|
|
|
|
|
|
|
var activeColumn = createElement("td", null, "activeColumn");
|
|
|
|
var cb = createElement("input", null, "checkBox",
|
|
|
|
{ checked: filter.active,
|
|
|
|
type: "checkbox" },
|
|
|
|
null, activeColumn);
|
|
|
|
var bound = onScriptActiveCheck.bindAsEventListener(cb);
|
2010-08-27 16:56:57 +02:00
|
|
|
cb.observe("click", bound);
|
2010-03-02 20:57:30 +01:00
|
|
|
row.appendChild(activeColumn);
|
|
|
|
|
|
|
|
filterTable.tBodies[0].appendChild(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onScriptActiveCheck(event) {
|
|
|
|
var index = this.parentNode.parentNode.rowIndex - 1;
|
|
|
|
filters[index].active = this.checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateSieveFilterRow(filterTable, number, filter) {
|
|
|
|
var row = $(filterTable.tBodies[0].rows[number]);
|
|
|
|
var columns = row.childNodesWithTag("td");
|
|
|
|
var nameColumn = columns[0];
|
|
|
|
while (nameColumn.firstChild) {
|
|
|
|
nameColumn.removeChild(nameColumn.firstChild);
|
|
|
|
}
|
|
|
|
nameColumn.appendChild(document.createTextNode(filter.name));
|
|
|
|
|
|
|
|
var activeColumn = columns[1];
|
|
|
|
while (activeColumn.firstChild) {
|
|
|
|
activeColumn.removeChild(activeColumn.firstChild);
|
|
|
|
}
|
|
|
|
createElement("input", null, "checkBox",
|
|
|
|
{ checked: filter.active,
|
|
|
|
type: "checkbox" },
|
|
|
|
null, activeColumn);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _editFilter(filterId) {
|
|
|
|
var urlstr = ApplicationBaseURL + "editFilter?filter=" + filterId;
|
|
|
|
var win = window.open(urlstr, "sieve_filter_" + filterId,
|
2010-03-11 15:52:52 +01:00
|
|
|
"width=560,height=380,resizable=0");
|
2010-03-02 20:57:30 +01:00
|
|
|
if (win)
|
|
|
|
win.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onFilterAdd(event) {
|
|
|
|
_editFilter("new");
|
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onFilterDelete(event) {
|
|
|
|
var filtersList = $("filtersList").tBodies[0];
|
|
|
|
var nodes = filtersList.getSelectedNodes();
|
|
|
|
if (nodes.length > 0) {
|
|
|
|
var deletedFilters = [];
|
|
|
|
for (var i = 0; i < nodes.length; i++) {
|
|
|
|
var node = nodes[i];
|
|
|
|
deletedFilters.push(node.rowIndex - 1);
|
|
|
|
}
|
|
|
|
deletedFilters = deletedFilters.sort(function (x,y) { return x-y; });
|
|
|
|
var rows = filtersList.rows;
|
|
|
|
for (var i = 0; i < deletedFilters.length; i++) {
|
|
|
|
var filterNbr = deletedFilters[i];
|
|
|
|
filters.splice(filterNbr, 1);
|
|
|
|
var row = rows[filterNbr];
|
|
|
|
row.parentNode.removeChild(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onFilterMoveUp(event) {
|
|
|
|
var filtersList = $("filtersList").tBodies[0];
|
|
|
|
var nodes = filtersList.getSelectedNodes();
|
|
|
|
if (nodes.length > 0) {
|
|
|
|
var node = nodes[0];
|
|
|
|
var previous = node.previous();
|
|
|
|
if (previous) {
|
|
|
|
var count = node.rowIndex - 1;
|
|
|
|
node.parentNode.removeChild(node);
|
|
|
|
filtersList.insertBefore(node, previous);
|
|
|
|
var swapFilter = filters[count];
|
|
|
|
filters[count] = filters[count - 1];
|
|
|
|
filters[count - 1] = swapFilter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onFilterMoveDown(event) {
|
|
|
|
var filtersList = $("filtersList").tBodies[0];
|
|
|
|
var nodes = filtersList.getSelectedNodes();
|
|
|
|
if (nodes.length > 0) {
|
|
|
|
var node = nodes[0];
|
|
|
|
var next = node.next();
|
|
|
|
if (next) {
|
|
|
|
var count = node.rowIndex - 1;
|
|
|
|
filtersList.removeChild(next);
|
|
|
|
filtersList.insertBefore(next, node);
|
|
|
|
var swapFilter = filters[count];
|
|
|
|
filters[count] = filters[count + 1];
|
|
|
|
filters[count + 1] = swapFilter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onFilterEdit(event) {
|
|
|
|
_editFilter(this.rowIndex - 1);
|
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyFilter(originalFilter) {
|
|
|
|
var newFilter = {};
|
|
|
|
|
|
|
|
newFilter.name = originalFilter.name;
|
|
|
|
newFilter.match = originalFilter.match;
|
|
|
|
newFilter.active = originalFilter.active;
|
2010-04-06 17:41:08 +02:00
|
|
|
if (originalFilter.rules) {
|
|
|
|
newFilter.rules = [];
|
|
|
|
for (var i = 0; i < originalFilter.rules.length; i++) {
|
|
|
|
newFilter.rules.push(_copyFilterElement(originalFilter.rules[i]));
|
|
|
|
}
|
2010-03-02 20:57:30 +01:00
|
|
|
}
|
|
|
|
newFilter.actions = [];
|
|
|
|
for (var i = 0; i < originalFilter.actions.length; i++) {
|
|
|
|
newFilter.actions.push(_copyFilterElement(originalFilter.actions[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return newFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _copyFilterElement(filterElement) { /* element = rule or action */
|
|
|
|
var newElement = {};
|
|
|
|
for (var k in filterElement) {
|
|
|
|
var value = filterElement[k];
|
|
|
|
if (typeof(value) == "string" || typeof(value) == "number") {
|
2010-08-06 17:34:05 +02:00
|
|
|
newElement[k] = value;
|
2010-03-02 20:57:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSieveCapabilitiesFromEditor() {
|
|
|
|
return sieveCapabilities;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFilterFromEditor(filterId) {
|
|
|
|
return copyFilter(filters[filterId]);
|
|
|
|
}
|
|
|
|
|
2010-08-27 16:56:57 +02:00
|
|
|
function setupMailboxesFromJSON(jsonResponse) {
|
|
|
|
var responseMboxes = jsonResponse.mailboxes;
|
|
|
|
userMailboxes = $([]);
|
|
|
|
for (var i = 0; i < responseMboxes.length; i++) {
|
|
|
|
var name = responseMboxes[i].path.substr(1);
|
|
|
|
userMailboxes.push(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateFilterFromEditor(filterId, filterJSON) {
|
|
|
|
var filter = filterJSON.evalJSON();
|
2010-03-02 20:57:30 +01:00
|
|
|
var sanitized = {};
|
|
|
|
for (var k in filter) {
|
|
|
|
if (!(k == "rules" && filter.match == "allmessages")) {
|
|
|
|
sanitized[k] = filter[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var table = $("filtersList");
|
|
|
|
if (filterId == "new") {
|
|
|
|
var newNumber = filters.length;
|
|
|
|
filters.push(sanitized);
|
|
|
|
appendSieveFilterRow(table, newNumber, sanitized);
|
|
|
|
} else {
|
|
|
|
filters[filterId] = sanitized;
|
|
|
|
updateSieveFilterRow(table, filterId, sanitized);
|
|
|
|
}
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
2010-08-06 17:34:05 +02:00
|
|
|
/* mail accounts */
|
|
|
|
function initMailAccounts() {
|
|
|
|
var mailAccountsJSON = $("mailAccountsJSON");
|
|
|
|
mailAccounts = mailAccountsJSON.value.evalJSON();
|
|
|
|
|
|
|
|
var mailAccountsList = $("mailAccountsList");
|
|
|
|
if (mailAccountsList) {
|
|
|
|
var li = createMailAccountLI(mailAccounts[0], true);
|
|
|
|
mailAccountsList.appendChild(li);
|
|
|
|
for (var i = 1; i < mailAccounts.length; i++) {
|
|
|
|
li = createMailAccountLI(mailAccounts[i]);
|
|
|
|
mailAccountsList.appendChild(li);
|
|
|
|
}
|
|
|
|
var lis = mailAccountsList.childNodesWithTag("li");
|
|
|
|
lis[0].readOnly = true;
|
|
|
|
lis[0].selectElement();
|
|
|
|
|
|
|
|
var button = $("mailAccountAdd");
|
|
|
|
if (button) {
|
|
|
|
button.observe("click", onMailAccountAdd);
|
|
|
|
}
|
|
|
|
button = $("mailAccountDelete");
|
|
|
|
if (button) {
|
|
|
|
button.observe("click", onMailAccountDelete);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var info = $("accountInfo");
|
|
|
|
var inputs = info.getElementsByTagName("input");
|
|
|
|
for (var i = 0; i < inputs.length; i++) {
|
|
|
|
$(inputs[i]).observe("change", onMailAccountInfoChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
info = $("identityInfo");
|
|
|
|
inputs = info.getElementsByTagName("input");
|
|
|
|
for (var i = 0; i < inputs.length; i++) {
|
|
|
|
$(inputs[i]).observe("change", onMailIdentityInfoChange);
|
|
|
|
}
|
|
|
|
$("actSignature").observe("click", onMailIdentitySignatureClick);
|
|
|
|
displayMailAccount(mailAccounts[0], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMailAccountInfoChange(event) {
|
|
|
|
this.mailAccount[this.name] = this.value;
|
|
|
|
var hasChanged = $("hasChanged");
|
|
|
|
hasChanged.value = "1";
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMailIdentityInfoChange(event) {
|
|
|
|
if (!this.mailAccount["identities"]) {
|
|
|
|
this.mailAccount["identities"] = [{}];
|
|
|
|
}
|
|
|
|
var identity = this.mailAccount["identities"][0];
|
|
|
|
identity[this.name] = this.value;
|
|
|
|
var hasChanged = $("hasChanged");
|
|
|
|
hasChanged.value = "1";
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMailIdentitySignatureClick(event) {
|
|
|
|
if (!this.readOnly) {
|
|
|
|
var dialogId = "signatureDialog";
|
|
|
|
var dialog = dialogs[dialogId];
|
|
|
|
if (!dialog) {
|
|
|
|
var label = _("Please enter your signature below:");
|
|
|
|
var fields = createElement("p");
|
|
|
|
fields.appendChild(createElement("textarea", "signature"));
|
|
|
|
fields.appendChild(createElement("br"));
|
|
|
|
fields.appendChild(createButton("okBtn", _("OK"),
|
|
|
|
onMailIdentitySignatureOK));
|
|
|
|
fields.appendChild(createButton("cancelBtn", _("Cancel"),
|
2010-08-19 16:19:24 +02:00
|
|
|
disposeDialog.bind(document.body, dialogId)));
|
2010-08-06 17:34:05 +02:00
|
|
|
var dialog = createDialog(dialogId,
|
|
|
|
_("Signature"),
|
|
|
|
label,
|
|
|
|
fields,
|
|
|
|
"none");
|
|
|
|
document.body.appendChild(dialog);
|
|
|
|
dialog.show();
|
|
|
|
dialogs[dialogId] = dialog;
|
|
|
|
|
|
|
|
if ($("composeMessagesType").value != 0) {
|
|
|
|
CKEDITOR.replace('signature',
|
|
|
|
{ height: "70px",
|
|
|
|
toolbar: [['Bold', 'Italic', '-', 'Link',
|
|
|
|
'Font','FontSize','-','TextColor',
|
|
|
|
'BGColor']
|
|
|
|
],
|
|
|
|
language: localeCode,
|
|
|
|
scayt_sLang: localeCode });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dialog.mailAccount = this.mailAccount;
|
|
|
|
if (!this.mailAccount["identities"]) {
|
|
|
|
this.mailAccount["identities"] = [{}];
|
|
|
|
}
|
|
|
|
var identity = this.mailAccount["identities"][0];
|
|
|
|
var area = $("signature");
|
|
|
|
area.value = identity["signature"];
|
|
|
|
dialog.show();
|
|
|
|
$("bgDialogDiv").show();
|
|
|
|
if (!CKEDITOR.instances["signature"])
|
|
|
|
area.focus();
|
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMailIdentitySignatureOK(event) {
|
|
|
|
var dialog = $("signatureDialog");
|
|
|
|
var mailAccount = dialog.mailAccount;
|
|
|
|
if (!mailAccount["identities"]) {
|
|
|
|
mailAccount["identities"] = [{}];
|
|
|
|
}
|
|
|
|
var identity = mailAccount["identities"][0];
|
|
|
|
|
|
|
|
var content = (CKEDITOR.instances["signature"]
|
|
|
|
? CKEDITOR.instances["signature"].getData()
|
|
|
|
: $("signature").value);
|
|
|
|
identity["signature"] = content;
|
|
|
|
displayAccountSignature(mailAccount);
|
|
|
|
dialog.hide();
|
|
|
|
$("bgDialogDiv").hide();
|
|
|
|
dialog.mailAccount = null;
|
|
|
|
var hasChanged = $("hasChanged");
|
|
|
|
hasChanged.value = "1";
|
|
|
|
}
|
|
|
|
|
|
|
|
function createMailAccountLI(mailAccount, readOnly) {
|
|
|
|
var li = createElement("li");
|
|
|
|
li.appendChild(document.createTextNode(mailAccount["name"]));
|
|
|
|
li.observe("click", onMailAccountEntryClick);
|
|
|
|
li.observe("mousedown", onRowClick);
|
|
|
|
if (readOnly) {
|
|
|
|
li.addClassName("readonly");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var editionCtlr = new RowEditionController();
|
|
|
|
editionCtlr.attachToRowElement(li);
|
|
|
|
editionCtlr.notifyNewValueCallback = function(ignore, newValue) {
|
|
|
|
mailAccount["name"] = newValue;
|
|
|
|
};
|
|
|
|
li.editionController = editionCtlr;
|
|
|
|
}
|
|
|
|
li.mailAccount = mailAccount;
|
|
|
|
|
|
|
|
return li;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMailAccountEntryClick(event) {
|
|
|
|
displayMailAccount(this.mailAccount, this.readOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayMailAccount(mailAccount, readOnly) {
|
|
|
|
var editor = $("mailAccountEditor");
|
|
|
|
var inputs = editor.getElementsByTagName("input");
|
|
|
|
for (var i = 0; i < inputs.length; i++) {
|
|
|
|
inputs[i].disabled = readOnly;
|
|
|
|
inputs[i].mailAccount = mailAccount;
|
|
|
|
}
|
|
|
|
|
|
|
|
var encryption = "none";
|
|
|
|
|
|
|
|
var encRadioValues = [ "none", "ssl", "tls" ];
|
|
|
|
if (mailAccount["encryption"]) {
|
|
|
|
encryption = mailAccount["encryption"];
|
|
|
|
}
|
|
|
|
var form = $("mainForm");
|
|
|
|
form.setRadioValue("encryption", encRadioValues.indexOf(encryption));
|
|
|
|
|
|
|
|
var port;
|
|
|
|
if (mailAccount["port"]) {
|
|
|
|
port = mailAccount["port"];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (encryption == "ssl") {
|
|
|
|
port = 993;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
port = 143;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$("port").value = port;
|
|
|
|
|
|
|
|
$("serverName").value = mailAccount["serverName"];
|
|
|
|
$("userName").value = mailAccount["userName"];
|
|
|
|
$("password").value = mailAccount["password"];
|
|
|
|
|
|
|
|
var identity = (mailAccount["identities"]
|
|
|
|
? mailAccount["identities"][0]
|
|
|
|
: {} );
|
|
|
|
$("fullName").value = identity["fullName"] || "";
|
|
|
|
$("email").value = identity["email"] || "";
|
|
|
|
|
|
|
|
displayAccountSignature(mailAccount);
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayAccountSignature(mailAccount) {
|
|
|
|
var actSignature = $("actSignature");
|
|
|
|
actSignature.mailAccount = mailAccount;
|
|
|
|
|
|
|
|
var actSignatureValue;
|
|
|
|
var identity = (mailAccount["identities"]
|
|
|
|
? mailAccount["identities"][0]
|
|
|
|
: {} );
|
|
|
|
var value = identity["signature"];
|
|
|
|
if (value && value.length > 0) {
|
|
|
|
if (value.length < 30) {
|
|
|
|
actSignatureValue = value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
actSignatureValue = value.substr(0, 30) + "...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
actSignatureValue = _("(Click to create)");
|
|
|
|
}
|
|
|
|
while (actSignature.firstChild) {
|
|
|
|
actSignature.removeChild(actSignature.firstChild);
|
|
|
|
}
|
|
|
|
actSignature.appendChild(document.createTextNode(actSignatureValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
function createMailAccount() {
|
|
|
|
var firstIdentity = mailAccounts[0]["identities"][0];
|
|
|
|
var newIdentity = {};
|
|
|
|
for (var k in firstIdentity) {
|
|
|
|
newIdentity[k] = firstIdentity[k];
|
|
|
|
}
|
|
|
|
delete newIdentity["isDefault"];
|
|
|
|
|
|
|
|
var newMailAccount = { name: _("New Mail Account"),
|
|
|
|
serverName: "mailserver",
|
|
|
|
userName: UserLogin,
|
|
|
|
password: "",
|
|
|
|
identities: [ newIdentity ] };
|
|
|
|
|
|
|
|
return newMailAccount;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMailAccountAdd(event) {
|
|
|
|
var newMailAccount = createMailAccount();
|
|
|
|
mailAccounts.push(newMailAccount);
|
|
|
|
var li = createMailAccountLI(newMailAccount);
|
|
|
|
var mailAccountsList = $("mailAccountsList");
|
|
|
|
mailAccountsList.appendChild(li);
|
|
|
|
var selection = mailAccountsList.getSelectedNodes();
|
|
|
|
for (var i = 0; i < selection.length; i++) {
|
|
|
|
selection[i].deselect();
|
|
|
|
}
|
|
|
|
displayMailAccount(newMailAccount, false);
|
|
|
|
li.selectElement();
|
|
|
|
li.editionController.startEditing();
|
2010-08-09 15:25:02 +02:00
|
|
|
|
|
|
|
var hasChanged = $("hasChanged");
|
|
|
|
hasChanged.value = "1";
|
|
|
|
|
2010-08-06 17:34:05 +02:00
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMailAccountDelete(event) {
|
|
|
|
var mailAccountsList = $("mailAccountsList");
|
|
|
|
var selection = mailAccountsList.getSelectedNodes();
|
|
|
|
if (selection.length > 0) {
|
|
|
|
var li = selection[0];
|
|
|
|
if (!li.readOnly) {
|
|
|
|
li.deselect();
|
|
|
|
li.editionController = null;
|
|
|
|
var next = li.next();
|
|
|
|
if (!next) {
|
|
|
|
next = li.previous();
|
|
|
|
}
|
|
|
|
mailAccountsList.removeChild(li);
|
|
|
|
var index = mailAccounts.indexOf(li.mailAccount);
|
|
|
|
mailAccounts.splice(index, 1);
|
|
|
|
next.selectElement();
|
|
|
|
displayMailAccount(next.mailAccount, next.readOnly);
|
2010-08-09 15:25:02 +02:00
|
|
|
|
|
|
|
var hasChanged = $("hasChanged");
|
|
|
|
hasChanged.value = "1";
|
2010-08-06 17:34:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveMailAccounts() {
|
|
|
|
/* This removal enables us to avoid a few warning from SOPE for the inputs
|
|
|
|
that were created dynamically. */
|
|
|
|
var editor = $("mailAccountEditor");
|
|
|
|
editor.parentNode.removeChild(editor);
|
|
|
|
|
|
|
|
compactMailAccounts();
|
|
|
|
var mailAccountsJSON = $("mailAccountsJSON");
|
|
|
|
mailAccountsJSON.value = mailAccounts.toJSON();
|
|
|
|
}
|
|
|
|
|
|
|
|
function compactMailAccounts() {
|
|
|
|
for (var i = 1; i < mailAccounts.length; i++) {
|
|
|
|
var account = mailAccounts[i];
|
|
|
|
var encryption = account["encryption"];
|
|
|
|
if (encryption) {
|
|
|
|
if (encryption == "none") {
|
|
|
|
delete account["encryption"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
encryption = "none";
|
|
|
|
}
|
|
|
|
var port = account["port"];
|
|
|
|
if (port) {
|
|
|
|
if ((encryption == "ssl" && port == 993)
|
|
|
|
|| port == 143) {
|
|
|
|
delete account["port"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* categories */
|
2009-08-06 21:07:25 +02:00
|
|
|
function resetTableActions() {
|
2009-08-04 21:29:38 +02:00
|
|
|
var r = $$("TABLE#categoriesList tbody tr");
|
|
|
|
for (var i = 0; i < r.length; i++) {
|
|
|
|
var row = $(r[i]);
|
|
|
|
row.observe("mousedown", onRowClick);
|
2009-08-06 21:07:25 +02:00
|
|
|
var tds = row.childElements();
|
2010-08-02 22:42:40 +02:00
|
|
|
var editionCtlr = new RowEditionController();
|
|
|
|
editionCtlr.attachToRowElement(tds[0]);
|
|
|
|
tds[1].childElements()[0].observe("dblclick", onColorEdit);
|
2009-08-04 21:29:38 +02:00
|
|
|
}
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onColorEdit (e) {
|
2009-08-04 21:29:38 +02:00
|
|
|
var r = $$("TABLE#categoriesList tbody tr td div.colorEditing");
|
|
|
|
for (var i=0; i<r.length; i++)
|
|
|
|
r[i].removeClassName ("colorEditing");
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
this.addClassName ("colorEditing");
|
2010-08-06 17:34:05 +02:00
|
|
|
var cPicker = window.open(ApplicationBaseURL + "../" + UserLogin
|
2009-08-04 21:29:38 +02:00
|
|
|
+ "/Calendar/colorPicker", "colorPicker",
|
|
|
|
"width=250,height=200,resizable=0,scrollbars=0"
|
|
|
|
+ "toolbar=0,location=0,directories=0,status=0,"
|
|
|
|
+ "menubar=0,copyhistory=0", "test"
|
|
|
|
);
|
|
|
|
cPicker.focus();
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
preventDefault(e);
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onColorPickerChoice (newColor) {
|
2009-08-04 21:29:38 +02:00
|
|
|
var div = $$("TABLE#categoriesList tbody tr td div.colorEditing").first ();
|
|
|
|
// div.removeClassName ("colorEditing");
|
|
|
|
div.showColor = newColor;
|
|
|
|
div.style.background = newColor;
|
2010-08-09 15:25:02 +02:00
|
|
|
if (parseInt($("hasChanged").value) == 0) {
|
|
|
|
var hasChanged = $("hasChanged");
|
|
|
|
hasChanged.value = "1";
|
|
|
|
}
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onCategoryAdd (e) {
|
2009-08-04 21:29:38 +02:00
|
|
|
var row = new Element ("tr");
|
|
|
|
var nametd = new Element ("td").update ("");
|
|
|
|
var colortd = new Element ("td");
|
|
|
|
var colordiv = new Element ("div", {"class": "colorBox"});
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
row.identify ();
|
|
|
|
row.addClassName ("categoryListRow");
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
nametd.addClassName ("categoryListCell");
|
|
|
|
colortd.addClassName ("categoryListCell");
|
|
|
|
colordiv.innerHTML = " ";
|
|
|
|
colordiv.showColor = "#F0F0F0";
|
|
|
|
colordiv.style.background = colordiv.showColor;
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
colortd.appendChild (colordiv);
|
|
|
|
row.appendChild (nametd);
|
|
|
|
row.appendChild (colortd);
|
|
|
|
$("categoriesList").tBodies[0].appendChild (row);
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
resetTableActions ();
|
2010-08-02 22:42:40 +02:00
|
|
|
nametd.editionController.startEditing();
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onCategoryDelete (e) {
|
2009-08-04 21:29:38 +02:00
|
|
|
var list = $('categoriesList').down("TBODY");;
|
|
|
|
var rows = list.getSelectedNodes();
|
|
|
|
var count = rows.length;
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
for (var i=0; i < count; i++) {
|
2010-08-02 22:55:45 +02:00
|
|
|
rows[i].editionController = null;
|
2009-08-04 21:29:38 +02:00
|
|
|
rows[i].remove ();
|
|
|
|
}
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
2010-05-16 19:27:25 +02:00
|
|
|
function serializeCategories() {
|
2009-08-04 21:29:38 +02:00
|
|
|
var r = $$("TABLE#categoriesList tbody tr");
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-12-01 17:53:15 +01:00
|
|
|
var values = [];
|
2009-08-04 21:29:38 +02:00
|
|
|
for (var i = 0; i < r.length; i++) {
|
|
|
|
var tds = r[i].childElements ();
|
|
|
|
var name = $(tds.first ()).innerHTML;
|
|
|
|
var color = $(tds.last ().childElements ().first ()).showColor;
|
2009-12-01 17:53:15 +01:00
|
|
|
values.push("\"" + name + "\": \"" + color + "\"");
|
2009-08-04 21:29:38 +02:00
|
|
|
}
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-12-01 17:53:15 +01:00
|
|
|
$("categoriesValue").value = "{ " + values.join(",\n") + "}";
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function resetCategoriesColors (e) {
|
2009-08-06 21:07:25 +02:00
|
|
|
var divs = $$("TABLE#categoriesList DIV.colorBox");
|
2009-08-04 21:29:38 +02:00
|
|
|
|
|
|
|
for (var i = 0; i < divs.length; i++) {
|
2009-08-06 21:07:25 +02:00
|
|
|
var d = divs[i];
|
2009-08-04 21:29:38 +02:00
|
|
|
var color = d.innerHTML;
|
|
|
|
d.showColor = color;
|
2009-08-06 21:07:25 +02:00
|
|
|
if (color != "undefined")
|
|
|
|
d.setStyle({ backgroundColor: color });
|
|
|
|
d.update(" ");
|
2009-08-04 21:29:38 +02:00
|
|
|
}
|
2008-09-28 21:49:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onReplyPlacementListChange() {
|
2009-08-04 21:29:38 +02:00
|
|
|
// above = 0
|
|
|
|
if ($("replyPlacementList").value == 0) {
|
|
|
|
$("signaturePlacementList").disabled=false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("signaturePlacementList").value=1;
|
|
|
|
$("signaturePlacementList").disabled=true;
|
|
|
|
}
|
2008-07-25 20:44:31 +02:00
|
|
|
}
|
|
|
|
|
2009-08-06 21:07:25 +02:00
|
|
|
function onComposeMessagesTypeChange(event) {
|
2010-03-08 17:40:18 +01:00
|
|
|
// var textArea = $('signature');
|
|
|
|
|
2010-08-06 17:34:05 +02:00
|
|
|
if (this.value == 0) /* text */ {
|
2010-03-08 17:40:18 +01:00
|
|
|
if (CKEDITOR.instances["signature"]) {
|
|
|
|
var content = CKEDITOR.instances["signature"].getData();
|
|
|
|
var htmlEditorWidget = $('cke_signature');
|
|
|
|
htmlEditorWidget.parentNode.removeChild(htmlEditorWidget);
|
|
|
|
delete CKEDITOR.instances["signature"];
|
|
|
|
var textArea = $("signature");
|
|
|
|
textArea.value = content;
|
|
|
|
textArea.style.display = "";
|
|
|
|
textArea.style.visibility = "";
|
|
|
|
}
|
|
|
|
} else {
|
2010-08-06 17:34:05 +02:00
|
|
|
if ($("signature") && !CKEDITOR.instances["signature"]) {
|
2010-03-08 17:40:18 +01:00
|
|
|
CKEDITOR.replace('signature',
|
|
|
|
{
|
2010-08-06 17:34:05 +02:00
|
|
|
height: "70px",
|
|
|
|
toolbar: [['Bold', 'Italic', '-', 'Link',
|
|
|
|
'Font','FontSize','-','TextColor',
|
|
|
|
'BGColor']
|
|
|
|
],
|
|
|
|
language: localeCode,
|
|
|
|
scayt_sLang: localeCode
|
2010-06-30 20:37:12 +02:00
|
|
|
}
|
|
|
|
);
|
2009-08-04 21:29:38 +02:00
|
|
|
}
|
2009-07-02 17:40:45 +02:00
|
|
|
}
|
2009-06-23 19:53:18 +02:00
|
|
|
}
|
|
|
|
|
2010-03-08 16:18:05 +01:00
|
|
|
function onChangePasswordClick(event) {
|
|
|
|
var field = $("newPasswordField");
|
|
|
|
var confirmationField = $("newPasswordConfirmationField");
|
|
|
|
if (field && confirmationField) {
|
|
|
|
var password = field.value;
|
|
|
|
if (password == confirmationField.value) {
|
2010-03-08 21:52:37 +01:00
|
|
|
if (password.length > 0) {
|
|
|
|
var loginValues = readLoginCookie();
|
|
|
|
var policy = new PasswordPolicy(loginValues[0],
|
|
|
|
loginValues[1]);
|
|
|
|
policy.setCallbacks(onPasswordChangeSuccess,
|
|
|
|
onPasswordChangeFailure);
|
|
|
|
policy.changePassword(password);
|
|
|
|
}
|
2010-03-08 16:18:05 +01:00
|
|
|
else
|
2010-03-08 21:52:37 +01:00
|
|
|
SetLogMessage("passwordError", _("Password must not be empty."),
|
2010-03-08 16:18:05 +01:00
|
|
|
"error");
|
|
|
|
}
|
|
|
|
else {
|
2010-03-08 21:52:37 +01:00
|
|
|
SetLogMessage("passwordError", _("The passwords do not match."
|
2010-03-08 16:18:05 +01:00
|
|
|
+ " Please try again."),
|
|
|
|
"error");
|
|
|
|
field.focus();
|
|
|
|
field.select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
2010-03-08 21:52:37 +01:00
|
|
|
function onPasswordChangeSuccess(message) {
|
|
|
|
SetLogMessage("passwordError", message, "info");
|
2010-03-08 16:18:05 +01:00
|
|
|
}
|
|
|
|
|
2010-03-08 21:52:37 +01:00
|
|
|
function onPasswordChangeFailure(code, message) {
|
|
|
|
SetLogMessage("passwordError", message, "error");
|
2010-03-08 16:18:05 +01:00
|
|
|
}
|
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initPreferences);
|