<!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>Plugins</title>
    <script type="text/javascript" src="${chrome.htdocs_location}js/folding.js"></script>
    <script type="text/javascript">
      jQuery(document).ready(function($){
        $("h3.foldable").enableFolding(true, true);
        $("p.foldable").enableFolding(true, false);
        $("thead .trac-toggler a").each(function() {
          $(this).attr("href", "").click(function() {
            var td = $(this).closest("table").find("tbody td");
            var a = td.find(".trac-toggler a");
            if ($(this).text() == "+") {
              td.removeClass("collapsed");
              a.text("&ndash;");
            } else {
              td.addClass("collapsed");
              a.text("+");
            }
            return false;
          });
        });
      });
    </script>
  </head>

  <body>
    <h2>Manage Plugins</h2>

    <form id="addplug" class="addnew" method="post" enctype="multipart/form-data" action="">
      <fieldset>
        <legend>Install Plugin:</legend>
        <div class="field">
          <label i18n:msg="">
            File: <input type="file" name="plugin_file" disabled="${readonly or None}" />
          </label>
        </div>
        <p class="help" py:choose="readonly">
          <py:when test="True">
            The web server does not have sufficient permissions to store files in
            the environment plugins directory.
          </py:when>
          <py:otherwise>
            Upload a plugin packaged as Python egg.
          </py:otherwise>
        </p>
        <div class="buttons">
          <input type="submit" name="install" value="${_('Install')}"
                 disabled="${readonly or None}" />
        </div>
      </fieldset>
    </form>

    <form py:for="idx, plugin in enumerate(plugins)" method="post" action="">
      <div class="plugin" id="trac-plugin-${plugin.name}">
        <h3 class="foldable">${plugin.name} ${plugin.version}</h3>
        <!--! FIXME: Plugin uninstall disabled as it is unreliable (#3545)
        <div class="uninstall buttons">
          <input type="hidden" name="plugin_filename"
                 value="${plugin.plugin_filename}" />
          <input type="submit" name="uninstall" value="${_('Uninstall')}"
                 disabled="${plugin.readonly or None}" />
        </div> -->
        <py:if test="plugin.info">
          <p class="summary">${plugin.info.get('summary')}</p>
          <dl py:if="'home_page' in plugin.info or
                     'author' in plugin.info or
                     'author_email' in plugin.info"
              class="info">
            <py:if test="'author' in plugin.info or 'author_email' in plugin.info">
              <dt>Author:</dt>
              <dd>
                <a py:strip="not plugin.info.get('author_email')"
                   href="mailto:${plugin.info.author_email}">
                  ${plugin.info.author or plugin.info.author_email}
                </a>
              </dd>
            </py:if>
            <py:if test="plugin.info.get('home_page')">
              <dt>Home page:</dt>
              <dd>
                <a onclick="window.open(this.href); return false"
                   href="${plugin.info.home_page}">${plugin.info.home_page}</a>
              </dd>
            </py:if>
            <py:if test="plugin.info.get('license')">
              <dt>License:</dt>
              <dd>${plugin.info.license}</dd>
            </py:if>
          </dl>
        </py:if>
        <table class="listing">
          <thead>
            <tr>
              <th>
                Component
                <span class="trac-toggler">
                  [<a title="Show all descriptions" href="${href.admin('general', 'plugin', show=plugin.name)
                                                            + '#trac-plugin-' + plugin.name}">+</a>]
                  [<a title="Hide all descriptions" href="${href.admin('general', 'plugin')
                                                            + '#trac-plugin-' + plugin.name}">&ndash;</a>]
                </span>
              </th>
              <th class="sel">Enabled</th>
            </tr>
          </thead>
          <tbody py:for="module_name, module in sorted(plugin.modules.iteritems())">
            <tr>
              <td py:with="show_doc = show == plugin.name or show == module_name" id="trac-mod-${module_name}"
                  class="trac-module${not show_doc and ' collapsed' or None}">
                <p class="trac-heading${module.description and ' foldable' or None}">
                  <py:choose>
                    <a py:when="module.description" class="trac-name"
                       href="${href.admin('general', 'plugin', show=not show_doc and module_name or None)                                                     
                               + '#trac-mod-' + module_name}">${module_name}.*</a>
                    <span py:otherwise="" class="trac-name">${module_name}.*</span>
                  </py:choose>
                  <span py:if="module.summary" class="trac-summary"> &mdash; ${module.summary}</span>
                </p>
                <div py:if="module.description" xml:space="preserve">${safe_wiki_to_html(context, module.description)}</div>
              </td>
              <td class="sel"></td>
            </tr>
            <tr py:for="component_name, component in sorted(module.components.iteritems())">
              <td py:with="show_doc = show == plugin.name or show == component.full_name" id="trac-comp-${component.full_name}"
                  class="trac-component${not show_doc and ' collapsed' or None}">
                <p class="trac-heading${component.description and ' foldable' or None}">
                  <py:choose>
                    <a py:when="component.description" class="trac-name"
                       href="${href.admin('general', 'plugin', show=not show_doc and component.full_name or None)                                             
                               + '#trac-comp-' + component.full_name}">${component_name}</a>
                    <span py:otherwise="" class="trac-name">${component_name}</span>
                  </py:choose>
                  <span py:if="component.summary" class="trac-summary"> &mdash; ${component.summary}</span>
                </p>
                <div py:if="component.description" xml:space="preserve">${safe_wiki_to_html(context, component.description)}</div>
              </td>
              <td class="sel">
                <input py:if="not component.required" type="hidden" name="component"
                       value="${module_name}.${component_name}" />
                <input type="checkbox" name="enable"
                       value="${module_name}.${component_name}"
                       checked="${component.enabled or None}"
                       disabled="${component.required or None}" />
              </td>
            </tr>
          </tbody>
        </table>
        <div class="buttons">
          <input type="hidden" name="plugin" value="$idx" />
          <input type="submit" name="update" value="${_('Apply changes')}" />
        </div>
      </div>
    </form>
  </body>

</html>
