//Main admin JS file
$(function() {
jQuery.validator.addMethod("noSpace", function(value, element) {
return value.indexOf(" ") < 0 && value != "";
}, "Space are not allowed");
jQuery.validator.addMethod("invalidUsername", function(value, element) {
return value != "" && value.toUpperCase() != "ROOT" && value.toUpperCase() != "ADMIN";
}, "Invalid username");
jQuery.validator.addMethod("numericField", function(value, element) {
var myregExp = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
return value == "" || (value != "" && myregExp.test(value));
}, "Invalid number");
jQuery.validator.addMethod("requiredTinyMCE", function(value, element) {
return tinyMCE.get($(element).attr('id')).getContent() != '';
//return Trim(tinyMCE.get(element.attr('id')).getContent()) == '';
//return value.indexOf(" ") < 0 && value != "";
}, "Required");
//cookies commentati per l'applicazione che al momento è l'unico front end
/*$.ajax({
url: $('#base_url').val() + "ajax/get_last_cookie_key",
type: 'POST',
data: 'lang=' + lang,
success: function (data) {
var actual_key=data;
var cookie_url=$('#base_url').val()+"cookie";
$.cookieBar({
message: "We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies. If you want to learn more, please refer to the cookie policy.
",
acceptText: "Ok, close this banner",
policyURL: cookie_url,
cookieName: actual_key
});
}
});*/
//setLang('',0);
$('.lang_switcher').bind('click',function(e) {
e.preventDefault();
setLang($(this).data('lang'),1);
});
var genericForm = 1;
/***HOME***/
if($('#home_container').length) {
$('#home_container').find('a').each(function() {
var href = $(this).attr('href');
$(this).bind('click',function(e) {
$.ajax({
url: $('#base_url').val() + "ajax/clear_filtri_eventi",
type: 'POST',
data: 'lang=' + lang,
success: function (data) {
document.location.href=href;
}
});
});
});
}
/***CARRELLO***/
if($('#carrello_paypal').length>0) {
function get_bundles() {
$.ajax({
type: "POST",
url: $('#base_url').val()+"ajax/get_bundles",
data: "data_slot="+$('#data_slot').val()+"&evento_id="+$('#evento_id').val(),
success: function(data) {
$('#bundle_container').html(data);
if($('#bundle_id').html().trim() != '' || $('#bundle_id').val().trim() != '') {
//$('#bundle_container').fadeIn();
$('#bundle_id').bind('change',function() {
get_quantity();
});
get_quantity();
} else {
$('#carrello_paypal').fadeOut(0);
}
}
});
}
function get_quantity() {
$.ajax({
type: "POST",
url: $('#base_url').val()+"ajax/get_quantity",
data: "bundle_id="+$('#bundle_id').val(),
success: function(data) {
var dataArr = data.split("|||");
$('#quantita').html(dataArr[0]);
$('#quantita').fadeIn();
$('#quantita').bind('change',function() {
$('#quantity_1').val($(this).val());
});
$('#amount_1').val(dataArr[1]);
$('#loader_caricamento').fadeOut(0);
$('#bundle_container').fadeIn(0);
$('#quantita_container').fadeIn(0);
}
});
}
$('#data_slot').bind('change',function() {
get_bundles();
});
if($('#data_slot').val() != '') {
get_bundles();
}
$('#quantita').bind('change',function() {
$('#quantity_1').val($(this).val());
});
$('#acquista_button').bind('click',function(e) {
e.preventDefault();
$('body').prepend('
');
$('#loader_conferma').fadeIn();
$.ajax({
type: "POST",
url: $('#base_url').val()+"ajax/set_ordine_data",
data: "quantita="+$('#quantita').val()+"&bundle_id="+$('#bundle_id').val()+"&evento_id="+$('#evento_id').val()+"&data_slot="+$('#data_slot').val(),
success: function(datas) {
$.ajax({
type: "POST",
url: $('#base_url').val()+"ajax/crea_ordine",
success: function(data) {
$('#custom').val(data+"-"+$('#quantita').val()+"-"+$('#bundle_id').val());
$.ajax({
type: "POST",
url: $('#base_url').val()+"ajax/conferma_ordine",
data:"ordine_id="+data+"&quantita="+$('#quantita').val()+"&bundle_id="+$('#bundle_id').val(),
success: function(data) {
document.location.href=$('#base_url').val()+'thank_you';
//$('#paypal_form').submit();
}
});
}
});
}
});
});
}
/****registrazione****/
if($('#registrazione_container').length>0) {
$('.recupera_link').bind('click',function(e) {
e.preventDefault();
$('#password_container').fadeIn();
});
$('.recupera_chiudi_btn').bind('click',function(e) {
e.preventDefault();
$('#password_container').fadeOut();
});
$('#reg').validate({
ignore: [],
errorPlacement: function(error, element) {
error.appendTo('#' + element.attr('name')+'-error');
},
rules: {
reg_email: {
remote: {
url: $('#base_url').val()+"ajax/check_email",
type: "post",
data: {
email: function() {
return $('#reg').find( "#reg_email" ).val();
},
id:function() {
return 0;
}
}
},
email:true,
required:true
},
privacy_policy_check: {
required:true
}
},
messages: {
reg_email: {
remote: "[registrazione_mail_in_uso]",
email: "[registrazione_mail_non_valida]",
required: "[registrazione_mail_non_valida]"
},
privacy_policy_check: {
required: "Attenzione, per poterti registrare devi aver letto l\'informativa privacy e acconsentire al trattamento dei tuoi dati."
}
}
});
}
if($('.evento_container').length>0) {
$('#vai_reg').bind('click',function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: $('#base_url').val()+"ajax/set_ordine_data",
data: "quantita="+$('#quantita').val()+"&bundle_id="+$('#bundle_id').val()+"&evento_id="+$('#evento_id').val()+"&data_slot="+$('#data_slot').val(),
success: function(data) {
document.location.href=$('#base_url').val()+"registrazione/1";
}
});
});
}
if($('.eventi_container').length>0) {
$.datepicker.setDefaults( $.datepicker.regional[ "en-GB" ] );
$('#filtra_eventi').bind('click',function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: $('#base_url').val()+"ajax/filtra_eventi",
data: "filtro_comune="+$('#filtro_comune').val()+"&filtro_data="+$('#from').val()+","+$('#to').val()+"&filtro_tag="+$('#filtro_tag').val(),
success: function(data) {
if($('#filtro_tag').val() == '0') {
document.location.href=$('#base_url').val()+$('#config_slug').val();
} else {
document.location.href=$('#base_url').val()+$('#config_slug').val()+"/"+$('#filtro_tag').find(":selected").data('slug');
}
}
});
});
$('#reset_filtro_eventi').bind('click',function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: $('#base_url').val()+"ajax/filtra_eventi",
data: "filtro_comune=&filtro_data=&filtro_tag=,",
success: function(data) {
document.location.href=$('#base_url').val()+$('#config_slug').val();
}
});
});
//$('#filtro_data_from').datepicker("option", $.datepicker.regional["de"])
$('#filtro_data_from').datepicker({
altField: "#from",
altFormat: "yy-mm-dd",
onClose: function(selectedDate) {
$( "#filtro_data_to" ).datepicker( "option", "minDate", selectedDate );
}
});
$('#filtro_data_to').datepicker({
altField: "#to",
altFormat: "yy-mm-dd",
regional: "de",
onClose: function(selectedDate) {
$( "#filtro_data_from" ).datepicker( "option", "maxDate", selectedDate );
}
});
}
if($('#cambia_email').length>0) {
$('#cambia_email').validate({
ignore: [],
errorPlacement: function(error, element) {
error.appendTo('#' + element.attr('name')+'-error');
},
rules: {
email: {
remote: {
url: $('#base_url').val()+"ajax/check_email",
type: "post",
data: {
email: function() {
return $( "#email" ).val();
},
id: function() {
return $( "#utente_id" ).val();
},
csfrtok: function () {
return $("#csfrtok").val();
}
}
},
email:true,
required:true
}
},
messages: {
email: {
remote: "Indirizzo email già in uso",
email: "Inserisci un indirizzo email valido",
required: "Inserisci un indirizzo email valido"
}
}
});
}
if($('#cambia_password').length>0) {
$('#cambia_password').validate({
ignore: [],
errorPlacement: function(error, element) {
error.appendTo('#' + element.attr('name')+'-error');
},
rules: {
password_corrente: {
remote: {
url: $('#base_url').val()+"ajax/check_old_password",
type: "post",
data: {
password: function() {
return $( "#password_corrente" ).val();
}
}
},
required:true
}
},
messages: {
password_corrente: {
remote: "Password errata",
required: "Inserisci la tua password attuale"
}
}
});
}
if($('#nuova_password_page').length>0) {
$.validator.addMethod(
"regex",
function(value, element, regexp) {
var check = false;
return this.optional(element) || regexp.test(value);
},
"Please check your input."
);
$('#nuova_password').validate({
ignore: [],
errorPlacement: function(error, element) {
error.appendTo('#' + element.attr('name')+'-error');
},
rules: {
password : {
regex: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/,
minlength : 8,
required:true
},
conferma_password : {
minlength : 8,
equalTo : "#password",
required:true
}
},
messages: {
password: {
regex: "Inserisci una password di minimo 8 caratteri contenente almeno un numero e una maiuscola",
required: "Inserisci una password di minimo 8 caratteri contenente almeno un numero e una maiuscola",
minlength: "Inserisci una password di minimo 8 caratteri contenente almeno un numero e una maiuscola",
},
conferma_password: {
required: "Inserisci una password di minimo 8 caratteri contenente almeno un numero e una maiuscola",
equalTo: "Le password non coincidono",
minlength: "Inserisci una password di minimo 8 caratteri contenente almeno un numero e una maiuscola",
}
}
});
}
/******PAGINE CON OBSERVER SCROLL*******/
if($('#js_scroll_template').length>0) {
/****fade tiny mce****/
$("p").addClass('observer_hide');
const config = {
//root: document.querySelector("#js_hd_cont"),
rootMargin: '-10%',
threshold: [0]
};
const myImgs = document.querySelectorAll('p');
observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
//console.log(entry);
const element = entry.target;
if (entry.intersectionRatio > 0) {
//console.log('in the view');
entry.target.classList.add('observer_show');
entry.target.classList.add('observer_in_view');
observer.unobserve(element);
} else {
//console.log('out of view');
//entry.target.classList.remove('observer_in_view');
//observer.unobserve(element);
}
});
},config);
myImgs.forEach(image => {
observer.observe(image);
});
/****fade elementi plugin con classe js_plugin_scroll_element****/
$('.js_plugin_scroll_element').each(function() {
$(this).addClass('observer_hide');
});
const myElements = document.querySelectorAll('.js_plugin_scroll_element');
observerplugin = new IntersectionObserver(entries => {
entries.forEach(entry => {
//console.log(entry);
const element = entry.target;
if (entry.intersectionRatio > 0) {
//console.log('in the view');
entry.target.classList.add('observer_show');
entry.target.classList.add('observer_in_view');
} else {
//console.log('out of view');
//entry.target.classList.remove('observer_in_view');
//observer.unobserve(element);
}
});
},config);
myElements.forEach(image => {
observerplugin.observe(image);
});
/****lazy loading images in tiny****/
const tinyImgs = document.querySelectorAll('p img');
observertinyimg = new IntersectionObserver(entries => {
entries.forEach(entry => {
//console.log(entry);
const element = entry.target;
if (entry.intersectionRatio > 0) {
//console.log('in the view');
const img = entry.target;
const src = img.getAttribute('data-src');
if(src!=null){
//console.log('url trattato'+src);
img.setAttribute('src', src);
}
observertinyimg.unobserve(element);
}
});
},config);
tinyImgs.forEach(image => {
observertinyimg.observe(image);
});
/****lazy loading images in tiny****/
const pluginImgs = document.querySelectorAll('.plugin_image_lazy');
observerpluginimg = new IntersectionObserver(entries => {
entries.forEach(entry => {
const element = entry.target;
if (entry.intersectionRatio >= 0) {
const img = entry.target;
const src = img.getAttribute('data-src');
img.setAttribute('src', src);
observerpluginimg.unobserve(element);
}
});
},config);
pluginImgs.forEach(image => {
observerpluginimg.observe(image);
});
/****lazy loading images in header_plugin****/
const pluginHeaderImgs = document.querySelectorAll('.plugin_header_image_lazy');
observerpluginheaderimg = new IntersectionObserver(entries => {
entries.forEach(entry => {
const element = entry.target;
if (entry.intersectionRatio >= 0) {
const img = entry.target;
const src = img.getAttribute('data-src');
img.setAttribute('src', src);
observerpluginheaderimg.unobserve(element);
}
});
},config);
pluginHeaderImgs.forEach(image => {
observerpluginheaderimg.observe(image);
});
}
if($('#paginazione_eventi_input').length>0) {
/*const config = {
//root: document.querySelector("#js_hd_cont"),
rootMargin: '-10%',
threshold: [0]
};
const bottomEventiDiv = document.querySelectorAll('.js_paginazione_eventi_div');
observerBottomEventi = new IntersectionObserver(entries => {
entries.forEach(entry => {
const element = entry.target;
console.log(entry.intersectionRatio);
if (entry.isIntersecting) {
alert("bottom");
//observerBottomEventi.unobserve(element);
}
});
},config);
bottomEventiDiv.forEach(image => {
observerBottomEventi.observe(image);
}); */
var chiamata_in_corso=0;
var ricevuto_uno_zero=0;
const el = document.querySelector('#paginazione_eventi_div')
const observer = new window.IntersectionObserver(([entry]) => {
console.log(entry.boundingClientRect.top)
if (entry.isIntersecting) {
//console.log('Enter')
//console.log("VISIBLE") // do things if visible
var filtro_data=$("#filtro_data_paginazione").val();
var filtro_tag=$("#filtro_tag_paginazione").val();
var filtro_comune=$("#filtro_comune_paginazione").val();
var attuale=$("#paginazione_eventi_input").val();
var nuovo=parseInt(attuale)+1;
var eventi_ids_estratti = $('input[name^=eventi_ids]').map(function(idx, elem) {
return $(elem).val();
}).get();
console.log(eventi_ids_estratti);
if(chiamata_in_corso==0 && ricevuto_uno_zero==0 && eventi_ids_estratti.length>=10){
chiamata_in_corso=1;
$("#loader_paginazione").fadeIn(300);
$.ajax({
type: "POST",
url: $('#base_url').val() +"ajax/eventi_paginazione",
data: 'pagina=' + nuovo+"&filtro_data="+filtro_data+"&filtro_comune="+filtro_comune+"&filtro_tag="+filtro_tag+"&eventi_ids_estratti="+eventi_ids_estratti,
success: function(data) {
$("#loader_paginazione").fadeOut(100);
if(data!=""){
$('#paginazione_eventi_input').val(nuovo);
//$('#paginazione_elements').append(data);
$(data).hide().appendTo("#paginazione_elements").fadeIn(1000);
} else {
ricevuto_uno_zero=1;
}
chiamata_in_corso=0;
},
error: function(xhr, status, error) {
$("#loader_paginazione").fadeOut(100);
chiamata_in_corso=0;
},
});
}
return
}
//console.log('Leave')
if (entry.boundingClientRect.top > 0) {
//console.log("BELOW") // do things if below
} else {
//console.log("ABOVE") // do things if above
}
}, {
root: null,
threshold: 0,
})
observer.observe(el);
}
if($('#paginazione_archivio_pasti_input').length>0) {
//////////////////greenforks paginazione archivio///////////////////////////
var chiamata_in_corso_archivio=0;
var ricevuto_uno_zero_archivio=0;
const el_archivio = document.querySelector('#paginazione_archivio_pasti_div')
const observer_archivio = new window.IntersectionObserver(([entry]) => {
console.log(entry.boundingClientRect.top)
if (entry.isIntersecting) {
//console.log('Enter')
//console.log("VISIBLE") // do things if visible
var filtro_data=$("#hidden_filter_date").val();
var attuale=$("#paginazione_archivio_pasti_input").val();
var nuovo=parseInt(attuale)+1;
var pasti_ids_estratti = $('input[name^=archivio_pasti_ids]').map(function(idx, elem) {
return $(elem).val();
}).get();
console.log(pasti_ids_estratti);
if(chiamata_in_corso_archivio==0 && ricevuto_uno_zero_archivio==0 && pasti_ids_estratti.length>=10){
chiamata_in_corso_archivio=1;
$("#loader_paginazione").fadeIn(300);
$.ajax({
type: "POST",
url: $('#base_url').val() +"ajax/archivio_pasti_paginazione",
data: 'pagina=' + nuovo+"&filtro_data="+filtro_data+"&pasti_ids_estratti="+pasti_ids_estratti,
success: function(data) {
$("#loader_paginazione").fadeOut(100);
if(data!=""){
$('#paginazione_archivio_pasti_input').val(nuovo);
//$('#paginazione_elements').append(data);
$(data).hide().appendTo("#paginazione_elements").fadeIn(1000);
} else {
ricevuto_uno_zero_archivio=1;
}
chiamata_in_corso_archivio=0;
},
error: function(xhr, status, error) {
$("#loader_paginazione").fadeOut(100);
chiamata_in_corso_archivio=0;
},
});
}
return
}
//console.log('Leave')
if (entry.boundingClientRect.top > 0) {
//console.log("BELOW") // do things if below
} else {
//console.log("ABOVE") // do things if above
}
}, {
root: null,
threshold: 0,
})
observer_archivio.observe(el_archivio);
////////////////////////////////////////////
}
/*******APP*********/
if($('.js_crea_pasto_1').length>0) {
if($('#mostra_alert_email').length>0) {
alert('[alert_email_crea_pasto]');
}
$('#reset_btn').bind('click',function(e) {
e.preventDefault();
if(confirm('[alert_canellazione_crea_pasto]')) {
$.ajax({
type: "POST",
url: $('#base_url').val()+"ajax/clear_session",
success: function(data) {
document.location.href=$('#base_url').val()+"crea_pasto_1";
}
});
}
});
}
if($('.js_archivio_pasti_1').length>0) {
$('#js_show_filter_button').bind('click',function(e) {
e.preventDefault();
// alert("click");
$('#js_container_filtro').show();
$('#js_show_filter_button').hide();
});
$('#js_reset_date_button').bind('click',function(e) {
e.preventDefault();
// alert("click");
document.location.href=$('#base_url').val()+"archivio_pasti_1";
});
$('#js_chiudi_date_button').bind('click',function(e) {
e.preventDefault();
// alert("click");
$('#js_container_filtro').hide();
$('#js_show_filter_button').show();
});
$('#js_filter_date_button').bind('click',function(e) {
e.preventDefault();
var data_selezionata=$("#hidden_filter_date").val();
document.location.href=$('#base_url').val()+"archivio_pasti_1/"+data_selezionata;
});
document.getElementById('js_date_filter_input').valueAsDate = new Date();
$('#js_date_filter_input').bind('change',function(e) {
e.preventDefault();
var data_selezionata=$("#js_date_filter_input").val();
$('#hidden_filter_date').val(data_selezionata);
});
}
if($('.js_archivio_pasti_2').length>0) {
$('#importa_btn').bind('click',function(e) {
e.preventDefault();
var pasto_archivio=$("#pasto_archivio").val();
$.ajax({
type: "POST",
url: $('#base_url').val()+"ajax/import_from_db_to_session",
data: 'pasto_archivio=' + pasto_archivio,
success: function(data) {
alert("[alert_precompilazione_archivio_2]");
}
});
});
}
/******GDPR*******/
if($('.privacy_policy').length>0) {
}
/************MODAL PLUGIN********************/
if ($("#modal_plugin_container").length){
showModalPlugin();
}
function hideModalPlugin() {
$('#sfondo').remove();
$('#modal_plugin_container').fadeOut();
$('#modal_plugin_container').html("");
}
function showModalPlugin() {
$('body').prepend('');
$('#modal_plugin_container').fadeIn();
$('#sfondo').bind('click',function(e) {
hideModalPlugin();
});
}
$('.open_modal_plugin_modal').each(function() {
$(this).bind('click',function(e) {
e.preventDefault();
showModalPlugin();
});
});
$('.close_modal_plugin_modal').each(function() {
$(this).bind('click',function(e) {
e.preventDefault();
hideModalPlugin();
});
});
$("#non_mostrare_piu_check").bind('change',function(e) {
e.preventDefault();
var id_modal = $(this).data('item');
var status=0;
if (this.checked)
{
status=1;
}
$.ajax({
type: "POST",
url: $('#base_url').val()+"ajax/set_cookie",
data: "id_modal="+id_modal+"&status="+status,
success: function(data){
if(data!=""){
}
}
});
});
/************MODAL PLUGIN********************/
/***QRREG***/
if($('#js_qrreg').length) {
$('#js_submit_form_button').bind('click',function(e) {
// if ($("#js_registrami").prop('checked')==true){
// $('#qrreg_form_reg').submit();
// } else {
// $('#qrreg_form').submit();
// }
$('#qrreg_form').submit();
});
function manageBottomButton(){
if ($("#js_inviami_qr").prop('checked') == false ){
$('#js_submit_form_button').hide();
$('#js_no_submit_form_button').show();
} else {
$('#js_submit_form_button').show();
$('#js_no_submit_form_button').hide();
}
}
$('#js_with_account').bind('click',function(e) {
if ($(this).prop('checked')==true){
var privacyurl=$('#base_url').val()+"privacy_policy";
$('#js_privacy_link').prop('href', privacyurl);
} else {
var privacyurl=$('#base_url').val()+"privacy_policy_lite";
$('#js_privacy_link').prop('href', privacyurl);
}
});
$('#js_inviami_qr').bind('click',function(e) {
if ($(this).prop('checked')==true){
$('#js_inviami_qr').prop('checked', true);
$('#js_registrami').prop('checked', false);
$('#js_privacy_block').hide();
$('#js_send_email_container').show();
$('#js_prendermi_rischio').hide();
} else {
$('#js_inviami_qr').prop('checked', false);
$('#js_send_email_container').hide();
$('#js_prendermi_rischio').show();
}
manageBottomButton();
});
// $('#js_registrami').bind('click',function(e) {
// if ($(this).prop('checked')==true){
// $('#js_inviami_qr').prop('checked', false);
// $('#js_registrami').prop('checked', true);
// $('#js_privacy_block').show();
// $('#js_privacy_lite_block').hide();
// } else {
// $('#js_registrami').prop('checked', false);
// $('#js_privacy_block').hide();
// }
// manageBottomButton();
// });
$('#qrreg_form').validate({
ignore: [],
errorPlacement: function(error, element) {
error.appendTo('#' + element.attr('name')+'-error');
},
rules: {
email_field: {
remote: {
url: $('#base_url').val()+"ajax/check_email_anon",
type: "post",
data: {
email: function() {
return $('#email_field').val();
},
csfrtok: function () {
return $("#csfrtok").val();
}
}
},
email:true,
required:true
},
privacy_check_lite: {
required: function () {
if ($("#js_inviami_qr").prop('checked') == true){
return true;
} else {
return false;
}
}
},
},
messages: {
email_field: {
remote: "La mail inserita corrisponde ad un account esistente",
email: "Inserisci una mail valida",
required: "Inserisci una mail valida"
},
privacy_check_lite: {
required: "Devi accettare la privacy policy"
},
},
});
// $('#qrreg_form_reg').validate({
// ignore: [],
// errorPlacement: function(error, element) {
// error.appendTo('#' + element.attr('name')+'-error');
// },
// rules: {
// email_field_reg: {
// remote: {
// url: $('#base_url').val()+"ajax/check_email_anon",
// type: "post",
// data: {
// email: function() {
// return $('#email_field_reg').val();
// },
// csfrtok: function () {
// return $("#csfrtok").val();
// }
// }
// },
// email:true,
// required:true
// },
// privacy_check: {
// required: function () {
// if ($("#js_registrami").prop('checked') == true){
// return true;
// } else {
// return false;
// }
// }
// }
// },
// messages: {
// email_field_reg: {
// remote: "La mail inserita corrisponde ad un account esistente",
// email: "Inserisci una mail valida",
// required: "Inserisci una mail valida"
// },
// privacy_check: {
// required: "Devi accettare la privacy policy"
// }
// },
// });
}
/***QRWEBV***/
if($('#js_qrwebv').length) {
function selectedNumber(){
var selected=0;
$('.js_bonus').each(function() {
if($(this).hasClass('js_sel_class')){
selected++;
}
});
return selected;
}
function clearSelections(){
$('.js_bonus').each(function() {
$(this).addClass('js_unsel_class').removeClass('js_sel_class');
var id_promozione = $(this).data('bo');
var selected_view_id="#js_selected_view_"+id_promozione;
$(selected_view_id).hide();
$("#js_bon_hid").val(0);
$("#js_bontop_hid").val(0);
});
}
$('.js_bonus').bind('click',function(e) {
e.preventDefault();
$('.js_bonus').addClass('js_unsel_class').removeClass('js_sel_class');
var id_promozione = $(this).data('bo');
var id_promozionetop = $(this).data('botop');
var selected_view_id="#js_selected_view_"+id_promozione;
clearSelections();
if($(this).hasClass('js_unsel_class')){
$(this).addClass('js_sel_class').removeClass('js_unsel_class');
$(selected_view_id).show();
var stringid="bon_hid_"+id_promozione;
$("#js_bon_hid").val(id_promozione);
var stringid="bontop_hid_"+id_promozionetop;
$("#js_bontop_hid").val(id_promozionetop);
} else {
$(this).addClass('js_unsel_class').removeClass('js_sel_class');
$(selected_view_id).hide();
}
var selected=selectedNumber();
if(selected>0){
$('#js_attiva_btn').show();
}
});
/*if($('#qrurl').length > 0) { //esiste un qr
var url=$("#qrurl").val();
$.ajax({
url : url,
cache: true,
processData : false,
}).always(function(){
$("#qr_code_img").attr("src", url).fadeIn();
});
}*/
}
/***QRIMG***/
if($('#js_qrimg').length) {
// $("#forcedownload").bind('click', function (e) {
// var qr = $(this).data("qr");
// var unid = $(this).data("unid");
// //var href = $(this).attr('href');
// $.ajax({
// url: $('#base_url').val() + "qrwebvdownload/" + qr + "/" + unid + "",
// success: function (data) {
// var pdfurl = $('#base_url').val() + "contents/temp/" + unid + ".pdf";
// fetch(pdfurl) // Replace with your file URL
// .then(response => response.blob())
// .then(blob => {
// let link = document.createElement("a");
// link.href = window.URL.createObjectURL(blob);
// link.download = "downloaded-file.pdf"; // Force download name
// document.body.appendChild(link);
// link.click();
// document.body.removeChild(link);
// })
// .catch(error => console.error("Download failed:", error));
// // document.location.href=href;
// }
// });
// });
$('#js_download_pdf_btn').bind('click',function(e) {
e.preventDefault();
$("#js_container_after_download").show();
$("#js_page_big_container").hide();
var ua = navigator.userAgent;
// alert(ua);
var isIOS = /iPad|iPhone|iPod/.test(ua);
var isSafari = isIOS && ua.includes("Safari") && !ua.includes("CriOS") && !ua.includes("FxiOS") ;
if ( isSafari) {
$("#js_container_after_download_safari_text").show();
$("#js_container_after_download_standard_text").hide();
$(window).scrollTop(0);
} else {
$(window).scrollTop(0);
var url=$("#js_download_pdf_btn").attr('href');
document.location.href=url;
}
});
var vimeourl=$("#js_vimeo_iframe").attr('src');
if(vimeourl!=""){
const iframe = document.querySelector('iframe');
const player = new Vimeo.Player(iframe);
/* player.on('fullscreenchange', function(data) {
console.log("FULLSCREEN CHANGE");
});*/
$('iframe').on('fullscreenchange webkitfullscreenchange mozfullscreenchange', function() {
var check_fullscreen = document.fullscreenElement !== this;
if(check_fullscreen){
player.unload();
$('#js_vimeo_player_container').hide();
$('#js_page_big_container').fadeIn(500);
}
});
$('#js_play_btn').bind('click',function(e) {
e.preventDefault();
$('#js_page_big_container').fadeOut(500);
$('#js_vimeo_player_container').fadeIn(500);
player.play();
///richiesta di fullscreen, per adesso non utilizzata
player.requestFullscreen().then(function() {
}).catch(function(error) {
// an error occurred
});
});
$('#js_close_play_btn').bind('click',function(e) {
e.preventDefault();
player.unload();
$('#js_page_big_container').fadeIn(500);
$('#js_vimeo_player_container').fadeOut(500);
});
}
function hideModalPdf() {
$('#sfondo').remove();
$('#js_modal_pdf').fadeOut();
$('#js_modal_pdf_list').html("");
}
$('#js_open_popup_pdf').bind('click',function(e) {
e.preventDefault();
$('#js_modal_pdf').fadeIn();
//sfondo
$('body').prepend('');
$('#sfondo').bind('click',function(e) {
hideModalPdf();
});
$('#js_chiudi_modal_pdf').bind('click',function(e) {
hideModalPdf();
});
});
function hideModalBooking() {
$('#sfondo').remove();
$('#js_modal_booking').fadeOut();
}
$('#js_open_popup_booking').bind('click',function(e) {
e.preventDefault();
$('#js_modal_booking').fadeIn();
//sfondo
$('body').prepend('');
$('#sfondo').bind('click',function(e) {
hideModalBooking();
});
$('#js_chiudi_modal_booking').bind('click',function(e) {
hideModalBooking();
});
});
/***** QRREG ****/
$('#js_submit_form_button').bind('click',function(e) {
$('#qrreg_form').submit();
});
function manageBottomButton(){
if ($("#js_inviami_qr").prop('checked') == false ){
$('#js_submit_form_button').hide();
$('#js_no_submit_form_button').show();
} else {
$('#js_submit_form_button').show();
$('#js_no_submit_form_button').hide();
}
}
$('#js_with_account').bind('click',function(e) {
if ($(this).prop('checked')==true){
var privacyurl=$('#base_url').val()+"privacy_policy";
$('#js_privacy_link').prop('href', privacyurl);
} else {
var privacyurl=$('#base_url').val()+"privacy_policy_lite";
$('#js_privacy_link').prop('href', privacyurl);
}
});
$('#js_nomail_text').bind('click',function(e) {
$(window).scrollTop(0);
});
$('#js_inviami_qr').bind('click',function(e) {
if ($(this).prop('checked')==true){
$('#js_inviami_qr').prop('checked', true);
$('#js_registrami').prop('checked', false);
$('#js_privacy_block').hide();
$('#js_send_email_container').show();
} else {
$('#js_inviami_qr').prop('checked', false);
$('#js_send_email_container').hide();
}
manageBottomButton();
});
$('#js_back_btn').bind('click',function(e) {
e.preventDefault();
$("#js_container_after_download").hide();
$("#js_page_big_container").show();
});
$('#qrreg_form').validate({
ignore: [],
errorPlacement: function(error, element) {
error.appendTo('#' + element.attr('name')+'-error');
},
rules: {
email_field: {
remote: {
url: $('#base_url').val()+"ajax/check_email_anon",
type: "post",
data: {
email: function() {
return $('#email_field').val();
},
csfrtok: function () {
return $("#csfrtok").val();
}
}
},
email:true,
required:true
},
privacy_check_lite: {
// required: function () {
// if ($("#js_inviami_qr").prop('checked') == true){
// return true;
// } else {
// return false;
// }
// }
required:true
},
},
messages: {
email_field: {
remote: "La mail inserita corrisponde ad un account esistente",
email: "Inserisci una mail valida",
required: "Inserisci una mail valida"
},
privacy_check_lite: {
required: "Devi accettare la privacy policy"
},
},
submitHandler: function(form) {
//alert("Do some stuff...");
//$('body').prepend('');
$('#js_container_qrreg').hide();
$('#js_container_qrreg_loader').fadeIn();
var with_account=0;
if($('#js_with_account').is(":checked") ){
with_account=1;
}
var csfrtok=$("#csfrtok").val();
var email=$('#email_field').val();
var id_promozione_slave=$('#promslv').val();
$.ajax({
url: $('#base_url').val() + "ajax/subqrreg",
type: 'POST',
data: 'csfrtok=' + csfrtok+"&em="+email+"&promslv="+id_promozione_slave+"&with_account="+with_account,
success: function (data) {
$('#js_container_qrreg_loader').hide();
$('#js_container_qrreg_saved').show();
$('#js_nomail_text').hide();
$('#js_nomail_text').hide();
$('#js_importante_leggere').hide();
$('#js_send_email_container').hide();
$('#js_submit_form_button').hide();
}
});
//submit via ajax
return false; //This doesn't prevent the form from submitting.
}
});
/***** QRREG ****/
}
/***QRLPA***/
if($('#js_qrlpa').length) {
$('#js_save_lpa').bind('click',function(e) {
e.preventDefault();
var checked=0;
var checkedval;
$('.js_risp_check').each(function() {
if ($(this).prop('checked')==true){
checked++;
checkedval=$(this).val();
}
});
if(checked>0){
var id_promozione=$('#js_prom').val();
var id_sca=$('#js_id_sca').val();
var id_lpa=$('#js_id_lpa').val();
var qr=$('#js_qr').val();
/* if(id_sca>0){
var url=$('#base_url').val()+"qrsca/"+qr+"/"+id_promozione+"/"+checkedval;
document.location.href=url;
} else {
var url=$('#base_url').val()+"qrwebv/"+qr+"/"+id_promozione+"/"+checkedval;
document.location.href=url;
}*/
$("#qrlpa_form").submit();
} else {
alert("seleziona una risposta");
}
});
$('.js_risp_check').bind('click',function(e) {
//deseleziona
$('#js_risp_1_check').prop('checked', false);
$('#js_risp_2_check').prop('checked', false);
$('#js_risp_3_check').prop('checked', false);
$('#js_risp_4_check').prop('checked', false);
$('#js_risp_5_check').prop('checked', false);
//seleziona
$(this).prop('checked', true);
//opacity
$('#js_save_lpa').css('opacity','1');
});
}
/***QRSCA***/
if($('#js_qrsca').length) {
$('#js_save_sca').bind('click',function(e) {
e.preventDefault();
var checked=0;
var checkedval;
$('.js_risp_check').each(function() {
if ($(this).prop('checked')==true){
checked++;
checkedval=$(this).val();
}
});
if(checked>0){
var id_promozione=$('#js_prom').val();
var id_sca=$('#js_id_sca').val();
var id_lpa=$('#js_id_lpa').val();
var qr=$('#js_qr').val();
/* var url=$('#base_url').val()+"qr/"+qr+"/"+id_promozione+"/"+checkedval;
document.location.href=url;*/
$("#qrsca_form").submit();
} else {
alert("seleziona una risposta");
}
});
$('.js_risp_check').bind('click',function(e) {
//deseleziona
$('#js_risp_1_check').prop('checked', false);
$('#js_risp_2_check').prop('checked', false);
$('#js_risp_3_check').prop('checked', false);
$('#js_risp_4_check').prop('checked', false);
$('#js_risp_5_check').prop('checked', false);
//seleziona
$(this).prop('checked', true);
//opacity
$('#js_save_sca').css('opacity','1');
});
}
});
function setLang(lang,redirect) {
$.ajax({
url: $('#base_url').val() + "ajax/set_lang",
type: 'POST',
data: 'lang=' + lang,
success: function (data) {
$('#lang').val(data);
if(redirect == 1) {
document.location.href=document.location.href;
}
}
});
}