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

<ul class="lfr-tree lfr-component">
	<c:if test="<%= supportsSetup %>">
		<li class="tree-item">
			<aui:input inlineLabel="right" label="setup" name="<%= PortletDataHandlerKeys.PORTLET_SETUP %>" type="checkbox" value="<%= true %>" />
		</li>

		<c:if test='<%= tabs2.equals("import") || tabs2.equals("staging") || !PortletItemLocalServiceUtil.getPortletItems(layout.getGroupId(), selPortlet.getRootPortletId(), com.liferay.portal.model.PortletPreferences.class.getName()).isEmpty() %>'>
			<li class="tree-item">
				<aui:input inlineLabel="right" label="archived-setups" name="<%= PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS %>" type="checkbox" value="<%= false %>" />
			</li>
		</c:if>

		<li class="tree-item">
			<aui:input inlineLabel="right" label="user-preferences" name="<%= PortletDataHandlerKeys.PORTLET_USER_PREFERENCES %>" type="checkbox" value="<%= false %>" />
		</li>
	</c:if>

	<c:if test="<%= supportsLAR %>">
		<li class="tree-item">
			<aui:input name="<%= PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT %>" type="hidden" value="<%= false %>" />

			<%
			PortletDataHandler portletDataHandler = selPortlet.getPortletDataHandlerInstance();

			String taglibTogglePortletDataControls = renderResponse.getNamespace() + "toggleChildren(this, '" + renderResponse.getNamespace() + "portletDataControls');";
			%>

			<c:choose>
				<c:when test='<%= tabs2.equals("import") || tabs2.equals("staging") %>'>
					<aui:input helpMessage="delete-portlet-data-help" inlineLabel="right" label="delete-portlet-data-before-importing" name="<%= PortletDataHandlerKeys.DELETE_PORTLET_DATA %>" type="checkbox" />

					<aui:input inlineLabel="right" label="data" name="<%= PortletDataHandlerKeys.PORTLET_DATA %>" onChange="<%= taglibTogglePortletDataControls %>" type="checkbox" value="<%= portletDataHandler.isPublishToLiveByDefault() %>" />
				</c:when>
				<c:otherwise>
					<aui:input inlineLabel="right" label="data" name='<%= PortletDataHandlerKeys.PORTLET_DATA + "_" + selPortlet.getRootPortletId() %>' onChange="<%= taglibTogglePortletDataControls %>" type="checkbox" value="<%= portletDataHandler.isPublishToLiveByDefault() %>" />
				</c:otherwise>
			</c:choose>

			<ul id="<portlet:namespace />portletDataControls">

				<%
				try {
					PortletDataHandlerControl[] controls = null;

					if (tabs2.equals("import")) {
						controls = portletDataHandler.getImportControls();
					}
					else {
						controls = portletDataHandler.getExportControls();
					}

					if (controls != null) {
						request.setAttribute("render_controls.jsp-controls", controls);
						request.setAttribute("render_controls.jsp-portletDisabled", !portletDataHandler.isPublishToLiveByDefault());
				%>

						<liferay-util:include page="/html/portlet/communities/render_controls.jsp" />

				<%
					}
				}
				catch (PortletDataException pde) {
				%>

					<li class="tree-item">
						<div class="portlet-msg-error"><%= LanguageUtil.get(pageContext, "error-initializing-import-controls") %></div>
					</li>

				<%
				}
				%>

				<c:choose>
					<c:when test='<%= tabs2.equals("import") %>'>
						<li class="tree-item">
							<aui:field-wrapper label="data-strategy">
								<ul>
									<li>
										<aui:input checked="<%= true %>" helpMessage="import-data-strategy-mirror-help" id="mirror" inlineLabel="right" label="mirror" name="<%= PortletDataHandlerKeys.DATA_STRATEGY %>" type="radio" value="<%= PortletDataHandlerKeys.DATA_STRATEGY_MIRROR %>" />
									</li>
									<li>
										<aui:input helpMessage="import-data-strategy-copy-as-new-help" id="copy_as_new" inlineLabel="right" label="copy-as-new" name="<%= PortletDataHandlerKeys.DATA_STRATEGY %>" type="radio" value="<%= PortletDataHandlerKeys.DATA_STRATEGY_COPY_AS_NEW %>" />
									</li>
								</ul>
							</aui:field-wrapper>
						</li>

						<li class="tree-item">
							<aui:field-wrapper label="user-id-strategy">
								<ul>
									<li>
										<aui:input checked="<%= true %>" id="currentUserId" inlineLabel="right" label="if-a-user-id-does-not-exist,-then-use-my-user-id" name="<%= PortletDataHandlerKeys.USER_ID_STRATEGY %>" type="radio" value="<%= UserIdStrategy.CURRENT_USER_ID %>" />
									</li>
									<li>
										<aui:input id="alwaysCurrentUserId" inlineLabel="right" label="always-use-my-user-id" name="<%= PortletDataHandlerKeys.USER_ID_STRATEGY %>" type="radio" value="<%= UserIdStrategy.ALWAYS_CURRENT_USER_ID %>" />
									</li>
								</ul>
							</aui:field-wrapper>
						</li>
					</c:when>
					<c:otherwise>
						<li class="tree-item">
							<aui:field-wrapper label="date-range">
								<ul>
									<li>
										<aui:input checked="<%= true %>" id="dateRangeAll" inlineLabel="right" label="all" name="range" onClick='<%= renderResponse.getNamespace() + "hideDateRange()" %>' type="radio" value="all" />
									</li>
									<li>
										<aui:input inlineLabel="right" label="from-last-publish-date" name="range" onClick='<%= renderResponse.getNamespace() + "hideDateRange()" %>' type="radio" value="fromLastPublishDate" />
									</li>
									<li>
										<aui:input id="dateRangeRange" inlineLabel="right" label="range" name="range" onClick='<%= renderResponse.getNamespace() + "showDateRange()" %>' type="radio" value="dateRange" />

										<%
										Calendar today = CalendarFactoryUtil.getCalendar(timeZone, locale);

										Calendar yesterday = CalendarFactoryUtil.getCalendar(timeZone, locale);

										yesterday.add(Calendar.DATE, -1);
										%>

										<br />

										<ul class="aui-helper-hidden" id="<portlet:namespace />startEndDate">
											<li>
												<aui:field-wrapper label="start-date">
													<liferay-ui:input-date
														dayParam="startDateDay"
														dayValue="<%= yesterday.get(Calendar.DATE) %>"
														disabled="<%= false %>"
														firstDayOfWeek="<%= yesterday.getFirstDayOfWeek() - 1 %>"
														monthParam="startDateMonth"
														monthValue="<%= yesterday.get(Calendar.MONTH) %>"
														yearParam="startDateYear"
														yearValue="<%= yesterday.get(Calendar.YEAR) %>"
														yearRangeStart="<%= yesterday.get(Calendar.YEAR) - 100 %>"
														yearRangeEnd="<%= yesterday.get(Calendar.YEAR) %>"
													/>

													&nbsp;

													<liferay-ui:input-time
														hourParam='<%= "startDateHour" %>'
														hourValue="<%= yesterday.get(Calendar.HOUR) %>"
														minuteParam='<%= "startDateMinute" %>'
														minuteValue="<%= yesterday.get(Calendar.MINUTE) %>"
														minuteInterval="<%= 1 %>"
														amPmParam='<%= "startDateAmPm" %>'
														amPmValue="<%= yesterday.get(Calendar.AM_PM) %>"
														disabled="<%= false %>"
													/>
												</aui:field-wrapper>

												<aui:field-wrapper label="end-date">
													<liferay-ui:input-date
														dayParam="endDateDay"
														dayValue="<%= today.get(Calendar.DATE) %>"
														disabled="<%= false %>"
														firstDayOfWeek="<%= today.getFirstDayOfWeek() - 1 %>"
														monthParam="endDateMonth"
														monthValue="<%= today.get(Calendar.MONTH) %>"
														yearParam="endDateYear"
														yearValue="<%= today.get(Calendar.YEAR) %>"
														yearRangeStart="<%= today.get(Calendar.YEAR) - 100 %>"
														yearRangeEnd="<%= today.get(Calendar.YEAR) %>"
													/>

													&nbsp;

													<liferay-ui:input-time
														amPmParam='<%= "endDateAmPm" %>'
														amPmValue="<%= today.get(Calendar.AM_PM) %>"
														disabled="<%= false %>"
														hourParam='<%= "endDateHour" %>'
														hourValue="<%= today.get(Calendar.HOUR) %>"
														minuteParam='<%= "endDateMinute" %>'
														minuteValue="<%= today.get(Calendar.MINUTE) %>"
													/>
												</aui:field-wrapper>
											</li>
										</ul>
									</li>
								</ul>
							</aui:field-wrapper>
						</li>
					</c:otherwise>
				</c:choose>
			</ul>
		</li>

		<%
		String taglibTogglePermissionsUl = renderResponse.getNamespace() + "toggleChildren(this, '" + renderResponse.getNamespace() + "permissionsUl');";
		%>

		<li class="tree-item">
			<aui:input helpMessage="export-import-portlet-permissions-help" inlineLabel="right" label="permissions" name="<%= PortletDataHandlerKeys.PERMISSIONS %>" onChange="<%= taglibTogglePermissionsUl %>" type="checkbox" />

			<ul id="<portlet:namespace />permissionsUl">
				<c:choose>
					<c:when test="<%= (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 5) || (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) %>">
						<li class="tree-item">
							<aui:input cssClass="disabled" disabled="<%= true %>" inlineLabel="right" label="permissions-assigned-to-roles" name="permissinsAssignedToRoles" type="checkbox" value="<%= true %>" />
						</li>
					</c:when>
					<c:otherwise>
						<li class="tree-item">
							<aui:input cssClass="disabled" disabled="<%= true %>" inlineLabel="right" label="permissions-assigned-to-organizations-user-groups-roles-and-communities" name="permissionsAssignedToOrganizationsUserGroupsRolesAndCommunities" type="checkbox" value="<%= true %>" />
						</li>

						<li class="tree-item">
							<aui:input cssClass="disabled" disabled="<%= true %>" inlineLabel="right" label="permissions-assigned-to-users" name="<%= PortletDataHandlerKeys.USER_PERMISSIONS %>" type="checkbox" />
						</li>
					</c:otherwise>
				</c:choose>
			</ul>
		</li>
		<li class="tree-item">
			<aui:input helpMessage="export-import-referenced-categories-help" inlineLabel="right" label="categories" name="<%= PortletDataHandlerKeys.CATEGORIES %>" type="checkbox" value="<%= false %>" />
		</li>
	</c:if>
</ul>

<aui:script>
	Liferay.provide(
		window,
		'<portlet:namespace />hideDateRange',
		function() {
			var A = AUI();

			A.one('#<portlet:namespace />startEndDate').hide();
		},
		['aui-base']
	);

	Liferay.provide(
		window,
		'<portlet:namespace />showDateRange',
		function() {
			var A = AUI();

			A.one('#<portlet:namespace />startEndDate').show();
		},
		['aui-base']
	);
</aui:script>