Advertisement
Guest User

Untitled

a guest
Feb 14th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.32 KB | None | 0 0
  1. let BookingProcesss = {
  2. wrapper: "#check_availibility_control",
  3.  
  4. id: function(element) {
  5. return jQuery(this.wrapper).find("#" + element);
  6. },
  7. data: function(data) {
  8. return jQuery(this.wrapper).find("[" + data + "]");
  9. },
  10. occupents: function(
  11. caller,
  12. target,
  13. control,
  14. max_adults,
  15. max_children,
  16. child_min,
  17. child_max
  18. ) {
  19. let _this = this;
  20.  
  21. let the_rooms = _this.id(caller).val();
  22.  
  23. jQuery
  24. .ajax({
  25. url: s4aJSO.ajax_url,
  26. method: "POST",
  27. dataType: "json",
  28. data: {
  29. action: s4aJSO.the_unique_plugin_name + "-ajax-submit",
  30. cmd: "build_occupents_list",
  31. the_rooms: the_rooms,
  32. max_adults: max_adults,
  33. max_children: max_children,
  34. child_min: child_min,
  35. child_max: child_max
  36. }
  37. })
  38. .done(function(data) {
  39. if (!data.error) {
  40. _this.id(control).remove();
  41. _this.id(target).append(data.html_str);
  42. ScrollTo(jQuery(_this.id(target)), -235, 100);
  43. }
  44. })
  45. .fail(function() {})
  46. .always(function(data) {});
  47. },
  48. child_occupents: function(
  49. caller,
  50. the_room,
  51. target,
  52. control,
  53. child_min,
  54. child_max
  55. ) {
  56. let _this = this;
  57.  
  58. let the_children = _this.id(caller).val();
  59.  
  60. jQuery
  61. .ajax({
  62. url: s4aJSO.ajax_url,
  63. method: "POST",
  64. dataType: "json",
  65. data: {
  66. action: s4aJSO.the_unique_plugin_name + "-ajax-submit",
  67. cmd: "build_child_occupents_list",
  68. the_room: the_room,
  69. the_children: the_children,
  70. child_min: child_min,
  71. child_max: child_max
  72. }
  73. })
  74. .done(function(data) {
  75. if (!data.error) {
  76. _this.id(control).remove();
  77. _this.id(target).append(data.html_str);
  78. }
  79. })
  80. .fail(function() {})
  81. .always(function(data) {});
  82. },
  83. form_fields: function() {
  84. let _this = this;
  85.  
  86. let listing_id = _this.data('data-field="id"').val();
  87. let establishment = _this.data('data-field="establishment"').val();
  88. let the_arrival_date = _this.data('data-field="the_arrival_date"').val();
  89. let the_departure_date = _this
  90. .data('data-field="the_departure_date"')
  91. .val();
  92.  
  93. let roomCount = _this.id("the_rooms").val();
  94.  
  95. let Units = {};
  96.  
  97. for (unitNumber = 1; unitNumber <= roomCount; unitNumber++) {
  98. let values = {};
  99.  
  100. values["adults"] = _this
  101. .data('data-room="' + unitNumber + '"')
  102. .find('[data-type="adult"]')
  103. .val();
  104.  
  105. let Children = {};
  106. let age = {};
  107. let childCount = _this
  108. .data('data-room="' + unitNumber + '"')
  109. .find('[data-type="child"]')
  110. .val();
  111.  
  112. for (childNumber = 1; childNumber <= childCount; childNumber++) {
  113. age[childNumber] = _this
  114. .data('data-room="' + unitNumber + '"')
  115. .find('[data-child="' + childNumber + '"]')
  116. .find('[data-type="age"]')
  117. .val();
  118. }
  119.  
  120. Children["age"] = age;
  121. values["Children"] = age;
  122. Units[unitNumber] = values;
  123. }
  124.  
  125. let result = {};
  126.  
  127. result["listing_id"] = listing_id;
  128. result["establishment"] = establishment;
  129. result["the_arrival_date"] = the_arrival_date;
  130. result["the_departure_date"] = the_departure_date;
  131. result["Units"] = Units;
  132.  
  133. return result;
  134. },
  135. reserve: function(rate_id, form, field) {
  136. let _this = this;
  137. let form_fields = _this.form_fields();
  138. let reserveForm = _this.id(form);
  139.  
  140.  
  141. form_fields["rate_id"] = rate_id;
  142.  
  143. _this.id(field).val(JSON.stringify(form_fields));
  144. jQuery("#s4a_loader").show();
  145. reserveForm.submit();
  146. },
  147. validateChildrenAgeSelection: function(units) {
  148. let size = Object.keys(units).length;
  149. let i;
  150. let foo = true;
  151.  
  152. for (i = 0; i < size; i++) {
  153. let index = i + 1;
  154. var children_obj = units[index]["Children"];
  155.  
  156. let children_arr = Object.keys(children_obj).map(function(key) {
  157. return [Number(key), children_obj[key]];
  158. });
  159. let arr_size = children_arr.length;
  160. if (arr_size > 0) {
  161. var x;
  162. for (x = 0; x < arr_size; x++) {
  163. if (
  164. children_arr[x][1] === "" ||
  165. children_arr[x][1] === undefined ||
  166. children_arr[x][1] === null
  167. ) {
  168. foo = false;
  169. break;
  170. }
  171. }
  172. }
  173. }
  174. return foo;
  175. },
  176. updateDate: function(startDate, endDate) {
  177. let _this = this;
  178. jQuery(".datepicker_checkin").val(startDate);
  179. jQuery(".datepicker_checkout").val(endDate);
  180. checkAvailibilty();
  181. jQuery("html, body").animate(
  182. {
  183. scrollTop: jQuery(_this.id("js_SearchForSpecials")).offset().top
  184. },
  185. 50
  186. );
  187. },
  188. get_available_rooms: function(caller, rooms, target, showValidate) {
  189.  
  190. if (showValidate == null) {
  191. showValidate = true;
  192. } else {
  193. showValidate = showValidate;
  194. }
  195.  
  196. let _this = this;
  197. let form_fields = _this.form_fields();
  198.  
  199. S4AValidation("null", jQuery(_this.id(caller)).find(".datepicker_checkin"));
  200. S4AValidation(
  201. "null",
  202. jQuery(_this.id(caller)).find("#datepicker_checkout")
  203. );
  204. jQuery(_this.id(caller))
  205. .find("input.s4a_val-error:first")
  206. .focus();
  207.  
  208. if (_this.validateChildrenAgeSelection(form_fields["Units"])) {
  209. if (jQuery("#select-alert").length > 0) {
  210. jQuery("#select-alert").remove();
  211. }
  212.  
  213. if (S4AValidationSucess(_this.id(caller))) {
  214. // _this.id(rooms).html('<hr/><div class="spinner"><div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div><div class="rect5"></div></div>');
  215.  
  216. jQuery("#s4a_loader").show();
  217.  
  218. jQuery
  219. .ajax({
  220. url: s4aJSO.ajax_url,
  221. method: "POST",
  222. dataType: "json",
  223. data: {
  224. action: s4aJSO.the_unique_plugin_name + "-ajax-submit",
  225. cmd: "get_available_rooms",
  226. listing_id: form_fields.listing_id,
  227. the_arrival_date: form_fields.the_arrival_date,
  228. the_departure_date: form_fields.the_departure_date,
  229. Units: form_fields.Units
  230. }
  231. })
  232. .done(function(data) {
  233. jQuery("#s4a_loader").hide();
  234. if (!data.error) {
  235. let local = data.html_str["ListingRooms"]["local"];
  236. let channel = data.html_str["ListingRooms"]["channel"];
  237.  
  238. if (channel) {
  239. _this.id(rooms).html(channel);
  240. } else {
  241. _this.id(rooms).html(local);
  242. }
  243. calenderStart();
  244. }
  245. })
  246. .fail(function() {
  247. jQuery("#s4a_loader").hide();
  248. })
  249. .always(function(data) {
  250. jQuery("#s4a_loader").hide();
  251. });
  252. } else if (!showValidate) {
  253. S4ARemoveValidation(
  254. jQuery(_this.id(caller)).find(".datepicker_checkin")
  255. );
  256. S4ARemoveValidation(
  257. jQuery(_this.id(caller)).find("#datepicker_checkout")
  258. );
  259. }
  260. } else {
  261. if (jQuery("#select-alert").length == 0) {
  262. jQuery(
  263. "<br><div id='select-alert' class='alert alert-info' role='alert'> Please select children(s) age to continue!</div>"
  264. ).insertAfter("#get_available_rooms");
  265. }
  266. }
  267. },
  268. check_coupon_code: function(caller, form, price, listingId, target) {
  269. /* jQuery('#'+caller + ' #apply_button').unbind('click');
  270. jQuery('#'+caller + ' #apply_button').off('click'); */
  271.  
  272. let code = jQuery("#" + caller)
  273. .find("#voucher_code")
  274. .val();
  275. if (code == "") return;
  276. jQuery("#" + caller + " #apply_button").attr("disabled", "disabled");
  277.  
  278. let email = jQuery("#" + form)
  279. .find(".s4a_val-user_email")
  280. .val();
  281. let flag = true;
  282. S4AValidation("null", jQuery(jQuery("#" + caller)).find("#voucher_code"));
  283.  
  284. if (S4AValidationSucess(jQuery("#" + caller)) && flag) {
  285. flag = false;
  286.  
  287. if (
  288. jQuery("#s4a_resevation").find(
  289. ".payment_details .amount_details tbody .discount"
  290. ).length == 0
  291. ) {
  292. jQuery
  293. .ajax({
  294. url: s4aJSO.ajax_url,
  295. method: "POST",
  296. dataType: "json",
  297. data: {
  298. action: s4aJSO.the_unique_plugin_name + "-ajax-submit",
  299. cmd: "check_coupon_code",
  300. price: price,
  301. code: code,
  302. email: email,
  303. listingId: listingId
  304. }
  305. })
  306. .done(function(data) {
  307. if (!data.error) {
  308. if (!data.html_str["error"]) {
  309. if (data.html_str["status"] == "Active") {
  310. jQuery("#" + form)
  311. .find(".promo_show")
  312. .show();
  313. jQuery("#" + form)
  314. .find(".exlcuding_message")
  315. .show();
  316.  
  317. $coupon_amount = data.html_str["coupon_amount"];
  318. $discount_type = data.html_str["discount_type"];
  319.  
  320. if ($discount_type == "Fixed Amount Discount") {
  321. jQuery("#" + form)
  322. .find(".promo_percent")
  323. .hide();
  324. jQuery("#" + form)
  325. .find(".promo_amount")
  326. .show();
  327. jQuery("#" + form)
  328. .find(".promo_amount .price_wrapper .value")
  329. .html($coupon_amount.toLocaleString());
  330. jQuery("#" + form)
  331. .find(".promo_amount .price_wrapper .value")
  332. .attr("data-value", $coupon_amount);
  333. } else if ($discount_type == "Percentage Discount") {
  334. jQuery("#" + form)
  335. .find(".promo_amount")
  336. .hide();
  337. jQuery("#" + form)
  338. .find(".promo_percent")
  339. .show();
  340. jQuery("#" + form)
  341. .find("#promo_percent")
  342. .html($coupon_amount.toLocaleString() + "%");
  343. }
  344.  
  345. jQuery("#" + caller)
  346. .find("#coupon_amount")
  347. .val(data.html_str["discount_amount"]);
  348. jQuery("#" + form)
  349. .find(".payment_details .amount_details tbody")
  350. .append(
  351. '<tr class="discount"><td>Discount: </td><td class="css_text_right"> -' +
  352. data.html_str["discount_amount"] +
  353. "</td></tr>"
  354. );
  355.  
  356. $total_amount = price - data.html_str["discount_amount"];
  357. jQuery("#" + form)
  358. .find(".res_total .price_wrapper .value")
  359. .html($total_amount.toLocaleString());
  360. jQuery("#" + form)
  361. .find(".res_total .price_wrapper .value")
  362. .attr("data-value", $total_amount);
  363.  
  364. alert("Promo code applied successfully!");
  365. } else {
  366. alert("Promo code is inactive!");
  367. jQuery(jQuery("#" + caller))
  368. .find("#voucher_code")
  369. .addClass("s4a_val-error");
  370. }
  371. } else {
  372. alert("Invalid promo code!");
  373. jQuery(jQuery("#" + caller))
  374. .find("#voucher_code")
  375. .addClass("s4a_val-error");
  376. }
  377. }
  378. })
  379. .fail(function() {})
  380. .always(function(data) {
  381. jQuery("#" + caller + " #apply_button").removeAttr("disabled");
  382. flag = true;
  383. });
  384. } else {
  385. // One coupon already applied
  386. flag = true;
  387. jQuery(jQuery("#" + caller))
  388. .find("#voucher_code")
  389. .addClass("s4a_val-warning");
  390. jQuery("#" + caller + " #apply_button").removeAttr("disabled");
  391. }
  392. } else {
  393. jQuery("#" + caller + " #apply_button").removeAttr("disabled");
  394. }
  395. }
  396. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement