@using GreenTree.Nachtragsmanagement.Web.Extensions

@model GreenTree.Nachtragsmanagement.Web.Models.Deviation.DisturbanceDataModel

<div class="claimEditContainer">

	<script>
		function saveDisturbance() {
			var form = $("#disturbanceEditForm");
			$(form).submit(function (e) {
				$.ajax({
					type: "POST",
					url: '@Url.Action("EditDisturbance", "Deviation")',
					data: form.serialize(),
					success: function (response) {
						setTimeout(function () {
							$(".claimEditContainer").remove();
							if (response == "success") {
								parent.callCustomEventListener('DisturbanceDataCallbackEventReceiver');
							} else {
								$("body").append(response);
							}
						}, 200);
					}
				});
				e.preventDefault();
			});
			form.submit();
		}
	</script>

	@Html.DevExpress().PopupControl(s =>
{
	s.Name = "devPopupControlEditDisturbance";

	if (Model.Id == -1)
		s.HeaderText = "Neue VA-Kategorie erstellen";
	else
		s.HeaderText = "\"" + Model.Description + "\" bearbeiten";

	s.Modal = true;
	s.Width = new Unit(250, UnitType.Pixel);
	s.CloseAction = CloseAction.CloseButton;
	s.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
	s.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
	s.AllowDragging = false;
	s.AllowResize = false;
	s.ShowFooter = false;
	s.ShowOnPageLoad = true;
	s.SetContent(() =>
	{
		using (Html.BeginForm("EditDisturbance", "Deviation", FormMethod.Post, new { id = "disturbanceEditForm" }))
		{
			ViewContext.Writer.Write("<div class='editFormWrapper'>");

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

			ViewContext.Writer.Write(Html.CustomLabelFor(m => m.Description, "Beschreibung:"));
			ViewContext.Writer.Write(Html.ValidationMessageFor(m => m.Description).ToHtmlString());
			Html.DevExpress().TextBoxFor(m => m.Description, t =>
			{
				t.Width = new Unit(100, UnitType.Percentage);
			}).Render();

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

			Html.RenderPartial(
				"~/Views/Shared/_PopupButtonPanel.cshtml",
				new GreenTree.Nachtragsmanagement.Web.Models.Global.PopupModel
				{
					PopupName = "devPopupControlEditDisturbance",
					AcceptFunction = "function (s, e) { saveDisturbance(); }"
				}
			);
		}
	});
	s.Styles.Content.Paddings.Padding = new Unit(0);
	s.Styles.ModalBackground.Opacity = 0;
}).GetHtml()
</div>