<%
/**
 * 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="general-display-settings">
	<aui:select name="displayStyle">

		<%
		for (String curDisplayStyle : PropsValues.ASSET_PUBLISHER_DISPLAY_STYLES) {
		%>

			<aui:option label="<%= curDisplayStyle %>" selected="<%= displayStyle.equals(curDisplayStyle) %>" />

		<%
		}
		%>

	</aui:select>

	<aui:select cssClass="hidden-field abstract-length" helpMessage="abstract-length-key-help" name="abstractLength">
		<aui:option label="100" selected="<%= abstractLength == 100 %>" />
		<aui:option label="200" selected="<%= abstractLength == 200 %>" />
		<aui:option label="300" selected="<%= abstractLength == 300 %>" />
		<aui:option label="400" selected="<%= abstractLength == 400 %>" />
		<aui:option label="500" selected="<%= abstractLength == 500 %>" />
	</aui:select>

	<aui:input cssClass="hidden-field show-asset-title" inlineLabel="left" name="showAssetTitle" type="checkbox" value="<%= showAssetTitle %>" />

	<aui:input cssClass="hidden-field show-context-link" inlineLabel="left" name="showContextLink" type="checkbox" value="<%= showContextLink %>" />

	<aui:select cssClass="hidden-field asset-link-behaviour" name="assetLinkBehaviour">
		<aui:option label="show-full-content" selected='<%= assetLinkBehaviour.equals("showFullContent") %>' value="showFullContent" />
		<aui:option label="view-in-a-specific-portlet" selected='<%= assetLinkBehaviour.equals("viewInPortlet") %>' value="viewInPortlet" />
	</aui:select>

	<c:if test='<%= selectionStyle.equals("dynamic") %>'>
		<aui:select label="maximum-items-to-display" name="delta">

			<%
			int[] deltas = {1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100};

			for (int currentDelta: deltas) {
			%>

				<aui:option label="<%= currentDelta %>" selected="<%= (delta == currentDelta) %>" />

			<%
			}
			%>

		</aui:select>

		<aui:select name="paginationType">
			<aui:option label="none" selected='<%= paginationType.equals("none") %>' />
			<aui:option label="simple" selected='<%= paginationType.equals("simple") %>' />
			<aui:option label="regular" selected='<%= paginationType.equals("regular") %>' />
		</aui:select>

		<aui:input inlineLabel="left" label="exclude-assets-with-0-views" name="excludeZeroViewCount" type="checkbox" value="<%= excludeZeroViewCount %>" />
	</c:if>

	<aui:input inlineLabel="left" name="showAvailableLocales" type="checkbox" value="<%= showAvailableLocales %>" />

	<aui:field-wrapper helpMessage='<%= !openOfficeServerEnabled ? "enabling-openoffice-integration-provides-document-conversion-functionality" : StringPool.BLANK %>' label="enable-conversion-to">

		<div class="aui-field-row">

			<%
			for (String conversion : conversions) {
			%>

				<aui:field-wrapper inlineField="<%= true %>" inlineLabel="left" label="<%= conversion.toUpperCase() %>">
					<input <%= ArrayUtil.contains(extensions, conversion) ? "checked": "" %> <%= !openOfficeServerEnabled ? "disabled" : "" %> name="<portlet:namespace />extensions" type="checkbox" value="<%= conversion %>" />
			 	</aui:field-wrapper>

			<%
			}
			%>

		</div>

	</aui:field-wrapper>

	<aui:input inlineLabel="left" name="enablePrint" type="checkbox" value="<%= enablePrint %>" />

	<aui:input inlineLabel="left" name="enableFlags" type="checkbox" value="<%= enableFlags %>" />

	<aui:input inlineLabel="left" name="enableRatings" type="checkbox" value="<%= enableRatings %>" />

	<aui:input inlineLabel="left" name="enableComments" type="checkbox" value="<%= enableComments %>" />

	<aui:input inlineLabel="left" name="enableCommentRatings" type="checkbox" value="<%= enableCommentRatings %>" />

	<c:if test='<%= selectionStyle.equals("manual") %>'>
		<aui:input helpMessage="enable-tag-based-navigation-help" inlineLabel="left" label="enable-tag-based-navigation" name="enableTagBasedNavigation" type="checkbox" value="<%= enableTagBasedNavigation %>" />
	</c:if>
</aui:fieldset>

<aui:fieldset label="show-metadata">
	<aui:input name="metadataFields" type="hidden" />

	<%
	Set availableMetadataFields = SetUtil.fromArray(StringUtil.split(allMetadataFields));

	// Left list

	List leftList = new ArrayList();

	for (int i = 0; i < metadataFields.length; i++) {
		String folderColumn = metadataFields[i];

		leftList.add(new KeyValuePair(folderColumn, LanguageUtil.get(pageContext, folderColumn)));
	}

	// Right list

	List rightList = new ArrayList();

	Arrays.sort(metadataFields);

	Iterator itr = availableMetadataFields.iterator();

	while (itr.hasNext()) {
		String folderColumn = (String)itr.next();

		if (Arrays.binarySearch(metadataFields, folderColumn) < 0) {
			rightList.add(new KeyValuePair(folderColumn, LanguageUtil.get(pageContext, folderColumn)));
		}
	}

	rightList = ListUtil.sort(rightList, new KeyValuePairComparator(false, true));
	%>

	<liferay-ui:input-move-boxes
		leftTitle="current"
		rightTitle="available"
		leftBoxName="currentMetadataFields"
		rightBoxName="availableMetadataFields"
		leftReorder="true"
		leftList="<%= leftList %>"
		rightList="<%= rightList %>"
	/>
</aui:fieldset>

<aui:script use="aui-base">
	var selectDisplayStyle = A.one('#<portlet:namespace />displayStyle');

	function showHiddenFields () {
		var assetLinkBehaviour = A.one('.asset-link-behaviour');
		var hiddenFields = A.all('.hidden-field');
		var selectDisplayStyle = A.one('#<portlet:namespace />displayStyle');

		if (hiddenFields) {
			hiddenFields.hide();
		}

		if (selectDisplayStyle) {
			var displayStyle = selectDisplayStyle.val();

			if (displayStyle == 'full-content') {
				var showAssetTitle = A.one('.show-asset-title');
				var showContextLink = A.one('.show-context-link');

				if (showAssetTitle) {
					showAssetTitle.show();
				}

				if (showContextLink) {
					showContextLink.show();
				}
			}
			else {
				if (displayStyle == 'abstracts') {
					var abstractLength = A.one('.abstract-length');

					if (abstractLength) {
						abstractLength.show();
					}
				}

				if (assetLinkBehaviour) {
					assetLinkBehaviour.show();
				}
			}
		}
	}

	showHiddenFields();

	if (selectDisplayStyle) {
		selectDisplayStyle.on('change', showHiddenFields);
	}
</aui:script>