2010-04-13 16:18:27 +02:00
|
|
|
/* -*- Mode: java; tab-width: 2; 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
|
2010-04-13 16:18:27 +02:00
|
|
|
Copyright (C) 2006-2010 Inverse
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
This file is part of OpenGroupware.org.
|
2006-06-15 21:34:10 +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.
|
2006-06-15 21:34:10 +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.
|
2006-06-15 21:34:10 +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
|
|
|
*/
|
|
|
|
|
2006-10-04 00:06:00 +02:00
|
|
|
var uixEmailUsr =
|
2010-04-13 16:19:58 +02:00
|
|
|
"([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
|
2006-10-04 00:06:00 +02:00
|
|
|
var uixEmailDomain =
|
2010-04-13 16:19:58 +02:00
|
|
|
"([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
|
2006-10-04 00:06:00 +02:00
|
|
|
var uixEmailRegex = new RegExp("^"+uixEmailUsr+"\@"+uixEmailDomain+"$");
|
|
|
|
|
2006-09-26 20:44:42 +02:00
|
|
|
var displayNameChanged = false;
|
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,
|
2008-08-28 16:48:45 +02:00
|
|
|
mobile, postalAddress, homePostalAddress,
|
|
|
|
departmentNumber, l)
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
2010-04-13 16:19:58 +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];
|
|
|
|
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;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-04-13 16:19:58 +02:00
|
|
|
var e = $('workMail');
|
|
|
|
if (e.value.length > 0
|
|
|
|
&& !uixEmailRegex.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
|
|
|
|
&& !uixEmailRegex.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-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-04-13 16:19:58 +02:00
|
|
|
if (validateContactEditor())
|
|
|
|
$('mainForm').submit();
|
|
|
|
this.blur();
|
2008-03-07 23:10:03 +01:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
$("submitButton").observe("click", onEditorSubmitClick);
|
2010-06-16 22:21:38 +02:00
|
|
|
|
|
|
|
Event.observe(document, "keydown", onDocumentKeydown);
|
2006-09-26 20:44:42 +02:00
|
|
|
}
|
2007-10-18 23:54:24 +02:00
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initEditorForm);
|