{% extends "base.html" %}

{% block title %} | {{group.name}}{% endblock %}
{% block bodydata %} data-project-id="{{group.project.id}}" data-project-isprivate="{{group.project.isprivate}}" data-group-id="{{group.id}}" data-everyone-contributes="{{ group.project.everyone_contributes }}"{% endblock %}

{% block main %}
        <div class="page-header">
            <div class="container">
                <div class="row">
                    <div class="col-sm-6">
                        <h1 class="smaller"><a href="{% url 'admin:project_overview' group.project.id %}">{{group.project.name}}</a></h1>
                        <a href="{% url 'admin:project_overview' group.project.id %}"><span class="glyphicon glyphicon-arrow-left"></span> Project home page</a>
                    </div>
                    <ul class="header-nav">
                        <li><a href="{% url 'admin:category_list' group.project.id %}">Categories <span class="badge">{{ group.project.categories.count }}</span></a></li>
                        <li class="active"><a href="{% url 'admin:usergroup_list' group.project.id %}">User groups <span class="badge">{{ group.project.usergroups.count }}</span></a></li>
                    </ul>
                </div>
            </div>
        </div>

        <div class="container">
            {% include 'snippets/messages.html' %}

            <div class="row">
                <div class="col-sm-4">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h6 class="item-info">User group</h6>
                            <h3>{{ group.name }}</h3>
                            {% if group.description %}<p>{{ group.description|linebreaksbr }}</p>{% endif %}
                        </div>
                        <div class="list-group">
                            <a href="{% url 'admin:usergroup_overview' group.project.id group.id %}" class="list-group-item">Members</a>
                            <a href="{% url 'admin:usergroup_permissions' group.project.id group.id %}" class="list-group-item active">Permissions</a>
                            <a href="{% url 'admin:usergroup_data' group.project.id group.id %}" class="list-group-item">Data</a>
                            <a href="{% url 'admin:usergroup_settings' group.project.id group.id %}" class="list-group-item">Settings</a>
                        </div>
                    </div>
                </div>
                <div class="col-sm-8">
                    <h3 class="header">Roles</h3>
                    {% if group.project.everyone_contributes != 'false' and not group.can_contribute %}
                    <div class="alert alert-warning hint">
                        <strong>Note:</strong> Currently, all users{% if not group.project.isprivate and group.project.everyone_contributes == 'auth' %}, who have access to this project,{% endif %} can contribute to the project. This setting overwrites permissions of individual user groups. If you plan to restrict contributing permissions to certain user groups, head to <a href="{% url 'admin:project_settings' group.project.id %}" class="alert-link">Project Settings</a> first and change the project permissions.
                    </div>
                    {% endif %}
                    <form id="permissions">
                        <div class="radio">
                            <label>
                                <input type="radio" name="permission" id="read_only" value="read_only" {% if not group.can_contribute and not group.can_moderate %} checked="true" {% endif %}>
                                <strong>Read only</strong>
                            </label><br>
                            Members of this user group will only be able to read data from its data groupings. However, the users will be able to comment on contributions.
                        </div>
                        <div class="radio">
                            <label>
                                <input type="radio" name="permission" id="can_contribute" value="can_contribute" {% if group.can_contribute and not group.can_moderate %} checked="true" {% endif %}>
                                <strong>Contributor</strong>
                            </label><br>
                            Members of this user group will be able to contribute new data to the project and read data from its data groupings.
                        </div>
                        <div class="radio">
                            <label>
                                <input type="radio" name="permission" id="can_moderate" value="can_moderate" {% if group.can_moderate %} checked="true" {% endif %}>
                                <strong>Moderator</strong>
                            </label><br>
                            Members of this user group will be able to contribute new data as well as to read and moderate data from its data groupings.
                        </div>

                        <div class="form-group">
                            <button type="submit" class="btn btn-primary">Update permissions</button>
                            <button type="reset" class="btn btn-link">Reset</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
{% endblock %}

{% block libraries %}
            <script src="/static/lib/handlebars/handlebars.js"></script>
            <script src="/static/js/templates.js"></script>

            <script src="/static/js/admin.control.ajax.js"></script>
            <script src="/static/js/admin.ui.usergroup.permissions.js"></script>
{% endblock %}
