Source: public-defender.js

$(function(){ 

    /**
    * This function handles submit button of plea form
    */
    $(document).on("click", "#defender_response_submit", function() {   
      
        $.post($("#defender_response_form").attr('action'), $("#defender_response_form").serialize(), function(data) {
            if(data.status.localeCompare("success")==0){
                var responseMsg = atob(data.message);
                
                $.get(base_url + "staff/plea/show-form", function(data) {
                    $('.new-tab-wrap').find('.active').removeClass('active')
                    $('#myTabContent').find('.show.active').removeClass('show active')
                    $('#new-plea-tab').parent('li').show()
                    $('#new-plea-tab').text('Plea')
                    $('#new-plea-tab').addClass('active')
                    $('#new-plea').addClass('show active')
                    $("#plea_section").empty();
                    $("#plea_section").append(data);
                    $('#plea_msg').html(responseMsg);
                    $('#plea-form').hide()
                    if($('#plea-form').is(':hidden')){
                        $('#plea-show').show()
                   }
                });
            }
            else if(data.status.localeCompare("validation_failed") ==0){
                var pleaerror = atob(data.pleatype);
                var noterror = atob(data.note);
                $("#ple_error").html(atob(data.pleatype));
                $("#note_error").html(atob(data.note));
            }
        }, 'json');
    return false;
    });

    /**
    * This function handles button click to open plea form
    */
    $(document).on('click', '.js-change-plea', function() {
        $('#plea_msg').html('');

            $.get(base_url + "staff/plea/show-form", function(data) { 
                $('.new-tab-wrap').find('.active').removeClass('active')
                $('#myTabContent').find('.show.active').removeClass('show active')
                $('#new-plea-tab').parent('li').show()
                $('#new-plea-tab').text('Plea')
                $('#new-plea-tab').addClass('active')
                $('#new-plea').addClass('show active')
                $("#plea_section").empty();
                $("#plea_section").append(data);
                $('#plea-show').hide()
                if($('#plea-show').is(':hidden')){
                    $('#plea-form').show()
               }
            });

            // document.querySelector('.queue-page').scrollIntoView({ behavior: 'smooth' });
        
    });
})

/**
* This function handles submit button of plea form and adds the data to the table
*/
var newPleAction = {
    submit: function(){
        $.get(base_url + "staff/plea/load-plea", function(data) { 
            $('.new-tab-wrap').find('.active').removeClass('active')
            $('#myTabContent').find('.show.active').removeClass('show active')
            $('#new-plea-tab').parent('li').show()
            $('#new-plea-tab').text('Plea')
            $('#new-plea-tab').addClass('active')
            $('#new-plea').addClass('show active')
            $("#plea_section").empty();
            $("#plea_section").append(data);
            $('#plea-show').show()
           
        });
    }
}