{% load i18n djinn_core %}

<div class="fileupload">
  <div class="btn fileinput-button">
    <i class="icon-plus icon-white"></i>

    {% if button_label %}
    <span>{{ button_label }}</span>
    {% else %}
    {% if multiple %}
    <span>{% trans "Select images" %}</span>
    {% else %}
    {% if attachments %}
    <span>{% trans "Replace image" %}</span>
    {% else %}
    <span>{% trans "Select image" %}</span>
    {% endif %}
    {% endif %}
    {% endif %}

    <input type="file" 
           {% if multiple %}
           multiple="true"
           {% endif %}
           name="{{ name }}_upload"
           {% if show_progress %}
           data-progress="#progress_{{ name }}"
           {% endif %}
           data-attachmenttype="{{ attachment_type }}"
           data-valuefield="#id_{{ name }}"
           data-uploadurl="{{ upload_url }}"
           data-target="#uploads_{{ name }}" />

    <input id="id_{{ name }}" name="{{ name }}" type="hidden" 
           value="{{ value }}" />

  </div>

  {% if show_progress %}
  <div id="progress_{{ name }}" 
       class="progress progress-info hide">
    <div class="bar"></div>
  </div>
  {% endif %}

  <ul class="unstyled uploaded-files" id="uploads_{{ name }}">
    
    {% for att in attachments %}
    <li class="editable">

      <img src="{{ att.get_thumbnail_url }}" />
      {{ att.title }}
      
      <span class="controls pull-right">
        <a class="edit-inline"
           {% if att|implements:"pgcontent.models.attachment.ImageAttachment" %}
           href="{% url 'pgcontent_edit_imageattachment' att.id %}"
           {% else %}
           href="{% url 'djinn_contenttypes_edit_imgattachment' att.id %}"
           {% endif %}
           >
          Aanpassen
        </a>
        <a class="rm-inline"
           data-pu_callback="djinn.forms.remove_attachment:{{ att.id }}"
           {% if att|implements:"pgcontent.ImageAttachment" %}
           href="{% url 'pgcontent_delete_imageattachment' att.id %}"
           {% else %}
           href="{% url 'djinn_contenttypes_delete_imgattachment' att.id %}"
           {% endif %}
           >
          Verwijderen
        </a>
      </span>
      
    </li>
    {% endfor %}
  </ul>

</div>
