$(function () {
var pickups = null;
var calendar_rgba = Helpers.convertHex(getComputedStyle(document.documentElement).getPropertyValue('--primary-color-st'), 0.35);
document.documentElement.style.setProperty('--box-shadow-color', '0 15px 20px -3px ' + calendar_rgba);
$('.calendar__date--avaiable').click(function () {
selectDay($(this));
});
function selectDay(element) {
$(".calendar__date--selected-only").removeClass("calendar__date--selected-only");
$(element).addClass('calendar__date--selected-only');
var dateSelected = $(element).attr('date');
$('.calendar-search-result').html('');
$('.calendar-search-result').append('
Seleziona\u0020il\u0020numero\u0020di\u0020biglietti Seleziona\u0020il\u0020numero\u0020di\u0020biglietti\u0020e\u0020clicca\u0020\u0022calcola\u0020quotazione\u0022\u0020per\u0020procedere ');
$('.calendar__dates').append('Caricamento\u0020calendario\u0020in\u0020corso
');
$.get('/it/calendar/day-detail', {
productId: productID,
date: dateSelected
}, function (res) {
$('.calendar__on-loading').remove();
if (res.length > 0 && typeof res[0].is_seated != 'undefined' && res[0].is_seated) {
$('.calendar-search-result').append('');
}
for (var i = 0; i < res.length; i++) {
var price = "";
var explanation = "";
if (res[i].price != null) price = '' + res[i].price + ' € ';
if (res[i].explanation != null) explanation = '' + res[i].explanation + '
';
var ticketCalendarElement = '' +
'
' +
'
' + res[i].descr + ' ' + explanation +
'' +
'
' + price +
'
' +
'- ' +
' ' +
'+ ' +
'
' +
'
' +
'
';
$('.calendar-search-result').append(ticketCalendarElement);
}
if (res.length > 0) {
$('.calendar-search-result').append('Calcola\u0020quotazione ');
$(".calendar-search-result").find('h4').text('Data\u0020selezionata: ' + Helpers.convertDateToIta(dateSelected));
$('.request-quote').click(requestQuote);
} else {
$('.calendar-search-result').html("Non\u0020ci\u0020sono\u0020prodotti\u0020per\u0020la\u0020data\u0020selezionata
");
}
$('html,body').animate({
scrollTop: $('.calendar-search-result').offset().top - 30
}, 'slow');
});
}
var months = [
"Gennaio",
"Febbraio",
"Marzo",
"Aprile",
"Maggio",
"Giugno",
"Luglio",
"Agosto",
"Settembre",
"Ottobre",
"Novembre",
"Dicembre"
];
var today = new Date();
var currentYear = today.getFullYear();
var currentMonth = today.getMonth();
$.each(months, function (i, item) {
var selected = currentMonth === i ? 'selected' : '';
$('#calendar__month').append('' + item + ' ');
});
for (var a = 0; a < 3; a++) {
var selected = a == 0 ? 'selected' : '';
$('#calendar__year').append('' + currentYear + ' ');
currentYear++;
}
currentYear = today.getFullYear();
if (typeof avaiableDays != "undefined") {
var firstAvaiableDay = new Date(avaiableDays[0].date);
currentYear = firstAvaiableDay.getFullYear();
currentMonth = firstAvaiableDay.getMonth();
var avDayLength = avaiableDays.length;
if (new Date(avaiableDays[0].date).getMonth() === new Date(avaiableDays[avDayLength - 1].date).getMonth())
$('.calendar__opts').hide();
$('#calendar__month').val(currentMonth);
$('#calendar__year').val(currentYear);
renderCalendar(currentMonth, currentYear);
} else {
renderCalendar(currentMonth, currentYear);
}
function daysInMonth(month, year) {
month++;
return new Date(year, month, 0).getDate();
}
function renderCalendar(month, year) {
month = parseInt(month);
year = parseInt(year);
$('.calendar__dates').html('');
var startWeek = dayOfWeek(1, month, year);
var differece = 7 - startWeek;
//Mese precedente
if (startWeek != 0) {
var lastMonthStartDay = daysInMonth(month - 1, year) - startWeek;
for (var a = lastMonthStartDay; a < daysInMonth(month - 1, year); a++) {
$('.calendar__dates').append('' + (lastMonthStartDay + 1) + '
');
lastMonthStartDay++;
}
}
//Mese corrente
var closeOnSunday = false;
var daysInCurrentMonth = daysInMonth(month, year);
for (var b = 0; b < daysInCurrentMonth; b++) {
$('.calendar__dates').append('' + (b + 1) + '
');
}
var closingMontDay = dayOfWeek(daysInCurrentMonth, month, year);
//Mese successivo
if (closingMontDay !== 6) {
var succMonthStartDay = 1;
for (var c = closingMontDay; c < 6; c++) {
$('.calendar__dates').append('' + succMonthStartDay + '
');
succMonthStartDay++;
}
}
$('.calendar__dates').append('Caricamento\u0020calendario\u0020in\u0020corso
');
if (typeof avaiableDays != "undefined") {
for (var i = 0; i < avaiableDays.length; i++) {
if (new Date(avaiableDays[i].date).getMonth() == month) {
var elements = $(".calendar__date--close > span:contains(" + (new Date(avaiableDays[i].date).getDate()) + ")");
if (elements.length > 1) {
for (var a = 0; a < elements.length; a++) {
var text = $(elements[a]).text();
var day = new Date(avaiableDays[i].date).getDate();
if (text == day) {
$(elements[a]).parent().removeClass('calendar__date--close');
$(elements[a]).parent().addClass('calendar__date--avaiable');
$(elements[a]).parent().attr('date', Helpers.formatDate(new Date(year, month, (new Date(avaiableDays[i].date).getDate()))));
}
}
} else {
$(elements).parent().removeClass('calendar__date--close');
$(elements).parent().addClass('calendar__date--avaiable');
$(elements).parent().attr('date', Helpers.formatDate(new Date(year, month, (new Date(avaiableDays[i].date).getDate()))));
}
}
}
$('.calendar__date--avaiable').click(function () {
selectDay($(this));
});
$('.calendar__on-loading').remove();
} else {
//Carico disponibilità
$.get('/it/calendar/available-days', {
productId: productID,
startDate: Helpers.formatDate(new Date(year, month, 1)),
endDate: Helpers.formatDate(new Date(year, month + 1, 0))
}, function (res) {
$('.calendar__on-loading').remove();
for (var i = 0; i < res.length; i++) {
var elements = $(".calendar__date--close > span:contains(" + (new Date(res[i].date).getDate()) + ")");
if (elements.length > 1) {
for (var a = 0; a < elements.length; a++) {
var text = $(elements[a]).text();
var day = new Date(res[i].date).getDate();
if (text == day) {
$(elements[a]).parent().removeClass('calendar__date--close');
$(elements[a]).parent().addClass('calendar__date--avaiable');
$(elements[a]).parent().attr('date', Helpers.formatDate(new Date(year, month, (new Date(res[i].date).getDate()))));
}
}
} else {
$(elements).parent().removeClass('calendar__date--close');
$(elements).parent().addClass('calendar__date--avaiable');
$(elements).parent().attr('date', Helpers.formatDate(new Date(year, month, (new Date(res[i].date).getDate()))));
}
}
$('.calendar__date--avaiable').click(function () {
selectDay($(this));
});
}).fail(function () {
$('.calendar__on-loading').remove();
$('.calendar__dates').append('Impossibile\u0020verificare\u0020disponibilit\u00E0
');
});
}
}
function dayOfWeek(day, month, year) {
return new Date(year, month, day).getDay() === 0 ? 6 : new Date(year, month, day).getDay() - 1;
}
function requestQuote() {
$('.request-quote').prop('disabled', true);
var products = [];
$('input[name^=qty]').each(
function () {
if ($(this).val() > 0) {
products.push({
'id': $(this).attr('data-product-id'),
'qty': $(this).val()
})
}
}
);
$('.calendar-quotation').empty();
$.ajax({
url: '/it/calendar/quote',
contentType: "application/json; charset=utf-8",
dataType: "json",
method: "POST",
data: JSON.stringify({
date: $('.calendar__date--selected-only').attr('date').toString(),
productId: productID,
products: products,
lang: "it"
})
}).done(function (res) {
$('.calendar-quotation').empty();
var quoteElements = '';
$(res).each(
function (index) {
/*var bookingCode = "";*/
var checked = "";
if (index == 0) checked = "checked";
var subDescr = "";
if (typeof this.subDescr != 'undefined' && this.subDescr != null) subDescr = "
" + this.subDescr + "
";
if (this.times.length > 0) {
var that = this;
$(this.times).each(
function (index) {
quoteElements += '
' +
'
' +
'
' +
'' +
'
' + Helpers.formatDayMont(that.date) + '
' +
'
' + Helpers.formatYear(that.date) + '
' +
'
' + this + '
' +
'
' +
'' +
'
' + that.descr + '
' +
'
' + that.total + ' €
' +
subDescr +
'
' +
' ' +
'
';
}
);
} else {
quoteElements += '
' +
'
' +
'
' +
'' +
'
' + Helpers.formatDayMont(this.date) + '
' +
'
' + Helpers.formatYear(this.date) + '
' +
'
' +
'' +
'
' + this.descr + '
' +
'
' + this.total + ' €
' +
subDescr +
'
' +
' ' +
'
';
}
}
);
quoteElements += '
';
$('.calendar-quotation').append('Effettua\u0020una\u0020selezione Il\u0020prezzo\u0020mostrato\u0020\u00E8\u0020complessivo\u0020per\u0020i\u0020biglietti\u0020richiesti ');
$('.calendar-quotation').append(quoteElements);
$('.request-quote').text('Modifica\u0020quotazione');
if (typeof avaiableDays != "undefined") {
if (pickupType == "M")
$('.calendar-quotation').append('Continua\u0020con\u0020la\u0020scelta\u0020del\u0020pickup ');
else if (pickupType == "O")
$('.calendar-quotation').append('Conferma\u0020selezione\u0020senza\u0020pickup - Oppure -
Seleziona\u0020un\u0020pickup ');
else
$('.calendar-quotation').append('Conferma\u0020selezione\u0020e\u0020mostra\u0020hotel ');
} else {
if (pickupType == "M")
$('.calendar-quotation').append('Continua\u0020con\u0020la\u0020scelta\u0020del\u0020pickup ');
else if (pickupType == "O")
$('.calendar-quotation').append('Conferma\u0020selezione\u0020senza\u0020pickup - Oppure -
Seleziona\u0020un\u0020pickup ');
else
$('.calendar-quotation').append('Conferma\u0020selezione\u0020e\u0020acquista ');
}
$('.get-pickup').click(function () {
requestPickups()
});
$('.store-cart').click(function () {
storeCart()
});
$('.store-package').click(function () {
storePackage()
});
$('html,body').animate({
scrollTop: $('.calendar-quotation').offset().top - 30
}, 'slow');
}).fail(function (res) {
nascondiLoader();
var errorMessage = "Unexpected error";
if (res.status == 400) errorMessage = res.responseJSON.error;
$.notify({
message: " " + errorMessage,
}, {
type: 'danger',
allow_dismiss: true,
delay: 5000
});
}).always(function () {
$('.request-quote').prop('disabled', false);
});
}
function requestPickups() {
$('.pickup-quotation').empty();
$.ajax({
url: '/it/calendar/pickups?rateKey=' + $('input[name="quotation"]:checked').val(),
contentType: "application/json; charset=utf-8",
dataType: "json",
method: "GET"
}).done(function (res) {
$('.pickup-quotation').empty();
pickups = res;
var pickupsElement = '';
$(res).each(
function (index) {
pickupsElement += '' + res[index].name + (res[index].time == null ? '' : ' - ' + res[index].time) + ' '
}
);
pickupsElement += ' ';
$('.pickup-quotation').append('Seleziona\u0020un\u0020pickup Seleziona\u0020un\u0020pickup\u0020e\u0020un\u0020orario ');
$('.pickup-quotation').append(pickupsElement);
var pickup = res[0];
var pickupinfo = "";
if (pickup.name != null) pickupinfo += "
Nome\u0020pickup: " + pickup.name + " ";
if (pickup.description != null) pickupinfo += "
Descrizione: " + pickup.description + " ";
if (pickup.address != null) pickupinfo += "
Indirizzo: " + pickup.address + " ";
if (pickup.city != null) pickupinfo += "
Citt\u00E0: " + pickup.city + " ";
if (pickup.postcode != null) pickupinfo += "
CAP: " + pickup.postcode + " ";
if (pickup.time != null) pickupinfo += "
Orario: " + pickup.time + " ";
if (pickup.total != null) pickupinfo += "
Importo\u0020totale\u0020pickup: " + pickup.total + " € ";
pickupinfo += "
";
$('.pickup-select').after(pickupinfo);
if (typeof avaiableDays != "undefined") {
$('.pickup-quotation').append('Conferma\u0020selezione\u0020e\u0020mostra\u0020hotel ');
} else {
$('.pickup-quotation').append('Conferma\u0020selezione\u0020e\u0020acquista ');
}
$('.pickup-store-cart').click(function () {
storeCart();
});
$('.pickup-select').change(function () {
showPickInfo($(this).val());
});
$('.pickup-store-package').click(function () {
storePackage();
});
$('html,body').animate({
scrollTop: $('.pickup-quotation').offset().top - 30
}, 'slow');
}).fail(function (res) {
nascondiLoader();
var errorMessage = "Unexpected error";
if (res.status == 400) errorMessage = res.responseJSON.error;
$.notify({
message: " " + errorMessage,
}, {
type: 'danger',
allow_dismiss: true,
delay: 5000
});
}).always(function () {
//$('.request-quote').prop('disabled', false);
});
}
function showPickInfo(pickupKey) {
$(".pick-up-info").remove();
var pickup = null;
$(pickups).each(
function (index) {
if (pickups[index].pickupKey == pickupKey) pickup = pickups[index];
}
);
var pickupinfo = "";
if (pickup.name != null) pickupinfo += "
Nome\u0020pickup: " + pickup.name + " ";
if (pickup.description != null) pickupinfo += "
Descrizione: " + pickup.description + " ";
if (pickup.address != null) pickupinfo += "
Indirizzo: " + pickup.address + " ";
if (pickup.city != null) pickupinfo += "
Citt\u00E0: " + pickup.city + " ";
if (pickup.postcode != null) pickupinfo += "
CAP: " + pickup.postcode + " ";
if (pickup.time != null) pickupinfo += "
Orario: " + pickup.time + " ";
if (pickup.total != null) pickupinfo += "
Importo\u0020totale\u0020pickup: " + pickup.total + " € ";
pickupinfo += "
";
$('.pickup-select').after(pickupinfo);
}
$('#calendar__month').on('change', function () {
var month = $(this).find(":selected").val();
var year = $('#calendar__year').find(":selected").val();
renderCalendar(month, year);
});
$('#calendar__year').on('change', function () {
var month = $('#calendar__month').find(":selected").val();
var year = $(this).find(":selected").val();
renderCalendar(month, year);
});
});