

<?php $__env->startSection('styles'); ?>

    <link href="/assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.css" rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker3.min.css" rel="stylesheet"
          type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet"
          type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-editable/bootstrap-editable/css/bootstrap-editable.css"
          rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.css" rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-editable/inputs-ext/address/address.css" rel="stylesheet"
          type="text/css"/>


    <style>

        .pac-container {
            z-index: 10052 !important;
        }

        #map {
            width: auto !important;
            height: 500px !important;
        }

        #map_edit {
            width: auto !important;
            height: 500px !important;
        }

        tfoot {
            display: table-header-group;
        }

        tfoot input {
            font-weight: normal !important;
        }

        tfoot select {
            font-weight: normal !important;
        }

        .dataTables_filter {
            display: none;
        }

        #orders-table_length {
            display: none;
        }

        .ws-nr {
            width: 100% !important;
        }

    </style>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <?php if(session()->has('error')): ?>
        <div class="alert alert-danger"><?php echo e(session()->get('error')); ?></div>
    <?php endif; ?>
    <?php if(session()->has('success')): ?>
        <div class="alert alert-success"><?php echo e(session()->get('success')); ?></div>
    <?php endif; ?>
    <?php if(count($errors) > 0): ?>
        <div class="alert alert-danger">
            <ul>
                <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li><?php echo e($error); ?></li>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </ul>
        </div>
    <?php endif; ?>
    <h1 class="page-title">
        Cấu hình ngôn ngữ
    </h1>
    <div class="row">
        <div class="col-md-12">
            <a id="btn-create" href="#edit" class="btn btn-success" data-toggle="modal" >Thêm</a>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped table-bordered table-hover" id="orders-table">
                <thead>
                <tr style="background-color: #5376B9; color: white">
                    <th>STT</th>
                    <th>KEY</th>
                    <th>Tiếng Việt</th>
                    <th>Tiếng Anh</th>
                    <th>Hành động</th>
                </tr>
                </thead>
                <tfoot>
                <tr>
                    <th></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th></th>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12" id="detail">
        </div>
    </div>


    <div class="modal fade bs-modal-lg" id="edit" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content ">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title" id="edit-title">Cập nhật</h4>
                </div>
                <div class="modal-body" id="edit-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>


<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script src="/assets/global/plugins/jquery-validation/js/jquery.validate.min.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery-validation/js/additional-methods.min.js" type="text/javascript"></script>

    <script>
        $.validator.addMethod("greaterThan",
            function (value, element, param) {
                var $otherElement = $(param);
                return parseInt(value, 10) >= parseInt($otherElement.val(), 10);
            }
        );
    </script>


<?php $__env->stopPush(); ?>


<?php $__env->startPush('scripts'); ?>
    <script>
        var table;

        function getPostByAttr() {
            table.ajax.reload();
        }

        $(function () {

            table = $('#orders-table').DataTable({
                "bDestroy": true,
                processing: true,
                searching: true,
                serverSide: true,
                aaSorting: [],
                ajax: {
                    url: '<?php echo url('admin/trans/trans.data'); ?>',
                    data: function (d) {

                    }
                },
                columns: [
                    {data: 'DT_Row_Index', name: 'DT_Row_Index', orderable: false, searchable: false},
                    {data: 'key', name: 'key'},
                    {data: 'vi', name: 'vi'},
                    {data: 'en', name: 'en'},
                    {data: 'action', name: 'action', 'orderable': false, searchable: false},
                ],
                drawCallback: function () {


                }
            });

            table.columns().every(function (index) {

                    var that = this;
                    $('input', this.footer()).on('keyup', function () {
                        if (that.search() !== this.value) {
                            that
                                .search(this.value)
                                .draw();
                        }
                    });

                    $('select', this.footer()).on('change', function () {
                        if (that.search() !== this.value) {
                            that
                                .search(this.value)
                                .draw();
                        }
                    });

            });

        });

        $(document).on('click', '.btn-edit', function (e) {
            e.preventDefault();
            var id = $(this).attr('data-id'); $('#edit-title').text('Cập nhật');
            $.ajax({
                url: '<?php echo e(url('admin/trans/edit')); ?>',
                type: 'get',
                data: {
                    id: id,
                },
                beforeSend: function () {
                    $('#edit-content').addClass('ht-on-loading');
                },
                dataType: 'json',
                success: function (response) {
                    $('#edit-content').removeClass('ht-on-loading').html(response.data);
                }
            });
        });

        $(document).on('click', '#btn-create', function (e) {
            e.preventDefault();
            $('#edit-title').text('Thêm');
            $.ajax({
                url: '<?php echo e(url('admin/trans/edit')); ?>',
                type: 'get',
                beforeSend: function () {
                    $('#edit-content').addClass('ht-on-loading');
                },
                dataType: 'json',
                success: function (response) {
                    $('#edit-content').removeClass('ht-on-loading').html(response.data);
                }
            });
        });

        $('#btn-save').click(function (e) {
            e.preventDefault();
            let data = $('#form-edit-trans').serialize();
            $.ajax({
                url: '<?php echo e(url('admin/trans/create')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#edit-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#edit-content').removeClass('ht-on-loading');
                    $('#edit').modal('hide');
                    if (response.status == 1) {
                        swal('Thành công', response.message, 'success');

                    } else if (response.status == 0) {
                        swal('Thông báo', response.message, 'warning');
                    } else if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    }
                    table.ajax.reload(null, false);
                }
            });

        });
        $(document).on('click', '.btn-delete', function (e) {
            e.preventDefault();
            var id = $(this).attr('data-id');

            bootbox.confirm({
                message: "Bạn có chắc chắn muốn xóa",
                buttons: {
                    confirm: {
                        label: 'Có',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: 'Không',
                        className: 'btn-danger'
                    }
                },


                callback: function (result) {
                    if (result == true) {
                        $.ajax({
                            url: '<?php echo e(url('admin/trans/delete')); ?>',
                            type: 'post',
                            data: {
                                id: id
                            },
                            dataType: 'json',
                            success: function (response) {
                                swal('Xóa thành công', '', 'success');
                                table.ajax.reload();
                            }
                        });
                    }
                }
            });
        });

    </script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('admin', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>