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

<aui:fieldset cssClass='<%= (proposalId > 0) ? "aui-helper-hidden" : "" %>'>

	<%
	String taglibOnClick = "Liferay.LayoutExporter.all({namespace: '" + renderResponse.getNamespace() + "', pane: '#" + renderResponse.getNamespace() + "pane', obj: this, publish: " + selectPages + "});";
	%>

	<aui:input checked="<%= results.isEmpty() %>" id="scope_all_pages" label="all-pages" name="scope" type="radio" value="all-pages" onClick="<%= taglibOnClick %>" />

	<%
	taglibOnClick = "Liferay.LayoutExporter.selected({namespace: '" + renderResponse.getNamespace() + "', pane: '#" + renderResponse.getNamespace() + "pane', obj: this, publish: " + selectPages + "});";
	%>

	<div>
		<aui:input checked="<%= !results.isEmpty() %>" cssClass="selected-pages-option" id="scope_selected_pages" label="selected-pages" name="scope" type="radio" value="selected-pages" onClick="<%= taglibOnClick %>" />

		<%
		String taglibUrl = "javascript:AUI().DialogManager.refreshByChild('#" + renderResponse.getNamespace() + "exportPagesFm');";
		%>

		(<liferay-ui:icon message='<%= results.isEmpty() ? "select-pages" : "change-selection" %>' label="<%= true %>" image="pages" url="<%= taglibUrl %>" />)
	</div>
</aui:fieldset>

<div id="<portlet:namespace />pane">

	<%
	int total = results.size();

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

	headerNames.add("pages");

	if (proposalId <= 0) {
		headerNames.add("options");
	}

	headerNames.add("type");

	SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, total, portletURL, headerNames, "there-are-no-selected-pages");

	searchContainer.setTotal(total);
	searchContainer.setResults(results);
	searchContainer.setRowChecker(new ExportPageChecker(renderResponse, "left", "top", RowChecker.COLSPAN, "exportPagesFm", RowChecker.ALL_ROW_IDS, RowChecker.ROW_IDS));

	List resultRows = searchContainer.getResultRows();

	for (int i = 0; i < results.size(); i++) {
		Layout curLayout = (Layout)results.get(i);

		ResultRow row = new ResultRow(curLayout, curLayout.getPrimaryKey(), i);

		row.addText("left", "top", curLayout.getName(locale));

		if (proposalId <= 0) {
			row.addJSP("left", "top", 1, "/html/portlet/communities/export_page_options.jsp");
		}

		row.addText("left", "top", LanguageUtil.get(pageContext, StringUtil.replace(curLayout.getType(), "_", "-")));

		resultRows.add(row);
	}
	%>

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