{# Copyright (C) 2006-2020 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/.
#}
# extends 'layout.html'
<!DOCTYPE html>
<html>
  # set parent = attachments.parent if attachments else attachment.resource.parent
  <head>
    <title>
      # block title
      #   if mode == 'new':
      ${_("%(parent)s – Attachment", parent=name_of(parent))}
      #   elif mode == 'list':
      ${_("%(parent)s – Attachments", parent=name_of(parent))}
      #   else:
      #     trans filename = attachment.filename, parent = name_of(parent)

      ${filename} on ${parent} – Attachment

      #     endtrans
      #   endif
      ${ super() }
      # endblock title
    </title>

    # block head
    ${ super() }
    #   if preview:
    <script>
      jQuery(function($) {
        $('#preview table.code').enableCollapsibleColumns(
          $('#preview table.code thead th.content'));
      });
    </script>
    #   endif
    # endblock head
  </head>

  <body>
    # block content
    <div id="content" class="attachment">
      # if mode == 'new':
      <h1>${tag_("Add Attachment to %(parent)s",
                 parent=tag.a(name_of(parent), href=url_of(parent)))}</h1>
      <form id="attachment" class="mod" method="post"
            enctype="multipart/form-data" action="#">
        ${jmacros.form_token_input()}
        <div class="field">
          <label>File{% if max_size is greaterthanorequal 0 %}
            ${_("(size limit %(value)s)", value=pretty_size(max_size))}{%
            endif %}:<br />
            <input type="file" name="attachment"
                   class="trac-disable-determinant" />
          </label>
        </div>
        <fieldset id="changeinfo">
          <legend>${_("Attachment Info")}</legend>
          # if 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>
            # set preferences
            <a href="${href.prefs()}" class="trac-target-new">${
              _("Preferences")}</a>
            # endset
            # if author == 'anonymous':
            <p class="hint">
              # trans preferences

              E-mail address and name can be saved in the
              ${preferences}.

              # endtrans
            </p>
            # endif
          </div>
          # endif
          <div class="field">
            <label>${_("Description of the file (optional):")}<br />
              <input type="text" class="trac-fullwidth wikitext"
                     name="description" value="${attachment.description}" />
            </label>
          </div>
          # if authname and authname != 'anonymous':
          <div class="options">
            <label>
              <input type="checkbox" name="replace"${
                     {'checked': is_replace}|htmlattr}/>
              ${_("Replace existing attachment of the same name")}
            </label>
          </div>
          # endif
        </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>

      # elif mode == '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="#">
          ${jmacros.form_token_input()}
          <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>


      # elif mode == 'list':
      <h1><a href="${url_of(parent)}">${name_of(parent)}</a></h1>
      #   with
      #     set context = context.child(parent)
      #     set alist = attachments
      #     include 'list_of_attachments.html'
      #   endwith

      # else:
      ## 'render' mode
      <h1><a href="${url_of(parent)}">${name_of(parent)}</a>:
        ${attachment.filename}</h1>
      <table id="info">
        <tr>
          <th scope="col">
            # with
            #   set file = attachment.filename
            #   set size
            <span title="${ngettext('%(num)d byte', '%(num)d bytes',
                                    num=attachment.size)}">${
              pretty_size(attachment.size)}</span>
            #   endset
            #   set author = authorinfo(attachment.author)
            #   set pdate = pretty_dateinfo(attachment.date)
            #   trans file, size, author, pdate

            File ${file}, ${size} (added by ${author}, ${pdate})

            #   endtrans
            # endwith
          </th>
        </tr>
        <tr>
          <td class="message searchable">
            ${wiki_to_html(context.child(parent), attachment.description)}
          </td>
        </tr>
      </table>

      #   if preview:
      <div id="preview" class="searchable">
        #   include 'preview_file.html'
      </div>
      #   endif

      #   if attachment and 'ATTACHMENT_DELETE' in perm(attachment.resource):
      <div class="buttons">
        <form method="get" action="#">
          <div id="delete"> {# jinjacheck: "ID delete already defined" OK #}
            <input type="hidden" name="action" value="delete" />
            <input type="submit" value="${_('Delete attachment')}" />
          </div>
        </form>
      </div>
      #   endif
      # endif
    </div>
    ${ super() }
    # endblock content
  </body>
</html>
