Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16929 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
$currentUser    = $this->currentUserHelper();
$roleName       = $currentUser->getUserTypeId();

$routeIndex = $this->url('recruitment-and-selection/interview/form');
$routeAdd = $this->url('recruitment-and-selection/interview/form/add', ['vacancy_uuid' => 'UUID_PLACEHOLDER']);
$routeVacancy = $this->url('recruitment-and-selection/interview/vacancy', ['vacancy_uuid' => 'UUID_PLACEHOLDER']);
$routeType = $this->url('recruitment-and-selection/interview/type', ['candidate_uuid' => 'UUID_PLACEHOLDER']);

$allowAdd = $acl->isAllowed($roleName, 'recruitment-and-selection/interview/form/add') ? 1 : 0;
$allowEdit = $acl->isAllowed($roleName, 'recruitment-and-selection/interview/form/edit') ? 1 : 0;
$allowDelete = $acl->isAllowed($roleName, 'recruitment-and-selection/interview/form/delete') ? 1 : 0;
$allowReport = $acl->isAllowed($roleName, 'recruitment-and-selection/interview/report') ? 1 : 0;
$allowFile = $acl->isAllowed($roleName, 'recruitment-and-selection/interview/file') ? 1 : 0;
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));





$this->inlineScript()->appendFile($this->basePath('assets/vendors/ckeditor/ckeditor.js'));




$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.css'));
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.css'));

$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.js'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/dataTables.responsive.min.js'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.min.js'));





$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));




$this->inlineScript()->appendFile($this->basePath('assets/vendors/moment/moment-with-locales.min.js'));
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'));


