1/* ----------------- Start Document ----------------- */ 2(function($){ 3"use strict"; 4 5$(document).ready(function(){ 6 7 var inputClicked = false; 8/*----------------------------------------------------*/ 9 /* Booking widget and confirmation form 10 /*----------------------------------------------------*/ 11 $('a.booking-confirmation-btn').on('click', function(e){ 12 13 e.preventDefault(); 14 var bookingForm = $('#booking-confirmation'); 15 if (bookingForm[0].checkValidity()) { 16 var button = $(this); 17 button.addClass('loading'); 18 $('#booking-confirmation').submit(); 19 } 20 21 }); 22 23 $(document).bind('change', function(e){ 24 if( $(e.target).is(':invalid') ){ 25 $(e.target).parent().addClass('invalid'); 26 } else { 27 $(e.target).parent().removeClass('invalid'); 28 } 29 }); 30 31 $('#listeo-coupon-link').on('click', function(e){ 32 e.preventDefault(); 33 $('.coupon-form').toggle(); 34 }); 35 36 function validate_coupon(listing_id,price) { 37 38 var current_codes = $('#coupon_code').val(); 39 if(current_codes){ 40 var codes = current_codes.split(','); 41 $.each(codes, function(index, item) { 42 console.log(item); 43 var ajax_data = { 44 'listing_id' : listing_id, 45 'coupon' : item, 46 'coupons' : codes, 47 'price' : price, 48 'action' : 'listeo_validate_coupon' 49 }; 50 $.ajax({ 51 type: 'POST', 52 dataType: 'json', 53 url: listeo.ajaxurl, 54 data: ajax_data, 55 56 success: function(data){ 57 58 if(data.success){ 59 60 61 62 } else { 63 64 65 $('#coupon-widget-wrapper-output div.error').html(data.message).show(); 66 $('#coupon-widget-wrapper-applied-coupons span[data-coupon="'+item+'"] i').trigger('click'); 67 $('#apply_new_coupon').val(''); 68 $("#coupon-widget-wrapper-output .error").delay(3500).hide(500); 69 70 } 71 $('a.listeo-booking-widget-apply_new_coupon').removeClass('active'); 72 } 73 }); 74 }); 75 } 76 77 78 79 } 80 81 // Apply new coupon 82 $('a.listeo-booking-widget-apply_new_coupon').on('click', function(e){ 83 84 e.preventDefault(); 85 $(this).addClass('active'); 86 $('#coupon-widget-wrapper-output div').hide(); 87 88 var ajax_data = { 89 'listing_id' : $('#listing_id').val(), 90 'coupon' : $('#apply_new_coupon').val(), 91 'price' : $('.booking-estimated-cost').data('price'), 92 'action' : 'listeo_validate_coupon' 93 }; 94 95 //check if it was already addd 96 97 var current_codes = $('#coupon_code').val(); 98 var result = current_codes.split(','); 99 var arraycontainscoupon = (result.indexOf($('#apply_new_coupon').val()) > -1); 100 101 $('#coupon-widget-wrapper-output div').hide(); 102 if(arraycontainscoupon) { 103 $(this).removeClass('active'); 104 $('input#apply_new_coupon').removeClass('bounce').addClass('bounce'); 105 return; 106 } 107 $.ajax({ 108 type: 'POST', 109 dataType: 'json', 110 url: listeo.ajaxurl, 111 data: ajax_data, 112 113 success: function(data){ 114 115 if(data.success){ 116 117 if(current_codes.length>0){ 118 $('#coupon_code').val(current_codes + ',' + data.coupon); 119 } else { 120 $('#coupon_code').val(data.coupon); 121 } 122 $('#apply_new_coupon').val(''); 123 $('#coupon-widget-wrapper-applied-coupons').append("<span data-coupon="+data.coupon+">"+data.coupon+"<i class='fa fa-times'></i></span>") 124 $('#coupon-widget-wrapper-output .success').show(); 125 if($('#booking-confirmation-summary').length>0){ 126 calculate_booking_form_price(); 127 } else { 128 if($("#form-booking").hasClass('form-booking-event')){ 129 calculate_price(); 130 } else { 131 check_booking(); 132 } 133 134 } 135 $("#coupon-widget-wrapper-output .success").delay(3500).hide(500); 136 137 } else { 138 139 $('input#apply_new_coupon').removeClass('bounce').addClass('bounce'); 140 $('#coupon-widget-wrapper-output div.error').html(data.message).show(); 141 142 $('#apply_new_coupon').val(''); 143 $("#coupon-widget-wrapper-output .error").delay(3500).hide(500); 144 145 } 146 $('a.listeo-booking-widget-apply_new_coupon').removeClass('active'); 147 } 148 }); 149 }); 150 151
152 // Remove coupon from widget and calculate price again 153 $('#coupon-widget-wrapper-applied-coupons').on('click', 'span i', function(e){ 154 155 var coupon = $(this).parent().data('coupon'); 156 157 158 var coupons = $('#coupon_code').val(); 159 var coupons_array = coupons.split(','); 160 coupons_array = coupons_array.filter(function(item) { 161 console.log(item); 162 console.log(coupon); 163 return item !== coupon 164 }) 165 166 $('#coupon_code').val(coupons_array.join(",")); 167 $(this).parent().remove(); 168 if($('#booking-confirmation-summary').length>0){ 169 calculate_booking_form_price(); 170 } else { 171 check_booking(); 172 calculate_price(); 173 174 } 175 }); 176 177 178 179 //Book now button 180 $('.listing-widget').on('click', 'a.book-now', function(e){ 181 182 var button = $(this); 183 184 if($('#date-picker').val()){ 185 inputClicked = true; 186 187 188 if ($(".time-picker").length && !$(".time-picker").val()) { 189 inputClicked = false; 190 191 } 192 if ($("#slot").length && !$("#slot").val()) { 193 inputClicked = false; 194 195 } 196 if(inputClicked){ 197 check_booking(); 198 } 199 200 201 } 202 console.log(inputClicked); 203 204 if(inputClicked == false){ 205 $('.time-picker,.time-slots-dropdown,.date-picker-listing-rental').addClass('bounce'); 206 } else { 207 button.addClass('loading'); 208 } 209 e.preventDefault(); 210 211 var freeplaces = button.data('freeplaces'); 212 213 214 // var checked = $(".bookable-services input[type=checkbox]:checked").length; 215 216 // if (!checked) { 217 // alert("You must select at least one extra service."); 218 // return false; 219 // } 220 221 222 223 setTimeout(function() { 224 button.removeClass('loading'); 225 $('.time-picker,.time-slots-dropdown,.date-picker-listing-rental').removeClass('bounce'); 226 227 }, 3000); 228 229 try { 230 if ( freeplaces > 0 ) 231 { 232 233 // preparing data for ajax 234 var startDataSql = moment( $('#date-picker').data('daterangepicker').startDate, ["MM/DD/YYYY"]).format("YYYY-MM-DD"); 235 var endDataSql = moment( $('#date-picker').data('daterangepicker').endDate, ["MM/DD/YYYY"]).format("YYYY-MM-DD"); 236 237 var ajax_data = { 238 'listing_type' : $('#listing_type').val(), 239 'listing_id' : $('#listing_id').val() 240 //'nonce': nonce 241 }; 242 var invalid = false; 243 if ( startDataSql ) ajax_data.date_start = startDataSql; 244 if ( endDataSql ) ajax_data.date_end = endDataSql; 245 if ( $('input#slot').val() ) ajax_data.slot = $('input#slot').val(); 246 if ( $('.time-picker#_hour').val() ) ajax_data._hour = $('.time-picker#_hour').val(); 247 if ( $('.time-picker#_hour_end').val() ) ajax_data._hour_end = $('.time-picker#_hour_end').val(); 248 if ( $('.adults').val() ) ajax_data.adults = $('.adults').val(); 249 if ( $('.childrens').val() ) ajax_data.childrens = $('.childrens').val(); 250 if ( $('#tickets').val() ) ajax_data.tickets = $('#tickets').val(); 251 if ( $('#coupon_code').val() ) ajax_data.coupon = $('#coupon_code').val(); 252 253 if ( $('#listing_type').val() == 'service' ) { 254 255 if( $('input#slot').val() == undefined || $('input#slot').val() == '' ) { 256 inputClicked = false; 257 invalid = true; 258 } 259 if( $('.time-picker').length ) { 260 261 invalid = false; 262 } 263 } 264 265 if(invalid == false) { 266 267 var services = []; 268 // $.each($("input[name='_service[]']:checked"), function(){ 269 // services.push($(this).val()); 270 // }); 271 $.each($("input.bookable-service-checkbox:checked"), function(){ 272 var quantity = $(this).parent().find('input.bookable-service-quantity').val(); 273 services.push({"service" : $(this).val(), "value" : quantity}); 274 }); 275 ajax_data.services = services; 276 $('input#booking').val( JSON.stringify( ajax_data ) ); 277 $('#form-booking').submit(); 278 279 280 } 281 282 } 283 } catch (e) { 284 console.log(e); 285 } 286 287 if ( $('#listing_type').val() == 'event' ) 288 { 289 290 var ajax_data = { 291 'listing_type' : $('#listing_type').val(), 292 'listing_id' : $('#listing_id').val(), 293 'date_start' : $('.booking-event-date span').html(), 294 'date_end' : $('.booking-event-date span').html(), 295 //'nonce': nonce 296 }; 297 if ( $('#coupon_code').val() ) ajax_data.coupon = $('#coupon_code').val(); 298 var services = []; 299 $.each($("input.bookable-service-checkbox:checked"), function(){ 300 var quantity = $(this).parent().find('input.bookable-service-quantity').val(); 301 services.push({"service" : $(this).val(), "value" : quantity}); 302 }); 303 ajax_data.services = services; 304 305 // converent data 306 ajax_data['date_start'] = moment(ajax_data['date_start'], wordpress_date_format.date).format('YYYY-MM-DD'); 307 ajax_data['date_end'] = moment(ajax_data['date_end'], wordpress_date_format.date).format('YYYY-MM-DD'); 308 if ( $('#tickets').val() ) ajax_data.tickets = $('#tickets').val(); 309 $('input#booking').val( JSON.stringify( ajax_data ) ); 310 311 $('#form-booking').submit(); 312 313 } 314 315 }); 316 317 if(Boolean(listeo_core.clockformat)){ 318 var dateformat_even = wordpress_date_format.date+' HH:mm'; 319 } else { 320 var dateformat_even = wordpress_date_format.date+' hh:mm A'; 321 } 322 323 324 function updateCounter() { 325 var len = $(".bookable-services input[type='checkbox']:checked").length; 326 if(len>0){ 327 $(".booking-services span.services-counter").text(''+len+''); 328 $(".booking-services span.services-counter").addClass('counter-visible'); 329 } else{ 330 $(".booking-services span.services-counter").removeClass('counter-visible'); 331 $(".booking-services span.services-counter").text('0'); 332 } 333 } 334 335 $('.single-service').on('click', function() { 336 updateCounter(); 337 $(".booking-services span.services-counter").addClass("rotate-x"); 338 339 setTimeout(function() { 340 $(".booking-services span.services-counter").removeClass("rotate-x"); 341 }, 300); 342 }); 343 344 345 // $( ".input-datetime" ).each(function( index ) { 346 // var $this = $(this); 347 // var input = $(this).next('input'); 348 // var date = parseInt(input.val()); 349 // if(date){ 350 // var a = new Date(date); 351 // var timestamp = moment(a); 352 // $this.val(timestamp.format(dateformat_even)); 353 // } 354 355 // }); 356 357 //$('#_event_date').val(timestamp.format(dateformat_even)); 358 359 $('.input-datetime').daterangepicker({ 360 "opens": "left", 361 // checking attribute listing type and set type of calendar 362 singleDatePicker: true, 363 timePicker: true, 364 autoUpdateInput: false, 365 timePicker24Hour: Boolean(listeo_core.clockformat), 366 minDate: moment().subtract(0, 'days'), 367 368 locale: { 369 format : dateformat_even, 370 371 "firstDay" : parseInt(wordpress_date_format.day), 372 "applyLabel" : listeo_core.applyLabel, 373 "cancelLabel" : listeo_core.cancelLabel, 374 "fromLabel" : listeo_core.fromLabel, 375 "toLabel" : listeo_core.toLabel, 376 "customRangeLabel": listeo_core.customRangeLabel, 377 "daysOfWeek": [ 378 listeo_core.day_short_su, 379 listeo_core.day_short_mo, 380 listeo_core.day_short_tu, 381 listeo_core.day_short_we, 382 listeo_core.day_short_th, 383 listeo_core.day_short_fr, 384 listeo_core.day_short_sa 385 ], 386 "monthNames": [ 387 listeo_core.january, 388 listeo_core.february, 389 listeo_core.march, 390 listeo_core.april, 391 listeo_core.may, 392 listeo_core.june, 393 listeo_core.july, 394 listeo_core.august, 395 listeo_core.september, 396 listeo_core.october, 397 listeo_core.november, 398 listeo_core.december, 399 ], 400 }, 401 402 403 }); 404 405 $('.input-datetime').on('apply.daterangepicker', function(ev, picker) { 406 $(this).val(picker.startDate.format(dateformat_even)); 407 }); 408 409 $('.input-datetime').on('cancel.daterangepicker', function(ev, picker) { 410 $(this).val(''); 411 }); 412 413 414 $('.input-date').daterangepicker({ 415 "opens": "left", 416 // checking attribute listing type and set type of calendar 417 singleDatePicker: true, 418 timePicker: false, 419 autoUpdateInput: false, 420 421 minDate: moment().subtract(0, 'days'), 422 423 locale: { 424 format : 'YYYY-MM-DD', 425 "firstDay" : parseInt(wordpress_date_format.day), 426 "applyLabel" : listeo_core.applyLabel, 427 "cancelLabel" : listeo_core.cancelLabel, 428 "fromLabel" : listeo_core.fromLabel, 429 "toLabel" : listeo_core.toLabel, 430 "customRangeLabel": listeo_core.customRangeLabel, 431 "daysOfWeek": [ 432 listeo_core.day_short_su, 433 listeo_core.day_short_mo, 434 listeo_core.day_short_tu, 435 listeo_core.day_short_we, 436 listeo_core.day_short_th, 437 listeo_core.day_short_fr, 438 listeo_core.day_short_sa 439 ], 440 "monthNames": [ 441 listeo_core.january, 442 listeo_core.february, 443 listeo_core.march, 444 listeo_core.april, 445 listeo_core.may, 446 listeo_core.june, 447 listeo_core.july, 448 listeo_core.august, 449 listeo_core.september, 450 listeo_core.october, 451 listeo_core.november, 452 listeo_core.december, 453 ], 454 }, 455 456 457 }); 458 459 $('.input-date').on('apply.daterangepicker', function(ev, picker) { 460 $(this).val(picker.startDate.format('YYYY-MM-DD')); 461 }); 462 463 $('.input-date').on('cancel.daterangepicker', function(ev, picker) { 464 $(this).val(''); 465 }); 466 // $('.input-datetime').on( 'apply.daterangepicker', function(){ 467 468 // var picked_date = $(this).val(); 469 // var input = $(this).next('input'); 470 // input.val(moment(picked_date,dateformat_even).format('YYYY-MM-DD HH:MM:SS')); 471 // } ); 472 473 function wpkGetThisDateSlots( date ) { 474 475 var slots = { 476 isFirstSlotTaken: false, 477 isSecondSlotTaken: false 478 } 479 480 if ( $( '#listing_type' ).val() == 'event' ) 481 return slots; 482 483 if ( typeof disabledDates !== 'undefined' ) { 484 if ( wpkIsDateInArray( date, disabledDates ) ) { 485 slots.isFirstSlotTaken = slots.isSecondSlotTaken = true; 486 return slots; 487 } 488 } 489 490 if ( typeof wpkStartDates != 'undefined' && typeof wpkEndDates != 'undefined' ) { 491 slots.isSecondSlotTaken = wpkIsDateInArray( date, wpkStartDates ); 492 slots.isFirstSlotTaken = wpkIsDateInArray( date, wpkEndDates ); 493 } 494 //console.log(slots); 495 return slots; 496 497 } 498 499 function wpkIsDateInArray( date, array ) { 500 return jQuery.inArray( date.format("YYYY-MM-DD"), array ) !== -1; 501 } 502 503 504 $('#date-picker').daterangepicker({ 505 "opens": "left", 506 // checking attribute listing type and set type of calendar 507 singleDatePicker: ( $('#date-picker').data('listing_type') == 'rental' ? false : true ), 508 timePicker: false, 509 minDate: moment().subtract(0, 'days'), 510 minSpan : { days: $('#date-picker').data('minspan') }, 511 startDate : Cookies.get('listeo_rental_startdate'), 512 endDate : Cookies.get('listeo_rental_enddate'), 513 locale: { 514 format: wordpress_date_format.date, 515 "firstDay": parseInt(wordpress_date_format.day), 516 "applyLabel" : listeo_core.applyLabel, 517 "cancelLabel" : listeo_core.cancelLabel, 518 "fromLabel" : listeo_core.fromLabel, 519 "toLabel" : listeo_core.toLabel, 520 "customRangeLabel": listeo_core.customRangeLabel, 521 "daysOfWeek": [ 522 listeo_core.day_short_su, 523 listeo_core.day_short_mo, 524 listeo_core.day_short_tu, 525 listeo_core.day_short_we, 526 listeo_core.day_short_th, 527 listeo_core.day_short_fr, 528 listeo_core.day_short_sa 529 ], 530 "monthNames": [ 531 listeo_core.january, 532 listeo_core.february, 533 listeo_core.march, 534 listeo_core.april, 535 listeo_core.may, 536 listeo_core.june, 537 listeo_core.july, 538 listeo_core.august, 539 listeo_core.september, 540 listeo_core.october, 541 listeo_core.november, 542 listeo_core.december, 543 ], 544 545 }, 546 547 isCustomDate: function( date ) { 548 549 var slots = wpkGetThisDateSlots( date ); 550 551 if ( ! slots.isFirstSlotTaken && ! slots.isSecondSlotTaken ) 552 return []; 553 554 if ( slots.isFirstSlotTaken && ! slots.isSecondSlotTaken ) { 555 return [ 'first-slot-taken' ]; 556 } 557 558 if ( slots.isSecondSlotTaken && ! slots.isFirstSlotTaken ) { 559 return [ 'second-slot-taken' ]; 560 } 561 562 }, 563 564 isInvalidDate: function(date) { 565 566 // working only for rental 567 568 569 if ($('#listing_type').val() == 'event' ) return false;
570 if ($('#listing_type').val() == 'service' && typeof disabledDates != 'undefined' ) { 571 if ( jQuery.inArray( date.format("YYYY-MM-DD"), disabledDates ) !== -1) return true; 572 573 } 574 575 if ($(".time-slots-dropdown").length) { 576 var timeslotdays = $(".time-slots-dropdown") 577 .data("slots-days") 578 .toString(); 579 580 var timeslotdaysArray = timeslotdays.split(","); 581 // O is sunday in moment, monday in slot 582 if (timeslotdaysArray.includes(moment(date).day().toString())) { 583 console.log("day"); 584 return false; 585 } else { 586 console.log("noday"); 587 return true; 588 } 589 } 590 591 if ($('#listing_type').val() == 'rental' ) { 592 593 var slots = wpkGetThisDateSlots( date ); 594 595 return slots.isFirstSlotTaken && slots.isSecondSlotTaken; 596 } 597 } 598 599 }); 600 601 $('#date-picker').on('show.daterangepicker', function(ev, picker) { 602 603 $('.daterangepicker').addClass('calendar-visible calendar-animated'); 604 $('.daterangepicker').removeClass('calendar-hidden'); 605 }); 606 $('#date-picker').on('hide.daterangepicker', function(ev, picker) { 607 608 $('.daterangepicker').removeClass('calendar-visible'); 609 $('.daterangepicker').addClass('calendar-hidden'); 610 }); 611 612 function calculate_price(){ 613 614 var ajax_data = { 615 'action': 'calculate_price', 616 'listing_type' : $('#date-picker').data('listing_type'), 617 'listing_id' : $('input#listing_id').val(), 618 'tickets' : $('input#tickets').val(), 619 'coupon' : $('input#coupon_code').val(), 620 //'nonce': nonce 621 }; 622 var services = []; 623 624 $.each($("input.bookable-service-checkbox:checked"), function(){ 625 var quantity = $(this).parent().find('input.bookable-service-quantity').val(); 626 services.push({"service" : $(this).val(), "value" : quantity}); 627 }); 628 ajax_data.services = services; 629 $.ajax({ 630 type: 'POST', dataType: 'json', 631 url: listeo.ajaxurl, 632 data: ajax_data, 633 634 success: function(data){ 635 636 $('#negative-feedback').fadeOut(); 637 $('a.book-now').removeClass('inactive'); 638 if(data.data.price) { 639 if(listeo_core.currency_position=='before'){ 640 $('.booking-estimated-cost span').html(listeo_core.currency_symbol+' '+data.data.price); 641 642 } else { 643 $('.booking-estimated-cost span').html(data.data.price+' '+listeo_core.currency_symbol); 644 } 645 $('.booking-estimated-cost').data('price',data.data.price) 646 $('.booking-estimated-cost').fadeIn(); 647 } 648 if(data.data.price_discount) { 649 if(listeo_core.currency_position=='before'){ 650 $('.booking-estimated-discount-cost span').html(listeo_core.currency_symbol+' '+data.data.price_discount); 651 } else { 652 $('.booking-estimated-discount-cost span').html(data.data.price_discount+' '+listeo_core.currency_symbol); 653 } 654 $('.booking-estimated-cost').addClass('estimated-with-discount'); 655 $('.booking-estimated-discount-cost').fadeIn(); 656 657 } else { 658 $('.booking-estimated-cost').removeClass('estimated-with-discount'); 659 $('.booking-estimated-discount-cost').fadeOut(); 660 } 661 } 662 }); 663 } 664 665 function calculate_booking_form_price() { 666 var ajax_data = { 667 'action' : 'listeo_calculate_booking_form_price', 668 'coupon' : $('input#coupon_code').val(), 669 'price' : $('li.total-costs').data('price'), 670 } 671 672 $.ajax({ 673 type: 'POST', dataType: 'json', 674 url: listeo.ajaxurl, 675 data: ajax_data, 676 677 success: function(data){ 678 679 if(data.price >= 0) { 680 681 if(listeo_core.currency_position=='before'){ 682 $('.total-discounted_costs span').html(listeo_core.currency_symbol+' '+data.price); 683 } else { 684 $('.total-discounted_costs span').html(data.price+' '+listeo_core.currency_symbol); 685 } 686 687 $('.total-discounted_costs').fadeIn(); 688 $('.total-costs').addClass('estimated-with-discount'); 689 690 } else { 691 $('.total-discounted_costs ').fadeOut(); 692 $('.total-costs').removeClass('estimated-with-discount'); 693 } 694 } 695 }); 696 697 }; 698 699 // function when checking booking by widget 700 function check_booking() 701 { 702 inputClicked = true; 703 if ( is_open === false ) return 0; 704 705 // if we not deal with services with slots or opening hours 706 if ( $('#date-picker').data('listing_type') == 'service' && 707 ! $('input#slot').val() && ! $('.time-picker').val() ) 708 { 709 $('#negative-feedback').fadeIn(); 710 711 return; 712 } 713 714 Cookies.set('listeo_rental_startdate', $('#date-picker').data('daterangepicker').startDate.format(wordpress_date_format.date)); 715 Cookies.set('listeo_rental_enddate', $('#date-picker').data('daterangepicker').endDate.format(wordpress_date_format.date)); 716 717 var startDataSql = moment( $('#date-picker').data('daterangepicker').startDate, ["MM/DD/YYYY"]).format("YYYY-MM-DD"); 718 var endDataSql = moment( $('#date-picker').data('daterangepicker').endDate, ["MM/DD/YYYY"]).format("YYYY-MM-DD"); 719 720 console.log($('#date-picker').data('daterangepicker').startDate); 721 722 // preparing data for ajax 723 var ajax_data = { 724 'action': 'check_avaliabity', 725 'listing_type' : $('#date-picker').data('listing_type'), 726 'listing_id' : $('input#listing_id').val(), 727 'coupon' : $('input#coupon_code').val(), 728 'date_start' : startDataSql, 729 'date_end' : endDataSql, 730 //'nonce': nonce 731 }; 732 var services = []; 733 // $.each($("input.bookable-service-checkbox:checked"), function(){ 734 // services.push($(this).val()); 735 // }); 736 // $.each($("input.bookable-service-quantity"), function(){ 737 // services.push($(this).val()); 738 // }); 739 $.each($("input.bookable-service-checkbox:checked"), function(){ 740 var quantity = $(this).parent().find('input.bookable-service-quantity').val(); 741 services.push({"service" : $(this).val(), "value" : quantity}); 742 }); 743 744 ajax_data.services = services; 745 746 if ( $('input#slot').val() ) ajax_data.slot = $('input#slot').val(); 747 if ( $('input.adults').val() ) ajax_data.adults = $('input.adults').val(); 748 if ( $('.time-picker').val() ) ajax_data.hour = $('.time-picker').val(); 749 if ( $(".time-picker-end-hour").val()) ajax_data.end_hour = $(".time-picker-end-hour").val(); 750 751 752 // loader class 753 $('a.book-now').addClass('loading'); 754 $('a.book-now-notloggedin').addClass('loading'); 755 756 $.ajax({ 757 type: 'POST', dataType: 'json',
758 url: listeo.ajaxurl, 759 data: ajax_data, 760 761 success: function(data){ 762 763 // loader clas 764 if (data.success == true && ( ! $(".time-picker").length || is_open != false ) ) { 765 if ( data.data.free_places > 0) { 766 $('a.book-now,a.book-now-notloggedin').data('freeplaces',data.data.free_places); 767 $('.booking-error-message').fadeOut(); 768 $('a.book-now').removeClass('inactive'); 769 if(data.data.price) { 770 if(listeo_core.currency_position=='before'){ 771 $('.booking-estimated-cost span').html(listeo_core.currency_symbol+' '+data.data.price); 772 } else { 773 $('.booking-estimated-cost span').html(data.data.price+' '+listeo_core.currency_symbol); 774 } 775 $('.booking-estimated-cost').data('price',data.data.price) 776 $('.booking-estimated-cost').fadeIn(); 777 } else { 778 $('.booking-estimated-cost span').html( '0 '+listeo_core.currency_symbol); 779 $('.booking-estimated-cost').fadeOut(); 780 } 781 if(data.data.price_discount) { 782 if(listeo_core.currency_position=='before'){ 783 $('.booking-estimated-discount-cost span').html(listeo_core.currency_symbol+' '+data.data.price_discount); 784 } else { 785 $('.booking-estimated-discount-cost span').html(data.data.price_discount+' '+listeo_core.currency_symbol); 786 } 787 $('.booking-estimated-cost').addClass('estimated-with-discount'); 788 $('.booking-estimated-discount-cost').fadeIn(); 789 790 } else { 791 $('.booking-estimated-cost').removeClass('estimated-with-discount'); 792 $('.booking-estimated-discount-cost').fadeOut(); 793 } 794 validate_coupon($('input#listing_id').val(),data.data.price); 795 $('.coupon-widget-wrapper').fadeIn(); 796 } else { 797 $('a.book-now,a.book-now-notloggedin').data('freeplaces',0); 798 $('.booking-error-message').fadeIn(); 799 800 $('.booking-estimated-cost').fadeOut(); 801 802 $('.booking-estimated-cost span').html(''); 803 804 } 805 } else { 806 $('a.book-now,a.book-now-notloggedin').data('freeplaces',0); 807 $('.booking-error-message').fadeIn(); 808 809 $('.booking-estimated-cost').fadeOut(); 810 } 811 $('a.book-now').removeClass('loading'); 812 $('a.book-now-notloggedin').removeClass('loading'); 813 } 814 }); 815 816 } 817 818 var is_open = true; 819 var lastDayOfWeek; 820 821 822 823 824 // update slots and check hours setted to this day 825 function update_booking_widget () 826 { 827 828 // function only for services 829 if ( $('#date-picker').data('listing_type') != 'service') return; 830 $('a.book-now').addClass('loading'); 831 $('a.book-now-notloggedin').addClass('loading'); 832 // get day of week 833 var date = $('#date-picker').data('daterangepicker').endDate._d; 834 var dayOfWeek = date.getDay() - 1; 835 console.log(date.getDay() - 1); 836 837 if(date.getDay() == 0){ 838 dayOfWeek = 6; 839 } 840 841 842 var startDataSql = moment( $('#date-picker').data('daterangepicker').startDate, ["MM/DD/YYYY"]).format("YYYY-MM-DD"); 843 var endDataSql = moment( $('#date-picker').data('daterangepicker').endDate, ["MM/DD/YYYY"]).format("YYYY-MM-DD"); 844 845 var ajax_data = { 846 'action' : 'update_slots', 847 'listing_id' : $('input#listing_id').val(), 848 'date_start' : startDataSql, 849 'date_end' : endDataSql, 850 'slot' : dayOfWeek 851 //'nonce': nonce 852 }; 853 854 $.ajax({ 855 type: 'POST', dataType: 'json', 856 url: listeo.ajaxurl, 857 data: ajax_data, 858 859 860 success: function(data){ 861 862 $('.time-slots-dropdown .panel-dropdown-scrollable').html(data.data); 863 864 // reset values of slot selector 865 if ( dayOfWeek != lastDayOfWeek) 866 { 867 868 $( '.panel-dropdown-scrollable .time-slot input' ).prop("checked", false); 869 870 $('.panel-dropdown.time-slots-dropdown input#slot').val(''); 871 $('.panel-dropdown.time-slots-dropdown a').html( $('.panel-dropdown.time-slots-dropdown a').attr('placeholder') ); 872 $(' .booking-estimated-cost span').html(' '); 873 874 } 875 876 lastDayOfWeek = dayOfWeek; 877 878 if ( ! $( '.panel-dropdown-scrollable .time-slot[day=\'' + dayOfWeek + '\']' ).length ) 879 { 880 881 $( '.no-slots-information' ).show(); 882 $('.panel-dropdown.time-slots-dropdown a').html( $( '.no-slots-information' ).html() ); 883 884 } 885 else 886 { 887 888 // when we dont have slots for this day reset cost and show no slots 889 $( '.no-slots-information' ).hide(); 890 $(' .booking-estimated-cost span').html(' '); 891 892 893 } 894 // show only slots for this day 895 $( '.panel-dropdown-scrollable .time-slot' ).hide( ); 896 897 $( '.panel-dropdown-scrollable .time-slot[day=\'' + dayOfWeek + '\']' ).show( ); 898 $(".time-slot").each(function() { 899 var timeSlot = $(this); 900 $(this).find('input').on('change',function() { 901 902 var timeSlotVal = timeSlot.find("strong").text(); 903 var slotArray = [timeSlot.find("strong").text(), timeSlot.find("input").val()]; 904 905 906 $('.panel-dropdown.time-slots-dropdown input#slot').val( JSON.stringify( slotArray ) ); 907 908 $('.panel-dropdown.time-slots-dropdown a').html(timeSlotVal); 909 910 $(".panel-dropdown").removeClass("active"); 911 912 913 914 check_booking(); 915 }); 916 }); 917 $('a.book-now').removeClass('loading'); 918 $('a.book-now-notloggedin').removeClass('loading'); 919 } 920 }); 921 922 923 // check if opening days are active 924 if ( $(".time-picker").length ) { 925 if(availableDays){ 926 927 928 if ( availableDays[dayOfWeek].opening == 'Closed' || availableDays[dayOfWeek].closing == 'Closed') 929 { 930 931 $('#negative-feedback').fadeIn(); 932 933 //$('a.book-now').css('background-color','grey'); 934 935 is_open = false;
936 //console.log('zamkniete tego dnia' + dayOfWeek); 937 return; 938 } 939 940 // converent hours to 24h format 941 var opening_hour = moment( availableDays[dayOfWeek].opening, ["h:mm A"]).format("HH:mm"); 942 var closing_hour = moment( availableDays[dayOfWeek].closing, ["h:mm A"]).format("HH:mm"); 943 944 945 // get hour in 24 format 946 var current_hour = $('.time-picker').val(); 947 948 949 // check if currer hour bar is open 950 if ( current_hour >= opening_hour && current_hour <= closing_hour) 951 { 952 953 is_open = true; 954 $('#negative-feedback').fadeOut(); 955 $('a.book-now').attr('href','#').css('background-color','#f30c0c'); 956 check_booking() 957 console.log('otwarte' + dayOfWeek); 958 959 960 } else { 961 962 is_open = false; 963 $('#negative-feedback').fadeIn(); 964 //$('a.book-now').attr('href','#').css('background-color','grey'); 965 $('.booking-estimated-cost span').html(''); 966 console.log('zamkniete'); 967 968 } 969 } 970 } 971 } 972 973 // if slots exist update them 974 if ( $( '.time-slot' ).length ) { update_booking_widget(); } 975 976 // show only services for actual day from datapicker 977 $( '#date-picker' ).on( 'apply.daterangepicker', update_booking_widget ); 978 $( '#date-picker' ).on( 'change', function(){ 979 check_booking(); 980 update_booking_widget(); 981 }); 982 983 984 // when slot is selected check if there are avalible bookings 985 $( '#date-picker' ).on( 'apply.daterangepicker', check_booking ); 986 $( '#date-picker' ).on( 'cancel.daterangepicker', check_booking ); 987 988 $(document).on("change", 'input#slot,input.adults, input.bookable-service-quantity, .form-booking-service input.bookable-service-checkbox,.form-booking-rental input.bookable-service-checkbox', function(event) { 989 check_booking(); 990 }); 991 //$('input#slot').on( 'change', check_booking ); 992 993 $('input#tickets,.form-booking-event input.bookable-service-checkbox').on('change',function(e){ 994 //check_booking(); 995 calculate_price(); 996 }); 997 998 999 // hours picker 1000 if ( $(".time-picker").length ) { 1001 var time24 = false; 1002 1003 if(listeo_core.clockformat){ 1004 time24 = true; 1005 } 1006 const calendars = $(".time-picker").flatpickr({ 1007 enableTime: true, 1008 noCalendar: true, 1009 dateFormat: "H:i", 1010 time_24hr: time24, 1011 disableMobile: "true", 1012 1013 1014 // check if there are free days on change and calculate price 1015 onClose: function(selectedDates, dateStr, instance) { 1016 update_booking_widget(); 1017 check_booking(); 1018 }, 1019 1020 }); 1021 1022 if($('#_hour_end').length) { 1023 calendars[0].config.onClose = [() => { 1024 setTimeout(() => calendars[1].open(), 1); 1025 }]; 1026 1027 calendars[0].config.onChange = [(selDates) => { 1028 calendars[1].set("minDate", selDates[0]); 1029 }]; 1030 1031 calendars[1].config.onChange = [(selDates) => { 1032 calendars[0].set("maxDate", selDates[0]); 1033 }] 1034 } 1035 }; 1036 1037 1038 1039/*----------------------------------------------------*/ 1040/* Bookings Dashboard Script 1041/*----------------------------------------------------*/ 1042$(".booking-services").on("click", '.qtyInc', function() { 1043 var $button = $(this); 1044 1045 var oldValue = $button.parent().find("input").val(); 1046 console.log(oldValue); 1047 if(oldValue == 2) { 1048 //$button.parents('.single-service').find('label').trigger('click'); 1049 $button.parents('.single-service').find('input.bookable-service-checkbox').prop("checked",true); 1050 updateCounter(); 1051 } 1052 if($("#form-booking").hasClass('form-booking-event')){ 1053 calculate_price(); 1054 } else { 1055 check_booking(); 1056 } 1057 //calculate_price(); 1058}); 1059 1060 1061if ( $( "#booking-date-range" ).length ) { 1062 1063 // to update view with bookin 1064 1065 var bookingsOffset = 0; 1066 1067 // here we can set how many bookings per page 1068 var bookingsLimit = 5; 1069 1070 // function when checking booking by widget 1071 function listeo_bookings_manage(page) 1072 { 1073 1074 if($('#booking-date-range').data('daterangepicker')){ 1075 var startDataSql = moment( $('#booking-date-range').data('daterangepicker').startDate, ["MM/DD/YYYY"]).format("YYYY-MM-DD"); 1076 var endDataSql = moment( $('#booking-date-range').data('daterangepicker').endDate, ["MM/DD/YYYY"]).format("YYYY-MM-DD"); 1077 1078 } else { 1079 var startDataSql = ''; 1080 var endDataSql = ''; 1081 } 1082 if(!page) { page = 1 } 1083 if (page == "prev") { 1084 var current = $("div.pagination-container li.current").data("paged"); 1085 page = current-1; 1086 } 1087 if (page == "next") { 1088 var current = $("div.pagination-container li.current").data("paged"); 1089 page = current+1; 1090 } 1091 1092 1093 // preparing data for ajax 1094 var ajax_data = { 1095 'action': 'listeo_bookings_manage', 1096 'date_start' : startDataSql, 1097 'date_end' : endDataSql, 1098 'listing_id' : $('#listing_id').val(), 1099 'listing_status' : $('#listing_status').val(), 1100 'booking_author' : $('#booking_author').val(), 1101 'dashboard_type' : $('#dashboard_type').val(), 1102 'limit' : bookingsLimit, 1103 'offset' : bookingsOffset, 1104 'page' : page, 1105 //'nonce': nonce 1106 }; 1107 1108 1109 // display loader class 1110 $(".dashboard-list-box").addClass('loading'); 1111 1112 $.ajax({ 1113 type: 'POST', dataType: 'json',
1114 url: listeo.ajaxurl, 1115 data: ajax_data, 1116 1117 success: function(data){ 1118 1119 1120 // display loader class 1121 $(".dashboard-list-box").removeClass('loading'); 1122 1123 if(data.data.html){ 1124 $('#no-bookings-information').hide(); 1125 $( "ul#booking-requests" ).html(data.data.html); 1126 $( ".pagination-container" ).html(data.data.pagination); 1127 } else { 1128 $( "ul#booking-requests" ).empty(); 1129 $( ".pagination-container" ).empty(); 1130 $('#no-bookings-information').show(); 1131 } 1132 1133 } 1134 }); 1135 1136 } 1137 1138 $( '#dashboard-booking-author-search' ).autocomplete({ 1139 1140 source: function(req, response){ 1141 $.getJSON( 1142 listeo_core.ajax_url + 1143 "?callback=?&action=listeo_core_incremental_listing_suggest", 1144 req, 1145 response 1146 ); 1147 }, 1148 select: function(event, ui) { 1149 window.location.href=ui.item.link; 1150 }, 1151 minLength: 3, 1152 }); 1153 1154 // hooks for get bookings into view 1155 $( '#booking-date-range' ).on( 'apply.daterangepicker', function(e){ 1156 listeo_bookings_manage(); 1157 }); 1158 $( '#listing_id' ).on( 'change', function(e){ 1159 listeo_bookings_manage(); 1160 }); 1161 $( '#listing_status' ).on( 'change', function(e){ 1162 listeo_bookings_manage(); 1163 }); 1164 $("#booking_author").on("change", function (e) { 1165 listeo_bookings_manage(); 1166 }); 1167 1168 $( 'div.pagination-container').on( 'click', 'a', function(e) { 1169 e.preventDefault(); 1170 1171 var page = $(this).parent().data('paged'); 1172 1173 listeo_bookings_manage(page); 1174 1175 $( 'body, html' ).animate({ 1176 scrollTop: $(".dashboard-list-box").offset().top 1177 }, 600 ); 1178 1179 return false; 1180 } ); 1181 1182 1183 $(document).on('click','.reject, .cancel',function(e) { 1184 e.preventDefault(); 1185 if (window.confirm(listeo_core.areyousure)) { 1186 var $this = $(this); 1187 $this.parents('li').addClass('loading'); 1188 var status = 'confirmed'; 1189 if ( $(this).hasClass('reject' ) ) status = 'cancelled'; 1190 if ( $(this).hasClass('cancel' ) ) status = 'cancelled'; 1191 1192 // preparing data for ajax 1193 var ajax_data = { 1194 'action': 'listeo_bookings_manage', 1195 'booking_id' : $(this).data('booking_id'), 1196 'status' : status, 1197 //'nonce': nonce 1198 }; 1199 $.ajax({ 1200 type: 'POST', dataType: 'json', 1201 url: listeo.ajaxurl, 1202 data: ajax_data, 1203 1204 success: function(data){ 1205 1206 // display loader class 1207 $this.parents('li').removeClass('loading'); 1208 1209 listeo_bookings_manage(); 1210 1211 } 1212 }); 1213 } 1214 }); 1215 1216 $(document).on('click','.delete',function(e) { 1217 e.preventDefault(); 1218 if (window.confirm(listeo_core.areyousure)) { 1219 var $this = $(this); 1220 $this.parents('li').addClass('loading'); 1221 var status = 'deleted'; 1222 1223 // preparing data for ajax 1224 var ajax_data = { 1225 'action': 'listeo_bookings_manage', 1226 'booking_id' : $(this).data('booking_id'), 1227 'status' : status, 1228 //'nonce': nonce 1229 }; 1230 $.ajax({ 1231 type: 'POST', dataType: 'json', 1232 url: listeo.ajaxurl, 1233 data: ajax_data, 1234 1235 success: function(data){ 1236 1237 // display loader class 1238 $this.parents('li').removeClass('loading'); 1239 1240 listeo_bookings_manage(); 1241 1242 } 1243 }); 1244 } 1245 }); 1246 1247 $(document).on('click','.renew_booking',function(e) { 1248 e.preventDefault(); 1249 if (window.confirm(listeo_core.areyousure)) { 1250 var $this = $(this); 1251 $this.parents('li').addClass('loading'); 1252 1253 1254 // preparing data for ajax 1255 var ajax_data = { 1256 'action': 'listeo_bookings_renew_booking', 1257 'booking_id' : $(this).data('booking_id'), 1258 //'nonce': nonce 1259 }; 1260 $.ajax({ 1261 type: 'POST', dataType: 'json', 1262 url: listeo.ajaxurl, 1263 data: ajax_data, 1264 1265 success: function(data){ 1266 if(data.success) { 1267 1268 } else { 1269 alert(listeo_core.booked_dates); 1270 } 1271 // display loader class 1272 $this.parents('li').removeClass('loading'); 1273 1274 listeo_bookings_manage(); 1275 1276 } 1277 }); 1278 } 1279 }); 1280 1281 1282 $(document).on('click','.approve',function(e) { 1283 e.preventDefault(); 1284 var $this = $(this); 1285 $this.parents('li').addClass('loading'); 1286 var status = 'confirmed'; 1287 if ( $(this).hasClass('reject' ) ) status = 'cancelled'; 1288 if ( $(this).hasClass('cancel' ) ) status = 'cancelled'; 1289 1290 // preparing data for ajax 1291 var ajax_data = { 1292 'action': 'listeo_bookings_manage', 1293 'booking_id' : $(this).data('booking_id'), 1294 'status' : status, 1295 //'nonce': nonce 1296 }; 1297 $.ajax({ 1298 type: 'POST', dataType: 'json',
1299 url: listeo.ajaxurl, 1300 data: ajax_data, 1301 1302 success: function(data){ 1303 1304 // display loader class 1305 $this.parents('li').removeClass('loading'); 1306 1307 listeo_bookings_manage(); 1308 1309 } 1310 }); 1311 1312 }); 1313 $(document).on('click','.mark-as-paid',function(e) { 1314 e.preventDefault(); 1315 var $this = $(this); 1316 $this.parents('li').addClass('loading'); 1317 var status = 'paid'; 1318 1319 // preparing data for ajax 1320 var ajax_data = { 1321 'action': 'listeo_bookings_manage', 1322 'booking_id' : $(this).data('booking_id'), 1323 'status' : status, 1324 //'nonce': nonce 1325 }; 1326 $.ajax({ 1327 type: 'POST', dataType: 'json', 1328 url: listeo.ajaxurl, 1329 data: ajax_data, 1330 1331 success: function(data){ 1332 1333 // display loader class 1334 $this.parents('li').removeClass('loading'); 1335 1336 listeo_bookings_manage(); 1337 1338 } 1339 }); 1340 1341 }); 1342 1343 1344 var start = moment().subtract(30, 'days'); 1345 var end = moment(); 1346 1347 function cb(start, end) { 1348 $("#booking-date-range span,#chart-date-range span").html( 1349 start.format("MMMM D, YYYY") + " - " + end.format("MMMM D, YYYY") 1350 ); 1351 } 1352 1353 var ranges = new Object(); 1354 ranges[listeo_core.today] = [moment().subtract(1, "days"), moment()]; 1355 ranges[listeo_core.yesterday] = [moment().subtract(1, 'days'), moment().subtract(1, 'days')]; 1356 ranges[listeo_core.last_7_days] = [moment().subtract(6, 'days'), moment()]; 1357 ranges[listeo_core.last_30_days] = [moment().subtract(29, 'days'), moment()]; 1358 ranges[listeo_core.this_month] = [moment().startOf('month'), moment().endOf('month')]; 1359 ranges[listeo_core.last_month] = [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]; 1360 1361 var today = listeo_core.today; 1362 1363 $('#booking-date-range-enabler').on('click',function(e){ 1364 1365 e.preventDefault(); 1366 $(this).hide(); 1367 cb(start, end); 1368 $('#booking-date-range,#chart-date-range').show().daterangepicker({ 1369 "opens": "left", 1370 "autoUpdateInput": false, 1371 "alwaysShowCalendars": true, 1372 startDate: start, 1373 endDate: end, 1374 ranges: ranges, 1375 locale: { 1376 format: wordpress_date_format.date, 1377 "firstDay": parseInt(wordpress_date_format.day), 1378 "applyLabel" : listeo_core.applyLabel, 1379 "cancelLabel" : listeo_core.cancelLabel, 1380 "fromLabel" : listeo_core.fromLabel, 1381 "toLabel" : listeo_core.toLabel, 1382 "customRangeLabel": listeo_core.customRangeLabel, 1383 "daysOfWeek": [ 1384 listeo_core.day_short_su, 1385 listeo_core.day_short_mo, 1386 listeo_core.day_short_tu, 1387 listeo_core.day_short_we, 1388 listeo_core.day_short_th, 1389 listeo_core.day_short_fr, 1390 listeo_core.day_short_sa 1391 ], 1392 "monthNames": [ 1393 listeo_core.january, 1394 listeo_core.february, 1395 listeo_core.march, 1396 listeo_core.april, 1397 listeo_core.may, 1398 listeo_core.june, 1399 listeo_core.july, 1400 listeo_core.august, 1401 listeo_core.september, 1402 listeo_core.october, 1403 listeo_core.november, 1404 listeo_core.december, 1405 ], 1406 } 1407 }, cb).trigger('click'); 1408 cb(start, end); 1409 }) 1410 1411 1412 1413 1414 1415 // Calendar animation and visual settings 1416 $('#booking-date-range').on('show.daterangepicker', function(ev, picker) { 1417 1418 $('.daterangepicker').addClass('calendar-visible calendar-animated bordered-style'); 1419 $('.daterangepicker').removeClass('calendar-hidden'); 1420 }); 1421 $('#booking-date-range').on('hide.daterangepicker', function(ev, picker) { 1422 1423 $('.daterangepicker').removeClass('calendar-visible'); 1424 $('.daterangepicker').addClass('calendar-hidden'); 1425 }); 1426 1427} // end if dashboard booking 1428 1429 1430 1431 // $('a.reject').on('click', function() { 1432 1433 // console.log(picker); 1434 1435 // }); 1436 }); 1437 1438})(this.jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.