<%
/**
 * 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.
 */
%>

<c:if test="<%= installPluginsURL != null %>">

	<%
	String taglibOnClick = "submitForm(document." + renderResponse.getNamespace() + "fm , '" + installPluginsURL.toString() +"');";
	%>

	<aui:button onClick="<%= taglibOnClick %>" value="install-more-layout-templates" />

	<br /><br />
</c:if>

<%
List<String> headerNames = new ArrayList<String>();

headerNames.add("layout-template");
headerNames.add("active");
headerNames.add("roles");

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

List layoutTemplates = layoutTemplates = LayoutTemplateLocalServiceUtil.getLayoutTemplates();

int total = layoutTemplates.size();

searchContainer.setTotal(total);

List results = ListUtil.subList(layoutTemplates, searchContainer.getStart(), searchContainer.getEnd());

searchContainer.setResults(results);

List resultRows = searchContainer.getResultRows();

for (int i = 0; i < results.size(); i++) {
	LayoutTemplate layoutTemplate = (LayoutTemplate)results.get(i);

	PluginPackage pluginPackage = layoutTemplate.getPluginPackage();
	PluginSetting pluginSetting = PluginSettingLocalServiceUtil.getPluginSetting(company.getCompanyId(), layoutTemplate.getLayoutTemplateId(), Plugin.TYPE_LAYOUT_TEMPLATE);

	ResultRow row = new ResultRow(layoutTemplate, layoutTemplate.getLayoutTemplateId(), i);

	PortletURL rowURL = renderResponse.createRenderURL();

	rowURL.setParameter("struts_action", "/enterprise_admin/edit_plugin");
	rowURL.setParameter("redirect", currentURL);

	if (pluginPackage != null) {
		rowURL.setParameter("moduleId", pluginPackage.getModuleId());
	}

	rowURL.setParameter("pluginId", layoutTemplate.getLayoutTemplateId());
	rowURL.setParameter("pluginType", "layout-template");
	rowURL.setParameter("title", layoutTemplate.getName());

	// Name and thumbnail

	StringBundler sb = new StringBundler();

	if (showEditPluginHREF) {
		sb.append("<a href=\"");
		sb.append(rowURL.toString());
		sb.append("\">");
	}

	sb.append("<img align=\"left\" src=\"");
	sb.append(layoutTemplate.getContextPath());
	sb.append(layoutTemplate.getThumbnailPath());
	sb.append("\" style=\"margin-right: 10px\" /><strong>");
	sb.append(layoutTemplate.getName());
	sb.append("</strong>");

	if (showEditPluginHREF) {
		sb.append("</a>");
	}

	sb.append("<br />");
	sb.append(LanguageUtil.get(pageContext, "package"));
	sb.append(": ");

	if (pluginPackage == null) {
		sb.append(LanguageUtil.get(pageContext, "unknown"));
	}
	else {
		sb.append(pluginPackage.getName());

		if (pluginPackage.getContext() != null) {
			sb.append(" (");
			sb.append(pluginPackage.getContext());
			sb.append(")");
		}
	}

	row.addText(sb.toString());

	// Active

	row.addText(LanguageUtil.get(pageContext, (pluginSetting.isActive() ? "yes" : "no")));

	// Roles

	row.addText(StringUtil.merge(pluginSetting.getRolesArray(), ", "));

	// Add result row

	resultRows.add(row);
}
%>

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