<%
/**
 * 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">
	<li class="tree-item">
		<aui:input disabled="<%= true %>" inlineLabel="right" name="pages" type="checkbox" value="<%= true %>" />
	</li>

	<c:if test='<%= tabs4.equals("import") %>'>
		<li class="tree-item">
			<aui:input helpMessage="delete-missing-layouts-help" inlineLabel="right" label="delete-missing-layouts" name="<%= PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS %>" type="checkbox" value="<%= false %>" />
		</li>
	</c:if>

	<li class="tree-item">
		<aui:input disabled="<%= true %>" inlineLabel="right" name="portlets" type="checkbox" value="<%= true %>" />

		<ul>
			<li class="tree-item">
				<aui:input inlineLabel="right" label="setup" name="<%= PortletDataHandlerKeys.PORTLET_SETUP %>" type="checkbox" value="<%= true %>" />
			</li>
			<li class="tree-item">
				<aui:input inlineLabel="right" label="archived-setups" name="<%= PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS %>" type="checkbox" value="<%= true %>" />
			</li>
			<li class="tree-item">
				<aui:input inlineLabel="right" label="user-preferences" name="<%= PortletDataHandlerKeys.PORTLET_USER_PREFERENCES %>" type="checkbox" value="<%= true %>" />
			</li>
			<li id="<portlet:namespace />deleteDataOption" class="tree-item" style="display: none;">
				<aui:input helpMessage="delete-portlet-data-help" inlineLabel="right" label="delete-portlet-data-before-importing" name="<%= PortletDataHandlerKeys.DELETE_PORTLET_DATA %>" type="checkbox" />
			</li>
			<li class="tree-item">
				<c:choose>
					<c:when test='<%= tabs4.equals("import") %>'>

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

						<aui:input label="data" inlineLabel="right" name="<%= PortletDataHandlerKeys.PORTLET_DATA %>" onChange="<%= taglibToggleDataStrategies %>" type="checkbox" value="<%= true %>" />

						<aui:input name="<%= PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT %>" type="hidden" value="<%= true %>" />

						<ul id="<portlet:namespace />portletDataStrategies" style="display: none;">
							<li class="tree-item">
								<aui:field-wrapper label="data-strategy">
									<ul>
										<li>
											<aui:input checked="<%= true %>" helpMessage="import-data-strategy-mirror-help" 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" 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 %>" 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 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>
						</ul>
					</c:when>
					<c:otherwise>
						<aui:input name="<%= PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT %>" type="hidden" value="<%= true %>" />

						<c:if test="<%= !liveGroup.isStaged() %>">
							<aui:input name="<%= PortletDataHandlerKeys.PORTLET_DATA_ALL %>" type="hidden" value="<%= true %>" />
						</c:if>

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

						<aui:input inlineLabel="right" label="data" name="<%= PortletDataHandlerKeys.PORTLET_DATA %>" onChange="<%= taglibToggleDataControls %>" type="checkbox" value="<%= true %>" />

						<ul id="<portlet:namespace />portletDataControls">
							<li class="tree-item">
								<aui:field-wrapper label="range">
									<ul>
										<li>
											<aui:input checked="<%= true %>" 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 helpMessage="export-date-range-help" inlineLabel="right" label="date-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
															amPmParam='<%= "startDateAmPm" %>'
															amPmValue="<%= yesterday.get(Calendar.AM_PM) %>"
															disabled="<%= false %>"
															hourParam='<%= "startDateHour" %>'
															hourValue="<%= yesterday.get(Calendar.HOUR) %>"
															minuteParam='<%= "startDateMinute" %>'
															minuteValue="<%= yesterday.get(Calendar.MINUTE) %>"
															minuteInterval="<%= 1 %>"
														/>
													</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) %>"
															minuteInterval="<%= 1 %>"
														/>
													</aui:field-wrapper>
												</li>
											</ul>
										</li>
										<li>
											<aui:input inlineField="<%= true %>" inlineLabel="right" label="last" name="range" onClick='<%= renderResponse.getNamespace() + "hideDateRange()" %>' type="radio" value="last" />

											<aui:select label="" name="last">
												<aui:option label='<%= LanguageUtil.format(pageContext, "x-hours", "12") %>' value="12" />
												<aui:option label='<%= LanguageUtil.format(pageContext, "x-hours", "24") %>' value="24" />
												<aui:option label='<%= LanguageUtil.format(pageContext, "x-hours", "48") %>' value="48" />
												<aui:option label='<%= LanguageUtil.format(pageContext, "x-days", "7") %>' value="168" />
											</aui:select>
										</li>
									</ul>
								</aui:field-wrapper>
							</li>
						</ul>

						<ul id="<portlet:namespace />portletDataList" style="display: none;">

							<%
							itr1 = portletsList.iterator();

							while (itr1.hasNext()) {
								Portlet curPortlet = (Portlet)itr1.next();

								PortletDataHandler portletDataHandler = curPortlet.getPortletDataHandlerInstance();

								try {
									PortletDataHandlerControl[] controls = null;

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

									if (controls != null) {
										String rootPortletId = curPortlet.getRootPortletId();

										boolean checked = portletDataHandler.isPublishToLiveByDefault();

										boolean showRenderControls = true;

										if (!liveGroup.isStagedPortlet(curPortlet.getRootPortletId())) {
											showRenderControls = false;
										}

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

										<li class="tree-item">

											<%
											String taglibOnChange = renderResponse.getNamespace() + "toggleChildren(this, '" + renderResponse.getNamespace() + PortletDataHandlerKeys.PORTLET_DATA + StringPool.UNDERLINE + rootPortletId + "Controls');";
											%>

											<aui:input inlineLabel="right" label="<%= PortalUtil.getPortletTitle(curPortlet, application, locale) %>" name='<%= PortletDataHandlerKeys.PORTLET_DATA + StringPool.UNDERLINE + rootPortletId %>' onChange="<%= taglibOnChange %>" type="checkbox" value="<%= checked %>" />

											<ul id="<portlet:namespace /><%= PortletDataHandlerKeys.PORTLET_DATA %>_<%= rootPortletId %>Controls">
												<li class="<%= renderResponse.getNamespace() %>handler-control">
													<aui:input disabled="<%= !checked %>" inlineLabel="right" label="setup "name="<%= PortletDataHandlerKeys.PORTLET_SETUP + StringPool.UNDERLINE + rootPortletId %>" type="checkbox" value="<%= true %>" />
												</li>

												<c:if test="<%= showRenderControls %>">
													<liferay-util:include page="/html/portlet/communities/render_controls.jsp" />
												</c:if>
											</ul>
										</li>

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

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

							<%
								}
							}
							%>

						</ul>
					</c:otherwise>
				</c:choose>
			</li>
		</ul>
	</li>

	<li class="tree-item">

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

		<aui:input inlineLabel="right" label="permissions" name="<%= PortletDataHandlerKeys.PERMISSIONS %>" onChange="<%= taglibTogglePermissionsUl %>" type="checkbox" />

		<ul id="<portlet:namespace />permissionsUl" style="display: none;">
			<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="permissionsAssignedToRoles" 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 %>" helpMessage="export-import-permissions-assigned-to-users-help" inlineLabel="right" label="permissions-assigned-to-users" name="permissionsAssignedToUsers" type="checkbox" />
					</li>
				</c:otherwise>
			</c:choose>
		</ul>
	</li>

	<li class="tree-item">
		<aui:input helpMessage="export-import-theme-help" inlineLabel="right" label="theme" name="<%= PortletDataHandlerKeys.THEME %>" type="checkbox" value="<%= true %>" />
	</li>

	<li class="tree-item">
		<aui:input helpMessage="export-import-categories-help" inlineLabel="right" label="categories" name="<%= PortletDataHandlerKeys.CATEGORIES %>" type="checkbox" value="<%= false %>" />
	</li>
</ul>

<br />

<c:choose>
	<c:when test='<%= tabs4.equals("export") || tabs4.equals("export-live") %>'>
		<div id="<portlet:namespace />exportMoreDiv">
			<aui:a href='<%= "javascript:" + renderResponse.getNamespace() + "exportMore();" %>' label="more-options"> &raquo;</aui:a>
		</div>

		<div id="<portlet:namespace />exportLessDiv" style="display: none;">
			<aui:a href='<%= "javascript:" + renderResponse.getNamespace() + "exportLess();" %>' label="less-options"> &laquo;</aui:a>
		</div>
	</c:when>
	<c:otherwise>
		<div id="<portlet:namespace />importMoreDiv">
			<aui:a href='<%= "javascript:" + renderResponse.getNamespace() + "importMore();" %>' label="more-options"> &raquo;</aui:a>
		</div>

		<div id="<portlet:namespace />importLessDiv" style="display: none;">
			<aui:a href='<%= "javascript:" + renderResponse.getNamespace() + "importLess();" %>' label="less-options"> &laquo;</aui:a>
		</div>
	</c:otherwise>
</c:choose>

<aui:script>
	function <portlet:namespace />exportLess() {
		document.getElementById("<portlet:namespace />portletDataList").style.display = "none";

		document.getElementById("<portlet:namespace /><%= PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT %>").value = "true";

		document.getElementById("<portlet:namespace />permissionsUl").style.display = "none";

		document.getElementById("<portlet:namespace />exportMoreDiv").style.display = "";
		document.getElementById("<portlet:namespace />exportLessDiv").style.display = "none";
	}

	function <portlet:namespace />exportMore() {
		document.getElementById("<portlet:namespace />portletDataList").style.display = "inline";

		document.getElementById("<portlet:namespace /><%= PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT %>").value = "false";

		document.getElementById("<portlet:namespace />permissionsUl").style.display = "";

		document.getElementById("<portlet:namespace />exportMoreDiv").style.display = "none";
		document.getElementById("<portlet:namespace />exportLessDiv").style.display = "";
	}

	function <portlet:namespace />importLess() {
		document.getElementById("<portlet:namespace />deleteDataOption").style.display = "none";
		document.getElementById("<portlet:namespace />portletDataStrategies").style.display = "none";
		document.getElementById("<portlet:namespace />permissionsUl").style.display = "none";

		document.getElementById("<portlet:namespace />importMoreDiv").style.display = "";
		document.getElementById("<portlet:namespace />importLessDiv").style.display = "none";
	}

	function <portlet:namespace />importMore() {
		document.getElementById("<portlet:namespace />deleteDataOption").style.display = "";
		document.getElementById("<portlet:namespace />portletDataStrategies").style.display = "";
		document.getElementById("<portlet:namespace />permissionsUl").style.display = "";

		document.getElementById("<portlet:namespace />importMoreDiv").style.display = "none";
		document.getElementById("<portlet:namespace />importLessDiv").style.display = "";
	}

	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']
	);

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

			var parentDiv = A.one('#' + parentDivId);

			var enabled = checkbox.checked;

			if (parentDiv) {
				parentDiv.all('input').each(
					function(item, index, collection) {
						var disabled = !enabled;

						if (enabled && item.hasClass('disabled')) {
							disabled = true;
						}

						item.set('disabled', disabled);
					}
				);
			}
		},
		['aui-base']
	);
</aui:script>