2009-07-19 18:41:42 +02:00
|
|
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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")) {
|
|
|
|
serializeCategories(null);
|
|
|
|
}
|
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) {
|
|
|
|
alert (getLabel ("Day start time must be prior to day end time."));
|
|
|
|
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) {
|
|
|
|
alert(getLabel("Please specify your message and your email addresses for which you want to enable auto reply."));
|
|
|
|
sendForm = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($("enableForward") && $("enableForward").checked) {
|
|
|
|
if ($("forwardAddress").value.strip().length == 0) {
|
|
|
|
alert(getLabel("Please specify an address to which you want to forward your messages."));
|
|
|
|
sendForm = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 22:54:09 +02:00
|
|
|
if (sendForm)
|
|
|
|
$("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
|
|
|
|
|
|
|
function _setupEvents(enable) {
|
2009-08-04 21:29:38 +02:00
|
|
|
var widgets = [ "timezone", "shortDateFormat", "longDateFormat",
|
|
|
|
"timeFormat", "weekStartDay", "dayStartTime", "dayEndTime",
|
2009-10-01 23:41:54 +02:00
|
|
|
"firstWeek", "messageCheck", "subscribedFoldersOnly",
|
|
|
|
"language"];
|
2009-08-04 21:29:38 +02:00
|
|
|
for (var i = 0; i < widgets.length; i++) {
|
|
|
|
var widget = $(widgets[i]);
|
|
|
|
if (widget) {
|
|
|
|
if (enable)
|
|
|
|
widget.observe("change", onChoiceChanged);
|
|
|
|
else
|
|
|
|
widget.stopObserving("change", onChoiceChanged);
|
|
|
|
}
|
2008-08-25 19:53:27 +02:00
|
|
|
}
|
2009-07-02 17:40:45 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
$("replyPlacementList").observe ("change", onReplyPlacementListChange);
|
|
|
|
$("composeMessagesType").observe ("change", onComposeMessagesTypeChange);
|
2009-08-06 21:07:25 +02:00
|
|
|
$("categoriesValue").value = "";
|
2008-07-25 20:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onChoiceChanged(event) {
|
2009-08-04 21:29:38 +02:00
|
|
|
var hasChanged = $("hasChanged");
|
|
|
|
hasChanged.value = "1";
|
2008-07-25 20:44:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
_setupEvents(false);
|
2008-07-25 20:44:31 +02:00
|
|
|
}
|
|
|
|
|
2009-10-15 00:11:13 +02:00
|
|
|
function addDefaultEmailAddresses() {
|
|
|
|
var defaultAddresses = $("defaultEmailAddresses").value.split(/, */);
|
|
|
|
var addresses = $("autoReplyEmailAddresses").value.split(/, */);
|
|
|
|
|
|
|
|
defaultAddresses.each(function(adr) {
|
|
|
|
for (var i = 0; i < addresses.length; i++)
|
|
|
|
if (adr == addresses[i])
|
|
|
|
break;
|
|
|
|
if (i == addresses.length)
|
|
|
|
addresses.push(adr);
|
|
|
|
});
|
|
|
|
|
|
|
|
$("autoReplyEmailAddresses").value = addresses.join(", ");
|
|
|
|
}
|
|
|
|
|
2008-07-25 20:44:31 +02:00
|
|
|
function initPreferences() {
|
2009-08-04 21:29:38 +02:00
|
|
|
_setupEvents(true);
|
|
|
|
if (typeof (initAdditionalPreferences) != "undefined")
|
|
|
|
initAdditionalPreferences();
|
|
|
|
|
|
|
|
if ($("signature")) {
|
2009-10-15 00:11:13 +02:00
|
|
|
onComposeMessagesTypeChange();
|
2009-08-04 21:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if ($("addDefaultEmailAddresses"))
|
|
|
|
$("addDefaultEmailAddresses").observe("click", addDefaultEmailAddresses);
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
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();
|
2009-08-04 21:29:38 +02:00
|
|
|
tds[0].observe("mousedown", endAllEditables);
|
2009-08-06 21:07:25 +02:00
|
|
|
tds[0].observe("dblclick", onNameEdit);
|
2009-08-04 21:29:38 +02:00
|
|
|
tds[1].observe("mousedown", endAllEditables);
|
2009-08-06 21:07:25 +02:00
|
|
|
tds[1].childElements()[0].observe ("dblclick", onColorEdit);
|
2009-08-04 21:29:38 +02:00
|
|
|
}
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function makeEditable (element) {
|
2009-08-04 21:29:38 +02:00
|
|
|
element.addClassName ("editing");
|
|
|
|
element.removeClassName ("categoryListCell");
|
|
|
|
var tmp = element.innerHTML;
|
|
|
|
element.innerHTML = "";
|
|
|
|
var textField = new Element ("input", {"type": "text",
|
|
|
|
"width": "100%"});
|
|
|
|
textField.value = tmp;
|
|
|
|
textField.observe ("keydown", interceptEnter);
|
|
|
|
element.appendChild (textField);
|
|
|
|
textField.focus ();
|
|
|
|
textField.select ();
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function interceptEnter (e) {
|
2009-08-04 21:29:38 +02:00
|
|
|
if (e.keyCode == Event.KEY_RETURN) {
|
|
|
|
endAllEditables (null);
|
|
|
|
preventDefault (e);
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function endEditable (element) {
|
2009-08-04 21:29:38 +02:00
|
|
|
var tmp = element.childElements ().first ().value;
|
|
|
|
element.innerHTML = tmp;
|
|
|
|
element.removeClassName ("editing");
|
|
|
|
element.addClassName ("categoryListCell");
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function endAllEditables (e) {
|
2009-08-04 21:29:38 +02:00
|
|
|
var r = $$("TABLE#categoriesList tbody tr td");
|
|
|
|
for (var i=0; i<r.length; i++) {
|
|
|
|
if (r[i] != this && r[i].hasClassName ("editing"))
|
|
|
|
endEditable ($(r[i]));
|
|
|
|
}
|
2009-07-16 17:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onNameEdit (e) {
|
2009-08-04 21:29:38 +02:00
|
|
|
endAllEditables ();
|
|
|
|
if (!this.hasClassName ("editing")) {
|
|
|
|
makeEditable (this);
|
|
|
|
}
|
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");
|
|
|
|
var cPicker = window.open(ApplicationBaseURL + "../" + UserLogin
|
|
|
|
+ "/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;
|
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");
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
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);
|
|
|
|
makeEditable (nametd);
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
resetTableActions ();
|
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++) {
|
|
|
|
rows[i].remove ();
|
|
|
|
}
|
2009-07-16 17:57:31 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function serializeCategories (e) {
|
2009-08-04 21:29:38 +02:00
|
|
|
var r = $$("TABLE#categoriesList tbody tr");
|
|
|
|
var names = "(";
|
|
|
|
var colors = "(";
|
2009-07-16 17:57:31 +02:00
|
|
|
|
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-07-16 17:57:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
names += "\"" + name + "\", ";
|
|
|
|
colors += "\"" + color + "\", ";
|
|
|
|
}
|
|
|
|
names = names.substr (0, names.length - 1) + ")";
|
|
|
|
colors = colors.substr (0, colors.length - 1) + ")";
|
2009-07-16 17:57:31 +02:00
|
|
|
|
2009-08-04 21:29:38 +02:00
|
|
|
$("categoriesValue").value = "(" + names + ", " + colors + ")";
|
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) {
|
2009-08-04 21:29:38 +02:00
|
|
|
var textArea = $('signature');
|
2009-08-06 21:07:25 +02:00
|
|
|
|
|
|
|
if (event) {
|
|
|
|
// Due to a limitation of CKEDITOR, we reload the page when the user
|
2009-08-26 17:08:56 +02:00
|
|
|
// changes the composition mode to avoid Javascript errors.
|
2009-09-16 22:25:47 +02:00
|
|
|
var saveAndReload = confirm(getLabel("composeMessageChanged"));
|
2009-08-06 21:07:25 +02:00
|
|
|
if (saveAndReload)
|
|
|
|
return savePreferences();
|
|
|
|
else {
|
|
|
|
// Restore previous value of composeMessagesType
|
|
|
|
$("composeMessagesType").stopObserving("change", onComposeMessagesTypeChange);
|
|
|
|
$("composeMessagesType").value = ((Event.element(event).value == 1)?"0":"1");
|
|
|
|
Event.element(event).blur();
|
|
|
|
$("composeMessagesType").observe("change", onComposeMessagesTypeChange);
|
|
|
|
return false;
|
2009-08-04 21:29:38 +02:00
|
|
|
}
|
|
|
|
}
|
2009-08-06 21:07:25 +02:00
|
|
|
|
|
|
|
if ($("composeMessagesType").value == 1) {
|
|
|
|
// HTML mode
|
2009-08-04 21:29:38 +02:00
|
|
|
CKEDITOR.replace('signature',
|
|
|
|
{
|
2009-08-26 17:08:56 +02:00
|
|
|
height: "290px",
|
|
|
|
toolbar :
|
2009-08-04 21:29:38 +02:00
|
|
|
[['Bold', 'Italic', '-', 'Link',
|
|
|
|
'Font','FontSize','-','TextColor',
|
|
|
|
'BGColor']
|
|
|
|
]
|
2009-08-06 21:07:25 +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
|
|
|
}
|
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initPreferences);
|