@model IEnumerable<GreenTree.Maschinenbestellungen.Web.Models.Rights.User.UserModel>

@{
    ViewData["Title"] = "Benutzerverwaltung";
}

<!-- Custom JavaScript -->
<script>

    $(window).resize(function () {
        $(".dataTables_scrollBody").height($(window).height() - 260);
    });

    $(document).ready(function () {
        $("#usersTable").DataTable({
            scrollY: $(window).height() - 260 + "px",
            autoWidth: true,
            paging: false,
            "bInfo": false,
            columns: [
                {
                    data: "ID",
                    orderable: true
                },
                {
                    data: "Kontoname",
                    orderable: true
                },
                {
                    data: "Vorname",
                    orderable: true
                },
                {
                    data: "Nachname",
                    orderable: true
                },
                {
                    data: "Geburtsdatum",
                    orderable: true
                },
                {
                    data: "Aktiviert",
                    orderable: true
                },
                {
                    data: "Rechte",
                    orderable: false
                },
                {
                    data: "Aktionen",
                    orderable: false
				}
            ],
            language: {
                zeroRecords: "Keine Einträge gefunden",
                search: "Suchen:"
			}
        });
    });

    function showDeleteModal(id) {
        if (!id) return;
        $('#deleteModal').modal("show");
        $("[name='id'").val(id);
    }

</script>

<h1>Benutzerverwaltung</h1>

<p>
    <a asp-action="Create">Neuen Benutzer anlegen</a>
</p>
<table id="usersTable" class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Id)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Accountname)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Forename)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Lastname)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Birthdate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Activated)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Policies)
            </th>
            <th>
                Aktionen
            </th>
        </tr>
    </thead>
    <tbody>
    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Id)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Accountname)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Forename)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Lastname)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Birthdate)
            </td>
            <td>
                @Html.YesNoBadgeFor(modelItem => item.Activated)
            </td>
            <td>
                @Html.TokenBoxFor(modelItem => item.Policies)
            </td>
            <td>
                @Html.ActionLink("Bearbeiten", "Edit", new { id = item.Id }) |
                @Html.ActionLink("Anzeigen", "Details", new { id = item.Id }) |
                <a href="#" onclick="showDeleteModal(@item.Id)">Löschen</a>
            </td>
        </tr>
    }
    </tbody>
</table>

<div id="deleteModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Benutzer löschen</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form asp-action="Delete">
                <div class="modal-body">
                    <p>Sind Sie sicher, dass Sie diesen Benutzer löschen möchten?</p>
                    <input name="id" type="hidden" />
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">Ja</button>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Nein</button>
                </div>
            </form>
        </div>
    </div>
</div>

@section Scripts {
    @{
		await Html.RenderPartialAsync("_TokenBoxLibPartial");
	}
}
