{# vim: set ts=2 et sts=2 sw=2: #}
{% from "layout/errorlist.html" import errorlist %}
{% if image_form.instance.pk %}
  {% set current_form = image_form %}
{% else %}
  {% set current_form = video_form %}
{% endif %}
<div id="gallery-upload-modal" class="kbox" title="{% if current_form.instance.pk %}{{ _('Continue Uploading Media') }}{% else %}{{ _('Upload a New Media File') }}{% endif %}" data-modal="true" data-target="#btn-upload" data-id="upload-kbox" data-position="none">
  <form id="gallery-upload-type" action="" method="post"{% if current_form.instance.pk %} class="draft"{% endif %}>
    <label class="row-left upload-type">{{ _('Upload') }}</label>
    <div class="row-right upload-type">
      <label><input type="radio" name="upload-type" value="image" checked="checked"> {{ _('Image') }}</label>
      <label><input type="radio" name="upload-type" value="video"> {{ _('Video') }}</label>
    </div>
  </form>
  <form id="gallery-upload-image" class="upload-form {% if image_form.instance.pk %}draft{% endif %}"
    data-post-url="{{ url('gallery.upload_async', media_type='image') }}"
    method="post" enctype="multipart/form-data"
    action="{{ url('gallery.upload', media_type='image') }}">
    {{ csrf() }}
    {{ errorlist(image_form) }}
    <label for="id_file" class="row-left upload-media file">{{ _('Image') }}</label>
    <div class="row-right upload-media file">
      <label for="id_file">{{ _('Select an image file to upload.') }}</label>
      {{ image_form['file']|safe }}
      <div class="details">{{ _('Accepted formats include: PNG, JPEG, GIF. <a target="_blank" href="{learn_more}">Learn more...</a>')|fe(learn_more='http://infohost.nmt.edu/tcc/help/pubs/pil/formats.html') }}</div>
    </div>
    <label class="row-left progress file">{{ _('Progress') }}</label>
    <div class="row-right progress file">
      <span></span>
      <a href="{{ url('gallery.gallery', media_type=media_type) }}">{{ _('Cancel') }}</a>
    </div>
    <label class="row-left preview">{{ _('Preview') }}</label>
    <div class="row-right preview">
      {% if image_form.instance.pk %}
        <div class="image-preview file">
          <img src="{{ image_form.instance.thumbnail_url_if_set() }}">
        </div>
        <input type="submit" name="cancel" class="draft link-btn" data-name="file" data-action="{{ url('gallery.cancel_draft', media_type='image') }}" value="{{ _('Delete this image') }}">
      {% endif %}
    </div>
    {% for field in current_form if field.name in ('title', 'locale', 'description') %}
      <label class="row-left metadata" for="id_{{ field.name }}">{{ field.label }}</label>
      <div class="row-right metadata">
        {% if field.help_text %}
          <div class="details">{{ field.help_text }}</div>
        {% endif %}
        {{ field|safe }}
      </div>
    {% endfor %}
    <div class="upload-action">
      <input type="submit" name="upload" value="{{ _('Submit file') }}">
      <input type="submit" name="cancel" class="kbox-cancel link-btn{% if image_form.instance.pk %} draft{% endif %}" data-action="{{ url('gallery.cancel_draft', media_type='image') }}" value="{{ _('Cancel') }}">
    </div>
  </form>
  <form id="gallery-upload-video" class="upload-form {% if video_form.instance.pk %}draft{% endif %} {% if video_form.instance.pk %}errors{% endif %}"
    data-post-url="{{ url('gallery.upload_async', media_type='video') }}"
    method="post" enctype="multipart/form-data"
    action="{{ url('gallery.upload', media_type='video') }}">
    {{ csrf() }}
    {{ errorlist(video_form) }}
    <label class="row-left upload-media" for="id_flv">{{ _('Video') }}</label>
    <div class="row-right upload-media flv">
      <label for="id_flv">{{ _('Select a Flash video (FLV) to upload.') }}</label>
      {{ video_form['flv']|safe }}
      <div class="details">{{ _('Please no SWFs, only FLVs.') }}</div>
    </div>
    <div class="row-right upload-media ogv">
      <label for="id_ogv">{{ _('Select an Ogv video to upload.') }}</label>
      {{ video_form['ogv']|safe }}
    </div>
    <div class="row-right upload-media webm">
      <label for="id_webm">{{ _('Select a WebM video to upload.') }}</label>
      {{ video_form['webm']|safe }}
    </div>
    <label class="row-left progress flv ogv webm">{{ _('Progress') }}</label>
    <div class="row-right progress flv">
        <span></span>
        <a href="{{ url('gallery.gallery', media_type=media_type) }}">{{ _('Cancel') }}</a>
    </div>
    <div class="row-right progress ogv">
        <span></span>
        <a href="{{ url('gallery.gallery', media_type=media_type) }}">{{ _('Cancel') }}</a>
    </div>
    <div class="row-right progress webm">
        <span></span>
        <a href="{{ url('gallery.gallery', media_type=media_type) }}">{{ _('Cancel') }}</a>
    </div>
    <label class="row-left preview">{{ _('Preview') }}</label>
    <div class="row-right preview">
      <ul>
        {% if video_form.instance.pk %}
          {% if video_form.instance.flv %}
            <li class="video-preview flv">
              {{ video_form.instance.flv.name.rsplit('/', 1)[-1] }}
              <input type="submit" name="cancel" class="draft link-btn" data-name="flv" data-action="{{ url('gallery.cancel_draft', media_type='video')|urlparams(field='flv') }}" value="{{ _('Delete {format} file')|fe(format='flv') }}">
            </li>
          {% endif %}
          {% if video_form.instance.ogv %}
            <li class="video-preview ogv">
              {{ video_form.instance.ogv.name.rsplit('/', 1)[-1] }}
              <input type="submit" name="cancel" class="draft link-btn" data-name="ogv" data-action="{{ url('gallery.cancel_draft', media_type='video')|urlparams(field='ogv') }}" value="{{ _('Delete {format} file')|fe(format='ogv') }}">
            </li>
          {% endif %}
          {% if video_form.instance.webm %}
            <li class="video-preview webm">
              {{ video_form.instance.webm.name.rsplit('/', 1)[-1] }}
              <input type="submit" name="cancel" class="draft kbox-cancel link-btn" data-name="webm" data-action="{{ url('gallery.cancel_draft', media_type='video')|urlparams(field='webm') }}" value="{{ _('Delete {format} file')|fe(format='webm') }}">
            </li>
          {% endif %}
        {% endif %}
      </ul>
    </div>
    <label class="row-left progress thumbnail">{{ _('Progress') }}</label>
    <div class="row-right progress thumbnail">
      <span></span>
      <a href="{{ url('gallery.gallery', media_type=media_type) }}">{{ _('Cancel') }}</a>
    </div>
    <label class="row-left upload-media thumbnail">{{ _('Thumbnail') }}</label>
    <div class="row-right upload-media thumbnail">
      {% if video_form.instance.thumbnail %}
        <div class="image-preview">
          <img src="{{ video_form.instance.thumbnail.url }}"/>
        </div>
        <input type="submit" name="cancel" class="draft link-btn" data-name="thumbnail" data-action="{{ url('gallery.cancel_draft', media_type='video')|urlparams(field='thumbnail') }}" value="{{ _('Delete thumbnail') }}">
      {% endif %}
      <label for="id_thumbnail">{{ _('Upload a thumbnail for your video. Suggested size: {width}x{height}px')|f(width=settings.THUMBNAIL_SIZE, height=settings.THUMBNAIL_SIZE) }}</label>
      {{ video_form['thumbnail']|safe }}
    </div>
    <div class="upload-action">
      <input type="submit" name="upload" value="{{ _('Submit file') }}">
      <input class="kbox-cancel link-btn{% if video_form.instance.pk %} draft{% endif %}"
             data-action="{{ url('gallery.cancel_draft', media_type='video')}}"
             name="cancel" type="submit" value="{{ _('Cancel') }}">
    </div>
  </form>
</div>
