Proyectos de Subversion LeadersLinked - Backend

Rev

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

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

$roleName = $currentUser->getUserTypeId();

$routeDatatable     = $this->url('recruitment-and-selection/applications');
$routeUserByEmail   = $this->url('recruitment-and-selection/applications/user-by-email');

$allowAdd           = $acl->isAllowed($roleName, 'recruitment-and-selection/applications/add') ? 1 : 0;
$allowDelete        = $acl->isAllowed($roleName, 'recruitment-and-selection/applications/delete') ? 1 : 0;
$allowView          = $acl->isAllowed($roleName, 'recruitment-and-selection/applications/view') ? 1 : 0;
$allowUserByEmail   = $acl->isAllowed($roleName, 'recruitment-and-selection/applications/user-by-email') ? 1 : 0;
$allowLevel         = $acl->isAllowed($roleName, 'recruitment-and-selection/applications/level') ? 1 : 0;
$allowStatus        = $acl->isAllowed($roleName, 'recruitment-and-selection/applications/status') ? 1 : 0;
$allowComment       = $acl->isAllowed($roleName, 'recruitment-and-selection/applications/comment') ? 1 : 0;

$allowFileAdd       = $acl->isAllowed($roleName, 'recruitment-and-selection/applications/files/add') ? 1 : 0;
$allowInterviewAdd  = $acl->isAllowed($roleName, 'recruitment-and-selection/applications/interviews/add') ? 1 : 0;



$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.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/bootstrap-fileinput/css/fileinput.min.css'));
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap-fileinput/themes/explorer-fa/theme.css'));

$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/plugins/piexif.js'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/plugins/sortable.js'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/fileinput.js'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/locales/es.js'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/themes/fa/theme.js'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/themes/explorer-fa/theme.js'));


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

$this->inlineScript()->appendFile($this->basePath('assets/vendors/select2/js/select2.full.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->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/jquery-input-number/input-number-format.jquery.js'));

// bootbox Alert //


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

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


