var full = false; function parse_phone(phone) { const digits = phone.replace(/\D/g, ''); if (digits.startsWith('00')) { parsedNumber = parseInt(digits); } else if (digits.startsWith('0')) { parsedNumber = parseInt(`0049${digits.slice(1)}`); } else { parsedNumber = parseInt(`00${digits}`); } return parsedNumber; } function get_free_places() { $.ajax({ url: '/api/v1/stats/registrations', type: 'GET', dataType: "json", success: function (data) { if (data['free'] <= 0) { $('.register .btn').prop('disabled', true); $('.register .field-btn').css('cursor', 'no-drop'); full = true; $('#register .btn').text('Fully booked. Please try again later!'); Swal.fire({ title: 'Unfortunately, all seats are already taken :(', text: 'Just check back later...', icon: 'warning', }); } else { $('#register .btn').text('Register (still _FREE_ seats available)'.replace('_FREE_', data['free'])); $('.register .field-btn').css('cursor', 'auto'); } } }); } function register() { $('.register .btn').prop('disabled', true); $.ajax({ url: '/api/v1/registration', type: 'POST', data: JSON.stringify({ address: $('#address').val(), age: $('#age').val(), city: $('#city').val(), comment: $('#note').val(), email: $('#mail').val(), firstname: $('#firstname').val(), food: $('#food').val(), lastname: $('#lastname').val(), newsletter: $('#newsletter').prop('checked'), notice: $('#reason').val(), phone: parse_phone($('#phone').val()), picture: $('#picture').prop('checked'), tshirt: $('#tshirt').val(), }), contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { Swal.fire({ title: 'Thank you very much for your registration!', text: 'You will receive further information shortly via email', icon: 'success', willClose: function () { location.replace('/') } }); }, error: function (data) { Swal.fire({ title: 'Oops, something went wrong', text: data.responseJSON.detail, icon: 'error' }); $('.register .btn').prop('disabled', false); $('.register .field-btn').css('cursor', 'auto'); } }); } $(document).on("click", ".tshirt-info", function (event) { Swal.fire({ title: 'Why are there only men's sizes?', text: 'In recent years, we have unfortunately encountered problems with womens sizes from our supplier. The colors were often inconsistent, or the ordered quantity could not be delivered. Since many female participants often ordered mens sizes anyway due to the cut, we have decided to offer exclusively these sizes. We ask for your understanding :)', icon: 'question' }); }); $(document).on("keyup", '#reason', function () { if ($('.register .btn').prop('disabled')) { if ($('#reason').val() === 'SecretStaff') { $('.register .btn').prop('disabled', false); $('.register .field-btn').css('cursor', 'auto'); } else { $('.register .btn').prop('disabled', true); $('.register .field-btn').css('cursor', 'no-drop'); } } }); $(document).on("click", '.agb label', function () { if ($(this).parent().find('input').prop('checked')) { $(this).parent().find('input').prop('checked', false); } else { $(this).parent().find('input').prop('checked', true); } }); $(document).on("submit", '.register', function () { if ($('#picture').prop('checked') == false) { Swal.fire({ showCancelButton: true, confirmButtonColor: '#d33', confirmButtonText: 'Register anyway!', cancelButtonColor: '#3085d6', cancelButtonText: 'Change choice', title: 'It is your right...', text: 'that you do not want us to publish photos and videos in which you are visible. However, this means a considerable additional effort for us, which we would be happy to avoid.', type: 'warning' }).then((result) => { if (result.value) { register(); } }); } else { register(); } return false }); $(function () { get_free_places(); });