<div xmlns="http://www.w3.org/1999/xhtml"
     xmlns:py="http://genshi.edgewall.org/" py:strip="">

  <!--! 
     
     WARNING: this file and the corresponding <py:def>s are going to be phased
              out soon. Please DON'T include macros.html in your own templates.

              See http://trac.edgewall.org/ticket/6374
  -->

  <!--!  Display the plural or singular form of a noun depending on a given
  -      number.
  -
  -      'cnt'       corresponding quantity
  -      'noun'
  -      'keepzero'  If True, 0 gets pluralized, otherwise nothing gets generated.
  -
  -      We take care to not insert any extra space.
  -->
  <py:def function="plural(cnt,noun,keepzero=False)"><py:if
      test="cnt != 0 or keepzero"
      >${cnt == 1 and ('1 '+noun) or '%d %ss' % (cnt, noun)}</py:if></py:def>

  <!--!  Display size of a content in human friendly format (think -H)
  -
  -      We take care to not insert any extra space.
  -->
  <py:def function="sizeinfo(size)"><span title="$size bytes">${
      pretty_size(size)
  }</span></py:def>

  <!--! Add Previous/Up/Next navigation links
  -
  -     `label` the label to use after the Previous/Next words
  -     `uplabel` the label to use for the Up link
  -
  -     Assume the 'chrome' datastructure to be available from the context.
  -->
  <ul py:def="prevnext_nav(label, uplabel=None)" py:with="links = chrome.links"
      py:if="'up' in chrome.links or
             'prev' in chrome.links or
             'next' in chrome.links">
    <li class="first" py:choose="">
      &larr; <a py:when="'prev' in links" py:with="link = links.prev[0]"
                class="prev" href="${link.href}"
                title="${link.title}">Previous $label</a>
      <span py:otherwise="" class="missing">Previous $label</span>
    </li>
    <li py:if="uplabel and 'up' in links">
      <a py:with="link = links.up[0]" href="${link.href}"
         title="${link.title}">$uplabel</a>
    </li>
    <li class="last" py:choose="">
      <a py:when="'next' in links"  py:with="link = links.next[0]"
         class="next" href="${link.href}"
         title="${link.title}">Next $label</a>
      <span py:otherwise="" class="missing">Next $label</span> &rarr;
    </li>
  </ul>


  <!--! Display a div for visualizing a preview of a file content
  -
  -     'preview' is usually obtained from calling Mimeview.preview_data()
  -
  -->
  <py:def function="preview_file(preview)">
    ${preview.rendered}
    <py:choose>
      <p py:when="preview.size == 0">
        <strong>(The file is empty)</strong>
      </p>
      <p py:when="not preview.rendered">
        <strong>HTML preview not available</strong>,
        <py:choose>
          <py:when test="preview.max_file_size_reached">
            since the file size exceeds $preview.max_file_size bytes.
          </py:when>
          <py:otherwise>
            since no preview renderer could handle it.
          </py:otherwise>
        </py:choose>
        Try <a href="$preview.raw_href">downloading</a> the file instead.
      </p>
    </py:choose>
  </py:def>

  <!--! Display a list of attachments
  -
  -     'alist' is an AttachmentList object (see attachment.py)
  -     'compact' is used to switch between a compact list of attachments (e.g. as used for
  -       the wiki view) and an expanded list (e.g. as used for the ticket view)
  -->
  <py:def function="list_of_attachments(alist, compact=False, add_button_title=None)">
    <py:def function="show_one_attachment(attachment)">
      <a href="${url_of(attachment.resource)}" title="${_('View attachment')}">$attachment.filename</a>
      <a href="${url_of(attachment.resource, format='raw')}"
         title="${_('Download')}" class="trac-rawlink"><img src="${chrome.htdocs_location}download.png" alt="${_('Download')}"/></a>
      (${sizeinfo(attachment.size)}) - added by <em>${authorinfo(attachment.author)}</em>
      ${dateinfo(attachment.date)} ago.
    </py:def>
    <py:if test="alist.attachments or alist.can_create">
      <py:choose test="">
        <py:when test="compact and alist.attachments">
          <h3>Attachments</h3>
          <ul>
            <py:for each="attachment in alist.attachments">
              <li>
                ${show_one_attachment(attachment)}
                <q py:if="compact and attachment.description">${wiki_to_oneliner(context, attachment.description)}</q>
              </li>
            </py:for>
          </ul>
        </py:when>
        <py:when test="not compact">
          <h2>Attachments</h2>
          <div py:if="alist.attachments or alist.can_create" id="attachments">
            <dl py:if="alist.attachments" class="attachments">
              <py:for each="attachment in alist.attachments">
                <dt>${show_one_attachment(attachment)}</dt>
                <dd py:if="attachment.description">
                  ${wiki_to_oneliner(context, attachment.description)}
                </dd>
              </py:for>
            </dl>
            ${attach_file_form(alist, add_button_title)}
          </div>
        </py:when>
      </py:choose>
    </py:if>
  </py:def>

  <!--! Conditionally render an ''Attach File'' button
  -
  -     'alist' is an AttachmentList object (see attachment.py)
  -->
  <py:def function="attach_file_form(alist, add_button_title=None)">
    <form py:if="alist.can_create" method="get" action="${alist.attach_href}" id="attachfile">
      <div>
        <input type="hidden" name="action" value="new" />
        <input type="submit" name="attachfilebutton" value="${add_button_title or _('Attach file')}" />
      </div>
    </form>
  </py:def>

  <!--!  Display a generic "progress bar", for use in roadmap and milestone.
  -
  -      `stats` argument is a TicketGroupStats instance
  -       `interval_hrefs` are links to a query for each of the stats.intervals
  -->
  <py:def function="progress_bar(stats, interval_hrefs, percent=None, legend=True, style=None, stats_href=None)">
    <table class="progress" style="$style">
      <tr>
        <td py:for="idx, interval in enumerate(stats.intervals)" py:choose=""
            class="$interval.css_class" style="${interval.percent and 'width: %d%%' % interval.percent or 'display: none'}">
          <a py:when="interval_hrefs" href="${interval_hrefs[idx]}"
            title="${interval.count} of ${stats.count} ${stats.unit}${
            stats.count != 1 and 's' or ''} ${interval.title}"></a>
          <a py:otherwise=""
            title="${interval.count} of ${stats.count} ${stats.unit}${
            stats.count != 1 and 's' or ''} ${interval.title}"></a>
        </td>
      </tr>
    </table>
    <p class="percent">${percent is None and '%d%%' % stats.done_percent or percent}</p>
    <dl py:if="legend">
      <py:for each="idx, interval in enumerate(stats.intervals)">
        <dt py:choose="">
          <a py:when="interval_hrefs" href="${interval_hrefs[idx]}">${interval.title.capitalize()} ${stats.unit}s:</a>
          <a py:otherwise="">${interval.title.capitalize()} ${stats.unit}s:</a>
        </dt>
        <dd py:choose="">
          <a py:when="interval_hrefs" href="${interval_hrefs[idx]}">${interval.count}</a>
          <a py:otherwise="">${interval.count}</a>
        </dd>
      </py:for>
      <py:if test="stats_href">
        <dt>/ <a href="${stats_href}">Total ${stats.unit}s:</a></dt>
        <dd><a href="${stats_href}">${sum([x.count for x in stats.intervals], 0)}</a></dd>
      </py:if>
    </dl>
</py:def>

</div>