$this->inlineScript()->captureStart();
echo <<<JS
jQuery(document).ready(function($) {

    var allowDelete   = $allowDelete  ;
    var allowView   = $allowView  ;
    

    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': '$routeDatatable',
            'type': 'get',
            'data': function(d) {
                d.vacancy_id = $('#form-filter #vacancy_id').val();
            },
            '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) {
                   

                    $('#form-add').attr('action', response.data.link_add);
                    if(response.data.link_add.length == 0) {
                        $('btn.btn-add').hide();
                    } else {
                        $('btn.btn-add').show();
                    }


                    json.recordsTotal = response.data.total;
                    json.recordsFiltered = response.data.total;
                    json.data = response.data.items;
                } else {
                    $('btn.btn-add').hide();
                    $.fn.showError(response.data)
                }
                return JSON.stringify(json);
            }
        },
        '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': 'first_name' },
                { 'mDataProp': 'last_name' },
                { 'mDataProp': 'email' },
                { 'mDataProp': 'status' },
                { 'mDataProp': 'level' },
                { 'mDataProp': 'actions' },
            ],
        'columnDefs': [
            {
                'targets': -1,
                'orderable': false,
                'render': function(data, type, row) {
                    s = '';
                    if (allowView) {
                        s = s + '<button class="btn btn-primary btn-view" data-href="' + data['link_view'] + '" data-toggle="tooltip" title="LABEL_VIEW"><i class="fa fa-external-link-alt"></i> LABEL_VIEW </button>&nbsp;';
                    }
                    if (allowDelete) {
                        s = s + '<button class="btn btn-danger btn-delete" data-href="' + data['link_delete'] + '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
                    }
                   
                    return s;
                }
            }
        ],
    });

    var validatorAdd = $('#form-add').validate({
            debug: true,
            onclick: false,
            onkeyup: false,
            ignore: [],
            rules: {
                'email': {
                    required: true,
                    maxlength: 250,
                    email: true,
                },
                'first_name': {
                    required: true,
                    maxlength: 128,
                },
                'last_name': {
                    required: true,
                    maxlength: 128,
                },
            },
            submitHandler: function(form)
            {
               $.ajax({
                    'dataType'  : 'json',
                    'accept'    : 'application/json',
                    'method'    : 'post',
                    'url'       :  $('#form-add').attr('action'),
                    'data'      :  $('#form-add').serialize()
                }).done(function(response) {
                    NProgress.start();
                    if(response['success']) {
                        $.fn.showSuccess(response['data']);
                        
                        $('#modal-add-application').modal('hide');

                        
                        gridTable.api().ajax.reload(null, false);
                    } else {
                        validatorAdd.resetForm();
                        if(jQuery.type(response['data']) == 'string') {
                            $.fn.showError(response['data']);
                        } else  {
                            $.each(response['data'], function( fieldname, errors ) {
                                $.fn.showFormErrorValidator('#form-add #' + fieldname, errors);
                            });
                        }
                    }
                }).fail(function( jqXHR, textStatus, errorThrown) {
                    $.fn.showError(textStatus);
                }).always(function() {
                    NProgress.done();

                });
                return false;

            },
            invalidHandler: function(form, validator) {

                return false;
            }
        });
    



    var validatorFile = $('#form-file').validate({
            debug: true,
            onclick: false,
            onkeyup: false,
            ignore: [],
            rules: {
                
                'name': {
                    required: true,
                    maxlength: 128,
                },
                'file': {
                    required: true,
                    extension: 'pdf|doc|docx',

                },
            },
            submitHandler: function(form)
            {
                var formdata = false;
                if (window.FormData){
                    formdata = new FormData(form); //form[0]);
                }


               $.ajax({
                    'dataType'  : 'json',
                    'accept'    : 'application/json',
                    'method'    : 'post',
                    'url'       :  $('#form-file').attr('action'),
                    'data'      :  formdata ? formdata : $('#form-file').serialize(),
                    'processData' : false,
                    'contentType' : false,
                }).done(function(response) {
                    NProgress.start();
                    if(response['success']) {
                        $.fn.showSuccess(response['data']['message']);
                        $('#fileTable tbody').html(
                            $('#fileTemplate').render( response['data']['files'] )
                        );
                        
                        $('#modal-add-file').modal('hide');


                    } else {
                        validatorFile.resetForm();
                        if(jQuery.type(response['data']) == 'string') {
                            $.fn.showError(response['data']);
                        } else  {
                            $.each(response['data'], function( fieldname, errors ) {
                                $.fn.showFormErrorValidator('#form-file #' + fieldname, errors);
                            });
                        }
                    }
                }).fail(function( jqXHR, textStatus, errorThrown) {
                    $.fn.showError(textStatus);
                }).always(function() {
                    NProgress.done();

                });
                return false;

            },
            invalidHandler: function(form, validator) {

                return false;
            }
        });

       var validatorStatus = $('#form-status').validate({
            debug: true,
            onclick: false,
            onkeyup: false,
            ignore: [],
            rules: {
                'status': {
                    required: true,
                },
            },
            submitHandler: function(form)
            {

               $.ajax({
                    'dataType'  : 'json',
                    'accept'    : 'application/json',
                    'method'    : 'post',
                    'url'       :  $('#form-status').attr('action'),
                    'data'      :  $('#form-status').serialize(),

                }).done(function(response) {
                    NProgress.start();
                    if(response['success']) {
                        $.fn.showSuccess(response['data']['message']);

                        $('#view_application_status').html(response['data']['status']);
                        $('#modal-status').modal('hide');


                    } else {
                        validatorFile.resetForm();
                        if(jQuery.type(response['data']) == 'string') {
                            $.fn.showError(response['data']);
                        } else  {
                            $.each(response['data'], function( fieldname, errors ) {
                                $.fn.showFormErrorValidator('#form-status #' + fieldname, errors);
                            });
                        }
                    }
                }).fail(function( jqXHR, textStatus, errorThrown) {
                    $.fn.showError(textStatus);
                }).always(function() {
                    NProgress.done();

                });
                return false;

            },
            invalidHandler: function(form, validator) {

                return false;
            }
        });

       var validatorLevel = $('#form-level').validate({
            debug: true,
            onclick: false,
            onkeyup: false,
            ignore: [],
            rules: {
                'level': {
                    required: true,
                },
            },
            submitHandler: function(form)
            {

               $.ajax({
                    'dataType'  : 'json',
                    'accept'    : 'application/json',
                    'method'    : 'post',
                    'url'       :  $('#form-level').attr('action'),
                    'data'      :  $('#form-level').serialize(),

                }).done(function(response) {
                    NProgress.start();
                    if(response['success']) {
                        $.fn.showSuccess(response['data']['message']);

                        $('#view_application_level').html(response['data']['level']);
                        $('#modal-level').modal('hide');


                    } else {
                        validatorFile.resetForm();
                        if(jQuery.type(response['data']) == 'string') {
                            $.fn.showError(response['data']);
                        } else  {
                            $.each(response['data'], function( fieldname, errors ) {
                                $.fn.showFormErrorValidator('#form-level #' + fieldname, errors);
                            });
                        }
                    }
                }).fail(function( jqXHR, textStatus, errorThrown) {
                    $.fn.showError(textStatus);
                }).always(function() {
                    NProgress.done();

                });
                return false;

            },
            invalidHandler: function(form, validator) {

                return false;
            }
        });

       var validatorComment = $('#form-comment').validate({
            debug: true,
            onclick: false,
            onkeyup: false,
            ignore: [],
            rules: {
                'points': {
                    required: true,
                    min: 0,
                    max: 100,
                },
                'comment': {
                    updateCkeditor:function() {
                            CKEDITOR.instances.comment.updateElement();
                    },
                    required: false,
                },

            },
            submitHandler: function(form)
            {

               $.ajax({
                    'dataType'  : 'json',
                    'accept'    : 'application/json',
                    'method'    : 'post',
                    'url'       :  $('#form-comment').attr('action'),
                    'data'      :  $('#form-comment').serialize(),

                }).done(function(response) {
                    NProgress.start();
                    if(response['success']) {
                        $.fn.showSuccess(response['data']['message']);

                       
                        $('#view_application_points').html(response['data']['points']);
                        $('#view_application_comment').html(response['data']['comment']);

                        $('#modal-comment').modal('hide');


                    } else {
                        validatorFile.resetForm();
                        if(jQuery.type(response['data']) == 'string') {
                            $.fn.showError(response['data']);
                        } else  {
                            $.each(response['data'], function( fieldname, errors ) {
                                $.fn.showFormErrorValidator('#form-comment #' + fieldname, errors);
                            });
                        }
                    }
                }).fail(function( jqXHR, textStatus, errorThrown) {
                    $.fn.showError(textStatus);
                }).always(function() {
                    NProgress.done();

                });
                return false;

            },
            invalidHandler: function(form, validator) {

                return false;
            }
        });

    var validatorInterview = $('#form-interview').validate({
            debug: true,
            onclick: false,
            onkeyup: false,
            ignore: [],
            rules: {
                'user_id': {
                    required: true,
                },
                'type': {
                    required: true,
                },
                'last_date': {
                    required: true,
                },
         

            },
            submitHandler: function(form)
            {

               $.ajax({
                    'dataType'  : 'json',
                    'accept'    : 'application/json',
                    'method'    : 'post',
                    'url'       :  $('#form-interview').attr('action'),
                    'data'      :  $('#form-interview').serialize(),

                }).done(function(response) {
                    NProgress.start();
                    if(response['success']) {
                        $.fn.showSuccess(response['data']['message']);

                        $('#interviewTable tbody').html(
                            $('#interviewTemplate').render( response['data']['interviews'] )
                        );


                        $('#modal-interview').modal('hide');


                    } else {
                        validatorInterview.resetForm();
                        if(jQuery.type(response['data']) == 'string') {
                            $.fn.showError(response['data']);
                        } else  {
                            $.each(response['data'], function( fieldname, errors ) {
                                $.fn.showFormErrorValidator('#form-interview #' + fieldname, errors);
                            });
                        }
                    }
                }).fail(function( jqXHR, textStatus, errorThrown) {
                    $.fn.showError(textStatus);
                }).always(function() {
                    NProgress.done();

                });
                return false;

            },
            invalidHandler: function(form, validator) {

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

        });

    
    $('body').on('click', 'button.btn-refresh', function (e) {
        e.preventDefault();
        gridTable.api().ajax.reload(null, false);
        
    });

 $('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();
                    });
            }
       });
    });



    $('body').on('click', 'span.btn-search-email', function(e) {
        e.preventDefault();
        NProgress.start();


        $.ajax({
            'dataType'  : 'json',
            'accept'    : 'application/json',
            'method'    : 'get',
            'url'       : '$routeUserByEmail',
            'data'      : {
                email:  $('#form-add #email').val()
            }
        }).done(function(response) {
           
            NProgress.done();
            if(response['success']) {
                
                $('#form-add #user_id').val(response['data']['uuid']);
                $('#form-add #first_name').val(response['data']['first_name']);
                $('#form-add #last_name').val(response['data']['last_name']);
               
      
            } else {
                $('#form-add #user_id').val('');
                $('#form-add #first_name').val('');
                $('#form-add #last_name').val('');

                $.fn.showError(response['data']);
            } 
        }).fail(function( jqXHR, textStatus, errorThrown) {
        $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });
        return false;
    });







    $('body').on('click', 'button.btn-add', function (e) {
        e.preventDefault();
       
        $('#form-add #user_id').val('');
        $('#form-add #email').val('');
        $('#form-add #first_name').val('');
        $('#form-add #last_name').val('');
        validatorAdd.resetForm();        

        $('#modal-add-application').modal('show');


        


    });

    $('body').on('click', 'button.btn-cancel-modal-interview', function(e) {
        e.preventDefault();

        
        $('#modal-interview').modal('hide');

    });


    $('body').on('click', 'button.btn-cancel-modal-application', function(e) {
        e.preventDefault();


        $('#modal-add-application').modal('hide');

    });


    $('body').on('click', 'button.btn-close-application', function(e) {
        e.preventDefault();

        $('#row-view').hide();
        $('#row-list').show();
    });

    $('body').on('click', 'button.btn-view', function(e) {
        e.preventDefault();
         NProgress.start();

        
        $.ajax({
            'dataType'  : 'json',
            'accept'    : 'application/json',
            'method'    : 'get',
            'url'       : $(this).data('href'),
        }).done(function(response) {
           NProgress.done();

            $('#row-list').hide();

            $('#view_title_name').html(response['data']['vacancy']['name']);
            $('#view_title_last_date').html(response['data']['vacancy']['last_date']);
    

            $('#view_vacancy_name').html(response['data']['vacancy']['name']);
            $('#view_vacancy_last_date').html(response['data']['vacancy']['last_date']);
            $('#view_vacancy_job_description').html(response['data']['vacancy']['job_description']);
            $('#view_vacancy_industry').html(response['data']['vacancy']['industry']);
            $('#view_vacancy_job_category').html(response['data']['vacancy']['job_category']);

            $('#view_candidate_first_name').html(response['data']['application']['first_name']);
            $('#view_candidate_last_name').html(response['data']['application']['last_name']);
            $('#view_vacancy_email').html(response['data']['application']['email']);

            $('#view_application_level').html(response['data']['application']['level']);
            $('#view_application_status').html(response['data']['application']['status']);
            $('#view_application_points').html(response['data']['application']['points']);
            $('#view_application_comment').html(response['data']['application']['comment']);


            $('#form-level').attr('action', response['data']['link_level']);
            $('#form-status').attr('action', response['data']['link_status']);
            $('#form-comment').attr('action', response['data']['link_comment']);


            $('#form-file').attr('action', response['data']['link_files_add']);
            $('#fileTable').data('route', response['data']['link_files']);


            $('#form-interview').attr('action', response['data']['link_interviews_add']);
            $('#interviewTable').data('route', response['data']['link_interviews']);


            $('#fileTable tbody').html(
               $('#fileTemplate').render( response['data']['files'] )
            );

            $('#interviewTable tbody').html(
               $('#interviewTemplate').render( response['data']['interviews'] )
            );



            $('#row-view').show();


        }).fail(function( jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });
        return false;
    }); 

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

        $.ajax({
            'dataType': 'json',
            'accept': 'application/json',
            'method': 'post',
            'url': action,
        }).done(function(response) {
            if (response['success']) {
                $.fn.showSuccess(response['data']['message']);
                $('#fileTable tbody').html(
                    $('#fileTemplate').render( response['data']['files'] )
                );
            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });

    });    


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

        $.ajax({
            'dataType': 'json',
            'accept': 'application/json',
            'method': 'post',
            'url': action,
        }).done(function(response) {
            if (response['success']) {
                $.fn.showSuccess(response['data']['message']);
                $('#interviewTable tbody').html(
                    $('#interviewTemplate').render( response['data']['interviews'] )
                );
            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });

    });  

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

        $.ajax({
            'dataType': 'json',
            'accept': 'application/json',
            'method': 'get',
            'url': action,
        }).done(function(response) {
            if (response['success']) {
               
                $('#form-interview').attr('action',action);
                $('#form-interview #user_id').val(response['data']['user_id']).trigger('change');
                $('#form-interview #type').val(response['data']['type']).trigger('change');
                $('#form-interview #last_date').val(response['data']['last_date']);

                $('#modal-interview').modal('show');


            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });

    });  


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

        $('#form-interview').attr('action',action);
        $('#form-interview #user_id').val('').trigger('change');
        $('#form-interview #type').val('').trigger('change');
        $('#form-interview #last_date').val('');
        $('#modal-interview').modal('show');


    });  



    $('body').on('click', 'button.btn-change-level', function(e) {
        e.preventDefault();
        var action = $('#form-level').attr('action');

        $.ajax({
            'dataType': 'json',
            'accept': 'application/json',
            'method': 'get',
            'url': action,
        }).done(function(response) {
            if (response['success']) {
               
                $('#form-level #level').val(response['data']['level']).trigger('change');
                $('#modal-level').modal('show');


            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });

    });


    $('body').on('click', 'button.btn-change-status', function(e) {
        e.preventDefault();
        var action = $('#form-status').attr('action');

        $.ajax({
            'dataType': 'json',
            'accept': 'application/json',
            'method': 'get',
            'url': action,
        }).done(function(response) {
            if (response['success']) {
               
                $('#form-status #status').val(response['data']['status']).trigger('change');
                $('#modal-status').modal('show');


            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });

    });


    $('body').on('click', 'button.btn-change-comment', function(e) {
        e.preventDefault();
        var action = $('#form-comment').attr('action');

        $.ajax({
            'dataType': 'json',
            'accept': 'application/json',
            'method': 'get',
            'url': action,
        }).done(function(response) {
            if (response['success']) {
               

                CKEDITOR.instances.comment.setData(response['data']['comment']);
                $('#form-comment #points').val(response['data']['points']);
                $('#modal-comment').modal('show');


            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });

    });

   
    $('#form-file #file').fileinput({
        theme: 'fa',
        language: 'es',
        showUpload: false,
        dropZoneEnabled: false,
        maxFileCount: 1,
        allowedFileExtensions: ['pdf','doc','docx'],
        msgPlaceholder: '',
    });


    $('body').on('click', 'button.btn-add-file', function(e) {
        e.preventDefault();

    
        $('#form-file #name').val('');
        $('#form-file #file').fileinput('reset');
        $('#form-file #file').val('');


        validatorFile.resetForm();   
        $('#modal-add-file').modal('show');
    });

    $('body').on('click', 'button.btn-cancel-modal-file', function(e) {
        e.preventDefault();

       
         $('#modal-add-file').modal('hide');
    });

    $('body').on('click', 'button.btn-cancel-modal-comment', function(e) {
        e.preventDefault();

       
         $('#modal-comment').modal('hide');
    });

    $('body').on('click', 'button.btn-cancel-modal-level', function(e) {
        e.preventDefault();

       
         $('#modal-level').modal('hide');
    });

    $('body').on('click', 'button.btn-cancel-modal-status', function(e) {
        e.preventDefault();

       
         $('#modal-status').modal('hide');
    });

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


        NProgress.start(); 
        $.ajax({
            'dataType'  : 'json',
            'method'    : 'get',
            'url'       :  action,
        }).done(function(response) {
            if(response['success']) {
                var anchor = window.document.createElement("a");
                anchor.href = 'data:application/octet-stream;charset=utf-8;base64,' + response['data']['content'] ;
                anchor.download = response['data']['basename'];
                document.body.appendChild(anchor);
                anchor.click();  // IE: "Access is denied"; see: https://connect.microsoft.com/IE/feedback/details/797361/ie-10-treats-blob-url-as-cross-origin-and-denies-access
                document.body.removeChild(anchor);
            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function( jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });
    });

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


        NProgress.start(); 
        $.ajax({
            'dataType'  : 'json',
            'method'    : 'get',
            'url'       :  action,
        }).done(function(response) {
            if(response['success']) {
                var anchor = window.document.createElement("a");
                anchor.href = 'data:application/octet-stream;charset=utf-8;base64,' + response['data']['content'] ;
                anchor.download = response['data']['basename'];
                document.body.appendChild(anchor);
                anchor.click();  // IE: "Access is denied"; see: https://connect.microsoft.com/IE/feedback/details/797361/ie-10-treats-blob-url-as-cross-origin-and-denies-access
                document.body.removeChild(anchor);
            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function( jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });
    });

    $('#form-level #level').select2({ 
        theme: 'bootstrap-5',
        width: '100%',
        dropdownParent: $('#modal-level'),
    });
    
    $('#form-status #status').select2({ 
        theme: 'bootstrap-5',
        width: '100%',
        dropdownParent: $('#modal-status'),
    });

    
    $('#form-interview #type').select2({ 
        theme: 'bootstrap-5',
        width: '100%',
        dropdownParent: $('#modal-interview'),
    });
    
    
    $('#form-interview #user_id').select2({ 
        theme: 'bootstrap-5',
        width: '100%',
        dropdownParent: $('#modal-interview'),
    });
    
    $('#form-interview #last_date').datetimepicker({
        locale: 'es',
        format: 'DD/MM/YYYY'
    });



    $('#form-comment #points').inputNumberFormat({decimal: 0});
    
    
    CKEDITOR.replace('comment');
    

  });
JS;

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

?>
<!-- Content Header (Page header) -->

<div class="container">
    <div class="card" id="row-list">
        <div class="card-header">
            <h6 class="card-title">LABEL_APPLICATIONS_TO_NEW_JOBS</h6>
        </div>


        <div class="card-body">
            <div class="row">
                <div class="col-12 mt-3">
                    <?php
                    $form = $this->formFilter;
                    $form->setAttributes([
                        'method'    => 'post',
                        'name'      => 'form-filter',
                        'id'        => 'form-filter'
                    ]);

                    $form->prepare();
                    echo $this->form()->openTag($form);

                    $element = $form->get('vacancy_id');
                    $element->setAttributes(['class' => 'form-control']);
                    $element->setOptions(['label' => 'LABEL_VACANCY']);
                    ?>
                    <table class="table">
                        <tbody>
                            <tr>
                                <td><?php echo $this->formLabel($element); ?></td>
                                <td><?php echo $this->formSelect($element); ?></td>
                            </tr>
                        </tbody>
                    </table>
                    <?php echo $this->form()->closeTag($form); ?>
                </div>
            </div>
            <div class="row">
                <div class="col-12 mt-3">

                    <table id="gridTable" class="table   table-bordered">
                        <thead>
                            <tr>
                                <th>LABEL_FIRST_NAME</th>
                                <th>LABEL_LAST_NAME</th>
                                <th>LABEL_EMAIL</th>
                                <th>LABEL_STATUS</th>
                                <th>LABEL_LEVEL</th>
                                <th>LABEL_ACTIONS</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>

                </div>
            </div>
        </div>
        <div class="card-footer text-right">
            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-sync"></i> LABEL_REFRESH </button>
            <?php if ($allowAdd) : ?>
                <button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
            <?php endif; ?>
        </div>
    </div>


    <div class="card" id="row-view" style="display: none">
        <div class="card-header">
            <h6 class="card-title">
                <span id="view_title_name"></span>
                <small class="float-right">LABEL_LAST_DATE: <span id="view_title_last_date"></span></small>
            </h6>
        </div>
        <div class="card-body">
            <div class="row invoice-info">
                <div class="col-sm-6 invoice-col">
                    <strong>LABEL_VACANCY</strong>
                    <address>
                        <span id="view_vacancy_name"></span><br>
                        LABEL_LAST_DATE : <span id="view_vacancy_last_date"></span><br>
                        LABEL_JOB_DESCRIPTION : <span id="view_vacancy_job_description"></span><br>
                        LABEL_INDUSTRY : <span id="view_vacancy_industry"></span><br>
                        LABEL_JOB_CATEGORY : <span id="view_vacancy_job_category"></span>
                    </address>
                </div>
                <!-- /.col -->
                <div class="col-sm-3 invoice-col">
                    <strong>LABEL_CANDIDATE</strong>
                    <address>
                        LABEL_FIRST_NAME : <strong id="view_candidate_first_name"></strong><br>
                        LABEL_LAST_NAME : <strong id="view_candidate_last_name"></strong><br>
                        LABEL_EMAIL : <span id="view_vacancy_email"></span><br>
                    </address>
                </div>
                <!-- /.col -->
                <div class="col-sm-3 invoice-col">
                    <strong> LABEL_APPLICATION</strong><br>
                    <address>
                        LABEL_LEVEL : <span id="view_application_level"></span>
                        <?php if ($allowLevel) : ?>
                            <button class="btn btn-default btn-change-level"><i class="fa fa-external-link-alt"></i></button>
                        <?php endif; ?>
                        <br>
                        LABEL_STATUS : <span id="view_application_status"></span>
                        <?php if ($allowStatus) : ?>
                            <button class="btn btn-default btn-change-status"><i class="fa fa-external-link-alt"></i></button>
                        <?php endif; ?>
                        <br>
                        LABEL_POINTS : <span id="view_application_points"></span>
                        <?php if ($allowComment) : ?>
                            <button class="btn btn-default btn-change-comment"><i class="fa fa-external-link-alt"></i></button>
                        <?php endif; ?>
                        <br>
                    </address>
                </div>
                <!-- /.col -->
            </div>
            <div class="row invoice-info">
                <div class="col-sm-12 invoice-col">
                    <strong>LABEL_COMMENT</strong><br />
                    <div id="view_application_comment">
                    </div>
                </div>
            </div>
            <!-- /.row -->

            <!-- Table row -->
            <div class="row">
                <div class="col-12 table-responsive">
                    <table class="table " id="fileTable">
                        <thead>
                            <tr>
                                <th>LABEL_NAME</th>
                                <th>LABEL_FILE</th>
                                <th>LABEL_ACTIONS</th>
                            </tr>
                        </thead>
                        <tbody>

                        </tbody>

                        <tfoot>
                            <tr>
                                <td colspan="3" class="text-right">
                                    <?php if ($allowFileAdd) : ?>
                                        <button type="button" class="btn btn-primary btn-add-file"><i class="fa fa-plus"></i> LABEL_ADD </button>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        </tfoot>

                    </table>
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->


            <!-- Table row -->
            <div class="row">
                <div class="col-12 table-responsive">
                    <table class="table " id="interviewTable">
                        <thead>
                            <tr>
                                <th>LABEL_TYPE</th>
                                <th>LABEL_LAST_DATE</th>
                                <th>LABEL_INTERVIEWED_BY</th>
                                <th>LABEL_STATUS</th>
                                <th>LABEL_ACTIONS</th>
                            </tr>
                        </thead>
                        <tbody>

                        </tbody>

                        <tfoot>
                            <tr>
                                <td colspan="5" class="text-right">
                                    <?php if ($allowInterviewAdd) : ?>
                                        <button type="button" class="btn btn-primary  btn-add-interview"><i class="fa fa-plus"></i> LABEL_ADD </button>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        </tfoot>

                    </table>
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </div>
        <div class="card-footer text-right">
            <button type="button" class="btn btn-primary btn-close-application"><i class="far fa-time"></i> LABEL_CLOSE </button>
        </div>
    </div>

</div>














<!-- The Modal -->
<div class="modal" id="modal-add-application">
    <div class="modal-dialog  modal-xl">
        <div class="modal-content">

            <!-- Modal Header -->
            <div class="modal-header">
                <h6>LABEL_ADD_APPLICATION</h6>
            </div>

            <?php
            $form = $this->formAdd;
            $form->setAttributes([
                'method'    => 'post',
                'name'      => 'form-add',
                'id'        => 'form-add'
            ]);

            $form->prepare();
            echo $this->form()->openTag($form);

            $element = $form->get('user_id');
            echo $this->formHidden($element);

            ?>

            <!-- Modal body -->
            <div class="modal-body">

                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('email');
                        $element->setOptions(['label' => 'LABEL_EMAIL']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        ?>


                        <?php if ($allowUserByEmail) : ?>

                            <div class="input-group mb-3">
                                <?php echo  $this->formText($element); ?>
                                <span class="input-group-text btn-search-email">

                                    <i class="fa fa-search" aria-hidden="true"></i></span>

                            </div>


                        <?php
                        else :
                            echo $this->formText($element);
                        endif; ?>

                    </div>
                </div>
                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('first_name');
                        $element->setOptions(['label' => 'LABEL_FIRST_NAME']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        echo $this->formText($element);
                        ?>
                    </div>
                </div>
                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('last_name');
                        $element->setOptions(['label' => 'LABEL_LAST_NAME']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        echo $this->formText($element);
                        ?>
                    </div>
                </div>


            </div>
            <div class="modal-footer text-right">
                <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
                <button type="button" class="btn btn-light btn-cancel-modal-application">LABEL_CANCEL</button>
            </div>
            <?php echo $this->form()->closeTag($form); ?>
        </div>
    </div>
</div>


<!-- The Modal -->
<div class="modal" id="modal-add-file">
    <div class="modal-dialog  modal-xl">
        <div class="modal-content">

            <!-- Modal Header -->
            <div class="modal-header">
                <h6>LABEL_ADD_FILE</h6>
            </div>

            <?php
            $form = $this->formFile;
            $form->setAttributes([
                'method'    => 'post',
                'name'      => 'form-file',
                'id'        => 'form-file'
            ]);

            $form->prepare();
            echo $this->form()->openTag($form);



            ?>
            <div class="modal-body">


                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('name');
                        $element->setOptions(['label' => 'LABEL_NAME']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        echo $this->formText($element);
                        ?>
                    </div>
                </div>
                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('file');
                        $element->setOptions(['label' => 'LABEL_FILE']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        echo $this->formFile($element);
                        ?>
                    </div>
                </div>


            </div>
            <div class="modal-footer text-right">
                <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
                <button type="button" class="btn btn-light btn-cancel-modal-file">LABEL_CANCEL</button>
            </div>
            <?php echo $this->form()->closeTag($form); ?>

        </div>
    </div>
</div>


<!-- The Modal -->
<div class="modal" id="modal-comment">
    <div class="modal-dialog  modal-xl">
        <div class="modal-content">

            <!-- Modal Header -->
            <div class="modal-header">
                <h6>LABEL_EVALUATION</h6>
            </div>

            <?php
            $form = $this->formComment;
            $form->setAttributes([
                'method'    => 'post',
                'name'      => 'form-comment',
                'id'        => 'form-comment'
            ]);

            $form->prepare();
            echo $this->form()->openTag($form);



            ?>
            <div class="modal-body">


                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('points');
                        $element->setOptions(['label' => 'LABEL_POINTS']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        echo $this->formText($element);
                        ?>
                    </div>
                </div>
                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('comment');
                        $element->setOptions(['label' => 'LABEL_COMMENT']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        echo $this->formTextArea($element);
                        ?>
                    </div>
                </div>


            </div>
            <div class="modal-footer text-right">
                <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
                <button type="button" class="btn btn-light btn-cancel-modal-comment">LABEL_CANCEL</button>
            </div>
            <?php echo $this->form()->closeTag($form); ?>

        </div>
    </div>
</div>



<!-- The Modal -->
<div class="modal" id="modal-level">
    <div class="modal-dialog  modal-xl">
        <div class="modal-content">

            <!-- Modal Header -->
            <div class="modal-header">
                <h6>LABEL_LEVEL</h6>
            </div>

            <?php
            $form = $this->formLevel;
            $form->setAttributes([
                'method'    => 'post',
                'name'      => 'form-level',
                'id'        => 'form-level'
            ]);

            $form->prepare();
            echo $this->form()->openTag($form);



            ?>
            <div class="modal-body">


                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('level');
                        $element->setOptions(['label' => 'LABEL_LEVEL']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        echo $this->formSelect($element);
                        ?>
                    </div>
                </div>



            </div>

            <div class="modal-footer text-right">
                <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
                <button type="button" class="btn btn-light btn-cancel-modal-level">LABEL_CANCEL</button>
            </div>
            <?php echo $this->form()->closeTag($form); ?>
        </div>
    </div>
</div>


<!-- The Modal -->
<div class="modal" id="modal-status">
    <div class="modal-dialog  modal-xl">
        <div class="modal-content">

            <!-- Modal Header -->
            <div class="modal-header">
                <h6>LABEL_STATUS</h6>
            </div>

            <?php
            $form = $this->formStatus;
            $form->setAttributes([
                'method'    => 'post',
                'name'      => 'form-status',
                'id'        => 'form-status'
            ]);

            $form->prepare();
            echo $this->form()->openTag($form);



            ?>

            <!-- Modal body -->
            <div class="modal-body">


                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('status');
                        $element->setOptions(['label' => 'LABEL_STATUS']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        echo $this->formSelect($element);
                        ?>
                    </div>
                </div>


            </div>

            <div class="modal-footer text-right">
                <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
                <button type="button" class="btn btn-light btn-cancel-modal-status">LABEL_CANCEL</button>
            </div>
            <?php echo $this->form()->closeTag($form); ?>
        </div>
    </div>
</div>


<div class="modal" id="modal-interview">
    <div class="modal-dialog  modal-xl">
        <div class="modal-content">

            <!-- Modal Header -->
            <div class="modal-header">
                <h6>LABEL_INTERVIEW</h6>
            </div>

            <?php
            $form = $this->formInterview;
            $form->setAttributes([
                'method'    => 'post',
                'name'      => 'form-interview',
                'id'        => 'form-interview'
            ]);

            $form->prepare();
            echo $this->form()->openTag($form);



            ?>

            <div class="modal-body">

                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('user_id');
                        $element->setOptions(['label' => 'LABEL_INTERVIEWED_BY']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        echo $this->formSelect($element);
                        ?>
                    </div>
                </div>

                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('type');
                        $element->setOptions(['label' => 'LABEL_TYPE']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        echo $this->formSelect($element);
                        ?>
                    </div>
                </div>

                <div class="row">
                    <div class="col-12 mt-3">
                        <?php
                        $element = $form->get('last_date');
                        $element->setOptions(['label' => 'LABEL_LAST_DATE']);
                        $element->setAttributes(['class' => 'form-control']);

                        echo $this->formLabel($element);
                        echo $this->formText($element);
                        ?>
                    </div>
                </div>



            </div>

            <div class="modal-footer text-right">
                <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
                <button type="button" class="btn btn-light btn-cancel-modal-interview">LABEL_CANCEL</button>
            </div>
            <?php echo $this->form()->closeTag($form); ?>
        </div>
    </div>
</div>



<script id="fileTemplate" type="text/x-jsrender">
    <tr>
        <td>{{>name}}</td>
        <td>{{>filename}}</td>
        <td>
            {{if link_view}}
            <button class="btn btn-primary btn-view-file" data-href="{{>link_view}}" data-toggle="tooltip" title="LABEL_DOWNLOAD"><i class="fa fa-download"></i> LABEL_DOWNLOAD </button>
            {{/if}}
            {{if link_delete}}
            <button class="btn btn-danger btn-delete-file" data-href="{{>link_delete}}" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>
            {{/if}} 
        </td>
    </tr>
</script>





<script id="interviewTemplate" type="text/x-jsrender">
    <tr>
        <td>{{>type}}</td>
        <td>{{>last_date}}</td>
        <td>{{>interviewer}}</td>
        <td>{{>status}}</td>
        <td>
            {{if link_report}}
            <button class="btn btn-primary btn-report-interview" data-href="{{>link_report}}" data-toggle="tooltip" title="LABEL_DOWNLOAD"><i class="fa fa-download"></i> LABEL_DOWNLOAD </button>
            {{/if}}
            {{if link_edit}}
            <button class="btn btn-primary btn-edit-interview" data-href="{{>link_edit}}" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pen"></i> LABEL_EDIT </button>
            {{/if}}
            {{if link_delete}}
            <button class="btn btn-danger btn-delete-interview" data-href="{{>link_delete}}" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>
            {{/if}} 
        </td>
    </tr>
</script>