Source: pro-intake.js

$(function(){

	var initDatetimePicker = function() {
		$('#datetimepicker1').datetimepicker();
		$('#datetimepicker2').datetimepicker();
	}
	
    /**
    * This function handles button click to open probation intake form
    */
    $(document).on('click', '.js-probation-intake', function() {
        var id = $(this).data('id');
        if(id != null) {

            var pageURL = base_url + "staff/probation/show-intake-form/" +id ;
            var pageTitle = "iCourtApp::Probation";        
            var myWindow = newWindow.createPopupWin(pageURL, pageTitle, 800, 'auto');

        }
        else {

            var pageURL = base_url + "staff/probation/show-intake-form" ;
            var pageTitle = "iCourtApp::Probation";        
            var myWindow = newWindow.createPopupWin(pageURL, pageTitle, 800, 'auto');
        
        }
    });


    /**
    * This function handles button click to open fair intake form
    */
    $(document).on('click', '.js-fair-intake', function() {
       

            var pageURL = base_url + "staff/probation/show-fair-form" ;
            var pageTitle = "iCourtApp::Probation";        
            var myWindow = newWindow.createPopupWin(pageURL, pageTitle, 800, 'auto');
        
    });

    /**
    * This function handles button click to open e-intake form
    */
    $(document).on('click', '.js-e-intake', function() {
        var id = $(this).data('id');
        if(id != null) {
            var pageURL = base_url + "staff/probation/show-e-form/"+id ;
            var pageTitle = "iCourtApp::Probation";        
            var myWindow = newWindow.createPopupWin(pageURL, pageTitle, 875, 'auto');
        }else{
            var pageURL = base_url + "staff/probation/show-e-form" ;
            var pageTitle = "iCourtApp::Probation";        
            var myWindow = newWindow.createPopupWin(pageURL, pageTitle, 875, 'auto');
        }
    
});


    /**
    * This function handles button click to delete probation intake form from table
    */
    $(document).on('click', '.js-delete-pro-intake-form', function() {
        var answer = confirm('Are you sure you want to delete?')
        if(answer == true) {
            var id = $(this).data('id')
            var _this = $(this)
            $.get(base_url + "staff/probation/request-prointake-form-delete/"+id, function(data) {
                var msg = atob(data.message)
                switch(data.status){
                    case "delete":
                        $.get(base_url + "staff/probation/intake-control", function (data) {
                            $("#probation_section").empty();
                            $("#probation_section").append(data);
                            $("#new_probation_message").append(msg);
                        });
                    break;
                    case "error":
                        // lawa
                        $.get(base_url + "staff/probation/intake-control", function (data) {
                            $("#probation_section").empty();
                            $("#probation_section").append(data);
                            $("#new_probation_message").append(msg);
                        });
                    break;
                }
            })
        }
    });


/**
* This function handles button click to delete fair intake form from table
*/
$(document).on('click', '.js-delete-fair-form', function() {
    var answer = confirm('Are you sure you want to delete?')
    if(answer == true) {
        var id = $(this).data('id')
        var _this = $(this)
        $.get(base_url + "staff/probation/request-fair-form-delete/"+id, function(data) {
            var msg = atob(data.message)
            switch(data.status){
                case "delete":
                    $.get(base_url + "staff/probation/fair-control", function (data) {
                        $("#probation_section").empty();
                        $("#probation_section").append(data);
                        $("#new_probation_message").append(msg);
                    });
                break;
                case "error":
                    // lawa
                    $.get(base_url + "staff/probation/fair-control", function (data) {
                        $("#probation_section").empty();
                        $("#probation_section").append(data);
                        $("#new_probation_message").append(msg);
                    });
                break;
            }
        })
    }
});

/**
* This function handles button click to delete e-intake form from table
*/
$(document).on('click', '.js-delete-e-form', function() {
    var answer = confirm('Are you sure you want to delete?')
    if(answer == true) {
        var id = $(this).data('id')
        var _this = $(this)
        $.get(base_url + "staff/probation/request-e-form-delete/"+id, function(data) {
            var msg = atob(data.message)
            switch(data.status){
                case "delete":
                    $.get(base_url + "staff/probation/e-control", function (data) {
                        $("#probation_section").empty();
                        $("#probation_section").append(data);
                        $("#new_probation_message").append(msg);
                    });
                break;
                case "error":
                    // lawa
                    $.get(base_url + "staff/probation/e-control", function (data) {
                        $("#probation_section").empty();
                        $("#probation_section").append(data);
                        $("#new_probation_message").append(msg);
                    });
                break;
            }
        })
    }
});
})


/**
* This function handles submit button of probation intake form and adds the data to the table
*/
var proIntakeAction = {
    submit: function() {
        $.get(base_url + "staff/probation/intake-control", function (data) {
            $('.new-tab-wrap').find('.active').removeClass('active')
            $('#myTabContent').find('.show.active').removeClass('show active')
            $('#new-probation-tab').parent('li').show()
            $('#new-probation-tab').text('Probation')
            $('#new-probation-tab').addClass('active')
            $('#new-probation').addClass('show active')
            $("#probation_section").empty();
            $("#probation_section").append(data);
            $('#probation-form').hide();
            // initDatepicker();


        });
    }
}

/**
* This function handles submit button of fair intake form and adds the data to the table
*/
var fairIntakeAction = {
    submit: function() {
        $.get(base_url + "staff/probation/fair-control", function (data) {
            $('.new-tab-wrap').find('.active').removeClass('active')
            $('#myTabContent').find('.show.active').removeClass('show active')
            $('#new-probation-tab').parent('li').show()
            $('#new-probation-tab').text('Probation')
            $('#new-probation-tab').addClass('active')
            $('#new-probation').addClass('show active')
            $("#probation_section").empty();
            $("#probation_section").append(data);
            $('#probation-form').hide();
            // initDatepicker();


        });
    }
}

/**
* This function handles submit button of e-intake form and adds the data to the table
*/
var eIntakeAction = {
    submit: function() {
        $.get(base_url + "staff/probation/e-control", function (data) {
            $('.new-tab-wrap').find('.active').removeClass('active')
            $('#myTabContent').find('.show.active').removeClass('show active')
            $('#new-probation-tab').parent('li').show()
            $('#new-probation-tab').text('Probation')
            $('#new-probation-tab').addClass('active')
            $('#new-probation').addClass('show active')
            $("#probation_section").empty();
            $("#probation_section").append(data);
            $('#probation-form').hide();
            // initDatepicker();


        });
    }
}