<%@ page import="com.atlassian.jira.issue.search.SearchResults,
                 com.atlassian.jira.issue.search.util.QueryCreator,
                 com.atlassian.jira.web.action.issue.IssueNavigator,
                 com.atlassian.jira.web.component.IssueTableLayoutBean,
                 com.atlassian.jira.web.component.IssueTableWebComponent,
                 java.util.List"%>
<%@ taglib uri="webwork" prefix="webwork" %>
<%@ taglib uri="sitemesh-page" prefix="page" %>
<webwork:if test="/searchResults && /hasAnyErrors == false">
    <jsp:include page="/includes/navigator/table/header.jsp"/>
</webwork:if>
<webwork:else>
    <page:applyDecorator name="jirapanel">
        <page:param name="title"><webwork:property value="text('navigator.title')"/></page:param>
        <page:param name="width">100%</page:param>
        <p>
            <webwork:text name="'navigator.desc1'"/>
        </p>
        <p>
            <webwork:text name="'navigator.desc2'"/>
        </p>

        <webwork:if test="/hasErrors == true">
            <div class="warningBox">
                <webwork:text name="'navigator.warning'"/>
            </div>
        </webwork:if>
    </page:applyDecorator>
</webwork:else>

<%--  If we have used a 'smart search' then inform the user of this fact, and allow them to query again without smart search --%>
<% if ("true".equalsIgnoreCase(request.getParameter("usedQuickSearch"))) { %>
<p>
    <%-- resin has a bug where you can't get URL parameters multiple times, so retrieve it here, and pass it around --%>
    <webwork:property value="$originalQuickSearchQuery" id="origQuery" />

    <form method="POST" action="<%= QueryCreator.QUERY_PREFIX%>" name="smartquery">
    <input type="hidden" name="query" value="<webwork:property value="@origQuery" />" >
        <div class="noteBox fullyCentered" style="width:50%;">
            <span style="float: right;">
                <webwork:component template="help.jsp" name="'quicksearch'" >
                    <webwork:param name="'noalign'" value="true"/>
                </webwork:component>
            </span>
        <webwork:text name="'navigator.quicksearch.activated'"/>
        <a href="<%= QueryCreator.QUERY_PREFIX%>&query=<webwork:property value="@origQuery" />"
           onClick="document.smartquery.submit(); return false;"><webwork:text name="'navigator.quicksearch.runwithout'"/></a>.
        </div>
    </form>
<% } %>




<p>
<webwork:if test="/hasErrorMessages == false && /hasErrors == false" >
<%-- Set this so that it can be used further down --%>
<webwork:property value="/" id="issueNavigator" />

<%
    IssueNavigator issueNavigator = (IssueNavigator) request.getAttribute("issueNavigator");

    SearchResults searchResultsPager = issueNavigator.getSearchResults();
    List currentPage = searchResultsPager != null ? searchResultsPager.getIssues() : null;
    if (currentPage != null && !currentPage.isEmpty())
    {
        // as the table layout bean is expensive to create - lets not create it if we don't need to 
        IssueTableLayoutBean layoutBean = issueNavigator.getTableLayoutFactory().getStandardLayout(issueNavigator.getSearchRequest(), issueNavigator.getRemoteUser());
        if ("printable".equalsIgnoreCase(request.getParameter("decorator")))
        {
            layoutBean.setSortingEnabled(false);
        }
%>
<%= new IssueTableWebComponent().getHtml(layoutBean, currentPage, searchResultsPager) %>
<%
    }
%>
</webwork:if>
</p>
