<?php $__env->startSection('module_name'); ?>
Category
<?php $__env->stopSection(); ?>

<?php $__env->startSection('add_btn'); ?>
<?php echo Form::open(['method' => 'get', 'url' => ['admin/category/create'], 'files' => true]); ?>

<span><?php echo Form::submit('Add Category', ['class' => 'btn btn-success pull-right']); ?></span>
<?php echo Form::close(); ?>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('table-properties'); ?>
width="400px" style="table-layout:fixed;"
<?php $__env->stopSection(); ?>



<style>
	td {
		white-space: nowrap;
		overflow: hidden;
		width: 30px;
		height: 30px;
		text-overflow: ellipsis;
	}
    .fhgyt th {
    border: 1px solid #e3e6f3 !important;
}
.fhgyt td {
    border: 1px solid #e3e6f3 !important;
    background: #f9f9f9
}
</style>
<?php $__env->startSection('table'); ?>

<table class="fhgyt" id="userTableAppend" style="opacity: 0">
<thead>
	<tr>

        <th>Name</th>
        <th>Description</th>
        <th>Image</th>
        <th>Edit</th>
		<th>Delete</th>


	</tr>
</thead>
<tbody>
</tbody>
</table>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('app_jquery'); ?>

<script>

$(document).ready(function(){

    fetchRecords();

    function fetchRecords(){

       $.ajax({
         url: '<?php echo asset("admin/category/get_category"); ?>',
         type: 'get',
         dataType: 'json',
         success: function(response){
            console.log('response');
            $("#userTableAppend").css("opacity",1);
           var len = response['data'].length;
		   console.log('response2');

           console.log(response);

              for(var i=0; i<len; i++){
                  var id =  response['data'][i].id;
                  var name =  response['data'][i].name;
                  var description =  response['data'][i].description;
                //   var image =  response['data'][i].avatar;
                  var image = `<img src="` +response['data'][i].avatar+ `" width="24%">`;
				  var edit = `<a class="btn btn-info" href="<?php echo asset('admin/category/edit/` + id + `'); ?>">Edit</a>`;
                       createModal({
                            id: 'category_' + response['data'][i].id,
                            header: '<h4>Delete</h4>',
                            body: 'Do you want to continue ?',
                            footer: `
                                <button class="btn btn-danger" onclick="delete_request(` + response['data'][i].id + `)"
                                data-dismiss="modal">
                                    Delete
                                </button>
                                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                                `,
                        });
                        var delete_btn = `<a class="btn btn-info" data-toggle="modal" data-target="#` + 'category_' + response['data'][i].id + `">Delete</a>`;

                        var tr_str = "<tr id='row_"+response['data'][i].id+"'>" +


                    "<td>" +name+ "</td>" +
                    "<td>" +description+ "</td>" +
                    "<td>" + image+ "</td>" +
                    "<td>" +edit+ "</td>" +
                    "<td>" +delete_btn+ "</td>" +


                "</tr>";

                $("#userTableAppend tbody").append(tr_str);
                }
                $(document).ready(function() {
console.log('sadasdasdad');
                $('#userTableAppend').DataTable({
					dom: '<"top_datatable"B>lftipr',
                    buttons: [
                        'copy', 'csv', 'excel', 'pdf', 'print'
                    ],
                });
            });
        }
       });
    }

});

function set_msg_modal(msg){
        $('.set_msg_modal').html(msg);
    }
    function delete_request(id) {
            $.ajax({

                url: "<?php echo asset('admin/category/delete'); ?>/" + id,
                type: 'POST',
                dataType: 'json',
                data: {
                    _token: '<?php echo @csrf_token(); ?>'
                },
                success: function(response) {
                    console.log(response);
                    if (response.status) {
                        var myTable = $('#userTableAppend').DataTable();
                        myTable.row('#row_' + id).remove().draw();
                    }
                }
            });
        }

</script>
<?php $__env->stopSection(); ?>


<?php echo $__env->make('layouts.default_module', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home2/demohatinco/public_html/medical2_backend/resources/views/admin/category/index.blade.php ENDPATH**/ ?>