<%
/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
%>

<%
PortletURL portletURL = renderResponse.createRenderURL();

SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, 5, portletURL, null, null);

int total = SocialEquityUserLocalServiceUtil.getRankedEquityUsersCount(scopeGroupId);

searchContainer.setTotal(total);

List<SocialEquityUser> results = SocialEquityUserLocalServiceUtil.getRankedEquityUsers(scopeGroupId, searchContainer.getStart(), searchContainer.getEnd(), new SocialEquityUserRankComparator(true));

searchContainer.setResults(results);

List resultRows = searchContainer.getResultRows();

for (int i = 0; i < results.size(); i++) {
	SocialEquityUser socialEquityUser = results.get(i);

	ResultRow row = new ResultRow(socialEquityUser, socialEquityUser.getEquityUserId(), i);

	// User display

	row.addJSP("/html/portlet/top_users/user_display.jsp", application, request, response);

	// Add result row

	resultRows.add(row);
}
%>

<div>
	<%= LanguageUtil.format(pageContext, "top-users-out-of-x", String.valueOf(total)) %>
</div>

<c:if test="<%= total > 0 %>">
	<br />
</c:if>

<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" paginate="<%= false %>" />

<c:if test="<%= results.size() > 0 %>">
	<div class="taglib-search-iterator-page-iterator-bottom" id="<portlet:namespace />searchTopUsers">
		<liferay-ui:search-paginator searchContainer="<%= searchContainer %>" type="article" />
	</div>
</c:if>

<aui:script use="aui-io-plugin">
	var searchTopUsers = A.one('#<portlet:namespace />searchTopUsers');

	if (searchTopUsers) {
		var parent = searchTopUsers.get('parentNode');

		parent.plug(
			A.Plugin.IO,
			{
				autoLoad: false
			}
		);

		searchTopUsers.all('a').on(
			'click',
			function(event) {
				var uri = event.currentTarget.get('href').replace(/p_p_state=normal/i, 'p_p_state=exclusive');

				parent.io.set('uri', uri);
				parent.io.start();

				event.preventDefault();
			}
		);
	}
</aui:script>