<!--!
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
-->

<!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"
      xmlns:bh="http://issues.apache.org/bloodhound/wiki/Ui/Dashboard"
      py:with="preview_mode = 'preview' in req.args;
          can_append = 'TICKET_APPEND' in perm(ticket.resource);
          can_create = 'TICKET_CREATE' in perm(ticket.resource) and not ticket.exists;
          can_modify = 'TICKET_CHGPROP' in perm(ticket.resource);
          can_edit = 'TICKET_EDIT_DESCRIPTION' in perm(ticket.resource);
          only_for_admin = 'TICKET_ADMIN' in perm(ticket.resource);
          has_edit_comment = 'TICKET_EDIT_COMMENT' in perm(ticket.resource);
          has_property_editor = not version and version != 0 and not cnum_edit
                                and (can_append or can_modify or can_edit or can_create);
          colspan = 'span7';
          cols_activity = 'span5'">
  <xi:include href="layout.html" />
  <xi:include href="widget_macros.html" />

  <head>
    <!--! hack for hiding the activity feed title in desktop/tablet landscape mode (the title is part of the sticky) -->
    <style>
      @media (min-width: 768px) {
        #activity h3 { display: none !important; }
      }
      @media (max-width: 767px) {
        #activity h3 { display: inherit !important; }
      }
    </style>
    <title py:choose="">
      <py:when test="ticket.exists">#${ticket.id} (${ticket.summary})</py:when>
      <py:otherwise>New Ticket</py:otherwise>
    </title>
    <script py:if="ticket.exists" type="text/javascript" src="${chrome.htdocs_location}js/threaded_comments.js"></script>
    <script type="text/javascript" py:choose="">
      jQuery(document).ready(function($) {
        /* Affixed navbar */
        $(".local-nav a").click(function() {
          $($(this).attr('href')).removeClass('collapsed')
                                 .parent().removeClass("collapsed");
        });
        $('.trac-nav').hide();
        $('.trac-topnav').hide();

        <py:if test="has_property_editor">
        // Install in place editing
        install_workflow();
        $('#edit-cancel, #edit-cancel-below').click(revert_ticket);

        var modify_elem = $('#modify');
        modify_elem.parent().hide();
        $('#propertyform .buttons [name="preview"]').hide();
        $('#comment').change(function (e) {
          $('#hidden-comment').val($('#comment').val());
        });
        $('#propertyform .buttons [name="submit"]').click(function (e) {
          if ($('button#edit-submit').length) {
            // if available trigger the edit state's update button
            $('button#edit-submit').click();
            e.preventDefault();
          }
          // otherwise the default submit comment only happens
        });

        function modify_ticket(newticket) {
          if ($('#vc-summary').is('.edit-active'))
            // Already in editable state
            return;
          $('#vc-summary').attr('contenteditable', 'true');
          $('[data-edit="inplace"]').each(function() {
              var fc = $(this).addClass('edit-active');
              var fieldnm = fc.attr('id').substr(3);
              fc.attr('data-edit-orig', fc.html());
              
              if (fieldnm != 'summary') {
                fc.empty();
              }
              var editor = $('#properties #field-' + fieldnm);
              if (editor.length == 0)
                editor = $('#editor-' + fieldnm);
              var fieldval = editor.val();
              editor = editor.clone(false);
              if (fieldnm === 'summary') {
                editor.hide().appendTo($('#dummy-vc-summary'));
              }
              else {
                editor.appendTo(fc);
              }
              editor.val(fieldval);
              if (editor.prop('tagName') === 'TEXTAREA') {
                if (editor.is('.wikitext'))
                  addWikiFormattingToolbar(editor.get(0));
              }
              if (fieldnm === 'summary') {
                editor.wrap('<div class="btn-group"></div>')
              }
            });

          // Enable automatic preview
          //$('#inplace-propertyform').autoSubmit({preview : 1}, 
          //    full_preview, '#overview .trac-loading')
          $('#inplace-propertyform').submit(function() {
              $('#hidden-comment').val($('#edit-comment').val());
            })

          $('#inplace-edit, #vc-status a').hide();
          $('#edit-state-buttons, #edit-state-buttons-below, #edit-workflow-buttons, #edit-comment').show();
          if (!newticket) {
            // disable input controls on all other forms when in modify mode
            $('.activityfeed, .relations, #attachments').css('opacity', '0.3');
            $('form:not("#inplace-propertyform") :input').attr('disabled', 'disabled');
            $('#qct-inline, #qct-inline-notice-success, #qct-inline-notice-error').hide({'duration': 400});
          }
        }

        function add_update_hidden_summary_fn() {
          $('#vc-summary').blur(function () {
            if ($('#vc-summary.edit-active').length == 1) {
              $('#dummy-vc-summary input#field-summary').val($('#vc-summary').text());
            }
          });
        }

        function revert_ticket(e) {
          $('[data-edit="inplace"]').each(function() {
              var fc = $(this).removeClass('edit-active');
              fc.html(fc.attr('data-edit-orig')).attr('data-edit-orig', '');
            });
          //remove summary field and re-add the summary blur function
          $('#dummy-vc-summary div').remove();
          add_update_hidden_summary_fn();
          $('#vc-summary').attr('contenteditable', 'false');

          $('#inplace-edit, #vc-status a').show();
          $('#edit-state-buttons, #edit-state-buttons-below, #edit-workflow-buttons, #edit-comment').hide();
          $('form:not("#inplace-propertyform") :input').removeAttr('disabled');
          $('.activityfeed, .relations, #attachments').css('opacity', '');

          e.preventDefault();
        }

        function install_workflow(){
          <py:if test="bhrelations">/*<![CDATA[*/
          $('select[id$=_resolve_resolution]').each(function () {
            var prefix = $(this).attr('id').split('_').slice(0, 2).join('_');
            $(this).parent().append('<span class="duplicate_id hide">Duplicate ID:&nbsp;' +
                                    '<input id="' + prefix + '_duplicate_id" name="duplicate_id" type="text" class="input-mini" value="${ticket_duplicate_of}" /></span>');
          });
          /*]]>*/</py:if>
          var actions_box = $('#workflow-actions')
              .click(function(e) { e.stopPropagation(); });
          $('#action').children('div').each(function() {
              var action_ui = $(this).clone(false).prependTo(actions_box)
                  .wrap('<li style="padding: 5px 10px"></li>');
              var action_trigger = action_ui.find('input[name=action]');
              var action_select_trigger = action_ui.find('select');
              var action_input_trigger = action_ui.find('input:not([name=action])');

              function action_click() {
                var action = action_ui.find('input[name=action]').val();
                var newowner = action_ui.find('input[id$=_reassign_owner]').val();
                var newresolution = action_ui.find('select[id$=_resolution]').val();
                var newlabel = action_ui.find('label[for^=action_]')
                    .text();
                if (action === 'leave')
                  newlabel = newlabel + ' as ' + $('#vc-status a').text();
                else if (newowner)
                  newlabel = newlabel + ' to ' + newowner;
                else if (newresolution) {
                  newlabel = newlabel + ' as ' + newresolution;
                  if (newresolution === 'duplicate') {
                    $('.duplicate_id', $(this).parent()).show();
                  } else {
                    $('.duplicate_id', $(this).parent()).hide();
                  }
                }
                $('#submit-action-label').text(newlabel);

                // Enable | disable action controls
                actions_box.find('input[name=action]').each(function() {
                    $(this).siblings().find("*[id]")
                        .enable($(this).checked());
                    $(this).siblings().filter("*[id]")
                        .enable($(this).checked());
                  });
              }
              action_trigger.click(action_click);
              action_select_trigger.change(action_click);
              action_input_trigger.blur(action_click);
              if (action_trigger.attr('checked'))
                action_click();

              var action_help = action_ui.find('.help-block').detach()
                  .text().replace(/\s+/g, ' ').replace(/^ Tip /g, 'Tip: ')
                  .replace(/^\s$/, '');
              if (action_help)
                  $('<i class="icon-info-sign"></i>').appendTo(action_ui)
                      .attr('title', action_help);
            });
          }

        add_update_hidden_summary_fn();

        $('#inplace-edit-button button#inplace-edit').click(function (e) {
          modify_ticket(false);
          e.preventDefault();
        });
        </py:if>

        $('body').scrollspy({
            'target' : '.ticket-navbar',
            'offset' : 0
          })
        $("div.description").find("h1,h2,h3,h4,h5,h6").addAnchor(_("Link to this section"));
        $(".foldable").enableFolding(false, true);
        /*<![CDATA[*/
        $("#modify").parent().toggleClass("collapsed");
        $(".trac-topnav a").click(function() { $("#modify").parent().removeClass("collapsed"); });

        /* only enable control elements for the currently selected action */
        var actions = $("#action input[name='action']");

        function updateActionFields() {
          actions.each(function () {
            $(this).siblings().find("*[id]").enable($(this).checked());
            $(this).siblings().filter("*[id]").enable($(this).checked());
          });
        }
        actions.click(updateActionFields);
        updateActionFields();

        var comment_focused = false;
        $("#comment").focus(function() { comment_focused = true; })
                     .blur(function() { comment_focused = false; });
        function full_preview(data, reply) {
          var items = $(reply);
          // Unthread, unrevert and update changelog
          if (!$('#trac-comments-oldest').checked()){
            $("input[name='trac-comments-order']").addClass('disablechange');
            $('#trac-comments-oldest').click();
          }
          $("#changelog").replaceWith(items.filter("#changelog"));
          if ($('#trac-comments-only-toggle').attr('checked'))
            $('#trac-comments-only-toggle').click().attr('checked', true);
          // Show warning
          var new_changes = $("#changelog .trac-new");
          $("#trac-edit-warning").toggle(new_changes.length != 0);
          if (new_changes.length != 0)
            $("#changelog").parent().show().removeClass("collapsed");
          // Update view time
          $("#propertyform input[name='view_time']").replaceWith(items.filter("input[name='view_time']"));
          // Update preview
          var preview = $("#ticketchange").html(items.filter('#preview').children());
          var show_preview = preview.children().length != 0;
          $("#ticketchange").toggle(show_preview);
          // Collapse property form if comment editor has focus
          if (show_preview && comment_focused)
            $("#modify").parent().addClass("collapsed");
          if ($("input[name='trac-comments-order']").hasClass('disablechange')) {
            $('#trac-comments-newest').click();
            $("input[name='trac-comments-order']").removeClass('disablechange')
          }
        }
        $("#propertyform").autoSubmit({preview: '1'}, full_preview,
            "#ticketchange .trac-loading");
        $("#trac-comment-editor").autoSubmit({preview_comment: '1'}, function(data, reply) {
          var comment = $("#trac-comment-editor").next("div.comment").html(reply);
          comment.toggle(comment.children().length != 0);
        }, "#changelog .trac-loading");

        // quick hack to set arrow direction on change
        if (typeof(comments_prefs) !== "undefined") {
          arrow_dir = {
            'oldest': function() {
              $('div#changelog').addClass('downarrow');
              $('div#changelog').removeClass('uparrow');
            },
            'newest': function() {
              $('div#changelog').addClass('uparrow');
              $('div#changelog').removeClass('downarrow');
            },
          };
          $('#trac-comments-newest').change(arrow_dir['newest']);
          $('#trac-comments-oldest').change(arrow_dir['oldest']);
          arrow_dir[comments_prefs.comments_order]();
        };
        /*]]>*/
        <py:if test="preview_mode">
        $("#attachments").toggleClass("collapsed");
        $("#trac-add-comment").scrollToTop();
        </py:if>
        <py:if test="not ticket.exists">
        modify_ticket(true);
        $('#vc-status').parent().hide();
        $('#vc-product').parent().hide();
        </py:if>
        $('[placeholder-content]').blur(function () {
          if ($(this).text().trim()) { $(this).attr('placeholder-hide', 'true'); }
          else { $(this).removeAttr('placeholder-hide'); }
        });
        /*<![CDATA[*/
        var init_comment_height = $('#comment').height();
        $("#comment").focus(function() {
          if ($(this).height() < 50) {
            $(this).animate({ height: 100 }, 500);
          }}).blur(function() { 
          if ($(this).height() <= 100 && $(this).val().length == 0 ) {
            $(this).animate({ height: init_comment_height }, 500);
          }
          });
        /*]]>*/
      });
    </script>
  </head>

  <body>
    <py:def function="render_ticket_summary(t, showid)">
      <py:if test="showid"><h2><span class="visible-phone">${'#' + t.id if t.exists else 'NEW'} - </span></h2></py:if>
      <h2 class="ticket-summary searchable clip-affix" contenteditable="false"
        data-edit="${'inplace' if can_modify or can_create else None}" id="vc-summary"
        placeholder-content="${'Enter ticket summary' if not t.summary else ''}">${t.summary if t.summary else None}</h2>
    </py:def>
    
    <py:def function="render_ticket_summary_details(t)">
      <h5 id="trac-ticket-title" py:choose="">
        <py:when test="t.exists">
          <a href="${href.ticket(t.id)}"
              i18n:msg="id">Ticket #${t.id}</a>
          <small py:if="version is not None">
            <py:choose test="">
              <py:when test="version == 0">
                <i18n:msg>at <a href="#comment:description" class="muted">Initial Version</a></i18n:msg>
              </py:when>
              <py:otherwise>
                <i18n:msg params="version">at <a href="#comment:$version" class="muted">Version $version</a></i18n:msg>
              </py:otherwise>
            </py:choose>
          </small> &mdash;
        </py:when>
        <py:otherwise>
          New Ticket <small><span py:if="preview_mode and t.type" class="status">(${t.type})</span></small>
        </py:otherwise>

        <span class="ticket-info">
          <span id="h_owner">Assigned to
            ${(owner_link if defined('owner_link') else authorinfo(t.owner)) if t.owner else ''},
          </span>
          <py:if test="t.changetime != t.time">
            <span i18n:msg="modified">last modified ${pretty_dateinfo(t.changetime)}</span>
          </py:if>
          <span py:if="not t.exists" class="label label-warning">(ticket not yet created)</span>
        </span>
      </h5>
      <span id="inplace-edit-button" py:if="has_property_editor"
            class="btn-toolbar" style="${'display: None;' if not t.exists else ''}">
        <button id="inplace-edit" class="btn">
          <i class="icon-edit"></i>
          <span>${_('Modify Ticket')}</span>
        </button>
        <span id="edit-state-buttons" class="btn-toolbar" style="display: None">
          <button id="edit-submit" class="btn" type="submit"
              value="Submit changes" name="submit">
            Submit changes
          </button>
          <button id="edit-cancel" class="btn-link" title="Discard changes">
            Cancel
          </button>
        </span>
      </span>
    </py:def>

    <div id="content" class="ticket">
      <div class="trac-topnav span2" py:if="has_property_editor">
        <a href="#propertyform" title="Go to the ticket editor">Modify</a> &darr;
      </div>
      <br/>
      
      <div class="row">
        <div class="span12">
          ${render_ticket_summary(ticket, False)}
        </div>
      </div>

      <div class="row">
        <div class="$colspan">
          <form py:strip="not has_property_editor" method="post" id="inplace-propertyform"
              action="${href.ticket(ticket.id) + '#trac-add-comment' if ticket.exists else href.newticket() + '#ticket'}">
            <py:if test="has_property_editor">
              <input type="hidden" name="start_time" value="${to_utimestamp(start_time)}" />
              <input type="hidden" name="view_time" value="${to_utimestamp(ticket['changetime'])}" />
            </py:if>
            <input id="hidden-comment" type="hidden" name="comment" value="" />
    
            <!--! ticket properties -->
            <div class="properties">
              ${render_ticket_summary_details(ticket)}
            </div>

            <div>
              <div id="belowStatus">
                <!--! ticket details -->
                <!--! main ticket info -->
                <div class="properties">
                  <xi:include href="bh_ticket_box.html"
                      py:with="preview_mode = change_preview.fields if change_preview else False;
                               colcount = 4 if bhdb else 6"/>
                </div>

                <div id="dummy-vc-summary" style="display: none"></div>

                <py:if test="ticket.exists">
                  <textarea id="edit-comment" class="trac-resizable span7 hide" name="edit-comment"
                      rows="4" placeholder="Enter new comment" onfocus="this.placeholder = ''"
                      onblur="this.placeholder = 'Enter new comment'"></textarea>

                  <div id="edit-state-buttons-below" class="btn-toolbar hide">
                    <button id="edit-submit-below" class="btn" type="submit"
                        value="Submit changes" name="submit">
                      Submit changes
                    </button>
                    <button id="edit-cancel-below" class="btn-link" title="Discard changes">
                      Cancel
                    </button>
                  </div>
                </py:if>

                <py:if test="not ticket.exists">
                  <!--! Attachment on creation checkbox -->
                  <p py:if="'ATTACHMENT_CREATE' in perm(ticket.resource.child('attachment'))">
                    <label>
                      <input type="checkbox" name="attachment" checked="${'attachment' in req.args or None}" />
                      I have files to attach to this ticket
                    </label>
                  </p>

                  <!-- Current product prefix, used to override default_product from config. -->
                  <input type="hidden" id="field-product" name="field_product" value="$req.perm.env.product.prefix" />

                  <div class="buttons">
                    <input type="submit" class="btn" name="submit" value="${_('Create ticket')}" />
                  </div>
                </py:if>
              </div>
            </div>
          </form>

          <div py:if="bhrelations and ticket.exists and has_property_editor" class="relations">
            <bh:widget urn="TicketRelations">
              <bh:args>
                <bh:arg name="tid">$ticket.id</bh:arg>
                <bh:arg name="max">20</bh:arg>
              </bh:args>
            </bh:widget>
          </div>

          <!--! do not show attachments for old versions of this ticket or for new tickets -->
          <div py:if="not version and version != 0 and ticket.exists">
            <xi:include href="bh_fu_list_of_attachments.html" py:with="alist = attachments; foldable = True"/>
          </div>

          <div id="help" class="help-block" i18n:msg="">
            <span class="label label-info">Note:</span> See
            <a href="${href.wiki('TracTickets')}">TracTickets</a> for help on using tickets.
          </div>
        </div>
        
        <div class="${cols_activity + ' activityfeed' if ticket.exists else None}">
          <form py:if="ticket.exists" id="prefs" method="get" action="${href.prefs()}">
            <div id="trac-comments-order" class="pull-right">
              <input type="radio" id="trac-comments-newest" name="trac-comments-order" value="newest" />
              <label for="trac-comments-newest">
                <span>Newest first</span>
              </label>
              <input type="radio" id="trac-comments-oldest" name="trac-comments-order" value="oldest" checked="checked" />
              <label for="trac-comments-oldest">
                <span>Oldest first</span>
              </label>
            </div>
            <div class="clearboth"></div>
          </form>

          <form py:if="has_property_editor" method="post" id="propertyform"
                    action="${href.ticket(ticket.id) + '#trac-add-comment' if ticket.exists
                              else href.newticket() + '#ticket'}">

            <div py:if="ticket.exists and can_append">
              <!--! Add comment -->
              <div id="trac-add-comment" class="field">
                <div class="trac-nav">
                  <a href="#belowStatus" title="View ticket fields and description">View</a> &uarr;
                </div>
                <div id="trac-edit-warning" class="warning system-message alert"
                      style="${'display: none' if start_time == ticket['changetime'] else None}"
                      i18n:msg="">
                  <span class="label label-warning">Warning</span>
                  This ticket has been modified since you started editing. You should review the
                  <em class="trac-new">other modifications</em> which have been appended above,
                  and any <em class="trac-conflict">conflicts</em> shown in the preview below.
                  You can nevertheless proceed and submit your changes if you wish so.
                </div>

                <!--! Comment field -->
                <fieldset class="iefix">
                  <textarea id="comment" name="comment" class="trac-resizable" rows="2"
                      placeholder="Enter new comment" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter new comment'">${comment}</textarea>
                  <input type="submit" id="comment-submit" class="btn pull-right" name="submit" value="${_('Submit')}" />
                  <label for="comment" class="help-block" i18n:msg="">
                    <span class="label label-info">Tip</span>
                    You may use
                    <a tabindex="42" href="${href.wiki('WikiFormatting')}">WikiFormatting</a>
                    here.
                  </label>
                </fieldset>
              </div>
            </div>

            <div>
              <h2 py:if="ticket.exists" class="foldable">Modify Ticket</h2>
              <div id="modify" class="well">
                <!--! Properties -->
                <fieldset id="properties" py:if="can_modify or can_edit or can_create"
                          py:with="fields = [f for f in fields if not f.skip and f.name != 'product']">
                  <legend py:choose="">
                    <py:when test="ticket.exists">Change Properties</py:when>
                    <py:otherwise>Properties</py:otherwise>
                  </legend>

                  <table id="modifyproperties">
                    <tr py:if="can_modify or can_create">
                      <td colspan="2">
                        <label for="field-product-name">Product:</label>
                        <input type="text" disabled="disabled"
                          id="field-product-name" name="field_product_name"
                          value="$req.perm.env.product.name ($req.perm.env.product.prefix)" />
                        <input type="hidden" id="field-product" name="field_product" value="$req.perm.env.product.prefix" />
                      </td>
                    </tr>

                    <tr py:if="can_modify or can_create">
                      <td colspan="2">
                        <label for="field-summary">Summary:</label>
                        <input class="span4" type="text" id="field-summary" name="field_summary" value="$ticket.summary" />
                      </td>
                    </tr>

                    <tr py:if="only_for_admin">
                      <td colspan="2">
                        <label for="field-reporter">Reporter:</label>
                        <input type="text" id="field-reporter" name="field_reporter" value="${ticket.reporter}" />
                      </td>
                    </tr>

                    <tr py:if="can_edit or can_create">
                      <td colspan="2">
                        <label for="field-description">Description:</label>
                        <fieldset class="iefix">
                          <textarea id="field-description" name="field_description"
                                    class="span7 wikitext trac-resizable" rows="10">${ticket.description}</textarea>
                          <label for="field-description" id="field-description-help" class="help-block pull-right" i18n:msg="">
                            <span class="label label-info">Tip</span>
                            You may use
                            <a tabindex="42" href="${href.wiki('WikiFormatting')}">WikiFormatting</a> here.
                          </label>
                        </fieldset>
                      </td>
                    </tr>

                    <tr py:for="row in group(fields, 2, lambda f: f.type != 'textarea')"
                        py:if="can_modify or can_create">
                      <py:for each="idx, field in enumerate(row)"
                              py:with="value = ticket.get_value_or_default(field.name)">
                        <td>
                          <label for="field-${field.name}" py:if="field" id="${'editor-' + field.name}"
                                  i18n:msg="field">${field.edit_label or field.label or field.name}:</label>
                          <py:choose test="field.type" py:if="field">
                            <select py:when="'select'" id="field-${field.name}" name="field_${field.name}">
                              <option py:if="field.optional"></option>
                              <option py:for="option in field.options"
                                      selected="${value == option or None}"
                                      value="$option" py:content="option"></option>
                              <optgroup py:for="optgroup in field.optgroups"
                                        py:if="optgroup.options"
                                        label="${optgroup.label}">
                                <option py:for="option in optgroup.options"
                                        selected="${value == option or None}"
                                        value="$option" py:content="option"></option>
                              </optgroup>
                            </select>
                            <textarea py:when="'textarea'" id="field-${field.name}" name="field_${field.name}"
                                      cols="${field.width}" rows="${field.height}"
                                      class="${'wikitext ' if field.format == 'wiki' else None}trac-resizable">${value}</textarea>
                            <span py:when="'checkbox'">
                              <input type="checkbox" id="field-${field.name}" name="field_${field.name}"
                                      checked="${value == '1' or None}" value="1" />
                              <input type="hidden" name="field_checkbox_${field.name}" value="1" />
                            </span>
                            <label py:when="'radio'" class="checkbox inline"
                                    py:for="idx, option in enumerate(field.options)">
                              <input type="radio" name="field_${field.name}" value="${option}"
                                      checked="${value == option or None}" />
                              ${option}
                            </label>
                            <py:otherwise><!--! Text input fields -->
                              <py:choose>
                                <span py:when="field.cc_entry"><!--! Special case for Cc: field -->
                                  <em>${field.cc_entry}</em>
                                  <input type="checkbox" id="field-cc" name="cc_update"
                                    title="This checkbox allows you to add or remove yourself from the CC list."
                                    checked="${field.cc_update}" />
                                </span>
                                <!--! Cc: when TICKET_EDIT_CC is allowed -->
                                <span py:when="field.name == 'cc'">
                                  <input type="text" id="field-${field.name}"
                                    title="Space or comma delimited email addresses and usernames are accepted."
                                    name="field_${field.name}" value="${value}" />
                                </span>
                                <!--! All the other text input fields -->
                                <input py:otherwise="" type="text" id="field-${field.name}"
                                  name="field_${field.name}" value="${value}" />
                              </py:choose>
                            </py:otherwise>
                          </py:choose>
                        </td>
                      </py:for>
                    </tr>
                  </table>
                </fieldset>

                <!--! Workflow support -->
                <py:if test="ticket.exists"> <!--! do not display the actions for New tickets -->
                  <py:choose>
                    <fieldset py:when="can_append or can_modify" id="action">
                      <legend>Action</legend>
                      <xi:include href="bh_ticket_actions.html" />
                    </fieldset>
                    <py:otherwise>
                      <py:for each="key, label, controls, hints in action_controls">
                        <input py:if="key == action" type="hidden" name="action" value="$action" />
                      </py:for>
                    </py:otherwise>
                  </py:choose>
                </py:if>
              </div>
            </div>

            <div>
              <!--! Preview of ticket changes -->
              <div py:if="ticket.exists and can_append" id="ticketchange" class="ticketdraft"
                    style="${'display: none' if not (change_preview.fields or change_preview.comment)
                                                or cnum_edit is not None else None}">
                <xi:include href="bh_ticket_change.html" py:with="change = change_preview; preview = True"/>
              </div>

              <!--! Author or Reporter -->
              <div py:if="authname == 'anonymous'" class="field">
                <fieldset py:choose="">
                  <legend py:when="ticket.exists">Author</legend>
                  <legend py:otherwise="">Reporter</legend>
                  <table>
                    <tr>
                      <th>
                        <label for="author">Your email or username:</label><br />
                      </th>
                      <td>
                        <input type="text" id="author" name="author" size="40" value="$author_id" />
                        <br />
                      </td>
                    </tr>
                  </table>
                  <p py:if="author_id == 'anonymous'" class="hint">
                    <i18n:msg>E-mail address and user name can be saved in the <a href="${href.prefs()}" class="trac-target-new">Preferences</a>.</i18n:msg>
                  </p>
                </fieldset>
              </div>

              <py:if test="ticket.exists">
                <div class="trac-nav">
                  <a href="#attachments" title="Go to the list of attachments">Attachments</a> &uarr;
                </div>
                <div class="buttons">
                  <input type="hidden" name="start_time" value="${to_utimestamp(start_time)}" />
                  <input type="hidden" name="view_time" value="${to_utimestamp(ticket['changetime'])}" />
                  <input type="hidden" name="replyto" value="${replyto}" />
                </div>
              </py:if>
            </div>
          </form>

          <div id="changelog">
            <!--! add comment + modify ticket -->
            <py:for each="change in changes">
              <div class="change${' trac-new' if change.date > start_time and 'attachment' not in change.fields else None}"
                    id="${'trac-change-%d-%d' % (change.cnum, to_utimestamp(change.date)) if 'cnum' in change else None}">
                <xi:include href="bh_ticket_change.html"/>
              </div>
            </py:for>
          </div>
        </div>
      </div>
    </div>

    <script type="text/x-tmpl" id="tmpl-inplace-submit" py:if="has_property_editor">
      <div class="btn-toolbar">
        <div class="btn-group">
          <span class="trac-loading">&nbsp;</span>
        </div>
      </div>
    </script>

  </body>
</html>
