{% extends "main.html" %}
{% load karaage_tags %}


{% block title %}Group{% endblock %}


{% block breadcrumbs %}
<div class="breadcrumbs">
    <a href='{% url "index" %}'>Home</a>&nbsp;›
    <a href="{% url 'kg_group_list' %}">Groups</a>&nbsp;›
    {{ group }}
</div>
{% endblock %}


{% block content %}
<div id="content-main">

    <div class="module">
        <h2>Group Details</h2>

        <h3>{{ group }}</h3>
        <div class="table-container">
            <table class="keyvalue">
                <tr><th>Name:</th><td>{{ group.name }}</td></tr>
                <tr><th>Description:</th><td>{{ group.description }}</td></tr>
            </table>
        </div>

        {% if is_admin %}
        <div class="object-tools">
            <ul>
                <li><a href="{% url 'kg_group_edit' group.name %}" class="changelink">Edit details</a></li>
                <li><a href="{% url 'kg_group_delete' group.name %}" class="deletelink">Delete</a></li>
                <li><a href="{% url 'kg_group_logs' group.name %}">Logs</a></li>
                <li><a href="{% url 'kg_group_verbose' group.name %}">Verbose</a></li>
            </ul>
        </div>
        {% endif %}
    </div>

    {% if group.software_set.all or group.institute_set.all or group.project_set.all %}
    <div class="module">
        <h2>Used by</h2>
        <div class="table-container">
            <table>
                <thead>
                    <tr><th>Type</th><th>Link</th></tr>
                </thead>
                <tbody>
                    {% for software in group.software_set.all %}
                    <tr>
                        <td>Software</td>
                        <td><a href="{{ software.get_absolute_url }}">{{ software }}</a></td>
                    </tr>
                    {% endfor %}
                    {% for institute in group.institute_set.all %}
                    <tr>
                        <td>Institute</td>
                        <td><a href="{{ institute.get_absolute_url }}">{{ institute }}</a></td>
                    </tr>
                    {% endfor %}
                    {% for project in group.project_set.all %}
                    <tr>
                        <td>Project</td>
                        <td><a href="{{ project.get_absolute_url }}">{{ project }}</a></td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    {% endif %}

    <div class="module">
        <h2>Members</h2>
        {% if group.members.all %}
        <div class="table-container">
            <table>
                <thead>
                    <tr><th>Username</th><th>Full Name</th>{% if is_admin %}<th></th>{% endif %}</tr>
                </thead>
                <tbody>
                {% for member in group.members.all %}
                <tr>
                    <td><a href="{{ member.get_absolute_url }}">{{ member.username }}</a></td>
                    <td>{{ member.get_full_name }}</td>
                    {% if is_admin %}
                    <td>
                        <div><a href="{% url 'kg_group_remove_person' group.name member.username %}" class="deletelink">Delete</a></div>
                    </td>
                    {% endif %}
                </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        {% else %}
        <p>No members</p>
        {% endif %}
    </div>

    {% if form %}
    <div class="module">
        <h2>Add Member</h2>
        <form method="post" action="{% url "kg_group_add_person" group.name %}" class="simple">{% csrf_token %}
            {{ form }}
            <input type="submit" value="Add" class="default" />
        </form>
    </div>
    {% endif %}

    {% if is_admin %}
    <div class="module">
        <h2>Comments</h2>
        {% comments group %}
        <div class="object-tools">
            <ul>
                <li><a href="{% url 'kg_group_add_comment' group.name %}" class="addlink">Add comment</a></li>
            </ul>
        </div>
    </div>
    {% endif %}
</div>
{% endblock %}
