<%--
/**
 * 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");

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

DDMTemplateVersion templateVersion = DDMTemplateVersionServiceUtil.getTemplateVersion(templateVersionId);

DDMTemplate template = templateVersion.getTemplate();

String title = LanguageUtil.format(request, "x-version-x", new Object[] {templateVersion.getName(locale), templateVersion.getVersion()});

PortletURL backURL = PortletURLBuilder.createRenderURL(
	renderResponse
).setMVCPath(
	"/view_template_history.jsp"
).setRedirect(
	redirect
).setParameter(
	"templateId", template.getTemplateId()
).buildPortletURL();
%>

<clay:container-fluid>
	<c:choose>
		<c:when test="<%= ddmDisplay.isShowBackURLInTitleBar() %>">

			<%
			portletDisplay.setShowBackIcon(true);
			portletDisplay.setURLBack(backURL.toString());

			renderResponse.setTitle(title);
			%>

		</c:when>
		<c:otherwise>
			<liferay-ui:header
				backURL="<%= backURL.toString() %>"
				localizeTitle="<%= false %>"
				title="<%= title %>"
			/>
		</c:otherwise>
	</c:choose>

	<aui:model-context bean="<%= templateVersion %>" model="<%= DDMTemplateVersion.class %>" />

	<aui:input disabled="<%= true %>" name="name" />

	<aui:input disabled="<%= true %>" name="language" />

	<aui:input disabled="<%= true %>" name="description" />

	<c:choose>
		<c:when test="<%= template.getType().equals(DDMTemplateConstants.TEMPLATE_TYPE_FORM) %>">

			<%
			DDMStructure structure = ddmDisplayContext.fetchStructure(template);

			String portletResourceNamespace = ParamUtil.getString(request, "portletResourceNamespace", liferayPortletResponse.getNamespace());

			String script = templateVersion.getScript();

			String fieldsJSONArrayString = String.valueOf(_getFormTemplateFieldsJSONArray(structure, script));
			%>

			<%@ include file="/form_builder.jspf" %>
		</c:when>
		<c:otherwise>
			<aui:input cssClass="script" disabled="<%= true %>" name="script" type="textarea" />
		</c:otherwise>
	</c:choose>

	<aui:button-row>
		<aui:button href="<%= backURL.toString() %>" type="cancel" />
	</aui:button-row>
</clay:container-fluid>