<!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:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      py:strip="True">
    
    <xi:include href="agilo_ticket_pane.html" />
    
    <!--! Remove attachements upload form -->
    <py:match path="form[@id='attachfile']" once="True" />
    
    <!--! Remove the attachments section if there there are no attachments
          as the box is useless then (in vanilla trac you can at least upload
          new attachments with the form in this box. -->
    <py:if test="len(attachments.get('attachments', [])) == 0">
        <!--! Hide the 'Attachments' heading but only that one, not the 
             'Change History' heading-->
        <py:match path="div[@id='content']/h2" once="True">
            <py:if test="select('*|text()').render() != 'Attachments'">
                <h2 py:attrs="select('@*')">${select('*|text()')}</h2>
            </py:if>
        </py:match>
        <!--! Hide the box without contents (because form is hidden previously) -->
        <py:match path="div[@id='attachments']" once="True" />
    </py:if>
    
    <!--! Remove the form to change any attributes here -->
    <py:match path="form[@id='propertyform']/fieldset[@id='properties']" />
    <py:match path="form[@id='propertyform']/fieldset[@id='action']" />
    
    <!--! 
        Add a new hidden field 'action' for the ticket view so that this field
        is available for previews!
    -->
    <py:match path="*/form[@id='propertyform']">
        <py:if test="may_comment_ticket">
            <form py:attrs="select('@*')">
                <input type="hidden" name="action" value="leave" />
                ${select("*|text()")}
            </form>
        </py:if>
    </py:match>
    
    <!--! Add the calculated properties below the ticket fields  -->
    <py:match path="*/div[@id='ticket']/table[@class='properties']">
        <table py:attrs="select('@*')">
            ${select("*|text()")}
            <!--! Insert the calculated properties as well -->
            <py:with vars="fields = [f for f in ticket.get_calculated_fields() if not f.skip]">
              <tr py:for="row in group(fields, 2, lambda f: f.type != 'textarea')"
                  py:with="fullrow = len(row) == 1" class="calculated">
                <py:for each="idx, field in enumerate(row)">
                  <th py:if="idx == 0 or not fullrow"
                      id="${field and 'h_'+field.name or None}">
                    <py:if test="field">${_(field.label) or _(field.name)}:</py:if>
                  </th>
                  <td py:if="idx == 0 or not fullrow"
                      headers="${field and 'h_'+field.name or None}"
                      class="${field and field.name in ('cc', 'keywords') and 'searchable' or None}"
                      colspan="${fullrow and 3 or None}">
                    <py:if test="field">
                      <py:choose test="">
                        <py:when test="'rendered' in field">${field.rendered}</py:when>
                        <py:otherwise>${ticket[field.name]}</py:otherwise>
                      </py:choose>
                    </py:if>
                  </td>
                </py:for>
              </tr>
            </py:with>
        </table>
    </py:match>
    
    <!--! 
        Remove the preview ticket details because they are not changed when
        commenting anyway 
    -->
    <py:match path="div[@id='ticket'][@class='ticketdraft']" />
    
    <py:match path="*/div[@id='ticket']/div[@class='description']">
        ${select("*|text()")}
        <div py:attrs="select('@*')">
            <h3>${_('References')}</h3>
            <table class="links">
                <xi:include href="agilo_links_view.html" />
                ${display_links(ticket, read_only=True)}
            </table>
        </div>
    </py:match>
    
    <!--!
      Add the link to the Agilo ticket help. There should be a more elegant way to replace the content of the tag without removing the tag.
    -->
    <py:match path="*/div[@id='help']" once="true">
        <div id="help">
        ${select("*|text()")}
        You may also have a look at Agilo <a href="${req.href('agilo-help', 'user/ticket')}">extensions to the ticket</a>.
        </div>
    </py:match>
    
    <!--! Include the original template which does all the hard work -->
    <xi:include href="ticket.html" />
    
</html>
