@using GreenTree.Nachtragsmanagement.Web.Extensions

@model GreenTree.Nachtragsmanagement.Web.Models.Global.EditEntityCommentModel

<div class="editCommentContainer">

	<script>

		function saveComment() {
			var form = $("#commentEditForm");
			$(form).submit(function (e) {
				$.ajax({
					type: "POST",
					url: '@Url.Action("EditEntityComment", "Global")',
					data: form.serialize(),
					success: function (response) {
						setTimeout(function () {
							$(".editCommentContainer").remove();
							if (response == "success") {
								if (typeof editCommentCallback === 'function') {
									editCommentCallback();
								}
							} else {
								$("body").append(response);
							}
						}, 200);
					}
				});
				e.preventDefault();
			});
			form.submit();
		}

	</script>

	@Html.DevExpress().PopupControl(p =>
	{
		p.Name = "devPopupControlEditComment";
		p.HeaderText = "Kommentar bearbeiten";
		p.ShowHeader = true;
		p.ShowFooter = false;
		p.Modal = true;
		p.Width = new Unit(500, UnitType.Pixel);
		p.MinHeight = new Unit(200, UnitType.Pixel);
		p.ShowOnPageLoad = true;
		p.SetContent(() =>
		{
			using (Html.BeginForm("EditEntityComment", "Global", FormMethod.Post, new { id = "commentEditForm" }))
			{
				ViewContext.Writer.Write("<div class='editFormWrapper'>");

				ViewContext.Writer.Write("<input type=\"hidden\" value=\"" + Model.EntityId + "\" id=\"EntityId\" name=\"EntityId\" />");
				ViewContext.Writer.Write("<input type=\"hidden\" value=\"" + Model.EntityType + "\" id=\"EntityType\" name=\"EntityType\" />");

				ViewContext.Writer.Write(Html.CustomLabelFor(m => m.Comment, "Kommentar:"));
				ViewContext.Writer.Write(Html.ValidationMessageFor(m => m.Comment).ToHtmlString());
				Html.DevExpress().MemoFor(m => m.Comment, t =>
				{
					t.Width = new Unit(100, UnitType.Percentage);
					t.Height = new Unit(90, UnitType.Pixel);
				}).Render();

				ViewContext.Writer.Write("</div>");

				Html.RenderPartial(
					"~/Views/Shared/_PopupButtonPanel.cshtml",
					new GreenTree.Nachtragsmanagement.Web.Models.Global.PopupModel
					{
						PopupName = "devPopupControlEditComment",
						AcceptFunction = "function (s, e) { saveComment(); }"
					}
				);
			}
		});
		p.CloseAction = CloseAction.CloseButton;
		p.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
		p.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
		p.Styles.Content.Paddings.Padding = new Unit(0, UnitType.Pixel);
		p.Styles.ModalBackground.Opacity = 0;
	}).GetHtml()

</div>