{% extends "telemeta/base.html" %}
{% load i18n %}
{% load telemeta_tags %}

{% block head_title %}{% trans "Collection" %}{{collection|prepend:' : '}} - {{ block.super }}{% endblock %}

{% block extra_javascript %}
<script src="{{ STATIC_URL }}telemeta/js/swfobject.js" type="text/javascript"></script>
<script src="{{ STATIC_URL }}telemeta/js/popupdiv.js" type="text/javascript"></script>
<script src="{{ STATIC_URL }}telemeta/js/playlist.js" type="text/javascript"></script>
<script>
    {% if user.is_authenticated %}
    $(document).ready(function(){
        var p = playlistUtils;

        {% for playlist in playlists %}
        p.addPlaylist('{{ playlist.playlist.title }}','{{playlist.playlist.public_id}}');
        {% endfor %}

        {% if collection %}
        var anchor = $('#_add_to_playlist');
        if(anchor.length){
        anchor.click(function(){
            p.showAddResourceToPlaylist(anchor,'collection','{{collection.id}}',gettrans('collection added to the selected playlist'));return false;
        });
        }
        {% endif %}
    });
    {% endif %}
</script>
{% endblock %}

{% if collection %}

{% block title %}
    <img src="{{ STATIC_URL }}telemeta/images/collections_red.png" style="vertical-align:middle" />
    Collection : {{ collection.title }}
{% endblock %}

{% block title_buttons %}
  <div>
    {% if user.is_authenticated and perms.telemeta.change_mediaitem %}
    <a href="{% url "telemeta-collection-edit" collection.public_id %}">
      <button type="button" class="btn btn-default">
        <span class="glyphicon glyphicon-edit"></span> {% trans "Edit" %}
      </button>
    </a>
    <a href="{% url "telemeta-collection-copy" collection.public_id %}">
      <button type="button" class="btn btn-default">
        <span class="glyphicon glyphicon-new-window"></span> {% trans "Copy" %}
      </button>
    </a>
    {% endif %}
    {% if user.is_authenticated %}
    <a id="_add_to_playlist" href='#'>
      <button type="button" class="btn btn-default">
        <span class="glyphicon glyphicon-pushpin"></span> {% trans "List" %}
      </button>
    </a>
    {% endif %}
    {% if user.is_authenticated and perms.telemeta.change_mediacollection %}
    <a href="{% url "telemeta-collection-additem" collection.public_id %}">
      <button type="button" class="btn btn-default">
        <span class="glyphicon glyphicon-plus"></span> {% trans "Add item" %}
      </button>
    </a>
    {% if audio_export_enabled or perms.telemeta.can_download_all_items or user.is_superuser %}
    <a href="{% url "telemeta-collection-zip" collection.public_id %}" id="zip_package">
      <button type="button" class="btn btn-default">
        <span class="glyphicon glyphicon-compressed"></span> {% trans "Zip" %}
      </button>
    </a>
    {% endif %}
    {% if user.is_superuser %}
    <a id="_export_epub" href="{% url "telemeta-collection-epub" collection.public_id %}">
      <button type="button" class="btn btn-default">
        <span class="glyphicon glyphicon-book"></span> {% trans "Epub" %}
      </button>
    </a>
    {% endif %}
    {% endif %}
   </div>
{% endblock %}

