2010-10-26 21:23:08 +02:00
|
|
|
/* -*- Mode: js2-mode; tab-width: 4; c-label-minimum-indentation: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-08-28 16:48:45 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/*
|
2008-08-28 16:48:45 +02:00
|
|
|
Copyright (C) 2005 SKYRIX Software AG
|
2011-04-14 23:26:35 +02:00
|
|
|
Copyright (C) 2006-2011 Inverse
|
2010-10-26 21:23:08 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
This file is part of OpenGroupware.org.
|
2010-10-26 21:23:08 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
OGo 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.
|
2010-10-26 21:23:08 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
OGo 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.
|
2010-10-26 21:23:08 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
2006-06-15 21:34:10 +02:00
|
|
|
*/
|
|
|
|
|
2010-07-05 20:50:00 +02:00
|
|
|
var dateRegex = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
|
2006-10-04 00:06:00 +02:00
|
|
|
|
2006-09-26 20:44:42 +02:00
|
|
|
var displayNameChanged = false;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-10-26 21:23:08 +02:00
|
|
|
var tabIndex = 0;
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
function unescapeCallbackParameter(s) {
|
2010-04-13 16:19:58 +02:00
|
|
|
if(!s || s.length == 0)
|
|
|
|
return s;
|
|
|
|
s = s.replace(/'/g, "'");
|
|
|
|
s = s.replace(/"/g, '"');
|
2006-06-15 21:34:10 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyContact(type, email, uid, sn,
|
|
|
|
cn, givenName, telephoneNumber, facsimileTelephoneNumber,
|
2010-10-26 21:23:08 +02:00
|
|
|
mobile, postalAddress, homePostalAddress,
|
2008-08-28 16:48:45 +02:00
|
|
|
departmentNumber, l)
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
2010-10-26 21:23:08 +02:00
|
|
|
// var type = arguments[0];
|
|
|
|
// var email = arguments[1];
|
|
|
|
// var uid = arguments[2];
|
|
|
|
// var sn = arguments[3];
|
|
|
|
// var givenName = arguments[4];
|
|
|
|
// var telephoneNumber = arguments[5];
|
|
|
|
// var facsimileTelephoneNumber = arguments[6];
|
|
|
|
// var mobile = arguments[7];
|
|
|
|
// var postalAddress = arguments[8];
|
|
|
|
// var homePostalAddress = arguments[9];
|
|
|
|
// var departmentNumber = arguments[10];
|
|
|
|
// var l = arguments[11];
|
2010-04-13 16:19:58 +02:00
|
|
|
var e;
|
|
|
|
e = $('cn');
|
|
|
|
e.setAttribute('value', unescapeCallbackParameter(cn));
|
|
|
|
e = $('email');
|
|
|
|
e.setAttribute('value', email);
|
|
|
|
e = $('sn');
|
|
|
|
e.setAttribute('value', unescapeCallbackParameter(sn));
|
|
|
|
e = $('givenName');
|
|
|
|
e.setAttribute('value', unescapeCallbackParameter(givenName));
|
|
|
|
e = $('telephoneNumber');
|
|
|
|
e.setAttribute('value', telephoneNumber);
|
|
|
|
e = $('facsimileTelephoneNumber');
|
|
|
|
e.setAttribute('value', facsimileTelephoneNumber);
|
|
|
|
e = $('mobile');
|
|
|
|
e.setAttribute('value', mobile);
|
|
|
|
e = $('postalAddress');
|
|
|
|
e.setAttribute('value', unescapeCallbackParameter(postalAddress));
|
|
|
|
e = $('homePostalAddress');
|
|
|
|
e.setAttribute('value', unescapeCallbackParameter(homePostalAddress));
|
|
|
|
e = $('departmentNumber');
|
|
|
|
e.setAttribute('value', unescapeCallbackParameter(departmentNumber));
|
|
|
|
e = $('l');
|
|
|
|
e.setAttribute('value', unescapeCallbackParameter(l));
|
2006-06-15 21:34:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function validateContactEditor() {
|
2010-04-13 16:19:58 +02:00
|
|
|
var rc = true;
|
2010-10-26 21:23:08 +02:00
|
|
|
|
2010-04-13 16:19:58 +02:00
|
|
|
var e = $('workMail');
|
|
|
|
if (e.value.length > 0
|
2011-04-14 23:26:35 +02:00
|
|
|
&& !emailRE.test(e.value)) {
|
2010-06-02 21:11:15 +02:00
|
|
|
alert(_("invalidemailwarn"));
|
2010-04-13 16:19:58 +02:00
|
|
|
rc = false;
|
2009-09-22 22:36:28 +02:00
|
|
|
}
|
2006-09-19 15:51:03 +02:00
|
|
|
|
2010-04-13 16:19:58 +02:00
|
|
|
e = $('homeMail');
|
|
|
|
if (e.value.length > 0
|
2011-04-14 23:26:35 +02:00
|
|
|
&& !emailRE.test(e.value)) {
|
2010-06-02 21:11:15 +02:00
|
|
|
alert(_("invalidemailwarn"));
|
2010-04-13 16:19:58 +02:00
|
|
|
rc = false;
|
2009-09-22 22:36:28 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-07-05 20:50:00 +02:00
|
|
|
e = $('birthday');
|
|
|
|
if (e.value.length > 0
|
|
|
|
&& !dateRegex.test(e.value)) {
|
|
|
|
alert(_("invaliddatewarn"));
|
|
|
|
rc = false;
|
|
|
|
}
|
|
|
|
|
2010-04-13 16:19:58 +02:00
|
|
|
return rc;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-09-16 00:27:59 +02:00
|
|
|
|
2006-09-26 20:44:42 +02:00
|
|
|
function onFnKeyDown() {
|
2010-04-13 16:19:58 +02:00
|
|
|
var fn = $("fn");
|
|
|
|
fn.onkeydown = null;
|
|
|
|
displayNameChanged = true;
|
2006-09-26 20:44:42 +02:00
|
|
|
|
2010-04-13 16:19:58 +02:00
|
|
|
return true;
|
2006-09-26 20:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onFnNewValue(event) {
|
2010-04-13 16:19:58 +02:00
|
|
|
if (!displayNameChanged) {
|
|
|
|
var sn = $("sn").value.trim();
|
|
|
|
var givenName = $("givenName").value.trim();
|
2006-09-26 20:44:42 +02:00
|
|
|
|
2010-04-13 16:19:58 +02:00
|
|
|
var fullName = givenName;
|
|
|
|
if (fullName && sn)
|
|
|
|
fullName += ' ';
|
|
|
|
fullName += sn;
|
2006-09-26 20:44:42 +02:00
|
|
|
|
2010-04-13 16:19:58 +02:00
|
|
|
$("fn").value = fullName;
|
|
|
|
}
|
2006-09-26 20:44:42 +02:00
|
|
|
|
2010-04-13 16:19:58 +02:00
|
|
|
return true;
|
2006-09-26 20:44:42 +02:00
|
|
|
}
|
|
|
|
|
2008-03-07 23:10:03 +01:00
|
|
|
function onEditorCancelClick(event) {
|
2009-11-04 23:13:20 +01:00
|
|
|
this.blur();
|
|
|
|
preventDefault(event);
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEditorSubmitClick(event) {
|
2010-10-26 21:23:08 +02:00
|
|
|
if (validateContactEditor()) {
|
|
|
|
saveCategories();
|
2010-04-13 16:19:58 +02:00
|
|
|
$('mainForm').submit();
|
2010-10-26 21:23:08 +02:00
|
|
|
}
|
2010-04-13 16:19:58 +02:00
|
|
|
this.blur();
|
2008-03-07 23:10:03 +01:00
|
|
|
}
|
|
|
|
|
2010-10-26 21:23:08 +02:00
|
|
|
function saveCategories() {
|
|
|
|
var container = $("categoryContainer");
|
|
|
|
var catsInput = $("contactCategories");
|
|
|
|
if (container && catsInput) {
|
|
|
|
var newCategories = $([]);
|
|
|
|
var inputs = container.select("INPUT");
|
|
|
|
for (var i = 0; i < inputs.length; i++) {
|
|
|
|
var newValue = inputs[i].value.trim();
|
|
|
|
if (newValue.length > 0 && newValue != _("New category")
|
|
|
|
&& newCategories.indexOf(newValue) == -1) {
|
|
|
|
newCategories.push(newValue);
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 15:31:24 +01:00
|
|
|
var json = Object.toJSON(newCategories);
|
2010-10-26 21:23:08 +02:00
|
|
|
catsInput.value = json;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-16 22:21:38 +02:00
|
|
|
function onDocumentKeydown(event) {
|
|
|
|
var target = Event.element(event);
|
|
|
|
if (target.tagName == "INPUT" || target.tagName == "SELECT") {
|
|
|
|
if (event.keyCode == Event.KEY_RETURN) {
|
|
|
|
var fcn = onEditorSubmitClick.bind($("submitButton"));
|
|
|
|
fcn();
|
|
|
|
Event.stop(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 21:23:08 +02:00
|
|
|
function appendCategoryInput(label) {
|
|
|
|
var container = $("categoryContainer");
|
|
|
|
|
|
|
|
var inputContainer = createElement("div");
|
|
|
|
var textInput = createElement("input", null, "comboBoxField", null,
|
|
|
|
{ type: "text"}, inputContainer);
|
|
|
|
textInput.observe("change", onCategoryInputChange);
|
|
|
|
textInput.observe("focus", onCategoryInputFocus);
|
|
|
|
textInput.value = label;
|
|
|
|
textInput.tabIndex = tabIndex;
|
|
|
|
tabIndex++;
|
|
|
|
var button = createElement("button", null, "comboBoxButton");
|
|
|
|
inputContainer.appendChild(button);
|
|
|
|
button.observe("click", onComboButtonClick);
|
|
|
|
button.textInput = textInput;
|
|
|
|
button.menuName = "categoriesMenu";
|
|
|
|
|
|
|
|
container.appendChild(inputContainer);
|
|
|
|
|
|
|
|
return textInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onComboButtonClick(event) {
|
|
|
|
var menu = $(this.menuName);
|
|
|
|
popupMenu(event, this.menuName, this.textInput);
|
|
|
|
var container = $("categoryContainer");
|
|
|
|
var menuTop = (container.cascadeTopOffset()
|
2010-10-27 17:16:20 +02:00
|
|
|
- container.scrollTop
|
|
|
|
+ this.textInput.offsetTop
|
|
|
|
+ this.textInput.clientHeight);
|
2010-10-26 22:42:29 +02:00
|
|
|
var menuLeft = this.textInput.cascadeLeftOffset() + 1;
|
2010-10-27 17:16:20 +02:00
|
|
|
var width = this.textInput.clientWidth;
|
2010-10-26 21:23:08 +02:00
|
|
|
menu.setStyle({ "top": menuTop + "px",
|
|
|
|
"left": menuLeft + "px",
|
2010-10-27 17:16:20 +02:00
|
|
|
"width": width + "px" });
|
2010-10-26 21:23:08 +02:00
|
|
|
|
2010-11-08 19:47:11 +01:00
|
|
|
return false;
|
2010-10-26 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onCategoryInputChange(event) {
|
|
|
|
var newValue = this.value.trim();
|
|
|
|
if (newValue == "") {
|
|
|
|
var inputContainer = this.parentNode;
|
|
|
|
inputContainer.parentNode.removeChild(inputContainer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (gCategories.indexOf(newValue) == -1) {
|
|
|
|
gCategories.push(newValue);
|
|
|
|
gCategories.sort(function (a, b)
|
|
|
|
{ return a.toLowerCase() > b.toLowerCase(); } );
|
|
|
|
regenerateCategoriesMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCategoryInputFocus(event) {
|
|
|
|
this.select();
|
|
|
|
}
|
|
|
|
|
|
|
|
function regenerateCategoriesMenu() {
|
|
|
|
var menu = $("categoriesMenu");
|
|
|
|
if (menu) {
|
|
|
|
while (menu.lastChild) {
|
|
|
|
menu.removeChild(menu.lastChild);
|
|
|
|
}
|
|
|
|
var list = createElement("ul");
|
|
|
|
for (var i = 0; i < gCategories.length; i++) {
|
|
|
|
var label = gCategories[i];
|
|
|
|
var entry = createElement("li");
|
|
|
|
entry.label = label;
|
|
|
|
entry.menuCallback = onCategoryMenuEntryClick;
|
2011-08-18 05:31:04 +02:00
|
|
|
entry.on("mousedown", onMenuClickHandler);
|
2010-10-26 21:23:08 +02:00
|
|
|
entry.appendChild(document.createTextNode(label));
|
|
|
|
list.appendChild(entry);
|
|
|
|
}
|
|
|
|
menu.appendChild(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCategoryMenuEntryClick(event) {
|
|
|
|
document.menuTarget.value = this.label;
|
|
|
|
document.menuTarget.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEmptyCategoryClick(event) {
|
|
|
|
var textInput = appendCategoryInput(_("New category"));
|
|
|
|
window.setTimeout(function() {textInput.focus();},
|
|
|
|
100);
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2006-10-12 18:42:59 +02:00
|
|
|
function initEditorForm() {
|
2010-04-13 16:18:27 +02:00
|
|
|
var tabsContainer = $("editorTabs");
|
|
|
|
var controller = new SOGoTabsController();
|
|
|
|
controller.attachToTabsContainer(tabsContainer);
|
|
|
|
|
2010-04-13 16:19:58 +02:00
|
|
|
displayNameChanged = ($("fn").value.length > 0);
|
|
|
|
$("fn").onkeydown = onFnKeyDown;
|
|
|
|
$("sn").onkeyup = onFnNewValue;
|
|
|
|
$("givenName").onkeyup = onFnNewValue;
|
2008-03-07 23:10:03 +01:00
|
|
|
|
2010-04-13 16:19:58 +02:00
|
|
|
$("cancelButton").observe("click", onEditorCancelClick);
|
2010-10-26 21:23:08 +02:00
|
|
|
var submitButton = $("submitButton");
|
|
|
|
if (submitButton) {
|
|
|
|
submitButton.observe("click", onEditorSubmitClick);
|
|
|
|
}
|
2010-06-16 22:21:38 +02:00
|
|
|
|
|
|
|
Event.observe(document, "keydown", onDocumentKeydown);
|
2010-10-26 21:23:08 +02:00
|
|
|
|
|
|
|
regenerateCategoriesMenu();
|
|
|
|
var catsInput = $("contactCategories");
|
|
|
|
if (catsInput && catsInput.value.length > 0) {
|
|
|
|
var contactCats = $(catsInput.value.evalJSON(false));
|
|
|
|
for (var i = 0; i < contactCats.length; i++) {
|
|
|
|
appendCategoryInput(contactCats[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var emptyCategory = $("emptyCategory");
|
2011-03-10 22:15:35 +01:00
|
|
|
if (emptyCategory) {
|
|
|
|
emptyCategory.tabIndex = 10000;
|
|
|
|
emptyCategory.observe("click", onEmptyCategoryClick);
|
|
|
|
}
|
|
|
|
}
|
2007-10-18 23:54:24 +02:00
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initEditorForm);
|