@{
	Layout = "~/Views/Shared/_FunctionLayout.cshtml";
}

@model IEnumerable<GreenTree.Nachtragsmanagement.Web.Models.Misc.HelpPageDataModel>

<script src='@Url.Content("~/Scripts/jquery.mCustomScrollbar.concat.min.js")'></script>
<script>
	var deleteId;
	var saveOperation;

	$(document).ready(function () {
		setTimeout(function () {
			setHelpContentHeight();
			@if (ViewData["InitialEditHelpPage"] != null)
			{
				ViewContext.Writer.Write("editHelpPage(" + (int)ViewData["InitialEditHelpPage"] + ");");
			}
		}, 500);
		$.ajaxSetup({
			cache: false
		});
	});

	$(window).resize(function () {
		setHelpContentHeight();
	});

	function setHelpContentHeight() {
		var height = $(window).height();
		$("#helpPageNavigation").height(height - 60);
		$("#helpPageContent").height(height - 32);
		if (typeof devHelpPageHtmlContentEditor !== 'undefined') {
			devHelpPageHtmlContentEditor.SetHeight(height);
		}
	}

	function viewHelpPage(id) {
		if (!id) return;
		$.ajax({
			url: '@Url.Action("ViewHelpPage", "Misc")',
			data: { Id: id },
			success: function (response) {
				$("#helpPageContent").html(response);
			},
			error: function () {
				 alert("error occured");
			}
		});
	}

	function editHelpPage(id) {
		if (!id) return;
		$.ajax({
			url: '@Url.Action("EditHelpPage", "Misc")',
			data: { Id: id },
			success: function (response) {
				setTimeout(function () {
					$("#helpPageContent").html(response);
					devHelpPageHtmlContentEditor.SetHeight($("#helpPageContent").height() - 1);
				}, 200);
			},
			error: function () {
				 alert("error occured");
			}
		});
	}

	function saveDataCallback() {
		devPopupControlEditHelpPage.Hide();
	}

	function confirmDelete(id) {
		if (!id) return;
		deleteId = id;
		$.ajax({
			type: "GET",
			url: '@Url.Action("GetHelpPage", "Misc")',
			data: { Id: id },
			success: function (response) {
				if (response == "notFound") return;
				var helpPage = JSON.parse(response);
				var popupControl = MVCxClientPopupControl.Cast(devPopupControlDeleteHelpPage);
				popupControl.SetHeaderText(popupControl.GetHeaderText().replace("{helpPage}", helpPage.Title));
				$(".dialogText").text($(".dialogText").text().replace("{helpPage}", helpPage.Title));
				popupControl.Show();
			}
		});
	}

	function deleteHelpPage() {
		$.ajax({
			type: "POST",
			url: '@Url.Action("DeleteHelpPage", "Misc")',
			data: { Id: deleteId },
			success: function (response) {
				var popupControl = MVCxClientPopupControl.Cast(devPopupControlDeleteHelpPage);
				popupControl.Hide();
				setTimeout(function () {
					window.location = window.location;
				}, 200);
			},
			error: function () {
				 alert("error occured");
			}
		});
	}
</script>

<link rel="stylesheet" type="text/css" href='@Url.Content("~/Content/jquery.mCustomScrollbar.min.css")' />

<style>

	.helpTable {
		width: 100%;
	}

	.helpTable > tbody > tr > td {
		vertical-align: top;
	}

	.helpTable > tbody > tr > td:first-of-type {
		padding-right: 12px;
	}

	.helpTable > tbody > tr > td:last-of-type {
		padding-left: 12px;
	}

	.helpPageMenu {
		width: auto;
		margin: 0 8px 6px 0;
		padding-bottom: 6px;
		border-bottom: 1px dashed #009688;
		overflow: auto;
	}

	#helpPageNavigation {
		border-right: 1px solid #009688;
	}

	#helpPageContent {
		color: black;
		overflow: auto !important;
	}
</style>

<table class="helpTable">
	<tr>
		<td style="width: 20%; min-width: 313px">
			<div class="helpPageMenu">
				@Html.DevExpress().Button(b =>
				{
					b.Name = "devButtonNewHelpPage";
					b.Text = "Neu";
					b.UseSubmitBehavior = false;
					//b.RenderMode = ButtonRenderMode.Link;
					b.ClientSideEvents.Click = "function (s, e) { editHelpPage(-1); }";
				}).GetHtml()
			</div>
			<div id="helpPageNavigation" class="mCustomScrollbar" data-mcs-theme="minimal-dark" style="width: 100%">
				@Html.Partial("~/Views/Misc/_HelpPageTreePartial.cshtml", Model)
			</div>
		</td>
		<td style="width: 80%">
			<div id="helpPageContent" style="width: 100%">

			</div>
		</td>
	</tr>
</table>

@Html.Partial("~/Views/Shared/_PopupDialogYesNo.cshtml", new GreenTree.Nachtragsmanagement.Web.Models.Global.YesNoDialogModel
{
	PopupName = "devPopupControlDeleteHelpPage",
	Content = "<div class='dialogText' style='padding: 12px'>Sind Sie sicher, dass Sie die Hilfe-Seite \"{helpPage}\" löschen möchten?</div>",
	HeaderText = "\"{helpPage}\" löschen",
	YesFunction = "function (s, e) { deleteHelpPage(); }"
})