<!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'">
        <!--! FIXME: message_contains_tag --> 
        <h1><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 %(size)s)',
                  size=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">
                <!--! FIXME: message_contains_tag --> 
                ファイル $attachment.filename, ${sizeinfo(attachment.size)}
                (登録者: ${authorinfo(attachment.author)}, ${dateinfo(attachment.date)} 前)
              </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>
