{% 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 %}

<h1>Choose target {{ target_type|capfirst }} in new Group:</h1>

<div id="hierarchyTree" class="jstree jstree-default">
    <ul>
    {% if target_type == 'project' %}
        {% if not manager.containers.projects %}<li>[No Projects in Group]</li>{% endif %}
        {% for d in manager.containers.projects %}
            <li id='project-{{ d.id }}' rel="project" class="jstree-last jstree-leaf jstree-closed">
                <ins class="jstree-icon" style="height:10px">
                    {% if d.countChildren_cached %}<img src="{% static 'webgateway/img/folder_closed.png' %}" />{% endif %}
                </ins>
                <a hre="#">
                    <img src="{% static "webclient/image/folder16.png" %}"/>
                    {{ d.name|truncatebefor:"35" }}
                    {% if d.countChildren_cached %}
                        <span class="children_count">{{ d.countChildren_cached}}</span>
                    {% endif %}
                </a>
            {% if target_type == 'dataset' %}
                <ul>
                {% for c in d.listChildren %}
                    <li id='dataset-{{ c.id }}' rel="dataset" class="clear jstree-last jstree-open jstree-leaf">
                        <ins class="jstree-icon" style="height:10px"></ins>
                        <a hre="#">
                            <img src="{% static "webclient/image/folder_image16.png" %}"/>
                            {{ c.name|truncatebefor:"35" }}
                            {% if c.countChildren_cached %}
                                <span class="children_count">{{ c.countChildren_cached }}</span>
                            {% endif %}
                        </a>
                    </li>
                {% endfor %}
                </ul>
            {% endif %}
            </li>
        {% endfor %}
    {% endif %}

    <!-- Orphaned datasets (if target=='dataset') -->
    {% if target_type == 'dataset' %}
        {% if not manager.containers.datasets %}<li>[No Datasets in Group]</li>{% endif %}
        {% for c in manager.containers.datasets %}
            <li id='dataset-{{ c.id }}' rel="dataset" class="clear jstree-last">
                <ins class="jstree-icon" style="height:10px"></ins>
                <a hre="#">
                    <img src="{% static "webclient/image/folder_image16.png" %}"/>
                    {{ c.name|truncatebefor:"35" }}
                    {% if c.countChildren_cached %}
                        <span class="children_count">{{ c.countChildren_cached }}</span>
                    {% endif %}
                </a>
            </li>
        {% endfor %}
    {% endif %}

    <!-- Screens (if target=='screen') -->
    {% if target_type == 'screen' %}
        {% if not manager.containers.screens %}<li>[No Screens in Group]</li>{% endif %}
        {% for c in manager.containers.screens %}
            <li id='screen-{{ c.id }}' rel="screen" class="clear jstree-last">
                <ins class="jstree-icon" style="height:10px"></ins>
                <a hre="#">
                    <img src="{% static "webclient/image/folder_screen16.png" %}"/>
                    {{ c.name|truncatebefor:"35" }}
                    {% if c.countChildren_cached %}
                        <span class="children_count">{{ c.countChildren_cached }}</span>
                    {% endif %}
                </a>
            </li>
        {% endfor %}
    {% endif %}
    </ul>
</div>