<commit_before>{% extends "base.html" %}
{% block head_javascript %}
    {{ super() }}
    <script type="text/javascript">
        var PREREG_CHECK_INTERVAL = 15 * 60 * 1000;
        var checkCap = function () {
            $.getJSON('../preregistration/check_prereg', function (check) {
                if (check.force_refresh) {
                    location.reload();  // Reload the page to prevent registering after reg is closed
                } else {
                    setTimeout(checkCap, PREREG_CHECK_INTERVAL);
                }
            });
        };
        setTimeout(checkCap, PREREG_CHECK_INTERVAL);

        var REG_TYPES = {
            row: '#reg-types',
            selector: '.reg-type-selector',
            options: [{
                title: 'Single Attendee',
                description: 'A single registration; you can register more before paying.',
                onClick: function () {
                    $('.group_fields').addClass('hide');
                    if ($.field('badge_type').val() == '{{ c.PSEUDO_GROUP_BADGE }}') {
                        $('input[name="badge_type"]').val('{{ c.ATTENDEE_BADGE }}');
                    }
                    if ($.field('first_name')) {
                        $('#bold-field-message').insertBefore($.field('first_name').parents('.form-group'));
                    }
                    showOrHideBadgeTypes();
                    togglePrices();
                }
            }]
        };
        {% if c.GROUPS_ENABLED and attendee and attendee.is_new and not group_id %}
            REG_TYPES.options.push({
                title: 'Group Leader',
                {% if c.BEFORE_GROUP_PREREG_TAKEDOWN %}
                    description: '<p class="list-group-item-text">Register a group of {{ c.MIN_GROUP_SIZE }} people or more.</p>',
                {% else %}
                    description: '<p class="list-group-item-text">The deadline for Group registration has passed, but you can still register as a regular attendee.</p>',
                {% endif %}
                onClick: function () {
                    {% if c.BEFORE_GROUP_PREREG_TAKEDOWN %}
                        $('.group_fields').removeClass('hide');
                        $('input[name="badge_type"]').val('{{ c.PSEUDO_GROUP_BADGE }}');
                        $('#bold-field-message').insertBefore($.field('name').parents('.form-group'));
                        showOrHideBadgeTypes();
                        togglePrices();
                    {% else %}
                        setBadge(REG_TYPES, 0);
                        toastr.clear();
                        toastr.error('Group registration has closed.');
                    {% endif %}
                }
            });
        {% endif %}
        var BADGE_TYPES = {
            row: '#badge-types',
            selector: '.badge-type-selector',
            options: [{
                title: '{% if c.PAGE_PATH == "/preregistration/form" or c.PAGE_PATH == "/preregistration/dealer_registration" or undoing_extra %}Attending{% elif attendee %}{{ attendee.ribbon_and_or_badge }}{% endif %}',
                description: 'Allows access to the convention for its duration.',
                extra: 0,
                price: {{ c.BADGE_PRICE }},
                onClick: function () {
                    $('input[name="badge_type"]').val('{{ c.ATTENDEE_BADGE }}');
                }
            }]
        };
        {% if c.SHIRT_LEVEL in c.PREREG_DONATION_TIERS and c.SHIRT_AVAILABLE %}
            BADGE_TYPES.options.push({
                title: 'Add a tshirt',
                description: 'Add a {{ c.EVENT_NAME }} themed t-shirt to your registration.',
                extra: {{ c.SHIRT_LEVEL }},
                price: {{ c.BADGE_PRICE }}
            });
        {% endif %}
        {% if c.SUPPORTER_LEVEL in c.PREREG_DONATION_TIERS and c.SUPPORTER_AVAILABLE %}
            BADGE_TYPES.options.push({
                title: 'Supporter',
                description: 'Donate extra and get more swag with your registration.',
                extra: {{ c.SUPPORTER_LEVEL }},
                price: {{ c.BADGE_PRICE }}
            });
        {% endif %}

        {% for badge_type in c.BADGE_TYPE_PRICES %}
            {% if badge_type != c.ATTENDEE_BADGE %}
            BADGE_TYPES.options.push({
                title: '{{ c.BADGES[badge_type] }}',
                description: 'Donate extra to get an upgraded badge with perks.',
                extra: 0,
                price: {{ c.BADGE_TYPE_PRICES[badge_type] }},
                badge_type: '{{ badge_type }}',
                onClick: function () {
                    $('input[name="badge_type"]').val('{{ badge_type }}');
                }
            });
            {% endif %}
        {% endfor %}

        BADGE_TYPES.options.sort(function(a, b){
            return a.price > b.price;
        });

        var togglePrices = function () {
            var showTotalPrices = {% if c.PAGE_PATH == '/preregistration/form' and not c.PREREG_DONATION_DESCRIPTIONS %}($.val('badge_type') != {{ c.PSEUDO_DEALER_BADGE }}){% else %}false{% endif %};
            $.each(BADGE_TYPES.options, function (i, type) {
                var $price = $(BADGE_TYPES.selector).slice(i, i + 1).find('.price').empty();
                var $price_notice = $(BADGE_TYPES.selector).slice(i, i + 1).find('.price_notice').empty();
                if (showTotalPrices) {
                    $price.append(': $').append(type.extra + type.price);
                    {% for amount_extra, val in c.PREREG_DONATION_OPTS %}
                        if (type.extra == {{ amount_extra }} && type.extra >= {{ c.SUPPORTER_LEVEL }}) {
                            $price_notice.append('{{ price_notice("Supporter registration", c.SUPPORTER_DEADLINE, c.SUPPORTER_LEVEL) }}')
                        } else if (type.extra == {{ amount_extra }} && !type.badge_type ) {
                            $price_notice.append('{{ price_notice("Preregistration", c.PREREG_TAKEDOWN, amount_extra) }}')
                        }
                    {% endfor %}
                } else if (type.extra) {
                    $price.append(': +$').append(type.extra);
                } else if (type.price) {
                    $price.append(': $').append(type.price);
                }
            });
            $.each(REG_TYPES.options, function (i, type) {
                var $price = $(REG_TYPES.selector).slice(i, i + 1).find('.price').empty();
                var $price_notice = $(REG_TYPES.selector).slice(i, i + 1).find('.price_notice').empty();
                if (!showTotalPrices) {
                    if (type.title == 'Single Attendee') {
                        $price.append(': $').append({{ c.BADGE_PRICE }});
                        $price_notice.append('{{ price_notice("Preregistration", c.PREREG_TAKEDOWN) }}')
                    } else if (type.title == 'Group Leader') {
                        $price.append(': $').append({{ c.GROUP_PRICE }}).append(' per badge');
                        $price_notice.append('{{ price_notice("Group registration", c.GROUP_PREREG_TAKEDOWN, 0, c.GROUP_DISCOUNT) }}')
                    }
                }
            });
        };
        var showOrHideBadgeTypes = function () {
            // We use 'pseudo' badge types to create dealers and groups, which is antithetical to using attending-facing
            // badge types for upgrades. We thus want to hide any badge buttons with a unique badge type if the attendee
            // is a dealer or group leader.
            if ($(BADGE_TYPES.row).size()) {
                $.each(BADGE_TYPES.options, function (i, badgeType) {
                    if (badgeType.badge_type && badgeType.badge_type != {{ c.ATTENDEE_BADGE }}) {
                        var current_button = $(BADGE_TYPES.selector).slice(i, 1+i);
                        current_button.toggle($.field('badge_type').val() != '{{ c.PSEUDO_GROUP_BADGE }}' && $.field('badge_type').val() != '{{ c.PSEUDO_DEALER_BADGE }}');
                        // If an 'invalid' badge type is currently selected when the reg type is changed, reset to the
                        // first in the list
                        if (!current_button.is(":visible") && current_button.hasClass('active')) {
                            setBadge(BADGE_TYPES, 0);
                        }
                    }
                });
            }
        };
        var setBadge = function (types, index) {
            var type = types.options[index];
            $(types.selector)
                .removeClass('active')
                .slice(index, 1 + index)
                .addClass('active');
            (type.onClick || $.noop)();
        };
        var setKickinFromBadge = function (types, index) {
            var type = types.options[index];
            if (type.extra !== undefined && type.extra !== null && $.field('amount_extra')) {
                {% if c.PREREG_DONATION_DESCRIPTIONS %}
                    $('input:radio[name=amount_extra][value='+ type.extra +']').prop('checked', true).trigger('change');
                {% else %}
                    $.field('amount_extra').val(type.extra).trigger('change');
                {% endif %}
            }
        };
        var makeBadgeMatchExtra = function () {
            if (_(BADGE_TYPES.options).size()) {
                var target = 0;
                $.each(BADGE_TYPES.options, function (i, badgeType) {
                    if (badgeType.extra && $.field('amount_extra') && badgeType.extra == $.val('amount_extra')) {
                        target = i;
                    } else if (badgeType.badge_type && badgeType.badge_type == $.val('badge_type')) {
                        target = i;
                    }
                });
                if (!$(BADGE_TYPES.selector).slice(target, 1 + target).is('.active')) {
                    setBadge(BADGE_TYPES, target);
                }
            }
        };
        $(function () {
            togglePrices();
            showOrHideBadgeTypes();
            if ($(BADGE_TYPES.row).size()) {
                $.each([REG_TYPES, BADGE_TYPES], function (i, types) {
                    $.each(types.options, function (index, type) {
                        $(types.row).append(
                            $('<div class="col-sm-3"></div>').append(
                                $('<a class="list-group-item"></a>').addClass(types.selector.substring(1)).click(function () {
                                    setBadge(types, index);
                                    setKickinFromBadge(types, index);
                                }).append(
                                    $('<h4 class="list-group-item-heading"></h4>')
                                        .append(type.title)
                                        .append('<span class="price"></span>')
                                ).append(
                                    $('<p class="list-group-item-text"></p>').html(type.description).append('<span class="price_notice"></span>'))));
                    });
                    $(types.row).append('<div style="clear:both">&nbsp;</div>');
                });
                if (window.REG_TYPES && $(REG_TYPES.row).size()) {
                    setBadge(REG_TYPES, $.field('name') && $.val('name') ? 1 : 0);  // default to attendee or group
                }
                makeBadgeMatchExtra();
                if ($.field('amount_extra')) {
                    {% if not c.PREREG_DONATION_DESCRIPTIONS %}
                        $.field('amount_extra').parents('.form-group').hide();
                    {% else %}
                        $.field('amount_extra').on('change', makeBadgeMatchExtra);
                    {% endif %}
                }
            }
        });
    </script>
{% endblock head_javascript %}
<commit_msg>Sort badge type options in all browsers The sort function is supposed to only return numbers, and Safari was enforcing that by not sorting the badge type buttons properly. Fixes https://github.com/MidwestFurryFandom/rams/issues/77.<commit_after>{% extends "base.html" %}
{% block head_javascript %}
    {{ super() }}
    <script type="text/javascript">
        var PREREG_CHECK_INTERVAL = 15 * 60 * 1000;
        var checkCap = function () {
            $.getJSON('../preregistration/check_prereg', function (check) {
                if (check.force_refresh) {
                    location.reload();  // Reload the page to prevent registering after reg is closed
                } else {
                    setTimeout(checkCap, PREREG_CHECK_INTERVAL);
                }
            });
        };
        setTimeout(checkCap, PREREG_CHECK_INTERVAL);

        var REG_TYPES = {
            row: '#reg-types',
            selector: '.reg-type-selector',
            options: [{
                title: 'Single Attendee',
                description: 'A single registration; you can register more before paying.',
                onClick: function () {
                    $('.group_fields').addClass('hide');
                    if ($.field('badge_type').val() == '{{ c.PSEUDO_GROUP_BADGE }}') {
                        $('input[name="badge_type"]').val('{{ c.ATTENDEE_BADGE }}');
                    }
                    if ($.field('first_name')) {
                        $('#bold-field-message').insertBefore($.field('first_name').parents('.form-group'));
                    }
                    showOrHideBadgeTypes();
                    togglePrices();
                }
            }]
        };
        {% if c.GROUPS_ENABLED and attendee and attendee.is_new and not group_id %}
            REG_TYPES.options.push({
                title: 'Group Leader',
                {% if c.BEFORE_GROUP_PREREG_TAKEDOWN %}
                    description: '<p class="list-group-item-text">Register a group of {{ c.MIN_GROUP_SIZE }} people or more.</p>',
                {% else %}
                    description: '<p class="list-group-item-text">The deadline for Group registration has passed, but you can still register as a regular attendee.</p>',
                {% endif %}
                onClick: function () {
                    {% if c.BEFORE_GROUP_PREREG_TAKEDOWN %}
                        $('.group_fields').removeClass('hide');
                        $('input[name="badge_type"]').val('{{ c.PSEUDO_GROUP_BADGE }}');
                        $('#bold-field-message').insertBefore($.field('name').parents('.form-group'));
                        showOrHideBadgeTypes();
                        togglePrices();
                    {% else %}
                        setBadge(REG_TYPES, 0);
                        toastr.clear();
                        toastr.error('Group registration has closed.');
                    {% endif %}
                }
            });
        {% endif %}
        var BADGE_TYPES = {
            row: '#badge-types',
            selector: '.badge-type-selector',
            options: [{
                title: '{% if c.PAGE_PATH == "/preregistration/form" or c.PAGE_PATH == "/preregistration/dealer_registration" or undoing_extra %}Attending{% elif attendee %}{{ attendee.ribbon_and_or_badge }}{% endif %}',
                description: 'Allows access to the convention for its duration.',
                extra: 0,
                price: {{ c.BADGE_PRICE }},
                onClick: function () {
                    $('input[name="badge_type"]').val('{{ c.ATTENDEE_BADGE }}');
                }
            }]
        };
        {% if c.SHIRT_LEVEL in c.PREREG_DONATION_TIERS and c.SHIRT_AVAILABLE %}
            BADGE_TYPES.options.push({
                title: 'Add a tshirt',
                description: 'Add a {{ c.EVENT_NAME }} themed t-shirt to your registration.',
                extra: {{ c.SHIRT_LEVEL }},
                price: {{ c.BADGE_PRICE }}
            });
        {% endif %}
        {% if c.SUPPORTER_LEVEL in c.PREREG_DONATION_TIERS and c.SUPPORTER_AVAILABLE %}
            BADGE_TYPES.options.push({
                title: 'Supporter',
                description: 'Donate extra and get more swag with your registration.',
                extra: {{ c.SUPPORTER_LEVEL }},
                price: {{ c.BADGE_PRICE }}
            });
        {% endif %}

        {% for badge_type in c.BADGE_TYPE_PRICES %}
            {% if badge_type != c.ATTENDEE_BADGE %}
            BADGE_TYPES.options.push({
                title: '{{ c.BADGES[badge_type] }}',
                description: 'Donate extra to get an upgraded badge with perks.',
                extra: 0,
                price: {{ c.BADGE_TYPE_PRICES[badge_type] }},
                badge_type: '{{ badge_type }}',
                onClick: function () {
                    $('input[name="badge_type"]').val('{{ badge_type }}');
                }
            });
            {% endif %}
        {% endfor %}

        BADGE_TYPES.options.sort(function(a, b){
            return (a.price > b.price) ? 1 : (a.price < b.price) ? -1 : 0;
        });

        var togglePrices = function () {
            var showTotalPrices = {% if c.PAGE_PATH == '/preregistration/form' and not c.PREREG_DONATION_DESCRIPTIONS %}($.val('badge_type') != {{ c.PSEUDO_DEALER_BADGE }}){% else %}false{% endif %};
            $.each(BADGE_TYPES.options, function (i, type) {
                var $price = $(BADGE_TYPES.selector).slice(i, i + 1).find('.price').empty();
                var $price_notice = $(BADGE_TYPES.selector).slice(i, i + 1).find('.price_notice').empty();
                if (showTotalPrices) {
                    $price.append(': $').append(type.extra + type.price);
                    {% for amount_extra, val in c.PREREG_DONATION_OPTS %}
                        if (type.extra == {{ amount_extra }} && type.extra >= {{ c.SUPPORTER_LEVEL }}) {
                            $price_notice.append('{{ price_notice("Supporter registration", c.SUPPORTER_DEADLINE, c.SUPPORTER_LEVEL) }}')
                        } else if (type.extra == {{ amount_extra }} && !type.badge_type ) {
                            $price_notice.append('{{ price_notice("Preregistration", c.PREREG_TAKEDOWN, amount_extra) }}')
                        }
                    {% endfor %}
                } else if (type.extra) {
                    $price.append(': +$').append(type.extra);
                } else if (type.price) {
                    $price.append(': $').append(type.price);
                }
            });
            $.each(REG_TYPES.options, function (i, type) {
                var $price = $(REG_TYPES.selector).slice(i, i + 1).find('.price').empty();
                var $price_notice = $(REG_TYPES.selector).slice(i, i + 1).find('.price_notice').empty();
                if (!showTotalPrices) {
                    if (type.title == 'Single Attendee') {
                        $price.append(': $').append({{ c.BADGE_PRICE }});
                        $price_notice.append('{{ price_notice("Preregistration", c.PREREG_TAKEDOWN) }}')
                    } else if (type.title == 'Group Leader') {
                        $price.append(': $').append({{ c.GROUP_PRICE }}).append(' per badge');
                        $price_notice.append('{{ price_notice("Group registration", c.GROUP_PREREG_TAKEDOWN, 0, c.GROUP_DISCOUNT) }}')
                    }
                }
            });
        };
        var showOrHideBadgeTypes = function () {
            // We use 'pseudo' badge types to create dealers and groups, which is antithetical to using attending-facing
            // badge types for upgrades. We thus want to hide any badge buttons with a unique badge type if the attendee
            // is a dealer or group leader.
            if ($(BADGE_TYPES.row).size()) {
                $.each(BADGE_TYPES.options, function (i, badgeType) {
                    if (badgeType.badge_type && badgeType.badge_type != {{ c.ATTENDEE_BADGE }}) {
                        var current_button = $(BADGE_TYPES.selector).slice(i, 1+i);
                        current_button.toggle($.field('badge_type').val() != '{{ c.PSEUDO_GROUP_BADGE }}' && $.field('badge_type').val() != '{{ c.PSEUDO_DEALER_BADGE }}');
                        // If an 'invalid' badge type is currently selected when the reg type is changed, reset to the
                        // first in the list
                        if (!current_button.is(":visible") && current_button.hasClass('active')) {
                            setBadge(BADGE_TYPES, 0);
                        }
                    }
                });
            }
        };
        var setBadge = function (types, index) {
            var type = types.options[index];
            $(types.selector)
                .removeClass('active')
                .slice(index, 1 + index)
                .addClass('active');
            (type.onClick || $.noop)();
        };
        var setKickinFromBadge = function (types, index) {
            var type = types.options[index];
            if (type.extra !== undefined && type.extra !== null && $.field('amount_extra')) {
                {% if c.PREREG_DONATION_DESCRIPTIONS %}
                    $('input:radio[name=amount_extra][value='+ type.extra +']').prop('checked', true).trigger('change');
                {% else %}
                    $.field('amount_extra').val(type.extra).trigger('change');
                {% endif %}
            }
        };
        var makeBadgeMatchExtra = function () {
            if (_(BADGE_TYPES.options).size()) {
                var target = 0;
                $.each(BADGE_TYPES.options, function (i, badgeType) {
                    if (badgeType.extra && $.field('amount_extra') && badgeType.extra == $.val('amount_extra')) {
                        target = i;
                    } else if (badgeType.badge_type && badgeType.badge_type == $.val('badge_type')) {
                        target = i;
                    }
                });
                if (!$(BADGE_TYPES.selector).slice(target, 1 + target).is('.active')) {
                    setBadge(BADGE_TYPES, target);
                }
            }
        };
        $(function () {
            togglePrices();
            showOrHideBadgeTypes();
            if ($(BADGE_TYPES.row).size()) {
                $.each([REG_TYPES, BADGE_TYPES], function (i, types) {
                    $.each(types.options, function (index, type) {
                        $(types.row).append(
                            $('<div class="col-sm-3"></div>').append(
                                $('<a class="list-group-item"></a>').addClass(types.selector.substring(1)).click(function () {
                                    setBadge(types, index);
                                    setKickinFromBadge(types, index);
                                }).append(
                                    $('<h4 class="list-group-item-heading"></h4>')
                                        .append(type.title)
                                        .append('<span class="price"></span>')
                                ).append(
                                    $('<p class="list-group-item-text"></p>').html(type.description).append('<span class="price_notice"></span>'))));
                    });
                    $(types.row).append('<div style="clear:both">&nbsp;</div>');
                });
                if (window.REG_TYPES && $(REG_TYPES.row).size()) {
                    setBadge(REG_TYPES, $.field('name') && $.val('name') ? 1 : 0);  // default to attendee or group
                }
                makeBadgeMatchExtra();
                if ($.field('amount_extra')) {
                    {% if not c.PREREG_DONATION_DESCRIPTIONS %}
                        $.field('amount_extra').parents('.form-group').hide();
                    {% else %}
                        $.field('amount_extra').on('change', makeBadgeMatchExtra);
                    {% endif %}
                }
            }
        });
    </script>
{% endblock head_javascript %}

{'fraction_non_alphanumeric': 0.14411752465770528, 'fraction_numerical': 0.002455366432227725, 'mean_word_length': 1.461837926441963, 'pattern_counts': {'":': 2, '<': 44, '<?xml version=': 0, '>': 47, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3946479', 'n_tokens_mistral': 6851, 'n_tokens_neox': 6377, 'n_words': 1223}