Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).off('click', '.btn-proceed, .btn-proceed-in-room-box');
- $(document).on('click', '.btn-proceed, .btn-proceed-in-room-box', function (e) {
- saveModalInputs();
- e.preventDefault();
- if (typeof ajaxInProgress != 'undefined' && ajaxInProgress) {
- return;
- }
- submit = false;
- var url = $(this).data('url');
- if ($(this).data('form')) {
- var objects = {};
- var objectsType = {};
- var promotionsForObjects = {};
- var nonrefundable = {};
- form_obj = $($(this).data('form'));
- $.each(form_obj.find($(this).data("required")), function () {
- if ($(this).data('object_id') && $(this).attr('data-quantity') > 0) {
- var qntVal = Number($(this).attr('data-quantity'));
- if (typeof objects[$(this).data('object_id')] === 'undefined') {
- objects[$(this).data('object_id')] = qntVal;
- } else {
- objects[$(this).data('object_id')] += qntVal;
- }
- if (typeof promotionsForObjects[$(this).data('object_id')] === 'undefined') {
- promotionsForObjects[$(this).data('object_id')] = [];
- }
- for (var i = 0; i < qntVal; i++) {
- //Dodajemy promocję tyle razy ile egzemplarzy zostało wybranych w tej promocji
- promotionsForObjects[$(this).data('object_id')].push($(this).data('promotion_id'));
- }
- if ($(this).data('nonrefundable')) {
- if (typeof nonrefundable[$(this).data('object_id')] === 'undefined') {
- nonrefundable[$(this).data('object_id')] = qntVal;
- } else {
- nonrefundable[$(this).data('object_id')] += qntVal;
- }
- }
- objectsType[$(this).data('object_id')] = $(this).data('object_type');
- submit = true;
- url += '&adult[' + $(this).data('object_id') + ']=' + $(this).attr('data-adult');
- url += '&childBig[' + $(this).data('object_id') + ']=' + $(this).attr('data-childBig');
- url += '&childSmall[' + $(this).data('object_id') + ']=' + $(this).attr('data-childSmall');
- }
- });
- if (!$.isEmptyObject(objects)) {
- $.each(objects, function (key, value) {
- if (objectsType[key] == 'offer') {
- url += '&offer[' + key + ']=' + value;
- } else {
- url += '&object[' + key + ']=' + value;
- }
- if (typeof promotionsForObjects[key] !== 'undefined') {
- url += '&promotion[' + key + ']=' + (promotionsForObjects[key]);
- }
- if (typeof nonrefundable[key] !== 'undefined') {
- url += '&nonrefundable[' + key + ']=' + (nonrefundable[key]);
- }
- });
- }
- } else {
- submit = true;
- }
- if (submit) {
- ajaxInProgress = true;
- url += '&setPersons=1';
- app_booking.loadcenter({
- url: url,
- container: $('.center-section'),
- callback: function () {
- app_center_booking.assign_roomClicks();
- app_center_booking.section_toggle($('.toggle'), 'add-options-more');
- ajaxInProgress = false;
- }
- });
- } else {
- app_booking.ajax_error_msg(TXT.form_room_error, 'red');
- ajaxInProgress = false;
- }
- });
- var saveModalInputs = function () {
- var offers = $('#multi-dialog:visible .room-wrapper');
- offers.each(function () {
- saveInputs($(this).prev().data('element'), $(this));
- });
- }
- var saveInputs = function (target, inputWrapper) {
- var input;
- if (typeof target == "undefined" || target == null) {
- input = roomPersonInput;
- } else {
- input = target;
- }
- input.closest('section').addClass('active');
- var adult = [];
- var childBig = [];
- var childSmall = [];
- var capacity = 0;
- inputWrapper.find('.room').each(function () {
- adult.push($(this).find('input[name="persons[adult]"]').val());
- childBig.push($(this).find('input[name="persons[childBig]"]').val());
- childSmall.push($(this).find('input[name="persons[childSmall]"]').val());
- capacity += parseInt($(this).find('input[name="persons[adult]"]').val()) + parseInt($(this).find('input[name="persons[childBig]"]').val());
- });
- input.attr('data-quantity', inputWrapper.find('.room').length);
- input.attr('data-adult', adult.toString());
- input.attr('data-childBig', childBig.toString());
- input.attr('data-childSmall', childSmall.toString());
- input.attr('data-capacity', capacity);
- setFilterTop();
- app_booking.removeModal();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement