%
/******************************************************************************
* Copyright (c) 2000-2011 E-DEAL
*
* E-DEAL S.A.
* 41, rue Périer
* 92120 Montrouge
* France
*
* T: +33 (0)1 73 03 29 80
* F: +33 (0)1 73 01 69 77
* http://www.e-deal.com
*
* La diffusion de ce code source sous quelque forme que ce soit sans
* l'autorisation de E-DEAL est interdite.
*
* Vous êtes autorisés à modifier ce code source uniquement pour votre usage
* propre et sous réserve que les mentions de copyright demeurent intactes.
*
* Ce code est fourni en l'état. Aucune garantie d'aucune sorte, explicite ou
* implicite n'est donnée. En aucun cas E-DEAL ne pourra être tenu pour
* responsable des dommages pouvant résulter de l'utilisation de ce code
* source.
******************************************************************************/
%>
<%@ page import="com.edeal.frontline.FieldNotInitializedException" %>
<%@ page import="com.edeal.frontline.FlContext" %>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="com.edeal.frontline.helper.ContextHelper" %>
<%@ page import="com.edeal.frontline.Utils" %>
<%@ page contentType="text/javascript; charset=UTF8" session="true" %>
<%@ taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<%
FlRequest flRequest = new FlRequest(request);
FlContext context = flRequest.getContext();
String salesModel = request.getParameter("salesModel");
if (salesModel == null) {
salesModel = "";
}
String pad = request.getParameter("pad");
boolean personalAddressDefault = "true".equalsIgnoreCase(pad);
String emailPattern = request.getParameter("emailPattern");
if (emailPattern == null) {
emailPattern = "";
}
String PerLocID = request.getParameter("PerLocID");
if (PerLocID == null) {
PerLocID = "";
}
String id = request.getParameter("id");
%>
var eraseFaxOnSubmit = false;
var showEmailChange = true;
function doAllFormatTel() {
var f = document.forms[0];
doFormatTel(f.PerPhone, ' :', f.PerCtrID);
doFormatTel(f.PerMobile, ' :', f.PerCtrID);
if (f.PerFax) {
doFormatTel(f.PerFax, ' :', f.PerCtrID);
}
}
function doPerLocIDChange() {
var f = document.forms[0];
doAjax('/sales/person/loc_change_ajax.jsp?newLocID=' + f.PerLocID.value + '&newEntID=' + f.PerEntID.value);
}
function doUpdatePersonFromSilhouette() {
var f = document.forms[0];
doAjax('/getSilhouetteFromEmailOrCookie.fl?emailOrCookie=' + f.PerMail.value);
}
var mailPatternVal = '';
var perPhoneVal = '';
var perFaxVal = '';
var isPerEntIDChangedFirstTime = true;
function doPerEntIDChange() {
<% if (Utils.isEmpty(id) || !ContextHelper.hasMultifunction(context)) { %>
updateEntFields();
<% } else { %>
if (!isPerEntIDChangedFirstTime) {
var namePopup = "entchangePopup";
var urlPopup = "/open_popup_entchange.fl";
jQuery.openPopupLayer({
name: namePopup,
width: "auto",
height: "auto",
cache: true,
url: urlPopup,
error: function () {
//alert("Erreur lors de l'ouverture de la popup !");
}
});
} else {
isPerEntIDChangedFirstTime = false;
}
<% } %>
}
function updateEntFields (popName) {
$.closePopupLayer(popName);
var f = document.forms[0];
doAjax('/sales/person/ent_change_ajax.jsp?newEntID=' + f.PerEntID.value + '&PerLocID=<%= PerLocID %>');
if (!isPerEntIDChangedFirstTime) {
loadEntFieldsValues();
if (window.confirm('')) {
f.PerPhone.value = perPhoneVal;
}
doEmailPattern(mailPatternVal);
} else {
if (f.PerEntID.value != '') {
isPerEntIDChangedFirstTime = false;
}
}
}
function loadEntFieldsValues() {
var f = document.forms[0];
if (f.PerEntID) {
$.getJSON("/get_ent_fields.fl?newEntID=" + f.PerEntID.value, function(data) {
perPhoneVal = data.entPhone;
if (f.PerFax) {
perFaxVal = data.entFax;
}
mailPatternVal = data.entEmailPattern;
});
}
}
function doPerPhoneChange() {
var f = document.forms[0];
var phoneField = f.PerPhone;
if (f.PerFax) {
var faxField = f.PerFax;
}
var countryField = f.PerCtrID;
if (faxField && faxField.value == '' && phoneField.value.length > 3) {
faxField.value = phoneField.value.substring(0, phoneField.value.length - 3);
eraseFaxOnSubmit = true;
}
if (faxField && faxField.value == '' && phoneField.value.length > 3) {
faxField.value = phoneField.value.substring(0, phoneField.value.length - 3);
eraseFaxOnSubmit = true;
}
doFormatTel(phoneField, ' :', countryField);
}
function doPerMobileChange() {
var f = document.forms[0];
var mobileField = f.PerMobile;
var countryField = f.PerCtrID;
doFormatTel(mobileField, ' :', countryField);
}
function doPerFaxChange() {
var f = document.forms[0];
var faxField = f.PerFax;
var countryField = f.PerCtrID;
doFormatTel(faxField, ' :', countryField);
eraseFaxOnSubmit = false;
}
function doCountryChange() {
<% if (personalAddressDefault) { %>
var f = document.forms[0];
var field = f.PerCtrID;
var oldCountry = f.country;
retrieveCity(field.options[field.selectedIndex].value, f.PerZip.value, 'PerCity');
doEpureTel(f.PerPhone, f.PerPhone, oldCountry);
if (f.PerFax) {
doEpureTel(f.PerFax, f.PerFax, oldCountry);
}
oldCountry.value = field.options[field.selectedIndex].value;
doFormatTel(f.PerPhone, ' :', field);
if (f.PerFax) {
doFormatTel(f.PerFax, ' :', field);
}
<% } %>
}
function removePerEntID() {
mf = document.forms[0];
mf.PerEntID.value = "";
mf.lblPerEntID.value = "";
}
function doPerEntIDRemove() {
if(window.confirm('')) {
mf = document.forms[0];
mf.PerPhone.value = "";
if (mf.PerFax) {
mf.PerFax.value = "";
}
if (mf.PerMail) {
mf.PerMail.value = "";
}
}
}
function doEmailPattern(emailPattern) {
f = document.forms[0];
var oldEmailAddress = f.PerMail.value;
var firstName = f.PerFstName.value;
firstName = checkString(firstName, 'lower');
firstName = checkString(firstName, 'remaccents');
while(firstName.indexOf(' ') > -1) {
firstName = firstName.replace(' ', '');
}
var name = f.PerName.value;
name = checkString(name, 'lower');
name = checkString(name, 'remaccents');
while(name.indexOf(' ') > -1) {
name = name.replace(' ', '');
}
var pattern = '';
if (emailPattern == undefined) {
pattern = '<%= emailPattern != null ? emailPattern : "" %>';
} else {
pattern = emailPattern;
}
if (name == '') return;
if (pattern == '') return;
var newEmailAddress = pattern;
if (firstName != '') newEmailAddress = newEmailAddress.replace('FIRST', firstName);
if (firstName != '') {
if (firstName.indexOf("-") != -1){
newEmailAddress = newEmailAddress.replace('INITIAL', firstName.charAt(0)+firstName.substring(firstName.indexOf("-")+1,firstName.indexOf("-")+2));
}else {
newEmailAddress = newEmailAddress.replace('INITIAL', firstName.charAt(0));
}
}
newEmailAddress = newEmailAddress.replace('NAME', name);
<%-- if (newEmailAddress != oldEmailAddress) {
if (oldEmailAddress != '' && showEmailChange) {
if (confirm("\n'" + oldEmailAddress + "' '" + newEmailAddress + "'\n")) {
f.PerMail.value = newEmailAddress;
}
} else {
try {
f.PerMail.value = newEmailAddress;
} catch (error) {
}
}
} --%>
}
function doPerFstNameChange() {
var f = document.forms[0];
if (f.PerFstName.value != '<%= Utils.getMessage(session, "F611C", true, "") %>') {
// Mantis 30620
// Mantis 30587
// f.PerFstName.value = checkString(f.PerFstName.value, 'capitalize');
if (f.PerName.value != '<%= Utils.getMessage(session, "F611D", true, "") %>') {
//doVerifMatchCode();
doEmailPattern();
}
}
}
function doPerNameChange() {
var f = document.forms[0];
if (f.PerName.value != '<%= Utils.getMessage(session, "F611D", true, "") %>') {
// Mantis 30587
// f.PerName.value = checkString(f.PerName.value, 'remaccents');
// f.PerName.value = checkString(f.PerName.value, 'capitalize');
if (f.PerFstName.value != '<%= Utils.getMessage(session, "F611C", true, "") %>') {
doEmailPattern();
}
}
}
function doZipChange() {
var f = document.forms[0];
retrieveCity(f.PerCtrID.options[f.PerCtrID.selectedIndex].value, f.PerZip.value, 'PerCity');
}
function doOnLoad() {
var f = document.forms[0];
if (f) {
if (f.PerCtrID) {
f.PerCtrID.onchange = doCountryChange;
}
if (f.PerPhone) {
f.PerPhone.onchange = doPerPhoneChange;
}
if (f.PerFax) {
f.PerFax.onchange = doPerFaxChange;
}
if (f.PerMobile) {
f.PerMobile.onchange = doPerMobileChange;
}
if (f.PerZip) {
f.PerZip.onchange = doZipChange;
}
}
<% if (Utils.isEmpty(id) || !ContextHelper.hasMultifunction(context)) { %>
doPerEntIDChange();
<% } else { %>
updateEntFields();
<% } %>
loadEntFieldsValues();
doLoadDep();
setChampAss();
}