$this->inlineScript()->appendFile($this->basePath('assets/vendors/select2/js/select2.js'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/select2/js/i18n/es.js'));
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/select2/css/select2.css'));

$this->headLink()->appendStylesheet($this->basePath('assets/vendors/select2-bootstrap5-theme/select2-bootstrap-5-theme.css'));

// JsRender //
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jsrender/jsrender.min.js'));

$status_acepted = \LeadersLinked\Model\RecruitmentSelectionInterview::STATUS_ACCEPTED;
$status_rejected = \LeadersLinked\Model\RecruitmentSelectionInterview::STATUS_REJECTED;

$points_0 = \LeadersLinked\Model\RecruitmentSelectionInterview::POINTS_0;
$points_1 = \LeadersLinked\Model\RecruitmentSelectionInterview::POINTS_1;
$points_2 = \LeadersLinked\Model\RecruitmentSelectionInterview::POINTS_2;
$points_3 = \LeadersLinked\Model\RecruitmentSelectionInterview::POINTS_3;
$points_4 = \LeadersLinked\Model\RecruitmentSelectionInterview::POINTS_4;



$this->headStyle()->captureStart();
echo <<<CSS

CSS;
$this->headStyle()->captureEnd();

$this->inlineScript()->captureStart();
echo <<<JS

jQuery( document ).ready(function( $ ) {
    var allowDelete = $allowDelete;
    var allowEdit = $allowEdit;
    var allowReport = $allowReport;
    var allowFile = $allowFile;
    $.validator.setDefaults({
        debug: true,
        highlight: function(element) {
            $(element).addClass('is-invalid');
        },
        unhighlight: function(element) {
            $(element).removeClass('is-invalid');
        },
        errorElement: 'span',
        errorClass: 'error invalid-feedback',
        errorPlacement: function(error, element) {
            if(element.parent('.btn-file').length) {
                error.insertAfter(element.parent().parent());
            } else if(element.parent('.toggle').length) {
                error.insertAfter(element.parent().parent());
            } else {
                error.insertAfter(element.parent());
            }
        }
    });


    var gridTable = $('#gridTable').dataTable({
        'processing': true,
        'serverSide': true,
        'searching': true,
        'order': [
            [0, 'asc']
        ],
        'ordering': true,
        'ordenable': true,
        'responsive': true,
        'select': false,
        'paging': true,
        'pagingType': 'simple_numbers',
        'ajax': {
            'url': '$routeIndex',
            'type': 'get',
            'beforeSend': function(request) {
                NProgress.start();
            },
            'dataFilter': function(response) {
                var response = jQuery.parseJSON(response);
                var json = {};
                json.recordsTotal = 0;
                json.recordsFiltered = 0;
                json.data = [];
                if (response.success) {
                    json.recordsTotal = response.data.total;
                    json.recordsFiltered = response.data.total;
                    json.data = response.data.items;
                } else {
                    $.fn.showError(response.data)
                }
                return JSON.stringify(json);
                gridTable.api().ajax.reload(null, false);
            }
        },
        'language': {
            'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
            'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
            'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
            'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
            'sInfo': 'LABEL_DATATABLE_SINFO',
            'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
            'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
            'sInfoPostFix': '',
            'sSearch': 'LABEL_DATATABLE_SSEARCH',
            'sUrl': '',
            'sInfoThousands': ',',
            'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
            'oPaginate': {
                'sFirst': 'LABEL_DATATABLE_SFIRST',
                'sLast': 'LABEL_DATATABLE_SLAST',
                'sNext': 'LABEL_DATATABLE_SNEXT',
                'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
            },
            'oAria': {
                'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
                'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
            },
        },
        'drawCallback': function(settings) {
            NProgress.done();
           
        },
        'aoColumns': [
            {
                'mDataProp': function(data, type, row) {
                    return data.first_name + ' ' + data.last_name
                }
            },
            {
                'mDataProp': 'email'
            },
            {
                'mDataProp': function(data, type, row){ 
                    switch(data.type) {
                        case 'r':
                            return 'LABEL_HUMAN_RESOURCE'  
                        case 'b':
                            return 'LABEL_BOSS_INTERVIEW'
                        default:
                            return data.type
                    }
                }
            },
            {
                'mDataProp': 'vacancy'
            },
            {
                'mDataProp': function(data, type, row){ 
                    switch(data.points) {
                        case '0':
                            return 'LABEL_ANOTHER'
                        case '':
                            return 'LABEL_ANOTHER'   
                        case '1':
                            return '25%'
                        case '2':
                            return '50%'
                        case '3':
                            return '75%'
                        case '4':
                            return '100%'
                        default:
                            return data.points
                    }
                }
            },
            {
                'mDataProp': 'actions'
            },
        ],
        'columnDefs': [
            {
                'targets': 0,
                'className': 'text-vertical-middle',
            },
           
            {
                'targets': -1,
                'orderable': false,
                'render': function(data, type, row) {
                   
                    
                    s = '';
                    
                    if (allowEdit) {
                        s = s + '<button class="btn btn-info btn-sm btn-edit" data-href="' + data['link_edit'] + '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pen"></i> LABEL_EDIT </button>&nbsp;';
                    }
                    if (allowFile && data['link_file']) {
                        s = s + '<button class="btn btn-info btn-sm btn-evaluation" id="btn-file" data-href="' + data['link_file']+ '" data-toggle="tooltip" title="LABEL_EVALUATION"><i class="fa fa-external-link-alt"></i> LABEL_EVALUATION </button>&nbsp;';
                    }                    
                    if (allowDelete) {
                        s = s + '<button class="btn btn-danger btn-sm btn-delete" data-href="' + data['link_delete'] + '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
                    }
                    if (allowReport) {
                        s = s + '<a class="btn btn-info btn-sm btn-pdf" href="' + data['link_report'] + '" target="_blank" data-toggle="tooltip" title="LABEL_PDF"><i class="fa fa-file-o"></i> LABEL_PDF </button>&nbsp;';
                    }
                    return s;
                }
            }
        ],
    });

    function getContent() {
        return $('[data-competency-behavior]').map(
            function (idx, td) {
                const competencyUuid = $(td).data('competency-uuid');
                const behaviorUuid = $(td).data('behavior-uuid');
                const textarea = $(td).find('textarea');
                const select = $(td).find('select');

                return {
                    competencyUuid: competencyUuid,
                    behaviorUuid : behaviorUuid,
                    comment: textarea.val(),
                    evaluation: select.val(),
                }
            }
        ).get()
    }


    $('body').on('click', 'button.btn-evaluation', function(e) {
        e.preventDefault();
        NProgress.start();
        var action = $(this).data('href');
        window.location.href = action;
    });


    var validator = $('#form-interview').validate({
        debug: true,
        onclick: false,
        onkeyup: false,
        ignore: [],
        rules: {},
        submitHandler: function(form) {
            $.ajax({
                'dataType': 'json',
                'accept': 'application/json',
                'method': 'post',
                'url': $('#form-interview').attr('action').replaceAll('UUID_PLACEHOLDER', $('#vacancy_uuid').val()),
                'data': {
                    content: JSON.stringify(getContent()),
                    candidate_uuid: $('#candidate_uuid').val(),
                    points: $('#points').val(),
                    comment: $('#comment').val(),
                    status: $('#status').val(),
                }
            }).done(function(response) {
                NProgress.start();
                if (response['success']) {
                    $.fn.showSuccess(response['data']);
                    $('#main').hide();
                    $('#interview').hide();
                    gridTable.api().ajax.reload(null, false);
                } else {
                    validator.resetForm();
                    if (jQuery.type(response['data']) == 'string') {
                        $.fn.showError(response['data']);
                    } else {
                        $.each(response['data'], function(fieldname, errors) {
                            $.fn.showFormErrorValidator('#interview #' + fieldname, errors);
                        });
                    }
                }
            }).fail(function(jqXHR, textStatus, errorThrown) {
                $.fn.showError(textStatus);
            }).always(function() {
                NProgress.done();
            });
            return false;
        },
        invalidHandler: function(form, validator) {}
    });

    $('body').on('click', 'button.btn-add', function(e) {
        $('#form-interview').attr('action', "$routeAdd")
        $('#candidate_uuid').prop('disabled', false);
        $('#vacancy_uuid').prop('disabled', false);
        $('#vacancy_uuid').change();
        $('#filter_vacancy_uuid').change();
        
        e.preventDefault();

        NProgress.start();
        $.ajax({
            'dataType': 'json',
            'accept': 'application/json',
            'method': 'get',
            'url': $(this).data('url'),
        }).done(function(response) {
            if (response['success']) {
                var data = response.data
                $("#form-interview #comment").val('');
                $('#form-interview #status').val('$status_acepted');
                $("#form-interview #points").val('$points_0');
                $("#content").hide();
                $("#main").show();
                validator.resetForm();
                $('#custom-tabs #custom-tabs-general-tab').tab('show');
                $('#candidate_uuid').change();
                $('#interview').show();
            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });
    });

    $('body').on('click', 'button.btn-edit', function(e) {
        var url = $(this).data('href');
        e.preventDefault();
        NProgress.start();
        $.ajax({
            'dataType': 'json',
            'accept': 'application/json',
            'method': 'get',
            'url': url,
        }).done(function(response) {
            if (response['success']) {
                var data = response.data
                $('#vacancy_uuid').val(data['vacancy']['uuid']);
                $('#vacancy_uuid').prop('disabled', true);
                $('#candidate_uuid').html('');
                var option = $('<option />')
                    .val(data['candidate']['uuid'])
                    .text(data['candidate']['first_name'] + ' ' + data['candidate']['last_name']);
                $('#candidate_uuid').append(option).prop('disabled', true);
                $("#form-interview #comment").val(data['interview']['comment']);
                $('#form-interview #status').val(data['interview']['status']);
                $("#form-interview #points").val(data['interview']['points']);
                $("#competencies-job").html($("#competenciesTemplate").render(data))
                data.interview.content.forEach(obj => {
                    $('#textarea-' + obj.competencyUuid + '-' + obj.behaviorUuid).val(obj.comment);
                    $('#select-' + obj.competencyUuid + '-' + obj.behaviorUuid).val(obj.evaluation);
                })
                $("#form-interview").attr('action', url)
                $("#content").hide();
                $("#main").show()
            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });
    });

     $('body').on('click', 'button.btn-delete', function(e) { 
        e.preventDefault();
        var action = $(this).data('href');


          swal.fire({
            title: 'LABEL_ARE_YOU_SURE',
            icon: 'question',
            cancelButtonText: 'LABEL_NO',
            showCancelButton: true,
            confirmButtonText: 'LABEL_YES'
          }).then((result) => {
            if (result.isConfirmed) {

                    NProgress.start();
                    $.ajax({
                        'dataType'  : 'json',
                        'accept'    : 'application/json',
                        'method'    : 'post',
                        'url'       :  action,
                    }).done(function(response) {
                        if(response['success']) {
                            $.fn.showSuccess(response['data']);
                            gridTable.api().ajax.reload(null, false);
                        } else {
                            $.fn.showError(response['data']);
                        }
                    }).fail(function( jqXHR, textStatus, errorThrown) {
                        $.fn.showError(textStatus);
                    }).always(function() {
                        NProgress.done();
                    });
            }
       });
    });


    $('#filter_vacancy_uuid').change(function (e) {
        e.preventDefault();

        var uuid = e.target.value;

        gridTable.api().ajax.url("$routeIndex" + "/" + uuid);
        gridTable.api().ajax.reload(null, false);
    })

    $('body').on('click', 'button.btn-cancel', function(e) {
        e.preventDefault();
        $('#main').show();
        $('#row-form').hide();
        $('#div-listing').show();
    });

    $('#form-filter #filter_vacancy_uuid').change(function(e) {
        e.preventDefault();
        gridTable.api().ajax.reload(null, false);
    })

     /**
     * Clicked cancel new/edit Form
     */
    $('button.btn-edit-cancel').click(function(e) {
        e.preventDefault();
        $("#content").show();
        $("#main").hide();
    });
    /**
     * Clicked save and continue new Form
     */
    $('button.btn-form-save-continue').click(function(e) {
        e.preventDefault();
        $('#form-interview #form-continue').val('1')
        $('#form-interview').submit();
    });
    /**
     * Clicked save and close new/edit Form
     */
    $('button.btn-form-save-close').click(function(e) {
        e.preventDefault();
        $('#form-interview #form-continue').val('0')
        $("#content").show();
        $("#main").hide();
        $('#form-interview').submit();
        gridTable.api().ajax.reload(null, false);
    });

    $('#vacancy_uuid').on('change', function (event) {
       
        $('#candidate_uuid').html('');
        var uuid = event.target.value;

        $.ajax({
            'dataType': 'json',
            'accept': 'application/json',
            'method': 'get',
            'url':  String('$routeVacancy').replaceAll('UUID_PLACEHOLDER', uuid),
        }).done(function (response) {
            var data = response.data
            $('#candidate_uuid').change();
            $('#job-description').html($('#job-description-template').render(data));
            $("#competencies-job").html($("#competenciesTemplate").render(data))
            data.candidates.forEach(function (candidate) {
                var option = $('<option />')
                    .val(candidate.uuid)
                    .text(candidate.first_name)
                    .data('addUrl', candidate.add_url)
                    .data('editUrl', candidate.edit_url)
                    .data('deleteUrl', candidate.delete_url)
                    .data('reportUrl', candidate.report_url)

                $('#candidate_uuid').append(option);
            });
        })
       
    });

    $('#candidate_uuid').on('change', function(event){

        var uuid = event.target.value;

        $.ajax({
            'dataType' : 'json',
            'accept' : 'aplication/json',
            'method' : 'get',
            'url': String('$routeType').replaceAll('UUID_PLACEHOLDER', uuid),
        }).done(function (response) {
            $('#interview').html(response.data);
        })
    })

   $('#vacancy_uuid').change();
   $('#candidate_uuid').change();
   $('#filter_vacancy_uuid').change();

});
JS;
$this->inlineScript()->captureEnd();

$jsonVacancies = json_encode($vacancies);

$js = <<<JS
        const backendVariables= {
        add_link: "$routeAdd",
        table_link: "$routeIndex",
        type_link: "$routeType",
        vacancy_link: "$routeVacancy",
        vacancies: $jsonVacancies,
        permisions: {
            allowAdd: $allowAdd,
            allowEdit: $allowEdit,
            allowDelete: $allowDelete,
            allowReport: $allowReport,
            allowFile: $allowFile
        }
        }       
JS;

$this->inlineScript()->appendScript($js);
$this->inlineScript()->appendFile('/react-bundles/recruitment_and_selection/interviews/interviewsBundle.js');
?>


<!-- Content Header (Page header) -->
<div id="recruitment_and_selection-interview">
</div>