the bola v2 website
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import AOS from "aos";
  2. import jQuery from "jquery";
  3. import API from './api/api';
  4. const $ = jQuery;
  5. const api = new API();
  6. var bookingRules = [];
  7. setTimeout(() => {
  8. console.log("AOS init");
  9. AOS.init();
  10. }, 500);
  11. $(document).ready(function () {
  12. $('.article-carousel-item').on('click', function(){
  13. let redirectlink = $(this).data('href')
  14. location.href = redirectlink;
  15. })
  16. $('#contact-form').on('submit', function(e){
  17. e.preventDefault();
  18. let name = $(this).find("#name").val();
  19. let email = $(this).find("#email").val();
  20. let message = $(this).find("#message").val();
  21. let submitButton = $(this).find('#submitButton');
  22. let loadingSpan = document.createElement('span');
  23. $(submitButton).prop("disabled",true);
  24. $(loadingSpan).attr("role", "status");
  25. $(loadingSpan).attr("aria-hidden", "true");
  26. $(loadingSpan).addClass("spinner-border spinner-border-sm");
  27. submitButton.text("Sending ");
  28. $(submitButton).append(loadingSpan)
  29. const _callback = (resp) => {
  30. let {status} = resp
  31. if(status === "Success"){
  32. submitButton.text("Success");
  33. $("#name").val("");
  34. $("#email").val("");
  35. $("#message").val("");
  36. } else {
  37. submitButton.text("Fail");
  38. }
  39. setTimeout(()=>{
  40. $(submitButton).prop("disabled",false);
  41. submitButton.text("Submit");
  42. },1000)
  43. }
  44. api.enquiry({name, email, message}, _callback)
  45. })
  46. // this section is for booking page
  47. //check if booking section exist in any page
  48. let bookingContainer = $('#booking-section');
  49. if(bookingContainer.length > 0){
  50. api.listState({
  51. _callback: ({state_city}) => {
  52. const selectLocationInput = $("#select-location");
  53. if(Array.isArray(state_city)){
  54. state_city.forEach(({state, city}, i) => {
  55. let newOption = document.createElement('option');
  56. $(newOption).attr("id", `location_${i}`)
  57. $(newOption).attr("value",JSON.stringify({state,city}))
  58. $(newOption).addClass("select-value")
  59. newOption.text = `${city}, ${state}`
  60. $(selectLocationInput).append(newOption)
  61. });
  62. }
  63. $(selectLocationInput).on('change', ()=>{
  64. resetField()
  65. })
  66. }
  67. })
  68. // set date max and min
  69. let { maxDate, minDate } = createDateInputWithRange(14)
  70. let inputDate = $('#input-booking-date')
  71. $(inputDate).attr("min", minDate)
  72. $(inputDate).attr("max", maxDate)
  73. resetDate()
  74. }
  75. $("#booknow-btn").on('click', function(){
  76. document.getElementById("download-container").scrollIntoView();
  77. })
  78. $("#select-location").on('change', function(){
  79. resetDate()
  80. resetRules()
  81. resetField()
  82. $("#select-location").children("#default-input-select-location").remove()
  83. setTimeout(() => {
  84. document.getElementById("field-location-container").scrollIntoView({ behavior: "smooth", block: "end", inline: "end" });
  85. }, 300);
  86. if(this.value !== "default" ){
  87. let {state, city} = JSON.parse(this.value);
  88. api.listLocation({
  89. state,
  90. city,
  91. _callback: ({field_location}) => {
  92. let template = $('#field-location-template')
  93. let container = $(template).parent()
  94. //reset eveything
  95. $(container).children(".select-field").remove()
  96. try{
  97. field_location.forEach(({field_name, city, state, photo_path}) => {
  98. let newField = $(template).clone()
  99. $(newField).css('display','block')
  100. $(newField).removeAttr("id")
  101. $(newField).addClass("select-field")
  102. $(newField).find('.field-location-text').text("")
  103. $(newField).on('click', ()=>{ handleClickFieldLocation(city, state, field_name, newField) })
  104. $(newField).find('.field-location-img').attr("style", `background-image:url(https://thebola.club/files/${photo_path})`)
  105. $(container).append(newField)
  106. });
  107. }catch(err){
  108. console.log(err)
  109. }
  110. },
  111. });
  112. }
  113. })
  114. const handleClickFieldLocation = function (city, state, field_name, refElem) {
  115. $("#field-location-container").find(".select-field").removeClass("active")
  116. $(refElem).addClass("active")
  117. resetDate()
  118. resetRules()
  119. resetField()
  120. setTimeout(() => {
  121. document.getElementById("field-container").scrollIntoView();
  122. }, 300);
  123. api.listField({state, city, field_name, _callback:({results})=>{
  124. let container = $('#field-container')
  125. let template = $('#field-template')
  126. try{
  127. results.forEach(({location_name, photo_path, slot_rules}) => {
  128. let newField = $(template).clone()
  129. $(newField).css('display','block')
  130. $(newField).removeAttr("id")
  131. $(newField).addClass("select-field")
  132. $(newField).find('.field-text').text(location_name)
  133. $(newField).on('click', ()=>{ handleClickField(slot_rules, newField)})
  134. $(newField).find('.field-img').attr("style", `background-image:url(https://thebola.club/files/${photo_path})`)
  135. $(container).append(newField)
  136. });
  137. }catch(err){
  138. console.log(err)
  139. }
  140. }})
  141. }
  142. const handleClickField = function (slot_rules,refElem){
  143. // remove all child active class, then add active on clicked
  144. let fieldContainer = $('#field-container');
  145. $(fieldContainer).find(".select-field").removeClass("active")
  146. $(refElem).addClass("active");
  147. resetRules()
  148. resetDate()
  149. bookingRules = slot_rules.rules
  150. }
  151. $('#input-booking-date').change(function() {
  152. if(bookingRules){
  153. // render rule of slot base on current input value date
  154. var dayName = getDayNameFromInput(document.getElementById("input-booking-date"));
  155. resetRules()
  156. setTimeout(() => {
  157. // append slot list
  158. bookingRules[dayName].forEach(({end_time, start_time, price, id}) => {
  159. let newOption = document.createElement('option');
  160. $(newOption).attr("id", id)
  161. $(newOption).addClass("select-value")
  162. newOption.text = `${start_time} - ${end_time} (RM ${price})`
  163. $("#input-booking-slot").append(newOption)
  164. });
  165. }, 1000);
  166. }
  167. });
  168. function createDateInputWithRange(days) {
  169. var today = new Date();
  170. var futureDate = new Date(today.getTime() + days * 24 * 60 * 60 * 1000);
  171. var maxDate = futureDate.toISOString().split('T')[0];
  172. let minDate = today.toISOString().split('T')[0];
  173. return { maxDate, minDate };
  174. }
  175. function getDayNameFromInput(inputElement) {
  176. var selectedDate = inputElement.value;
  177. var date = new Date(selectedDate);
  178. var dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  179. var dayIndex = date.getDay();
  180. return dayNames[dayIndex];
  181. }
  182. function resetField(){
  183. $('#field-container').children(".select-field").remove()
  184. }
  185. function resetDate(){
  186. let { maxDate, minDate } = createDateInputWithRange(14)
  187. $('#input-booking-date').val(minDate)
  188. }
  189. function resetRules(){
  190. $("#input-booking-slot").children(".select-value").remove();
  191. }
  192. });