<%@ page import="com.atlassian.core.util.WebRequestUtils" %>
<%@ page import="com.atlassian.jira.ComponentManager"%>
<%@ page import="com.atlassian.jira.plugin.webfragment.model.JiraHelper"%>
<%@ page import="com.atlassian.jira.web.component.webfragment.WebFragmentWebComponent"%>
<%@ page import="com.atlassian.util.profiling.UtilTimerStack"%>
<%@ page import="org.ofbiz.core.entity.GenericValue"%>
<%@ taglib uri="webwork" prefix="webwork" %>
<%@ taglib uri="sitemesh-page" prefix="page" %>
<webwork:bean id="fieldVisibility" name="'com.atlassian.jira.web.bean.FieldVisibilityBean'"/>

<page:applyDecorator name="portletpanel">
    <page:param name="header">
        <webwork:if test="@showToggle == 'true' && property('projectinfo') != 'brief'">
            <% if (WebRequestUtils.isGoodBrowser(request))
            { %> <span class="switch actionLinks subText"
                       id="project_<webwork:property value="../id"/>_<webwork:property value="string('id')"/>-switch"
                       onclick="CookieUtil.toggleVisibility('project_<webwork:property value="../id"/>_<webwork:property value="string('id')"/>', '<webwork:property value="/text('displaypane.show')" />', '<webwork:property value="/text('displaypane.hide')" />')"><webwork:property
                value="text('displaypane.hide')"/></span> <% } %>
        </webwork:if>
        <webwork:text name="'common.concepts.project'"/> :
        <b><a href="<%= request.getContextPath() %>/browse/<webwork:property value="string('key')"/>"><webwork:property
                value="string('name')"/></a></b>
        <font size="1">(<webwork:property value="string('key')"/>)</font>
    </page:param>
    <tbody id="project_<webwork:property value="../id"/>_<webwork:property value="string('id')"/>">
    <page:param name="header.colspan">2</page:param>
    <tr class="rowClear">
        <td colspan="2">
            <webwork:if test="../property('projectinfo') != 'brief' && string('lead') != null">
                <b><webwork:text name="'common.concepts.lead'"/>:</b> <a
                    href="<webwork:url page="/secure/ViewProfile.jspa"><webwork:param name="'name'" value="string('lead')" /></webwork:url>">
                <webwork:property value="@user/user(string('lead'))/fullName"/></a><br>
            </webwork:if>

            <b><webwork:text name="'common.concepts.reports'"/>:</b>
            <webwork:iterator value="/projectTabPanels(.)" status="'iteratorStatus'">
                <a href="<%= request.getContextPath() %>/browse/<webwork:property value="string('key')"/>?report=<webwork:property value="completeKey" />">
                    <webwork:property value="label"/></a>
                <webwork:if test="@iteratorStatus/last == false">|</webwork:if>
            </webwork:iterator>
        </td>
    </tr>
    <webwork:if test="property('projectinfo') != 'brief'">
        <webwork:property value="./long('id')">
            <webwork:if test="@fieldVisibility/fieldHidden(., 'priority', 'all') == false">
                <tr class="rowClear">
                    <td>
                        <b><webwork:text name="'common.concepts.openissues'"/>:</b> <font size=1>(<webwork:text
                            name="'common.concepts.bypriority'"/>)</font>
                    </td>
                    <td valign="middle">
                        <table width="100" valign="middle" align="center" cellspacing="0" cellpadding="0" border="0">
                            <tr>
                                <webwork:property value="/priorityStats(..)">
                                <webwork:if test="size > 0">
                                    <webwork:iterator>
                                <td width="<webwork:property value="value[1]"/>" bgcolor="<webwork:property value="value[2]"/>"><a href="<webwork:url page="/secure/IssueNavigator.jspa">
                                                 <webwork:param name="'reset'" value="'true'" />
                                                 <webwork:param name="'pid'" value="../.." />
                                                 <webwork:param name="'priority'" value="key" />
                                                 <webwork:param name="'resolution'" value="'-1'" />
                                             </webwork:url>" title="<webwork:text name="'percentagegraph.title'">
                                                  <webwork:param name="'value0'"><webwork:property value="/constantsManager/priorityName(key)" /></webwork:param>
                                                  <webwork:param name="'value1'"><webwork:property value="value[1]" /></webwork:param>
                                                  <webwork:param name="'value2'"><webwork:property value="value[0]" /></webwork:param>
                                              </webwork:text>"><img src="<%= request.getContextPath() %>/images/bar.gif" alt="<webwork:text name="'percentagegraph.title'">
                                                  <webwork:param name="'value0'"><webwork:property value="/constantsManager/priorityName(key)" /></webwork:param>
                                                  <webwork:param name="'value1'"><webwork:property value="value[1]" /></webwork:param>
                                                  <webwork:param name="'value2'"><webwork:property value="value[0]" /></webwork:param>
                                              </webwork:text>" height="10" width="<webwork:property value="value[1]"/>" border="0" /></a></td>
                                </webwork:iterator>
                                </webwork:if>
                                <webwork:else>
                                    <font size="1"><webwork:text name="'common.concepts.noopenissues'"/></font>
                                </webwork:else>
                                </webwork:property>
                            </tr>
                        </table>
                    </td>
                </tr>
            </webwork:if>
        </webwork:property>
        <webwork:property value="." id="project"/>
        <%
            UtilTimerStack.push("Rendering Preset Filters on the dashboard");
            GenericValue project = (GenericValue) pageContext.getAttribute("project");
            WebFragmentWebComponent webFragment = (WebFragmentWebComponent) ComponentManager.getComponentInstanceOfType(WebFragmentWebComponent.class);
            JiraHelper jiraHelper = new JiraHelper(request, project);
            if (webFragment.hasDisplayableItems("system.preset.filters", jiraHelper))
            {
        %>
        <tr class="rowClear">
            <td colspan="2">
                <%-- these styles are used by the webfragment below --%>
                <style type="text/css">
                    .presetfiltertable { width: 100%}
                    .presetfilter { font-size:10px;}
                </style>
                <b><webwork:text name="'common.concepts.filterissues'"/>:</b><br>
                <%= webFragment.getHtml("templates/plugins/webfragments/system-preset-filters.vm", "system.preset.filters", jiraHelper) %>
            </td>
        </tr>
        <%
            }
            UtilTimerStack.pop("Rendering Preset Filters on the dashboard");
        %>
    </webwork:if>
    </tbody>
</page:applyDecorator>

<script type="text/javascript">
    <!-- //this script shows or hides the project category based on a cookie
    var id = "project_<webwork:property value="../id"/>_<webwork:property value="string('id')"/>";
    <%-- Not using WebWork Text tag so that the code works when i18n highlighting is switched on --%>
    cookieHide(id, '<webwork:property value="/text('displaypane.show')" escape="false" />');
    //-->
</script>
