Added support for dynamic mail labels/tags management.

The CSS in the UIxPreferences remains to be done.
This commit is contained in:
Ludovic Marcotte
2013-11-11 10:49:58 -05:00
parent 6a9bcfda68
commit 37d3234b60
24 changed files with 625 additions and 230 deletions
+4 -18
View File
@@ -1,14 +1,15 @@
/*
Copyright (C) 2005-2013 Inverse inc.
Copyright (C) 2005 SKYRIX Software AG
This file is part of OpenGroupware.org.
This file is part of SOGo.
OGo is free software; you can redistribute it and/or modify it under
SOGo is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
@@ -93,21 +94,6 @@ DIV#folderTreeContent
right: 0px;
overflow: auto; }
#label-menu LI.label1
{ color: #f00; }
#label-menu LI.label2
{ color: #ff9a00; }
#label-menu LI.label3
{ color: #009a00; }
#label-menu LI.label4
{ color: #3130ff; }
#label-menu LI.label5
{ color: #9c309c; }
.aptview_title
{
color: #000000;
+43 -45
View File
@@ -2488,9 +2488,11 @@ function onMenuLabelNone() {
});
}
function _onMenuLabelFlagX(flag) {
function onMenuLabelFlag() {
var messages = new Hash();
var flag = this.readAttribute("data-name");
if (document.menuTarget.tagName == "DIV")
// Menu called from message content view
messages.set(Mailer.currentMessages[Mailer.currentMailbox],
@@ -2502,45 +2504,25 @@ function _onMenuLabelFlagX(flag) {
if (row)
messages.set(rowID.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"));
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/";
messages.keys().each(function(id) {
var flags = messages.get(id).split(" ");
var operation = "add";
if (flags.indexOf("label" + flag) > -1)
operation = "remove";
triggerAjaxRequest(url + id + "/" + operation + "Label" + flag,
messageFlagCallback,
{ mailbox: Mailer.currentMailbox, msg: id,
label: operation + flag } );
});
}
function onMenuLabelFlag1() {
_onMenuLabelFlagX(1);
}
function onMenuLabelFlag2() {
_onMenuLabelFlagX(2);
}
function onMenuLabelFlag3() {
_onMenuLabelFlagX(3);
}
function onMenuLabelFlag4() {
_onMenuLabelFlagX(4);
}
function onMenuLabelFlag5() {
_onMenuLabelFlagX(5);
var flags = messages.get(id).split(" ");
var operation = "add";
if (flags.indexOf(flag) > -1)
operation = "remove";
triggerAjaxRequest(url + id + "/" + operation + "Label?flag=" + flag.asCSSIdentifier(),
messageFlagCallback,
{ mailbox: Mailer.currentMailbox, msg: id,
label: operation + flag } );
});
}
function onMenuToggleMessageFlag(event) {
@@ -2707,14 +2689,33 @@ function onLabelMenuPrepareVisibility() {
var lis = this.childNodesWithTag("ul")[0].childNodesWithTag("li");
var isFlagged = false;
for (var i = 1; i < 6; i++) {
if (flags["label" + i]) {
isFlagged = true;
lis[1 + i].addClassName("_chosen");
// lis is our array of labels, ex:
// li
// li.seperator
// li.label1
// li.broccoli
// ...
for (var i = 2; i < lis.length; i++) {
// We bind the event handlers if we need to
if (lis[i].menuCallback == null) {
lis[i].menuCallback = onMenuLabelFlag;
lis[i].on("mousedown", onMenuClickHandler);
lis[i].removeClassName("disabled");
}
var flag = lis[i].readAttribute("data-name");
if (flags[flag]) {
isFlagged = true;
lis[i].addClassName("_chosen");
}
else {
lis[i].removeClassName("_chosen");
}
else
lis[1 + i].removeClassName("_chosen");
}
if (isFlagged)
lis[0].removeClassName("_chosen");
else
@@ -2834,12 +2835,9 @@ function getMenus() {
onMenuChangeToDraftsFolder,
onMenuChangeToTrashFolder ],
"label-menu": [ onMenuLabelNone, "-", onMenuLabelFlag1,
onMenuLabelFlag2, onMenuLabelFlag3,
onMenuLabelFlag4, onMenuLabelFlag5 ],
"label-menu": [ onMenuLabelNone, "-" ],
"mark-menu": [ onMenuToggleMessageRead, null, null, null, "-", onMenuToggleMessageFlag ],
// , "-",
// null, null, null ],
searchMenu: [ setSearchCriteria, setSearchCriteria,
setSearchCriteria, setSearchCriteria,
+3 -1
View File
@@ -1,11 +1,13 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
var type;
function onLoadColorPicker(event) {
showColorPicker();
}
function onChooseColor(newColor) {
window.opener.onColorPickerChoice(newColor);
window.opener.onColorPickerChoice(newColor, type);
window.close();
}
+4 -3
View File
@@ -90,9 +90,10 @@ function setupConstants() {
"flagged": _("Flagged"),
"junk": _("Junk"),
"not_junk": _("Not Junk") };
for (var i = 1; i < 6; i++) {
var key = "label" + i;
flagLabels[key] = _("Label " + i);
for (var name in labels) {
flagLabels[name] = _( labels[name][0] );
}
}
+147 -16
View File
@@ -17,6 +17,10 @@ function savePreferences(sender) {
serializeContactsCategories();
}
if ($("mailLabelsListWrapper")) {
serializeMailLabels();
}
if (typeof mailCustomFromEnabled !== "undefined" && !emailRE.test($("email").value)) {
showAlertDialog(_("Please specify a valid sender address."));
sendForm = false;
@@ -182,6 +186,7 @@ function initPreferences() {
if (typeof (initAdditionalPreferences) != "undefined")
initAdditionalPreferences();
// Calender categories
var wrapper = $("calendarCategoriesListWrapper");
if (wrapper) {
var table = wrapper.childNodesWithTag("table")[0];
@@ -195,6 +200,22 @@ function initPreferences() {
$("calendarCategoryDelete").observe("click", onCalendarCategoryDelete);
}
// Mail labels/tags
var wrapper = $("mailLabelsListWrapper");
if (wrapper) {
var table = wrapper.childNodesWithTag("table")[0];
resetMailLabelsColors(null);
var r = $$("#mailLabelsListWrapper tbody tr");
for (var i= 0; i < r.length; i++)
r[i].identify();
table.multiselect = true;
resetMailTableActions();
$("mailLabelAdd").observe("click", onMailLabelAdd);
$("mailLabelDelete").observe("click", onMailLabelDelete);
}
// Contact categories
wrapper = $("contactsCategoriesListWrapper");
if (wrapper) {
var table = wrapper.childNodesWithTag("table")[0];
@@ -855,21 +876,15 @@ function compactMailAccounts() {
}
}
/* calendar categories */
function resetCalendarTableActions() {
var r = $$("#calendarCategoriesListWrapper tbody tr");
for (var i = 0; i < r.length; i++) {
var row = $(r[i]);
row.observe("mousedown", onRowClick);
var tds = row.childElements();
var editionCtlr = new RowEditionController();
editionCtlr.attachToRowElement(tds[0]);
tds[1].childElements()[0].observe("dblclick", onColorEdit);
}
}
/* common function between calendar categories and mail labels */
function onColorEdit (e, type) {
var r;
function onColorEdit (e) {
var r = $$("#calendarCategoriesListWrapper div.colorEditing");
if (type == "calendar")
r = $$("#calendarCategoriesListWrapper div.colorEditing");
else
r = $$("#mailLabelsListWrapper div.colorEditing");
for (var i=0; i<r.length; i++)
r[i].removeClassName("colorEditing");
@@ -881,12 +896,19 @@ function onColorEdit (e) {
+ "menubar=0,copyhistory=0", "test"
);
cPicker.focus();
cPicker.type = type;
preventDefault(e);
}
function onColorPickerChoice (newColor) {
var div = $$("#calendarCategoriesListWrapper div.colorEditing").first ();
function onColorPickerChoice (newColor, type) {
var div;
if (type == "calendar")
div = $$("#calendarCategoriesListWrapper div.colorEditing").first ();
else
div = $$("#mailLabelsListWrapper div.colorEditing").first ();
// div.removeClassName ("colorEditing");
div.showColor = newColor;
div.style.background = newColor;
@@ -895,6 +917,26 @@ function onColorPickerChoice (newColor) {
hasChanged.value = "1";
}
}
/* /common function between calendar categories and mail labels */
/* calendar categories */
function resetCalendarTableActions() {
var r = $$("#calendarCategoriesListWrapper tbody tr");
for (var i = 0; i < r.length; i++) {
var row = $(r[i]);
row.observe("mousedown", onRowClick);
var tds = row.childElements();
var editionCtlr = new RowEditionController();
editionCtlr.attachToRowElement(tds[0]);
tds[1].childElements()[0].observe("dblclick", onCalendarColorEdit);
}
}
function onCalendarColorEdit (e) {
var onCCE = onColorEdit.bind(this);
onCCE(e, "calendar");
}
function onCalendarCategoryAdd (e) {
var row = new Element ("tr");
@@ -959,6 +1001,95 @@ function resetCalendarCategoriesColors (e) {
/* /calendar categories */
/* mail label/tags */
function resetMailTableActions() {
var r = $$("#mailLabelsListWrapper tbody tr");
for (var i = 0; i < r.length; i++) {
var row = $(r[i]);
row.observe("mousedown", onRowClick);
var tds = row.childElements();
var editionCtlr = new RowEditionController();
editionCtlr.attachToRowElement(tds[0]);
tds[1].childElements()[0].observe("dblclick", onMailColorEdit);
}
}
function onMailColorEdit (e) {
var onMCE = onColorEdit.bind(this);
onMCE(e, "mail");
}
function onMailLabelAdd (e) {
var row = new Element ("tr");
var nametd = new Element ("td").update ("");
var colortd = new Element ("td");
var colordiv = new Element ("div", {"class": "colorBox"});
row.identify ();
row.addClassName ("labelListRow");
nametd.addClassName ("labelListCell");
colortd.addClassName ("labelListCell");
colordiv.innerHTML = "&nbsp;";
colordiv.showColor = "#F0F0F0";
colordiv.style.background = colordiv.showColor;
colortd.appendChild (colordiv);
row.appendChild (nametd);
row.appendChild (colortd);
$("mailLabelsListWrapper").childNodesWithTag("table")[0].tBodies[0].appendChild (row);
resetMailTableActions ();
nametd.editionController.startEditing();
}
function onMailLabelDelete (e) {
var list = $('mailLabelsListWrapper').down("TABLE").down("TBODY");
var rows = list.getSelectedNodes();
var count = rows.length;
for (var i=0; i < count; i++) {
rows[i].editionController = null;
rows[i].remove ();
}
}
function resetMailLabelsColors (e) {
var divs = $$("#mailLabelsListWrapper DIV.colorBox");
for (var i = 0; i < divs.length; i++) {
var d = divs[i];
var color = d.innerHTML;
d.showColor = color;
if (color != "undefined")
d.setStyle({ backgroundColor: color });
d.update("&nbsp;");
}
}
function serializeMailLabels() {
var r = $$("#mailLabelsListWrapper TBODY TR");
var values = [];
for (var i = 0; i < r.length; i++) {
var tds = r[i].childElements ();
var name = r[i].readAttribute("data-name");
var label = $(tds.first ()).innerHTML;
var color = $(tds.last ().childElements ().first ()).showColor;
/* if name is null, that's because we've just added a new tag */
if (!name) {
name = label.replace(/ /g,"_");
}
values.push("\"" + name + "\": [\"" + label + "\", \"" + color + "\"]");
}
$("mailLabelsValue").value = "{ " + values.join(",\n") + "}";
}
/* /mail label/tags */
/* contacts categories */
function resetContactsTableActions() {
var r = $$("#contactsCategoriesListWrapper tbody tr");