@extends('admin.sub_contents.base')
@section('main')

@foreach($resarch as $row)
<div class="single_glance_row mt-4 single_edit_item">
    <div style="display: flex;">
        <div class="left" style="width: 80%;">
            <span class="title" style="font-size:11px;">{{$row->research}}</span>
        </div>
        <div class="right" style="width: 20%;">
            <span class="title" style="font-size:11px; font-weight: 600;">
                <button type="button" class="btn btn2 edit_research mb-1" data-id="{{$row->id}}" style="padding: 2px 5px !important; font-size: 11px;"><i class="fa fa-pencil"></i></button>

            </span>
            <span class="title" style="font-size:11px; font-weight: 600;">
                <button type="button" class="btn btn2 delete_research mb-1" data-id="{{$row->id}}" style="padding: 2px 5px !important; font-size: 11px;"><i class="fa fa-trash" style="margin-left:2px;"></i></button>
            </span>
        </div>

    </div>
</div>

@endforeach

@endsection


<script>
    $(function(){

        var form_row_added=false;

        $('.edit_research').on('click', function(){
            if(form_row_added){
                $('.open_research_info_div').remove();
                form_row_added=false;
            }
            var self=$(this);
            var self_tr=self.closest('.single_edit_item');

            var res_id=self.data('id');

            form_row_added=true;

            self_tr.after(
             "<div class='open_research_info_div'><div class='open_research_edit_info_div_inner'></div></div>"
            );

            fetch_sub_content(
                '.open_research_edit_info_div_inner',
                "{{ route('sub-content', ['name'=>'edit_research_form']) }}?res_id="+res_id
            );

        });

        $('.delete_research').on('click', function(){
            var id = $(this).attr("data-id");
            var form_data={
                _token: "{{ csrf_token() }}",
                delete_id: id,
            }
            swal({
                title: "Are you sure?",
                text: "You will not be able to recover this data!",
                type: "warning",
                showCancelButton: true,
                confirmButtonClass: "btn-danger",
                cancelButtonClass: "btn-info",
                confirmButtonText: "Yes, delete!",
                cancelButtonText: "No, cancel!",

            }, function(isConfirm){

                if(isConfirm){
                    $.post("{{ route('ajax-post', ['name'=>'delete_research_info']) }}",form_data
                    ).done(function(res){

                        pop_up_msg(res.msg);

                        $('#load_department').empty();
                        fetch_sub_content(
                            '#load_research_interest',
                            "{{ route('sub-content', ['name'=>'load_research_interest']) }}"
                        );

                    }).fail(function(err){
                        pop_up_msg(err_msg(err), 'error');
                    });
                }
            });

        });
    });
</script>
