@extends('layouts.app-hr')

@section('content')
    <?php Fun::lang()?>

    <div class="page">
        <div class=container-fluid>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3>{{__('administrator.department')}} </h3>
                            </div>
                            <div class="pull-right">
                                <a href="{{route('department.create')}}" class=" button_info"><span
                                            class="fa fa-plus"></span> {{__('administrator.add_new')}}</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="wrapper-table">
                <table id="datatable_products" width="100%" class="table table-striped table-hover   table-hover">
                    <thead>
                    <tr>
                        <th> #</th>
                        <th>{{ __('administrator.department_name') }}</th>
                        <th>{{ __('administrator.note') }}</th>
                        <th> {{ __('administrator.action') }}</th>
                    </tr>
                    </thead>
                    <tbody>

                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="modal fade bs-modal-lg" id="form_delete" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-dm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h3 class="modal-title">Are you sure?</h3>
                </div>
                <br/>
                <form role="form" method="delete" id="delete">
                    {{csrf_field()}}
                    <div class="row">
                        <div class="col-md-12">
                            <div class="col-md-10">
                                <h4>Are you want to delete?</h4>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" data-dismiss="modal" class="button_danger"><i class="fa fa-close"></i> No
                        </button>
                        <button type="button" class="button_primary deleteRecord" data-toggle="modal"><i
                                    class="fa fa-save"></i> OK
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection



@section('script')

    <script type="text/javascript">
        $(document).ready(function () {
            $('#datatable_products').DataTable({
                ordering: false,
                serverSide: true,
                lengthMenu: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],
                ajax: "{{ route('datatable_department') }}",
                columns:
                    [
                        {data: 'DT_RowIndex'},
                        {data: 'department_name'},
                        {data: 'note'},
                        {data: 'action'},

                    ],

                "initComplete": function (settings, json) {
                }
            });

            $.fn.dataTable.ext.errMode = 'throw';
        });

        $(document).on('click', '.delete_products', function () {
            $('#form_delete').modal('show');
            var id = $(this).data("id");
            $(".deleteRecord").click(function () {
                var token = $("meta[name='csrf-token']").attr("content");
                $.ajax({
                    url: "{{route('department.delete_department')}}",
                    type: 'GET',
                    data: {
                        "id": id,
                        "_token": token,
                    },
                    success: function () {
                        $('#form_delete').modal('hide');
                        location.reload();

                    }
                });
            });
        });
    </script>
@stop



