<%@ page import="com.atlassian.jira.web.action.ProjectActionSupport,
                 java.util.Collection,
                 java.util.Iterator,
                 org.ofbiz.core.entity.GenericValue,
                 com.atlassian.jira.security.PermissionManager,
                 com.atlassian.jira.ManagerFactory,
                 com.atlassian.jira.project.ProjectManager,
                 java.util.ArrayList,
                 com.atlassian.jira.security.Permissions,
                 com.atlassian.util.profiling.UtilTimerStack,
                 com.opensymphony.user.User,
                 com.atlassian.seraph.auth.DefaultAuthenticator,
                 com.atlassian.core.util.StringUtils"%>
<%
    Collection savedFilters = ManagerFactory.getSearchRequestManager().getVisibleRequests(u);
    String name;
    String shortName;
    Long requestId;
%>

<script language="javascript">
    function rowHover(row)
    {
        row.oldClassName = row.className;
        row.className = 'rowHover';
        row.onmouseout = function()
        {
            this.className = this.oldClassName;
        }
    }

    function showFilters(event)
    {
        var popupHtml = '<table border=0 cellpadding=0 cellspacing=0 width=100% bgcolor=ffffff>';
        popupHtml += '<tr><td width="1%"><img src="<%= request.getContextPath() %>/images/icons/favicon.png" border="0"></td><td bgcolor="<%= topBgColour %>" class="navitem" valign="middle">&nbsp;&nbsp;Saved Filters</td></tr>';
        popupHtml += '<tr><td colspan="2" bgcolor="<%= menuBgColour %>"><img src="<%= request.getContextPath() %>/images/border/spacer.gif" height=5 width=1></td></tr>';
        popupHtml += '</table>';

        popupHtml += '<table width="100%">';
        <%
            if (savedFilters == null || savedFilters.isEmpty())
            {
                %>
                popupHtml += '<tr><td>You have no saved filters</td></tr>';
            <%
            }
            else
            {
                for (Iterator i = savedFilters.iterator(); i.hasNext();)
                {
                    GenericValue gv = (GenericValue) i.next();
                    name = gv.getString("name");
                    if (name == null)
                        shortName = "";
                    else
                        shortName = StringUtils.crop(name, 40, " ...");

                    shortName = org.apache.commons.lang.StringUtils.replace(shortName,"'", "&#39;");

                    requestId = gv.getLong("id");
            %>
                    popupHtml += '<tr onmouseover="rowHover(this)"><td onClick="javascript:window.location.href=\'<%= request.getContextPath()%>/secure/IssueNavigator.jspa?mode=hide&requestId=<%= requestId %>\';"><a href="<%= request.getContextPath()%>/secure/IssueNavigator.jspa?mode=hide&requestId=<%= requestId %>"><%= shortName %></a></td></tr>';
            <%  }
            }%>

        popupHtml += '</table>';

        showHelpTip(event, popupHtml, true);
    }
</script>