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

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

{% block extra_javascript %}
<script src="{% url telemeta-js "swfobject.js" %}" type="text/javascript"></script>
<script src="{% url telemeta-js "popupdiv.js" %}" type="text/javascript"></script>
<script src="{% url telemeta-js "playlist.js" %}" type="text/javascript"></script>
<script>
    {% if user.is_authenticated %}
    jQuery(document).ready(function(){
        var p = playlistUtils;
        
        {% for playlist in playlists %}
        p.addPlaylist('{{ playlist.playlist.title }}','{{playlist.playlist.public_id}}');
        {% endfor %}

        {% if collection %}
        var anchor = jQuery('#_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="{% url telemeta-images "collections_red.png" %}" style="vertical-align:middle" /> 
    Collection : 
    <a href="{% url telemeta-collection-detail collection.public_id %}">{{ collection.title }}</a>
{% endblock %}

{% block title_buttons %}
  <div class="fixedWidthAsPlayer">
    {% if user.is_authenticated and perms.telemeta.change_mediacollection %}
      <a href="{% url telemeta-collection-edit collection.public_id %}" class="component_icon button icon_edit">{% trans "Edit" %}</a>
      <a href="{% url telemeta-collection-copy collection.public_id %}" class="component_icon button icon_copy">{% trans "Copy" %}</a>
      <a href="{% url telemeta-collection-additem collection.public_id %}" class="component_icon button icon_add">{% trans "Add item" %}</a>
     {% endif %}
    {% if user.is_authenticated %}
    <a href=# id ="_add_to_playlist" class="component_icon button icon_add_to_playlist">{% trans "Add to playlist" %}</a>
    {% endif %}
    <a href="{% url telemeta-collection-dublincore collection.public_id %}" class="component_icon button icon_dublin_core">Dublin Core</a>
   </div>
{% endblock %}

{% block content %}
    <div class="{% if collection.has_mediafile %}{% if public_access or perms.telemeta.can_play_all_items %}with-rightcol{% endif %}{% endif %}">
        {% if collection.has_mediafile %}
        {% if public_access or perms.telemeta.can_play_all_items %}
        <div id="rightcol">
            <div id="collection_player">
             <div class="title">
              <h3><b>{% trans "Listen to this collection" %}</b>
              (<a href="{% url telemeta-collection-m3u collection.public_id %}">M3U</a>,
              <a href="{% url telemeta-collection-xspf collection.public_id %}">XSPF</a>)</h3>
             </div>
                <!-- This is Jeroen Wijering's Flash MP3 Player, 
                  under CC Attribution-NonCommercial-ShareAlike 2.0 license
                  from: http://www.jeroenwijering.com/?item=Flash_MP3_Player-->
                <p id="collection_player_c">
                  <a href="http://www.macromedia.com/go/getflashplayer">Get Flash</a> to see this player.
                </p>
                <script type="text/javascript">
                  var so = new SWFObject('{% url telemeta-swf "mp3player.swf" %}','playlist','362','200','7');
                  so.addVariable("file","{% url telemeta-collection-xspf collection.public_id %}");
                  so.addVariable("displayheight","0");
                  so.addParam("wmode", "opaque");
                  so.write('collection_player_c');
                </script> 
            </div>
        </div>
        {% endif %}
        {% endif %}
      {% block infos %}
        <div class="intro">
            <span><img src="{% 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 %}{% else %}No item{% endif %}</span>
        </div>
        <div class="infos">
        {% block general_info %}
            <dl class="listing">
                {% dl_field collection "reference" %}
                {% dl_field collection "title"  %}
                {% dl_field collection "alt_title" %}
                {% dl_field collection "creator" placeholder %}
                {% 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>
                {% dl_field collection "year_published" placeholder %}
                {% 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 "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 %}
                        {% dl_field collection "publisher" %}
                        {% dl_field collection "publisher_collection" %}
                        {% dl_field collection "publisher_serial" %}
                        {% dl_field collection "booklet_author" %}
                        <dt>{% trans "Bibliographic references" %}</dt>
                        <dd>{{ collection.external_references|html_line_break|safe }}</dd>
                        {% dl_field collection "doctype_code" %}
                        {% dl_field collection "public_access_label" %}
                        {% dl_field collection "legal_rights" %}
                    </dl>
                </div>
            </div>
        {% endblock legal_data %}
        </div>
        <div class="extraInfos">
        {% block archive_data %}
            <div>
                <h4><a href="#">{% trans "Archiving data" %}</a></h4>
                <div>
                    <dl class="listing">
                        {% dl_field collection "acquisition_mode" %}
                        {% dl_field collection "cnrs_contributor" %}
                        {% dl_field collection "metadata_author" %}
                        <dt>{% trans "Related documentation" %}</dt>
                        <dd>{{ collection.booklet_description|html_line_break|safe }}</dd>
                        {% dl_field collection "publishing_status" %}
                        {% dl_field collection "alt_ids" %}
                        <dt>{% trans "Comments" %}</dt>
                        <dd>{{ collection.comment|html_line_break|safe }}</dd>
                        {% dl_field collection "metadata_writer" %}
                        {% dl_field collection "travail" %}
                        {% dl_field collection "items_done" %}
                        {% dl_field collection "conservation_site" %}
                    </dl>
                </div>
            </div>
        {% endblock archive_data %}
        </div>
        <div class="extraInfos">
        {% block technical_data %}
            <div>
                <h4><a href="#">{% trans "Technical data" %}</a></h4>
                <div>
                    <dl class="listing">
                        {% dl_field collection "code" %}
                        {% dl_field collection "old_code" %}
                        <dt>{% trans "Media type" %}</dt><dd>{% trans "Audio" %}</dd>
                        {% dl_field collection "approx_duration" %}
                        {% dl_field collection "computed_duration" %}
                        {% dl_field collection "physical_items_num" %}
                        <div class="wazing"></div>
                        <dt>{% trans "Number of items" %}</dt><dd>{{ collection.items.count }}</dd>
                        {% dl_field collection "physical_format" %}
                        {% dl_field collection "ad_conversion" %}
                    </dl>
                </div>
            </div>
        {% endblock technical_data %}
        </div>
        
        <div class="extraInfos">
            {% block related %}
                {% include "telemeta/inc/collection_related.html" %}
            {% endblock related %}
        </div>
        
        <div class="extraInfos">
        <h4><img src="{% 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>
{% endblock %}

{% 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;"
        class="component_icon button icon_delete" style="float:right;margin-top:0.5em;margin-bottom:1em">{% trans "Delete" %}</a>
{% endif %}

{% endblock %}

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

