{% load common_tags %}

{% comment %}
<!--
  Copyright (C) 2014 University of Dundee & Open Microscopy Environment.
  All rights reserved.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
{% endcomment %}

<ul id="groupList" class="submenu" style="box-shadow:0 0 0 white; top:0; bottom:0; overflow-y: auto; overflow-x: hidden; position: relative; float: left; width:220px">

{% if ome.is_admin %}
    <li class="non_selectable"><strong>My Groups</strong></li>
{% endif %}

{% for grp in myGroups %}
    <li {% if grp.id == eContext.context.groupId %}class="current_group"{% endif %}>
        {% if grp.id == ome.active_group %}
            <a href="#" data-gid="{{ grp.id }}">
        {% else %}
            <a href="{% url 'change_active_group' %}?active_group={{grp.id}}" data-gid="{{ grp.id }}">
        {% endif %}
            <img
            {% if grp.getDetails.getPermissions.isGroupWrite %} src="{% static 'webclient/image/group_green16.png' %}"
            {% else %}
                {% if grp.getDetails.getPermissions.isGroupAnnotate %} src="{% static "webclient/image/group_orange16.png" %}"
                {% else %}
                    {% if grp.details.permissions.isGroupRead %} src="{% static "webclient/image/group_red16.png" %}"
                    {% else %}
                        src="{% static "webclient/image/personal16.png" %}"
                    {% endif %}
                {% endif %}
            {% endif %} />
            {{ grp.getName }}
        </a>
    </li>
{% endfor %}

{% if ome.is_admin %}
    <li class="non_selectable"><strong>ALL Groups</strong></li>

    {% for grp in groups %}
        <li {% if grp.id == eContext.context.groupId %}class="current_group"{% endif %}>
            <a href="{% url 'change_active_group' %}?active_group={{grp.id}}&url={{ current_url }}?experimenter=-1" data-gid="{{ grp.id }}">
                <img
                {% if grp.getDetails.getPermissions.isGroupWrite %} src="{% static 'webclient/image/group_green16.png' %}"
                {% else %}
                    {% if grp.getDetails.getPermissions.isGroupAnnotate %} src="{% static "webclient/image/group_orange16.png" %}"
                    {% else %}
                        {% if grp.details.permissions.isGroupRead %} src="{% static "webclient/image/group_red16.png" %}"
                        {% else %}
                            src="{% static "webclient/image/personal16.png" %}"
                        {% endif %}
                    {% endif %}
                {% endif %} />
                {{ grp.getName }}
            </a>
        </li>
    {% endfor %}
{% endif %}
</ul>


{% for grp in groups %}
            <ul title="Switch to this Group and User" class="usersList" id="groupMembers-{{ grp.id }}" style="top:0px">
                {% if ui.dropdown_menu.everyone.enabled and grp.all %}
                    <li>
                        {% if grp.id == active_group.id %}
                        <a href="{{ current_url }}?experimenter=-1">
                            <!-- otherwise we switch group too -->
                        {% else %}
                        <a href="{% url 'change_active_group' %}?active_group={{grp.id}}&url={{ current_url }}?experimenter=-1">
                        {% endif %}
                        {{ ui.dropdown_menu.everyone.label }}
                        </a>
                    </li>
                {% endif %}
                
                {% if ui.dropdown_menu.leaders.enabled and grp.leaders %}
                    <li class="non_selectable"><strong>{{ ui.dropdown_menu.leaders.label }}</strong></li>
                    {% for user in grp.leaders %}
                        <li {% if user.id == experimenter %}class="current_user"{% endif %}>
                            <!-- if this user is in current group, we just switch user -->
                            {% if grp.id == active_group.id %}
                            <a href="{{ current_url }}?experimenter={{user.id}}">
                            <!-- otherwise we switch group too -->
                            {% else %}
                            <a href="{% url 'change_active_group' %}?active_group={{grp.id}}&url={{ current_url }}?experimenter={{user.id}}">
                            {% endif %}
                            {{ user.getFullName }}
                            </a>
                        </li>
                    {% endfor %}
                {% endif %}
                
                {% if ui.dropdown_menu.colleagues.enabled and grp.colleagues %}
                    <li class="non_selectable"><strong>{{ ui.dropdown_menu.colleagues.label }}</strong></li>
                    {% for user in grp.colleagues %}
                        <li {% if user.id == experimenter %}class="current_user"{% endif %}>
                            {% if grp.id == active_group.id %}
                            <a href="{{ current_url }}?experimenter={{user.id}}">
                            {% else %}
                            <a href="{% url 'change_active_group' %}?active_group={{grp.id}}&url={{ current_url }}?experimenter={{user.id}}">
                            {% endif %}
                                {{ user.getFullName }}
                            </a>
                        </li>
                    {% endfor %}
                {% endif %}
            </ul>
{% endfor %}

<div style="clear:both"></div>