{% block content %}
    <div class="{% if collection.has_mediafile %}{% if public_access == 'full' or perms.telemeta.can_play_all_items %}with-rightcol{% endif %}{% endif %}">
      {% block infos %}
        <div class="intro">
            <span><img src="{{ STATIC_URL }}telemeta/images/item_title.png" style="vertical-align:middle" /> {% if collection.items.count %}{{ collection.items.count }} {% ifequal collection.items.count 1 %}item{% else %}items{% endifequal %} (<a href="#item_list">{% trans "View list" %}</a>){% else %}No item{% endif %}</span>
        </div>

        <div class="infos">
        {% block general_info %}
            <dl class="listing">
                {% dl_field collection "title"  %}
                {% dl_field collection "alt_title" %}
                {% if collection.creator %}
                {% dl_field collection "creator" placeholder %}
                {% endif %}
                <dt>{% trans "Document status" %}</dt>
                <dd>{{ collection.document_status }}</dd>
                {% if collection.description %}
                <dt>{% trans "Description" %}</dt>
                <dd>{{ collection.description|html_line_break|safe }}</dd>
                {% endif %}
                {% dl_field collection "recording_context" %}
                <dt>{% trans "Recording period" %}</dt>
                    <dd>{% if collection.recorded_from_year %}{{ collection.recorded_from_year }}{% endif %}{% if collection.recorded_from_year and collection.recorded_to_year %} - {% endif %}{% if  collection.recorded_to_year %}{{ collection.recorded_to_year}}{% endif %}</dd>
                {% if '_E_' in collection.public_id %}
                {% dl_field collection "year_published" placeholder %}
                {% endif %}
                <dt>{% trans "Access type" %}</dt>
                <dd>{% trans collection.public_access %}</dd>
                {% for parent in parents %}
                <dt>{% trans parent.element_type|capitalize %}</dt>
                <dd><a href="{% url "telemeta-resource-detail" parent.element_type parent.public_id %}">{{ parent.title }}</a></dd>
                {% endfor %}
            </dl>
        {% endblock general_info %}
        </div>
        <div class="extraInfos">
        {% block geoethnic_data %}
            <div>
                <h4><a href="#">{% trans "Geographic and cultural informations" %}</a></h4>
                <div>
                    <dl class="listing">
                        {% dl_field collection "main_countries" join with ", " %}
                        {% dl_field collection "ethnic_groups" join with ", " placeholder %}
                    </dl>
                </div>
            </div>
        {% endblock geoethnic_data %}
        </div>
        <div class="extraInfos">
        {% block legal_data %}
            <div>
                <h4><a href="#">{% trans "Legal notices" %}</a></h4>
                <div>
                    <dl class="listing">
                        {% if collection.collector_is_creator %}
                          {% if collection.creator %}
                          <dt>{% trans "Recordist" %}</dt><dd>{{ collection.creator }}</dd>
                          {% endif%}
                        {% else %}
                        {% dl_field collection "collector" %}
                        {% endif %}
                        {% if collection.publisher %}
                        {% dl_field collection "publisher" %}
                        {% endif %}
                        {% dl_field collection "publisher_collection" %}
                        {% dl_field collection "publisher_serial" %}
                        {% dl_field collection "booklet_author" %}
                        {% if '_E_' in collection.public_id %}
                        {% dl_field collection "reference" %}
                        {% endif %}
                        {% if collection.external_references %}
                        <dt>{% trans "Bibliographic references" %}</dt>
                        <dd>{{ collection.external_references|html_line_break|safe }}</dd>
                        {% endif %}
                        {% dl_field collection "legal_rights" %}
                    </dl>
                </div>
            </div>
        {% endblock legal_data %}
        </div>
        <div class="extraInfos">
        {% block archive_data %}
            <div class="folded">
                <h4><a href="#">{% trans "Archiving data" %}</a></h4>
                <div>
                    <dl class="listing">
                        {% dl_field collection "code" %}
                        {% dl_field collection "old_code" %}
                        {% dl_field collection "acquisition_mode" %}
                        {% dl_field collection "cnrs_contributor" %}
                        {% dl_field collection "copy_type" %}
                        {% dl_field collection "metadata_author" %}
                        {% if collection.booklet_description %}
                         <dt>{% trans "Related documentation" %}</dt>
                         <dd>{{ collection.booklet_description|html_line_break|safe }}</dd>
                        {% endif %}
                        {% dl_field collection "publishing_status" %}
                        {% dl_field collection "status" %}
                        {% if collection.alt_copies %}
                         {% dl_field collection "alt_copies" %}
                        {% endif %}
                        <dt>{% trans "Comments" %}</dt>
                        <dd>{{ collection.comment|html_line_break|safe }}</dd>
                        {% dl_field collection "metadata_writer" %}
                        {% if last_revision %}
                        <dt>{% trans "Last modification" %}</dt>
                        <dd>{{ last_revision.time }} {% if user.is_authenticated %}(<a href="{% url "telemeta-profile-detail" last_revision.user.username %}">{{last_revision.user.username}}</a>){% endif %}</dd>
                        {% endif %}
                        {% dl_field collection "archiver_notes" %}
                        {% dl_field collection "items_done" %}
                        {% dl_field collection "conservation_site" %}
                    </dl>
                </div>
            </div>
        {% endblock archive_data %}
        </div>
        <div class="extraInfos">
        {% block technical_data %}
            <div class="folded">
                <h4><a href="#">{% trans "Technical data" %}</a></h4>
                <div>
                    <dl class="listing">
                        {% dl_field collection "media_type" %}
                        {% if not collection.computed_duration %}
                        {% dl_field collection "approx_duration" %}
                        {% endif %}
                        {% dl_field collection "computed_duration" %}
                        <dt>{% trans "Collection size" %}</dt>
                            <dd>{{ collection.computed_size|filesizeformat }}</dd>
                        {% dl_field collection "physical_items_num" %}
                        <div class="wazing"></div>
                        <dt>{% trans "Number of items" %}</dt>
                            <dd>{{ collection.items.count }}</dd>
                        {% dl_field collection "original_format" %}
                        {% if collection.physical_format %}
                        {% dl_field collection "physical_format" %}
                        {% endif %}
                        {% dl_field collection "ad_conversion" %}
                    </dl>
                </div>
            </div>
        {% endblock technical_data %}
        </div>

        {% if related_media %}
        <div class="extraInfos">
            {% block related %}
                {% include "telemeta/inc/collection_related.html" %}
            {% endblock related %}
        </div>
        {% endif %}

        <div class="extraInfos" id="item_list">
        <h4><img src="{{ STATIC_URL }}telemeta/images/item_title.png" style="vertical-align:middle" /> Items</h4>
        {% with "1" as location_name %}
            {% include "telemeta/inc/mediaitem_list.html" %}
        {% endwith %}
        </div>

        {% endblock infos %}
    </div>

    {% block dublincore %}
    <a href="{% url "telemeta-collection-dublincore" collection.public_id %}" style="float:left;margin-top:0.5em;margin-bottom:1em">
      <button type="button" class="btn btn-default">
        <img src="{{ STATIC_URL}}telemeta/images/dublin_core.png" /> Dublin Core
      </button>
    </a>
    {% endblock dublincore %}

{% endblock content %}

{% block delete %}
{% if user.is_authenticated and perms.telemeta.delete_mediacollection %}

    <a href="#" onclick="if(confirm(gettrans('delete the collection permanently?'))){window.location.href='{% url "telemeta-collection-delete" collection.public_id %}';};return false;" style="float:right;margin-top:0.5em;margin-bottom:1em">
      <button type="button" class="btn btn-default">
        <span class="glyphicon glyphicon-trash"></span> {% trans "Delete" %}
      </button>
    </a>

{% endif %}
{% endblock %}

{% else %}
    <p>No such collection</p>
{% endif %}
