//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");
$.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: "I cookies servono a migliorare i servizi che offriamo e a ottimizzare l\'esperienza dell\'utente. Per saperne di piú accedi alla cookie policy.
Se chiudi il presente banner o prosegui la navigazione del sito, acconsenti all\'utilizzo dei cookie.
",
acceptText: "Ok, chiudi banner",
policyURL: cookie_url,
cookieName: actual_key
});
}
});
$("img.lazy").lazyload({
effect : "fadeIn",
skip_invisible : false
});
$("div.lazy").lazyload({
effect : "fadeIn"
});
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: "Indirizzo email già in uso",
email: "Inserisci un indirizzo email valido",
required: "Inserisci un indirizzo email valido"
},
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({
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",
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();
}
}
},
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"
}
}
});
}
/******GDPR*******/
if($('#manage_privacy').length>0) {
$('#edit_policy').validate({
ignore: [],
errorPlacement: function(error, element) {
error.appendTo('#' + element.attr('name')+'-error');
},
rules: {
privacy_policy_check: {
required:true
}
},
messages: {
privacy_policy_check: {
required: "Attenzione, per poterti registrare devi aver letto l\'informativa privacy e acconsentire al trattamento dei tuoi dati."
}
}
});
$('#x_btn_marketing').bind('click',function(e) {
e.preventDefault();
$("#container_marketing_checkbox").show();
$("#container_label_marketing").hide();
$('#marketing_check').attr('checked', false);
});
$('#x_btn_newsletter').bind('click',function(e) {
e.preventDefault();
$("#container_newsletter_checkbox").show();
$("#container_label_newsletter").hide();
$('#newsletter_check').attr('checked', false);
});
}
/****HEADER***/
if($('#menu_laterale').length>0) {
$('#navigation_menu').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;
}
});
});
});
$('.menu_btn').bind('click',function(e) {
e.preventDefault();
if(!$('#menu_laterale').hasClass('open')) {
$('#menu_laterale').animate({'right':'0'},500,function() {
$('#menu_laterale').addClass('open');
});
$('body').prepend('');
$('#sfondo').bind('click',function() {
$('#sfondo').remove();
if($('#menu_laterale').hasClass('open')) {
$('#menu_laterale').animate({'right': '-270px'}, 500, function () {
$('#menu_laterale').removeClass('open');
});
}
});
} else {
$('#sfondo').remove();
if($('#menu_laterale').hasClass('open')) {
$('#menu_laterale').animate({'right': '-270px'}, 500, function () {
$('#menu_laterale').removeClass('open');
});
}
}
});
}
/****FORMS*****/
if(genericForm == 1) {
$('form').each(function() {
$(this).validate({
ignore: [],
errorPlacement: function(error, element) {
error.appendTo('#' + element.attr('name')+'-error');
}
});
});
}
});
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;
}
}
});
}