<!--!  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"
      py:with="perm = req.perm('admin', 'ticket/milestones');
               can_create = 'MILESTONE_CREATE' in perm;
               can_modify = 'MILESTONE_MODIFY' in perm;
               can_remove = 'MILESTONE_DELETE' in perm">
  <xi:include href="admin.html" />
  <head>
    <title>Milestones</title>
    <script type="text/javascript">
      jQuery(document).ready(function($) {
        $("#millist").addSelectAllCheckboxes();
      });
    </script>
  </head>

  <body>
    <h2>Manage Milestones <span py:if="view == 'list'" class="trac-count">(${len(milestones)})</span></h2>

    <py:choose test="view">
      <xi:include py:when="'detail'" href="milestone_edit_form.html" />

      <py:otherwise>
        <form class="addnew" id="addmilestone" method="post" action="" py:if="can_create">
          <fieldset>
            <legend>Add Milestone:</legend>
            <div class="field">
              <label>Name: <input type="text" name="name" id="name" size="22"/></label>
            </div>
            <div class="field">
              <input type="hidden" name="due" value="1" />
                <label>Due:
                <input type="text" id="duedate" class="trac-datetimepicker"
                       name="duedate" size="${len(datetime_hint) + 1}"
                       title="${_('Format: %(datehint)s', datehint=datetime_hint)}"/>
                <span class="trac-datetimehint" i18n:msg="datetimehint">Format: $datetime_hint</span>
              </label>
            </div>
            <div class="buttons">
              <input type="submit" name="add" class="trac-disable-on-submit" value="${_('Add')}"/>
            </div>
          </fieldset>
        </form>

        <py:choose>
          <form id="milestone_table" method="post" action="" py:when="milestones">
            <table class="listing" id="millist">
              <thead>
                <tr><th class="sel" py:if="can_remove"></th>
                  <th>Name</th><th>Due</th><th>Completed</th>
                  <th title="Default milestone for new tickets">Default</th>
                  <th title="Default milestone for retargeting tickets">Retarget</th>
                  <th title="Number of tickets associated with milestone">Tickets</th>
                </tr>
              </thead>
              <tbody><tr py:for="milestone in milestones">
                <td class="sel" py:if="can_remove">
                  <input type="checkbox" class="trac-disable-determinant"
                         name="sel" value="$milestone.name" />
                </td>
                <td>
                  <a href="${panel_href(milestone.name)}">${milestone.name}</a>
                </td>
                <td><py:if test="milestone.due">
                  ${format_datetime(milestone.due)}
                </py:if></td>
                <td><py:if test="milestone.completed">
                  ${format_datetime(milestone.completed)}
                </py:if></td>
                <td class="default">
                  <input type="radio" name="ticket_default" value="$milestone.name"
                         checked="${milestone.name==ticket_default or None}" />
                </td>
                <td class="default">
                  <input type="radio" name="retarget_default" value="$milestone.name"
                         checked="${milestone.name==retarget_default or None}" />
                </td>
                <td class="num" py:with="ticket_count = num_tickets(milestone)">
                  <a py:strip="ticket_count == 0"
                     href="${query_href(milestone.name)}">$ticket_count</a>
                </td>
              </tr></tbody>
            </table>
            <div class="buttons">
              <input type="submit" name="apply" value="${_('Apply changes')}" />
              <input type="submit" name="remove" class="trac-disable trac-disable-on-submit" value="${_('Remove selected items')}" py:if="can_remove" />
              <input type="submit" title="Clear default ticket milestone and default retargeting milestone"
                     name="clear" value="${_('Clear defaults')}" />
            </div>
            <p class="help">
              You can remove all items from this list to completely hide this
              field from the user interface.
            </p>
          </form>

          <p py:otherwise="" class="help">
            As long as you don't add any items to the list, this field
            will remain completely hidden from the user interface.
          </p>
        </py:choose>
      </py:otherwise>
    </py:choose>
  </body>

</html>
