@extends('layouts.main')
@section('title', 'Benutzer')
@section('headline', 'Benutzer')
@section('content')

    {{--<div class="page-title">
        <h3 class="breadcrumb-header pull-left">@yield('headline')</h3>
    </div>--}}
    <div id="main-wrapper">
        <div class="row">
            <div class="col-md-12">
                @if($alert == 'successDelete')
                    <div class="alert alert-success" role="alert">
                        Der Benutzer wurde erfolgreich gelöscht!
                    </div>
                @elseif($alert == 'errorDelete')
                    <div class="alert alert-danger" role="alert">
                        Beim Löschen des Benutzers ist ein Fehler aufgetreten!
                    </div>
                @elseif($alert == 'successCreate')
                    <div class="alert alert-success" role="alert">
                        Der Benutzer wurde erfolgreich angelegt!
                    </div>
                @elseif($alert == 'successUpdate')
                    <div class="alert alert-success" role="alert">
                        Der Benutzer wurde erfolgreich aktualisiert!
                    </div>
                @endif
                <div class="panel panel-white">
                    {{--<div class="panel-heading clearfix">
                        <h4 class="panel-title">Benutzerübersicht</h4>
                    </div>--}}
                    <div class="panel-body">
                        <div class="table-responsive">
                            <div class="filter-container" id="filterContainer">
                                {!! Form::open(['action' => 'Users\UsersOverviewController@index', 'class' => 'form-horizontal', 'id' => 'filterUserForm', 'method' => 'get', 'role' => 'form', 'files' => true]) !!}
                                    <input name="page" id="page" type="hidden" value="{{$page}}">
                                    <div id="pageLen" style="float: right; margin-left: 20px;">
                                        <input class="form-control" name="len" id="inputPageLen" type="text" max="999" maxlength="3" value="@if($pageLength){{$pageLength}}@else{{auth()->user()->table_page_length}}@endif" style="float: left; width: 50px;"> <label style="float: right; padding: 7px 5px 0;">Einträge anzeigen</label>
                                    </div>
                                {!! Form::close() !!}
                            </div>
                            <div class="button-line" id="buttonLine">
                                <a class="btn btn-primary" href="{{ route('create-user') }}"><i class="menu-icon icon-plus"></i> Neuer Benutzer</a>
                            </div>
                            <table id="data-table-users" class="cell-border data-table display table table-data-width">
                                <thead>
                                    <tr>
                                        <th class="col-action">Aktionen</th>
                                        <th>Vorname</th>
                                        <th>Nachname</th>
                                        <th>E-Mail</th>
                                        <th>Rolle</th>
                                        <th>Anz. Tab.zeilen</th>
                                        <th>ID</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse($users as $user)
                                        <tr>
                                            <td class="col-action">
                                                <a href="{{ route('edit-user', ['id' => $user->id]) }}" title="Benutzer bearbeiten"><i class="fa fa-pencil" aria-hidden="true"></i></a>
                                                @if(Auth::user()->id != $user->id)
                                                    <a href="javascript:confirmDeleteUser({{ $user->id }})" title="Benutzer löschen"><i class="fa fa-trash" aria-hidden="true"></i></a>
                                                @else
                                                    <a><i class="fa fa-trash" aria-hidden="true" style="color: #aaa; font-size: 18px;"></i></a>
                                                @endif
                                            </td>
                                            <td>{{ $user->first_name }}</td>
                                            <td>{{ $user->last_name }}</td>
                                            <td>{{ $user->email }}</td>
                                            <td>{{ $user->user_role_title }}</td>
                                            <td>{{ $user->table_page_length }}</td>
                                            <td>{{ $user->id }}</td>
                                        </tr>
                                    @empty
                                        <tr>
                                            <td>-</td>
                                            <td>-</td>
                                            <td>-</td>
                                            <td>-</td>
                                            <td>-</td>
                                            <td>-</td>
                                        </tr>
                                    @endforelse
                                </tbody>
                            </table>

                            <script type="text/javascript">
                                $('#data-table-users').DataTable({
                                    fixedHeader: {
                                        header: true,
                                        headerOffset: $('.page-header').outerHeight()
                                    },
                                    "pageLength": {{ $pageLength }},
                                    "lengthMenu": [ 10, 25, 50, 100 ],
                                    "lengthChange": false,
                                    "language": {
                                        "url": "/plugins/datatables/i18n/German.json"
                                    },
                                    "deferRender": true,
                                    "fnInitComplete": function (settings, json) {
                                        $('#filterContainer').insertAfter('#data-table-users_filter');
                                        $('#buttonLine').insertAfter('#data-table-users_filter');
                                        $('#filterContainer').show();
                                        $('#buttonLine').show();
                                    },
                                    "processing": true,
                                });

                                $('.table-responsive').on('scroll', function(e) {
                                    var left = $(this).scrollLeft();
                                    var left = left - 17;
                                    $('.fixedHeader-floating').css('left', -left);
                                });
                            </script>

                            {!! Form::open(['action' => 'Users\UserController@destroy', 'class' => 'form-horizontal', 'id' => 'deleteUserForm', 'method' => 'post', 'role' => 'form', 'files' => true]) !!}
                                <input type="hidden" id="deleteUserId" name="user_id" value="">
                            {!! Form::close() !!}
                        </div>
                    </div>
                </div>


            </div>
        </div><!-- Row -->
    </div><!-- Main Wrapper -->


@stop
