{% load i18n %}
{% load common_filters %}


{% comment %}
<!--
  Copyright (C) 2011 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 %}

{% block link %}

<style type="text/css">
    #hierarchyTree a .jstree-icon {
        background-position: 100px 100px;   /* clear background */
    }
    #hierarchyTree ins {
        background: none !important;
    }
</style>
{% endblock %}


{% block content %}

<div id="hierarchyTree" class="jstree jstree-default">
    {% if manager.image.countParents %}
    <ul>
      <!-- check if image is in a Plate -->
      {% with plate=manager.image.getPlate %}
        {% if plate %}
          <li rel="plate">
            <a href="{% url 'webindex' %}?show=plate-{{ plate.id }}">
              <ins class="jstree-icon">
                  <img src="{% static "webclient/image/folder_plate16.png" %}"/>
              </ins>{{ plate.name|truncatebefor:"35" }}
            </a>
            {% if plate.countParents %}
            <ul>
              {% for screen in plate.listParents %}
                <li rel="screen" class="jstree-last jstree-leaf">
                  <a href="{% url 'webindex' %}?show=screen-{{ screen.id }}">
                    <ins class="jstree-icon">
                        <img src="{% static "webclient/image/folder_screen16.png" %}"/>
                    </ins>{{ screen.name|truncatebefor:"35" }}
                  </a>
                </li>
              {% endfor %}
            </ul>
            {% endif %}
          </li>
        {% endif %}
      {% endwith %}

      <!-- Also check if image is in Datasets (can be in both) -->
      {% for c in manager.image.listParents %}
        {% if c.OMERO_CLASS == 'Dataset' %}
            <li rel="dataset" class="clear jstree-last {% if c.countParents %}jstree-open{% else %}jstree-leaf{% endif %}">
                <a href="{% url 'webindex' %}?show=dataset-{{ c.id }}">
                    <ins class="jstree-icon">
                        <img src="{% static "webclient/image/folder_image16.png" %}"/>
                    </ins>{{ c.name|truncatebefor:"35" }}
                </a>
                {% if c.countParents %}
                <ul>
                    {% for d in c.listParents %}
                        <li rel="project" class="jstree-last jstree-leaf">
                            <a href="{% url 'webindex' %}?show=project-{{ d.id }}">
                                <ins class="jstree-icon">
                                    <img src="{% static "webclient/image/folder16.png" %}"/>
                                </ins>{{ d.name|truncatebefor:"35" }}
                            </a>
                        </li>
                    {% endfor %}
                </ul>
                {% endif %}
            </li>
        {% endif %}
      {% endfor %}
    </ul>
    {% else %}
        <p>{% trans "Image is not contained in any datasets." %}</a>
    {% endif %}
</div>

{% endblock %}