@using GreenTree.Nachtragsmanagement.Web.Models.Global;

@model GreenTree.Nachtragsmanagement.Web.Models.Admin.AppInfo.AppUpdateDataModel

<div class="updateContainer">

	<script>

		function update() {
			devPopupControlDoUpdate.Hide();
			devLoadingPanelUpdate.SetText("Update wird durchgeführt und die Anwendung anschließend neu gestartet... bitte warten!");
			devLoadingPanelUpdate.Show();
			$.ajax({
				method: "POST",
				url: '@Url.Action("Update", "Admin")',
				success: function (response) {
					window.location = '@Url.Action("ViewUpdateSuccess", "Admin")'
				},
				error: function () {
					devLoadingPanelUpdate.Hide();
					alert("error occured");
				}
			});
		}

	</script>

	@Html.DevExpress().PopupControl(s =>
	{
		s.Name = "devPopupControlDoUpdate";
		s.HeaderText = "Update durchführen";
		s.Modal = true;
		s.Width = new Unit(450, UnitType.Pixel);
		s.CloseAction = CloseAction.CloseButton;
		s.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
		s.PopupVerticalAlign = PopupVerticalAlign.TopSides;
		s.PopupVerticalOffset = 50;
		s.AllowDragging = false;
		s.AllowResize = false;
		s.ShowFooter = false;
		s.ShowOnPageLoad = true;
		s.SetContent(() =>
		{
			ViewContext.Writer.Write(
				"<div class='dialogText' style='padding: 12px'>" +
					"<h2>Es ist ein Update verfügbar (v" + Model.UpdateVersion + ")</h2>" +
					"Beschreibung:<br />" +
					"<div style='margin: 6px 0 12px; padding: 6px 4px; border-top: 1px solid #009688; border-bottom: 1px solid #009688;" +
					"min-height: 80px; max-height: 150px; overflow: auto'>" +
					Model.UpdateDescription + "</div>" +
					"<p><b>Sind Sie sicher, dass Sie das Update durchführen möchten? " +
					"Der Vorgang kann einige Zeit in Anspruch nehmen.<br /><br />" +
					"Die Anwendung wird anschließend neu gestartet!</b></p>" +
				"</div>");
			Html.RenderPartial(
				"~/Views/Shared/_PopupButtonPanel.cshtml",
				new GreenTree.Nachtragsmanagement.Web.Models.Global.PopupModel
				{
					PopupName = "devPopupControlDoUpdate",
					AcceptFunction = "function (s, e) { update(); }"
				}
			);
		});
		s.Styles.Content.Paddings.Padding = new Unit(0);
		s.Styles.ModalBackground.Opacity = 0;
	}).GetHtml()

</div>