<%--
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */
--%>

<%@ include file="/init.jsp" %>

<%
String redirect = ParamUtil.getString(request, "redirect");

LayoutBranch layoutBranch = null;

long layoutBranchId = ParamUtil.getLong(request, "layoutBranchId");

if (layoutBranchId > 0) {
	layoutBranch = LayoutBranchLocalServiceUtil.getLayoutBranch(layoutBranchId);
}

long layoutRevisionId = ParamUtil.getLong(request, "layoutRevisionId");

if (layoutRevisionId <= 0) {
	layoutRevisionId = ParamUtil.getLong(request, "copyLayoutRevisionId");
}
%>

<liferay-ui:error exception="<%= LayoutBranchNameException.class %>">

	<%
	LayoutBranchNameException lbne = (LayoutBranchNameException)errorException;
	%>

	<c:if test="<%= lbne.getType() == LayoutBranchNameException.DUPLICATE %>">
		<liferay-ui:message key="a-page-variation-with-that-name-already-exists" />
	</c:if>

	<c:if test="<%= lbne.getType() == LayoutBranchNameException.TOO_LONG %>">
		<liferay-ui:message arguments="<%= new Object[] {4, 75} %>" key="please-enter-a-value-between-x-and-x-characters-long" translateArguments="<%= false %>" />
	</c:if>

	<c:if test="<%= lbne.getType() == LayoutBranchNameException.TOO_SHORT %>">
		<liferay-ui:message arguments="<%= new Object[] {4, 75} %>" key="please-enter-a-value-between-x-and-x-characters-long" translateArguments="<%= false %>" />
	</c:if>
</liferay-ui:error>

<%
String title = "add-page-variation";

if (layoutBranch != null) {
	title = "update-page-variation";
}
%>

<liferay-util:include page="/navigation.jsp" servletContext="<%= application %>">
	<liferay-util:param name="navigationName" value="<%= title %>" />
</liferay-util:include>

<clay:container-fluid
	id='<%= liferayPortletResponse.getNamespace() + ((layoutBranch != null) ? "updateBranch" : "addBranch") %>'
>
	<aui:model-context bean="<%= layoutBranch %>" model="<%= LayoutBranch.class %>" />

	<portlet:actionURL name="editLayoutBranch" var="editLayoutBranchURL">
		<portlet:param name="mvcRenderCommandName" value="editLayoutBranch" />
	</portlet:actionURL>

	<aui:form action="<%= editLayoutBranchURL %>" method="post" name="fm3">
		<aui:input name="redirect" type="hidden" value="<%= redirect %>" />
		<aui:input name="groupId" type="hidden" value="<%= String.valueOf(scopeGroupId) %>" />
		<aui:input name="layoutBranchId" type="hidden" value="<%= layoutBranchId %>" />
		<aui:input name="copyLayoutRevisionId" type="hidden" value="<%= String.valueOf(layoutRevisionId) %>" />
		<aui:input name="workflowAction" type="hidden" value="<%= String.valueOf(WorkflowConstants.ACTION_SAVE_DRAFT) %>" />

		<aui:input name="name" />

		<aui:input name="description" />

		<aui:button-row>
			<aui:button type="submit" value='<%= (layoutBranch != null) ? "update" : "add" %>' />

			<aui:button href="<%= redirect %>" value="cancel" />
		</aui:button-row>
	</aui:form>
</clay:container-fluid>