<!--!  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:xi="http://www.w3.org/2001/XInclude"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:i18n="http://genshi.edgewall.org/i18n">
  <xi:include href="admin.html"/>
  <head>
    <title>Repositories</title>
  </head>

  <body py:with="sorted_repos = sorted(repositories.iteritems(), key=lambda item: item[0].lower())">
    <h2>Manage Repositories <span py:if="view == 'list'" class="trac-count">(${len(repositories)})</span></h2>

    <py:def function="type_field(editable, multiline=False, selected=None)">
      <div class="field">
        <label>Type:<br py:if="multiline"/>
          <select size="1" id="trac-type" name="type" disabled="${not editable or None}">
            <option py:for="type in types" value="$type" selected="${type == selected or None}">${type or _('(default)')}</option>
            <option py:if="selected and selected not in types" selected="selected">$selected</option>
          </select>
        </label>
        <span class="hint">Default: $default_type</span>
      </div>
    </py:def>

    <py:def function="alias_field(editable, multiline=False, selected=None)">
      <div class="field">
        <label>Repository:<br py:if="multiline"/>
          <select size="1" id="trac-repository" name="alias" disabled="${not editable or None}">
            <option py:for="(reponame, info) in sorted_repos" py:if="'alias' not in info"
                    value="$info.name" selected="${info.name == selected or None}">${info.name or _('(default)')}</option>
            <option py:if="selected is not None and selected not in repositories" selected="selected">$selected</option>
          </select>
        </label>
      </div>
    </py:def>

    <py:choose test="view">
      <form py:when="'detail'" py:with="info = repositories[reponame]" class="mod" id="trac-modrepos" method="post" action="">
        <fieldset py:choose="" py:with="disabled = 'disabled' if not info.editable else None;
                                        readonly = 'readonly' if not info.editable else None">
          <legend py:when="info.editable">Modify Repository:</legend>
          <legend py:otherwise="">View Repository:</legend>
          <p py:if="not info.editable" class="hint" i18n:msg="">
            <strong>Note:</strong> This repository is not defined in the database and cannot be edited on this page.
          </p>
          <div class="field">
            <label>Name:<br/><input type="text" name="name" class="trac-autofocus"
                                    value="$info.name" readonly="$readonly" /></label>
          </div>
          <py:choose>
            <py:when test="'alias' in info">
              ${alias_field(info.editable, True, info.alias)}
            </py:when>
            <py:otherwise>
              ${type_field(info.editable, True, info.type)}
              <div class="field">
                <label>Directory:<br/><input type="text" name="dir" size="48" value="$info.dir" readonly="$readonly"/></label>
              </div>
              <div class="field">
                <label>URL:<br/><input type="text" name="url" size="48" value="$info.url" readonly="$readonly"/></label>
              </div>
            </py:otherwise>
          </py:choose>
          <div class="field">
            <label><input type="checkbox" name="hidden" value="1" checked="${info.hidden or None}"
                          disabled="${not info.editable or None}"/>
              Hide from repository index
            </label>
          </div>
          <div class="field">
            <fieldset>
              <label for="description" i18n:msg="">
                Description: (you may use <a tabindex="42" href="${href.wiki('WikiFormatting')}">WikiFormatting</a> here)
              </label>
              <p>
                <textarea id="description" name="description" class="wikitext trac-fullwidth trac-resizable"
                          rows="6" cols="60" readonly="$readonly">
$info.description</textarea>
              </p>
            </fieldset>
          </div>
          <div class="buttons">
            <input py:if="info.editable" type="submit" name="save" class="trac-disable-on-submit" value="${_('Save')}"/>
            <input type="submit" name="cancel" value="${_('Cancel')}"/>
          </div>
        </fieldset>
      </form>

      <py:otherwise>
        <form class="addnew" id="trac-addrepos" method="post" action="">
          <fieldset>
            <legend>Add Repository:</legend>
            <div class="field">
              <label>Name: <input type="text" name="name"/></label>
            </div>
            ${type_field(True)}
            <div class="field">
              <label>Directory: <input type="text" name="dir"/></label>
            </div>
            <div class="buttons">
              <input type="submit" name="add_repos" class="trac-disable-on-submit" value="${_('Add')}"/>
            </div>
          </fieldset>
        </form>

        <form py:if="any('alias' not in info for info in repositories.itervalues())"
              class="addnew" id="trac-addalias" method="post" action="">
          <fieldset>
            <legend>Add Alias:</legend>
            <div class="field">
              <label>Name: <input type="text" name="name"/></label>
            </div>
            ${alias_field(True)}
            <div class="buttons">
              <input type="submit" name="add_alias" class="trac-disable-on-submit" value="${_('Add')}"/>
            </div>
          </fieldset>
        </form>

        <form py:if="sorted_repos" id="trac-repository_table" method="post" action="">
          <table class="listing" id="trac-reposlist">
            <thead>
              <tr><th class="sel">&nbsp;</th>
                <th>Name</th><th>Type</th><th>Directory</th><th>Revision</th>
              </tr>
            </thead>
            <tbody>
              <tr py:for="(reponame, info) in sorted_repos">
                <td class="sel"><input py:if="info.editable" type="checkbox" name="sel" value="$info.name"/></td>
                <td class="name">
                  <a href="${panel_href(info.name or '(default)')}">${info.name or _('(default)')}</a>
                </td>
                <td>${(info.type or _('(default)')) if 'alias' not in info else None}</td>
                <td py:choose="">
                  <em py:when="'alias' in info" i18n:msg="repo">Alias of ${info.alias or _('(default)')}</em>
                  <span py:otherwise="" py:strip="not info.error" class="missing" title="$info.error">$info.prettydir</span>
                </td>
                <td><a py:if="info.rev" href="${href.changeset(info.rev, reponame) or None}">[$info.display_rev]</a></td>
              </tr>
            </tbody>
          </table>
          <div class="buttons">
            <input type="submit" name="refresh" value="${_('Refresh')}"/>
            <input type="submit" name="remove" class="trac-disable-on-submit" value="${_('Remove selected items')}"/>
          </div>
        </form>
      </py:otherwise>
    </py:choose>
  </body>

</html>
