var USER_LANG = "FR";
var waitMessage = "Veuillez patienter..";
var conErrorMessage = "Impossible d'établire une connexion au serveur.";
function alertGen(message, type){
return '
' + message + '
';
}
let apiV1 = class {
constructor() {
this.endPoint = "//fileservice.bhd-tuning-files.com/api/v1/" + USER_LANG + "/";
}
register(captcha){
$("#ajaxAlert").removeClass("alert-danger alert-success").addClass("alert-info").html(waitMessage);
var name = $("#name").val();
var email = $("#email").val();
var password1 = $("#password1").val();
var password2 = $("#password2").val();
var street_number = $("#street_number").val();
var route = $("#route").val();
var locality = $("#locality").val();
var administrative_area_level_1 = $("#administrative_area_level_1").val();
var postal_code = $("#postal_code").val();
var country = $("#country").val();
if(name != "" && email != "" && password1 != "" && password2 != "" && postal_code != ""){
$("#registerBtn").prop("disabled",true);
$.ajax({
url : this.endPoint + "register",
type : 'post',
data : {captcha: captcha, name: name, email: email, password1: password1, password2: password2, street_number: street_number, route: route, locality: locality, administrative_area_level_1: administrative_area_level_1, postal_code: postal_code, country: country,},
dataType : 'json',
success: function(d) {
$("#registerBtn").prop("disabled",false);
grecaptcha.reset();
if(d.success){
if(USER_LANG == "FR"){
var message = "Votre compte à été créer, redirection..";
}else{
var message = "Your account has been created, redirecting..";
}
$("#ajaxAlert").removeClass("alert-info alert-danger").addClass("alert-success").html(message);
setTimeout(location.reload(), 2000);
}else{
$("#ajaxAlert").removeClass("alert-info alert-success").addClass("alert-danger").html(d.message);
}
$("#captchaImage").attr("src", d.newCaptcha);
},
error: function(e, i) {
grecaptcha.reset();
$("#registerBtn").prop("disabled",false);
$("#ajaxAlert").removeClass("alert-info alert-success").addClass("alert-danger").html(conErrorMessage);
}
});
}else{
$("#registerBtn").prop("disabled",false);
setTimeout(grecaptcha.reset(), 2000);
if(USER_LANG == "FR"){
var errorMessage = "Veuillez remplire tout les champs.";
}else{
var errorMessage = "Please complete all fields.";
}
$("#ajaxAlert").removeClass("alert-info alert-success").addClass("alert-danger").html(errorMessage);
}
}
};
const api = new apiV1();
function initializeAutocomplete(id) {
var element = document.getElementById(id);
if (element) {
var autocomplete = new google.maps.places.Autocomplete(element, { types: ['geocode'] });
google.maps.event.addListener(autocomplete, 'place_changed', onPlaceChanged);
}
}
function onPlaceChanged() {
var place = this.getPlace();
for (var i in place.address_components) {
var component = place.address_components[i];
for (var j in component.types) { // Some types are ["country", "political"]
var type_element = document.getElementById(component.types[j]);
if (type_element) {
type_element.value = component.long_name;
}
}
}
}
google.maps.event.addDomListener(window, 'load', function() {
initializeAutocomplete('address');
});
function recaptchaValidate(token){
api.register(token);
}