$(function () {
var pickups = null;
var timeKey = null;
var timeSelected = 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, reset = true) {
if (reset) {
$(".calendar__date--selected-only").removeClass("calendar__date--selected-only");
$('.ticket-container').remove();
$('.request-quote').remove();
}
$(element).addClass('calendar__date--selected-only');
var dateSelected = $(element).attr('date');
timeKey = $(element).attr('timeKey') === undefined ? null : $(element).attr('timeKey');
timeSelected = $(element).attr('timeSelected') === undefined ? null : $(element).attr('timeSelected');
$('.calendar-search-result h4').html('');
$('.calendar-search-result .subtitle').html('');
$('.calendar__dates').append('
Loading\u0020calendar
');
$.get('/en/calendar/day-detail', {
productId: productID,
date: dateSelected,
timeKey: timeKey
}, function (res) {
$('.calendar-times-area').remove();
$('.calendar__on-loading').remove();
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);
}
$(".calendar-search-result").find('h4').text('Selected\u0020date: ' + Helpers.convertDateToIta(dateSelected));
if (timeSelected != null) {
$(".calendar-search-result").find('h4').append(' Selected\u0020time: ' + timeSelected);
}
if (res.times !== undefined && (res.times.morning.length > 0 || res.times.afternoon.length > 0 || res.times.evening.length > 0 || res.times.night.length > 0)) {
$('.calendar-search-result').append('
');
$('.calendar-search-result').find('.subtitle').text('Select\u0020a\u0020time');
for (var a = 0; a < res.times.morning.length; a++) {
if (a === 0)
$('.calendar-times-area').append("Morning ");
var timeCalendarElement = '' + res.times.morning[a].value + ' ';
$('.calendar-times-area').append(timeCalendarElement);
}
for (var b = 0; b < res.times.afternoon.length; b++) {
if (b === 0)
$('.calendar-times-area').append("Afternoon ");
var timeCalendarElement = '' + res.times.afternoon[b].value + ' ';
$('.calendar-times-area').append(timeCalendarElement);
}
for (var c = 0; c < res.times.evening.length; c++) {
if (c === 0)
$('.calendar-times-area').append("Evening ");
var timeCalendarElement = '' + res.times.evening[c].value + ' ';
$('.calendar-times-area').append(timeCalendarElement);
}
for (var d = 0; d < res.times.night.length; d++) {
if (d === 0)
$('.calendar-times-area').append("Night ");
var timeCalendarElement = '' + res.times.night[d].value + ' ';
$('.calendar-times-area').append(timeCalendarElement);
}
$('.calendar-times-button').click(function () {
selectDay($(this), false);
});
} else {
if (res.length > 0) {
$('.calendar-search-result').find('.subtitle').text('Select\u0020the\u0020number\u0020of\u0020tickets\u0020and\u0020click\u0020\u0022calculate\u0020price\u0022\u0020to\u0020proceed');
if (typeof res[0].is_seated != 'undefined' && res[0].is_seated) {
$('.calendar-search-result').find('.subtitle').append(' By\u0020selecting\u0020your\u0020tickets\u0020below\u0020you\u0020will\u0020be\u0020assigned\u0020the\u0020best\u0020seat\u0020available');
$('.calendar-search-result').find('.subtitle').append('Press\u0020here\u0020if\u0020you\u0020prefer\u0020to\u0020select\u0020places\u0020from\u0020the\u0020map ');
}
$('.calendar-search-result').append('Calculate\u0020quote ');
$('.request-quote').click(requestQuote);
} else {
$(".calendar-search-result").find('h4').html("There\u0020are\u0020no\u0020products\u0020for\u0020the\u0020selected\u0020date
");
}
}
$('html,body').animate({
scrollTop: $('.calendar-search-result').offset().top - 30
}, 'slow');
});
}
var months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
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('Loading\u0020calendar
');
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('/en/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('Unable\u0020to\u0020check\u0020availability
');
});
}
}
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: '/en/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",
timeKey: timeKey
})
}).done(function (res) {
$('.calendar-quotation').empty();
$('.calendar-quotation').append(' ');
$('.calendar-quotation').append(' ');
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').find('h4').text('Make\u0020a\u0020selection');
$('.calendar-quotation').find('.subtitle').text('The\u0020price\u0020shown\u0020is\u0020total\u0020for\u0020the\u0020tickets\u0020requested');
$('.calendar-quotation').append(quoteElements);
$('.request-quote').text('Modify\u0020quote');
if (typeof avaiableDays != "undefined") {
if (pickupType == "M")
$('.calendar-quotation').append('Continue\u0020with\u0020your\u0020pickup\u0020choice ');
else if (pickupType == "O")
$('.calendar-quotation').append('Confirm\u0020selection\u0020without\u0020pickup - Or -
Select\u0020a\u0020pickup ');
else
$('.calendar-quotation').append('Confirm\u0020selection\u0020and\u0020show\u0020hotel ');
} else {
if (pickupType == "M")
$('.calendar-quotation').append('Continue\u0020with\u0020your\u0020pickup\u0020choice ');
else if (pickupType == "O")
$('.calendar-quotation').append('Confirm\u0020selection\u0020without\u0020pickup - Or -
Select\u0020a\u0020pickup ');
else
$('.calendar-quotation').append('Confirm\u0020selection\u0020and\u0020buy ');
}
$('.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: '/en/calendar/pickups?rateKey=' + $('input[name="quotation"]:checked').val(),
contentType: "application/json; charset=utf-8",
dataType: "json",
method: "GET"
}).done(function (res) {
$('.pickup-quotation').empty();
$('.pickup-quotation').append(' ');
$('.pickup-quotation').append(' ');
pickups = res;
var pickupsElement = '';
$(res).each(
function (index) {
pickupsElement += '' + res[index].name + (res[index].time == null ? '' : ' - ' + res[index].time) + ' '
}
);
pickupsElement += ' ';
$('.pickup-quotation').find('h4').text('Select\u0020a\u0020pickup');
$('.pickup-quotation').find('.subtitle').text('Select\u0020a\u0020pickup\u0020and\u0020time');
$('.pickup-quotation').append(pickupsElement);
var pickup = res[0];
var pickupinfo = "";
if (pickup.name != null) pickupinfo += "
Pickup\u0020name: " + pickup.name + " ";
if (pickup.description != null) pickupinfo += "
Description: " + pickup.description + " ";
if (pickup.address != null) pickupinfo += "
Address: " + pickup.address + " ";
if (pickup.city != null) pickupinfo += "
City: " + pickup.city + " ";
if (pickup.postcode != null) pickupinfo += "
POSTAL\u0020CODE: " + pickup.postcode + " ";
if (pickup.time != null) pickupinfo += "
Hours: " + pickup.time + " ";
if (pickup.total != null) pickupinfo += "
Total\u0020pickup\u0020amount: " + pickup.total + " € ";
pickupinfo += "
";
$('.pickup-select').after(pickupinfo);
if (typeof avaiableDays != "undefined") {
$('.pickup-quotation').append('Confirm\u0020selection\u0020and\u0020show\u0020hotel ');
} else {
$('.pickup-quotation').append('Confirm\u0020selection\u0020and\u0020buy ');
}
$('.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 += "
Pickup\u0020name: " + pickup.name + " ";
if (pickup.description != null) pickupinfo += "
Description: " + pickup.description + " ";
if (pickup.address != null) pickupinfo += "
Address: " + pickup.address + " ";
if (pickup.city != null) pickupinfo += "
City: " + pickup.city + " ";
if (pickup.postcode != null) pickupinfo += "
POSTAL\u0020CODE: " + pickup.postcode + " ";
if (pickup.time != null) pickupinfo += "
Hours: " + pickup.time + " ";
if (pickup.total != null) pickupinfo += "
Total\u0020pickup\u0020amount: " + 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);
});
});