1 /* ----------------- Start Document ----------------- */ 2(function($){ 3"use strict"; 4 5$(document).ready(function(){ 6 $(".listeo_core-dashboard-action-delete").click(function (e) { 7 e.preventDefault(); 8 if (window.confirm(listeo_core.areyousure)) { 9 location.href = this.href; 10 } 11 }); 12 13 // $('.booking-widget').after("<div class='booking-widget-hook'></div>"); 14 15 // $(window).on('load resize', function() { 16 // var winWidth = $(window).width(); 17 // if (winWidth < 992) { 18 // $('.booking-widget').insertAfter("#titlebar"); 19 // } else if (winWidth > 992) { 20 // $('.booking-widget').insertAfter(".booking-widget-hook"); 21 // } 22 // }); 23 24 $("body").on("click", ".listeo_core-bookmark-it", function (e) { 25 e.preventDefault(); 26 if ($(this).is(".clicked,.liked")) { 27 return; 28 } 29 $(this).addClass("clicked"); 30 31 var post_id = $(this).data("post_id"), 32 handler = $(this), 33 nonce = $(this).data("nonce"), 34 addedtolist = $(this).data("saved-title"); 35 36 $.ajax({ 37 type: "POST", 38 dataType: "json", 39 url: listeo.ajaxurl, 40 data: { 41 action: "listeo_core_bookmark_this", 42 post_id: post_id, 43 nonce: nonce, 44 }, 45 success: function (response) { 46 console.log(response); 47 if (response.type == "success") { 48 handler 49 .removeClass("listeo_core-bookmark-it") 50 .addClass("liked") 51 .addClass("listeo_core-unbookmark-it") 52 .removeClass("clicked"); 53 var confirmed = handler.data("confirm"); 54 handler 55 .children(".like-icon") 56 .addClass("liked") 57 .removeClass("clicked") 58 .parent() 59 .html('<span class="like-icon liked"></span> ' + confirmed); 60 } else { 61 handler.removeClass("clicked"); 62 handler.children(".like-icon").removeClass("liked"); 63 } 64 }, 65 }); 66 }); 67 68 $(".listeo_core-unbookmark-it").on("click", function (e) { 69 e.preventDefault(); 70 var handler = $(this); 71 var post_id = $(this).data("post_id"); 72 var nonce = $(this).data("nonce"); 73 handler.closest("li").addClass("opacity-05"); 74 $.ajax({ 75 type: "POST", 76 dataType: "json", 77 url: listeo.ajaxurl, 78 data: { 79 action: "listeo_core_unbookmark_this", 80 post_id: post_id, 81 nonce: nonce, 82 }, 83 success: function (response) { 84 console.log(handler); 85 console.log(response); 86 if (response.type == "success") { 87 handler.closest("li").fadeOut(); 88 handler.removeClass("clicked"); 89 handler.removeClass("liked"); 90 handler.children(".like-icon").removeClass("liked"); 91 } else { 92 handler.closest("li").removeClass("opacity-05"); 93 } 94 }, 95 }); 96 }); 97 98 // Choose listing type step 99 $(".add-listing-section.type-selection a").on("click", function (e) { 100 e.preventDefault(); 101 var type = $(this).data("type"); 102 $("#listing_type").val(type); 103 $("#submit-listing-form").submit(); 104 }); 105 106 $(".add-listing-section.type-selection a").on("click", function (e) { 107 e.preventDefault(); 108 var type = $(this).data("type"); 109 $("#listing_type").val(type); 110 $("#submit-listing-form").submit(); 111 }); 112 113 var elements = document.querySelectorAll("input,select,textarea"); 114 115 for (var i = elements.length; i--; ) { 116 elements[i].addEventListener("invalid", function () { 117 this.scrollIntoView(false); 118 }); 119 } 120 121 // $(".add-listing-section.availability_calendar").on( 122 // "click", 123 // "span.calendar-day-date", 124 // function (e) { 125 // e.preventDefault(); 126 // var td = $(this).parent(); 127 // var timestamp = td.data("timestamp"); 128 // var date = td.data("date"); 129 // var $el = $(".listeo-calendar-avail"); 130 131 // if (td.hasClass("not_active")) { 132 // td.removeClass("not_active"); 133 // var current_dates = $el.val(); 134 // console.log(current_dates); 135 // console.log(date + "|"); 136 // current_dates = current_dates.replace(date + "|", ""); 137 // console.log(current_dates); 138 // $el.val(current_dates); 139 // } else { 140 // td.addClass("not_active"); 141 // $el.val($el.val() + date + "|"); 142 // } 143 // } 144 // ); 145 146 // $(".add-listing-section.availability_calendar").on( 147 // "click", 148 // "button", 149 // function (e) { 150 // e.preventDefault(); 151 // var td = $(this).parent().parent(); 152 // var timestamp = td.data("timestamp"); 153 // var date = td.data("date"); 154 // var $el = $(".listeo-calendar-avail"); 155 // var current_price = $(this).prev("span").text(); 156 157 // var price = (function ask() { 158 // var n = prompt(listeo_core.prompt_price); 159 // console.log(typeof n); 160 // if (n === null) { 161 // return n; 162 // } else if (n === "") { 163 // return current_price; 164 // } else { 165 // return isNaN(n) ? ask() : n; 166 // } 167 // })(); 168 // var json = {}; 169 // var reg_price; 170 // if (td.hasClass("weekend")) { 171 // reg_price = $("#_weekday_price").val(); 172 // } else { 173 // reg_price = $("#_normal_price").val(); 174 // } 175 // if (price != null && price != reg_price) { 176 // $(this).parent().find("span").html(price); 177 // // json.push({ 178 // // date : price 179 // // }); 180 // var current_value = $(".listeo-calendar-price").val(); 181 // if (current_value) { 182 // var json = jQuery.parseJSON($(".listeo-calendar-price").val()); 183 // } 184 // json[date] = price; 185 // var stringit = JSON.stringify(json); 186 // $(".listeo-calendar-price").val(stringit); 187 // } 188 // if (price == reg_price) { 189 // $(this).parent().find("span").html(price); 190 // var current_value = $(".listeo-calendar-price").val(); 191 // if (current_value) { 192 // var json = jQuery.parseJSON($(".listeo-calendar-price").val()); 193 // } 194 // delete json[date]; 195 // var stringit = JSON.stringify(json); 196 // $(".listeo-calendar-price").val(stringit); 197 // } 198 // } 199 // ); 200 201 $("#_normal_price").on("input", function (e) { 202 e.preventDefault(); 203 var price = $(this).val(); 204 $(".listeo-calendar-day:not(.weekend) .calendar-price span").html(price); 205 submit_calendar_update_price(); 206 }); 207 208 $("#_weekend_price,#_weekday_price").on("input", function (e) { 209 e.preventDefault(); 210 var price = $(this).val(); 211 $(".listeo-calendar-day.weekend .calendar-price span").html(price); 212 submit_calendar_update_price(); 213 }); 214 215 $(".add-listing-section.availability_calendar").on( 216 "click", 217 ".prev", 218 function (event) {
219 var month = $(this).data("prev-month"); 220 var year = $(this).data("prev-year"); 221 getCalendar(month, year); 222 } 223 ); 224 $(".add-listing-section.availability_calendar").on( 225 "click", 226 ".next", 227 function (event) { 228 var month = $(this).data("next-month"); 229 var year = $(this).data("next-year"); 230 getCalendar(month, year); 231 } 232 ); 233 $(".add-listing-section.availability_calendar").on( 234 "blur", 235 "#currentYear", 236 function (event) { 237 var month = $("#currentMonth").text(); 238 var year = $("#currentYear").text(); 239 getCalendar(month, year); 240 } 241 ); 242 243 function getCalendar(month, year) { 244 $.ajax({ 245 type: "post", 246 dataType: "json", 247 url: listeo_core.ajax_url, 248 data: { action: "listeo_core_calendar", month: month, year: year }, 249 success: function (data) { 250 $("#listeo-calendar-outer").html(data.response); 251 var _normal_price = $("#_normal_price").val(); 252 $(".listeo-calendar-day:not(.weekend) .calendar-price span").html( 253 _normal_price 254 ); 255 var _weekend_price = $("#_weekday_price").val(); 256 $(".listeo-calendar-day.weekend .calendar-price span").html( 257 _weekend_price 258 ); 259 submit_calendar_update_price(); 260 submit_calendar_update_unav_days(); 261 }, 262 }); 263 } 264 265 function submit_calendar_update_unav_days() { 266 var days = $(".listeo-calendar-avail").val(); 267 if (days) { 268 var array = days.split("|"); 269 270 $.each(array, function (key, day) { 271 if (day) { 272 $("td.listeo-calendar-day[data-date='" + day + "']").addClass( 273 "not_active" 274 ); 275 } 276 }); 277 } 278 } 279 280 function submit_calendar_update_price() { 281 var prices = $(".listeo-calendar-price").val(); 282 if (prices) { 283 var obj = JSON.parse(prices); 284 285 $.each(obj, function (day, price) { 286 if (day) { 287 $( 288 "td.listeo-calendar-day[data-date='" + 289 day + 290 "'] .calendar-price span" 291 ).text(price); 292 } 293 }); 294 } 295 } 296 var _normal_price = $("#_normal_price").val(); 297 $(".listeo-calendar-day:not(.weekend) .calendar-price span").html( 298 _normal_price 299 ); 300 var _weekend_price = $("#_weekday_price").val(); 301 $(".listeo-calendar-day.weekend .calendar-price span").html(_weekend_price); 302 submit_calendar_update_price(); 303 submit_calendar_update_unav_days(); 304 305 // // Store the start and end dates 306 // var startDate = null; 307 // var endDate = null; 308 309 // // Attach a click event listener to all table cells 310 // $("table td") 311 // .click(function () { 312 // var cellIndex = $(this).index(); 313 // var rowIndex = $(this).parent().index(); 314 315 // // If start date is not set, set it 316 // if (startDate === null) { 317 // startDate = { 318 // row: rowIndex, 319 // cell: cellIndex, 320 // }; 321 // $(this).addClass("selected"); 322 // } 323 // // If end date is not set, set it 324 // else if (endDate === null) { 325 // endDate = { 326 // row: rowIndex, 327 // cell: cellIndex, 328 // }; 329 // $(this).addClass("selected"); 330 331 // // Swap start and end date if necessary 332 // if ( 333 // startDate.row > endDate.row || 334 // (startDate.row === endDate.row && startDate.cell >
334 endDate.cell) 335 // ) { 336 // var tempDate = startDate; 337 // startDate = endDate; 338 // endDate = tempDate; 339 // } 340 341 // // Prompt user for value 342 // var value = prompt("Enter a value:"); 343 344 // // Set value for selected range of dates 345 // $("table tr").each(function (row) { 346 // $(this) 347 // .find("td") 348 // .each(function (cell) { 349 // if ( 350 // (row > startDate.row || 351 // (row === startDate.row && cell >= startDate.cell)) && 352 // (row < endDate.row || 353 // (row === endDate.row && cell <= endDate.cell)) 354 // ) { 355 // $(this).find("input").val(value); 356 // } 357 // }); 358 // }); 359 // } 360 // // If both start and end date are already set, reset the selection 361 // else { 362 // startDate = { 363 // row: rowIndex, 364 // cell: cellIndex, 365 // }; 366 // endDate = null; 367 // $("table td").removeClass("selected"); 368 // $(this).addClass("selected"); 369 // } 370 // }) 371 // .hover( 372 // function () { 373 // // If start date is already set, add class to all tds between start date and current hover 374 // if (startDate !== null && endDate === null) { 375 // var cellIndex = $(this).index(); 376 // var rowIndex = $(this).parent().index(); 377 // $("table tr").each(function (row) { 378 // $(this) 379 // .find("td") 380 // .each(function (cell) { 381 // if ( 382 // (row > startDate.row || 383 // (row === startDate.row && cell >= startDate.cell)) && 384 // (row < rowIndex || (row === rowIndex && cell <= cellIndex)) 385 // ) { 386 // $(this).addClass("selected"); 387 // } 388 // }); 389 // }); 390 // } 391 // }, 392 // function () { 393 // // If start date is already set, remove class from all tds between start date and current hover 394 // if (startDate !== null && endDate === null) { 395 // $("table tr").each(function (row) { 396 // $(this) 397 // .find("td") 398 // .each(function (cell) { 399 // if ( 400 // (row > startDate.row || 401 // (row === startDate.row && cell >= startDate.cell)) && 402 // (row < rowIndex || (row === rowIndex && cell <= cellIndex)) 403 // ) { 404 // $(this).removeClass("selected"); 405 // } 406 // }); 407 // }); 408 // } 409 // } 410 // ); 411 412 // send slots in json 413 var slot_container = 0; 414 var slots = new Array(); 415 416 $("#submit-listing-form").submit(function (e) { 417 //e.preventDefault(); 418 $(".slots-container").each(function () { 419 var inside_slots = new Array(); 420 var slot_number = 0; 421 $(this) 422 .find(".single-slot-time") 423 .each(function (slot_time) { 424 var timeText = $(this).text().replace(/-|-/g, "-"); 425 inside_slots[slot_number] = 426 timeText + "|" + $(this).parent().parent().find("#slot-qty").val(); 427 slot_number++; 428 }); 429 slots[slot_container] = inside_slots; 430 slot_container++; 431 }); 432 $("#_slots").val(JSON.stringify(slots)); 433 //console.log(JSON.stringify(slots)); 434 //$( this ).submit(); 435 }); 436 437 /* var json = jQuery.parseJSON($(".listeo-calendar-price").val()); 438 439 json[date] = price; 440 var stringit = JSON.stringify(json);*/ 441 442 $("#listeo-activities-list a.close-list-item").on("click", function (e) { 443 var $this = $(this), 444 id = $(this).data("id"), 445 nonce = $(this).data("nonce"); 446 447 $.ajax({ 448 type: "POST", 449 dataType: "json", 450 url: listeo.ajaxurl, 451 data: { 452 action: "remove_activity", 453 id: id, 454 nonce: nonce, 455 }, 456 success: function (data) { 457 if (data.success == true) { 458 $this 459 .parent() 460 .addClass("wait") 461 .fadeOut("normal", function () { 462 $this.remove(); 463 }); 464 } else { 465 } 466 }, 467 }); 468 e.preventDefault(); 469 }); 470 471 $("#listeo-clear-activities").on("click", function (e) { 472 var $this = $(this), 473 nonce = $(this).data("nonce"); 474 475 $.ajax({ 476 type: "POST", 477 dataType: "json",
478 url: listeo.ajaxurl, 479 data: { 480 action: "remove_all_activities", 481 nonce: nonce, 482 }, 483 success: function (data) { 484 if (data.success == true) { 485 $("ul#listeo-activities-list li:not(.cleared)").remove(); 486 $("li.cleared").show(); 487 $this.parent().parent().find(".pagination-container").remove(); 488 } else { 489 } 490 }, 491 }); 492 e.preventDefault(); 493 }); 494 495 $("select#sort-reviews-by").on("change", function (e) { 496 var button = $(this); 497 button.parents(".dashboard-list-box").addClass("loading"); 498 var page = button.find("#reviews_list_visitors").data("page"); 499 var post_id = $(this).val(); 500 $.ajax({ 501 type: "POST", 502 dataType: "json", 503 url: listeo.ajaxurl, 504 data: { 505 action: "reload_reviews", 506 id: post_id, 507 page: page, 508 //'nonce': nonce 509 }, 510 success: function (data) { 511 button.parents(".dashboard-list-box").removeClass("loading"); 512 if (data.success == true) { 513 $("#reviews_list_visitors").html(data.comments); 514 $("#visitor-reviews-pagination").html(data.pagination); 515 $(".popup-with-zoom-anim").magnificPopup({ 516 type: "inline", 517 518 fixedContentPos: false, 519 fixedBgPos: true, 520 521 overflowY: "auto", 522 523 closeBtnInside: true, 524 preloader: false, 525 526 midClick: true, 527 removalDelay: 300, 528 mainClass: "my-mfp-zoom-in", 529 }); 530 } else { 531 console.log("error"); 532 } 533 }, 534 }); 535 e.preventDefault(); 536 }); 537 538 $("#visitor-reviews-pagination").on("click", "a", function (e) { 539 var page = $(this).parent().data("paged"); 540 var post_id = $("#sort-reviews-by").val(); 541 $(".reviews-visitior-box").addClass("loading"); 542 $.ajax({ 543 type: "POST", 544 dataType: "json", 545 url: listeo.ajaxurl, 546 data: { 547 action: "reload_reviews", 548 id: post_id, 549 page: page, 550 }, 551 success: function (data) { 552 $(".reviews-visitior-box").removeClass("loading"); 553 if (data.success == true) { 554 $("#reviews_list_visitors").html(data.comments); 555 $("#visitor-reviews-pagination").html(data.pagination); 556 $(".popup-with-zoom-anim").magnificPopup({ 557 type: "inline", 558 559 fixedContentPos: false, 560 fixedBgPos: true, 561 562 overflowY: "auto", 563 564 closeBtnInside: true, 565 preloader: false, 566 567 midClick: true, 568 removalDelay: 300, 569 mainClass: "my-mfp-zoom-in", 570 }); 571 } else { 572 console.log("error"); 573 } 574 }, 575 }); 576 e.preventDefault(); 577 }); 578 579 $(".reviews-visitior-box").on("click", ".reply-to-review-link", function (e) { 580 $("#comment_reply").val(); 581 var post_id = $(this).data("postid"); 582 var review_id = $(this).data("replyid"); 583 584 $("#send-comment-reply input#reply-post-id").val(post_id); 585 $("#send-comment-reply input#reply-review-id").val(review_id); 586 }); 587 588 $(".reviews-visitior-box").on("click", ".edit-reply", function (e) { 589 //var review_id = $(this).parents('.review-li').data('review'); 590 $("#send-comment-edit-reply textarea#comment_reply").val(""); 591 var comment_id = $(this).data("comment-id"); 592 $.ajax({ 593 type: "POST", 594 dataType: "json", 595 url: listeo.ajaxurl, 596 data: { 597 action: "get_comment_review_details", 598 comment: comment_id, 599 //'nonce': nonce 600 }, 601 success: function (data) { 602 var comment_content = data.comment_content; 603 $("#send-comment-edit-reply textarea#comment_reply").val( 604 comment_content 605 ); 606 }, 607 }); 608 609 $("#send-comment-edit-reply input#reply_id").val(comment_id); 610 }); 611 612 $("#send-comment-edit-reply").on("submit", function (e) { 613 $("#send-comment-edit-reply button").addClass("loading"); 614 var content = $(this).find("textarea#comment_reply").val(); 615 var reply_id = $(this).find("input#reply_id").val(); 616 $.ajax({ 617 type: "POST", 618 dataType: "json",
619 url: listeo.ajaxurl, 620 data: { 621 action: "edit_reply_to_review", 622 //'post_id': $(this).find('input#reply-post-id').val(), 623 reply_id: $(this).find("input#reply_id").val(), 624 content: content, 625 //'nonce': nonce 626 }, 627 success: function (data) { 628 if (data.success == true) { 629 $("#send-comment-edit-reply button").removeClass("loading"); 630 $('.edit-reply[data-comment-id="' + reply_id + '"]').data( 631 "comment-content", 632 content 633 ); 634 // $('#review-'+review_id+' .edit-reply') 635 $(".mfp-close").trigger("click"); 636 } else { 637 $("#send-comment-edit-reply button").removeClass("loading"); 638 } 639 }, 640 }); 641 e.preventDefault(); 642 }); 643 644 $("#send-comment-reply").on("submit", function (e) { 645 $("#send-comment-reply button").addClass("loading"); 646 var review_id = $(this).find("input#reply-review-id").val(); 647 648 $.ajax({ 649 type: "POST", 650 dataType: "json", 651 url: listeo.aja
651xurl, 652 data: { 653 action: "reply_to_review", 654 post_id: $(this).find("input#reply-post-id").val(), 655 review_id: review_id, 656 content: $(this).find("textarea#comment_reply").val(), 657 //'nonce': nonce 658 }, 659 success: function (data) { 660 console.log(data); 661 if (data.success == true) { 662 $("#send-comment-reply button").removeClass("loading"); 663 $(".mfp-close").trigger("click"); 664 $("#review-" + review_id + " .reply-to-review-link") 665 .html('<i class="sl sl-icon-check"></i> ' + listeo_core.replied) 666 .off("click"); 667 //location.reload(); 668 } else { 669 $("#send-comment-reply button").removeClass("loading"); 670 } 671 }, 672 }); 673 e.preventDefault(); 674 }); 675 676 var critera = listeo_core.review_criteria.split(","); 677 678 $(".your-reviews-box").on("click", ".edit-review", function (e) { 679 //var review_id = $(this).parents('.review-li').data('review'); 680 $("#send-comment-edit-review input[type=radio]").prop("checked", false); 681 $("#send-comment-edit-review textarea#comment_reply").val(""); 682 $(".message-reply").addClass("loading"); 683 var comment_id = $(this).data("comment-id"); 684 685 $.ajax({ 686 type: "POST", 687 dataType: "json", 688 url: listeo.ajaxurl, 689 data: { 690 action: "get_comment_review_details", 691 comment: comment_id, 692 //'nonce': nonce 693 }, 694 success: function (data) { 695 $("#send-comment-edit-review input#reply_id").val(comment_id); 696 $("#send-comment-edit-review input#rating-" + data.comment_rating).prop( 697 "checked", 698 true 699 ); 700 $(".sub-ratings-container").html(data.ratings); 701 // $.each( critera, function( index, value ){ 702 // var rate_val = data[value]; 703 704 // console.log(rate_val); 705 706 // $("#send-comment-edit-review input#rating-"+value+"-"+rate_val).prop( "checked", true ); 707 // }); 708 $("#send-comment-edit-review textarea#comment_reply").val( 709 data.comment_content 710 ); 711 $(".message-reply").removeClass("loading"); 712 }, 713 }); 714 715 // var button = $(this); 716 // var comment_content = $(this).data('comment-content'); 717 // var comment_rating = $(this).data('comment-rating'); 718 719 // $('#send-comment-edit-review input#reply_id').val(comment_id); 720 721 // $('#send-comment-edit-review input#rating-'+comment_rating).prop( "checked", true ); 722 // $.each( critera, function( index, value ){ 723 // var rate_val = button.data('comment-'+value); 724 // $('#send-comment-edit-review input#rating-'+value+'-'+rate_val).prop( "checked", true ); 725 // }); 726 // $('#send-comment-edit-review textarea#comment_reply').val(comment_content); 727 }); 728 729 $(".listeo_core-dashboard-delete-review").click(function (e) { 730 e.preventDefault(); 731 if (window.confirm(listeo_core.areyousure)) { 732 location.href = this.href; 733 } 734 }); 735 736 function get_url_extension(url) { 737 return url.split(/\#|\?/)[0].split(".").pop().trim(); 738 } 739 740 $("body").on("submit", ".ical-import-form", function (e) { 741 e.preventDefault(); 742 743 $(this).find("button").addClass("loading"); 744 $("input.import_ical_url").removeClass("bounce"); 745 746 var form = $(this); 747 var listing_id = $(this).data("listing-id"); 748 var name = $(this).find("input.import_ical_name").val(); 749 var url = $(this).find("input.import_ical_url").val(); 750 var force_update = $(this) 751 .find("input.import_ical_force_update") 752 .prop("checked"); 753 var filetype = get_url_extension(url); //validate for .ical, .ics, .ifb, .icalendar 754 755 var valid_filetypes = ["ical", "ics", "ifb", "icalendar", "calendar"]; 756 757 if ( 758 url.indexOf("calendar") !== -1 || 759 url.indexOf("accommodation_id") !== -1 || 760 url.indexOf("ical") !== -1 || 761 $.inArray(filetype, valid_filetypes) > -1 762 ) { 763 $.ajax({ 764 type: "POST", 765 dataType: "json", 766 url: listeo.ajaxurl, 767 data: { 768 action: "add_new_listing_ical", 769 name: name, 770 url: url, 771 listing_id: listing_id, 772 force_update: force_update, 773 //'nonce': nonce 774 }, 775 success: function (data) { 776 if (data.type == "success") { 777 form.find("button").removeClass("loading"); 778 form.find("input.import_ical_name").val(""); 779 form.find("input.import_ical_url").val(""); 780 form 781 .parents(".ical-import-dialog") 782 .find(".saved-icals") 783 .html(data.output); 784 $(".ical-import-dialog .notification") 785 .removeClass("error notice") 786 .addClass("success") 787 .show() 788 .html(data.notification); 789 } 790 791 if (data.type == "error") { 792 form.find("button").removeClass("loading"); 793 794 $(".ical-import-dialog .notification") 795 .removeClass("success notice") 796 .addClass("error") 797 .show() 798 .html(data.notification); 799 } 800 }, 801 }); 802 } else { 803 $(this).find("button").removeClass("loading"); 804 $("input.import_ical_url").addClass("bounce"); 805 window.setTimeout(function () { 806 $("input.import_ical_url").removeClass("bounce"); 807 }, 1000); 808 } 809 }); 810 811 $("body").on("click", "a.ical-remove", function (e) { 812 e.preventDefault(); 813 var $this = $(this), 814 index = $(this).data("remove"), 815 nonce = $(this).data("nonce"); 816 var listing_id = $(this).data("listing-id"); 817 $this.parents(".saved-icals").addClass("loading"); 818 819 $.ajax({ 820 type: "POST", 821 dataType: "json",
822 url: listeo.ajaxurl, 823 data: { 824 action: "add_remove_listing_ical", 825 index: index, 826 listing_id: listing_id, 827 //'nonce': nonce 828 }, 829 success: function (data) { 830 if (data.type == "success") { 831 $this 832 .parents(".saved-icals") 833 .removeClass("loading") 834 .html(data.output); 835 } 836 $(".ical-import-dialog .notification").show().html(data.notification); 837 }, 838 }); 839 }); 840 841 $("body").on("click", "a.update-all-icals", function (e) { 842 e.preventDefault(); 843 var $this = $(this), 844 listing_id = $(this).data("listing-id"); 845 $this.addClass("loading"); 846 $.ajax({ 847 type: "POST", 848 dataType: "json", 849 url: listeo.ajaxurl, 850 data: { 851 action: "refresh_listing_import_ical", 852 listing_id: listing_id, 853 //'nonce': nonce 854 }, 855 success: function (data) { 856 $this.removeClass("loading"); 857 if (data.type == "success") { 858 $(".ical-import-dialog .notification") 859 .removeClass("error notice") 860 .addClass("success") 861 .show() 862 .html(data.notification); 863 } else if (data.type == "error") { 864 $(".ical-import-dialog .notification") 865 .removeClass("success notice") 866 .addClass("error") 867 .show() 868 .html(data.notification); 869 } 870 }, 871 }); 872 }); 873 874 $("#send-comment-edit-review").on("submit", function (e) { 875 $("#send-comment-edit-review button").addClass("loading"); 876 var value = "service"; 877 var button = $(this); 878 var content = $(this).find("textarea#comment_reply").val(); 879 var reply_id = $(this).find("input#reply_id").val(); 880 var reply_rating = $(this).find('input[type="radio"]:checked').val(); 881 882 var data = { 883 action: "edit_review", 884 //'post_id': $(this).find('input#reply-post-id').val(), 885 reply_id: $(this).find("input#reply_id").val(), 886 content: content, 887 //'nonce': nonce 888 }; 889 $.each(critera, function (index, value) { 890 data["rating_" + value] = button 891 .find('input[type="radio"][name="' + value + '"]:checked') 892 .val(); 893 }); 894 console.log(data); 895 896 $.ajax({ 897 type: "POST", 898 dataType: "json", 899 url: listeo.ajaxurl, 900 data: data, 901 success: function (data) { 902 if (data.success == true) { 903 $("#send-comment-edit-review button").removeClass("loading"); 904 905 // $('#review-'+review_id+' .edit-reply') 906 $(".mfp-close").trigger("click"); 907 } else { 908 $("#send-comment-edit-review button").removeClass("loading"); 909 } 910 }, 911 }); 912 e.preventDefault(); 913 }); 914 915 $("a.listeo_core-rate-review").on("click", function (e) { 916 e.preventDefault(); 917 var $this = $(this), 918 comment = $(this).data("comment"), 919 nonce = $(this).data("nonce"); 920 if ($this.data("processing")) { 921 return false; 922 } 923 924 $this.data("processing", true); 925 926 $.ajax({ 927 type: "POST", 928 dataType: "json", 929 url: listeo.ajaxurl, 930 data: { 931 action: "listeo_core_rate_review", 932 comment: comment, 933 //'nonce': nonce 934 }, 935 success: function (data) { 936 $this.html(data.output); 937 }, 938 939 complete: function () { 940 // Reset processing flag after request completes 941 $this.data("processing", false); 942 }, 943 }); 944 e.preventDefault(); 945 }); 946 947 // Contact Form Ajax 948 949 $("#send-message-from-widget").on("submit", function (e) { 950 $("#send-message-from-widget button") 951 .addClass("loading") 952 .prop("disabled", true); 953 954 $.ajax({ 955 type: "POST", 956 dataType: "json", 957 url: listeo.ajaxurl, 958 data: { 959 action: "listeo_send_message", 960 recipient: $(this).find("textarea#contact-message").data("recipient"), 961 referral: $(this).find("textarea#contact-message").data("referral"), 962 message: $(this).find("textarea#contact-message").val(), 963 //'nonce': nonce 964 }, 965 success: function (data) { 966 if (data.type == "success") { 967 $("#send-message-from-widget button").removeClass("loading"); 968 $("#send-message-from-widget .notification") 969 .show() 970 .html(data.message); 971 window.setTimeout(closepopup, 3000); 972 $(this).find("textarea#contact-message").val(""); 973 } else { 974 $("#send-message-from-widget .notification") 975 .removeClass("success") 976 .addClass("error") 977 .show() 978 .html(data.message); 979 $("#send-message-from-widget button") 980 .removeClass("loading") 981 .prop("disabled", false); 982 } 983 }, 984 }); 985 e.preventDefault(); 986 }); 987 988 function closepopup() { 989 var magnificPopup = $.magnificPopup.instance; 990 if (magnificPopup) { 991 magnificPopup.close(); 992 $("#send-message-from-widget button") 993 .removeClass("loading") 994 .prop("disabled", false); 995 } 996 } 997 998 $("#send-message-from-chat").on("submit", function (e) { 999 var message = $(this).find("textarea#contact-message").val(); 1000 1001 if (message) { 1002 $(this).find("textarea#contact-message").removeClass("error"); 1003 $(".loading").show(); 1004 $(this).find("button").prop("disabled", true); 1005 $.ajax({ 1006 type: "POST", 1007 dataType: "json",
1008 url: listeo.ajaxurl, 1009 data: { 1010 action: "listeo_send_message_chat", 1011 recipient: $(this).find("input#recipient").val(), 1012 conversation_id: $(this).find("input#conversation_id").val(), 1013 message: message, 1014 //'nonce': nonce 1015 }, 1016 success: function (data) { 1017 if (data.type == "success") { 1018 $(this).addClass("success"); 1019 refreshMessages(); 1020 $("#send-message-from-chat textarea").val(""); 1021 $("#send-message-from-chat button").prop("disabled", false); 1022 } else { 1023 $(this).addClass("error"); 1024 } 1025 }, 1026 }); 1027 } else { 1028 $(this).find("textarea#contact-message").addClass("error"); 1029 } 1030 e.preventDefault(); 1031 }); 1032 1033 $(document).on("click", ".booking-message", function (e) { 1034 var recipient = $(this).data("recipient"); 1035 var referral = $(this).data("booking_id"); 1036 $("#send-message-from-widget textarea").val(""); 1037 $("#send-message-from-widget .notification").hide(); 1038 1039 $("#send-message-from-widget textarea") 1040 .data("referral", referral) 1041 .data("recipient", recipient); 1042 1043 $(".send-message-to-owner").trigger("click"); 1044 }); 1045 1046 function refreshMessages() { 1047 if ($(".message-bubbles").length) { 1048 $.ajax({ 1049 type: "POST", 1050 dataType: "json", 1051 url: listeo.ajaxurl, 1052 data: { 1053 action: "listeo_get_conversation", 1054 conversation_id: $( 1055 "#send-message-from-chat input#conversation_id" 1056 ).val(), 1057 //'nonce': nonce 1058 }, 1059 success: function (data) { 1060 if (data.type == "success") { 1061 $(".message-bubbles").html(data.message); 1062 } 1063 $(".loading").hide(); 1064 }, 1065 complete: function () { 1066 setTimeout(refreshMessages, 4000); 1067 }, 1068 }); 1069 } 1070 } 1071 setTimeout(refreshMessages, 4000); 1072 1073 if ($("#coupon_bg-uploader").length > 0) { 1074 /* Upload using dropzone */ 1075 Dropzone.autoDiscover = false; 1076 1077 var couponDropzone = new Dropzone("#coupon_bg-uploader", { 1078 url: listeo_core.upload, 1079 maxFiles: 1, 1080 maxFilesize: listeo_core.maxFilesize, 1081 dictDefaultMessage: listeo_core.dictDefaultMessage, 1082 dictFallbackMessage: listeo_core.dictFallbackMessage, 1083 dictFallbackText: listeo_core.dictFallbackText, 1084 dictFileTooBig: listeo_core.dictFileTooBig, 1085 dictInvalidFileType: listeo_core.dictInvalidFileType, 1086 dictResponseError: listeo_core.dictResponseError, 1087 dictCancelUpload: listeo_core.dictCancelUpload, 1088 dictCancelUploadConfirmation: listeo_core.dictCancelUploadConfirmation, 1089 dictRemoveFile: listeo_core.dictRemoveFile, 1090 dictMaxFilesExceeded: listeo_core.dictMaxFilesExceeded, 1091 acceptedFiles: "image/*", 1092 accept: function (file, done) { 1093 done(); 1094 }, 1095 init: function () { 1096 this.on("addedfile", function () { 1097 if (this.files[1] != null) { 1098 this.removeFile(this.files[0]); 1099 } 1100 }); 1101 }, 1102 1103 success: function (file, response) { 1104 file.previewElement.classList.add("dz-success"); 1105 //remove any blank characters and empty lines from response 1106 response = response.replace(/(\r\n|\n|\r)/gm, ""); 1107 file["attachment_id"] = response; // push the id for future reference 1108 1109 $("#coupon_bg-uploader-id").val(file["attachment_id"]); 1110 }, 1111 error: function (file, response) { 1112 file.previewElement.classList.add("dz-error"); 1113 }, 1114 // update the following section is for removing image from library 1115 addRemoveLinks: true, 1116 removedfile: function (file) { 1117 var attachment_id = file["attachment_id"]; 1118 if (attachment_id == undefined) { 1119 attachment_id = $("#coupon_bg-uploader-id").val(); 1120 } 1121 $("#coupon_bg-uploader-id").val(""); 1122 $.ajax({ 1123 type: "POST", 1124 url: listeo_core.delete, 1125 data: { 1126 media_id: attachment_id, 1127 }, 1128 success: function (result) { 1129 console.log(result); 1130 }, 1131 error: function () { 1132 console.log("delete error"); 1133 }, 1134 }); 1135 var _ref; 1136 return (_ref = file.previewElement) != null 1137 ? _ref.parentNode.removeChild(file.previewElement) 1138 : void 0; 1139 }, 1140 }); 1141 1142 couponDropzone.on("maxfilesexceeded", function (file) { 1143 this.removeFile(file); 1144 }); 1145 if ($(".edit-coupon-photo").attr("data-photo")) { 1146 var mockFile = { 1147 name: $(".edit-coupon-photo").attr("data-name"), 1148 size: $(".edit-coupon-photo").attr("data-size"), 1149 }; 1150 couponDropzone.emit("addedfile", mockFile); 1151 couponDropzone.emit( 1152 "thumbnail", 1153 mockFile, 1154 $(".edit-coupon-photo").attr("data-photo") 1155 ); 1156 couponDropzone.emit("complete", mockFile); 1157 couponDropzone.files.push(mockFile); 1158 // If you use the maxFiles option, make sure you adjust it to the 1159 // correct amount: 1160 1161 couponDropzone.options.maxFiles = 1; 1162 } 1163 } 1164 1165 if ($("#avatar-uploader").length > 0) { 1166 /* Upload using dropzone */ 1167 Dropzone.autoDiscover = false;
1168 1169 var avatarDropzone = new Dropzone("#avatar-uploader", { 1170 url: listeo_core.upload, 1171 maxFiles: 1, 1172 maxFilesize: listeo_core.maxFilesize, 1173 dictDefaultMessage: listeo_core.dictDefaultMessage, 1174 dictFallbackMessage: listeo_core.dictFallbackMessage, 1175 dictFallbackText: listeo_core.dictFallbackText, 1176 dictFileTooBig: listeo_core.dictFileTooBig, 1177 dictInvalidFileType: listeo_core.dictInvalidFileType, 1178 dictResponseError: listeo_core.dictResponseError, 1179 dictCancelUpload: listeo_core.dictCancelUpload, 1180 dictCancelUploadConfirmation: listeo_core.dictCancelUploadConfirmation, 1181 dictRemoveFile: listeo_core.dictRemoveFile, 1182 dictMaxFilesExceeded: listeo_core.dictMaxFilesExceeded, 1183 acceptedFiles: "image/jpeg,image/png,image/gif,image/jpg", 1184 accept: function (file, done) { 1185 done(); 1186 }, 1187 init: function () { 1188 this.on("addedfile", function () { 1189 if (this.files[1] != null) { 1190 this.removeFile(this.files[0]); 1191 } 1192 }); 1193 }, 1194 1195 success: function (file, response) { 1196 file.previewElement.classList.add("dz-success"); 1197 file["attachment_id"] = response; // push the id for future reference 1198 $("#avatar-uploader-id").val(file["attachment_id"]); 1199 }, 1200 error: function (file, response) { 1201 file.previewElement.classList.add("dz-error"); 1202 $(file.previewElement).find(".dz-error-message").text(response); 1203 }, 1204 // update the following section is for removing image from library 1205 addRemoveLinks: true, 1206 removedfile: function (file) { 1207 var attachment_id = file["attachment_id"]; 1208 if (attachment_id == undefined) { 1209 attachment_id = $("#avatar-uploader-id").val(); 1210 } 1211 $("#avatar-uploader-id").val(""); 1212 $.ajax({ 1213 type: "POST", 1214 url: listeo_core.delete, 1215 data: { 1216 media_id: attachment_id, 1217 }, 1218 success: function (result) { 1219 console.log(result); 1220 }, 1221 error: function () { 1222 console.log("delete error"); 1223 }, 1224 }); 1225 var _ref; 1226 return (_ref = file.previewElement) != null 1227 ? _ref.parentNode.removeChild(file.previewElement) 1228 : void 0; 1229 }, 1230 }); 1231 1232 avatarDropzone.on("maxfilesexceeded", function (file) { 1233 this.removeFile(file); 1234 }); 1235 if ($(".edit-profile-photo").attr("data-photo")) { 1236 var mockFile = { 1237 name: $(".edit-profile-photo").attr("data-name"), 1238 size: $(".edit-profile-photo").attr("data-size"), 1239 }; 1240 avatarDropzone.emit("addedfile", mockFile); 1241 avatarDropzone.emit( 1242 "thumbnail", 1243 mockFile, 1244 $(".edit-profile-photo").attr("data-photo") 1245 ); 1246 avatarDropzone.emit("complete", mockFile); 1247 avatarDropzone.files.push(mockFile); 1248 // If you use the maxFiles option, make sure you adjust it to the 1249 // correct amount: 1250 1251 avatarDropzone.options.maxFiles = 1; 1252 } 1253 } 1254 1255 $( 1256 ".dynamic #tax-listing_category, .dynamic #tax-listing_category-panel input" 1257 ).on("change", function (e) { 1258 var cat_ids = []; 1259 1260 $("#tax-listing_feature-panel .checkboxes").addClass("loading"); 1261 $("#tax-listing_feature-panel .panel-buttons").hide(); 1262 var panel = false; 1263 1264 // if div with class drilldown-menu and data-name="tax-listing_category" exists 1265 if ( 1266 $( 1267 ".drilldown-menu-panel .drilldown-menu[data-name='tax-listing_category']" 1268 ).length > 0 1269 ) { 1270 $(".drilldown-generated").each(function () { 1271 cat_ids.push($(this).val()); 1272 }); 1273 panel = true; 1274 } else { 1275 if ($("#tax-listing_category-panel").length > 0) { 1276 panel = true; 1277 1278 $("#tax-listing_category-panel input[type=checkbox]:checked").each( 1279 function () { 1280 cat_ids.push($(this).val()); 1281 } 1282 ); 1283 } else { 1284 if ($("#tax-listing_feature-panel").length > 0) { 1285 panel = true; 1286 } 1287 if ($(this).prop("multiple")) { 1288 $("#tax-listing_category :selected").each(function (i, sel) { 1289 cat_ids.push($(sel).val()); 1290 }); 1291 } else { 1292 cat_ids.push($(this).val()); 1293 } 1294 } 1295 } 1296 1297 $.ajax({ 1298 type: "POST", 1299 dataType: "json",
1300 url: listeo.ajaxurl, 1301 data: { 1302 action: "listeo_get_features_from_category", 1303 cat_ids: cat_ids, 1304 panel: panel, 1305 //'nonce': nonce 1306 }, 1307 success: function (data) { 1308 $("#tax-listing_feature-panel .checkboxes").removeClass("loading"); 1309 $("#tax-listing_feature-panel .checkboxes .row") 1310 .html(data["output"]) 1311 .removeClass("loading"); 1312 $("#tax-listing_feature").html(data["output"]).removeClass("loading"); 1313 // $("#tax-listing_feature").empty().select2({ 1314 // data: data["data"], 1315 // }); 1316 if (data["success"]) { 1317 $("#tax-listing_feature-panel .panel-buttons").show(); 1318 } 1319 }, 1320 }); 1321 }); 1322 $(".dynamic #tax-listing_category").trigger("change"); 1323 //listeo_get_listing_types_from_categories 1324 1325 $( 1326 ".dynamic-taxonomies #tax-listing_category,.dynamic-taxonomies #tax-listing_category-panel input" 1327 ).on("change", function (e) { 1328 var cat_ids = []; 1329 1330 $(".dynamic-taxonomies #listeo-search-form_tax-service_category").hide(); 1331 $(".dynamic-taxonomies #listeo-search-form_tax-rental_category").hide(); 1332 $(".dynamic-taxonomies #listeo-search-form_tax-event_category").hide(); 1333 $( 1334 ".dynamic-taxonomies #listeo-search-form_tax-classifieds_category" 1335 ).hide(); 1336 $( 1337 ".dynamic-taxonomies #listeo-search-form_tax-service_category select, .dynamic-taxonomies #tax-service_category-panel select" 1338 ).val(""); 1339 $( 1340 ".dynamic-taxonomies #listeo-search-form_tax-rental_category select, .dynamic-taxonomies #tax-rental_category-panel select" 1341 ).val(""); 1342 $( 1343 ".dynamic-taxonomies #listeo-search-form_tax-event_category select, .dynamic-taxonomies #tax-event_category-panel select" 1344 ).val(""); 1345 $( 1346 ".dynamic-taxonomies #listeo-search-form_tax-classifieds_category select, .dynamic-taxonomies #tax-classifieds_category-panel select" 1347 ).val(""); 1348 $(".dynamic-taxonomies #tax-service_category-panel").hide(); 1349 $(".dynamic-taxonomies #tax-rental_category-panel").hide(); 1350 $(".dynamic-taxonomies #tax-event_category-panel").hide(); 1351 $(".dynamic-taxonomies #tax-classifieds_category-panel").hide(); 1352 $(".dynamic-taxonomies #tax-service_category-panel input:checkbox").prop( 1353 "checked", 1354 false 1355 ); 1356 $(".dynamic-taxonomies #tax-rental_category-panel input:checkbox").prop( 1357 "checked", 1358 false 1359 ); 1360 $(".dynamic-taxonomies #tax-event_category-panel input:checkbox").prop( 1361 "checked", 1362 false 1363 ); 1364 $( 1365 ".dynamic-taxonomies #tax-classifieds_category-panel input:checkbox" 1366 ).prop("checked", false); 1367 1368 $( 1369 ".dynamic-taxonomies #tax-event_category-panel input:checkbox" 1370 ).removeAttr("checked"); 1371 var panel = false; 1372 if ($("#tax-listing_category-panel").length > 0) { 1373 panel = true; 1374 1375 $("#tax-listing_category-panel input[type=checkbox]:checked").each( 1376 function () { 1377 cat_ids.push($(this).val()); 1378 } 1379 ); 1380 } else { 1381 if ($("#tax-listing_feature-panel").length > 0) { 1382 panel = true; 1383 } 1384 if ($(this).prop("multiple")) { 1385 $("#tax-listing_category :selected").each(function (i, sel) { 1386 cat_ids.push($(sel).val()); 1387 }); 1388 } else { 1389 cat_ids.push($(this).val()); 1390 } 1391 } 1392 $.ajax({ 1393 type: "POST", 1394 dataType: "json", 1395 url: listeo.ajaxurl, 1396 data: { 1397 action: "listeo_get_listing_types_from_categories", 1398 cat_ids: cat_ids, 1399 panel: panel, 1400 //'nonce': nonce 1401 }, 1402 success: function (data) { 1403 // $('#tax-listing_feature-panel .checkboxes').removeClass('loading'); 1404 // $('#tax-listing_feature-panel .checkboxes .row').html(data['output']).removeClass('loading'); 1405 // $('#tax-listing_feature').html(data['output']).removeClass('loading'); 1406 // if(data['success']){ 1407 // $('#tax-listing_feature-panel .panel-buttons').show(); 1408 // } 1409 // 1410 if (data["success"]) { 1411 var types = data["output"]; 1412 if (types.includes("service")) { 1413 $( 1414 ".dynamic-taxonomies #listeo-search-form_tax-service_category" 1415 ).show(); 1416 $(".dynamic-taxonomies #tax-service_category-panel").css( 1417 "display", 1418 "inline-block" 1419 ); 1420 } 1421 if (types.includes("rental")) { 1422 $( 1423 ".dynamic-taxonomies #listeo-search-form_tax-rental_category" 1424 ).show(); 1425 $(".dynamic-taxonomies #tax-rental_category-panel").css( 1426 "display", 1427 "inline-block" 1428 ); 1429 } 1430 if (types.includes("event")) { 1431 $( 1432 ".dynamic-taxonomies #listeo-search-form_tax-event_category" 1433 ).show(); 1434 $(".dynamic-taxonomies #tax-event_category-panel").css( 1435 "display", 1436 "inline-block" 1437 ); 1438 } 1439 if (types.includes("classifieds")) { 1440 $( 1441 ".dynamic-taxonomies #listeo-search-form_tax-classifieds_category" 1442 ).show(); 1443 $(".dynamic-taxonomies #tax-classifieds_category-panel").css( 1444 "display", 1445 "inline-block" 1446 ); 1447 } 1448 } 1449 }, 1450 }); 1451 }); 1452 1453 // check if there's change in the input lists inside of .drilldown-menu 1454 1455 $(document).on( 1456 "drilldown-updated", 1457 ".submit-page .drilldown-menu", 1458 function (e) { 1459 var listing_id = $("input[name='listing_id']").val(); 1460 1461 var cat_ids = []; 1462 $(".drilldown-generated").each(function () { 1463 cat_ids.push($(this).val()); 1464 }); 1465 1466 $.ajax({ 1467 type: "POST", 1468 dataType: "json",
1469 url: listeo.ajaxurl, 1470 data: { 1471 action: "listeo_get_features_ids_from_category", 1472 cat_ids: cat_ids, 1473 listing_id: listing_id, 1474 selected: selected_listing_feature, 1475 panel: false, 1476 //'nonce': nonce 1477 }, 1478 success: function (data) { 1479 $( 1480 ".listeo_core-term-checklist-listing_feature,.listeo_core-term-checklist-tax-listing_feature" 1481 ).removeClass("loading"); 1482 $( 1483 ".listeo_core-term-checklist-listing_feature,.listeo_core-term-checklist-tax-listing_feature" 1484 ) 1485 .html(data["output"]) 1486 .removeClass("loading"); 1487 }, 1488 }); 1489 } 1490 ); 1491 1492 $(document).on( 1493 "drilldown-updated", 1494 "#listeo_core-search-form .drilldown-menu", 1495 function (e) { 1496 var cat_ids = []; 1497 $(".drilldown-generated").each(function () { 1498 cat_ids.push($(this).val()); 1499 }); 1500 1501 $("#tax-listing_feature-panel .checkboxes").addClass("loading"); 1502 $("#tax-listing_feature-panel .panel-buttons").hide(); 1503 var panel = false; 1504 1505 // if div with class drilldown-menu and data-name="tax-listing_category" exists 1506 if ( 1507 $( 1508 ".drilldown-menu-panel .drilldown-menu[data-name='tax-listing_category']" 1509 ).length > 0 1510 ) { 1511 $(".drilldown-generated").each(function () { 1512 cat_ids.push($(this).val()); 1513 }); 1514 panel = true; 1515 } else { 1516 if ($("#tax-listing_category-panel").length > 0) { 1517 panel = true; 1518 1519 $("#tax-listing_category-panel input[type=checkbox]:checked").each( 1520 function () { 1521 cat_ids.push($(this).val()); 1522 } 1523 ); 1524 } else { 1525 if ($("#tax-listing_feature-panel").length > 0) { 1526 panel = true; 1527 } 1528 if ($(this).prop("multiple")) { 1529 $("#tax-listing_category :selected").each(function (i, sel) { 1530 cat_ids.push($(sel).val()); 1531 }); 1532 } else { 1533 cat_ids.push($(this).val()); 1534 } 1535 } 1536 } 1537 1538 $.ajax({ 1539 type: "POST", 1540 dataType: "json", 1541 url: listeo.ajaxurl, 1542 data: { 1543 action: "listeo_get_features_from_category", 1544 cat_ids: cat_ids, 1545 panel: panel, 1546 //'nonce': nonce 1547 }, 1548 success: function (data) { 1549 $("#tax-listing_feature-panel .checkboxes").removeClass("loading"); 1550 $("#tax-listing_feature-panel .checkboxes .row") 1551 .html(data["output"]) 1552 .removeClass("loading"); 1553 $("#tax-listing_feature").html(data["output"]).removeClass("loading"); 1554 // $("#tax-listing_feature").empty().select2({ 1555 // data: data["data"], 1556 // }); 1557 if (data["success"]) { 1558 $("#tax-listing_feature-panel .panel-buttons").show(); 1559 } 1560 }, 1561 }); 1562 } 1563 ); 1564 1565 $( 1566 ".add-listing-section.dynamic-features #listing_category,.add-listing-section.dynamic-features #tax-listing_category" 1567 ).on("change", function (e) { 1568 var listing_id = $("input[name='listing_id']").val(); 1569 if ($(this).prop("multiple")) { 1570 var cat_ids; 1571 cat_ids = $(this).val(); 1572 } else { 1573 var cat_ids = []; 1574 cat_ids.push($(this).val()); 1575 } 1576 1577 $.ajax({ 1578 type: "POST", 1579 dataType: "json", 1580 url: listeo.ajaxurl, 1581 data: { 1582 action: "listeo_get_features_ids_from_category", 1583 cat_ids: cat_ids, 1584 listing_id: listing_id, 1585 selected: selected_listing_feature, 1586 panel: false, 1587 //'nonce': nonce 1588 }, 1589 success: function (data) { 1590 $( 1591 ".listeo_core-term-checklist-listing_feature,.listeo_core-term-checklist-tax-listing_feature" 1592 ).removeClass("loading"); 1593 $( 1594 ".listeo_core-term-checklist-listing_feature,.listeo_core-term-checklist-tax-listing_feature" 1595 ) 1596 .html(data["output"]) 1597 .removeClass("loading"); 1598 }, 1599 }); 1600 }); 1601 1602 var selected_listing_feature = []; 1603 if ($(".add-listing-section").length) { 1604 $.each( 1605 $("input[name='tax_input[listing_feature][]']:checked"), 1606 function () { 1607 selected_listing_feature.push($(this).val()); 1608 } 1609 ); 1610 1611 $("select#listing_category").trigger("change"); 1612 $("select#tax-listing_category").trigger("change"); 1613 } 1614 1615 if ( 1616 $("body").hasClass("tax-listing_category") || 1617 $("body").hasClass("post-type-archive-listing") 1618 ) { 1619 $("select#tax-listing_category").trigger("change");
1620 $("#tax-listing_category-panel input:checked").trigger("change"); 1621 } 1622 $("#tax-listing_category-panel input:checked").trigger("change"); 1623 // foreach 1624 // if($('.panel-dropdown-content .notification').length>0) { 1625 // console.log($(this)); 1626 // $(this).find('.panel-buttons').hide(); 1627 // } 1628 $(".panel-dropdown-content .notification").each(function (index) { 1629 $(this).parent().parent().find(".panel-buttons").hide(); 1630 }); 1631 1632 // var uploadButton = { 1633 // $button: $(".uploadButton-input"), 1634 // $nameField: $(".uploadButton-file-name"), 1635 // }; 1636 1637 // uploadButton.$button.on("change", function () { 1638 // _populateFileField($(this)); 1639 // }); 1640 1641 // function _populateFileField($button) { 1642 // var selectedFile = []; 1643 // for (var i = 0; i < $button.get(0).files.length; ++i) { 1644 // selectedFile.push($button.get(0).files[i].name + "<br>"); 1645 // } 1646 // uploadButton.$nameField.html(selectedFile); 1647 // } 1648 1649 // var uploadButton = { 1650 // $button: $(".uploadButton-input"), 1651 // $nameField: $(".uploadButton-file-name"), 1652 // }; 1653 1654 $(".add-listing-section").on("change", ".uploadButton-input", function (e) { 1655 _populateFileField($(this)); 1656 }); 1657 $(".dashboard-list-box-static").on( 1658 "change", 1659 ".uploadButton-input", 1660 function (e) { 1661 _populateFileField($(this)); 1662 } 1663 ); 1664 1665 $(".zoom-anim-dialog").on("change", ".uploadButton-input", function (e) { 1666 _populateFileField($(this)); 1667 }); 1668 1669 function _populateFileField($button) { 1670 console.log($button); 1671 var selectedFile = []; 1672 1673 for (var i = 0; i < $button.get(0).files.length; ++i) { 1674 selectedFile.push($button.get(0).files[i].name + "<br>"); 1675 } 1676 console.log(selectedFile); 1677 $($button).siblings(".uploadButton-file-name").html(selectedFile); 1678 } 1679 1680 /*----------------------------------------------------*/ 1681 /* Time Slots 1682 /*----------------------------------------------------*/ 1683 /*----------------------------------------------------*/ 1684 /* Time Slots 1685/*----------------------------------------------------*/ 1686 1687 // Add validation parts 1688 function updateCopySlotsDisplay(daySlots) { 1689 var dayIndex = daySlots.index(".day-slots"); 1690 1691 if (daySlots.find(".slots-container .single-slot").length > 0) { 1692 $(".copy-slots-item[data-value='" + dayIndex + "']").css( 1693 "display", 1694 "block" 1695 ); 1696 } else { 1697 $(".copy-slots-item[data-value='" + dayIndex + "']").css( 1698 "display", 1699 "none" 1700 ); 1701 } 1702 // Check if there are any slots in any day 1703 updateIcalDropdownVisibility(); 1704 } 1705 1706 // Function to check if any day has slots and update ical-dropdown-btn visibility 1707 function updateIcalDropdownVisibility() { 1708 // First check each individual day 1709 $(".day-slots").each(function (index) { 1710 var $currentDay = $(this); 1711 1712 // Check if any OTHER day has slots (days we could copy from) 1713 var otherDaysWithSlots = false; 1714 $(".day-slots").each(function (otherIndex) { 1715 if ( 1716 index !== otherIndex && 1717 $(this).find(".slots-container .single-slot").length > 0 1718 ) { 1719 otherDaysWithSlots = true; 1720 return false; // Break the loop when we find at least one 1721 } 1722 }); 1723 1724 // Show Copy Day button only if other days have slots to copy from 1725 if (otherDaysWithSlots) { 1726 $currentDay.find(".ical-dropdown-btn").show(); 1727 } else { 1728 $currentDay.find(".ical-dropdown-btn").hide(); 1729 } 1730 }); 1731 } 1732 1733 function timeStringToMinutes(timeStr, ampm = null) { 1734 // Split the time string to get hours and minutes 1735 const [hours, minutes] = timeStr.split(":"); 1736 let totalHours = parseInt(hours, 10); 1737 1738 // Handle 12-hour format with AM/PM 1739 if (ampm) { 1740 // If it's 12 AM (midnight), we need to convert to 0 hours 1741 if (totalHours === 12 && ampm.toLowerCase() === "am") { 1742 totalHours = 0; 1743 } 1744 // If it's PM (but not 12 PM), we add 12 hours 1745 else if (ampm.toLowerCase() === "pm" && totalHours !== 12) { 1746 totalHours += 12; 1747 } 1748 // Note: 12 PM (noon) remains as 12 hours, which is correct 1749 } 1750 1751 return totalHours * 60 + parseInt(minutes, 10); 1752 } 1753
1754 function minutesToTimeString(minutes, use12HourFormat = false) { 1755 let totalHours = Math.floor(minutes / 60); 1756 let hours = totalHours % 24; 1757 let mins = minutes % 60; 1758 let ampm = ""; 1759 1760 if (hours < 0) { 1761 hours += 24; 1762 } 1763 1764 if (mins < 0) { 1765 mins += 60; 1766 hours -= 1; 1767 if (hours < 0) { 1768 hours += 24; 1769 } 1770 } 1771 1772 // Convert to 12-hour format if needed 1773 if (use12HourFormat) { 1774 // Determine AM/PM 1775 ampm = hours >= 12 ? "pm" : "am"; 1776 1777 // Convert to 12-hour clock 1778 if (hours > 12) { 1779 hours = hours - 12; 1780 } else if (hours === 0) { 1781 hours = 12; // 0 hours in 24-hour format is 12 AM in 12-hour format 1782 } 1783 // Note: hours = 12 stays as 12 (12 PM/noon) 1784 1785 return { 1786 time: `${hours.toString().padStart(2, "0")}:${mins 1787 .toString() 1788 .padStart(2, "0")}`, 1789 ampm: ampm, 1790 }; 1791 } 1792 1793 // 24-hour format 1794 return `${hours.toString().padStart(2, "0")}:${mins 1795 .toString() 1796 .padStart(2, "0")}`; 1797 } 1798 1799 $(document).ready(function () { 1800 // Check if we're using 12-hour or 24-hour format based on the listeo_core variable 1801 // listeo_core.clockformat = true means 24h format, false means 12h format 1802 var is12HourFormat = 1803 typeof listeo_core !== "undefined" && 1804 listeo_core.clockformat !== undefined 1805 ? !listeo_core.clockformat 1806 : $(".availability-slots").data("clock-type") === "12hr"; 1807 1808 $(".day-slots").each(function () { 1809 var daySlots = $(this); 1810 1811 // Update the display of copy-slots-item elements initially 1812 updateCopySlotsDisplay(daySlots); 1813 1814 // Copy slots FROM another day 1815 daySlots.find(".copy-slots-item").on("click", function (e) { 1816 e.preventDefault(); 1817 var targetDaySlots = $(this).closest(".day-slots"); 1818 var sourceDayIndex = $(this).data("value"); 1819 var sourceDaySlots = $(".day-slots").eq(sourceDayIndex); 1820 1821 var slotsToCopy = sourceDaySlots 1822 .find(".slots-container .single-slot") 1823 .clone(); 1824 1825 // Remove existing slots with animation 1826 targetDaySlots 1827 .find(".slots-container .single-slot") 1828 .animate({ height: 0, opacity: 0 }, "fast", function () { 1829 $(this).remove(); 1830 }); 1831 1832 // Add new slots with animation 1833 setTimeout(function () { 1834 targetDaySlots.find(".slots-container").append(slotsToCopy); 1835 // Re-initialize the numberPicker for copied slots 1836 slotsToCopy.find(".plusminus").each(function () { 1837 $(this).numberPicker(); 1838 }); 1839 slotsToCopy 1840 .hide() 1841 .animate({ height: "show", opacity: "show" }, "fast"); 1842 }, 200); 1843 1844 // Remove the "no-slots" message if it exists in the target day 1845 targetDaySlots 1846 .find(".no-slots") 1847 .addClass("no-slots-fadeout") 1848 .removeClass("no-slots-fadein"); 1849 1850 // Update the display of copy-slots-item elements after copying 1851 updateCopySlotsDisplay(sourceDaySlots); 1852 updateCopySlotsDisplay(targetDaySlots); 1853 }); 1854 1855 daySlots.find(".add-slot-btn").on("click", function (e) { 1856 e.preventDefault(); 1857 1858 var slotTime_Start = daySlots 1859 .find(".add-slot-inputs input.time-slot-start") 1860 .val(); 1861 var slotTime_End = daySlots 1862 .find(".add-slot-inputs input.time-slot-end") 1863 .val(); 1864 1865 // Get AM/PM values for 12-hour format 1866 var slotTimePM_AM_Start = ""; 1867 var slotTimePM_AM_End = ""; 1868 1869 if (is12HourFormat) { 1870 slotTimePM_AM_Start = daySlots 1871 .find(".add-slot-inputs select.time-slot-start") 1872 .val(); 1873 slotTimePM_AM_End = daySlots 1874 .find(".add-slot-inputs select.time-slot-end") 1875 .val(); 1876 } 1877 1878 // Checks if input values are not blank 1879 if (slotTime_Start.length > 0 && slotTime_End.length > 0) { 1880 // New Time Slot Div 1881 var newTimeSlot = daySlots 1882 .find(".single-slot.cloned") 1883 .clone(true) 1884 .addClass("slot-animation") 1885 .removeClass("cloned"); 1886 1887 setTimeout(function () { 1888 newTimeSlot.removeClass("slot-animation"); 1889 }, 300); 1890 1891 newTimeSlot.find(".plusminus input").val("1"); 1892 1893 // Plus - Minus Init 1894 newTimeSlot.find(".plusminus").numberPicker(); 1895 1896 // Check if there's am/pm dropdown (12-hour format) 1897 if (is12HourFormat) { 1898 newTimeSlot 1899 .find(".single-slot-time") 1900 .html( 1901 slotTime_Start + 1902 " " + 1903 '<i class="am-pm">' + 1904 slotTimePM_AM_Start + 1905 "</i>" + 1906 " - " + 1907 slotTime_End + 1908 " " + 1909 '<i class="am-pm">' + 1910 slotTimePM_AM_End + 1911 "</i>" 1912 ); 1913 } else { 1914 newTimeSlot 1915 .find(".single-slot-time") 1916 .html("" + slotTime_Start + " - " + slotTime_End); 1917 } 1918 1919 // Appending new slot 1920 newTimeSlot.appendTo(daySlots.find(".slots-container")); 1921 1922 // Refresh sortable script 1923 $(".slots-container").sortable("refresh"); 1924 1925 // Update the display of copy-slots-item elements after adding a new slot 1926 updateCopySlotsDisplay(daySlots); 1927 1928 // Calculate hour difference 1929 var slotTime_StartInMinutes, slotTime_EndInMinutes; 1930 1931 if (is12HourFormat) {
1932 slotTime_StartInMinutes = timeStringToMinutes( 1933 slotTime_Start, 1934 slotTimePM_AM_Start 1935 ); 1936 slotTime_EndInMinutes = timeStringToMinutes( 1937 slotTime_End, 1938 slotTimePM_AM_End 1939 ); 1940 } else { 1941 slotTime_StartInMinutes = timeStringToMinutes(slotTime_Start); 1942 slotTime_EndInMinutes = timeStringToMinutes(slotTime_End); 1943 } 1944 1945 // If end time is on next day (crosses midnight), add 24 hours (1440 minutes) to the end time 1946 if (slotTime_EndInMinutes < slotTime_StartInMinutes) { 1947 slotTime_EndInMinutes += 24 * 60; // Add 24 hours in minutes 1948 } 1949 1950 // Calculate the time difference 1951 const hourDifferenceInMinutes = 1952 slotTime_EndInMinutes - slotTime_StartInMinutes; 1953 1954 if (hourDifferenceInMinutes > 0) { 1955 // Set the new start time to the previous end time 1956 if (is12HourFormat) { 1957 daySlots 1958 .find(".add-slot-inputs input.time-slot-start") 1959 .val(slotTime_End); 1960 daySlots 1961 .find(".add-slot-inputs select.time-slot-start") 1962 .val(slotTimePM_AM_End); 1963 1964 // Calculate the new end time 1965 const newEndTimeInMinutes = 1966 slotTime_EndInMinutes + hourDifferenceInMinutes; 1967 const newEndTimeObj = minutesToTimeString( 1968 newEndTimeInMinutes, 1969 true 1970 ); 1971 1972 // Set new end time and AM/PM 1973 daySlots 1974 .find(".add-slot-inputs input.time-slot-end") 1975 .val(newEndTimeObj.time); 1976 daySlots 1977 .find(".add-slot-inputs select.time-slot-end") 1978 .val(newEndTimeObj.ampm); 1979 } else { 1980 // For 24-hour format 1981 daySlots 1982 .find(".add-slot-inputs input.time-slot-start") 1983 .val(slotTime_End); 1984 1985 // Calculate the new end time 1986 const newEndTimeInMinutes = 1987 slotTime_EndInMinutes + hourDifferenceInMinutes; 1988 const newEndTime = minutesToTimeString(newEndTimeInMinutes); 1989 1990 // Set new end time 1991 daySlots 1992 .find(".add-slot-inputs input.time-slot-end") 1993 .val(newEndTime); 1994 } 1995 } else { 1996 console.log( 1997 "End time is not larger than start time, not updating time inputs." 1998 ); 1999 } 2000 } else { 2001 // Validation Error 2002 daySlots.find(".add-slot").addClass("add-slot-shake-error"); 2003 setTimeout(function () { 2004 daySlots.find(".add-slot").removeClass("add-slot-shake-error"); 2005 }, 600); 2006 } 2007 }); 2008 2009 // Removing "no slots" message 2010 function hideSlotInfo() { 2011 var slotCount = daySlots.find(".slots-container").children().length; 2012 if (slotCount < 1) { 2013 daySlots 2014 .find(".no-slots") 2015 .addClass("no-slots-fadein") 2016 .removeClass("no-slots-fadeout"); 2017 } 2018 } 2019 hideSlotInfo(); 2020 2021 // Removing Slot 2022 daySlots.on("click touchstart", ".remove-slot", function (e) { 2023 e.preventDefault(); 2024 $(this) 2025 .closest(".single-slot") 2026 .animate({ height: 0, opacity: 0 }, "fast", function () { 2027 $(this).remove(); 2028 }); 2029 2030 // Removing "no slots" message 2031 setTimeout(function () { 2032 hideSlotInfo(); 2033 }, 400); 2034 2035 // Update the display of copy-slots-item elements after removing a slot 2036 updateCopySlotsDisplay(daySlots); 2037 }); 2038 2039 // Showing "no slots" message 2040 daySlots.find(".add-slot-btn").on("click", function (e) { 2041 e.preventDefault(); 2042 2043 var slotCount = daySlots.find(".slots-container").children().length; 2044 2045 if (slotCount >= 1) { 2046 daySlots 2047 .find(".no-slots") 2048 .removeClass("no-slots-fadein") 2049 .addClass("no-slots-fadeout"); 2050 } 2051 }); 2052 }); 2053 }); 2054 2055 // Sotrable Script 2056 $(".slots-container").sortable(); 2057 2058 // 24 hour clock type switcher 2059 if ($(".availability-slots").attr("data-clock-type") == "24hr") { 2060 $(".availability-slots").addClass("twenty-four-clock"); 2061 $(".availability-slots").find('input[type="time"]').attr({ max: "24:00" }); 2062 } 2063 2064 // Switcher 2065 $(".add-listing-section").each(function () { 2066 var switcherSection = $(this);
2067 var switcherInput = $(this).find(".switch input"); 2068 2069 if (switcherInput.is(":checked")) { 2070 $(switcherSection).addClass("switcher-on"); 2071 } 2072 2073 switcherInput.change(function () { 2074 if (this.checked === true) { 2075 $(switcherSection).addClass("switcher-on"); 2076 2077 if (switcherInput.attr("id") == "_booking_status") { 2078 $( 2079 ".add-listing-section.slots,.add-listing-section.basic_prices,.add-listing-section.availability_calendar" 2080 ).show(); 2081 } 2082 } else { 2083 $(switcherSection).removeClass("switcher-on"); 2084 if (switcherInput.attr("id") == "_booking_status") { 2085 $( 2086 ".add-listing-section.slots,.add-listing-section.basic_prices,.add-listing-section.availability_calendar" 2087 ).hide(); 2088 } 2089 } 2090 }); 2091 }); 2092 2093 if ($("#_booking_status").is(":checked")) { 2094 $( 2095 ".add-listing-section.slots,.add-listing-section.basic_prices,.add-listing-section.availability_calendar" 2096 ).show(); 2097 } else { 2098 $( 2099 ".add-listing-section.slots,.add-listing-section.basic_prices,.add-listing-section.availability_calendar" 2100 ).hide(); 2101 } 2102 2103 /*----------------------------------------------------*/ 2104 /* Booking Sticky Footer 2105 /*----------------------------------------------------*/ 2106 $(".booking-sticky-footer a.button").on("click", function (e) { 2107 var $anchor = $(this); 2108 $("html, body").animate( 2109 { scrollTop: $($anchor.attr("href")).offset().top - 100 }, 2110 1000 2111 ); 2112 }); 2113 2114 /*----------------------------------------------------*/ 2115 /* Opening Hours 2116 /*----------------------------------------------------*/ 2117 2118 $("body").on("click", ".opening-day-remove", function (e) { 2119 e.preventDefault(); 2120 var div_class = $(this).data("remove"); 2121 $(this).parent().parent().remove(); 2122 $("div." + div_class).remove(); 2123 }); 2124 2125 $("body").on("click", ".opening-day-add-hours", function (e) { 2126 e.preventDefault(); 2127 var dayname = $(this).data("dayname"); 2128 var count = $(this).parents(".opening-day").find(".row").length; 2129 var id = $(this).data("id"); 2130 var i = $(this).parents(".opening-day").find(".row").length; 2131 2132 var newElem = $( 2133 "" + 2134 '<div class="row"><div class="col-md-2 opening-day-tools"><a class="opening-day-remove button" data-remove="' + 2135 dayname + 2136 "-opening-hours-row" + 2137 count + 2138 '" href="#">' + 2139 listeo_core.remove + 2140 "</a>" + 2141 '</div><div class="col-md-5 ' + 2142 dayname + 2143 "-opening-hours-row" + 2144 count + 2145 '">' + 2146 '<input type="text" class="listeo-flatpickr" name="_' + 2147 id + 2148 '_opening_hour[]" placeholder="' + 2149 listeo_core.opening_time + 2150 '" value=""></div>' + 2151 '<div class="col-md-5 ' + 2152 dayname + 2153 "-opening-hours-row" + 2154 count + 2155 '" >' + 2156 '<input type="text" class="listeo-flatpickr" name="_' + 2157 id + 2158 '_closing_hour[]" placeholder="' + 2159 listeo_core.closing_time + 2160 '" value="">' + 2161 "</div></div>" 2162 ); 2163 2164 newElem.appendTo($(this).parents(".opening-day")); 2165 var time24 = false; 2166 2167 if (listeo_core.clockformat) { 2168 time24 = true; 2169 } 2170 $(this) 2171 .parents(".opening-day") 2172 .find(".row:last .listeo-flatpickr") 2173 .flatpickr({ 2174 enableTime: true, 2175 noCalendar: true, 2176 dateFormat: "H:i", 2177 time_24hr: time24, 2178 disableMobile: true, 2179 }); 2180 }); 2181 2182 $("input[type=radio][name=user_role]").change(function () { 2183 $("#listeo-core-registration-fields").html(""); 2184 if ( 2185 this.value == "owner" || 2186 this.value == "vendor" || 2187 this.value == "seller" 2188 ) { 2189 $("#listeo-core-registration-fields").html( 2190 $( 2191 ".listeo-custom-fields-wrapper #listeo-core-registration-owner-fields" 2192 ).html() 2193 ); 2194 } else { 2195 $("#listeo-core-registration-fields").html( 2196 $( 2197 ".listeo-custom-fields-wrapper #listeo-core-registration-guest-fields" 2198 ).html() 2199 ); 2200 } 2201 // setTimeout(function() { 2202 // // Use a more specific selector 2203 // $("#listeo-core-registration-fields .select2-single").each(function() { 2204 // // Destroy any existing select2 instance 2205 // if ($(this).hasClass('select2-hidden-accessible')) { 2206 // $("#listeo-custom-fields-wrapper").select2('destroy'); 2207 // } 2208 2209 // // Initialize select2 2210 // $(this).select2({ 2211 // dropdownPosition: "below", 2212 // minimumResultsForSearch: 20, 2213 // width: "100%", 2214 // placeholder: $(this).data("placeholder"), 2215 // formatNoMatches: listeo_core.no_results_text, 2216 // }); 2217 // }); 2218 // }, 100); 2219 }); 2220 2221 /*----------------------------------------------------*/ 2222 /* Pricing List 2223 /*----------------------------------------------------*/ 2224 function pricingCoverSwitcher() { 2225 var readURL = function (input) { 2226 if (input.files && input.files[0]) { 2227 var reader = new FileReader(); 2228 var input_obj = $(input); 2229 2230 reader.onload = function (e) { 2231 $(input).parent().find(".cover-pic").attr("src", e.target.result); 2232 $(input).parent().find(".menu-cover-id").val(""); 2233 }; 2234
2235 reader.readAsDataURL(input.files[0]); 2236 } 2237 }; 2238 $("#pricing-list-container").on("change", ".file-upload", function (e) { 2239 readURL(this); 2240 }); 2241 $("#pricing-list-container").on("click", ".upload-button", function (e) { 2242 $(this).next(".file-upload").click(); 2243 }); 2244 } 2245 pricingCoverSwitcher(); 2246 2247 $(".remove-cover").on("click", function (e) { 2248 e.preventDefault(); 2249 $(this).next(".menu-cover-id").val(""); 2250 $(this) 2251 .parent() 2252 .find(".cover-pic") 2253 .attr("src", listeo.theme_url + "/images/pricing-cover-placeholder.png"); 2254 }); 2255 2256 function newMenuItem() { 2257 // var newElem = $('tr.pricing-list-item:not(.pricing-submenu)').last().clone(true); 2258 // console.log(newElem.length); 2259 // if(!newElem){ 2260 var extra_services = listeo_core.extra_services_options_type; 2261 2262 //check if extra_services is an array 2263 var select_extra_service_types = ""; 2264 if (typeof extra_services === "string") { 2265 extra_services = extra_services.split(","); 2266 } 2267 2268 // '<div class="fm-input pricing-bookable-options">' + 2269 // '<select class="select2-single" name="_menu[0][menu_elements][0][bookable_options]" id="">' + 2270 // select_extra_service_types + 2271 // "</select>" + 2272 // '<div class="checkboxes in-row pricing-quanity-buttons">' + 2273 // '<input type="checkbox" class="input-checkbox" name="_menu[0][menu_elements][0][bookable_quantity]" id="_menu[0][menu_elements][0][bookable_quantity]" />' + 2274 // '<label for="_menu[0][menu_elements][0][bookable_quantity]">' + 2275 // listeo_core.quantitybuttons + 2276 // "</label>" + 2277 // '<input type="number" class="bookable_quantity_max" step="1" name="_menu[0][menu_elements][0][bookable_quantity_max]" placeholder="' + 2278 // listeo_core.bookable_quantity_max + 2279 // '" />"' + 2280 // "</div>" + 2281 // check if extra_services size is less then 4 2282 if (extra_services.length < 4) { 2283 var select_extra_service_types = 2284 '<div class="fm-input pricing-bookable-options">' + 2285 '<select class="select2-single" name="_menu[0][menu_elements][0][bookable_options]" id="">'; 2286 if (!extra_services.includes("onetime")) { 2287 select_extra_service_types += 2288 '<option value="onetime">' + listeo_core.onetimefee + "</option>"; 2289 } 2290 // check if byguest is in array extra_service 2291 2292 if (!extra_services.includes("byguest")) { 2293 select_extra_service_types += 2294 '<option value="byguest">' + listeo_core.multiguest + "</option>"; 2295 } 2296 if (!extra_services.includes("bydays")) { 2297 select_extra_service_types += 2298 '<option value="bydays">' + listeo_core.multidays + "</option>"; 2299 } 2300 if (!extra_services.includes("byguestanddays")) { 2301 select_extra_service_types += 2302 '<option value="byguestanddays">' + 2303 listeo_core.multiguestdays + 2304 "</option>"; 2305 } 2306 select_extra_service_types += 2307 "</select>" + 2308 '<div class="checkboxes in-row pricing-quanity-buttons">' + 2309 '<input type="checkbox" class="input-checkbox" name="_menu[0][menu_elements][0][bookable_quantity]" id="_menu[0][menu_elements][0][bookable_quantity]" />' + 2310 '<label for="_menu[0][menu_elements][0][bookable_quantity]">' + 2311 listeo_core.quantitybuttons + 2312 "</label>" + 2313 '<input type="number" class="bookable_quantity_max" step="1" name="_menu[0][menu_elements][0][bookable_quantity_max]" placeholder="' + 2314 listeo_core.bookable_quantity_max + 2315 '" />' + 2316 "</div>"; 2317 } 2318 2319 var newElem = $( 2320 "" + 2321 '<tr class="pricing-list-item pattern" data-iterator="0">' + 2322 "<td>" + 2323 '<div class="fm-move"><i class="sl sl-icon-cursor-move"></i></div>' + 2324 '<div class="fm-input pricing-cover"><div class="pricing-cover-wrapper" data-tippy-placement="bottom" title="Change Avatar"><img class="cover-pic" src="' + 2325 listeo.theme_url + 2326 '/images/pricing-cover-placeholder.png" alt=""><div class="upload-button"></div><input class="file-upload" type="file" accept="image/*" name="_menu[0][menu_elements][0][cover]"></div></div>' + 2327 '<div class="fm-input pricing-name"><input type="text" placeholder="' + 2328 listeo_core.menu_title + 2329 '" name="_menu[0][menu_elements][0][name]" /></div>' + 2330 '<div class="fm-input pricing-ingredients"><input type="text" placeholder="' + 2331 listeo_core.menu_desc + 2332 '" name="_menu[0][menu_elements][0][description]"/></div>' + 2333 '<div class="fm-input pricing-price">' + 2334 '<i class="data-unit">' + 2335 listeo_core.currency_symbol + 2336 "</i>" + 2337 '<input type="number" step="0.01" placeholder="' + 2338 listeo_core.menu_price + 2339 '" name="_menu[0][menu_elements][0][price]" /></div>' + 2340 '<div class="fm-input pricing-bookable"><div class="switcher-tip" data-tip-content="' + 2341 listeo_core.pricingTooltip + 2342 '">' + 2343 '<input type="checkbox" class="input-checkbox switch_1" value="on" name="_menu[0][menu_elements][0][bookable]" /></div></div>' + 2344 select_extra_service_types + 2345 "</div>" + 2346 '<div class="fm-close"><a class="delete" href="#"><i class="fa fa-remove"></i></a></div>' + 2347 "</td>" + 2348 "</tr>" 2349 ); 2350 //} 2351 2352 newElem.find("input").val(""); 2353 2354 var prev_category_number = $(".pricing-submenu").last().data("number"); 2355 var prev_data_iterator = $("tr.pricing-list-item:not(.pricing-submenu)") 2356 .last() 2357 .data("iterator"); 2358 2359 if (prev_category_number == undefined) { 2360 prev_category_number = 0; 2361 } 2362 2363 var next_data_iterator = prev_data_iterator + 1; 2364 2365 var last_table_el = $("tr.pricing-list-item").last(); 2366 2367 newElem.find("input").each(function () { 2368 // replace 1st number with current category title number 2369 2370 this.name = this.name.replace( 2371 /\[\d+\]/, 2372 "[" + prev_category_number + "]" 2373 ); 2374 this.id = this.id.replace(/\[\d+\]/, "[" + prev_category_number + "]"); 2375 //replace 2nd number / if it's new category start from 0, if not iterate 2376 if (last_table_el.hasClass("pricing-submenu")) { 2377 next_data_iterator = 0; 2378 // replace 2nd number 2379 this.name = replaceLast( 2380 this.name, 2381 "[0]", 2382 "[" + next_data_iterator + "]" 2383 ); 2384 this.id = replaceLast(this.id, "[0]", "[" + next_data_iterator + "]"); 2385 } else { 2386 // replace 2nd number 2387 this.name = replaceLast( 2388 this.name, 2389 "[0]", 2390 "[" + next_data_iterator + "]" 2391 ); 2392 this.id = replaceLast(this.id, "[0]", "[" + next_data_iterator + "]"); 2393 } 2394 }); 2395 newElem.find("select").each(function () { 2396 // replace 1st number with current category title number 2397 2398 this.name = this.name.replace( 2399 /\[\d+\]/, 2400 "[" + prev_category_number + "]" 2401 ); 2402 this.id = this.id.replace(/\[\d+\]/, "[" + prev_category_number + "]"); 2403 //replace 2nd number / if it's new category start from 0, if not iterate 2404 if (last_table_el.hasClass("pricing-submenu")) { 2405 next_data_iterator = 0; 2406 // replace 2nd number 2407 this.name = replaceLast( 2408 this.name, 2409 "[0]", 2410 "[" + next_data_iterator + "]" 2411 ); 2412 this.id = replaceLast(this.id, "[0]", "[" + next_data_iterator + "]"); 2413 } else { 2414 // replace 2nd number 2415 this.name = replaceLast( 2416 this.name, 2417 "[0]", 2418 "[" + next_data_iterator + "]" 2419 ); 2420 this.id = replaceLast(this.id, "[0]", "[" + next_data_iterator + "]"); 2421 } 2422 }); 2423 2424 newElem.find("label").each(function () { 2425 //replace 1st number with current category title number 2426 this.htmlFor = this.htmlFor.replace( 2427 /\[\d+\]/, 2428 "[" + prev_category_number + "]" 2429 ); 2430 //console.log(this.htmlFor); 2431 2432 //replace 2nd number / if it's new category start from 0, if not iterate 2433 if (last_table_el.hasClass("pricing-submenu")) { 2434 next_data_iterator = 0; 2435 // replace 2nd number 2436 this.htmlFor = replaceLast( 2437 this.htmlFor, 2438 "[0]", 2439 "[" + next_data_iterator + "]" 2440 ); 2441 } else { 2442 // replace 2nd number 2443 this.htmlFor = replaceLast( 2444 this.htmlFor, 2445 "[0]", 2446 "[" + next_data_iterator + "]" 2447 ); 2448 } 2449 }); 2450 //console.log(newElem); 2451 2452 newElem 2453 .appendTo("table#pricing-list-container") 2454 .data("iterator", next_data_iterator) 2455 .find("select") 2456 .trigger("chosen:updated"); 2457 2458 $("#pricing-list-container").data("iterator", next_data_iterator); 2459 } 2460 2461 var test = "_menu[0][menu_elements][0][bookable_quantity]"; 2462 // console.log(test); 2463 // console.log(test.search(/\[\d+\]/)); 2464 2465 function replaceLast(string, search, replace) { 2466 // find the index of last time word was used 2467 var n = string.lastIndexOf(search); 2468 2469 // slice the string in 2, one from the start to the lastIndexOf 2470 // and then replace the word in the rest 2471 return string.slice(0, n) + string.slice(n).replace(search, replace); 2472 } 2473 2474 if ($("table#pricing-list-container").is("*")) { 2475 $(".add-pricing-list-item").on("click", function (e) { 2476 e.preventDefault(); 2477 newMenuItem(); 2478 }); 2479 2480 // remove ingredient 2481 $(document).on("click", "#pricing-list-container .delete", function (e) { 2482 e.preventDefault(); 2483 $(this).parent().parent().remove(); 2484 }); 2485 2486 // add submenu 2487 $(".add-pricing-submenu").on("click", function (e) { 2488 e.preventDefault(); 2489 var i = $(".pricing-submenu").length; 2490 2491 var newElem = $( 2492 "" + 2493 '<tr class="pricing-list-item pricing-submenu" data-number="' + 2494 i + 2495 '">' + 2496 "<td>" + 2497 '<div class="fm-move"><i class="sl sl-icon-cursor-move"></i></div>' + 2498 '<div class="fm-input"><input name="_menu[' + 2499 i + 2500 '][menu_title]" type="text" placeholder="' + 2501 listeo_core.category_title + 2502 '" /></div>' + 2503 '<div class="fm-close"><a class="delete" href="#"><i class="fa fa-remove"></i></a></div>' + 2504 "</td>" + 2505 "</tr>" 2506 ); 2507 2508 newElem.appendTo("table#pricing-list-container"); 2509 }); 2510 2511 $("table#pricing-list-container tbody").sortable({ 2512 forcePlaceholderSize: true, 2513 forceHelperSize: false, 2514 placeholder: "sortableHelper", 2515 zIndex: 999990, 2516 opacity: 0.6, 2517 tolerance: "pointer", 2518 start: function (e, ui) { 2519 ui.placeholder.height(ui.helper.outerHeight()); 2520 }, 2521 stop: function (event, ui) { 2522 updateNames($(this)); 2523 }, 2524 }); 2525 2526 $(window).on("load resize", function () { 2527 var winWidth = $(window).width(); 2528 if (winWidth < 992) { 2529 $("table#pricing-list-container tbody").sortable("disable"); 2530 } else if (winWidth > 992) { 2531 $("table#pricing-list-container tbody").sortable("enable"); 2532 } 2533 }); 2534 } 2535 2536 //updates list name numbers 2537 function updateNames($list) { 2538 var cat_i = 0; 2539 var subcat_i = 0; 2540 $list.find("tr").each(function () { 2541 var prev_data_iterator = $(this).data("iterator"); 2542 2543 //category 2544 if ($(this).hasClass("pricing-submenu")) { 2545 var cat_input = $(this).find("input"); 2546 cat_input.each(function () { 2547 this.name = this.name.replace(/(\[\d\])/, "[" + cat_i + "]"); 2548 }); 2549 var cat_select = $(this).find("select"); 2550 2551 cat_select.each(function () { 2552 this.name = this.name.replace(/(\[\d\])/, "[" + cat_i + "]"); 2553 }); 2554 $(this).data("number", cat_i); 2555 } else { 2556 var prev_category_number = $(this) 2557 .prevAll(".pricing-submenu") 2558 .first() 2559 .data("number"); 2560 if (typeof prev_category_number === "undefined") { 2561 prev_category_number = 0; 2562 } 2563 var subcat_input = $(this).find("input"); 2564 2565 subcat_input.each(function () { 2566 // replace 1st number with current category title number 2567 this.name = this.name.replace( 2568 /\[\d+\]/, 2569 "[" + prev_category_number + "]" 2570 ); 2571 this.name = replaceLast( 2572 this.name, 2573 "[" + prev_data_iterator + "]", 2574 "[" + subcat_i + "]" 2575 ); 2576 }); 2577 var subcat_select = $(this).find("select"); 2578 2579 subcat_select.each(function () { 2580 // replace 1st number with current category title number 2581 this.name = this.name.replace( 2582 /\[\d+\]/, 2583 "[" + prev_category_number + "]" 2584 ); 2585 this.name = replaceLast( 2586 this.name, 2587 "[" + prev_data_iterator + "]", 2588 "[" + subcat_i + "]" 2589 ); 2590 }); 2591 $(this).data("iterator", subcat_i); 2592 subcat_i++; 2593 } 2594 2595 if ($(this).hasClass("pricing-submenu")) { 2596 cat_i++; 2597 subcat_i = 0; 2598 } 2599 // $inp.each(function () { 2600 // this.name = this.name.replace(/(\[\d\])/, '[' + idx + ']'); 2601 // }) 2602 }); 2603 } 2604 2605 // Unit character 2606 var fieldUnit = $(".pricing-price").children("input").attr("data-unit"); 2607 $(".pricing-price") 2608 .children("input") 2609 .before('<i class="data-unit">' + fieldUnit + "</i>"); 2610 2611 // Unit character 2612 2613 if ( 2614 $("body").hasClass("page-template-template-home-search-splash") || 2615 $("body").hasClass("page-template-template-home-search") || 2616 $("body").hasClass("page-template-template-split-map") 2617 ) { 2618 var open_cal = "right"; 2619 } else { 2620 var open_cal = "left"; 2621 } 2622 2623 $(".add-repeatable-list-item").on("click", function (e) { 2624 e.preventDefault(); 2625 newRepeatableItem($(this)); 2626 }); 2627 2628 // remove ingredient 2629 $(document).on("click", "#repeatable-list-container .delete", function (e) { 2630 e.preventDefault(); 2631 $(this).parent().parent().remove(); 2632 }); 2633 2634 function newRepeatableItem(el) { 2635 var newElem = el.parent().find(".repeatable-list-item").last().clone(true); 2636 var appendTo = el.parent().find("table"); 2637 newElem.find("input").val(""); 2638 console.log(appendTo); 2639 var prev_data_iterator = el 2640 .parent() 2641 .find(".repeatable-list-item") 2642 .last() 2643 .data("iterator"); 2644 2645 var next_data_iterator = prev_data_iterator + 1; 2646 2647 newElem.find("input").each(function () { 2648 // replace 1st number with current category title number 2649 2650 this.name = this.name.replace(/\[\d+\]/, "[" + next_data_iterator + "]"); 2651 this.id = this.id.replace(/\[\d+\]/, "[" + next_data_iterator + "]"); 2652 }); 2653 newElem.find("select").each(function () { 2654 this.name = this.name.replace(/\[\d+\]/, "[" + next_data_iterator + "]"); 2655 this.id = this.id.replace(/\[\d+\]/, "[" + next_data_iterator + "]"); 2656 }); 2657 newElem.find("textarea").each(function () { 2658 this.name = this.name.replace(/\[\d+\]/, "[" + next_data_iterator + "]"); 2659 this.id = this.id.replace(/\[\d+\]/, "[" + next_data_iterator + "]"); 2660 }); 2661 newElem 2662 .appendTo(appendTo) 2663 .removeClass("pattern") 2664 .data("iterator", next_data_iterator); 2665 } 2666 2667 // loop all .fm-input and check if it has data-unit attribute 2668 $(".repeatable-list-item .fm-input").each(function () { 2669 var repeatableFieldUnit = $(this).children("input").data("unit"); 2670 if (repeatableFieldUnit) 2671 $(this) 2672 .children("input") 2673 .before('<i class="data-unit">' + repeatableFieldUnit + "</i>"); 2674 }); 2675 2676 // var repeatableFieldUnit = $(".repeatable-list-item .fm-input input").data("unit"); 2677 // console.log($(".repeatable-list-item .fm-input input").data("unit")); 2678 // if (repeatableFieldUnit) 2679 // $(".repeatable-list-item .fm-input") 2680 // .children("input") 2681 // .before('<i class="data-unit">' + repeatableFieldUnit + "</i>"); 2682 2683 $(".date_range").daterangepicker({ 2684 opens: open_cal, 2685 // checking attribute listing type and set type of calendar 2686 autoUpdateInput: false, 2687 2688 minDate: moment().subtract(0, "days"), 2689 locale: { 2690 format: wordpress_date_format.date, 2691 firstDay: parseInt(wordpress_date_format.day), 2692 applyLabel: listeo_core.applyLabel, 2693 cancelLabel: listeo_core.clearLabel, 2694 fromLabel: listeo_core.fromLabel, 2695 toLabel: listeo_core.toLabel, 2696 customRangeLabel: listeo_core.customRangeLabel, 2697 daysOfWeek: [ 2698 listeo_core.day_short_su, 2699 listeo_core.day_short_mo, 2700 listeo_core.day_short_tu, 2701
2701 listeo_core.day_short_we, 2702 listeo_core.day_short_th, 2703 listeo_core.day_short_fr, 2704 listeo_core.day_short_sa, 2705 ], 2706 monthNames: [ 2707 listeo_core.january, 2708 listeo_core.february, 2709 listeo_core.march, 2710 listeo_core.april, 2711 listeo_core.may, 2712 listeo_core.june, 2713 listeo_core.july, 2714 listeo_core.august, 2715 listeo_core.september, 2716 listeo_core.october, 2717 listeo_core.november, 2718 listeo_core.december, 2719 ], 2720 }, 2721 }); 2722 2723 $(".date_range").on("apply.daterangepicker", function (ev, picker) { 2724 $("input[name=_listing_type]").prop("disabled", false); 2725 $(this) 2726 .val( 2727 picker.startDate.format(wordpress_date_format.date) + 2728 " - " + 2729 picker.endDate.format(wordpress_date_format.date) 2730 ) 2731 .trigger("change"); 2732 Cookies.set( 2733 "listeo_rental_startdate", 2734 picker.startDate.format(wordpress_date_format.date) 2735 ); 2736 Cookies.set( 2737 "listeo_rental_enddate", 2738 picker.endDate.format(wordpress_date_format.date) 2739 ); 2740 }); 2741 2742 $(".date_range").on("cancel.daterangepicker", function (ev, picker) { 2743 $("input[name=_listing_type]").prop("disabled", true); 2744 $(this).val("").trigger("change"); 2745 }); 2746 2747 $(".date_range").on("show.daterangepicker", function (ev, picker) { 2748 $(".daterangepicker").addClass( 2749 "calendar-visible calendar-animated bordered-alt-style" 2750 ); 2751 $(".daterangepicker").removeClass("calendar-hidden"); 2752 $("input[name=_listing_type]").prop("disabled", false); 2753 }); 2754 $(".date_range").on("hide.daterangepicker", function (ev, picker) { 2755 $(".daterangepicker").removeClass("calendar-visible"); 2756 $(".daterangepicker").addClass("calendar-hidden"); 2757 }); 2758 2759 $("input.slot-time-input") 2760 .keydown(function (e) { 2761 if (e.ctrlKey || e.metaKey) { 2762 return true; 2763 } 2764 2765 if (e.which >= 37 && e.which <= 40) { 2766 return true; 2767 } 2768 2769 if (e.which !== 8 && e.which !== 0 && e.key.match(/[^:0-9]/)) { 2770 return false; 2771 } 2772 }) 2773 .keyup(function (e) { 2774 var $this = $(this); 2775 2776 if ( 2777 e.ctrlKey || 2778 e.metaKey || 2779 e.which === 8 || 2780 e.which === 0 || 2781 (e.which >= 37 && e.which <= 40) 2782 ) { 2783 return true; 2784 } 2785 2786 var ss = parseInt(this.selectionStart); 2787 2788 var v = $this.val(); 2789 var t = v.replace(/[^0-9]/g, ""); 2790 if ($(".availability-slots").attr("data-clock-type") == "24hr") { 2791 var h = Math.max(0, Math.min(24, parseInt(t.substr(0, 2)))); 2792 } else { 2793 var h = Math.max(0, Math.min(12, parseInt(t.substr(0, 2)))); 2794 } 2795 var m = Math.max(0, Math.min(59, parseInt(t.substr(2)))); 2796 2797 if (t.length < 3) { 2798 m = ""; 2799 } 2800 2801 var r; 2802 2803 if (v.length === 2) { 2804 r = String("0" + h).substr(String(h).length - 1) + ":"; 2805 ss++; 2806 } else if (v.length >= 3 && v.length < 5) { 2807 r = String("0" + h).substr(String(h).length - 1) + ":" + m; 2808 ss++; 2809 } else if (v.length === 5) { 2810 r = 2811 String("0" + h).substr(String(h).length - 1) + 2812 ":" + 2813 String("0" + m).substr(String(m).length - 1); 2814 } 2815 2816 if (r && r !== $this.val()) { 2817 $this.val(r); 2818 this.selectionStart = this.selectionEnd = ss; 2819 } 2820 }) 2821 .blur(function (e) { 2822 var $this = $(this); 2823 2824 var v = $this.val(); 2825 var t = v.replace(/[^0-9]/g, ""); 2826 var h = Math.max(0, Math.min(23, parseInt(t.substr(0, 2)))); 2827 var m = Math.max(0, Math.min(59, parseInt(t.substr(2)))) || 0; 2828 var r = ""; 2829 2830 if (!isNaN(h)) { 2831 r = 2832 String("0" + h).substr(String(h).length - 1) + 2833 ":" + 2834 String("0" + m).substr(String(m).length - 1); 2835 } 2836 2837 $this.val(r); 2838 }); 2839 2840 $(document.body).on("click", ".remove-uploaded-file", function () { 2841 $(this).closest(".job-manager-uploaded-file").remove(); 2842 $(this).closest(".listeo-uploaded-file").remove(); 2843 2844 return false; 2845 }); 2846 2847 //select export ical 2848 // 2849 $("input.listeo-export-ical-input").blur(function () { 2850 if ($(this).attr("data-selected-all")) { 2851 //Remove atribute to allow select all again on focus 2852 $(this).removeAttr("data-selected-all"); 2853 } 2854 }); 2855 2856 $("input.listeo-export-ical-input").click(function () { 2857 if (!$(this).attr("data-selected-all")) {
2858 try { 2859 $(this).selectionStart = 0; 2860 $(this).selectionEnd = $(this).value.length + 1; 2861 //add atribute allowing normal selecting post focus 2862 $(this).attr("data-selected-all", true); 2863 } catch (err) { 2864 $(this).select(); 2865 //add atribute allowing normal selecting post focus 2866 $(this).attr("data-selected-all", true); 2867 } 2868 } 2869 }); 2870 2871 function updateDashboardChart(params) { 2872 console.log($("#chart-date-range").data("daterangepicker")); 2873 var startDataSql = moment( 2874 $("#chart-date-range").data("daterangepicker").startDate, 2875 ["MM/DD/YYYY"] 2876 ).format("YYYY-MM-DD"); 2877 2878 var endDataSql = moment( 2879 $("#chart-date-range").data("daterangepicker").endDate, 2880 ["MM/DD/YYYY"] 2881 ).format("YYYY-MM-DD"); 2882 2883 var listing_id = $("#listing_id").val(); 2884 var stat_type = $("#stat_type").val(); 2885 2886 var ajax_data = { 2887 action: "listeo_chart_refresh", 2888 date_start: startDataSql, 2889 date_end: endDataSql, 2890 listing: listing_id, 2891 stat_type: stat_type, 2892 2893 //'nonce': nonce 2894 }; 2895 2896 $.ajax({ 2897 type: "POST", 2898 dataType: "json", 2899 url: listeo.ajaxurl, 2900 data: ajax_data, 2901 2902 success: function (data) { 2903 // loader clas 2904 2905 let labels = new Array(); 2906 Object.keys(data.labels).forEach((key) => { 2907 labels.push(data.labels[key]); 2908 }); 2909 chart.data.labels = labels; 2910 2911 let postdata = new Array(); 2912 Object.keys(data.data).forEach((key) => { 2913 postdata.push(data.data[key]); 2914 }); 2915 console.log(postdata); 2916 chart.data.datasets = postdata; 2917 2918 chart.update(); 2919 }, 2920 }); 2921 } 2922 2923 if ($("#chart-date-range").length) { 2924 var start = moment().subtract(6, "days"); 2925 var end = moment(); 2926 2927 function cb(start, end) { 2928 $("#chart-date-range span").html( 2929 start.format("MMMM D, YYYY") + " - " + end.format("MMMM D, YYYY") 2930 ); 2931 } 2932 2933 var ranges = new Object(); 2934 ranges[listeo_core.today] = [moment().subtract(1, "days"), moment()]; 2935 ranges[listeo_core.yesterday] = [ 2936 moment().subtract(1, "days"), 2937 moment().subtract(1, "days"), 2938 ]; 2939 ranges[listeo_core.last_7_days] = [moment().subtract(6, "days"), moment()]; 2940 ranges[listeo_core.last_30_days] = [ 2941 moment().subtract(29, "days"), 2942 moment(), 2943 ]; 2944 ranges[listeo_core.this_month] = [ 2945 moment().startOf("month"), 2946 moment().endOf("month"), 2947 ]; 2948 ranges[listeo_core.last_month] = [ 2949 moment().subtract(1, "month").startOf("month"), 2950 moment().subtract(1, "month").endOf("month"), 2951 ]; 2952 2953 cb(start, end); 2954 2955 // $("#chart-date-range-enabler").on("click", function (e) { 2956 // e.preventDefault(); 2957 // $(this).hide(); 2958 // cb(start, end); 2959 $("#chart-date-range") 2960 .show() 2961 .daterangepicker( 2962 { 2963 opens: "left", 2964 autoUpdateInput: false, 2965 alwaysShowCalendars: true, 2966 startDate: start, 2967 endDate: end, 2968 ranges: ranges, 2969 locale: { 2970 format: wordpress_date_format.date, 2971 firstDay: parseInt(wordpress_date_format.day), 2972 applyLabel: listeo_core.applyLabel, 2973 cancelLabel: listeo_core.cancelLabel, 2974 fromLabel: listeo_core.fromLabel, 2975 toLabel: listeo_core.toLabel, 2976 customRangeLabel: listeo_core.customRangeLabel, 2977 daysOfWeek: [ 2978 listeo_core.day_short_su, 2979 listeo_core.day_short_mo, 2980 listeo_core.day_short_tu, 2981 listeo_core.day_short_we, 2982 listeo_core.day_short_th, 2983 listeo_core.day_short_fr, 2984 listeo_core.day_short_sa, 2985 ], 2986 monthNames: [ 2987 listeo_core.january, 2988 listeo_core.february, 2989 listeo_core.march, 2990 listeo_core.april, 2991 listeo_core.may, 2992 listeo_core.june, 2993 listeo_core.july, 2994 listeo_core.august, 2995 listeo_core.september, 2996 listeo_core.october, 2997 listeo_core.november, 2998 listeo_core.december, 2999 ], 3000 }, 3001 }, 3002 cb 3003 ); 3004 3005 cb(start, end); 3006 // }); 3007 3008 // Calendar animation and visual settings
3009 $("#chart-date-range").on("show.daterangepicker", function (ev, picker) { 3010 $(".daterangepicker").addClass( 3011 "calendar-visible calendar-animated bordered-style" 3012 ); 3013 $(".daterangepicker").removeClass("calendar-hidden"); 3014 }); 3015 $("#chart-date-range").on("hide.daterangepicker", function (ev, picker) { 3016 $(".daterangepicker").removeClass("calendar-visible"); 3017 $(".daterangepicker").addClass("calendar-hidden"); 3018 }); 3019 } 3020 3021 // hooks for get bookings into view 3022 $("#chart-date-range").on("apply.daterangepicker", function (e) { 3023 updateDashboardChart(); 3024 }); 3025 3026 $(".dashboard-chart-full #listing_id").on("change", function (e) { 3027 updateDashboardChart(); 3028 }); 3029 $(".dashboard-chart-full #stat_type").on("change", function (e) { 3030 updateDashboardChart(); 3031 }); 3032 3033 $(".listeo-create-stripe-express-link-account").on("click", function (e) { 3034 e.preventDefault(); 3035 var $this = $(this); 3036 $(this).addClass("loading"); 3037 $.ajax({ 3038 type: "POST", 3039 dataType: "json", 3040 url: listeo.ajaxurl, 3041 data: { 3042 action: "create_express_stripe_account", 3043 }, 3044 success: function (data) { 3045 if (data.success) { 3046 get_listeo_stripe_account_link(); 3047 } else { 3048 $this.removeClass("loading"); 3049 $this.after("<p>" + data.data + "</p>"); 3050 } 3051 }, 3052 }); 3053 }); 3054 3055 function get_listeo_stripe_account_link() { 3056 $.ajax({ 3057 type: "POST", 3058 dataType: "json", 3059 url: listeo.ajaxurl, 3060 data: { 3061 action: "get_express_stripe_account_link", 3062 }, 3063 success: function (data) { 3064 if (data.success) { 3065 $(".listeo-create-stripe-express-link-account").hide(); 3066 $(".real-conntect-w-stripe-btn").attr("href", data.data).show(); 3067 } else { 3068 $(".listeo-create-stripe-express-link-account").removeClass( 3069 "loading" 3070 ); 3071 $(".listeo-create-stripe-express-link-account").after( 3072 "<p>" + data.data + "</p>" 3073 ); 3074 } 3075 }, 3076 }); 3077 } 3078 3079 // claim listing 3080 3081 $("#claim-listing-form").on("submit", function (e) { 3082 $("#claim-dialog button").addClass("loading").prop("disabled", true); 3083 3084 var form = $("#claim-listing-form")[0]; // Get the DOM element of the form 3085 var formData = new FormData(form); 3086 3087 // check if required fields are filled 3088 var required_fields = true; 3089 $("#claim-listing-form .required").each(function () { 3090 if (!$(this).val()) { 3091 required_fields = false; 3092 $(this).addClass("error"); 3093 } 3094 }); 3095 // if required fields are not filled 3096 if (!required_fields) { 3097 $("#claim-dialog button").removeClass("loading").prop("disabled", false); 3098 $("#claim-dialog .notification") 3099 .removeClass("success") 3100 .addClass("error") 3101 .show() 3102 .html(listeo_core.required_fields); 3103 e.preventDefault(); 3104 return false; 3105 } 3106 3107 $.ajax({ 3108 type: "POST", 3109 dataType: "json", 3110 url: listeo_core.ajax_url, 3111 data: formData, 3112 processData: false, // Set processData to false to prevent jQuery from automatically convert
3112ing the data to a string 3113 contentType: false, // Set contentType to false, so jQuery does not set the Content-Type header 3114 success: function (data) { 3115 if (data.success) { 3116 // if data has a value payment and it's not empty 3117 if (data.payment_url && data.payment_url !== "") { 3118 //scroll to top 3119 $("html, body").animate({ scrollTop: 0 }, "slow"); 3120 $("#claim-dialog button") 3121 .removeClass("loading") 3122 .prop("disabled", false); 3123 $("#claim-dialog form").hide(); 3124 $(".claim-listing-pay-button") 3125 .attr("href", data.payment_url) 3126 .show(); 3127 $(".claim-confirmation-box").show(); 3128 3129 // window.location.href = data.payment; 3130 } else { 3131 $("#claim-listing-form .required").each(function () { 3132 $(this).removeClass("error"); 3133 }); 3134 $("#claim-dialog button").removeClass("loading"); 3135 $("#claim-dialog .notification") 3136 .removeClass("error") 3137 .addClass("success") 3138 .show() 3139 .html(data.message); 3140 window.setTimeout(closepopup, 3000); 3141 $(".claim-listing-button span").text(data.button_text); 3142 $(".claim-listing-button").removeClass("popup-with-zoom-anim"); 3143 if (data.reload && listeo_core.autologin) { 3144 setTimeout(function () { 3145 window.location.reload(); // you can pass true to reload function to ignore the client cache and reload from the server 3146 }, 2000); 3147 } 3148 } 3149 } else { 3150 $("#claim-dialog .notification") 3151 .removeClass("success") 3152 .addClass("error") 3153 .show() 3154 .html(data.message); 3155 $("#claim-dialog button") 3156 .removeClass("loading") 3157 .prop("disabled", false); 3158 } 3159 }, 3160 }); 3161 e.preventDefault(); 3162 }); 3163 3164 // review validation 3165 $(".add-sub-rating").each(function () { 3166 const ratingName = $(this).find('input[type="radio"]').first().attr("name"); 3167 $(this).append(`<input type="text" 3168 class="rating-validator" 3169 style="position: absolute; opacity: 0; pointer-events: none;" 3170 name="validate_${ratingName}" 3171 required 3172 data-rating-group="${ratingName}">`); 3173 }); 3174 3175 // Update validator input when stars are clicked 3176 $('.leave-rating input[type="radio"]').on("change", function () { 3177 const ratingGroup = $(this).attr("name"); 3178 const validator = $(`input[data-rating-group="${ratingGroup}"]`); 3179 validator.val($(this).val()); 3180 3181 // Remove error styling if present 3182 $(this).closest(".add-sub-rating").removeClass("rating-validation-error"); 3183 $(this).closest(".add-sub-rating").find(".rating-error-message").hide(); 3184 }); 3185 3186 // Handle form submission 3187 $("#commentform").on("submit", function (e) { 3188 let isValid = true; 3189 let firstError = null; 3190 3191 $(".add-sub-rating").each(function () { 3192 const ratingGroup = $(this); 3193 const hasRating = 3194 ratingGroup.find('input[type="radio"]:checked').length > 0; 3195 3196 if (!hasRating) { 3197 isValid = false; 3198 ratingGroup.addClass("rating-validation-error"); 3199 ratingGroup.find(".rating-error-message").show(); 3200 3201 if (!firstError) { 3202 firstError = ratingGroup; 3203 } 3204 } 3205 }); 3206 3207 if (!isValid) { 3208 e.preventDefault(); 3209 if (firstError) { 3210 $("html, body").animate( 3211 { 3212 scrollTop: firstError.offset().top - 100, 3213 }, 3214 500 3215 ); 3216 } 3217 } 3218 }); 3219 // ------------------ End Document ------------------ // 3220}); 3221 3222})(this.jQuery); 3223/**/
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.