<!--!  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"
            py:if="view == 'detail' and can_modify or
                   view == 'list' and can_create">
      jQuery(document).ready(function($) {
        $("#duedate").datetimepicker();
        $("#completeddate").datetimepicker();
      });
    </script>
  </head>

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

    <py:choose test="view">
      <form py:when="'detail'" class="mod" method="post" id="modifymilestone" action=""
            py:with="disabled = 'disabled' if not can_modify else None;
                     readonly = 'readonly' if not can_modify else None">
        <fieldset>
          <legend>Modify Milestone:</legend>
          <div class="field">
            <label>Name:<br /> <input type="text" name="name" class="trac-autofocus"
                                      value="$milestone.name" readonly="${readonly}" /></label>
          </div>
          <div class="field">
            <label>Due:<br />
              <input type="text" id="duedate" name="duedate" size="${len(datetime_hint)}"
                     value="${milestone.due and format_datetime(milestone.due)}" readonly="${readonly}"
                     title="${_('Format: %(datehint)s', datehint=datetime_hint)}"/>
              <span class="hint" i18n:msg="datehint">Format: $datetime_hint</span>
            </label>
          </div>
          <div class="field">
            <label>
              <input type="checkbox" id="completed" name="completed"
                     checked="${milestone.completed or None}" disabled="${disabled}"/>
              Completed:<br />
            </label>
            <label>
              <input type="text" id="completeddate" name="completeddate"
                     size="${len(datetime_hint)}"
                     value="${format_datetime(milestone.completed)}" readonly="${readonly}"
                     title="${_('Format: %(datehint)s', datehint=datetime_hint)}" />
              <span class="hint" i18n:msg="datehint">Format: $datetime_hint</span>
            </label>
            <script type="text/javascript">
              jQuery(document).ready(function($) {
                function updateCompletedDate() {
                  $("#completeddate").enable($("#completed").checked());
                }
                $("#completed").click(updateCompletedDate);
                updateCompletedDate();
              });
            </script>
          </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}">
${milestone.description}</textarea>
              </p>
            </fieldset>
          </div>
          <div class="buttons">
            <input type="submit" name="save" value="${_('Save')}" class="trac-disable-on-submit" disabled="${disabled}"/>
            <input type="submit" name="cancel" value="${_('Cancel')}"/>
          </div>
        </fieldset>
      </form>

      <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">
              <label>
                Due:
                <input type="text" id="duedate" name="duedate" size="${len(datetime_hint)}"
                       title="${_('Format: %(datehint)s', datehint=datetime_hint)}"/>
                <span class="hint" 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">&nbsp;</th>
                  <th>Name</th><th>Due</th><th>Completed</th><th>Default</th><th>Tickets</th>
                </tr>
              </thead>
              <tbody><tr py:for="(milestone, ticket_count) in milestones">
                <td py:if="can_remove">
                  <input type="checkbox" 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="default" value="$milestone.name"
                         checked="${milestone.name==default or None}" />
                </td>
                <td class="num">${ticket_count}</td>
              </tr></tbody>
            </table>
            <div class="buttons">
              <input type="submit" name="apply" value="${_('Apply changes')}" />
              <input type="submit" name="remove" class="trac-disable-on-submit" value="${_('Remove selected items')}" py:if="can_remove"/>
            </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>
