{% extends 'base.html' %}

{% block bodydata %}
data-project-id="{{ project.id }}"
data-project-private="{{ project.isprivate }}"
data-project-locked="{{ project.islocked }}"
data-project-everyone-contributes="{{ project.everyone_contributes }}"
data-usergroup-id="{{ usergroup.id }}"
{% endblock %}

{% block title %} | Project: {{ project.name }} - User group: {{ usergroup.name }} - Permissions{% endblock %}

{% block main %}
<div class="page-header">
    <div class="container">
        <h1 class="smaller">
            {% if project.islocked %}<span class="glyphicon glyphicon-lock" aria-hidden="true"></span>{% endif %}
            <a href="{% url 'admin:project_overview' project.id %}">{{ project.name }}</a>
        </h1>

        {% include 'projects/navigation.html' %}
    </div>
</div>

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

    <div class="row">
        <div class="col-sm-4">
            {% include 'users/usergroup_navigation.html' %}
        </div>

        <div class="col-sm-8">
            <h3 class="header">
                {% if project.islocked %}<span class="glyphicon glyphicon-lock" aria-hidden="true"></span>{% endif %}
                User group permissions
            </h3>

            {% if project.islocked %}
                <div class="alert alert-info">
                    <p>The project is locked, therefore user group permissions cannot be edited. If you wish to edit it, you have to unlock the project in the <a href="{% url 'admin:project_settings' project.id %}"><strong>project settings</strong></a> first.</p>
                </div>
            {% endif %}

            {% if project.everyone_contributes != 'false' and not usergroup.can_contribute %}
                <div class="alert alert-warning hint">
                    <p>Currently, all users{% if not project.isprivate and 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' project.id %}" class="alert-link">project settings</a> first and change the project permissions.</p>
                </div>
            {% endif %}

            <form id="permissions" method="POST" action="{% url 'admin:usergroup_permissions' project.id usergroup.id %}">
                {% csrf_token %}

                <div class="radio">
                    <label>
                        <input type="radio" name="permission" id="read_only" value="read_only" {% if not usergroup.can_contribute and not usergroup.can_moderate %}checked="true"{% endif %} {% if project.islocked %}disabled{% endif %} />
                        <strong>Read only</strong>
                        <p>Members of this user group will only be able to read data from its subsets.</p>
                    </label>
                </div>

                <div class="radio">
                    <label>
                        <input type="radio" name="permission" id="can_contribute" value="can_contribute" {% if usergroup.can_contribute and not usergroup.can_moderate %}checked="true"{% endif %} {% if project.islocked %}disabled{% endif %} />
                        <strong>Contributors</strong>
                        <p>Members of this user group will be able to contribute new data to the project and read data from its subsets.</p>
                    </label>
                </div>

                <div class="radio">
                    <label>
                        <input type="radio" name="permission" id="can_moderate" value="can_moderate" {% if usergroup.can_moderate %}checked="true"{% endif %} {% if project.islocked %}disabled{% endif %} />
                        <strong>Moderators</strong>
                        <p>Members of this user group will be able to contribute new data as well as to read and moderate data from its subsets.</p>
                    </label>
                </div>

                {% if not project.islocked %}
                    <div class="form-group">
                        <button type="submit" class="btn btn-primary">Save</button>
                    </div>
                {% endif %}
            </form>
        </div>
    </div>
</div>
{% endblock %}

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