<!--!  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: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">/*<![CDATA[*/
      jQuery(document).ready(function($) {
        // Sets state of group toggler when component checkboxes are clicked
        function setGroupTogglerState() {
          var table = $(this).closest("table.listing");
          var checkboxes = $("td.sel input:checkbox:enabled", table);
          var numSelected = checkboxes.filter(":checked").length;
          var noneSelected = numSelected === 0;
          var allSelected = numSelected === checkboxes.length;
          $("th.sel input:checkbox", table)
            .prop({"checked": allSelected,
                   "indeterminate": !(noneSelected || allSelected)});
        }
        // Add group event behavior for controlling state of toggler
        $("table.listing td.sel input:checkbox:enabled")
          .click(setGroupTogglerState);
        // Add click behavior for the group toggler and initialize its state
        $("table.listing th.sel").wrapInner('<label></label>').children()
          .each(function() {
            $('<input type="checkbox"/>').click(function() {
              $("td.sel input:checkbox:enabled",
                $(this).closest("table.listing")).prop("checked", this.checked);
            }).prependTo(this).each(setGroupTogglerState);
          });
        $("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 <span class="trac-count">(${len(plugins)})</span></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>
        <div class="buttons">
          <input type="submit" name="install" class="trac-disable-on-submit"
                 value="${_('Install')}" disabled="${readonly or None}" />
        </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>
      </fieldset>
    </form>

    <form py:for="idx, plugin in enumerate(plugins)" id="edit-plugin-${plugin.name.lower()}" 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${' collapsed' if not show_doc and module.description else None}">
                <p class="trac-heading${' foldable' if module.description else None}">
                  <py:choose>
                    <a py:when="module.description" class="trac-name"
                       href="${href.admin('general', 'plugin', show=module_name if not show_doc else 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 trac-module"></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${' collapsed' if not show_doc else None}">
                <p class="trac-heading${' foldable' if component.description else None}">
                  <py:choose>
                    <a py:when="component.description" class="trac-name"
                       href="${href.admin('general', 'plugin', show=component.full_name if not show_doc else 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 trac-component">
                <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>
