<div class="modal fade" id="modal-report" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel"
    aria-hidden="true">
    <div class="modal-dialog" style="max-width: 70rem; ">
        <div class="modal-content">


            <div class="modal-header">
                <h5 class="modal-title">Add New</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                 <div class="row"> 
                <!-- <button class="btn btn-success" type="button" onclick="showValue()"><i class="feather icon-plus"></i> Add</button> -->
               <div class="col-lg-2">
                <input type="text" id="search_text77" class="form-control"
                            placeholder="Search..." style="width: 250%;" autofocus>
               </div> 
                </div><br><br>
                
               
                <style>
                table.scrolldown {
                    width: 100%;

                    /* border-collapse: collapse; */
                    border-spacing: 0;
                    /*border: 2px solid black;*/
                }

                /* To display the block as level element */
                table.scrolldown tbody,
                table.scrolldown thead {
                    display: block;
                }

                thead tr th {
                    /*height: 40px; 
            line-height: 40px;*/
                }

                table.scrolldown tbody {

                    /* Set the height of table body */
                    height: 300px;

                    /* Set vertical scroll */
                  
                }
                
                </style>



                <div class="table-responsive" id="tableresult">

                </div>

                <div class="card mb-4">
                    <div class="card-body">
                        <form action="" method="POST" id="validation-form" novalidate="novalidate">
                            <div class="form-row align-items-center">


                                <div class="col-md-10">
                                    <label class="form-label">Description <span class="text-danger">*</span></label>
                                    <input type="text" name="Description" id="Description" class="form-control"
                                        placeholder="Description" value="">
                                </div>
                                <input type="hidden" name="OldValue" id="OldValue" value="">
                                <input type="hidden" name="ModalValue" id="ModalValue" value="">
                                <input type="hidden" name="ValueId" id="ValueId" value="">
                                <input type="hidden" name="id" id="descid" value="">
                                <input type="hidden" name="action" id="DescAction" value="Save">
                                <div class="col-md-2">
                                    <label class="form-label d-none d-md-block">&nbsp;</label>
                                    <button type="button" id="btn_search" class="btn btn-primary btn-block"
                                        onclick="addDesc()">Add</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
function desc_lists(val) {
    var action = 'view';
    var ModalValue = $('#ModalValue').val();
    $.ajax({
        url: "<?php echo e(url('getDescList')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            ModalValue: val
        },
        success: function(data) {
            //console.log(data);
            $('#tableresult').html(data);
        }
    });
}

function addDesc() {
    var Description = $('#Description').val();
    var ModalValue = $('#ModalValue').val();
    var action = $('#DescAction').val();
    var id = $('#descid').val()
    if (Description.trim() == '') {
        alert("Please Enter Description");
        $('#Description').focus();
    } else {
        $.ajax({
            url: "<?php echo e(url('saveDesc')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                action: action,
                Description: Description,
                ModalValue: ModalValue,
                id: id
            },
            beforeSend: function() {
                $('#btn_search').attr('disabled', 'disabled');
                $('#btn_search').text('Please Wait...');
            },
            success: function(data) {
                console.log(data);
                $('#Description').val('');
                $('#descid').val('');
                $('#DescAction').val('Save');
                desc_lists(ModalValue);
                $('#btn_search').attr('disabled', false);
                $('#btn_search').text('Add');
            }
        });
    }
}

$(document).ready(function() {
    function load_data(query) {
        var action = 'search';
        var ModalValue = $('#ModalValue').val();
        $.ajax({
            url: "<?php echo e(url('getDescList')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                srquery: query,
                ModalValue: ModalValue
            },
           
            success: function(data) {
                console.log(data);
                $('#tableresult').html(data);

            }
        });
    }
    $('#search_text77').keyup(function() {

        var search = $(this).val();
        if (search != '') {
            load_data(search);
        } else {
            load_data();
           
        }
    });

    $(document).on("click", ".update", function(event) {
        event.preventDefault();
        event.stopPropagation();
        var id = $(this).attr("data-id");
        var action = "fetch_record";
        $.ajax({
            url: "<?php echo e(url('updateDesc')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: id
            },
            dataType: "json",
            success: function(data) {
                //console.log(data);
                $('#Description').val(data.Description);
                $('#ModalValue').val(data.Type);
                $('#descid').val(id);
                $('#DescAction').val('Edit');
                $('#btn_search').text("Update");
                $('.modal-title').html(
                    "Update <span class='font-weight-light'>Description</span>");

            }
        });
    });

    $(document).on("click", ".delete", function(event) {
        event.preventDefault();
        var id = $(this).attr("data-id");
        var ModalValue = $('#ModalValue').val();
        var action = "delete";
        $.ajax({
            url: "<?php echo e(url('deleteDesc')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: id
            },
            success: function(data) {
                //alert(data);
                desc_lists(ModalValue);
            }
        });
    });

//     $('#modal-report').on('hidden.bs.modal', function () {
//         var ValueId = $('#ValueId').val();
//     var CurrValue = $('#'+ValueId).val();
//     var OldValue = $('#OldValue').val();
//      var ModalValue = $('#ModalValue').val();
     
//      $('#'+ValueId).val(OldValue);
//      $('#modal-report').modal("hide");
     
//      if(CurrValue==""){
//         $('#'+ValueId).val(OldValue);
        
//      }
//      else{
//        var ConcatValue =  CurrValue+"\n"+OldValue;
//         $('#'+ValueId).val(ConcatValue); 
//      }
// });

});
</script><?php /**PATH /home/gssnagpu/public_html/hospsoft.in/siddhivinaynetra/resources/views/masters/inccommonmodal.blade.php ENDPATH**/ ?>