2009-10-26 19:30:06 +01:00
|
|
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2009-08-24 22:47:23 +02:00
|
|
|
function validateListEditor () {
|
2009-10-28 18:48:22 +01:00
|
|
|
return serializeReferences();
|
2009-08-24 22:47:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function makeEditable (element) {
|
2009-10-28 18:48:22 +01:00
|
|
|
element.addClassName("editing");
|
|
|
|
element.removeClassName("referenceListCell");
|
|
|
|
|
|
|
|
var span = element.down("SPAN");
|
|
|
|
span.update();
|
2009-08-24 22:47:23 +02:00
|
|
|
|
2009-10-28 18:48:22 +01:00
|
|
|
var textField = element.down("INPUT");
|
|
|
|
textField.show();
|
|
|
|
textField.focus();
|
|
|
|
textField.select();
|
2009-10-26 19:30:06 +01:00
|
|
|
|
2009-10-28 18:48:22 +01:00
|
|
|
return true;
|
|
|
|
}
|
2009-10-17 19:54:14 +02:00
|
|
|
|
2009-10-28 18:48:22 +01:00
|
|
|
function endEditable(event, textField) {
|
|
|
|
if (!textField)
|
|
|
|
textField = this;
|
|
|
|
|
|
|
|
var uid = textField.readAttribute("uid");
|
|
|
|
var cell = textField.up("TD");
|
|
|
|
var textSpan = cell.down("SPAN");
|
|
|
|
|
|
|
|
cell.removeClassName("editing");
|
|
|
|
cell.addClassName("referenceListCell");
|
|
|
|
textField.hide();
|
2009-08-24 22:47:23 +02:00
|
|
|
|
2009-10-28 18:48:22 +01:00
|
|
|
if (uid) {
|
|
|
|
var tmp = textField.value;
|
2009-08-24 22:47:23 +02:00
|
|
|
tmp = tmp.replace (/</, "<");
|
|
|
|
tmp = tmp.replace (/>/, ">");
|
2009-10-28 18:48:22 +01:00
|
|
|
textSpan.update(tmp);
|
2009-08-24 22:47:23 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-10-28 18:48:22 +01:00
|
|
|
cell.up("TR").remove();
|
2009-08-24 22:47:23 +02:00
|
|
|
}
|
2009-10-28 18:48:22 +01:00
|
|
|
|
|
|
|
if (event)
|
|
|
|
Event.stop(event);
|
|
|
|
|
|
|
|
return false;
|
2009-08-24 22:47:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function endAllEditables (e) {
|
2009-10-28 18:48:22 +01:00
|
|
|
var r = $$("TABLE#referenceList TBODY TR TD");
|
|
|
|
for (var i = 0; i < r.length; i++) {
|
|
|
|
var element = $(r[i]);
|
|
|
|
if (r[i] != this && element.hasClassName("editing"))
|
|
|
|
endEditable(null, element.down("INPUT"));
|
2009-08-24 22:47:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onNameEdit (e) {
|
2009-10-28 18:48:22 +01:00
|
|
|
endAllEditables();
|
|
|
|
if (!this.hasClassName("editing")) {
|
2009-08-24 22:47:23 +02:00
|
|
|
makeEditable (this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onReferenceAdd (e) {
|
2009-10-28 18:48:22 +01:00
|
|
|
var tablebody = $("referenceList").tBodies[0];
|
|
|
|
var row = new Element("tr");
|
|
|
|
var td = new Element("td");
|
|
|
|
var textField = new Element("input");
|
|
|
|
var span = new Element("span");
|
2009-08-24 22:47:23 +02:00
|
|
|
|
|
|
|
row.addClassName ("referenceListRow");
|
2009-10-28 18:48:22 +01:00
|
|
|
row.observe("mousedown", onRowClick);
|
|
|
|
td.addClassName ("referenceListCell");
|
|
|
|
td.observe("mousedown", endAllEditables);
|
|
|
|
td.observe("dblclick", onNameEdit);
|
|
|
|
textField.addInterface(SOGoAutoCompletionInterface);
|
|
|
|
textField.addressBook = activeAddressBook;
|
|
|
|
textField.excludeLists = true;
|
|
|
|
textField.observe("autocompletion:changed", endEditable);
|
|
|
|
|
|
|
|
td.appendChild(textField);
|
|
|
|
td.appendChild(span);
|
|
|
|
row.appendChild (td);
|
|
|
|
tablebody.appendChild(row);
|
|
|
|
tablebody.deselectAll();
|
|
|
|
row.selectElement();
|
|
|
|
|
|
|
|
makeEditable(td);
|
2009-08-24 22:47:23 +02:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:48:22 +01:00
|
|
|
function onReferenceDelete(e) {
|
2009-08-24 22:47:23 +02:00
|
|
|
var list = $('referenceList').down("TBODY");;
|
|
|
|
var rows = list.getSelectedNodes();
|
|
|
|
var count = rows.length;
|
|
|
|
|
2009-10-28 18:48:22 +01:00
|
|
|
for (var i = 0; i < count; i++) {
|
|
|
|
rows[i].remove();
|
2009-08-24 22:47:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-28 18:48:22 +01:00
|
|
|
function serializeReferences(e) {
|
|
|
|
var r = $$("TABLE#referenceList TBODY TR INPUT");
|
|
|
|
var cards = new Array();
|
2009-08-24 22:47:23 +02:00
|
|
|
for (var i = 0; i < r.length; i++) {
|
2009-10-28 18:48:22 +01:00
|
|
|
var uid = $(r[i]).readAttribute("uid");
|
|
|
|
if (uid)
|
|
|
|
cards.push(uid);
|
2009-08-24 22:47:23 +02:00
|
|
|
}
|
2009-10-28 18:48:22 +01:00
|
|
|
$("referencesValue").value = cards.join(",");
|
|
|
|
return true;
|
2009-08-24 22:47:23 +02:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:48:22 +01:00
|
|
|
function resetTableActions() {
|
|
|
|
var r = $$("TABLE#referenceList TBODY TR");
|
2009-08-24 22:47:23 +02:00
|
|
|
for (var i = 0; i < r.length; i++) {
|
|
|
|
var row = $(r[i]);
|
|
|
|
row.observe("mousedown", onRowClick);
|
2009-10-28 18:48:22 +01:00
|
|
|
var td = row.down("TD");
|
2009-08-24 22:47:23 +02:00
|
|
|
td.observe("mousedown", endAllEditables);
|
|
|
|
td.observe("dblclick", onNameEdit);
|
2009-10-28 18:48:22 +01:00
|
|
|
var textField = td.down("INPUT");
|
|
|
|
textField.addInterface(SOGoAutoCompletionInterface);
|
|
|
|
textField.addressBook = activeAddressBook;
|
|
|
|
textField.excludeLists = true;
|
|
|
|
textField.confirmedValue = textField.value;
|
|
|
|
textField.observe("autocompletion:changed", endEditable);
|
2009-08-24 22:47:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEditorCancelClick(event) {
|
2009-10-28 18:48:22 +01:00
|
|
|
preventDefault(event);
|
|
|
|
window.close();
|
2009-08-24 22:47:23 +02:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:48:22 +01:00
|
|
|
function initListEditor() {
|
2009-08-24 22:47:23 +02:00
|
|
|
var table = $("referenceList");
|
|
|
|
table.multiselect = true;
|
2009-10-28 18:48:22 +01:00
|
|
|
resetTableActions();
|
|
|
|
$("referenceAdd").observe("click", onReferenceAdd);
|
|
|
|
$("referenceDelete").observe("click", onReferenceDelete);
|
2009-08-24 22:47:23 +02:00
|
|
|
$("cancelButton").observe("click", onEditorCancelClick);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.observe("dom:loaded", initListEditor);
|