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 statValue(data, name) { const entry = data.find(function (item) { return item.name.toLowerCase() === name.toLowerCase(); }); return entry ? entry.value : 0; } function update_registration_status(data) { const registered = statValue(data, 'total'); const max = statValue(data, 'max'); const remaining = statValue(data, 'free'); const progress = max > 0 ? Math.round((registered / max) * 100) : 0; $('#registration-status').show(); $('#registration-progress-bar').css('width', progress + '%'); $('#registration-status-text').text( "_REGISTERED_ of _MAX_ registered (_REMAINING_ spots remaining)" .replace('_REGISTERED_', registered) .replace('_MAX_', max) .replace('_REMAINING_', remaining) ); } function get_free_places() { $.ajax({ url: '/api/v1/stats/registrations', type: 'GET', dataType: "json", success: function (data) { const freePlaces = statValue(data, 'free'); if (freePlaces <= 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 .field-btn').css('cursor', 'auto'); } } }); } function register(options) { options = options || {}; $('.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(), confirm_duplicate_email: options.confirmDuplicateEmail || false, }), 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) { if ( !options.confirmDuplicateEmail && data.responseJSON && data.responseJSON.detail === 'email_already_registered' ) { Swal.fire({ showCancelButton: true, confirmButtonColor: '#d33', confirmButtonText: "Register anyway!", cancelButtonColor: '#3085d6', cancelButtonText: "Change choice", title: "Email address already in use", text: "This email address has already been used for a registration. Do you still want to register?", icon: 'warning', }).then((result) => { if (result.value) { register({ confirmDuplicateEmail: true }); } else { $('.register .btn').prop('disabled', false); $('.register .field-btn').css('cursor', 'auto'); } }); return; } 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\u0027s 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(); });