function writeLog(table, url, description) {
jQuery.ajax({
url: "https://api.annuncifunebri.it/v2/writeLog",
data: {
'table': table,
'url': url,
'description': description,
},
method: "POST",
crossDomain: true,
dataType: 'jsonp'
});
}
jQuery('#annfu_invio').on('click', function () {
if (!jQuery('#annfu_dati_personali').attr('checked')) {
return confirm('Inviando il cordoglio acconsentirai al trattamento dei tuoi dati personali');
}
});
//invio del cordoglio
jQuery('#annfu_form_cordoglio form').on('submit', function () {
var error = "";
var token = jQuery('#annfu_token').val();
var hash = jQuery('#annfu_hash').val();
var nome = jQuery('#annfu_nome').val();
var mail = jQuery('#annfu_mail').val();
var testo = jQuery('#annfu_testo').val();
var recapito = jQuery('#annfu_recapito').val();
var visibile = jQuery('#annfu_visibile').attr('checked') ? 0 : 1;
Cookies.set('cordoglio.nome', nome, {expires: 365});
Cookies.set('cordoglio.mail', mail, {expires: 365});
Cookies.set('cordoglio.testo', testo, {expires: 365});
Cookies.set('cordoglio.recapito', recapito, {expires: 365});
Cookies.set('cordoglio.visibile', visibile, {expires: 365});
if (nome == "") error += "Il nome è obbligatorio ";
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if (mail != "" && !re.test(mail)) error += "L'email non è corretta ";
if (error != "") jQuery('#annfu_errori').html(error);
else {
jQuery('#annfu_loading').removeClass('hidden');
jQuery.ajax({
url: "https://api.annuncifunebri.it/v2/cordogli",
data: {
token: token,
hash: hash,
nome: nome,
cognome: '',
mail: mail,
testo: testo,
recapito: recapito,
visibile: visibile,
},
type: "POST",
crossDomain: true,
dataType: 'jsonp',
success: function (data) {
var success = '';
if ('utente' in data) {
if (data.testo === null) {
jQuery('.annfu_partecipazioni').html('
' + data.partecipazioni + '
');
success = 'La partecipazione è stata inserita correttamente ed è in attesa di approvazione';
} else {
if ('utente' in data) {
var visibile = data.visibile == 0 ? '; sarà visibile solo dalla famiglia' : '';
var cordoglio = '
' +
' Inserisci il tuo numero di cellulare per ricevere gratuitamente una conferma all\'avvenuta approvazione del cordoglio' +
'' +
'
' +
'
';
jQuery('.annfu_cordogli').prepend(cordoglio);
success = 'Il cordoglio è stato inserito correttamente ed è in attesa di approvazione';
Cookies.remove('cordoglio.testo');
Cookies.remove('cordoglio.visibile');
}
}
jQuery('#annfu_successo').html(success);
} else {
jQuery('#annfu_errori').html('Non è stato possibile inserire il cordoglio. Riprovare tra qualche minuto.');
Cookies.set('cordoglio.error', 'Non è stato possibile inserire il cordoglio. Riprovare tra qualche minuto.');
location.reload(true);
}
},
error: function (data) {
jQuery('#annfu_errori').html('Non è stato possibile inserire il cordoglio. Riprovare tra qualche minuto');
Cookies.set('cordoglio.error', 'Non è stato possibile inserire il cordoglio. Riprovare tra qualche minuto');
location.reload(true);
},
});
jQuery('#annfu_errori, #annfu_successo').html('');
jQuery('#annfu_testo').val('');
jQuery('#annfu_loading').addClass('hidden');
}
return false;
});
//salvataggio numero di telefono dell'utente dopo l'inserimento del cordoglio
jQuery(".annfu_cordogli").on("submit", "form", function (e) {
e.preventDefault();
id = jQuery(this).parent().attr('id');
if (jQuery('#' + id + ' .annfu_sms_numero').val() != '') {
jQuery.ajax({
url: "https://api.annuncifunebri.it/v2/utenti",
data: jQuery('#' + id + ' form').serialize(),
type: "PUT",
crossDomain: true,
dataType: 'json',
success: function (data) {
if (!('error' in data)) {
jQuery('#' + id).addClass('annfu_success').html(data.text);
} else {
jQuery('#' + id + ' .annfu_sms_error').html(data.text);
}
},
error: function (data) {
console.log('Error: ', data);
jQuery('#' + id + ' .annfu_sms_error').html(data.text);
},
});
} else {
jQuery('#' + id + '.annfu_sms_error').html('Devi inserire un numero valido');
}
});
var extra = {'page': window.location.href, 'os': "Unknown OS"};
if (navigator.appVersion.indexOf("Win") != -1) extra['os'] = "Windows";
if (navigator.appVersion.indexOf("Mac") != -1) extra['os'] = "MacOS";
if (navigator.appVersion.indexOf("X11") != -1) extra['os'] = "Unix";
if (navigator.appVersion.indexOf("Linux") != -1) extra['os'] = "Linux";
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
extra['browser'] = navigator.appName;
extra['browser_version'] = '' + parseFloat(navigator.appVersion);
extra['user_agent'] = nAgt;
var nameOffset, verOffset, ix;
if ((verOffset = nAgt.indexOf("Opera")) != -1) { // In Opera, the true version is after "Opera" or after "Version"
extra['browser'] = "Opera";
extra['browser_version'] = nAgt.substring(verOffset + 6);
if ((verOffset = nAgt.indexOf("Version")) != -1) fullVersion = nAgt.substring(verOffset + 8);
}
else if ((verOffset = nAgt.indexOf("MSIE")) != -1) { // In MSIE, the true version is after "MSIE" in userAgent
extra['browser'] = "Microsoft Internet Explorer";
extra['browser_version'] = nAgt.substring(verOffset + 5);
}
else if ((verOffset = nAgt.indexOf("Chrome")) != -1) { // In Chrome, the true version is after "Chrome"
extra['browser'] = "Chrome";
extra['browser_version'] = nAgt.substring(verOffset + 7);
}
else if ((verOffset = nAgt.indexOf("Safari")) != -1) { // In Safari, the true version is after "Safari" or after "Version"
extra['browser'] = "Safari";
extra['browser_version'] = nAgt.substring(verOffset + 7);
if ((verOffset = nAgt.indexOf("Version")) != -1) extra['browser_version'] = nAgt.substring(verOffset + 8);
}
else if ((verOffset = nAgt.indexOf("Firefox")) != -1) { // In Firefox, the true version is after "Firefox"
extra['browser'] = "Firefox";
extra['browser_version'] = nAgt.substring(verOffset + 8);
}
else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) // In most other browsers, "name/version" is at the end of userAgent
{
extra['browser'] = nAgt.substring(nameOffset, verOffset);
extra['browser_version'] = nAgt.substring(verOffset + 1);
if (browserName.toLowerCase() == browserName.toUpperCase()) browserName = navigator.appName;
}
// trim the fullVersion string at semicolon/space if present
if ((ix = extra['browser_version'].indexOf(";")) != -1) extra['browser_version'] = extra['browser_version'].substring(0, ix);
if ((ix = extra['browser_version'].indexOf(" ")) != -1) extra['browser_version'] = extra['browser_version'].substring(0, ix);
extra['privacy'] = jQuery('#annfu_dati_personali').attr('checked') ? 1 : 0;
jQuery('#annfu_form_cordoglio .controllato').on('keyup', function () {
var text = jQuery(this).val();
if (text.length >= 3) {
jQuery.ajax({
url: "https://api.annuncifunebri.it/v2/cordogliIniziati",
data: {
token: jQuery('#annfu_token').val(),
hash: jQuery('#annfu_hash').val(),
nome: jQuery('#annfu_nome').val(),
mail: jQuery('#annfu_mail').val(),
testo: jQuery('#annfu_testo').val(),
recapito: jQuery('#annfu_recapito').val(),
visibile: jQuery('#annfu_visibile').attr('checked') ? 0 : 1,
extra: JSON.stringify(extra)
},
type: "POST",
crossDomain: true,
dataType: 'jsonp',
success: function (data) {
},
error: function (data) {
}
});
}
});
jQuery('#annfu_dati_personali').on('click', function () {
if (jQuery(this).is(':checked')) {
jQuery('#annfu_invio').removeProp('disabled');
} else {
jQuery('#annfu_invio').prop('disabled', 'disabled');
}
});
//fiori
function controllaFiori() {
var errors = [];
var fiore_id = jQuery('input[name=fiore_id]:checked').val();
var nome = jQuery('#annfu_fiore_nome').val();
var cognome = jQuery('#annfu_fiore_cognome').val();
var telefono = jQuery('#annfu_fiore_telefono').val();
var mail = jQuery('#annfu_fiore_mail').val();
if (nome == '' && cognome == '' && mail == '' && telefono == '') {
errors.push("Tutti i campi sono obbligatori");
} else {
if (!fiore_id) errors.push("Devi selezionare una composizione");
if (nome.length < 3) errors.push("Il nome è obbligatorio (min 3 caratteri)");
if (cognome.length < 3) errors.push("Il cognome è obbligatorio (min 3 caratteri)");
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if (!re.test(mail)) errors.push("L'email non è corretta");
if (telefono.length < 7) errors.push("Il telefono è obbligatorio");
}
if (errors.length == 0) {
jQuery('#annfu_error').html('');
jQuery('#annfu_ordina').removeProp('disabled').removeClass('annfu_ordina_disabled');
if (jQuery('#annfu_fiore_testo_fascia').val() != '') {
jQuery('.annfu_totale_testo_fascia').html('Testo da inserire nella fascia ' + jQuery('#annfu_fiore_testo_fascia').val());
}
if (jQuery('#annfu_fiore_testo_biglietto').val() != '') {
jQuery('.annfu_totale_testo_biglietto').html('Testo da inserire nel biglietto ' + jQuery('#annfu_fiore_testo_biglietto').val());
}
jQuery('.annfu_totale_dati').html('Dati personali ' + nome + ' ' + cognome + ' ' + 'Email: ' + mail + ' Telefono: ' + telefono);
writeLog('fiori', location.href, 'compilato i dati anagrafici: ' + nome + ',' + cognome + ',' + mail + ',' + telefono);
} else {
jQuery('#annfu_error').html(errors.join(' '));
jQuery('#annfu_ordina').prop('disabled', 'disabled').addClass('annfu_ordina_disabled');
jQuery('.annfu_totale_dati').html('');
}
return errors;
}
function calcolaImporto() {
var importo = jQuery('input[name=fiore_id]:checked').data('importo') || 0;
var quantita = 1; //jQuery('#annfu_fiore_quantita').val() || 0;
return importo * quantita;
}
jQuery('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
if (e.target.text == 'Fiori') {
if (jQuery('.annfu_fiori_wrapper').height() > 410) {
jQuery('.annfu_fiori_wrapper').addClass('scroll');
}
}
});
jQuery('.annfu_fiore_dettagli').on('click', function () {
html = '';
html += '