@using GreenTree.Nachtragsmanagement.Web.Extensions

@model IEnumerable<GreenTree.Nachtragsmanagement.Core.Authentication.ActiveDirectoryUser>

<div class="userSearchContainer">
	<script>

		function selectUser() {
			var searchVal = CustomNumber.GetText();
			if (!searchVal) return;
			$.ajax({
				type: "POST",
				url: '@Url.Action("SelectUser", "Admin")',
				data: { accountName: devListBoxSearchUsers.GetValue() },
				success: function (response) {
					setTimeout(function () {
						if (!response) return;
						CustomNumber.SetText(response.AccountName);
						Forename.SetText(response.ForeName);
						Lastname.SetText(response.LastName);
						MailAddress.SetText(response.Mail);
						Password.SetEnabled(false);
						$(Password.GetMainElement()).css("background", "#efefef");
						$(Password.GetMainElement()).find("input").css("background", "#efefef");
						IsActiveDirectory.SetChecked(true);
						devPopupControlSearchUser.Hide();
						$("#imgPasswordInfo").css("display", "block");
					}, 200);
				},
				error: function () {
					 alert("error occured");
				}
			});
		}

	</script>

	@Html.DevExpress().PopupControl(s =>
	{
		s.Name = "devPopupControlSearchUser";
		s.HeaderText = "Benutzersuche";
		s.Modal = true;
		s.Width = new Unit(280, 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("SelectUser", "Admin", FormMethod.Post, new { id = "userSelectForm" }))
			{
				ViewContext.Writer.Write("<div class='editFormWrapper'>");

				ViewContext.Writer.Write("Suchergebnis:");
				Html.DevExpress().ListBox(t =>
				{
					t.Name = "devListBoxSearchUsers";
					t.Width = new Unit(100, UnitType.Percentage);
					t.Height = new Unit(210, UnitType.Pixel);
					t.Properties.ValueField = "AccountName";
					t.Properties.TextField = "Name";
				}).BindList(Model).Render();

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

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