<!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 the main ticket detail box but only if not in preview mode -->
    <py:match path="div[@id='ticket'][@class!='ticketdraft']" />
    
    <!--! Remove 'Change History' title but not 'Attachments'  -->
    <py:match path="h2">
        <py:if test="select('*|text()').render() != 'Change History'">
            <h2>${select('*|text()')}</h2>
        </py:if>
    </py:match>
    
    <!--! Remove the changelog box -->
    <py:match path="div[@id='changelog']" />
    <!--! Remove 'Add/Change #... (...)' title  -->
    <py:match path="h3" />
    
    <!--! Remove comment textarea  -->
    <!--! <py:match path="form[@id='propertyform']/div[@class='field']"/>-->
    
    <xi:include href="agilo_links_edit.html" />
    <!--! 
        Change the main edit form so that it displays references.
    -->
    <py:match path="*/form[@id='propertyform']" once="True">
        <!-- References -->
        ${display_links_edit(ticket, read_only=not may_edit_links, go_to_edit_pane=True, links_search_url=LINKS_SEARCH_URL, links_url=LINKS_URL)}
        <form py:attrs="select('@*')">
            <input type="hidden" name="pane" value="edit"/>
            ${select("*|text()")}
        </form>
    </py:match>
    
    <!--! Trac 0.11.1 does not have the ticket.get_value_or_default method so it
          is very hard for us to replace the ticket type in a sane way.
          
          Unfortunately the XPath "*/select[@id='field-${field.name}']" does 
          not work because py:match is processed before py:for so we fall back 
          to hardcoding just the type.
          
          This py:match must be declared *before* "*/fieldset[@id='properties']"
          otherwise the reference box won't show up.
    -->
    <py:match path="select[@id='field-type']" once="true">
        <py:choose>
            <py:when test="ticket.is_old_trac">
                <py:for each="field in fields">
                    <py:if test="field.name == 'type' and field.type == 'select'">
                        <py:with vars="value = ticket.get_value_or_default('type')">
                            <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}"
                                      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}"
                                        py:content="option"></option>
                              </optgroup>
                            </select>
                         </py:with>
                    </py:if>
                </py:for>
            </py:when>
            <py:otherwise>
                <select id="field-type" name="field_type">
                    ${select("*|text()")}
                </select>
            </py:otherwise>
        </py:choose>
    </py:match>
    <!--!
        Remove the Properties form fields if the current user has only linking permission
    -->
    <py:match path="*/fieldset[@id='properties']" once="True" py:if="may_edit_ticket">
        <fieldset py:attrs="select('@*')">
            ${select("*|text()")}
        </fieldset>
    </py:match>
<!--
    <py:match path="*/fieldset[@id='action']" once="True" py:if="may_edit_ticket or True">
        <fieldset py:attrs="select('@*')">
            ${select("*|text()")}
        </fieldset>
    </py:match>
-->
    <!--!
        Add the Delete button
    -->
    <py:match path="*/div[@class='buttons']" once="true">
        <div class="button">
        ${select("*|text()")}
        <input type="submit" name="delete" value="${_('Delete')}" py:if="may_delete_ticket" />
        </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>
