$(function() {
// Get the User Type Id
//amatAPI.request('tipouser_module', null, registration_getUserTypeId);
// Bind the form
$('#registration_module').submit(function(e) {
e.preventDefault();
$('.buttonSubmit').attr('disabled',true);
var data = $(this).serializeArray();
var checkAll = true;
$.each(data, function(key, value) {
// Check value
data[key].value = value.value.trim();
if (
($('#registration_module').find('input[name='+value.name+']').attr('optional') != "true") &&
(
(value.value == '') ||
(!registration_checkValue(value))
)
) {
checkAll = false;
var obj = $('#registration_module').find('input[name='+value.name+']');
$($('#registration_module').find('input[name='+value.name+']')).addClass('error');
$('#error_div').remove();
$('#registration_module').prepend('
Errore nei campi
');
alert("Errore nei campi: verificare il corretto inserimento del campo "+obj.attr('alias'));
}
else {
$('#error_div').remove();
$('#registration_module').find('input[name='+value.name+']').removeClass('error');
data[key].value = encodeURI(value.value);
}
});
if (tokenName!="" && tokenValue!="") token = tokenName+"_"+tokenValue; else token = "";
if (checkAll) {
// Proceed with registration
var dataToBeSent = {
'Id_Tipo_Utente': 8,
'Nome': $('#nome_utente').val(),
'Cognome': $('#cognome_utente').val(),
'Telefono': $('#telefono_utente').val(),
'email': $('#email_utente').val(),
'CodiceFiscale': $('#codicefiscale_utente').val(),
'username_utente': $('#username_utente').val(),
'password_utente': $('#password_utente').val(),
'AzioneRichiesta': $('#action_name').val(),
'Denominazione': $('#denominazione_utente').val(),
'Indirizzo': $('#indirizzo_utente').val(),
'token': token
};
// amatAPI.request('reguser_module', datiForm, registration_registerUser);
$.post(site_url+"/user/registra/add", dataToBeSent, registration_registerUser);
}
else {
$('.buttonSubmit').attr('disabled',false);
// $('body').scrollTo('#error_div');
}
});
});
//var registration_getUserTypeId = function(data) {
// if (typeof data == "undefined") return false;
//
// $.each(data, function(key, value) {
// $('#typeuserid').append('');
// });
//
// return true;
//}
var registration_registerUser = function(data,xtext) {
$('.buttonSubmit').attr('disabled',false);
if (data != "OK") {alert(data); return false;}
var datiAggiornati = {
'Nome': $('#nome_utente').val(),
'Cognome': $('#cognome_utente').val(),
'Telefono': $('#telefono_utente').val(),
'email': $('#email_utente').val(),
'CodiceFiscale': $('#codicefiscale_utente').val(),
'username_utente': $('#username_utente').val(),
'password_utente': $('#password_utente').val(),
'Denominazione': $('#denominazione_utente').val(),
'Indirizzo': $('#indirizzo_utente').val()
};
$.post(site_url+"/user/postMail", {info : JSON.stringify(datiAggiornati),action:'new'} ).done(function( data ){
// if (data=='OK') alert("Notifica via email inviata"); else alert("Notifica via email NON inviata");
console.log(data);
});
alert('Dati inseriti correttamente');
location.href=site_url;
/* }
else {
// User already registered
$('#error_div').remove();
$('#registration_module').prepend('
Errore in fase di registrazione
');
alert("Errore in fase di registrazione:\n"+data[0]['Stato User Information']['Info']);
console.log(data[0]['Stato User Information']['Info']);
}
*/
return true;
}
function registration_checkValue(value) {
switch(value.name) {
case 'email':
// Simple check
var check = /\S+@\S+\.\S+/;
return check.test(value.value);
break;
case 'cf':
if ($.isNumeric(value.value)) return ControllaPIVA(value.value); else return ControllaCF(value.value);
break;
case 'phonenumber':
var check = /^([0-9\ \+\.\-\_]+)$/;
return check.test(value.value);
break;
case 'repeat_password':
if ($('#registration_module').find('input[name=password]').val() != value.value) return false;
break;
default:
return true;
}
return true;
}
function registration_errorHandler(element) {
$(element).addClass('error');
}