366 lines
No EOL
14 KiB
JavaScript
366 lines
No EOL
14 KiB
JavaScript
$(document).ready(function () {
|
||
|
||
|
||
var frm$ = $('.st-booking-form');
|
||
var summary$ = $('.st-booking-summary');
|
||
|
||
var roomCountSR$ = $('#booking_request_singleRoomCount');
|
||
var roomCountDR$ = $('#booking_request_doubleRoomCount');
|
||
var roomCountTR$ = $('#booking_request_tripleRoomCount');
|
||
|
||
var roomChildCountSR$ = $('#booking_request_singleRoomChildCount');
|
||
var roomChildCountDR$ = $('#booking_request_doubleRoomChildCount');
|
||
var roomChildCountTR$ = $('#booking_request_tripleRoomChildCount');
|
||
|
||
var extraBookingDaysBefore$ = $('#booking_request_extraBookingDaysBefore');
|
||
var extraBookingDaysAfter$ = $('#booking_request_extraBookingDaysAfter');
|
||
|
||
/*
|
||
extraBookingDaysBefore
|
||
extraBookingDaysAfter
|
||
*/
|
||
function setExtraBookingDaysProgram($this, $to) {
|
||
|
||
if ($to === 'before') {
|
||
var show$ = $('#extraDaysProgramBefore_show');
|
||
var hide$ = $('#extraDaysProgramBefore_hide');
|
||
var date$ = $('#extraDaysProgramBefore_date');
|
||
}
|
||
if ($to === 'after') {
|
||
var show$ = $('#extraDaysProgramAfter_show');
|
||
var hide$ = $('#extraDaysProgramAfter_hide');
|
||
var date$ = $('#extraDaysProgramAfter_date');
|
||
}
|
||
|
||
if($($this).val() === 0){
|
||
show$.hide();
|
||
hide$.show();
|
||
}
|
||
if($($this).val() > 0){
|
||
show$.show();
|
||
hide$.hide();
|
||
}
|
||
|
||
function parseDate(input) {
|
||
var parts = input.match(/(\d+)/g);
|
||
// note parts[1]-1
|
||
return new Date(parts[2], parts[1]-1, parts[0]);
|
||
}
|
||
|
||
|
||
if(date$.data('org-date')) {
|
||
// console.log(date$.data('org-date'));
|
||
|
||
var date = parseDate(date$.data('org-date'));
|
||
//console.log(date);
|
||
if ($to === 'before') {
|
||
//console.log($($this).val());
|
||
date.setDate(date.getDate() - parseInt($($this).val()));
|
||
}
|
||
if ($to === 'after') {
|
||
// console.log($($this).val());
|
||
date.setDate(date.getDate() + parseInt($($this).val()));
|
||
}
|
||
//console.log(date);
|
||
date$.html(date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear());
|
||
}
|
||
}
|
||
|
||
if(extraBookingDaysBefore$){
|
||
extraBookingDaysBefore$.on('change', function () {
|
||
setExtraBookingDaysProgram(this, 'before');
|
||
});
|
||
setExtraBookingDaysProgram(this, 'before');
|
||
}
|
||
|
||
if(extraBookingDaysAfter$){
|
||
extraBookingDaysAfter$.on('change', function () {
|
||
setExtraBookingDaysProgram(this, 'after');
|
||
|
||
});
|
||
setExtraBookingDaysProgram(this, 'after');
|
||
}
|
||
|
||
|
||
var travelers$ = $('.st-traveler');
|
||
var travelerFields$ = travelers$.find('input,select,checkbox');
|
||
|
||
frm$.find('input, select').change(function () {
|
||
var tmp = location.href.split('?');
|
||
var tmp2 = tmp[0].split('/');
|
||
tmp2.pop();
|
||
var url = tmp2.join('/') + '/berechne-gesamtpreis';
|
||
if (tmp[1]) {
|
||
url += '?' + tmp[1];
|
||
}
|
||
$.ajax({
|
||
url: url,
|
||
type: 'post',
|
||
data: frm$.serialize()
|
||
|
||
}).then(function (r) {
|
||
summary$.html(r);
|
||
/*
|
||
$('#st-booking-price-set-table .st-total-price-set').html($(r).find('.st-total-price').text());
|
||
$('#st-booking-price-set-table .st-deposit-price-set').html($(r).find('.st-deposit-price').text());
|
||
$('#st-booking-price-set-table .st-final-price-set').html($(r).find('.st-final-price').text());
|
||
*/
|
||
|
||
}, function () {
|
||
summary$.html('Aufgrund eines Fehlers konnte kein Angebot ermittelt werden.');
|
||
})
|
||
});
|
||
|
||
$('#booking_request_departure').change(function () {
|
||
//show nothing
|
||
$('.flight_times_ele').hide();
|
||
$('#no_flight_time').hide();
|
||
$('#yes_flight_time').hide();
|
||
|
||
if (!$(this).val() || $(this).find("option:selected").text().indexOf("Eigenanreise") == 0) {
|
||
return;
|
||
}if ($('#flight_time_' + $(this).val()).length) {
|
||
$('#flight_time_' + $(this).val()).show();
|
||
$('#yes_flight_time').show();
|
||
} else {
|
||
$('#no_flight_time').show();
|
||
}
|
||
});
|
||
var toggle_first = [];
|
||
|
||
function updateNationality(ele) {
|
||
var obj = ele.parents('.nationality_select').data('toggle');
|
||
if (ele.val()) {
|
||
|
||
var values = $("input[name='travel_program_countries_id[]']").map(function () {
|
||
return $(this).val();
|
||
}).get();
|
||
|
||
var url = $('#booking_form').data('url') + 'api/passolution/de';
|
||
var data = {nationality_id: ele.val(), country_ids: values, travel_date_start: $('#booking_form').data('travel_date_start'), travel_program_id: $('#booking_form').data('travel_program_id')};
|
||
//console.log(data);
|
||
//console.log(url);
|
||
$.ajax({
|
||
url: url,
|
||
type: "POST",
|
||
data: data,
|
||
}).then(function (r) {
|
||
//console.log(r);
|
||
if(r.response){
|
||
$(obj).find('.set_nationality_country_text').html(r.response);
|
||
$(obj).show('slow');
|
||
if (!toggle_first[ele.val()]) {
|
||
$(obj).find('.accordion-toggle').click();
|
||
toggle_first[ele.val()] = true;
|
||
}
|
||
}else{
|
||
console.log(r);
|
||
}
|
||
}, function () {
|
||
summary$.html('Aufgrund eines Fehlers konnte keine Anfrage übermittel werden.');
|
||
});
|
||
} else {
|
||
$(obj).hide();
|
||
}
|
||
}
|
||
|
||
$('.nationality_select').find('select').change(function () {
|
||
updateNationality($(this));
|
||
});
|
||
|
||
|
||
function updateAllNationality() {
|
||
$('.nationality_select').find('select').each(function () {
|
||
updateNationality($(this));
|
||
});
|
||
}
|
||
|
||
updateAllNationality();
|
||
|
||
|
||
function toggleUpdateChevron(e) {
|
||
var $i = $(e.target)
|
||
.parent('.panel-group')
|
||
.find("i.indicator");
|
||
|
||
$i.toggleClass('icon-minus icon-plus');
|
||
}
|
||
|
||
$('.acc_nationality_panel').on('hidden.bs.collapse', toggleUpdateChevron);
|
||
$('.acc_nationality_panel').on('shown.bs.collapse', toggleUpdateChevron);
|
||
|
||
|
||
function toggleChevronIn(e) {
|
||
var $i = $(e.target)
|
||
.parent('.panel-group')
|
||
.find("i.indicator");
|
||
|
||
$i.toggleClass('icon-minus icon-plus');
|
||
|
||
if ($i.hasClass('icon-minus')) {
|
||
$i.parent('h5').find('span').html('Leistungen ausblenden');
|
||
}
|
||
if ($i.hasClass('icon-plus')) {
|
||
$i.parent('h5').find('span').html('Leistungen einblenden');
|
||
}
|
||
}
|
||
|
||
$('.booking_insurance_toogle').on('hidden.bs.collapse', toggleChevronIn);
|
||
$('.booking_insurance_toogle').on('shown.bs.collapse', toggleChevronIn);
|
||
|
||
|
||
function updateTravelers() {
|
||
var travelersIndex = 1;
|
||
|
||
var singleTravelerCount = parseInt(roomCountSR$.val());
|
||
var doubleTravelerCount = parseInt(roomCountDR$.val()) * 2;
|
||
var tripleTravelerCount = parseInt(roomCountTR$.val()) * 3;
|
||
|
||
var singleTravelerChildCount = parseInt(roomChildCountSR$.val()) * 2;
|
||
var doubleTravelerChildCount = parseInt(roomChildCountDR$.val()) * 3;
|
||
var tripleTravelerChildCount = parseInt(roomChildCountTR$.val()) * 4;
|
||
|
||
var allTravelersCount = singleTravelerCount + doubleTravelerCount + tripleTravelerCount + singleTravelerChildCount + doubleTravelerChildCount + tripleTravelerChildCount;
|
||
|
||
travelers$.hide();
|
||
travelerFields$.prop('required', false);
|
||
|
||
var counter = 1;
|
||
var $offset = 1;
|
||
|
||
//single
|
||
if (singleTravelerCount > 0) {
|
||
for (var i = $offset; i <= singleTravelerCount; i++) {
|
||
var travelerSelector = '.st-traveler-' + i;
|
||
var roomIndexSelector = travelerSelector + ' .st-traveller-index';
|
||
//var currentRoomIndex = $(travelerSelector).attr("data-room-index");
|
||
$(travelerSelector).show().find('input,select').prop('required', true);
|
||
$(roomIndexSelector).text(counter + ".) Reiseteilnehmer | Einzelzimmer 1. Erwachsender");
|
||
counter++;
|
||
}
|
||
}
|
||
//single + child
|
||
$offset = $offset + parseInt(roomCountSR$.find('option').length) - 1;
|
||
//4 next 5
|
||
|
||
if (singleTravelerChildCount > 0) {
|
||
for (var i = $offset; i < singleTravelerChildCount + $offset; i++) {
|
||
var travelerSelector = '.st-traveler-' + i;
|
||
var roomIndexSelector = travelerSelector + ' .st-traveller-index';
|
||
//var currentRoomIndex = $(travelerSelector).attr("data-room-index");
|
||
$(travelerSelector).show().find('input,select').prop('required', true);
|
||
$(roomIndexSelector).text(counter + ".) Reiseteilnehmer | Einzelzimmer | 1. Erwachsender");
|
||
counter++;
|
||
|
||
//child
|
||
i++;
|
||
var travelerSelector = '.st-traveler-' + i;
|
||
var roomIndexSelector = travelerSelector + ' .st-traveller-index';
|
||
//var currentRoomIndex = $(travelerSelector).attr("data-room-index");
|
||
$(travelerSelector).show().find('input,select').prop('required', true);
|
||
$(roomIndexSelector).text(counter + ".) Reiseteilnehmer | Einzelzimmer | Kind");
|
||
counter++;
|
||
}
|
||
}
|
||
//double
|
||
$offset = $offset + (parseInt(roomChildCountSR$.find('option').length) - 1) * 2;
|
||
//4 + 4*2 next 13
|
||
if (doubleTravelerCount > 0) {
|
||
$m = 1;
|
||
|
||
for (var i = $offset; i < doubleTravelerCount + $offset; i++) {
|
||
var travelerSelector = '.st-traveler-' + i;
|
||
var roomIndexSelector = travelerSelector + ' .st-traveller-index';
|
||
// var currentRoomIndex = $(travelerSelector).attr("data-room-index");
|
||
$(travelerSelector).show().find('input,select').prop('required', true);
|
||
$(roomIndexSelector).text(counter + ".) Reiseteilnehmer | Doppelzimmer | " + $m + ". Erwachsender");
|
||
counter++;
|
||
$m++;
|
||
if ($m == 3) {
|
||
$m = 1;
|
||
}
|
||
}
|
||
}
|
||
//double + child
|
||
$offset = $offset + (parseInt(roomCountDR$.find('option').length) - 1) * 2;
|
||
//12 + 3*2 next 19
|
||
if (doubleTravelerChildCount > 0) {
|
||
$m = 1;
|
||
for (var i = $offset; i < doubleTravelerChildCount + $offset; i++) {
|
||
var travelerSelector = '.st-traveler-' + i;
|
||
var roomIndexSelector = travelerSelector + ' .st-traveller-index';
|
||
//var currentRoomIndex = $(travelerSelector).attr("data-room-index");
|
||
$(travelerSelector).show().find('input,select').prop('required', true);
|
||
$(roomIndexSelector).text(counter + ".) Reiseteilnehmer | Doppelzimmer | " + $m + ". Erwachsender");
|
||
counter++;
|
||
$m++;
|
||
if ($m == 3) {
|
||
$m = 1;
|
||
//child
|
||
i++;
|
||
var travelerSelector = '.st-traveler-' + i;
|
||
var roomIndexSelector = travelerSelector + ' .st-traveller-index';
|
||
//var currentRoomIndex = $(travelerSelector).attr("data-room-index");
|
||
$(travelerSelector).show().find('input,select').prop('required', true);
|
||
$(roomIndexSelector).text(counter + ".) Reiseteilnehmer | Doppelzimmer | Kind");
|
||
counter++;
|
||
}
|
||
}
|
||
}
|
||
|
||
//triple
|
||
$offset = $offset + (parseInt(roomChildCountDR$.find('option').length) - 1) * 3;
|
||
//18 + 3*3 next 28
|
||
if (tripleTravelerCount > 0) {
|
||
$m = 1;
|
||
for (var i = $offset; i < tripleTravelerCount + $offset; i++) {
|
||
var travelerSelector = '.st-traveler-' + i;
|
||
var roomIndexSelector = travelerSelector + ' .st-traveller-index';
|
||
//var currentRoomIndex = $(travelerSelector).attr("data-room-index");
|
||
$(travelerSelector).show().find('input,select').prop('required', true);
|
||
$(roomIndexSelector).text(counter + ".) Reiseteilnehmer | Dreibettzimmer | " + $m + ". Erwachsender");
|
||
counter++;
|
||
$m++;
|
||
if ($m == 4) {
|
||
$m = 1;
|
||
}
|
||
}
|
||
}
|
||
|
||
//triple + child
|
||
$offset = $offset + (parseInt(roomCountTR$.find('option').length) - 1) * 3;
|
||
//27 + 2*3 next 34
|
||
if (tripleTravelerChildCount > 0) {
|
||
$m = 1;
|
||
for (var i = $offset; i < tripleTravelerChildCount + $offset; i++) {
|
||
var travelerSelector = '.st-traveler-' + i;
|
||
var roomIndexSelector = travelerSelector + ' .st-traveller-index';
|
||
//var currentRoomIndex = $(travelerSelector).attr("data-room-index");
|
||
$(travelerSelector).show().find('input,select').prop('required', true);
|
||
$(roomIndexSelector).text(counter + ".) Reiseteilnehmer | Dreibettzimmer | " + $m + ". Erwachsender");
|
||
counter++;
|
||
$m++;
|
||
if ($m == 4) {
|
||
$m = 1;
|
||
//child
|
||
i++;
|
||
var travelerSelector = '.st-traveler-' + i;
|
||
var roomIndexSelector = travelerSelector + ' .st-traveller-index';
|
||
//var currentRoomIndex = $(travelerSelector).attr("data-room-index");
|
||
$(travelerSelector).show().find('input,select').prop('required', true);
|
||
$(roomIndexSelector).text(counter + ".) Reiseteilnehmer | Dreibettzimmer | Kind");
|
||
counter++;
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
roomCountSR$.change(updateTravelers);
|
||
roomCountDR$.change(updateTravelers);
|
||
roomCountTR$.change(updateTravelers);
|
||
roomChildCountSR$.change(updateTravelers);
|
||
roomChildCountDR$.change(updateTravelers);
|
||
roomChildCountTR$.change(updateTravelers);
|
||
updateTravelers();
|
||
}); |