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

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

<script>
	var gridScrollHeight;
	var gridScrollOffset = 250;
	var resizeFinished;

	$(document).ready(function () {
		gridScrollHeight = calculateGridScrollHeight();
		setTimeout(function () {
			devGridViewLog.PerformCallback();
		}, 500);
	});

	$(window).resize(function () {
		clearTimeout(window.resizedFinished);
		window.resizedFinished = setTimeout(function () {
			setGridScrollHeight();
		}, 250);
	});

	function calculateGridScrollHeight() {
		var windowHeight = $(window).height();
		var gridHeaderHeight = $("#devGridViewLog_DXHeadersRow0").height();
		var gridFooterHeight = $("#devGridViewLog_DXFooterRow").height();
		return windowHeight - gridHeaderHeight - gridFooterHeight - gridScrollOffset;
	}

	function setGridScrollHeight() {
		gridScrollHeight = calculateGridScrollHeight();
		devGridViewLog.PerformCallback();
	}

	function onToolbarItemClick(s, e) {
		if (!s || !e) return;
		if (e.item.name == "Print") {
			parent.$(".printPopupContainer").remove();
			$.ajax({
				type: "POST",
				url: '@Url.Action("ExportPartialLogs", "Misc")',
				data: { displayMode: "popup", exportFormat: "" },
				success: function (response) {
					parent.$("body").append(response);
					parent.exportFormat = "pdf";
				}
			});
		} else if (e.item.name == "ToggleColumnChooser") {
			if (devGridViewLog.IsCustomizationWindowVisible())
				devGridViewLog.HideCustomizationWindow();
			else
				devGridViewLog.ShowCustomizationWindow();
		}
	}

	function viewLog(id) {
		if (!id) return;
		$.ajax({
			url: '@Url.Action("viewLog", "Misc")',
			data: { Id: id },
			success: function (response) {
				setTimeout(function () {
					$(".logViewContainer").remove();
					$("body").append(response);
				}, 200);
			},
			error: function () {
				 alert("error occured");
			}
		});
	}

	function deleteLog(id) {
		$.ajax({
			type: "POST",
			url: '@Url.Action("DeleteLog", "Misc")',
			data: { Id: id },
			success: function (response) {
				setTimeout(function () {
					devGridViewLog.PerformCallback();
				}, 200);
			},
			error: function () {
				 alert("error occured");
			}
		});
	}
</script>

@Html.Partial("~/Views/Misc/_LogGridPartial.cshtml", Model)