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

<aui:form action="<%= editCommerceOrderURL %>" method="post" name="transitionFm">
	<aui:input id="transitionCommerceOrderId" name="commerceOrderId" type="hidden" value="" />
	<aui:input name="workflowTaskId" type="hidden" value="" />
	<aui:input name="transitionName" type="hidden" value="" />

	<div class="hide" id="<portlet:namespace />transitionComments">
		<aui:input name="redirect" type="hidden" value="<%= currentURL %>" />
		<aui:input name="<%= Constants.CMD %>" type="hidden" value="transition" />

		<aui:input cols="55" name="comment" placeholder="comment" rows="1" type="textarea" />
	</div>
</aui:form>

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

			var link = event.currentTarget;

			var workflowTaskId = parseInt(link.getData('workflowTaskId'), 10);

			var form = A.one('#<portlet:namespace />transitionFm');

			A.one('#<portlet:namespace />transitionCommerceOrderId').val(
				link.getData('commerceOrderId')
			);
			A.one('#<portlet:namespace />workflowTaskId').val(workflowTaskId);
			A.one('#<portlet:namespace />transitionName').val(
				link.getData('transitionName')
			);

			if (workflowTaskId <= 0) {
				submitForm(form);

				return;
			}

			var transitionComments = A.one(
				'#<portlet:namespace />transitionComments'
			);

			transitionComments.show();

			var dialog = Liferay.Util.Window.getWindow({
				dialog: {
					bodyContent: form,
					destroyOnHide: true,
					height: 400,
					resizable: false,
					toolbars: {
						footer: [
							{
								cssClass: 'btn-primary mr-2',
								label: '<liferay-ui:message key="done" />',
								on: {
									click: function () {
										submitForm(form);
									},
								},
							},
							{
								cssClass: 'btn-cancel',
								label: '<liferay-ui:message key="cancel" />',
								on: {
									click: function () {
										dialog.hide();
									},
								},
							},
						],
						header: [
							{
								cssClass: 'close',
								discardDefaultButtonCssClasses: true,
								labelHTML:
									'<span aria-hidden="true">&times;</span>',
								on: {
									click: function (event) {
										dialog.hide();
									},
								},
							},
						],
					},
					width: 720,
				},
				title: link.text(),
			});
		},
		['aui-base', 'liferay-util-window']
	);
</aui:script>