<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="layout.html" />
  <xi:include href="macros.html" />
  <head>
    <title>Attachment</title>
  </head>

  <body py:with="parent = attachments and attachments.parent or
                          attachment.resource.parent">
    <div py:choose="mode" id="content" class="attachment">
      <py:when test="'new'">
        <h1>Add Attachment to <a href="${url_of(parent)}">${name_of(parent)}</a></h1>
        <form id="attachment" method="post" enctype="multipart/form-data" action="">
          <div class="field">
            <label>File<py:if test="max_size >= 0"> (size limit
                  ${pretty_size(max_size, format='%d')})</py:if>:<br />
              <input type="file" name="attachment" /></label>
          </div>
          <fieldset>
            <legend>Attachment Info</legend>
            <py:if test="authname == 'anonymous'">
              <div class="field">
                <label>Your email or username:<br />
                  <input type="text" name="author" size="30" value="$author" />
                </label>
              </div>
              </py:if>
            <div class="field">
              <label>Description of the file (optional):<br />
                <input type="text" name="description" size="60" /></label>
            </div>
            <br />
            <py:if test="authname and authname != 'anonymous'">
              <div class="options">
                <label><input type="checkbox" name="replace" />
                  Replace existing attachment of the same name</label>
              </div>
              <br />
            </py:if>
          </fieldset>
          <div class="buttons">
            <input type="hidden" name="action" value="new" />
            <input type="hidden" name="realm" value="$parent.realm" />
            <input type="hidden" name="id" value="$parent.id" />
            <input type="submit" value="Add attachment" />
            <input type="submit" name="cancel" value="Cancel" />
          </div>
        </form>
      </py:when>

      <py:when test="'delete'">
        <h1><a href="${url_of(parent)}">${name_of(parent)}</a>: $attachment.filename</h1>
        <p><strong>Are you sure you want to delete this attachment?</strong><br />
          This is an irreversible operation.</p>
        <div class="buttons">
          <form method="post" action="">
            <div id="delete">
              <input type="hidden" name="action" value="delete" />
              <input type="submit" name="cancel" value="Cancel" />
              <input type="submit" value="Delete attachment" />
            </div>
          </form>
        </div>
      </py:when>

      <py:when test="'list'">
        <h1><a href="${url_of(parent)}">${name_of(parent)}</a></h1>
        <py:with vars="context = context(parent)">
          ${list_of_attachments(attachments, add_button_title=_("Attach another file"))}
        </py:with>
      </py:when>

      <py:otherwise> <!--! 'render' mode -->
        <h1><a href="${url_of(parent)}">${name_of(parent)}</a>: $attachment.filename</h1>
        <table id="info" summary="Description">
          <tbody>
            <tr>
              <th scope="col">
                File $attachment.filename, ${sizeinfo(attachment.size)}
                (added by ${authorinfo(attachment.author)},  ${dateinfo(attachment.date)} ago)
              </th>
            </tr>
            <tr>
              <td class="message searchable" xml:space="preserve">
                ${wiki_to_html(context(parent), attachment.description)}
              </td>
            </tr>
          </tbody>
        </table>

        <div py:if="preview" id="preview" class="searchable">
          ${preview_file(preview)}
        </div>

        <py:if test="attachment and 'ATTACHMENT_DELETE' in perm(attachment.resource)">
          <div class="buttons">
            <form method="get" action="">
              <div id="delete">
                <input type="hidden" name="action" value="delete" />
                <input type="submit" value="${_('Delete attachment')}" />
              </div>
            </form>
          </div>
        </py:if>
      </py:otherwise>

    </div>
  </body>
</html>
