{% extends "admin/base.html" %}

{% block main %}
{% include "admin/snippets/path.html" %}
<h2>Edit {{ doc_type }}</h2>
{% if form %}
<form action="" method="post" enctype="multipart/form-data">
    <table>
        {{ form.as_table }}
    </table>

    {% if doc_item.attachments %}
    <h2>Attachments</h2>
    {% if document.attachments %}
    <table border="1">
        <thead>
            <tr>
                <th>File</th>
                <th>Size</th>
                <th>Type</th>
                <th>Code</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            {% for name, data in document.attachments.iteritems %}
            <tr>
              <td><a href="{% url couchdb:attachment app=app.name doc_type=doc_type doc_id=document.id filename=name %}">{{ name }}</a></td>
              <td>{{ data.length|filesizeformat }}</td>
              <td>{{ data.content_type }}</td>
              <td>
                  {% templatetag openblock %} image "{{ name }}" ["title" ["width" ["height"]]] {% templatetag closeblock %}<br/>
                  {% templatetag openblock %} attachment "{{ name }}" {% templatetag closeblock %}<br/>
              </td>
              <td><a href="{% url couchdb:attachment_delete app=app.name doc_type=doc_type doc_id=document.id filename=name %}">x</a></td>
            </tr>
            {% endfor %}
        </tbody>
    </table>

    {% endif %}

    <input type="file" name="file1" /><br/>
    <input type="file" name="file2" /><br/>
    <input type="file" name="file3" /><br/>
    {% endif %}

    <br/>
    <input type="submit" value="Save"/>

</form>
{% else %}
<div class="notice">No form for &laquo;{{ app.name }}.{{ doc_type }}&raquo; provided. Using default output.</div>
<ul>
{% for key, value in document.items %}
    <li><strong>{{ key }}</strong>: {{ value }}</li>
{% endfor %}
</ul>
{% endif %}


<a href="{% url couchdb:document_delete app=app.name doc_type=doc_type doc_id=doc_id %}">Delete</a>
{% endblock %}
