| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- var remainingMenu = 0;
- var package_id = 1;
- $(document).ready(function() {
- var events = null;
- var budss_qty = 0;
- var budss_event_date = '';
- var budss_event_time = '';
- var timer = 0;
- var remainingTime = 0;
- //Clear session
- window.localStorage.clear();
- window.localStorage.setItem('budss_product_id', 1);
-
- //Initialize transaction
- $.get('/api/initialize/',function(response) {
- if (response !== '' && response !== undefined) {
- window.localStorage.setItem('budss_uid', response);
- }
- else {
- console.warning('Unable to initialize the transaction...');
- }
- });
- $('#field').on('focus', function() {
- if ($('#field').val() === '0') {
- $('#field').val('');
- }
- });
- $('#field').on('blur', function() {
- if ($('#field').val() === '') {
- $('#field').val(0);
- }
- });
- $('#field').on('change', function() {
- budss_qty = $('#field').val();
- window.localStorage.setItem('budss_qty', budss_qty);
- });
-
- $('#Date-20').on('change', function() {
- budss_event_date = $('#Date-20').val();
- $('#days-of-the-week-2').html('');
- window.localStorage.setItem('budss_event_date', budss_event_date);
- $('#days-of-the-week-2').append($('<option>', {value: '', text: 'Select a time...'}));
- $.each(events, function(index, value) {
- if (value['datum'] === budss_event_date) {
- $('#days-of-the-week-2').append($('<option>', {value: value['id'], text: value['time']}));
- }
- });
- });
-
- $('#days-of-the-week-2').on('change', function() {
- budss_event_time = $('#days-of-the-week-2').val();
- window.localStorage.setItem('budss_event_time', budss_event_time);
- });
-
- $('#bookingStep1Btn').on('click', function(event) {
- const participants = window.localStorage.getItem('budss_qty');
- if (participants !== null && participants > 0) {
- $('#step1Error').hide();
- let enabledDates = [];
- $.getJSON('/api/getevents/?package_id=' + package_id + '&participants=' + participants, function(data) {
- events = data;
- $.each(data, function(index, value) {
- enabledDates.push(value['date']);
- });
-
- $("#Date-20").datepicker({
- minDate: 0,
- dateFormat: 'yy-mm-dd',
- beforeShowDay: checkDate
- });
-
- function checkDate(in_date) {
- in_date = in_date.getFullYear() + '-' + (in_date.getMonth() + 1) + '-' + in_date.getDate();
- if (enabledDates.includes(in_date)) {
- return [true, "av", "Available"];
- }
- else {
- return [false, "notav", 'Not Available'];
- }
- }
-
- $('.step-1').hide();
- $('.step-2').show();
- setTimeout(() => {
- const viewTop = $('.cta-wrap').offset().top;
- $('html, body').animate({
- scrollTop: viewTop-200
- }, 100);
- },100);
- });
- }
- else {
- $('#step1Error').show();
- }
- });
-
- $('#bookingStepBack').on('click', function(event) {
- $('.step-2').hide();
- $('.step-1').show();
- });
- $('#bookingStepBack2').on('click', function(event) {
- $('.step-3').hide();
- $('.step-2').show();
- });
- $('#bookingStep2Btn').on('click', function(event) {
- const participants = window.localStorage.getItem('budss_qty');
- const eventid = window.localStorage.getItem('budss_event_time');
- const uid = window.localStorage.getItem('budss_uid');
- remainingMenu = parseInt(participants);
- console.log('Remaining menu items 1: ', remainingMenu);
-
- $.get('/api/reservation/?event_id='+eventid+'&qty='+participants+'&uuid='+uid, function(result) {
- const response = JSON.parse(result);
- remainingTime = parseInt(response['timer']);
- timer = setInterval(function() {
- remainingTime--;
- window.localStorage.setItem('remainingTime', remainingTime);
- if (remainingTime < 60) {
- $('.cart_timer').css('color','#ff0000');
- }
- if (remainingTime === 0) {
- window.location.reload();
- }
- const minutes = Math.floor(remainingTime / 60);
- const remainingSeconds = remainingTime % 60;
- $('.cart_timer').html(`${minutes}:${remainingSeconds.toString().padStart(2, '0')}`);
- },1000);
- });
-
- $('#menuContainer').html('');
- if (budss_event_date !== '' && budss_event_time !== '') {
- $('.step-2').hide();
- let menu = events.map(function(item) {
- if (item['id'] === parseInt(budss_event_time)) {
- return item['products'];
- }
- });
- menu = menu.filter(function( element ) {
- return element !== undefined;
- });
-
- $.each(menu[0], function(index, value) {
- if (value['currency'] === 'huf') {
- $.post('/api/getproducts', value, function(response) {
- $('#menuContainer').append(response);
- });
- }
- });
- const participants = window.localStorage.getItem('budss_qty');
- $('.menu_counter').html(participants);
- if (!localStorage.getItem('budss_products')) {
- localStorage.setItem('budss_products', JSON.stringify({}));
- }
- $('.step-3').show();
- }
- else {
- $('#step2Error').show();
- }
- });
-
- $('#bookingStep3Btn').on('click', function(event) {
- $('#step3Error').hide();
- if ($('.menu_counter').html() === '0') {
- window.location.href='/order';
- }
- else {
- $('#step3Error').show();
- }
- });
- });
- function decProductQty(id) {
- const actual = parseInt($('.menu_'+id).val());
- const participants = parseInt(window.localStorage.getItem('budss_qty'));
- let products = JSON.parse(window.localStorage.getItem('budss_products'));
- if (actual > 0 && remainingMenu <= participants) {
- const newValue = actual - 1;
- const remaining = participants - newValue;
- const hash = 'id_'+id;
- remainingMenu++;
- if (!products[hash]) {
- products[hash] = 0;
- }
- products[hash] = newValue;
- window.localStorage.setItem('budss_products', JSON.stringify(products));
- $('.menu_counter').html(remainingMenu.toString());
- $('.menu_'+id).val(newValue);
- }
- if (remainingMenu === 0) {
- $('#bookingStep3Btn').css('background-color', '#e5ff29');
- }
- else {
- $('#bookingStep3Btn').css('background-color', '#afafaf');
- }
- }
- function incProductQty(id) {
- const actual = parseInt($('.menu_'+id).val());
- const participants = parseInt(window.localStorage.getItem('budss_qty'));
- let products = JSON.parse(window.localStorage.getItem('budss_products'));
- if (remainingMenu <= participants && remainingMenu > 0) {
- const newValue = actual + 1;
- const remaining = participants - newValue;
- const hash = 'id_'+id;
- remainingMenu--;
- if (!products[hash]) {
- products[hash] = 0;
- }
- products[hash] = newValue;
- window.localStorage.setItem('budss_products', JSON.stringify(products));
- $('.menu_counter').html(remainingMenu.toString());
- $('.menu_'+id).val(newValue);
- }
- if (remainingMenu === 0) {
- $('#bookingStep3Btn').css('background-color', '#e5ff29');
- }
- else {
- $('#bookingStep3Btn').css('background-color', '#afafaf');
- }
- }
- function setService(obj, id) {
- $('.service-card_wrapper').removeClass('active-service');
- $(obj).addClass('active-service');
- package_id = id;
- window.localStorage.setItem('budss_product_id', id);
- }
|