@extends('admin.layouts.master')

@section('title')
    Developers
@stop

@section('style')

{{--<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">--}}

<style>
    .modal-content{
      z-index:2000 !important;
    }

    .modal-backdrop {
        z-index: 1040 !important;
    }
    .modal-dialog {
        margin: 2px auto;
        z-index: 1100 !important;
    }
</style>

@stop

@section('content')
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                <span class="fa fa-users"></span> Developers
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-users"></i> Admin Panel</a></li>
                <li class="active">Developers</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content" style=" padding-bottom: 100%;">
            <div class="page-header">
                <a href="#" id="btnAdd" name="btnAdd" class="btn btn-primary"><i class="fa fa-plus-circle"></i> New Developer</a>
            </div>

            <table class="table table-hover" id="user_table" width="100%">
                <thead>
                <tr style="background: grey ;color:#fff; font-weight: bold">
                    <td>ID</td>
                    <td>Code</td>
                    <td>Name</td>
                    {{--<td>Full Name</td>
                    <td>Email</td>
                    <td>Role</td>--}}
                    <td>Created At</td>
                    <td>Last Update</td>
                    <td>Actions</td>
                </tr>
                </thead>
                @foreach($devs as $dev)
                    <tr >
                        <td>{{$dev->id}}</td>
                        <td width="15%">{{$dev->code}}</td>
                        <td width="25%">{{$dev->name}}</td>
                        <td>{{date("d-M-Y", strtotime($dev->created_at))}}</td>
                        <td>@if ($dev->updated_at == null)
                            NULL
                        @else
                            {{date("d-M-Y", strtotime($dev->updated_at))}}
                        @endif
                        </td>
                        <td class="btn btn-default ">
                            <a href="#" data-toggle="modal" data-target="#e{{$dev->id}}" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a>
                            <!-- Edit Modal -->
                            <div class="modal fade" id="e{{$dev->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                <div class="modal-dialog" role="document">
                                    <form method="post" action="{{route('developer.update')}}">
                                        <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">Edit Developer Info for <b>"{{$dev->name}}"</b></h4>
                                            </div>
                                            <div class="modal-body text-left">
                                                <input type="hidden" name="id" value="{{$dev->id}}">
                                                <div class="form-group has-feedback @if($errors->has('code')) has-error @endif">
                                                    <label for="code" class="control-label">Developer Code</label>
                                                    <input value="{{$dev->code}}" type="text" name="code" id="code" class="form-control" required>
                                                    <span class="glyphicon glyphicon-book form-control-feedback"></span>
                                                    @if($errors->has('code')) <span class="help-block">{{$errors->first('code')}}</span> @endif
                                                </div>
                                                <div class="form-group has-feedback @if($errors->has('name')) has-error @endif">
                                                    <label for="name" class="control-label">Developer Name</label>
                                                    <input value="{{$dev->name}}" type="text" name="name" id="name" class="form-control" required>
                                                    <span class="glyphicon glyphicon-user form-control-feedback"></span>
                                                    @if($errors->has('name')) <span class="help-block">{{$errors->first('name')}}</span> @endif
                                                </div>

                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                <button type="submit" class="btn btn-primary">Update</button>
                                            </div>

                                        </div>
                                        {{csrf_field()}}
                                    </form>
                                </div>
                            </div>

                            <a href="#" data-toggle="modal" data-target="#d{{$dev->id}}" class="text-danger btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
                            <!-- Delete Modal -->
                            <div class="modal fade" id="d{{$dev->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                <div class="modal-dialog" role="document">
                                    <form method="post" action="{{route('developer.delete')}}">
                                    <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"><i class="fa fa-warning"></i> confirm deletion</h4>
                                        </div>
                                        <div class="modal-body text-danger">
                                            <input type="hidden" name="id" value="{{$dev->id}}">
                                            Are you sure want to delete developer <b>"{{$dev->name}}"</b>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                            <button type="submit" class="btn btn-primary">Confirm</button>
                                        </div>

                                    </div>
                                        {{csrf_field()}}
                                    </form>
                                </div>
                            </div>
                        </td>
                    </tr>
                    @endforeach
            </table>
            @if(Session('info'))
                <div class="row">
                    <div class="col-md-6 col-md-offset-3 text-center">
                        <div class="tem alert alert-success navbar-fixed-bottom"><span class="glyphicon glyphicon-ok-circle"></span> {{Session('info')}}</div>
                    </div>
                </div>
            @endif
        </section>

        <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <form method="post" action="{{route('developer.new')}}">
                    <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">Create New Developer</h4>
                        </div>
                        <div class="modal-body text-left">
                            <input type="hidden" name="id" value="">
                            <div class="form-group has-feedback @if($errors->has('code')) has-error @endif">
                                <label for="code" class="control-label">Developer Code * </label>
                                <input value="" type="text" name="code" id="code" class="form-control" required>
                                <span class="glyphicon glyphicon-book form-control-feedback"></span>
                                @if($errors->has('code')) <span class="help-block">{{$errors->first('code')}}</span> @endif
                            </div>
                            <div class="form-group has-feedback @if($errors->has('name')) has-error @endif">
                                <label for="name" class="control-label">Developer Name *</label>
                                <input value="" type="text" name="name" id="name" class="form-control" required>
                                <span class="glyphicon glyphicon-user form-control-feedback"></span>
                                @if($errors->has('name')) <span class="help-block">{{$errors->first('name')}}</span> @endif
                            </div>

                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            <button type="submit" class="btn btn-primary">Save</button>
                        </div>

                    </div>
                    {{csrf_field()}}
                </form>
            </div>
        </div>

    </div>


@stop

@section('script')

    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>

    <script>
        $(document).ready(function() {
            $('#user_table').DataTable( {
                "bDestroy": true,
                /*searching: true,
                paging: true,
                lengthChange: true,
                pageLength: 10,
                info: true,
                orderable: true,*/
                "order": [[ 0, "desc" ]]
            } );
        } );

        $("#btnAdd").on("click", function(){
            //alert('ready');
            $('#addModal').modal('toggle');
            $("#addModal").appendTo("body");

        });
    </script>
@stop