atcheck/public/js/map/seatchart.js

103 lines
3.5 KiB
JavaScript
Raw Normal View History

2019-12-07 19:49:42 +01:00
var firstSeatLabel = 1;
2019-12-09 12:17:23 +01:00
$(document).ready(function() {
const seat_map = $('#room_arrangement').val().split('++');
var $cart = $('#selected-seats'),
seatNumber = '',
placeNumber = ('#sel-seat'),
$counter = $('#counter'),
$name = $('#studentName'),
$total = $('#total'),
sc = $('#seat-map').seatCharts({
map: seat_map,
seats: {
2019-12-07 19:49:42 +01:00
h: {
2019-12-09 12:17:23 +01:00
price : 2500,
classes : 'student-class',
category: 'Student Seat'
},
},
naming : {
2019-12-07 19:49:42 +01:00
rows: ['','','',''],
2019-12-09 12:17:23 +01:00
top : false,
getLabel : function (character, row, column) {
if (row === '1') {
2019-12-07 19:49:42 +01:00
return column;
2019-12-09 12:17:23 +01:00
} else if (row === '2') {
2019-12-07 19:49:42 +01:00
return column;
2019-12-09 12:17:23 +01:00
} else if (row === '3') {
2019-12-07 19:49:42 +01:00
return column;
}
2019-12-09 12:17:23 +01:00
},
},
legend : {
node : $('#legend'),
items : [
2019-12-07 19:49:42 +01:00
[ 'c', 'available', 'Dostępne miejsce'],
[ 'f', 'unavailable', 'Zajęte miejsce']
2019-12-09 12:17:23 +01:00
]
},
click: function () {
if (this.status() == 'available' && recalculateTotal(sc) < 1) {
//let's create a new <li> which we'll add to the cart items
$('<span> '+this.settings.label+ '</span>')
.attr('id', 'cart-item-'+this.settings.id)
.data('seatId', this.settings.id)
.appendTo($cart);
2019-12-08 00:00:52 +01:00
2019-12-09 12:17:23 +01:00
seatNumber = 'rząd: ' + this.settings.row + ' miejsce: ' + this.settings.label;
localStorage.setItem('myElement', seatNumber);
/*
* Lets update the counter and total
*
* .find function will not find the current seat, because it will change its stauts only after return
* 'selected'. This is why we have to add 1 to the length and the current seat price to the total.
*/
$counter.text(sc.find('selected').length+1);
$total.text(recalculateTotal(sc)+1);
2019-12-07 19:49:42 +01:00
2019-12-09 12:17:23 +01:00
return 'selected';
} else if (this.status() == 'selected') {
//update the counter
$counter.text(sc.find('selected').length-1);
//and total
$total.text(recalculateTotal(sc)-1);
2019-12-07 19:49:42 +01:00
2019-12-09 12:17:23 +01:00
//remove the item from our cart
$('#cart-item-'+this.settings.id).remove();
$('#item-'+this.settings.id).remove();
2019-12-07 19:49:42 +01:00
2019-12-09 12:17:23 +01:00
//seat has been vacated
return 'available';
} else if (this.status() == 'unavailable') {
//seat has been already booked
return 'unavailable';
} else {
return this.style();
}
2019-12-07 19:49:42 +01:00
}
2019-12-09 12:17:23 +01:00
});
//this will handle "[cancel]" link clicks
$('#selected-seats').on('click', '.cancel-cart-item', function () {
//let's just trigger Click event on the appropriate seat, so we don't have to repeat the logic here
sc.get($(this).parents('li:first').data('seatId')).click();
});
//let's pretend some seats have already been booked
//sc.get(['1_2', '4_1', '7_1', '7_2']).status('unavailable');
});
function recalculateTotal(sc) {
var total = 0;
//basically find every selected seat and sum its price
sc.find('selected').each(function () {
total += 1;//this.data().price;
});
return total;
}