<!--!  Copyright (C) 2006-2023 Edgewall Software

  This software is licensed as described in the file COPYING, which
  you should have received as part of this distribution. The terms
  are also available at https://trac.edgewall.org/wiki/TracLicense.

  This software consists of voluntary contributions made by many
  individuals. For the exact contribution history, see the revision
  history and logs, available at https://trac.edgewall.org/.
-->
<!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"
      xmlns:i18n="http://genshi.edgewall.org/i18n"
      py:with="parent = attachments.parent if attachments else attachment.resource.parent">
  <xi:include href="layout.html" />
  <head>
    <title py:choose="mode">
      <py:when test="'new'">${name_of(parent)} &ndash; Attachment</py:when>
      <py:when test="'list'">${name_of(parent)} &ndash; Attachments</py:when>
      <py:otherwise><i18n:msg params="filename, parent">${attachment.filename} on ${name_of(parent)} &ndash; Attachment</i18n:msg></py:otherwise>
    </title>
    <py:if test="preview">
      <script>
        jQuery(function($) {
          $('#preview table.code').enableCollapsibleColumns($('#preview table.code thead th.content'));
        });
      </script>
    </py:if>
  </head>

  <body>
    <div py:choose="mode" id="content" class="attachment">
      <py:when test="'new'">
        <h1 i18n:msg="parent">Add Attachment to <a href="${url_of(parent)}">${name_of(parent)}</a></h1>
        <form id="attachment" class="mod" method="post" enctype="multipart/form-data" action="#">
          <div class="field">
            <label>File<py:if test="max_size >= 0">
              <i18n:msg params="value">(size limit ${pretty_size(max_size)})</i18n:msg></py:if>:<br />
              <input type="file" name="attachment" class="trac-disable-determinant" /></label>
          </div>
          <fieldset id="changeinfo">
            <legend>Attachment Info</legend>
            <py:if test="authname == 'anonymous'">
              <div class="field">
                <label>Your email or username:<br />
                  <input type="text" name="author" class="trac-fullwidth" value="${attachment.author or author}" />
                </label>
                <p py:if="author == 'anonymous'" class="hint">
                  <i18n:msg>E-mail address and name can be saved in the <!--!
                    --><a href="${href.prefs()}" class="trac-target-new">Preferences</a>.</i18n:msg>
                </p>
              </div>
              </py:if>
            <div class="field">
              <label>Description of the file (optional):<br />
                <input type="text" class="trac-fullwidth" name="description" value="$attachment.description" />
              </label>
            </div>
            <py:if test="authname and authname != 'anonymous'">
              <div class="options">
                <label><input type="checkbox" name="replace" checked="${is_replace or None}" />
                  Replace existing attachment of the same name</label>
              </div>
            </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" class="trac-disable trac-disable-on-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" class="trac-disable-on-submit" value="${_('Delete attachment')}" />
              <input type="submit" name="cancel" value="${_('Cancel')}" />
            </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.child(parent)">
          <xi:include href="list_of_attachments.html" py:with="alist = attachments"/>
        </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">
          <tr>
            <th scope="col" i18n:msg="file,size,author,date">
              File $attachment.filename, <!--!
              --><span title="${ngettext('%(num)d byte', '%(num)d bytes',
                                         num=attachment.size)}"><!--!
              -->${pretty_size(attachment.size)}</span> <!--!
              -->(added by ${authorinfo(attachment.author)}, ${pretty_dateinfo(attachment.date)})
            </th>
          </tr>
          <tr>
            <td class="message searchable" xml:space="preserve">
              ${wiki_to_html(context.child(parent), attachment.description)}
            </td>
          </tr>
        </table>

        <div py:if="preview" id="preview" class="searchable">
          <xi:include href="preview_file.html" py:with="preview = 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>
