<commit_before>var selectedShow;
var selectedSeats = [];
var adultSeatsAmount = 0;
var studentSeatsAmount = 0;

$(document).ready(initShows);

$('body').on('click', '.show-selection-link', function(e) {
    e.preventDefault();

    var selectedShowId = Number($(this).find('div').attr('id').replace('show-', ''));

    $.ajax({
        type: 'GET',
        url: '/api/v1/shows/' + selectedShowId,
        dataType: 'JSON',
        success: function(data) {
            selectedShow = data;

            getTemplate('/views/partials/seatselection.ejs', function(err, template) {
                var seatSelection = ejs.render(template, {show: selectedShow, time: new Date(data.time)});
                $('#content').html(seatSelection);
                $('.breadcrumb li:eq(1)').toggleClass('active');
                initSeatCharts();
            });
        }
    });
}).on('click', '#checkout-button', function(e) {
    e.preventDefault();

    $('#checkout-button').popover({
        trigger: 'manual',
        placement: 'left',
        container: 'body'
    });

    adultSeatsAmount = parseInt($('#adultTickets').val());
    studentSeatsAmount = parseInt($('#studentTickets').val());

    if (selectedSeats.length <= 0) {
        $(this).data('bs.popover').options.content = 'Please select your seats first.';
        $(this).popover('show');
        setTimeout(function() {
            $('#checkout-button').popover('hide');
        }, 3000);
        return;
    } else if (selectedSeats.length !== adultSeatsAmount + studentSeatsAmount) {
        $(this).data('bs.popover').options.content = 'Please ensure that the number of seats selected matches the number of people in your group.';
        $(this).popover('show');
        setTimeout(function() {
            $('#checkout-button').popover('hide');
        }, 3000);
        return;
    }

    getTemplate('/views/partials/checkout.ejs', function(err, template) {
        var checkout = ejs.render(template, {
            selectedSeats: selectedSeats,
            show: selectedShow,
            time: new Date(selectedShow.time),
            adultSeatsAmount: adultSeatsAmount,
            studentSeatsAmount: studentSeatsAmount,
            totalPrice: (studentSeatsAmount * selectedShow.studentprice) + (adultSeatsAmount * selectedShow.adultprice)
        });
        $('#content').html(checkout);
        $('.breadcrumb li:eq(2)').toggleClass('active');

        // Braintree Setup
        $.ajax({
            type: 'GET',
            url: '/api/v1/token',
            dataType: 'JSON',
            success: function(data) {
                braintree.setup(data.clientToken, 'custom', {
                    id: 'payment-form',
                    onReady: function() {
                        $('.spinner').remove();
                        $('#payment-form').removeClass('hidden');
                    },
                    onPaymentMethodReceived: function(obj) {
                        $.ajax({
                            type: 'POST',
                            url: '/api/v1/checkout',
                            dataType: 'JSON',
                            data: {
                                seats: $('input[name=seats]').val(),
                                price: (studentSeatsAmount * selectedShow.studentprice) + (adultSeatsAmount * selectedShow.adultprice),
                                showid: $('input[name=showid]').val(),
                                showname: $('input[name=showname]').val(),
                                paymentMethodNonce: obj['nonce'],
                                firstName: $('input[name=firstName]').val(),
                                lastName: $('input[name=lastName]').val(),
                                email: $('input[name=email]').val(),
                                phone: $('input[name=phone]').val(),
                                address: $('input[name=address]').val(),
                                city: $('input[name=city]').val(),
                                state: $('input[name=state]').val(),
                                zip: $('input[name=zip]').val()
                            },
                            success: function(data) {
                                getTemplate('/views/partials/confirmation.ejs', function(err, template) {
                                    var confirmation = ejs.render(template, {
                                        confirmationNumber: data.confirmationNumber,
                                        show: selectedShow,
                                        time: new Date(selectedShow.time)
                                    });
                                    $('#content').html(confirmation);
                                    $('.breadcrumb li:eq(3)').toggleClass('active');
                                });
                            }
                        });
                    },
                    hostedFields: {
                        number: {
                            selector: '#card-number',
                            placeholder: 'Credit Card Number'
                        },
                        cvv: {
                            selector: '#cvv',
                            placeholder: 'CVV'
                        },
                        expirationDate: {
                            selector: '#expiration-date',
                            placeholder: 'MM/YY'
                        },
                        styles: {
                            'input': {
                                'font-family': '"Helvetica Neue", Helvetica, Arial, sans-serif',
                                'font-size': '14px'
                            },
                            '::-moz-placeholder': {'color': '#999'},
                            ':-ms-input-placeholder': {'color': '#999'},
                            '::-webkit-input-placeholder': {'color': '#999'}
                        }
                    }
                });
            }
        });
<commit_msg>Check if seats have been taken<commit_after>var selectedShow;
var selectedSeats = [];
var adultSeatsAmount = 0;
var studentSeatsAmount = 0;

$(document).ready(initShows);

$('body').on('click', '.show-selection-link', function(e) {
    e.preventDefault();

    var selectedShowId = Number($(this).find('div').attr('id').replace('show-', ''));

    $.ajax({
        type: 'GET',
        url: '/api/v1/shows/' + selectedShowId,
        dataType: 'JSON',
        success: function(data) {
            selectedShow = data;

            getTemplate('/views/partials/seatselection.ejs', function(err, template) {
                var seatSelection = ejs.render(template, {show: selectedShow, time: new Date(data.time)});
                $('#content').html(seatSelection);
                $('.breadcrumb li:eq(1)').toggleClass('active');
                initSeatCharts();
            });
        }
    });
}).on('click', '#checkout-button', function(e) {
    e.preventDefault();

    $('#checkout-button').popover({
        trigger: 'manual',
        placement: 'left',
        container: 'body'
    });

    adultSeatsAmount = parseInt($('#adultTickets').val());
    studentSeatsAmount = parseInt($('#studentTickets').val());

    if (selectedSeats.length <= 0) {
        $(this).data('bs.popover').options.content = 'Please select your seats first.';
        $(this).popover('show');
        setTimeout(function() {
            $('#checkout-button').popover('hide');
        }, 3000);
        return;
    } else if (selectedSeats.length !== adultSeatsAmount + studentSeatsAmount) {
        $(this).data('bs.popover').options.content = 'Please ensure that the number of seats selected matches the number of people in your group.';
        $(this).popover('show');
        setTimeout(function() {
            $('#checkout-button').popover('hide');
        }, 3000);
        return;
    }

    getTemplate('/views/partials/checkout.ejs', function(err, template) {
        var checkout = ejs.render(template, {
            selectedSeats: selectedSeats,
            show: selectedShow,
            time: new Date(selectedShow.time),
            adultSeatsAmount: adultSeatsAmount,
            studentSeatsAmount: studentSeatsAmount,
            totalPrice: (studentSeatsAmount * selectedShow.studentprice) + (adultSeatsAmount * selectedShow.adultprice)
        });
        $('#content').html(checkout);
        $('.breadcrumb li:eq(2)').toggleClass('active');

        // Braintree Setup
        $.ajax({
            type: 'GET',
            url: '/api/v1/token',
            dataType: 'JSON',
            success: function(data) {
                braintree.setup(data.clientToken, 'custom', {
                    id: 'payment-form',
                    onReady: function() {
                        $('.spinner').remove();
                        $('#payment-form').removeClass('hidden');
                    },
                    onPaymentMethodReceived: function(obj) {
                        $.ajax({
                            type: 'GET',
                            url: '/api/v1/purchased_seats',
                            dataType: 'JSON',
                            success: function(data) {
                                var seats = selectedSeats.split(',');
                                var problem = false;
                                data.forEach(function(purchasedSeat) {
                                    if (seats.indexOf(purchasedSeat) == -1) {
                                        problem = true;
                                    }
                                });

                                if (!problem) {
                                    $.ajax({
                                        type: 'POST',
                                        url: '/api/v1/checkout',
                                        dataType: 'JSON',
                                        data: {
                                            seats: $('input[name=seats]').val(),
                                            price: (studentSeatsAmount * selectedShow.studentprice) + (adultSeatsAmount * selectedShow.adultprice),
                                            showid: $('input[name=showid]').val(),
                                            showname: $('input[name=showname]').val(),
                                            paymentMethodNonce: obj['nonce'],
                                            firstName: $('input[name=firstName]').val(),
                                            lastName: $('input[name=lastName]').val(),
                                            email: $('input[name=email]').val(),
                                            phone: $('input[name=phone]').val(),
                                            address: $('input[name=address]').val(),
                                            city: $('input[name=city]').val(),
                                            state: $('input[name=state]').val(),
                                            zip: $('input[name=zip]').val()
                                        },
                                        success: function(data) {
                                            getTemplate('/views/partials/confirmation.ejs', function(err, template) {
                                                var confirmation = ejs.render(template, {
                                                    confirmationNumber: data.confirmationNumber,
                                                    show: selectedShow,
                                                    time: new Date(selectedShow.time)
                                                });
                                                $('#content').html(confirmation);
                                                $('.breadcrumb li:eq(3)').toggleClass('active');
                                            });
                                        }
                                    });
                                } else {
                                    // TODO: Alert user of error
                                }
                            }
                        });
                    },
                    hostedFields: {
                        number: {
                            selector: '#card-number',
                            placeholder: 'Credit Card Number'
                        },
                        cvv: {
                            selector: '#cvv',
                            placeholder: 'CVV'
                        },
                        expirationDate: {
                            selector: '#expiration-date',
                            placeholder: 'MM/YY'
                        },
                        styles: {
                            'input': {
                                'font-family': '"Helvetica Neue", Helvetica, Arial, sans-serif',
                                'font-size': '14px'
                            },
                            '::-moz-placeholder': {'color': '#999'},
                            ':-ms-input-placeholder': {'color': '#999'},
                            '::-webkit-input-placeholder': {'color': '#999'}
                        }
                    }
                });
            }
        });

{'fraction_non_alphanumeric': 0.13200059898173105, 'fraction_numerical': 0.00434261755016472, 'mean_word_length': 1.077940261356565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 69, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6303444', 'n_tokens_mistral': 3079, 'n_tokens_neox': 2919, 'n_words': 512}