

<?php $__env->startSection('styles'); ?>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css">
    <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;
        }

        /*.alert-danger .btn-danger {*/
        /*float: right;*/
        /*}*/

        /*.alert-danger span {*/
        /*line-height: 34px;*/
        /*}*/

        /*.alert-danger > div:after {*/
        /*clear: both;*/
        /*content: '';*/
        /*display: table;*/
        /*}*/
    </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(session()->has('success_coupon')): ?>
        <?php echo session()->get('success_coupon'); ?>

    <?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">
        Danh sách loại tài sản
    </h1>


    <div class="row">

        <?php if(auth('backend')->user()->can('add-item-type')): ?>
        <div class="col-md-12">
            <div class="text-center" style="margin-top: 15px; line-height: 34px">
                <a href="#add-item-type" data-toggle="modal" class="btn btn-success" id="btn-add-item-type"
                   style="float: right">Thêm loại tài sản</a>

            </div>
        </div>
        <?php endif; ?>

        <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>Tên</th>
                    <th>Mã hệ thống</th>
                    <th>Mã tham chiếu</th>
                    <th style="width: 10%;">Thao tác</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 style="width: 10%;"></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="add-item-type" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close2" data-dismiss="modal" aria-hidden="true"><span
                                aria-hidden="true" style="
    color: white;
">×</span></button>
                    <h4 class="modal-title">Thêm loại tài sản</h4>
                </div>
                <div class="modal-body" id="add-item-type-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-item-type">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>





<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script src="/assets/global/plugins/dropzone/dropzone.min.js" type="text/javascript"></script>
<script src="/assets/pages/scripts/form-dropzone.min.js" type="text/javascript"></script>
<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 type="text/javascript"
        src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCydLs7dhJPuozABFQjJO-uk1PITW18oo8&libraries=places&region=vi&language=vi&sensor=false"></script>
<script type="text/javascript" src="/js/gmap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></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;

    $(document).on('click', '#btn-add-item-type', function () {
        $.ajax({
            url: '<?php echo e(url('admin2/warehouse/create-item-type')); ?>',
            type: 'get',
            dataType: 'json',
            beforeSend: function () {
                $('#add-item-type-content').addClass('ht-on-loading');
            },
            success: function (response) {
                $('#add-item-type-content').removeClass('ht-on-loading').html(response.data);
            }
        });
    });
    $(document).on('click', '.btn_edit_item_type', function () {
        $(this).parents('tr').find('.name_input').css('display','block');
        $(this).parents('tr').find('.reference_input').css('display','block');

        $(this).parents('tr').find('.name_text').css('display','none');
        $(this).parents('tr').find('.reference_text').css('display','none');
        $(this).parents('tr').find('.btn_save_item_type').css('display','block');
        $(this).parents('tr').find('.btn_cancel_item_type').css('display','block');
        $(this).css('display','none');
    })

    $(document).on('click', '.btn_cancel_item_type', function () {
        $(this).parents('tr').find('.name_input').css('display','none');
        $(this).parents('tr').find('.reference_input').css('display','none');

        $(this).parents('tr').find('.name_text').css('display','block');
        $(this).parents('tr').find('.reference_text').css('display','block');
        $(this).parents('tr').find('.btn_save_item_type').css('display','none');
        $(this).parents('tr').find('.btn_save_item_type').css('display','none');
        $(this).parents('tr').find('.btn_edit_item_type').css('display','block');
        $(this).css('display','none');
    })

    $(document).on('click', '.btn_save_item_type', function () {
        var id = $(this).attr('data-id');
        var name = $(this).parents('tr').find('.name_input').val();
        var reference = $(this).parents('tr').find('.reference_input').val();
        $.ajax({
            url: '<?php echo e(url('admin2/warehouse/edit-item-type')); ?>',
            type: 'post',
            data:{id: id, name: name, reference: reference},
            dataType: 'json',
            success: function (response) {
                swal('Thông báo', response.message, 'success');
                table.ajax.reload(null, false);
            }
        });

    })

    $(document).on('click', '.btn_delete_item_type', function () {
        var id = $(this).attr('data-id');
        $.confirm({
            title: 'Cảnh báo!',
            content: 'Dữ liệu sẽ bị xóa khi thực hiện thao tác',
            type: 'orange',
            typeAnimated: true,
            buttons: {
                OK: {
                    text: 'Đồng ý',
                    btnClass: 'btn-orange',
                    action: function(){
                        $.ajax({
                            url: '<?php echo e(url('admin2/warehouse/delete-item-type')); ?>',
                            type: 'post',
                            data:{id: id,},
                            dataType: 'json',
                            success: function (response) {
                                swal('Thông báo', response.message, 'success');
                                table.ajax.reload(null, false);
                            }
                        });
                    }
                },
                close: {
                    text: 'Đóng',
                    action: function () {
                        
                    }
                }
            }
        });

    })



    $(document).on('click', '#btn-save-item-type', function (e) {
        e.preventDefault();
        var data = $('#form-add-item-type').serialize();

        var formStatus = $('#form-add-item-type').validate({
            errorElement: "span",
            errorClass: "help-block help-block-error",

            highlight: function (e) {
                $(e).closest(".form-group").addClass("has-error")
            },
            unhighlight: function (e) {
                $(e).closest(".form-group").removeClass("has-error")
            },
            success: function (e) {
                e.closest(".form-group").removeClass("has-error")
            },
            rules: {
                'name': "required",
            },
            messages: {
                'name': "Không được bỏ trống tên"
                // 'amenities[]': "Không được bỏ trống tiện ích"
            }
        }).form();

        if (formStatus) {

            $.ajax({
                url: '<?php echo e(url('admin2/warehouse/create-item-type')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                beforeSend: function () {
                    $('#add-item-type-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#add-item-type-content').removeClass('ht-on-loading');
                    if (response.status == 1) {
                        $('#add-item-type').modal('hide');
                        table.ajax.reload(null, false);
                    } 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');
                    }
                }
            });
        }
    });


    $(function () {

        $('#orders-table tfoot th').each(function (index) {
            if (index != 0 && index != 3) {
                $(this).html('<input type="text" class="form-control" />');
            }
        });
        table = $('#orders-table').DataTable({
            "bDestroy": true,
            processing: true,
            searching: true,
            "aaSorting": [],
            serverSide: true,
            ajax: {
                url: '<?php echo url('admin2/warehouse/item-type.data'); ?>',
            },
            columns: [

                {data: 'DT_Row_Index', name: 'DT_Row_Index', orderable: false, searchable: false},
                {data: 'name', name: 'name'},
                {data: 'code', name: 'code'},
                {data: 'reference', name: 'reference'},

                {data: 'action', name: 'action', 'orderable': false, searchable: false},
            ],
        });


        table.columns().every(function (index) {
            if (index !== 0) {
                var that = this;
                $('input', this.footer()).on('keyup change', function () {
                    if (that.search() !== this.value) {
                        that
                            .search(this.value)
                            .draw();
                    }
                });
            }
        });

    });


</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('admin2', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>