<!--!  Copyright (C) 2006-2014 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 http://trac.edgewall.com/license.html.

  This software consists of voluntary contributions made by many
  individuals. For the exact contribution history, see the revision
  history and logs, available at http://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:i18n="http://genshi.edgewall.org/i18n"
      xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="layout.html" />
  <head>
    <title>$title</title>
    <script type="text/javascript" py:if="show_args_form">
      jQuery(document).ready(function($) {
        $("fieldset legend").enableFolding(false);
      });
    </script>
  </head>

  <body>
    <div id="content" class="report">
      <h1>$title
        <span py:if="numrows" class="numrows">(${ngettext('%(num)s match', '%(num)s matches', numrows)})</span>
      </h1>

      <form method="get" action="">
        <div id="prefs">
          <div>
            <label>
              Max items per page
              <input type="text" name="max" size="10" value="${max}" />
            </label>
            <fieldset id="reportfilters" py:if="show_args_form">
              <legend class="foldable">Arguments</legend>
              <table summary="Report arguments">
                <tbody>
                  <tr style="height: 1px"><td colspan="2"></td></tr>
                </tbody>
                <tbody py:for="(name, value) in sorted(args.items())" py:if="name != 'USER'">
                  <tr>
                    <th scope="row"><label>${name}</label></th>
                    <td class="filter">
                      <input type="text" name="${name}" value="${value or None}" size="42" />
                    </td>
                  </tr>
                </tbody>
              </table>
            </fieldset>
          </div>
          <div class="buttons">
            <input type="submit" value="${_('Update')}" />
          </div>
        </div>
      </form>

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

      <div 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>
      <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:def function="column_headers()">
        <tr py:for="header_group in header_groups" class="trac-columns">
          <th py:for="header in header_group" py:if="not header.hidden" py:with="fullrow = header is header_group[-1]"
              colspan="${'100' if fullrow else None}"
              class="${'asc' if header.asc else 'desc' if header.asc is not None else None}">
            <a href="${report_href(sort=header.col, asc=not header.asc)}">
              $header.title
            </a>
          </th>
        </tr>
      </py:def>
      <py:def function="group_heading(value_for_group, row_group)">
        <h2 py:if="value_for_group" class="report-result">
          <a py:strip="not row_group or '__grouplink__' not in row_group[0]" href="${row_group[0]['__grouplink__']}">$value_for_group</a>
          <span class="numrows" py:with="cnt = len(row_group)">
            (${ngettext('%(num)s match', '%(num)s matches', cnt) if cnt else _('No matches found.')})
          </span>
        </h2>
      </py:def>
      ${group_heading(*row_groups[0]) if row_groups else None}
      <table py:if="row_groups" class="listing tickets">
        <py:for each="groupindex, (value_for_group, row_group) in enumerate(row_groups)">
          <thead py:if="not groupindex">
            ${column_headers()}
          </thead>
          <tbody py:if="groupindex">
            <tr class="trac-group">
              <th colspan="100">
                ${group_heading(value_for_group or _('(empty)'), row_group)}
              </th>
            </tr>
            ${column_headers()}
          </tbody>

          <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 = {'class': 'fullrow', 'colspan': 100} if fullrow else {}"
                class="${'color' + row.__color__ + '-' if '__color__' in row else None
                      }${'odd' if row.__idx__ % 2 else 'even'
                      }${' ' + row['__class__'] if '__class__' in row else None}"
                style="${'background: ' + row.__bgcolor__ + ';' if '__bgcolor__' in row else None
                      }${'color: ' + row.__fgcolor__ + ';' if '__fgcolor__' in row else None
                      }${row.__style__ + ';' if '__style__' in row else None
                      }${'border: none; padding: 0;' if fullrow else 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>

                        <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 in ('ticket', 'id')">
                          <td class="ticket" py:attrs="td_attrs">
                            <a title="${_('View %(realm)s', realm=row.resource.realm)}"
                               href="${url_of(row.resource)}">${shortname_of(row.resource)}</a>
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <py:when test="col == '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'">
                          <td class="date" py:attrs="td_attrs">${format_time(from_utimestamp(long(cell.value))) if cell.value != '' else '--'}
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <py:when test="col in ('date', 'created', 'modified')">
                          <td class="date" py:attrs="td_attrs">${format_date(from_utimestamp(long(cell.value))) if cell.value != '' else '--'}
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

                        <py:when test="col == 'datetime'">
                          <td class="date" py:attrs="td_attrs">${format_datetime(from_utimestamp(long(cell.value))) if cell.value != '' else '--'}
                            <hr py:if="fullrow"/>
                          </td>
                        </py:when>

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

                        <py:when test="col == 'milestone'">
                          <td class="$col" py:attrs="td_attrs">
                            <a py:if="cell.value" 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>
        </py:for>
      </table>
      <xi:include href="page_index.html" />

      <div py:if="message" class="system-message">$message</div>
      <div py:if="numrows == 0" id="report-notfound">No matches found.</div>

      <div id="help" i18n:msg="">
        <strong>Note:</strong>
        See <a href="${href.wiki('TracReports')}">TracReports</a> for help on using and creating reports.
      </div>
    </div>
  </body>
</html>
