<!--!  Copyright (C) 2009-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>Available Reports</title>
    <script type="text/javascript" src="${chrome.htdocs_location}js/folding.js"></script>
    <script type="text/javascript">
      jQuery(document).ready(function($){
        $("span.foldable").enableFolding(true);
        $("#trac-toggle-description").click(function() {
          if ($(this).checked())
            $("div.description").parent().removeClass("collapsed");
          else
            $("div.description").parent().addClass("collapsed");
        });
      });
    </script>
  </head>

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

      <h1>Available Reports</h1>

      <form id="prefs" method="get" action="">
        <div>
          <input id="trac-toggle-description" type="checkbox" />
          <label for="trac-toggle-description">Show Descriptions</label>
        </div>
      </form>

      <div id="description" />

      <div py:choose="" class="reports">
        <div py:if="saved_query_href">
          <form method="get" action="${href.report()}">
            <div class="inlinebuttons">

              <input type="hidden" name="action" value="clear" />
              <input type="submit" value="${captioned_button('x', _('Clear'))}" title="Forget last query" class="trac-delete" />
            </div>
          </form>
          <h3><a href="$saved_query_href"><em>Return to Last Query</em></a></h3>
          <span class="foldable" />
          <div class="description">
            <p>Continue browsing through the current list of results,
              from the last selected report or custom query.</p>
          </div>
        </div>

        <div py:if="query_href">
          <h3><a href="$query_href"><em>New Custom Query</em></a></h3>
          <span class="foldable" />
          <div class="description">
            <p>Compose a new ticket query by selecting filters and columns to display.</p>
          </div>
        </div>

        <py:when test="reports">
          <h2>SQL reports and saved custom queries
            <span id="trac-sort-order" py:with="report_asc = asc if sort == 'report' else None;
                                                title_asc = asc if sort == 'title' else None">
              Sort by:
              <a href="${href.report(sort='report', asc='0' if report_asc else '1')}"
                 class="${('desc', 'asc')[report_asc] if report_asc is not None else None}">
                Identifier</a>
              <a href="${href.report(sort='title', asc='0' if title_asc else '1')}"
                 class="${('desc', 'asc')[title_asc] if title_asc is not None else None}">
                Title</a>
            </span>
          </h2>

          <div py:for="id, title, description, can_edit, can_delete in reports">
            <form py:if="can_delete" method="get" action="${href.report(id)}">
              <div class="inlinebuttons">
                <input type="hidden" name="action" value="delete" />
                <input type="submit" value="${captioned_button('–', _('Delete'))}"
                     title="Delete report" class="trac-delete" />
              </div>
            </form>
            <form py:if="can_edit" method="get" action="${href.report(id)}">
              <div class="inlinebuttons">
                <input type="hidden" name="action" value="edit" />
                <input type="submit" value="${captioned_button('✎', _('Edit'))}"
                     title="Edit report" />
              </div>
            </form>
            <h3><a title="View report" href="${href.report(id)}" py:choose="sort">
              <py:when test="'title'">$title <em>{$id}</em></py:when>
              <py:otherwise><em>{$id}</em> $title</py:otherwise>
              </a></h3>
            <span class="foldable" />
            <div py:if="description" class="description" xml:space="preserve">
              ${wiki_to_html(context.child('report', id), description)}
            </div>
          </div>
        </py:when>
        <p py:otherwise="">No reports available.</p>
      </div>


      <div py:if="'REPORT_CREATE' in perm('report')" 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 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>
