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

{% block head_title %}{% trans type %}{{resource|prepend:' : '}} - {{ block.super }}{% endblock %}

{% block extra_javascript %}
<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 %}
jQuery(document).ready(function(){
    var p = playlistUtils;

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

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

{% if resource %}

{% block title %}
    <img src="{{ STATIC_URL }}telemeta/images/{{ type }}.png" style="vertical-align:middle" />
    {{ type|capitalize }} : {{ resource.title }}
{% endblock %}

{% block title_buttons %}
<div class="fixedWidthAsPlayer">
    {% if perms.telemeta.change_mediacorpus or perms.telemeta.change_mediafonds %}
    <a href="{% url "telemeta-resource-edit" type resource.public_id %}">
      <button type="button" class="btn btn-default">
        <span class="glyphicon glyphicon-edit"></span> {% trans "Edit" %}
      </button>
    </a>
    <a href="{% url "telemeta-resource-copy" type resource.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 type == 'corpus' and user.is_superuser %}
    <a id="_export_epub" href="{% url "telemeta-resource-password-epub" type resource.public_id %}">
      <button type="button" class="btn btn-default">
        <span class="glyphicon glyphicon-book"></span> {% trans "Epub" %}
      </button>
    </a>
    {% endif %}
</div>
{% endblock %}

{% block content %}
      {% block infos %}
        <div class="intro">
        </div>

        <div class="infos">
        {% block general_info %}
            <dl class="listing">
              {% for field in resource.get_fields %}
               {% if "id" in field.name or "description" == field.name or "public_access" == field.name %}
                {{ field.label_tag.as_hidden }}{{ field.as_hidden }}
               {% elif field.get_internal_type == 'TextField' %}
                 <dt>{% trans field.verbose_name|capitalize %}</dt>
                 <dd>{{ resource|get_attr:field.name|html_line_break|safe }}</dd>
               {% else %}
                {% dl_field resource field.name %}
               {% endif %}
              {% endfor %}
              {% dl_field resource "computed_duration" %}
              {% 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 %}
              {% 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>

        {% endblock general_info %}

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

        <div class="extraInfos">
        <h4><img src="{{ STATIC_URL }}telemeta/images/item_title.png" style="vertical-align:middle" />{{resource.children_type|capitalize }} </h4>
        {% with resource.children.all as children %}
            {% include "telemeta/inc/children_list.html" %}
        {% endwith %}
        </div>

      </div>
    {% endblock infos %}

    {% block dublincore %}
    <a href="{% url "telemeta-resource-dublincore" type resource.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_mediaresource %}
    <a href="#" onclick="if(confirm(gettrans('delete the item permanently?'))){window.location.href='{% url "telemeta-resource-delete" type resource.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 delete %}

{% else %}
    <p>{% trans "No such resource" %}</p>
{% endif %}

