/**
 * Created by IOAN on 10/6/2015.
 */
$(document).ready(function(){

    $('.delete-job').on('click', function(e) {
        e.preventDefault();
        var post_data = {
            'csurl': encodeURIComponent(full_uri + "amodules/jobsresumes/ajax/job_actions.php"),
            'job_jobs_id':$(this).data('jid'),
            'chcAction': 'Delete'
        };

        BootstrapDialog.confirm('Do you really want to delete this job?', function(result){
            if(result) {
                $.ajax({
                    url: baseurl + '/proxy.php',
                    data: post_data,
                    type: 'post',
                    dataType: 'json',
                    cache: false,
                    success: function(r) {
                        if(r.result == 1) {
                            if(r.hasOwnProperty('flashm')) {
                                $.post(baseurl + '/flashm.php', {'flashm': r.flashm});
                            }
                            window.redirectLink = r.link;
                            window.setTimeout(function(){
                                var rlink = window.redirectLink;
                                delete(window.redirectLink);
                                document.location.href = rlink;
                            }, 200);
                        }
                    }
                });
            }

        });
    });

    $('.status-action').removeClass('hidden');

    $('.job-status').on('click', function(e){
        e.preventDefault();

        var $button = $(this);
        var job_jobs_id = $(this).data('jid');
        var job_status = $(this).data('job_status');
        var $parent = $(this).closest('.job-footer');
        var $job_stat = $('.job-stat', $parent);

        var post_data = {
            'csurl': encodeURIComponent(full_uri + "amodules/jobsresumes/ajax/job_actions.php"),
            'job_jobs_id':job_jobs_id,
            'job_status': 1-job_status,
            'chcAction': 'Status'
        };

        $.ajax({
            url: baseurl + '/proxy.php',
            data: post_data,
            type: 'post',
            dataType: 'json',
            cache: false,
            success: function(r) {
                if(r.result == 1) {
                    if(job_status == 1) {
                        $job_stat.text('Inactive');
                        $button.text('Activate');
                        $job_stat.removeClass('label-success').addClass('label-danger');
                        $button.data('job_status', 0);
                    }

                    if(job_status == 0) {
                        $job_stat.text('Active');
                        $button.text('Inactivate');
                        $job_stat.removeClass('label-danger').addClass('label-success');
                        $button.data('job_status', 1);
                    }
                }
            }
        });



    });

});