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

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

{% block extra_javascript %}
<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 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="{% url telemeta-type-images type %}" style="vertical-align:middle" />
    {{ type|capitalize }} :
    <a href="{% url telemeta-resource-detail type resource.public_id %}">{{ resource.title }}</a>
{% endblock %}

{% block title_buttons %}
  <div class="fixedWidthAsPlayer">
    {% if user.is_authenticated and perms.telemeta.change_mediaresource %}
      <a href="{% url telemeta-resource-edit type resource.public_id %}" class="component_icon button icon_edit">{% trans "Edit" %}</a>
      <a href="{% url telemeta-resource-copy type resource.public_id %}" class="component_icon button icon_copy">{% trans "Copy" %}</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-resource-dublincore type resource.public_id %}" class="component_icon button icon_dublin_core">Dublin Core</a>
   </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 %}
                {{ field.label_tag.as_hidden }}{{ field.as_hidden }}
               {% else %}
                {% dl_field resource field.name %}
               {% endif %}
              {% endfor %}
              {% 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 class="extraInfos">
            {% block related %}
                {% include "telemeta/inc/resource_related.html" %}
            {% endblock related %}
        </div>

        <div class="extraInfos">
        <h4><img src="{% 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>

        {% endblock infos %}
    </div>
{% endblock %}

{% block delete %}
{% if user.is_authenticated and perms.telemeta.delete_mediaresource %}
 <a href="#" onclick="if(confirm(gettrans('delete the resource permanently?'))){window.location.href='{% url telemeta-resource-delete type resource.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>{% trans "No such resource" %}</p>
{% endif %}

