(function ($) { var main_time_selected = false; prepareForms(); function prepareForms() { $('input').placeholder(); $('#reservation-form').validate({ submitHandler: function (form) { ga('send', 'pageview', {'page': '/tunnel/7/submit_form', 'title': 'Submit form'}); $('.progress-indicator').css('display', 'block'); function isURL(str) { var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|'+ // domain name '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string '(\\#[-a-z\\d_]*)?$','i'); // fragment locator return pattern.test(str); } $.ajax({ url: "./booking-formv2.php", type: 'GET', data: $(form).serialize(), success: function (data) { if (data == "OK") { $('.step3').hide(); $('.step4').removeClass('hidden').show(); ga('send', 'pageview', {'page': '/tunnel/8/thank_you', 'title': 'Thank you page'}); try { window.parent.postMessage('booking-confirmation', '*'); } catch (e) { } /*salesmachine.track_event($('email').val(), 'resa', { account_id: $('restoid').val(), guest_count: $('nbguests').val(), firstname: $('firstname').val(), lastname: $('name').val(), country: $('country').val() });*/ } else if(isURL(data)) { ga('send', 'pageview', {'page': '/tunnel/8/payment', 'title': 'Payment form'}); window.location.href = data; } else { var error_message = ""; try { var error = JSON.parse(data); if (undefined !== error.message) { if( (typeof error.message === "object") && (error.message !== null) ) { for (var index in error.message) { error_message += "field " + index + " : " + (error.message[index].map( function(v){ return v.replace("validation.", ""); }).join(",") ) + "\r\n"; } } else { error_message = error.message; } } } catch (e) { error_message = data; } alert(error_message); } $('.progress-indicator').css('display', 'none'); } }); return false; } }); } changeDate(); function changeDate() { $('.change-date a').click(function () { $('.change-date').hide(); $('#step22_pax').html(""); $('.step22').hide(); $('.step1').show(); }); } changeSchedule(); function changeSchedule() { $('.back-time').click(function () { $('.step3').hide(); $('.step22').show(); }); } waiter(); function waiter() { $('.progress-indicator').ajaxStart(function () { $(this).css('display', 'block'); }).ajaxStop(function () { $(this).css('display', 'none'); }); } checkavailability(); function checkavailability() { $('#check-availability').click(function () { if ($('#resatype').val() == 'concierge') { //TEST CONDITION FOR CONCIERGERIE $.when(checkingCreditConciergerie()).done(function (conciergerie) { if (conciergerie.success == 'true') { // Conciergerie activated __actioncheckavailability(); } else { // block widget alert(conciergerie.error); } }); } else { __actioncheckavailability(); } }); } function __actioncheckavailability() { if (!$('#date').val()) { $('.progress-indicator').css('display', 'none'); return false; } ga('send', 'pageview', {'page': '/tunnel/2/choose_date', 'title': 'Choose a date'}); var mydate = new Date($('#date').val().substring(0, 4), parseInt($('#date').val().substring(5, 7), 10) - 1, $('#date').val().substring(8, 10)); var months = $('#months').val().split(','); var month = months[mydate.getMonth()]; var fulldate = mydate.getFullYear() + "-" + pad(mydate.getMonth() + 1, 2) + "-" + pad(mydate.getDate(), 2); mydate.setHours(23); mydate.setMinutes(59); var html = ""; $.ajax({ url: "./getBookingTimes2.json.php", type: 'GET', async: false, data: "restaurantid=" + $("#restoid").val() + "&date=" + fulldate, success: function (objson) { window.dateShifts = objson; window.slots = []; $('.progress-indicator').css('display', 'block'); $.each(objson.shifts, function (index, shift) { html += '
' + shift.name + '
'; if (closedShift(shift)) { html += '
'; html += '
' + $("#msg_bookings_closed").val() + '
'; html += '
'; console.log('service bouclé'); return; } if (fullShift(shift)) { html += '
'; html += '
' + $("#msg_services_full").val() + '
'; html += '
'; console.log('service complet'); return; } $.each(shift.shift_slots, function (k, slot) { window.slots[slot.slot_name] = slot; var full = fullSlot(slot); var closed = closedSlot(slot); if(slot.capacity.total_per_slot != 0) { if(full || closed) { html += ''; html += slot.name + ''; } else { html += ''; html += slot.name + ''; } } }); console.log(shift); }); $("#step22_schedule").html(''); $("#step22_schedule").html(html); // Replace links with select if too many of them if ($("#step22_schedule a.btn-schedule").length > 15) { $('#step22_schedule .service_schedule').hide(); $("#step22_schedule .btn-schedule").hide(); var selectHtml = '
' + $("#timelabel").val() + '
' + '
' + '' + '
'; $("#step22_schedule").append(selectHtml); $("#step22_schedule select.select_schedule").on('change', function () { ga('send', 'pageview', {'page': '/tunnel/3/choose_time', 'title': 'Choose time'}); $("#step22_schedule").find("a.btn-schedule[data-time='" + $(this).val() + "']").click(); }); } clickbtnschedule(); if (main_time_selected == true) { // we display automatically the pax button selected based on time selected $("#step22_schedule select.select_schedule").trigger('change'); } }, error: function () { } }); if ($('#lang').val() == "fr") { var strdate = mydate.getDate() + ' ' + month + ' ' + mydate.getFullYear(); } else { var strdate = month + ' ' + mydate.getDate() + ', ' + mydate.getFullYear(); } $('.summary-date').text(strdate); //$('#summary-time').text($('#time').val()); //$('#summary-nbguests').text($('#nbguests').val()); $('.change-date').removeClass('hidden').show(); $('.step1').hide(); $('.step22').removeClass('hidden').show(); try { window.parent.postMessage('booking-step2', '*'); } catch (e) { } return false; } checktimeandpax(); function checktimeandpax() { $("#check-time-pax").click(function () { if ($('#resatype').val() == 'concierge') { //TEST CONDITION FOR CONCIERGERIE $.when(checkingCreditConciergerie()).done(function (conciergerie) { if (conciergerie.success == 'true') { // Conciergerie activated __actionchecktimeandpax(); } else { // block widget alert(conciergerie.error); } }); } else { __actionchecktimeandpax(); } }); } function __actionchecktimeandpax() { ga('send', 'pageview', {'page': '/tunnel/5/check_time_pax', 'title': 'Check time and pax'}); //TEST CONDITION FOR CONCIERGERIE $('.progress-indicator').css('display', 'block'); var sch_sel = ""; var display_sch_sel = ""; var pax_sel = ""; $(".btn-schedule").each(function (index, el) { if ($(this).attr('class').search(/active-schedule/i) != -1) { sch_sel = $(this).data("time"); display_sch_sel = $(this).text(); } }); $(".btn-pax").each(function (index, el) { if ($(this).attr('class').search(/active-schedule/i) != -1) { pax_sel = $(this).data("pax"); } }); if (pax_sel == "") { if ($("#pax_people").length > 0) { if ($("#pax_people option:selected").val() != "-") { pax_sel = $("#pax_people option:selected").val(); } } } if (pax_sel == "" || sch_sel == "") { alert($("#problem-reservation-time-pax").val()); } else { $("#pax_hidden").val(pax_sel); $("#time_hidden").val(sch_sel); $(".summary-nbguests").text(pax_sel); $(".summary-time").text(display_sch_sel.replace(':', 'h')); $('.step22').hide(); $('.step3').removeClass('hidden').show(); ga('send', 'pageview', {'page': '/tunnel/6/fill_form', 'title': 'Fill form'}); try { window.parent.postMessage('booking-step3', '*'); } catch (e) { } } $('.progress-indicator').css('display', 'none'); } /*checkcustomer(); function checkcustomer() { $("#check-customer").click(function () { __actioncheckcustomer(); }); } function __actioncheckcustomer() { ga('send', 'pageview', {'page': '/tunnel/6/check_customer', 'title': 'Check customer'}); $('.step3').hide(); $('.step4').removeClass('hidden').show(); }*/ function clickbtnschedule() { __actionclickbtnschedule(); } function __actionclickbtnschedule() { $("a.btn-schedule").bind('click', function () { //TEST CONDITION FOR CONCIERGERIE classarray = $(this).attr("class").split(" "); $(".btn-schedule").each(function (index) { $(this).attr("class", "btn-schedule"); }); if ($.inArray("active-schedule", classarray) == true) { $(this).attr("class", "btn-schedule active-schedule"); } else { $(this).attr("class", "btn-schedule active-schedule"); } $("#date").val($(this).data('date')); var months = $('#months').val().split(','); var datebtn = $(this).data('date').split("-"); var timebtn = $(this).data('time'); var html = ""; var html2 = ""; $('.progress-indicator').css('display', 'block'); var slot = window.slots[timebtn]; var btn_written = false; html += '
' + $("#msg_pax").val() + '
'; var max = 10; var nb = 0; $.each(slot.possible_guests, function (k, v) { if (nb < max) { html += '' + v + ''; nb++; } else { if (nb == max) { html2 += '
'; html2 += '
'; } if (nb == 0) { html += $("#msg_no_availability").val(); } if ($('#lang').val() == "fr") { var strdate = datebtn[2] + ' ' + months[datebtn[1] - 1] + ' ' + datebtn[0]; } else { var strdate = months[datebtn[1] - 1] + ' ' + datebtn[2] + ', ' + datebtn[0]; } $('.summary-date').text(strdate); $("#step22_pax").html("") $("#step22_pax").html(html + html2); clickbtnpax(); selectclickbtnpax(); $('.progress-indicator').css('display', 'none'); return false; }); } function clickbtnpax() { $(".btn-pax").bind('click', function () { ga('send', 'pageview', {'page': '/tunnel/4/choose_guests', 'title': 'Choose guests'}); classarray = $(this).attr("class").split(" "); $(".btn-pax").each(function (index) { $(this).attr("class", "btn-pax"); }); $("#pax_people option:selected").removeAttr('selected'); $("#pax_people option[value=-]").attr('selected'); if ($.inArray("active-schedule", classarray) == true) { $(this).attr("class", "btn-pax active-schedule"); } else { $(this).attr("class", "btn-pax active-schedule"); } toggleWarningBookingCharges($(this).data().pax); return false; }); } function selectclickbtnpax() { $("#pax_people").bind('change', function () { var classarray = $(this).attr("class").split(" "); $(".btn-pax").each(function (index, element) { $(this).attr("class", "btn-pax"); }); toggleWarningBookingCharges($(this).val()); return false; }); } function toggleWarningBookingCharges(pax) { var min_pax_booking_charges = parseInt($('#min_pax_booking_charges').val()); if (parseInt(pax) >= min_pax_booking_charges) { $('#eb-notice').show(); } else { $('#eb-notice').hide(); } } function pad(str, max) { var string = new String(str); return string.length < max ? pad("0" + string, max) : str; } function checkingCreditConciergerie() { var result = false; $.ajax({ url: "http://app.zenchef.com/public/conciergerie/rid/" + $("#restoid_base64").val() + "/checking", type: 'GET', dataType: 'json', async: false, success: function (data) { $('.progress-indicator').css('display', 'block'); result = data; }, error: function () { } }); return result; } function closedSlot(slot) { return slot.closed; }; function fullSlot(slot, guests) { if (guests) { return !$.inArray(guests, slot.possible_guests); } else { return slot.possible_guests.length == 0; } }; function closedShift(shift) { var closedCount = 0; $.each(shift.shift_slots, function (k, s) { if (closedSlot(s)) { closedCount++; } }); return closedCount == shift.shift_slots.length; }; function fullShift(shift, guests) { var fullCount = 0; $.each(shift.shift_slots, function (k, s) { if (fullSlot(s, guests)) { fullCount++; } }); return fullCount == shift.shift_slots.length; }; })(jQuery);