Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 4.87 KB | None | 0 0
  1. $(document).off('click', '.btn-proceed, .btn-proceed-in-room-box');
  2. $(document).on('click', '.btn-proceed, .btn-proceed-in-room-box', function (e) {
  3.  
  4.  
  5.     saveModalInputs();
  6.  
  7.     e.preventDefault();
  8.     if (typeof ajaxInProgress != 'undefined' && ajaxInProgress) {
  9.         return;
  10.     }
  11.  
  12.     submit = false;
  13.     var url = $(this).data('url');
  14.     if ($(this).data('form')) {
  15.         var objects = {};
  16.         var objectsType = {};
  17.         var promotionsForObjects = {};
  18.         var nonrefundable = {};
  19.         form_obj = $($(this).data('form'));
  20.         $.each(form_obj.find($(this).data("required")), function () {
  21.             if ($(this).data('object_id') && $(this).attr('data-quantity') > 0) {
  22.                 var qntVal = Number($(this).attr('data-quantity'));
  23.                 if (typeof objects[$(this).data('object_id')] === 'undefined') {
  24.                     objects[$(this).data('object_id')] = qntVal;
  25.                 } else {
  26.                     objects[$(this).data('object_id')] += qntVal;
  27.                 }
  28.                 if (typeof promotionsForObjects[$(this).data('object_id')] === 'undefined') {
  29.                     promotionsForObjects[$(this).data('object_id')] = [];
  30.                 }
  31.                 for (var i = 0; i < qntVal; i++) {
  32.                     //Dodajemy promocję tyle razy ile egzemplarzy zostało wybranych w tej promocji
  33.                     promotionsForObjects[$(this).data('object_id')].push($(this).data('promotion_id'));
  34.                 }
  35.                 if ($(this).data('nonrefundable')) {
  36.                     if (typeof nonrefundable[$(this).data('object_id')] === 'undefined') {
  37.                         nonrefundable[$(this).data('object_id')] = qntVal;
  38.                     } else {
  39.                         nonrefundable[$(this).data('object_id')] += qntVal;
  40.                     }
  41.                 }
  42.                 objectsType[$(this).data('object_id')] = $(this).data('object_type');
  43.                 submit = true;
  44.  
  45.                 url += '&adult[' + $(this).data('object_id') + ']=' + $(this).attr('data-adult');
  46.                 url += '&childBig[' + $(this).data('object_id') + ']=' + $(this).attr('data-childBig');
  47.                 url += '&childSmall[' + $(this).data('object_id') + ']=' + $(this).attr('data-childSmall');
  48.             }
  49.         });
  50.         if (!$.isEmptyObject(objects)) {
  51.             $.each(objects, function (key, value) {
  52.                 if (objectsType[key] == 'offer') {
  53.                     url += '&offer[' + key + ']=' + value;
  54.                 } else {
  55.                     url += '&object[' + key + ']=' + value;
  56.                 }
  57.                 if (typeof promotionsForObjects[key] !== 'undefined') {
  58.                     url += '&promotion[' + key + ']=' + (promotionsForObjects[key]);
  59.                 }
  60.                 if (typeof nonrefundable[key] !== 'undefined') {
  61.                     url += '&nonrefundable[' + key + ']=' + (nonrefundable[key]);
  62.                 }
  63.             });
  64.         }
  65.     } else {
  66.         submit = true;
  67.     }
  68.     if (submit) {
  69.         ajaxInProgress = true;
  70.         url += '&setPersons=1';
  71.         app_booking.loadcenter({
  72.             url: url,
  73.             container: $('.center-section'),
  74.             callback: function () {
  75.                 app_center_booking.assign_roomClicks();
  76.                 app_center_booking.section_toggle($('.toggle'), 'add-options-more');
  77.                 ajaxInProgress = false;
  78.             }
  79.         });
  80.     } else {
  81.         app_booking.ajax_error_msg(TXT.form_room_error, 'red');
  82.         ajaxInProgress = false;
  83.     }
  84. });
  85.  
  86.  
  87. var saveModalInputs = function () {
  88.     var offers = $('#multi-dialog:visible .room-wrapper');
  89.     offers.each(function () {
  90.         saveInputs($(this).prev().data('element'), $(this));
  91.     });
  92. }
  93.  
  94.  
  95. var saveInputs = function (target, inputWrapper) {
  96.     var input;
  97.  
  98.     if (typeof target == "undefined" || target == null) {
  99.         input = roomPersonInput;
  100.     } else {
  101.         input = target;
  102.     }
  103.  
  104.     input.closest('section').addClass('active');
  105.  
  106.     var adult = [];
  107.     var childBig = [];
  108.     var childSmall = [];
  109.     var capacity = 0;
  110.  
  111.     inputWrapper.find('.room').each(function () {
  112.         adult.push($(this).find('input[name="persons[adult]"]').val());
  113.         childBig.push($(this).find('input[name="persons[childBig]"]').val());
  114.         childSmall.push($(this).find('input[name="persons[childSmall]"]').val());
  115.         capacity += parseInt($(this).find('input[name="persons[adult]"]').val()) + parseInt($(this).find('input[name="persons[childBig]"]').val());
  116.     });
  117.  
  118.     input.attr('data-quantity', inputWrapper.find('.room').length);
  119.     input.attr('data-adult', adult.toString());
  120.     input.attr('data-childBig', childBig.toString());
  121.     input.attr('data-childSmall', childSmall.toString());
  122.     input.attr('data-capacity', capacity);
  123.  
  124.     setFilterTop();
  125.     app_booking.removeModal();
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement