<commit_before>{% set value_json = field._value() | tojson %}
<div class="form-row" data-tooltip-anchor>
    <div id="userGroupList-{{ field.id }}" style="margin-bottom: 10px;"></div>
    <input type="hidden" id="{{ field.id }}" name="{{ field.name }}" value="{{ value_json | forceescape }}">
    <span></span>
</div>
<script>
    (function() {
        var field = $('#{{ field.id }}');
        var principals = JSON.parse(field.val());

        {% if field.multiple %}
            function addPrincipal(newPrincipals, setResult) {
                // remove existing ones first to avoid duplicates
                _.each(newPrincipals, function(principal) {
                    principals = _.without(principals, _.findWhere(principals, {
                        identifier: principal.identifier
                    }));
                });
                principals = principals.concat(newPrincipals);
                field.val(JSON.stringify(principals));
                field.trigger('change');
                setResult(true);
            }
            function removePrincipal(principal, setResult) {
                principals = _.without(principals, _.findWhere(principals, {
                    identifier: principal.get('identifier')
                }));
                field.val(JSON.stringify(principals));
                field.trigger('change');
                setResult(true);
            }
            var widget = new UserListField(
                'PluginOptionPeopleListDiv', 'PeopleList', principals,
                true, null, true,
                {{ field.groups | tojson }},
                null, null, false, false, false, true,
                addPrincipal, userListNothing, removePrincipal, {{ field.allow_external|tojson }}
            );
        {% else %}
            function addUser(newUser, setResult) {
                field.val(JSON.stringify(newUser));
                field.trigger('change');
                setResult(true);
            }

            function removeUser(setResult) {
                field.val('[]');
                field.trigger('change');
                setResult(true);
            }
            var widget = new SingleUserField(principals[0],
                    {{ field.name|tojson }},
                    true, true, null,
                    null, false,
                    false, {{ (not field.flags.required)|tojson }},
                    addUser, removeUser, {{ field.allow_external|tojson }});
        {% endif %}


        $E('userGroupList-{{ field.id }}').set(widget.draw());
    })();
</script><commit_msg>Remove deprecated simple principal widget calls<commit_after>{% extends 'forms/base_widget.html' %}

{% block html %}
    {% set value_json = field._value() | tojson %}
    <div class="form-row" data-tooltip-anchor>
        <div id="userGroupList-{{ field.id }}" style="margin-bottom: 10px;"></div>
        <input type="hidden" id="{{ field.id }}" name="{{ field.name }}" value="{{ value_json | forceescape }}">
        <span></span>
    </div>
{% endblock %}

{% block javascript %}
    <script>
        (function() {
            var field = $('#{{ field.id }}');
            var principals = JSON.parse(field.val());

            function addPrincipal(newPrincipals, setResult) {
                // remove existing ones first to avoid duplicates
                _.each(newPrincipals, function(principal) {
                    principals = _.without(principals, _.findWhere(principals, {
                        identifier: principal.identifier
                    }));
                });
                principals = principals.concat(newPrincipals);
                field.val(JSON.stringify(principals));
                field.trigger('change');
                setResult(true);
            }
            function removePrincipal(principal, setResult) {
                principals = _.without(principals, _.findWhere(principals, {
                    identifier: principal.get('identifier')
                }));
                field.val(JSON.stringify(principals));
                field.trigger('change');
                setResult(true);
            }
            var widget = new UserListField(
                'PluginOptionPeopleListDiv', 'PeopleList', principals,
                true, null, true,
                {{ field.groups | tojson }},
                null, null, false, false, false, true,
                addPrincipal, userListNothing, removePrincipal, {{ field.allow_external|tojson }}
            );

            $E('userGroupList-{{ field.id }}').set(widget.draw());
        })();
    </script>
{% endblock %}
{'fraction_non_alphanumeric': 0.13626516464471403, 'fraction_numerical': 0.0010831889081455806, 'mean_word_length': 1.7255017709563165, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6884284', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1145, 'n_words': 225}