<div class="modal fade" id="modal-report22" 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_text772" 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="tableresult2">

                </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="Description2" class="form-control"
                                        placeholder="Description" value="">
                                </div>
                                <input type="hidden" name="OldValue" id="OldValue2" value="">
                                <input type="hidden" name="ModalValue" id="ModalValue2" value="">
                                <input type="hidden" name="ValueId" id="ValueId2" value="">
                                <input type="hidden" name="id" id="descid2" value="">
                                <input type="hidden" name="action" id="DescAction2" value="Save">
                                <div class="col-md-2">
                                    <label class="form-label d-none d-md-block">&nbsp;</label>
                                    <button type="button" id="btn_search2" class="btn btn-primary btn-block"
                                        onclick="addDesc2()">Add</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
function desc_lists2(val) {
    var action = 'view';
    var ModalValue = $('#ModalValue').val();
    $.ajax({
        url: "{{ url('getDescList2') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            ModalValue: val
        },
        success: function(data) {
            //console.log(data);
            $('#tableresult2').html(data);
        }
    });
}

function addDesc2() {
    var Description = $('#Description2').val();
    var ModalValue = $('#ModalValue2').val();
    var action = $('#DescAction2').val();
    var id = $('#descid2').val()
    if (Description.trim() == '') {
        alert("Please Enter Description");
        $('#Description2').focus();
    } else {
        $.ajax({
            url: "{{ url('saveDesc') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                action: action,
                Description: Description,
                ModalValue: ModalValue,
                id: id
            },
            beforeSend: function() {
                $('#btn_search2').attr('disabled', 'disabled');
                $('#btn_search2').text('Please Wait...');
            },
            success: function(data) {
                console.log(data);
                $('#Description2').val('');
                $('#descid2').val('');
                $('#DescAction2').val('Save');
                desc_lists2(ModalValue);
                $('#btn_search2').attr('disabled', false);
                $('#btn_search2').text('Add');
            }
        });
    }
}

$(document).ready(function() {
    function load_data2(query) {
        var action = 'search';
        var ModalValue = $('#ModalValue2').val();
        $.ajax({
            url: "{{ url('getDescList2') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                srquery: query,
                ModalValue: ModalValue
            },
           
            success: function(data) {
                console.log(data);
                $('#tableresult2').html(data);

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

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

    $(document).on("click", ".update", function(event) {
        event.preventDefault();
        event.stopPropagation();
        var id = $(this).attr("data-id");
        var action = "fetch_record";
        $.ajax({
            url: "{{ url('updateDesc') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                id: id
            },
            dataType: "json",
            success: function(data) {
                //console.log(data);
                $('#Description2').val(data.Description);
                $('#ModalValue2').val(data.Type);
                $('#descid2').val(id);
                $('#DescAction2').val('Edit');
                $('#btn_search2').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 = $('#ModalValue2').val();
        var action = "delete";
        $.ajax({
            url: "{{ url('deleteDesc') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                id: id
            },
            success: function(data) {
                //alert(data);
                desc_lists2(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>