<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.
  -
  -      FIXME: use ngettext insted of this.
  -->
  <py:def function="plural(cnt,noun,keepzero=False)"><py:if
      test="cnt != 0 or keepzero"
      >${cnt == 1 and ('1 '+noun) or '%d %s' % (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)s bytes', size=size)}">${
      pretty_size(size)
  }</span></py:def>

  <!--!  Display author information, eventually obfuscating the e-mail address
  -
  -      We take care to not insert any extra space.
  -->
  <py:def function="authorinfo(author, email_map=None)"><py:choose><py:when test="author"><py:with
    vars="author = show_email_addresses and email_map and '@' not in author and email_map[author] or author">${
      author and format_author(author) or 'anonymous'
  }</py:with></py:when><py:otherwise>anonymous</py:otherwise></py:choose></py:def>

  <!--!  Display a sequence of path components.
  -
  -      Each component is a link to the corresponding location in the browser.
  -->
  <py:def function="browser_path_links(path_links,rev=None)">
    <py:for each="idx, part in enumerate(path_links)"><py:with 
        vars="first = idx == 0; last = idx == len(path_links) - 1"><a 
          class="${classes('pathentry', first=first)}"
          title="${first and _('Go to root directory') or _('View %(part)s', part=part.name)}"
          href="$part.href">$part.name</a><py:if 
        test="not last"><span class="pathentry sep">/</span></py:if></py:with></py:for>
    <py:if test="rev"><span class="pathentry sep">@</span>
      <a class="pathentry" href="${href.changeset(rev)}" title="${_('View changeset %(rev)s', rev=rev)}">$rev</a>
    </py:if>
    <br style="clear: both" />
  </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>

  <!--! Add diff option fields (to be used inside a form)
  -
  -     `diff` the datastructure which contains diff options
  -
  -->
  <py:def function="diff_options_fields(diff)">
    <label for="style">${_('View differences')}</label>
    <select id="style" name="style">
      <option selected="${diff.style == 'inline' or None}"
              value="inline">${_('inline')}</option>
      <option selected="${diff.style == 'sidebyside' or None}"
              value="sidebyside">${_('side by side')}</option>
    </select>
    <div class="field">
      <!--! FIXME: message_contains_tag --> 
      差分発生行の前後
      <input type="text" name="contextlines" id="contextlines" size="2" maxlength="3"
             value="${diff.options.contextlines &lt; 0 and 'all' or diff.options.contextlines}" />
      <label for="contextlines"> 行を表示</label>
    </div>
    <fieldset id="ignore" py:with="options = diff.options">
      <legend>${_('Ignore')}:</legend>
      <div class="field">
        <input type="checkbox" id="ignoreblanklines" name="ignoreblanklines"
               checked="${options.ignoreblanklines or None}" />
        <label for="ignoreblanklines">${_('Blank lines')}</label>
      </div>
      <div class="field">
        <input type="checkbox" id="ignorecase" name="ignorecase"
               checked="${options.ignorecase or None}" />
        <label for="ignorecase">${_('Case changes')}</label>
      </div>
      <div class="field">
        <input type="checkbox" id="ignorewhitespace" name="ignorewhitespace"
               checked="${options.ignorewhitespace or None}" />
        <label for="ignorewhitespace">${_('White space changes')}</label>
      </div>
    </fieldset>
    <div class="buttons">
      <input type="submit" name="update" value="${_('Update')}" />
    </div>
  </py:def>

  <!--! 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 %(max)d bytes.', max=preview.max_file_size)}
          </py:when>
          <py:otherwise>
            ${_('Since no preview renderer could handle it.')}
          </py:otherwise>
        </py:choose>
        <!--! FIXME: message_contains_tag --> 
        ファイルを<a href="$preview.raw_href">ダウンロード</a>して下さい。
      </p>
      <py:when test="'errors' in preview">
        <p>
          <strong>${_('HTML preview not available.')}</strong>
         <!--! FIXME: message_contains_tag --> 
          閲覧するには、ファイルを<a href="$preview.raw_href">ダウンロード</a>して下さい。
        </p>
        <p>${plural(len(preview.errors), 'issue')} found:</p>
        <div py:for="renderer, err in preview.errors" class="system-message">
          <strong>${renderer.__class__.__name__}</strong>
          <pre>$err</pre>
        </div>
      </py:when>
    </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)">
      <!--! FIXME: message_contains_tag -->
      <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)}) - 登録者 <em>${authorinfo(attachment.author)}</em>
      ${dateinfo(attachment.date)} 前.
    </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
  -      FIXME: 複雑なので直接翻訳
  -->
  <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="${stats.count} 個中 ${interval.count} 個の${stats.unit}${
            stats.count != 1 and '' or ''}が${interval.title}"></a>
          <a py:otherwise=""
            title="${stats.count} 個中 ${interval.count} 個の${stats.unit}${
            stats.count != 1 and '' 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}:</a>
          <a py:otherwise="">${interval.title.capitalize()}の${stats.unit}:</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>
      <dt>/ <a href="${stats_href}">${stats.unit}の合計:</a></dt>
      <dd><a href="${stats_href}">${sum([x.count for x in stats.intervals], 0)}</a></dd>
    </dl>
</py:def>

</div>
