{# vim: set ts=2 et sts=2 sw=2: #}
{% extends "base.html" %}
{% if not title %}
  {% set title = _('{title} | Media Gallery')|f(title=media.title) %}
{% endif %}
{% set styles = ('gallery',) %}
{% set scripts = ('wiki',) %}
{% if not crumbs %}
  {% set crumbs = [(url('gallery.gallery', media_type), _('Media Gallery')),
                   (None, media.title)] %}
{% endif %}
{% if media_type == 'image' %}
  {% set delete_this = _('Delete this image') %}
  {% set edit_this = _('Edit this image') %}
{% else %}
  {% set delete_this = _('Delete this video') %}
  {% set edit_this = _('Edit this video') %}
{% endif %}

{% block content %}
  <article id="media-object" class="main">
    <h1>{{ media.title|truncate(length=55, killwords=True) }}</h1>
    {% if user.is_authenticated() %}
      <a id="btn-upload" class="btn-upload" href="{{ url('gallery.gallery', media_type)|urlparams(hash='upload') }}">{{ _('Upload a New Media File') }}</a>
    {% endif %}
    <div id="media-metainfo">
      <ul id="media-info">
        {% if media_type =='image' %}
          <li class="dimensions">
            {{ media.file.width }} x {{ media.file.height }} px
          </li>
          <li class="size">
            {{ media.file.size // 1024 }} KB
          </li>
        {% else %}{# video #}
          {% if media.flv %}
            <li class="format-flv">
              FLV ({{ media.flv.size // 1024 }} KB)
            </li>
          {% endif %}
          {% if media.ogv %}
            <li class="format-ogv">
              OGV ({{ media.ogv.size // 1024 }} KB)
            </li>
          {% endif %}
          {% if media.webm %}
            <li class="format-webm">
              WEBM ({{ media.webm.size // 1024 }} KB)
            </li>
          {% endif %}
        {% endif %}
        {% if media_format %}
          <li class="format">{{ media_format|upper }}</li>
        {% endif %}
      </ul>
      <ul id="media-meta">
        <li class="creator">{{ _('by {user}')|f(user=media.creator) }}</li>
        <li class="created">{{ _('Uploaded {date}')|fe(date=datetimeformat(media.created, format='datetime')) }}</li>
        <li class="locale">{{ settings.LANGUAGES[media.locale.lower()] }}</li>
      </ul>
    </div>
    <div id="media-view">
      {% if media_type == 'image' %}
        <img src="{{ media.file.url }}" alt="{{ media.title }}" />
      {% else %}
        {{ generate_video(media) }}
      {% endif %}
    </div>
    <div class="description">{{ media.description|wiki_to_html }}</div>
    <form id="media-actions" action="{{ url('gallery.delete_media', media_type, media.pk) }}" method="GET">
      {% if user == media.creator or
            (media_type == 'image' and user.has_perm('gallery.delete_image')) or
            (media_type == 'video' and user.has_perm('gallery.delete_video')) %}
        <input type="submit" value="{{ delete_this }}" />
      {% endif %}
      {% if user == media.creator or
            (media_type == 'image' and user.has_perm('gallery.change_image')) or
            (media_type == 'video' and user.has_perm('gallery.change_video')) %}
        <a href="{{ url('gallery.edit_media', media_type, media.id) }}">{{ edit_this }}</a>
      {% endif %}
    </form>
  </article>
{% endblock %}
