<?php $__env->startSection('module_name'); ?>
List of Questions
<?php $__env->stopSection(); ?>

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

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

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

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

<table id="questionTableAppend" style="opacity: 0">
    <thead>
        <tr>

            <th>Question</th>
            <th>Edit</th>
            <th>Delete</th>

        </tr>
    </thead>
    <tbody>
    </tbody>
</table>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('app_jquery'); ?>

<script>
    $(function() {

        fetchRecords();

        function fetchRecords() {
            $.ajax({
                url: '<?php echo asset("admin/getquestion/0"); ?>',
                type: 'get',
                dataType: 'json',
                success: function(response) {
                    $("#questionTableAppend").css("opacity", 1);
                    var len = response['data'].length;
                    console.log(response);
                    for (var i = 0; i < len; i++) {
                        console.log('aaaaaaa',response['data'][i]);
                        var id = response['data'][i].id;
                        // var question = response['data'][i].question;
                        var question_text = response['data'][i].question;
                        console.log('qqqqqqqq',response['data'][i].question);
                        var edit = `<a class="btn btn-info" href="<?php echo asset('admin/question/edit/` + id + `'); ?>">Edit</a>`;
                       createModal({
                            id: 'question_' + 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="#` + 'question_' + response['data'][i].id + `">Delete</a>`;

                        var tr_str = "<tr id='row_"+response['data'][i].id+"'>" +
                            "<td>" + question_text + "</td>" +
                            "<td>" + edit + "</td>" +
                            "<td>" + delete_btn + "</td>" +
                            "</tr>";

                        $("#questionTableAppend tbody").append(tr_str);
                    }
                    $('#questionTableAppend').DataTable({
                        dom: '<"top_datatable"B>lftipr',
                    });
                }
            });
        }

    });

    function delete_request(id) {
        $.ajax({

            url: "<?php echo asset('admin/question/delete'); ?>/" + id,
            type: 'POST',
            dataType: 'json',
            data: {
                _token: '<?php echo @csrf_token(); ?>'
            },
            success: function(response) {
                console.log(response);
                if(response.status){
                    var myTable = $('#questionTableAppend').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/question/index.blade.php ENDPATH**/ ?>