<commit_before>{% extends 'base.html' %}
{% load i18n %}
{% load tags %}

{% block content %}
    {% include 'image/edit/menu.html' %}   
    <div class="sided-main-content">
    <h1>{% trans "Edit your image: basic information" %}</h1>
    {% form_saved request %}
    <p id="form_help_text" style="display:none">{% blocktrans %}Remember that the locations and subjects fields autocomplete, and you need to press TAB to add something to your list. If it's not in a white box, it doesn't get saved!{% endblocktrans %}
    <form action="{% url image_edit_save_basic %}" method="post">{% csrf_token %}
        <div id="js_form" style="display:none">
            {{form.as_p}}
        </div>

        <noscript>
            <p><label for="id_title">{% trans "Title" %}:</label>
               <input id="id_title" type="text" name="title" value="{{image.title}}" maxlength="64" />
            </p>
            <p>
                <label for="id_subjects">{% trans "Subjects" %}:</label>
                <input type="text" name="subjects" id="id_subjects" value="{{subjects}}" disabled="disabled" />
                <span class="helptext">{% trans "You can't edit Subjects without Javascript. Please enable it in your Internet browser." %}</span>
            </p>
            <p>
                <label for="id_locations">{% trans "Locations" %}:</label>
                <input type="text" name="locations" value="{{locations}}" id="id_locations" />
                <span class="helptext">
                    <p class="hint">
                        {% blocktrans %}Use a comma to separate the values.{% endblocktrans %}
                    </p>
                </span>
            </p>
            <p>
                <label for="id_description">{% trans "Description" %}:</label>
                <textarea id="id_description" rows="10" cols="40" name="description">{{image.description}}</textarea>
            </p>
        </noscript>

        <input type="hidden" name="image_id" value="{{image.id}}" />
        <ul>
            <li><input class="button submit-button" type="submit" value="{% trans "Save" %} &rarr;" /></li>
            <li><a href="{{image.get_absolute_url}}/">{% trans "Return to image" %}</a></li>
        </ul>
    </form>
    </div>
{% endblock %}

{% block extra_js %}
<script language="javascript">
    $(document).ready(function() {
        $('p#form_help_text').show();
        $('#js_form').show();

        {% autoescape off %}
        {% for key, value in prefill_dict.items %}
        var startText = '{{value.1}}';
        var emptyText = '{{value.2}}';
        var resultsTitleText = '{{value.3}}';
        $('#id_{{key}}').autoSuggest('/autocomplete/{{key}}/',
            {asHtmlID: '{{key}}',
            selectedItemProp: 'name',
            searchObjProps: 'name',
            preFill: {{value.0}},
            selectedItemProp: 'name',
            selectedValuesProp: 'id',
            startText: startText,
            emptyText: emptyText,
            resultsTitleText: resultsTitleText});
        {% endfor %}
        {% endautoescape %}

        // Perform some magic as the user types the title
        var timer;
        var current_subjects = new Array();
        $('input[name=title]').keydown(function(e) {
            var $input = $(this)

            if (e.keyCode == 8 ) { //delete
                // TODO
            } else {
                var val = $input.val().toUpperCase();
                var regex = /(M|MESSIER|IC|NGC|VDB)\s*([0-9]+)/g;
                var m = regex.exec(val);
                if (m != null) {
                    clearTimeout(timer);
                    timer = setTimeout(function() {
                        while (m != null) {
                            m[0] = m[0].replace('MESSIER', 'M');

                            var subjects = $('input[name=subjects]');
                            var subjects_values = $('input[name=as_values_subjects]');
                            var split_regex = /([A-Z]+)(\d+)/;
                            var split = split_regex.exec(m[0]);
                            if (split)
                                s = split[1] + ' ' + split[2];
                            else
                                s = m[0]; // and good luck with that.

                            var subjects_regex = new RegExp(s + "\\b", "g");
                            var subjects_matches = subjects[0].defaultValue.toUpperCase().search(subjects_regex, "regex");
                            var subjects_values_matches = subjects_values.val().toUpperCase().search(subjects_regex, "regex");
                            if (subjects_matches == -1 && subjects_values_matches == -1) {
                                // Let's add the subject to the auto suggest box
                                if (subjects.val() == startText)
                                    subjects.val("");

                                subjects.val(subjects.val() + s);

                                e = jQuery.Event('keydown');
                                e.keyCode = 188; // tab
                                subjects.trigger(e);

                                current_subjects.push(s);
                            }
                            m = regex.exec(val);
                        }
                    }, 500);
                }
            }
        });
    });
</script>
{% endblock %}<commit_msg>PRevious magic was a little buggy.<commit_after>{% extends 'base.html' %}
{% load i18n %}
{% load tags %}

