@extends('layouts.admin',['hide_menu'=>false])

@section('content')


<div class="container" style="padding-top: 15px">

    $START_COMMENT_CREATE$
    <a onclick="modal('{{ route('$ROUTE$.create'$IF_HAS_PARENT$, [$parent]$END_HAS_PARENT$) }}')"
       href="javascript:void(0)" class="btn btn-primary btn-sm">
        <span class="fa fa-plus-square"></span>
        Add
    </a> &nbsp;&nbsp;&nbsp;&nbsp;
    $END_COMMENT_CREATE$
    {{ $items->total() }} items

    <br><br>

    @if(session()->has('flash_message'))
        <div class="alert alert-success alert-dismissible" style="display: inline-block" role="alert">
            <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            &nbsp; {{ session()->get('flash_message') }}
        </div>
        <br clear="all">
    @endif


    @if($errors->any())
        @foreach($errors->all() as $error)
            <div class="alert alert-danger alert-dismissible" style="display: inline-block" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                {{ $error }}
            </div>
        @endforeach
        <br clear="all">
    @endif

$SELECT_FROM_PARENT$

    <div class="table-responsive" style="{{ $items->total() == 0 ? 'display:none;' : "" }}">
    <table class="table table-striped table-inverse table-bordered table-hover table-sm table-responsive" style="width: auto !important;">
        <thead>
            <tr>
$TABLE_HEADER$
            $CHILD_LINK_HEADER$
            $MANYTO_LINK_HEADER$
            $START_COMMENT_DELETE$<th>&nbsp;</th>$END_COMMENT_DELETE$
            $START_COMMENT_UPDATE$<th>&nbsp;</th>$END_COMMENT_UPDATE$
            <th>&nbsp;</th>
        </tr>
        </thead>

        @foreach($items as $item)

            {{ $highlightClass = ""}}
            @if (session()->has('highlight'))
                @if (session()->get('highlight') == $item->id)
                    <!--
                        {{ $highlightClass = "info" }}
                        {{ request()->session()->forget('highlight') }}
                    -->
                @endif
            @endif

            <tr class="{{ $highlightClass }}">
$TABLE$

                $CHILD_LINK$
                $MANYTO_LINK$

                $START_COMMENT_DELETE$
                <td width="1">
                   <form class="form-inline" method="POST" action="{{  route('$ROUTE$.destroy', [$IF_HAS_PARENT$$parent, $END_HAS_PARENT$$item->$PRIMARY_KEY$]) }}">
                        {{ csrf_field() }}
                       <input name="_method" type="hidden" value="DELETE">
                       <button onclick="return confirm('Are you sure?')"  type="submit" class="btn btn-link btn-xs">
                           <span class="fa fa-remove"></span>
                       </button>
                   </form>
                </td>
                $END_COMMENT_DELETE$
                $START_COMMENT_UPDATE$
                <td width="1">
                   <a onclick="modal('{{ route('$ROUTE$.edit', [$IF_HAS_PARENT$$parent, $END_HAS_PARENT$$item->$PRIMARY_KEY$]) }}')" href="javascript:void(0)" class="btn btn-link btn-xs">
                       {{--<span class="fa fa-edit"></span>--}}
                       Edit
                   </a>
                </td>
                $END_COMMENT_UPDATE$
                <td width="1">
                   <a onclick="modal('{{ route('$ROUTE$.show', [$IF_HAS_PARENT$$parent, $END_HAS_PARENT$$item->$PRIMARY_KEY$]) }}')" href="javascript:void(0)" class="btn btn-link btn-xs">
                       {{--<span class="fa fa-view"></span>--}}
                       View
                   </a>
                </td>
            </tr>



            @endforeach


        </table>
    </div>



    @if ($items->lastPage() > 1)
        <div style="padding-top: 15px; display: inline-block;">
            {{ $items->appends(request()->query())->links('vendor.pagination.bootstrap-4') }}
        </div>
    @endif



    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <!--<h4 class="modal-title" id="myModalLabel">Modal title</h4>-->
                </div>
                <div class="modal-body">
                    <iframe frameborder="0" scrolling="auto" height="100%" width="100%" src=""></iframe>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

    <script>
        function modal(url) {
            $('#myModal').find('iframe').attr('src', url);
            $('#myModal').modal();
            $('#myModal .modal-body').css('height', $(window).height() * 0.7);
        }
    </script>

    {{-- reload page after modal close --}}
    <script>
        var refreshPageOnModalClose = false;
        $("#myModal").on("hidden.bs.modal", function () {
            if(refreshPageOnModalClose) {
                window.location.reload(true);
            }
        });
    </script>


</div>

@stop



