{% load signalbox_tags %}
{% memberships participant as participant_memberships %}

<h4>Study memberships</h4>
<table class="table">
    {% if participant_memberships %}
    <tr>
        <th>Study</th>
        <th>Allocated</th>
        {% if perms.signalbox.can_review %}<th>Settings</th>{% endif %}
        <th colspan=2>Observations</th>
        </tr>
        {% for m in participant_memberships %}
        <tr>
                <td>{{m.study.name}}
                    {% if m.relates_to %}(relates to {{m.relates_to.user.username}}){% endif %}
                </td>
                <td><img src="{{STATIC_URL}}icons/icon-{% if m.randomised %}yes{%else%}no{%endif%}.gif"></td>
                {% if perms.signalbox.can_review %}
                <td><a class="btn btn-mini" href="{% url 'admin:signalbox_membership_change' m.id %}">Edit</a></td>
                </td>
                {% endif %}

                <td>
                    <span class="text-info">{{m.incomplete_observations.count}} observations incomplete</span>
                </td>
                <td>
                    <a class="btn btn-mini" href="{% url 'membership_observations_todo' m.id %}">List</a>
                </td>

        </tr>
        {% endfor %}
    {% else %}
        <tr><td>Not participating in any studies</td></tr>
    {% endif %}
        <tr>
                <td colspan=6>
                    <a class="btn btn-primary" href="{% url 'create_membership' user_id=participant.id %}"> Add to a study</a>
                </td>
        </tr>
</table>
