{% extends "generic/object_edit.html" %}
{% load static %}
{% load form_helpers %}

{% block form %}
    <div class="panel panel-default">
        <div class="panel-heading"><strong>Secrets Group</strong></div>
        <div class="panel-body">
            {% render_field form.name %}
            {% render_field form.description %}
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading"><strong>Secret Assignment</strong></div>
        <div class="panel-body">
            {% if secrets.errors %}
                <div class="text-danger">
                    Please correct the error(s) below:

                    {% for secret in secrets.forms %}
                        {% if secret.errors %}
                            {% for error in secret.errors.values %}{{ error }}{% endfor %}
                        {% endif %}
                    {% endfor %}
                </div>
            {% endif %}
            {{ secrets.non_field_errors }}
            <table class="table" id="secrets">
                {{ secrets.management_form }}
                {% for secret_form in secrets.forms %}
                    {% if forloop.first %}
                        <thead>
                            <tr>
                                {% for field in secret_form.visible_fields %}
                                    <th>{{ field.label|capfirst }}</th>
                                {% endfor %}
                            </tr>
                        </thead>
                    {% endif %}
                    <tr class="formset_row-{{ secrets.prefix }}">
                        {% for field in secret_form.visible_fields %}
                            <td>
                                {% if forloop.first %}
                                    {% for hidden in secret_form.hidden_fields %}
                                        {{ hidden }}
                                    {% endfor %}
                                {% endif %}
                                {{ field }}
                                {% if field.errors %}
                                    <ul>
                                        {% for error in field.errors %}
                                            {# Embed an HTML comment indicating the error for extraction by tests #}
                                            <!-- FORM-ERROR {{ field.name }}: {{ error }} -->
                                            <li clas="text-danger">{{ error }}</li>
                                        {% endfor %}
                                    </ul>
                                {% endif %}
                            </td>
                        {% endfor %}
                    </tr>
                {% endfor %}
            </table>
        </div>
    </div>
    {% include "inc/extras_features_edit_form_fields.html" %}
{% endblock form %}

{% block javascript %}
{{ block.super }}
<script src="{% static 'jquery/jquery.formset.js' %}"></script>
<script type="text/javascript">
    $('.formset_row-{{ secrets.prefix }}').formset({
        addText: '<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add another Secret',
        addCssClass: 'btn btn-primary add-row',
        deleteText: '<span class="mdi mdi-trash-can-outline" aria-hidden="true"></span>',
        deleteCssClass: 'btn btn-danger delete-row',
        prefix: '{{ secrets.prefix }}',
        formCssClass: 'dynamic-formset-{{ secrets.prefix }}',
        added: jsify_form
    });
</script>
{% endblock javascript %}
