var clicked=false;
function ClickLogin()
{
clicked=true;
}
function Google_signIn(googleData) {
if (clicked) {
$(".availLoader").fadeIn('slow');
var profile = googleData.getBasicProfile(); //get google profile details
console.log(profile);
var email = profile.getEmail();
var name, profileImg, getId;
$.ajax({
url: "/site/oauthgmail",
type: 'POST',
data: {
email: email,
name: profile.getName(),
profileImg: profile.getImageUrl(),
getId:profile.getId()
},
cache: false,
success: function(resp) {
var obj = $.parseJSON(resp);
console.log(obj);
$('#personid').val(obj.personid);
$('#phoneid').val(obj.phone);
$('#issetUser').val("available");
var issetUser = $('#issetUser').val();
if (issetUser == "nonavailable") {
$('.wrapSubmitbtn').hide();
$('.wrapLoginbtn').show();
}
else if (issetUser == "available") {
$('.wrapSubmitbtn').show();
$('.wrapLoginbtn').hide();
}
setTimeout(function() {
$(".login-label").fadeOut(400, function() {
$(".login-label").attr("href", "/site/logout");
$(".login-label").find('span').html(email + " - Logout");
});
$(".login-label").fadeIn(400);
}, 2000);
var newRoute = $('#bookingLink').val();
if (newRoute == "assistant") {
$(".form-signup, .form-booking, .form-signin, .form-assistant").slideUp(500);
$(".form-assistantBooking").slideDown(500);
setTimeout(function() {
$("#trigger_assistantbooking").trigger("click");
}, 2500);
}
else {
$(".form-signup, .form-signin, .form-assistant, .form-assistantBooking").slideUp(500);
$(".form-booking").slideDown(500);
setTimeout(function() {
$("#trigger_booking").trigger("click");
}, 2500);
}
},
error: function(xhr, status, error) {
}
});
}
}
var bookNow = (function() {
"use strict";
var $html = $('html');
var $loginLbl = $('.login-label');
var bookingfrom = $("#bookingfrom").val();
var bookinguri = $("#bookinguri").val();
var weburl = $("#pageUrl").val();
var control = $("#pageController").val();
var locaction = $("#pageAction").val();
var previousBooking = $("#previous_booking").val();
var startPageUrl = "";
var movement;
function loginFacebook() {
$(".availLoader").fadeIn('slow');
FB.api('/me', {
locale: 'en_US',
fields: 'id, name, first_name, last_name, email, link, gender, locale, picture'
},
function (response) {
var id, email, name, firstname, lastname, picture;
$.ajax({
url: "/site/oauthfacebook",
data: {
id : response.id,
email : response.email,
firstname : response.first_name,
lastname : response.last_name,
name : response.name,
picture : response.picture.data.url
},
type: "POST",
success: function(resp) {
var obj = $.parseJSON(resp);
$('#personid').val(obj.personid);
$('#phoneid').val(obj.phone);
$('#issetUser').val("available");
var issetUser = $('#issetUser').val();
if (issetUser == "nonavailable") {
$('.wrapSubmitbtn').hide();
$('.wrapLoginbtn').show();
}
else if (issetUser == "available") {
$('.wrapSubmitbtn').show();
$('.wrapLoginbtn').hide();
}
setTimeout(function() {
$(".login-label").fadeOut(400, function() {
$(".login-label").attr("href", "/site/logout");
$(".login-label").find('span').html(response.email + " - Logout");
});
$(".login-label").fadeIn(400);
}, 1000);
var newRoute = $('#bookingLink').val();
if (newRoute == "assistant") {
$(".form-signup, .form-booking, .form-signin, .form-assistant").slideUp(500);
$(".form-assistantBooking").slideDown(500);
setTimeout(function() {
$("#trigger_assistantbooking").trigger("click");
}, 1000);
}
else {
$(".form-signup, .form-signin, .form-assistant, .form-assistantBooking").slideUp(500);
$(".form-booking").slideDown(500);
setTimeout(function() {
$("#trigger_booking").trigger("click");
}, 1000);
}
}
});
});
}
window.fbAsyncInit = function() {
FB.init({
appId : '1148786385153387',
xfbml : true,
cookie : true,
version : 'v2.0'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function setBlocks() {
var issetUser = $('#issetUser').val();
if (issetUser == "nonavailable") {
$('.wrapSubmitbtn').hide();
$('.wrapLoginbtn').show();
}
else if (issetUser == "available") {
$('.wrapSubmitbtn').show();
$('.wrapLoginbtn').hide();
}
}
function showBlocks() {
if (bookingfrom == "myself") {
$(".form-signup, .form-signin, .form-assistant, .form-assistantBooking").slideUp(500);
$(".form-booking").slideDown(500);
}
else if (bookingfrom == "assistant") {
$(".form-signup, .form-booking, .form-signin, .form-assistant").slideUp(500);
$(".form-assistantBooking").slideDown(500);
}
}
function bookingLink(link) {
$.ajax({
url: "/"+ control +"/setlinkroute",
type: 'POST',
data: {
datRoute: link,
datUrl: bookinguri
},
cache: false,
success: function(resp) {
//console.log(resp);
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
function setLinkroute(link) {
$("#bookingLink").val(link);
}
function showLoader() {
$(".availLoader").fadeIn('slow');
}
function hideLoader() {
$(".availLoader").fadeOut('slow');
}
function linkedUsers() {
$.ajax({
url: "/web/getchildusers?parentId=537",
type: 'GET',
data: {},
cache: false,
success: function(resp) {
var outputText = '';
$.each($.parseJSON(resp), function(key, value) {
var divCheckbox = "";
var divHtml = "
" + value.email + " " + value.first_name + "
" + divCheckbox + "";
outputText += divHtml;
});
$(".collection").html(outputText);
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
function pickedChilds() {
var myData = [{
tag: 'Apple iPhone',
}, {
tag: 'Microsoft Windows Phone',
}, {
tag: 'Google Android Phone',
}];
// $('.chips-placeholder').material_chip({
// placeholder: 'Enter a linked user',
// secondaryPlaceholder: '+Tag',
// data: myData
// });
}
function getAbsolutePath() {
var loc = window.location;
var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);
return loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));
}
function sessionUpdate(merchantid, slotversion, bookingdate){
$.ajax({
url: "/site/ajaxsessiondata",
type: 'POST',
data: {
merchantid: merchantid,
slotversion: slotversion,
bookingdate: bookingdate
},
cache: false,
success: function(resp) {
//console.log('ajaxsessiondata', resp);
var data = JSON.parse(resp);
$("#book_session").html("");
$("#book_session").append(data.option);
$("#book_session").formSelect();
var masdate = $("#book_date").val();
var sessionid = $("#book_session").find("option:selected").val();
var merchantid = $("#merchantid_book").val();
if ( sessionid != '' ) {
var lunch_person_book = data.data.lunch.maxpersons;
var dinner_person_book = data.data.dinner.maxpersons;
$("#lunch_person_book").val(lunch_person_book);
$("#dinner_person_book").val(dinner_person_book);
timeslotsUpdate(merchantid, masdate, sessionid);
}
else{
$("#book_time").html("");
$("#book_time").append("");
$("#book_time").formSelect();
}
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
function timeslotsUpdate(merchantid, masdate, sessionid){
var lunch_person_book = $("#lunch_person_book").val();
var dinner_person_book = $("#dinner_person_book").val();
var masdate =$("#book_date").val();
$.ajax({
url: "/site/ajaxtimeslots",
type: 'POST',
data: {
merchantid: merchantid,
masdate:masdate,
sessionid:sessionid
},
cache: false,
success: function(resp) {
//console.log('ajaxtimeslots', resp);
var data = JSON.parse(resp);
$("#book_time").html("");
$("#book_time").append(data.option);
$("#book_time").formSelect();
if(data.data == 'error')
{
personsUpdate(0, 0);
}
else
{
personsUpdate(lunch_person_book, dinner_person_book);
}
},
error: function(error) {
console.log(error);
}
});
}
function personsUpdate(lunch_person_book, dinner_person_book){
var sessionid = $("#book_session").find("option:selected").val();
var book_time = $("#book_time").find("option:selected").val();
var bookingsession = $('#book_session option:selected').val();
var loopval = 0;
var text="";
if ( sessionid != '' || book_time != '')
{
if ( bookingsession == 1 )
{
loopval = lunch_person_book;
if ( loopval == 0 || loopval == "" )
{
text="";
}
else
{
for (var i = 0; i <= loopval; i++)
{
text += "";
}
}
}
else{
loopval = dinner_person_book;
if ( loopval == 0 || loopval == "" )
{
text="";
}
else
{
for (var i = 0; i <= loopval; i++)
{
text += "";
}
}
}
$("#book_adult").html("");
$("#book_adult").append(text);
$("#book_adult").formSelect();
$("#book_children").html("");
$("#book_children").append(text);
$("#book_children").formSelect();
}
else{
}
}
function storeValues(formName){
var $this = $(this);
if ( formName == "myself" ) {
var bookingsession = $('#book_session').val();
var bookingdate = $('#book_date').val();
var bookingtime = $('#book_time').val();
var adults = $('#book_adult').val();
var children = $('#book_children').val();
var merchantid = $('#merchantid_book').val();
var merchantname = $('#merchant_name').val();
var personid = $('#personid').val();
var version = $('#version').val();
var offerid = $('#offerid').val();
var bookinglanguage = $('#bookingLanguage').val();
var startPageUrl = $('#startPageUrl').val();
$.ajax({
url: "/site/storevalues",
type: 'POST',
async: false,
data: {
bookingdate : bookingdate,
bookingsession : bookingsession,
bookingtime : bookingtime,
adults : adults,
children : children,
infants : 0,
merchantid : merchantid,
merchantname : merchantname,
personid : personid,
version : version,
offerid : offerid,
bookinglanguage: bookinglanguage,
startPageUrl : startPageUrl,
formName : formName,
forBooking : true,
language : bookinglanguage
},
cache: false,
success: function(resp) {
console.log(resp);
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
if ( formName == "assistant" ) {
}
}
function clearValues(){
$.ajax({
url: "/site/clearsessionvalues",
type: 'POST',
async: false,
cache: false,
success: function(resp) {
},
error: function(xhr, status, error) {
console.log(error);
}
});
location.reload();
}
function setPhonenumber(personid, phoneno){
$.ajax({
url: "/site/phone",
type: 'POST',
data: {
personid: personid,
phoneno: phoneno
},
success: function(resp) {
if ( resp == "success" ) {
$("#successModel").modal("close");
$("#movement").val("freeze");
var newbooking = $('#bookingid').val();
window.location.href = "/fr/site/confirmation?booking=" + newbooking;
}
else{
console.log(resp);
// $phoneError.fadeOut( function() {
// $phoneError.html('Something wrong!.');
// $phoneError.fadeIn();
// });
}
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
function bookingMovement(){
return $("#movement").val();
}
$(document).ready(function() {
M.updateTextFields();
$('ul.tabs').tabs();
$('select').formSelect();
// $('.chips').material_chip();
$('.modal').modal();
setBlocks();
showBlocks();
$('#timepicker').timepicker({
'minTime': '9:00am',
'maxTime': '11:30am',
'showDuration': true
});
$html.on("click", "#nearMe", function(e) {
var ckbox = $(this);
if (ckbox.is(':checked')) {
if ("geolocation" in navigator) { //check geolocation available
navigator.geolocation.getCurrentPosition(function(position) {
$("#reg_lat").val(position.coords.latitude);
$("#reg_lon").val(position.coords.longitude);
});
} else {
console.log("Browser doesn't support geolocation!");
}
}
else {
$("#reg_lat").val("");
$("#reg_lon").val("");
}
});
// Marked to remove
$html.on("click", ".to-assistant-link", function(e) {
e.preventDefault();
var datRoute = $(this).attr("data-route");
setLinkroute(datRoute);
bookingLink(datRoute);
$(this).addClass("top-active-button").siblings().removeClass("top-active-button");
$(".form-signup, .form-booking, .form-signin, .form-assistant").slideUp(500);
$(".form-assistantBooking").slideDown(500);
});
// Marked to remove
$html.on("click", ".to-myself-link", function(e) {
e.preventDefault();
var datRoute = $(this).attr("data-route");
setLinkroute(datRoute);
bookingLink(datRoute);
$(this).addClass("top-active-button").siblings().removeClass("top-active-button");
$(".form-signup, .form-signin, .form-assistant, .form-assistantBooking").slideUp(500);
$(".form-booking").slideDown(500);
M.updateTextFields();
});
// Marked to remove
$html.on("click", ".home-form", function(e) {
e.preventDefault();
$(".form-booking, .form-assistantBooking").slideUp(500);
$(".form-assistant").slideDown(500);
});
$html.on("change", "#book_date, #book_datepicker", function(e) {
e.preventDefault();
var merchantid = $("#merchantid_book").val();
var slotversion = $("#slotversion_book").val();
var bookingdate = $("#book_date").val();
sessionUpdate(merchantid, slotversion, bookingdate);
});
$html.on("change", "#book_session, #assistant_book_session", function(e) {
e.preventDefault();
var masdate =$("#book_date").val();
var sessionid =$("#book_session").find("option:selected").val();
var merchantid =$("#merchantid_book").val();
if ( sessionid != '' ) {
timeslotsUpdate(merchantid, masdate, sessionid);
}
});
$html.on("change", "#book_time, #assistant_book_time", function(e) {
e.preventDefault();
var masdate =$("#book_date").val();
var sessionid =$("#book_session").find("option:selected").val();
var book_time =$("#book_time").find("option:selected").val();
var merchantid =$("#merchantid_book").val();
if ( book_time != '' ) {
// personsUpdate();
}
});
$html.on("change", "#book_adult, #book_children", function(e) {
e.preventDefault();
var book_adult = $("#book_adult").find("option:selected").val();
var book_children = $("#book_children").find("option:selected").val();
var sessionid = $("#book_session").find("option:selected").val();
var lunch = $("#lunch_person_book").val();
var dinner = $("#dinner_person_book").val();
var total_seats = (sessionid == 1) ? lunch : dinner;
var seats_selected = parseInt(book_adult) + parseInt(book_children);
if(seats_selected > total_seats)
{
$("#book_adult").find("option:selected").val(0);
$("#book_children").find("option:selected").val(0);
$('#errorDisplay').text('There are only '+total_seats+' seats available.');
$('#erorrModel').modal('open');
}
});
var one=1;
$(".select-wrapper").each(function() {
$(this).css({"z-index" : 500 + one});
one++;
});
$('select[required]').css({
display: 'inline',
position: 'absolute',
float: 'left',
padding: 0,
margin: 0,
border: '1px solid rgba(255,255,255,0)',
height: 0,
width: 0,
top: '2em',
left: '3em',
opacity: 0,
pointerEvents: 'none'
});
$.validator.setDefaults({
errorClass: 'invalid',
validClass: 'valid',
onfocusout: false,
debug: true,
errorPlacement: function (error, element) {
if (element.prop('tagName') === 'SELECT') {
error.appendTo( element.parent() );
error.addClass('active');
}
else{
element.next("label").attr("data-error", error.contents().text());
}
},
highlight: function(element, errorClass, validClass) {
if (element.tagName === 'SELECT'){
$(element).closest('.select-wrapper').addClass('invalid');
}
else{
$(element).removeClass(validClass).addClass(errorClass);
}
},
unhighlight: function(element, errorClass, validClass) {
if (element.tagName === 'SELECT'){
$(element).closest('.select-wrapper').removeClass('invalid');
}
else{
$(element).removeClass(errorClass).addClass(validClass);
}
},
});
$.validator.addMethod("validOrNah", function(value, element) {
if ( $("#book_adult option:selected").val() != 0 || $("#book_children option:selected").val() != 0 ) {
return true;
}
return false;
}, "Please select the number of persons!");
$('#ajaxLogin').validate({
onfocusout: false,
onkeyup: false,
rules: {
log_email: {
required: true,
email: true
},
log_password: {
required: true
}
}
});
$html.on("submit", "#ajaxLogin", function(e) {
e.preventDefault();
var $this = $(this);
$this.valid();
if ($(this).valid()) {
showLoader();
var email = $this.find('input[name="log_email"]').val();
var password = $this.find('input[name="log_password"]').val();
var newRoute = $('#bookingLink').val();
var bookinglanguage = $('#bookingLanguage').val();
$.ajax({
url: "/site/sitelogin",
type: 'POST',
data: {
email: email,
password: password,
language: bookinglanguage
},
cache: false,
success: function(resp) {
var obj = $.parseJSON(resp);
if ( obj.status == 100 ) {
$('#personid').val(obj.personid);
$('#phoneid').val(obj.phone);
$('#issetUser').val("available");
setBlocks();
setTimeout(function() {
$loginLbl.fadeOut(400, function() {
$loginLbl.attr("href", "/site/logout");
$loginLbl.find('span').html(email + " - Logout");
});
$loginLbl.fadeIn(400);
}, 1000);
if (newRoute == "assistant") {
$(".form-signup, .form-booking, .form-signin, .form-assistant").slideUp(500);
$(".form-assistantBooking").slideDown(500);
setTimeout(function() {
$("#trigger_assistantbooking").trigger("click");
}, 1000);
}
else {
$(".form-signup, .form-signin, .form-assistant, .form-assistantBooking").slideUp(500);
$(".form-booking").slideDown(500);
setTimeout(function() {
$("#trigger_booking").trigger("click");
}, 1000);
}
}
else{
hideLoader();
setTimeout(function() {
$("#errorDisplay").html("Incorrect email or password.");
$("#erorrModel").modal("open");
}, 1000);
}
},
error: function(xhr, status, error) {
hideLoader();
console.log(error);
$("#errorDisplay").html("".error);
$("#erorrModel").modal("open");
}
});
}
});
$('#ajaxRegister').validate({
onfocusout: false,
onkeyup: false,
rules: {
reg_firstname: {
required: true
},
reg_lastname: {
required: true
},
// reg_password: {
// required: true
// },
reg_phone: {
required: true
},
// conditions: {
// required: true
// },
reg_email: {
required: true,
email: true,
// unregistered users can book now;
// remote: {
// url: "/site/ajaxmailexist",
// type: "post"
// }
}
},
messages: {
required: "Please fill this field.",
reg_email: {
required: "Please enter your email address.",
email: "Please enter a valid email address.",
remote: "Email already in use!"
},
conditions: {
required: "Please accept the terms of use.",
}
},
});
$html.on("submit", "#ajaxRegister", function(e) {
e.preventDefault();
var $this = $(this);
if (!$('#test5').is(':checked')) {
alert('Please accept the terms of service.');
return false;
}
$this.valid();
if ($(this).valid()) {
showLoader();
var reg_firstname = $this.find('input[name="reg_firstname"]').val();
var reg_lastname = $this.find('input[name="reg_lastname"]').val();
var reg_email = $this.find('input[name="reg_email"]').val();
var reg_password = $this.find('input[name="reg_password"]').val();
var reg_phone = $this.find('input[name="reg_phone"]').val();
var reg_lat = $this.find('input[name="reg_lat"]').val();
var reg_lon = $this.find('input[name="reg_lon"]').val();
var newRoute = $('#bookingLink').val();
var siteMode = $('#siteMode').val();
var mailing = $('#mailing').val();
var bookinglanguage = $('#bookingLanguage').val();
var merchant = $('#merchantid_book').val();
$.ajax({
url: "/site/siteregister",
type: 'POST',
data: {
reg_firstname: reg_firstname,
reg_lastname: reg_lastname,
reg_email: reg_email,
reg_password: reg_password,
reg_phone: reg_phone,
reg_lat: reg_lat,
reg_lon: reg_lon,
siteMode: siteMode,
language: bookinglanguage,
mailing: mailing,
merchant: merchant
},
cache: false,
success: function(resp) {
var obj = $.parseJSON(resp);
if ( obj.status == 100 ) {
$('#personid').val(obj.personid);
$('#phoneid').val(reg_phone);
$('#issetUser').val("available");
setBlocks();
setTimeout(function() {
$loginLbl.fadeOut(400, function() {
$loginLbl.attr("href", "/site/logout");
$loginLbl.find('span').html(reg_firstname + reg_lastname + " - Logout");
});
$loginLbl.fadeIn(400);
}, 1000);
if (newRoute == "assistant") {
$(".form-signup, .form-booking, .form-signin, .form-assistant").slideUp(500);
$(".form-assistantBooking").slideDown(500);
setTimeout(function() {
$("#trigger_assistantbooking").trigger("click");
}, 1000);
}
else {
$(".form-signup, .form-signin, .form-assistant, .form-assistantBooking").slideUp(500);
$(".form-booking").slideDown(500);
setTimeout(function() {
$("#trigger_booking").trigger("click");
}, 1000);
}
}
else{
hideLoader();
setTimeout(function() {
$("#errorDisplay").html(obj.msg);
$("#erorrModel").modal("open");
}, 1000);
}
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
});
$html.on("click", "#lostPhonesubmit", function(e) {
e.preventDefault();
var personid =$html.find("#personid").val();
var phoneno =$(this).closest("#lostPhone").find("#newphoneid").val();
var phoneError =$(this).closest("#lostPhone").find("#phoneError");
if ( phoneno !='' ) {
if ( $.isNumeric(phoneno) && phoneno.length >= 7) {
phoneError.fadeOut( function() {
phoneError.remove();
});
setPhonenumber(personid, phoneno);
}
else{
phoneError.fadeOut( function() {
phoneError.html('Minimum 7 numbers only!. Other characters not allowed!.');
phoneError.fadeIn();
});
}
}
else{
phoneError.fadeOut( function() {
phoneError.html('Phone number required!.');
phoneError.fadeIn();
});
}
});
$('#ajaxBooking').validate({
invalidHandler: function(event, validator) {
},
onfocusout: false,
onkeyup: false,
ignore: '*:not([name])',
rules: {
book_session: {
required: true
},
book_date: {
required: true
},
book_time: {
required: true
},
book_adult: {
validOrNah: true,
}
}
});
$html.on("submit", "#ajaxBooking", function(e) {
e.preventDefault();
var $this = $(this);
$this.valid(); // Check form is valid or not
M.updateTextFields();
if ($(this).valid()) {
var bookingsession = $this.find('#book_session option:selected').val();
var bookingdate = $this.find('input[name="book_date"]').val();
var bookingtime = $this.find('#book_time option:selected').val();
var adults = $this.find('#book_adult option:selected').val();
var children = $this.find('#book_children option:selected').val();
var merchantid = $('#merchantid_book').val();
var merchantname = $('#merchant_name').val();
var personid = $('#personid').val();
var phone = $('#phoneid').val();
var version = $('#version').val();
var offerid = $('#offerid').val();
var bookinglanguage = $('#bookingLanguage').val();
var startPageUrl = $('#startPageUrl').val();
var infants = 0;
if ( bookingMovement() == "freeze" ) {
hideLoader();
var bookingHtml='Restaurant: '+ merchantname +'' +
'Date: '+ bookingdate +' '+ bookingtime +' ' +
'Persons:  Adult(s) : '+ adults +', Children : '+ children +'';
$("#bookingData").html(bookingHtml);
$("#bookingDataRestaurant").html(merchantname);
$("#bookingDataDate").html(bookingdate +' '+ bookingtime);
$("#bookingDataAdults").html(adults);
$("#bookingDataChildren").html(children);
$("#bookingconfirmModal").modal("open");
}
else{
showLoader();
$.ajax({
url: "/site/sitebooking",
type: 'POST',
async: false,
data: {
bookingdate: bookingdate,
bookingsession: bookingsession,
bookingtime: bookingtime,
adults: adults,
children: children,
infants: infants,
merchantid: merchantid,
personid: personid,
version: version,
offerid: offerid,
language: bookinglanguage
},
success: function(resp) {
var obj = $.parseJSON(resp);
if (obj.code == 100) {
window.location.href = "/fr/site/confirmation?booking=" + (obj.bookingid);
hideLoader();
$('#ajaxBooking').fadeOut( function() {
$('#ajaxBooking')[0].reset();
$('#ajaxBooking').fadeIn();
});
console.log(phone);
var successMsg;
$('#bookingid').val(obj.bookingid);
if ( phone == '') {
var phoneForm='';
successMsg='Your booking is confirmed!
' + phoneForm;
}
else{
successMsg='Your booking is confirmed!
';
window.location.href = "/fr/site/confirmation?booking=" + (obj.bookingid);
}
$("#successDisplay").html(successMsg);
$("#successModel").modal("open");
$("#movement").val("freeze");
}
else {
hideLoader();
$("#errorDisplay").html(obj.msg);
$("#erorrModel").modal("open");
$('#ajaxBooking')[0].reset();
}
},
error: function(xhr, status, error) {
hideLoader();
console.log(error);
}
});
}
}
});
$('#ajaxassistantBookings').validate({
onfocusout: false,
onkeyup: false,
rules: {
assistant_book_date: {
required: true
},
assistant_book_session:{
required: true
},
assistant_book_time: {
required: true
},
childuserEmail: {
required: true,
email: true
},
noofPersons: {
required: true,
number: true
}
}
});
$html.on("submit", "#ajaxassistantBookings", function(e) {
e.preventDefault();
var $this = $(this);
$this.valid();
if ($(this).valid()) {
storeValues("assistant");
showLoader();
var bookingsession = $this.find('#assistant_book_session option:selected').val();
var bookingdate = $this.find('input[name="assistant_book_date"]').val();
var bookingtime = $this.find('#assistant_book_time option:selected').val();
var childuserEmail = $this.find('input[name="childuserEmail"]').val();
var adults = $this.find('input[name="noofPersons"]').val();
var merchantid = $this.find('input[name="book_merchantid"]').val();
var merchantEmail = $this.find('input[name="merchantEmail"]').val();
var appKey = "";
$.ajax({
url: "/app/assistantbooking",
type: 'POST',
data: {
bookingsession: bookingsession,
bookingdate: bookingdate,
bookingtime: bookingtime,
childuserEmail: childuserEmail,
adults: adults,
merchantid: merchantid,
merchantEmail: merchantEmail,
appKey: appKey
},
cache: false,
success: function(resp) {
hideLoader();
var obj = $.parseJSON(resp);
if (obj.status == 100) {
var newbooking = $('#bookingid').val();
window.location.href = "/fr/site/confirmation?booking=" + newbooking;
}
else {
$("#errorDisplay").html(obj.message);
$("#erorrModel").modal("open");
$('#ajaxassistantBookings')[0].reset();
}
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
});
// **********************
// LOGIN & SIGN UP
// **********************
$html.on("click", ".to-signin, .to-signin-link, .to-signup, .to-signup-link", function(e) {
e.preventDefault();
var $this = $(this);
var door = $(this).attr("data-door");
var startPageUrl = $('#startPageUrl').val();
var whichForm = "myself"; // this value must change dynamically if assistant booking enable
if ( whichForm == "myself" ) {
var ajaxBooking = $( "#ajaxBooking" );
ajaxBooking.validate();
if ( ajaxBooking.valid() ) {
$this.addClass("top-active-button").siblings().removeClass("top-active-button");
if ( door == "login" ) {
$(".form-signup, .form-booking, .form-assistantBooking").slideUp(500);
$(".form-signin").slideDown(500);
}
if ( door == "signup" ) {
$(".form-signin, .form-booking, .form-assistantBooking").slideUp(500);
$(".form-signup").slideDown(500);
}
return true;
}
else{
return false;
}
}
else if( whichForm == "assistant" ){
var ajaxassistantBookings = $( "#ajaxassistantBookings" );
ajaxassistantBookings.validate();
if ( ajaxassistantBookings.valid() ) {
$this.addClass("top-active-button").siblings().removeClass("top-active-button");
$(".form-signin, .form-booking, .form-assistantBooking").slideUp(500);
$(".form-signup").slideDown(500);
storeValues(whichForm);
return true;
}
else{
return false;
}
}
});
$html.on("click", ".to-goback-link", function(e) {
e.preventDefault();
var $this = $(this);
$(".form-signup, .form-signin").slideUp(500);
$(".form-booking").slideDown(500);
return true;
});
$html.on("click", "#triggerPickuser", function(e) {
e.preventDefault();
linkedUsers();
$('#pickUsers').modal({
dismissible: true, // Modal can be dismissed by clicking outside of the modal
opacity: .5, // Opacity of modal background
inDuration: 300, // Transition in duration
outDuration: 200, // Transition out duration
startingTop: '4%', // Starting top style attribute
endingTop: '10%', // Ending top style attribute
ready: function(modal, trigger) { // Callback for Modal open. Modal and trigger parameters available.
},
complete: function() {
//pickedChilds();
} // Callback for Modal close
});
$('#pickUsers').modal('open');
});
$('.modal.successModel').modal({
dismissible: true, // Modal can be dismissed by clicking outside of the modal
opacity: .5, // Opacity of modal background
inDuration: 300, // Transition in duration
outDuration: 200, // Transition out duration
startingTop: '4%', // Starting top style attribute
endingTop: '10%', // Ending top style attribute
ready: function(modal, trigger) { // Callback for Modal open. Modal and trigger parameters available.
},
complete: function() {
location.reload();
} // Callback for Modal close
});
$html.on("click", ".FBlogin", function(e) {
e.preventDefault();
FB.login(function(r) {
if (r.authResponse) {
var accessToken = r.authResponse.accessToken;
loginFacebook();
}
});
});
$html.on("click", ".movement", function(e) {
e.preventDefault();
showLoader();
var movement=$(this).attr("data-movement");
$("#movement").val(movement);
$("#bookingconfirmModal").modal("close");
if ( movement == "go") {
setTimeout(function() {
$(".form-signup, .form-signin, .form-assistant, .form-assistantBooking").slideUp(500);
$(".form-booking").slideDown(500);
$("#trigger_booking").trigger("click");
}, 500);
}
else{
hideLoader();
$("#movement").val("freeze");
}
});
$("#bookingconfirmModal").modal({
dismissible: false
});
//init
var merchantid = $("#merchantid_book").val();
var slotversion = $("#slotversion_book").val();
var bookingdate = $("#book_date").val();
sessionUpdate(merchantid, slotversion, bookingdate);
});
})();