<!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" />
  <head>
    <title>$title</title>
  </head>

  <body>
    <div id="content" class="report">

      <h1>$title
        <span py:if="numrows and report.id != -1" class="numrows">${_('(%(count)s matches)', count=numrows)}</span>
      </h1>

      <div py:if="description" id="description" xml:space="preserve">
        ${wiki_to_html(context, description)}
      </div>

      <div py:if="report.id != -1" class="buttons">
        <form py:if="'REPORT_MODIFY' in perm(report.resource)" action="" method="get">
          <div>
            <input type="hidden" name="action" value="edit" />
            <input type="submit" value="${_('Edit report')}" accesskey="e" />
          </div>
        </form>
        <form py:if="'REPORT_CREATE' in perm(report.resource)" action="" method="get">
          <div>
            <input type="hidden" name="action" value="copy" />
            <input type="submit" value="${_('Copy report')}" />
          </div>
        </form>
        <form py:if="'REPORT_DELETE' in perm(report.resource)" action="" method="get">
          <div>
            <input type="hidden" name="action" value="delete" />
            <input type="submit" value="${_('Delete report')}" />
          </div>
        </form>
      </div>
      <py:if test="report.id != -1">
        <h2 class="report-result" py:if="paginator.has_more_pages">
          ${_('Results')} <span class="numresults">(${paginator.displayed_items()})</span>
        </h2>
        <xi:include href="page_index.html" />
      </py:if>
      <py:for each="value_for_group, row_group in row_groups">
        <h2 class="report-result" py:if="value_for_group">$value_for_group
        <span class="numrows" py:with="v = len(row_group)">${v == 0 and _('(No matches)') or ngettext('(%(count)s match)', '(%(count)s matches)', v, count=v)}</span></h2>
        <table class="listing ${report.id == -1 and 'reports' or 'tickets'}">
          <thead>
            <tr py:for="header_group in header_groups">
              <th py:for="header in header_group" py:if="not header.hidden" py:with="fullrow = header is header_group[-1]"
                colspan="${fullrow and '100' or None}">
                <a py:strip="not sorting_enabled"
                   py:with="filtered_args = dict([(k,v) for k,v in args.items() if k not in ('sort', 'asc')])"
                  href="${href.report(report.id, sort=header.col, asc=not header.asc and '1' or '0', **filtered_args)}">
                  $header.title
                </a>
              </th>
            </tr>
          </thead>

          <tbody>
            <py:for each="row in row_group">
              <tr py:for="cell_group in row.cell_groups"
                py:with="fullrow = len(cell_group) == 1;
                         td_attrs = fullrow and {'class': 'fullrow', 'colspan': 100} or {}"
                class="${'__color__' in row and 'color'+row.__color__+'-' or ''}${row.__idx__ % 2 and 'odd' or 'even'}"
                style="${'__bgcolor__' in row and 'background: '+row.__bgcolor__+';' or None
                }${'__fgcolor__' in row and 'color: '+row.__fgcolor__+';' or None
                }${'__style__' in row and row.__style__+';' or None
                }${fullrow and 'border: none; padding: 0;' or None}">

                <py:for each="cell in cell_group">
                  <py:if test="not cell.header.hidden">
                    <py:with vars="col = cell.header.col.strip('_')">
                      <py:choose>

                        <!--! for the report listing -->
                        <py:when test="col == 'report'">
                          <td class="$col" py:attrs="td_attrs">
                            <a title="${_('View report')}" href="${href.report(cell.value)}">{$cell.value}</a>
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <py:when test="col == 'title' and report.id == -1">
                          <td class="$col" py:attrs="td_attrs">
                            <a title="${_('View report')}" href="${href.report(row.id)}">$cell.value</a>
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <!--! for the ticket listing -->
                        <py:when test="col in ('ticket', 'id')">
                          <td class="ticket" py:attrs="td_attrs">
                            <a title="${_('View %(realm)s', realm=row.resource.realm)}" href="${url_of(row.resource)}">#$cell.value</a>
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <py:when test="col in ('summary', '概要') and row.id">
                          <td class="$col" py:attrs="td_attrs">
                            <a title="${_('View %(realm)s', realm=row.resource.realm)}" href="${url_of(row.resource)}">$cell.value</a>
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <!--! generic fields -->
                        <py:when test="col == 'time' or col.endswith('時刻')">
                          <td class="date" py:attrs="td_attrs">${cell.value != '' and format_time(int(cell.value)) or '--'}
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <py:when test="col in ('date', 'created', 'modified') or col.endswith('日付')">
                          <td class="date" py:attrs="td_attrs">${cell.value != '' and format_date(int(cell.value)) or '--'}
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <py:when test="col == 'datetime' or col.endswith('日時')">
                          <td class="date" py:attrs="td_attrs">${cell.value != '' and format_datetime(int(cell.value)) or '--'}
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <py:when test="col in ('description', '説明')">
                          <td class="$col" py:attrs="td_attrs" xml:space="preserve">
                            ${wiki_to_html(context(row.resource), cell.value)}
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <py:when test="col == 'milestone'">
                          <td class="$col" py:attrs="td_attrs">
                            <a title="${_('View milestone')}" href="${href.milestone(cell.value)}">$cell.value</a>
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <py:otherwise>
                          <td class="$col" py:attrs="td_attrs">$cell.value
                            <hr py:if="fullrow"/>
                          </td>
                        </py:otherwise>

                      </py:choose>
                    </py:with>
                  </py:if>
                </py:for>
              </tr>
            </py:for>
          </tbody>
        </table>
      </py:for>
      <py:if test="report.id != -1">
        <xi:include href="page_index.html" />
      </py:if>
      <div py:if="report.id == -1 and 'REPORT_CREATE' in perm(report.resource)" class="buttons">
        <form action="" method="get" id="create_report">
          <div>
            <input type="hidden" name="action" value="new" />
            <input type="submit" value="${_('Create new report')}" />
          </div>
        </form>
      </div>

      <div py:if="message" class="system-message">$message</div>
      <div py:if="numrows == 0" id="report-notfound">${_('No matches found.')}</div>

      <!--! FIXME: message_contains_tag --> 
      <div id="help">
        <strong>Note:</strong>
        レポートについてのヘルプは <a href="${href.wiki('TracReports')}">TracReports</a> を参照して下さい。
      </div>
    </div>
  </body>
</html>