{% block content %}
    {% include 'image/edit/menu.html' %}   
    <div class="sided-main-content">
    <h1>{% trans "Edit your image: basic information" %}</h1>
    {% form_saved request %}
    <p id="form_help_text" style="display:none">{% blocktrans %}Remember that the locations and subjects fields autocomplete, and you need to press TAB to add something to your list. If it's not in a white box, it doesn't get saved!{% endblocktrans %}
    <form action="{% url image_edit_save_basic %}" method="post">{% csrf_token %}
        <div id="js_form" style="display:none">
            {{form.as_p}}
        </div>

        <noscript>
            <p><label for="id_title">{% trans "Title" %}:</label>
               <input id="id_title" type="text" name="title" value="{{image.title}}" maxlength="64" />
            </p>
            <p>
                <label for="id_subjects">{% trans "Subjects" %}:</label>
                <input type="text" name="subjects" id="id_subjects" value="{{subjects}}" disabled="disabled" />
                <span class="helptext">{% trans "You can't edit Subjects without Javascript. Please enable it in your Internet browser." %}</span>
            </p>
            <p>
                <label for="id_locations">{% trans "Locations" %}:</label>
                <input type="text" name="locations" value="{{locations}}" id="id_locations" />
                <span class="helptext">
                    <p class="hint">
                        {% blocktrans %}Use a comma to separate the values.{% endblocktrans %}
                    </p>
                </span>
            </p>
            <p>
                <label for="id_description">{% trans "Description" %}:</label>
                <textarea id="id_description" rows="10" cols="40" name="description">{{image.description}}</textarea>
            </p>
        </noscript>

        <input type="hidden" name="image_id" value="{{image.id}}" />
        <ul>
            <li><input class="button submit-button" type="submit" value="{% trans "Save" %} &rarr;" /></li>
            <li><a href="{{image.get_absolute_url}}/">{% trans "Return to image" %}</a></li>
        </ul>
    </form>
    </div>
{% endblock %}

{% block extra_js %}
<script language="javascript">
    $(document).ready(function() {
        $('p#form_help_text').show();
        $('#js_form').show();

        {% autoescape off %}
        {% for key, value in prefill_dict.items %}
        var startText = '{{value.1}}';
        var emptyText = '{{value.2}}';
        var resultsTitleText = '{{value.3}}';
        $('#id_{{key}}').autoSuggest('/autocomplete/{{key}}/',
            {asHtmlID: '{{key}}',
            selectedItemProp: 'name',
            searchObjProps: 'name',
            preFill: {{value.0}},
            selectedItemProp: 'name',
            selectedValuesProp: 'id',
            startText: startText,
            emptyText: emptyText,
            resultsTitleText: resultsTitleText});
        {% endfor %}
        {% endautoescape %}

        // Perform some magic as the user types the title
        var timer;
        var current_subjects = new Array();
        $('input[name=title]').keydown(function(e) {
            var $input = $(this)

            if (e.keyCode == 8 ) { //delete
                // TODO
            } else {
                clearTimeout(timer);
                timer = setTimeout(function() {
                    var val = $input.val().toUpperCase();
                    var regex = /(M|MESSIER|IC|NGC|VDB)\s*([0-9]+)/g;

                    var m = regex.exec(val);
                    while (m != null) {
                        m[0] = m[0].replace('MESSIER', 'M');

                        var subjects = $('input[name=subjects]');
                        var subjects_values = $('input[name=as_values_subjects]');
                        var split_regex = /([A-Z]+)(\d+)/;
                        var split = split_regex.exec(m[0]);
                        if (split)
                            s = split[1] + ' ' + split[2];
                        else
                            s = m[0]; // and good luck with that.

                        var subjects_regex = new RegExp(s + "\\b", "g");
                        var subjects_matches = subjects[0].defaultValue.toUpperCase().search(subjects_regex, "regex");
                        var subjects_values_matches = subjects_values.val().toUpperCase().search(subjects_regex, "regex");
                        if (subjects_matches == -1 && subjects_values_matches == -1) {
                            // Let's add the subject to the auto suggest box
                            if (subjects.val() == startText)
                                subjects.val("");

                            subjects.val(subjects.val() + s);

                            e = jQuery.Event('keydown');
                            e.keyCode = 188; // tab
                            subjects.trigger(e);

                            current_subjects.push(s);
                        }
                        m = regex.exec(val);
                    }
                }, 500);
            }
        });


    });
</script>
{% endblock %}
{'fraction_non_alphanumeric': 0.15540983606557376, 'fraction_numerical': 0.0059953161592505855, 'mean_word_length': 1.5382786495482643, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3092520', 'n_tokens_mistral': 3081, 'n_tokens_neox': 2841, 'n_words': 680}