$(document).ready(function() {
function createMap(seats_rows, seats_container) {
var $cart = $('#selected-seats');
var seat_selected = false;
seats_container.seatCharts({
map: seats_rows,
naming: {
rows: ['', '', '', ''],
top: false,
left: false,
},
legend: {
node: $('#legend'),
items: [
['c', 'available', 'Dostępne miejsce'],
['f', 'unavailable', 'Zajęte miejsce']
]
},
click: function () {
if (this.status() === 'available' && !seat_selected) {
// var's create a new
which we'll add to the cart items
$(' ' + this.settings.label + ' [x]')
.attr('id', 'cart-item-' + this.settings.id)
.data('seatId', this.settings.id)
.appendTo($cart);
seat_selected = true;
return 'selected';
} else if (this.status() === 'selected') {
//remove the item from our cart and make this seat available
$('#cart-item-' + this.settings.id).remove();
$('#item-' + this.settings.id).remove();
seat_selected = false;
return 'available';
} else if (this.status() === 'unavailable') {
return 'unavailable';
} else {
return this.style();
}
}
});
$('#selected-seats').on('click', '.cancel-cart-item', function () {
const id = $(this).parent().data('seatId');
$('#seat-map').find(`#${id}`).click();
});
}
function createMultiPartsMap(parts_number, seat_map) {
var $cart = $('#selected-seats');
var seat_selected = false;
// divide all rows into carousel slides
var parts_elements = []; // slides elements
var parts_rows = []; // sets of rows for slides
const per_page = 4; // max number of rows on one slide
var first_index = 0;
var last_index = 4;
for(var i=0; i -1) {
parts_elements[row_index].parent().remove(); // remove unnecessary slide from node
parts_rows.splice(row_index, 1); // remove unnecessary rows from list
parts_elements.splice(row_index, 1); // remove unnecessary slide from list
}
} else if(last_rows.length < 4) { // fill the last slide to 4 rows
const diff = 4 - last_rows.length;
for(var i=0; i which we'll add to the cart items
$(' ' + this.settings.label + ' [x]')
.attr('id', 'cart-item-' + this.settings.id)
.data('seatId', this.settings.id)
.appendTo($cart);
seat_selected = true;
return 'selected';
} else if (this.status() === 'selected') {
// //remove the item from our cart
$('#cart-item-' + this.settings.id).remove();
$('#item-' + this.settings.id).remove();
seat_selected = false;
return 'available';
} else if (this.status() === 'unavailable') {
return 'unavailable';
} else {
return this.style();
}
}
});
// execute seatchart function for the rest slides
for(var i = 1; i < parts_number - 1; i++) {
parts_elements[i].seatCharts({
map: parts_rows[i],
naming: {
rows: ['', '', '', ''],
top: false,
left: false,
},
click: function () {
if (this.status() === 'available' && !seat_selected) {
// //var's create a new which we'll add to the cart items
$(' ' + this.settings.label + ' [x]')
.attr('id', 'cart-item-' + this.settings.id)
.data('seatId', this.settings.id)
.appendTo($cart);
seat_selected = true;
return 'selected';
} else if (this.status() === 'selected') {
// //remove the item from our cart
$('#cart-item-' + this.settings.id).remove();
$('#item-' + this.settings.id).remove();
seat_selected = false;
return 'available';
} else if (this.status() === 'unavailable') {
return 'unavailable';
} else {
return this.style();
}
}
});
}
$('#selected-seats').on('click', '.cancel-cart-item', function () {
const id = $(this).parent().data('seatId');
$('#multi_parts-map').find(`#${id}`).click();
});
}
const seat_map = $('#room_arrangement').val().split('++');
if (seat_map.length > 4) {
const parts_number = $('#multi_parts_number').val();
createMultiPartsMap(parts_number, seat_map)
} else {
const seats_container = $('#seat-map');
createMap(seat_map, seats_container);
}
});