{% extends 'console/sortable_table.html' %}

{% block content %}

    <div>
        {% if messages %}
            {% for message in messages %}
                <div class="alert{% if message.tags %} alert-{{ message.tags }}{% endif %}" role="alert">{{ message }}</div>
            {% endfor %}
        {% endif %}
        <p>Tip: You can add a domain only if it's DNS zone contains a TXT record with this content: <strong>uwsgi:{{uuid}}</strong></p>
        <form id="add-domain-form" class="form-inline" role="form" action="{% url 'console_domains' %}" method="post">
            {% csrf_token %}
            {{ new_domain }}
            <button type="submit" class="btn btn-primary">Add</button>
        </form>
    </div>
    <br>
    <p>
    {% for tag in tags %}
        <button class="btn btn-default tag_filter margin-top" data-filter="{{ tag }}">{{ tag }}</button>
    {% endfor %}
    </p>
    <div class="table-responsive">
        <table class="table table-hover table-bordered tablesorter" id="domains-table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>UUID</th>
                    <th>TAGS</th>
                </tr>
            </thead>
            <tbody>
                {% for d in domains %}
                <tr class="table_row" data-category="{{ d.0.tags|join:' ' }}">
                    <td><a href="{% url 'console_domain' id=d.0.id %}">{{ d.0.id }}</a></td>
                    <td>{{ d.0.name }}</td>
                    <td>{{ d.0.uuid }}</td>
                    <td>
                        <form class="inline form-inline add-domain-form" role="form" action="{% url 'console_add_domain_tag' d.0.id %}" method="post">
                            {% csrf_token %}
                            {{ d.1.tags }}
                            <button type="submit" class="glyphicon glyphicon-floppy-save"></button>
                        </form>

                        <a href="?del={{ d.0.name }}"><span class="glyphicon glyphicon-remove-circle"></span></a>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}

{% block footer_js %}
    {{ block.super }}
    <script>var static_url = '{{ STATIC_URL }}';</script>
    <script src="{{ STATIC_URL }}console/js/add_tags.js"></script>
{% endblock %}
