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

    <div id="main-wrapper">
        <div class="row">
            <div class="col-md-12">
                @if(request()->get('del') == '1')
                    <div class="alert alert-success" role="alert">
                        Die Grobtechnik wurde erfolgreich gelöscht!
                    </div>
                @elseif(request()->get('del') == '0')
                    <div class="alert alert-danger" role="alert">
                        Beim Löschen der Grobtechnik ist ein Fehler aufgetreten!
                    </div>
                @elseif(request()->get('c') == '1')
                    <div class="alert alert-success" role="alert">
                        Die Grobtechnik wurde erfolgreich angelegt!
                    </div>
                @elseif(request()->get('c') == '0')
                    <div class="alert alert-danger" role="alert">
                        Beim speichern der Grobtechnik ist ein Fehler aufgetreten!
                    </div>
                @elseif(request()->get('u') == '1')
                    <div class="alert alert-success" role="alert">
                        Die Grobtechnik wurde erfolgreich aktualisiert!
                    </div>
                @elseif(request()->get('u') == '0')
                    <div class="alert alert-danger" role="alert">
                        Beim speichern der Grobtechnik ist ein Fehler aufgetreten!
                    </div>
                @endif
                <div class="panel panel-white">
                    <div class="panel-body">
                        <div class="table-responsive">
                            <div class="filter-container" id="filterContainer">
                                {!! Form::open(['action' => 'Medium\MediumOverviewController@index', 'class' => 'form-horizontal', 'id' => 'filterSourceTypesForm', 'method' => 'get', 'role' => 'form', 'files' => true]) !!}
                                    <input name="filtered" id="filtered" type="hidden" value="1">
                                    <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-medium') }}"><i class="menu-icon icon-plus"></i> Neues Suchwort</a>
                            </div>

                            {{$dataTable->table(['id' => 'data-table-medium'])}}

                            <script>
                                $(function() {
                                    $.ajaxSetup({
                                        headers: {
                                            'X-CSRF-TOKEN': '{{csrf_token()}}'
                                        }
                                    });

                                    var editor = new $.fn.dataTable.Editor({
                                        ajax: "/suchwoerter",
                                        table: "#data-table-medium",
                                        method: 'POST',
                                        //display: "bootstrap",
                                        idSrc:  'id',
                                        fields: [
                                            {label: "Suchwort DE", name: "searchword_de"},
                                            {label: "Suchwort EN", name: "searchword_en"},
                                            {label: "Suchwort FR", name: "searchword_fr"},
                                            //{label: "Grobtechnik ID", name: "t_medium_category_id"},
                                            {label: "Grobtechnik", name: "t_medium_category_id"},
                                        ]
                                    });

                                    $('#data-table-medium').on('click', 'tbody td:not(:first-child)', function (e) {
                                        editor.inline(this);
                                    });

                                    {{$dataTable->generateScripts()}}

                                })

                                // start artist rematching, if names are changed
                                $(document).on('keydown', '#DTE_Field_searchword_de, #DTE_Field_searchword_en, #DTE_Field_searchword_fr', function(e){

                                    var keyCode = (e.keyCode ? e.keyCode : e.which);
                                    if (keyCode == 13) {

                                        // Ajax request
                                        $.ajax({
                                            url: '/ajax/post-ajax-medium-rematching',
                                            type: 'POST',
                                            beforeSend: function (xhr) {
                                                var token = $('meta[name="csrf_token"]').attr('content');

                                                if (token) {
                                                    return xhr.setRequestHeader('X-CSRF-TOKEN', token);
                                                }
                                            },
                                            data: null,
                                            success:function(data){
                                                console.log('Ajax rematching wurde angestossen');
                                            },
                                            error:function(e){
                                                console.log(e);
                                                console.log('Ajax Error while assigning');
                                            }
                                        });
                                    }
                                });
                            </script>

                            {!! Form::open(['action' => 'Medium\MediumController@destroy', 'class' => 'form-horizontal', 'id' => 'deleteMediumForm', 'method' => 'post', 'role' => 'form', 'files' => true]) !!}
                                <input type="hidden" id="deleteMediumId" name="medium_id" value="">
                                <input type="hidden" id="deleteMediumPage" name="medium_page" value="">
                                <input type="hidden" id="deleteMediumLength" name="medium_length" value="">
                                <input type="hidden" id="deleteMediumSortColumn" name="medium_sort_column" value="">
                                <input type="hidden" id="deleteMediumSortDirection" name="medium_sort_direction" value="">
                            {!! Form::close() !!}
                        </div>
                    </div>

                    <p>* Spalte editierbar</p>
                </div>

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


@stop
