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
|
|
|
*/
|
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
var dateRegex = /^(([0-9]{2})?[0-9])?[0-9]-[0-9]?[0-9]-[0-9]?[0-9]$/;
|
2006-10-04 00:06:00 +02:00
|
|
|
|
2011-12-30 21:39:07 +01: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,
|
2011-12-30 21:39:07 +01:00
|
|
|
displayname, givenname, telephonenumber, facsimiletelephonenumber,
|
|
|
|
mobile, postalAddress, homePostalAddress,
|
|
|
|
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];
|
2011-12-30 21:39:07 +01:00
|
|
|
// var givenname = arguments[4];
|
|
|
|
// var telephonenumber = arguments[5];
|
|
|
|
// var facsimiletelephonenumber = arguments[6];
|
2010-10-26 21:23:08 +02:00
|
|
|
// var mobile = arguments[7];
|
2011-12-30 21:39:07 +01:00
|
|
|
// var postaladdress = arguments[8];
|
|
|
|
// var homepostaladdress = arguments[9];
|
|
|
|
// var departmentnumber = arguments[10];
|
2010-10-26 21:23:08 +02:00
|
|
|
// var l = arguments[11];
|
2010-04-13 16:19:58 +02:00
|
|
|
var e;
|
2011-12-30 21:39:07 +01:00
|
|
|
e = $('displayname');
|
|
|
|
e.setAttribute('value', unescapeCallbackParameter(displayname));
|
2010-04-13 16:19:58 +02:00
|
|
|
e = $('email');
|
|
|
|
e.setAttribute('value', email);
|
|
|
|
e = $('sn');
|
|
|
|
e.setAttribute('value', unescapeCallbackParameter(sn));
|
2011-12-30 21:39:07 +01:00
|
|
|
e = $('givenname');
|
|
|
|
e.setAttribute('value', unescapeCallbackParameter(givenname));
|
|
|
|
e = $('telephonenumber');
|
|
|
|
e.setAttribute('value', telephonenumber);
|
|
|
|
e = $('facsimiletelephonenumber');
|
|
|
|
e.setAttribute('value', facsimileTelephonenumber);
|
2010-04-13 16:19:58 +02:00
|
|
|
e = $('mobile');
|
|
|
|
e.setAttribute('value', mobile);
|
2011-12-30 21:39:07 +01:00
|
|
|
e = $('postaladdress');
|
2010-04-13 16:19:58 +02:00
|
|
|
e.setAttribute('value', unescapeCallbackParameter(postalAddress));
|
2011-12-30 21:39:07 +01:00
|
|
|
e = $('homepostaladdress');
|
2010-04-13 16:19:58 +02:00
|
|
|
e.setAttribute('value', unescapeCallbackParameter(homePostalAddress));
|
2011-12-30 21:39:07 +01:00
|
|
|
e = $('departmentnumber');
|
|
|
|
e.setAttribute('value', unescapeCallbackParameter(departmentnumber));
|
2010-04-13 16:19:58 +02:00
|
|
|
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
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
var e = $('mail');
|
2010-04-13 16:19:58 +02:00
|
|
|
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
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
e = $('mozillasecondemail');
|
2010-04-13 16:19:58 +02:00
|
|
|
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
|
|
|
}
|
2014-03-10 17:05:01 +01:00
|
|
|
|
|
|
|
var today = new Date();
|
|
|
|
var yyyy = today.getFullYear();
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
var byear = $('birthyear');
|
|
|
|
var bmonth = $('birthmonth');
|
|
|
|
var bday = $('birthday');
|
2014-03-10 17:05:01 +01:00
|
|
|
|
|
|
|
if(byear.value <= yyyy && (byear.value.length == 4)){
|
|
|
|
if(bmonth.value <= 12 && bmonth.value >=1){
|
|
|
|
if(bday.value <= 31 && bday.value >=1){
|
|
|
|
var bdayValue = byear.value + "-" + bmonth.value + "-" + bday.value;
|
|
|
|
if (bdayValue != "--" && !dateRegex.test(bdayValue)) {
|
|
|
|
alert(_("invaliddatewarn"));
|
|
|
|
rc = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
alert(_("invaliddatewarn"));
|
|
|
|
rc = false;}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
alert(_("invalidmonthwarn"));
|
|
|
|
rc = false;}
|
2010-07-05 20:50:00 +02:00
|
|
|
}
|
2014-03-10 17:05:01 +01:00
|
|
|
else{
|
|
|
|
alert(_("invalidyearwarn"));
|
|
|
|
rc = false;}
|
2010-07-05 20:50:00 +02:00
|
|
|
|
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
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
function onDisplaynameKeyDown() {
|
|
|
|
var fn = $("displayname");
|
2010-04-13 16:19:58 +02:00
|
|
|
fn.onkeydown = null;
|
2011-12-30 21:39:07 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
function onDisplaynameNewValue(event) {
|
|
|
|
if (!displaynameChanged) {
|
2010-04-13 16:19:58 +02:00
|
|
|
var sn = $("sn").value.trim();
|
2011-12-30 21:39:07 +01:00
|
|
|
var givenname = $("givenname").value.trim();
|
2006-09-26 20:44:42 +02:00
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
var fullname = givenname;
|
|
|
|
if (fullname && sn)
|
|
|
|
fullname += ' ';
|
|
|
|
fullname += sn;
|
2006-09-26 20:44:42 +02:00
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
$("displayname").value = fullname;
|
2010-04-13 16:19:58 +02:00
|
|
|
}
|
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();
|
2011-12-02 08:22:47 +01:00
|
|
|
onCloseButtonClick(event);
|
2009-11-04 23:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2011-12-30 21:39:07 +01:00
|
|
|
var catsInput = $("jsonContactCategories");
|
2010-10-26 21:23:08 +02:00
|
|
|
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) {
|
2011-12-30 21:39:07 +01:00
|
|
|
var fdisplayname = onEditorSubmitClick.bind($("submitButton"));
|
|
|
|
fdisplayname();
|
2010-06-16 22:21:38 +02:00
|
|
|
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);
|
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
displaynameChanged = ($("displayname").value.length > 0);
|
|
|
|
$("displayname").onkeydown = onDisplaynameKeyDown;
|
|
|
|
$("sn").onkeyup = onDisplaynameNewValue;
|
|
|
|
$("givenname").onkeyup = onDisplaynameNewValue;
|
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
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
if (typeof(gCategories) != "undefined") {
|
|
|
|
regenerateCategoriesMenu();
|
|
|
|
}
|
|
|
|
var catsInput = $("jsonContactCategories");
|
2010-10-26 21:23:08 +02:00
|
|
|
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);
|
|
|
|
}
|
2011-12-30 21:39:07 +01:00
|
|
|
}
|
2007-10-18 23:54:24 +02:00
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initEditorForm);
|