@using GreenTree.Nachtragsmanagement.Web.Extensions

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

<div class="changePasswordContainer">

	<script>

		function changePassword() {
			var form = $("#changePasswordEditForm");
			$(form).submit(function (e) {
				$.ajax({
					type: "POST",
					url: '@Url.Action("ChangePassword", "Global")',
					data: form.serialize(),
					success: function (response) {
						setTimeout(function () {
							$(".changePasswordContainer").remove();
							if (response == "success") {
								alert("Passwort erfolgreich geändert!");
							} else {
								$("body").append(response);
							}
						}, 200);
					}
				});
				e.preventDefault();
			});
			form.submit();
		}

	</script>

	<link rel="stylesheet" type="text/css" href="~/Content/function.css" />

@Html.DevExpress().PopupControl(s =>
{
	s.Name = "devPopupControlChangePassword";
	s.HeaderText = "Passwort ändern";
	s.ShowFooter = false;
	s.ShowMaximizeButton = false;
	s.Modal = true;
	s.ShowOnPageLoad = true;
	s.Width = new Unit(280, UnitType.Pixel);
	s.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
	s.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
	s.CloseAction = CloseAction.CloseButton;
	s.SetContent(() =>
	{
		using (Html.BeginForm("ChangePassword", "Global", FormMethod.Post, new { id = "changePasswordEditForm" }))
		{
			ViewContext.Writer.Write("<div class='editFormWrapper'>");

			ViewContext.Writer.Write(Html.CustomLabelFor(m => m.CurrentPassword, "Aktuelles Passwort:"));
			ViewContext.Writer.Write(Html.ValidationMessageFor(m => m.CurrentPassword).ToHtmlString());
			Html.DevExpress().TextBoxFor(m => m.CurrentPassword, t =>
			{
				t.Width = new Unit(100, UnitType.Percentage);
				t.Properties.Password = true;
			}).Render();

			ViewContext.Writer.Write(Html.CustomLabelFor(m => m.NewPassword, "Neues Passwort:"));
			ViewContext.Writer.Write(Html.ValidationMessageFor(m => m.NewPassword).ToHtmlString());
			Html.DevExpress().TextBoxFor(m => m.NewPassword, t =>
			{
				t.Width = new Unit(100, UnitType.Percentage);
				t.Properties.Password = true;
			}).Render();

			ViewContext.Writer.Write(Html.CustomLabelFor(m => m.ConfirmedPassword, "Neues Passwort bestätigen:"));
			ViewContext.Writer.Write(Html.ValidationMessageFor(m => m).ToHtmlString());
			Html.DevExpress().TextBoxFor(m => m.ConfirmedPassword, t =>
			{
				t.Width = new Unit(100, UnitType.Percentage);
				t.Properties.Password = true;
			}).Render();

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

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

</div>