Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15443 | Rev 16845 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php
$t = strtotime("+3 days");
$startDate = date('d/m/Y', $t);

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

$routeDatatable = $this->url('performance-evaluation/evaluations');
$routeAdd = $this->url('performance-evaluation/evaluations/add');

$allowAdd = $acl->isAllowed($roleName, 'performance-evaluation/evaluations/add') ? 1 : 0;
$allowDelete = $acl->isAllowed($roleName, 'performance-evaluation/evaluations/delete') ? 1 : 0;
$allowReport =  $acl->isAllowed($roleName, 'performance-evaluation/evaluations/report') ? 1 : 0;

$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));


$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));


$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));

$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));

$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));


$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));

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

$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datepicker/js/bootstrap-datepicker.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datepicker/js/bootstrap-datepicker.es.js'));


$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-datepicker/css/bootstrap-datepicker.css'));

$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.min.js'));

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

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

$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));


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


jQuery( document ).ready(function( $ ) {

    var allowAdd = $allowAdd;
    var allowDelete = $allowDelete
    var allowReport = $allowReport

    $.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('.form-group').length) {
                error.insertAfter(element);
            } else if(element.parent('.toggle').length) {
                error.insertAfter(element.parent().parent());
            } else {
                error.insertAfter(element.parent());
            }
        }
    });
    

        
    $.fn.showFormErrorValidator = function(fieldname, errors) {
        var field = $(fieldname);
        if(field) {
            $(field).addClass('form-group-has-error');

            var error = $('<div id="' + fieldname +'-error" class="form-group-invalid-feedback">' + errors + '</div>');
            if(field.parent('.form-group').length) {
                error.insertAfter(field.parent());
            } else {
                error.insertAfter(field);
            }
        }
    };


    var validator = $('#form').validate({
        debug: true,
        onclick: false,
        onkeyup: false,
        onfocusout: false,
        ignore: [],
        rules: {
            'last_date': {
                required: true,
            },
            'form_id' :  {
                required: true,
            },
            'supervisor_id' : {
                required: true,
            },
            'employee_id' : {
                required: true,
            }

        },
        submitHandler: function(form)
        {
            NProgress.start();
            $.ajax({
                'dataType'  : 'json',
                'accept'    : 'application/json',
                'method'    : 'post',
                'url'       :  $('#form').attr('action'),
                'data'      :  $('#form').serialize(),
            }).done(function(response) {
                if(response['success']) {
                    $('#row-form').hide();
                    $('#row-listing').show();
                    $('#row-header').show();
                    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('#form #' + fieldname, errors);
                        });
                    }
                }
            }).fail(function( jqXHR, textStatus, errorThrown) {
                $.fn.showError(textStatus);
            }).always(function() {
                NProgress.done();
            });
            return false;
        },
        invalidHandler: function(form, validator) {
            
        }
    });

        var gridTable = $('#gridTable').dataTable( {
            'processing': true,
            'serverSide': true,
            'searching': true,
            'order': [[ 1, 'asc' ]],
            'ordering':  true,
            'ordenable' : true,
            'responsive': true,
            'select' : false,
                'paging': true,
            'pagingType': 'simple_numbers',
            'lengthMenu': [ [10, 25, 50, -1], [10, 25, 50, 'All'] ],

                'ajax': {
                        'url' : '$routeDatatable',
                        'type' : 'get',
                'data': function ( d ) {
   
               
                },
                '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 );
                }
                },
            '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();
                $('button.btn-delete').confirmation({
                    rootSelector: 'button.btn-delete',
                    title : 'LABEL_ARE_YOU_SURE',
                    singleton : true,
                    btnOkLabel: 'LABEL_YES',
                    btnCancelLabel: 'LABEL_NO',
                    onConfirm: function(value) {
                        action = $(this).data('href');
                        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();
                        });
                    },
                });
 

            },
            'aoColumns': [
                { 'mDataProp': 'last_date' },
                { 'mDataProp': 'form' },
                { 'mDataProp': 'supervisor_first_name' },
                { 'mDataProp': 'employee_last_name' },
                { 'mDataProp': 'status' },
                { 'mDataProp': 'actions' },
            ],
            'columnDefs': [
                {
                    'targets': 0,
                    'render' : function ( data, type, row ) {
                        var s = data;
                          
                        return s;


                     }
                },
                {
                    'targets': 1,
                    'render' : function ( data, type, row ) {
                        var s = row['form'];
                          
                        if(allowReport && row['actions']['link_pdf_both']) {
                            s = s + '<br><button class="btn btn-default btn-pdf" data-href="' + row['actions']['link_pdf_both'] + '" data-toggle="tooltip" title="LABEL_PDF_BOTH"><i class="fa fa-pdf"></i> LABEL_PDF_BOTH </button>&nbsp;';
    
                        }
                        return s;

                     }
                },
                {
                    'targets': 2,
                    'render' : function ( data, type, row ) {
                        var s = row['supervisor_first_name'] + ' ' + row['supervisor_last_name'];

                        if(allowReport && row['actions']['link_pdf_supervisor']) {
                            s = s + '<br><button class="btn btn-default btn-pdf" data-href="' + row['actions']['link_pdf_supervisor'] + '" data-toggle="tooltip" title="LABEL_PDF_SUPERVISOR"><i class="fa fa-pdf"></i> LABEL_PDF_SUPERVISOR </button>&nbsp;';
    
                        }
                          
                        return s;


                     }
                },
                {
                    'targets': 3,
                    'render' : function ( data, type, row ) {
                        var s = row['employee_first_name'] + ' ' + row['employee_last_name'];
                          
                        if(allowReport && row['actions']['link_pdf_employee']) {
                            s = s + '<br><button class="btn btn-default btn-pdf" data-href="' + row['actions']['link_pdf_employee'] + '" data-toggle="tooltip" title="LABEL_PDF_EMPLOYEE"><i class="fa fa-pdf"></i> LABEL_PDF_EMPLOYEE </button>&nbsp;';
    
                        }

                        return s;


                     }
                },
                {
                    'targets': -1,
                    'orderable': false,
                    'render' : function ( data, type, row ) {
                        s = '';
                   
                     
                        if (allowDelete && data['link_delete']) {
                            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;
                    }
                }
              ],
        });

$('body').on('click', 'button.btn-pdf', 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();
        });



    });

    $('.btn-evaluation-close').on("click", function(e){
        e.preventDefault();
        
        $('#row-form').hide();
        $('#row-listing').show();
        $('#row-header').show();
        return false;
    });

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

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

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


        $('#form').attr('action','$routeAdd');

        $('#form #last_date').val('$startDate');
        $('#form #form_id').val('').trigger('change');
        $('#form #supervisor_id').val('').trigger('change');
        $('#form #employee_id').val('').trigger('change');
        validator.resetForm();

        $('#row-listing').hide();
        $('#row-header').hide();
        $('#row-form').show();
                    
        return false;
    });


    $('#form #last_date').datepicker({  
        language: 'es',
        format: 'dd/mm/yyyy',
        startDate: '$startDate',
    
    });

    $('#form #form_id').select2({
        theme: 'bootstrap4',
        width: '100%',
    });

    $('#form #supervisor_id').select2({
        theme: 'bootstrap4',
        width: '100%',
    });

    $('#form #employee_id').select2({
        theme: 'bootstrap4',
        width: '100%',
    });
    

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

<!-- Content Header (Page header) -->
<section id="row-header" class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-12">
                <h1>LABEL_EVALUATION</h1>
            </div>
        </div>
    </div>
    <!-- /.container-fluid -->
</section>
<section id="row-listing" class="content">
    <div class="container-fluid" id="row-lists">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <table id="gridTable" class="table   table-hover">
                            <thead>
                                <tr>
                                    <th style="width:15%">LABEL_LAST_DATE</th>
                                    <th style="width:35%">LABEL_FORM_NAME</th>
                                    <th style="width:35%">LABEL_SUPERVISOR</th>
                                    <th style="width:35%">LABEL_EMPLOYEE</th>
                                    <th style="width:15%">LABEL_STATUS</th>
                                    <th style="width:15%">LABEL_ACTIONS</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                    </div>
                    <div class="card-footer clearfix">
                        <div style="float:right;">
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></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>
            </div>
        </div>
    </div>
</section>


<section id="row-form" class="content" style="display: none">
    <div class="container-fluid" id="row-lists">
        <div class="row">
            <div class="col-12">
                <?php
                $form = $this->form;
                $form->setAttributes([
                    'method' => 'post',
                    'name' => 'form',
                    'action' => $routeAdd,
                    'id' => 'form'
                ]);
                $form->prepare();
                echo $this->form()->openTag($form);

                ?>
                <div class="card">
                    <div class="card-header">
                        <h3>LABEL_NEW_EVALUATION</h3>
                    </div>
                    <div class="card-body">
                        <div class="form-group">
                            <?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 class="form-group">
                            <?php
                            $element = $form->get('form_id');
                            $element->setOptions(['label' => 'LABEL_FORM_NAME']);
                            $element->setAttributes(['class' => 'form-control']);
                            echo $this->formLabel($element);
                            echo $this->formSelect($element);
                            ?>
                        </div>
                        <div class="form-group">
                            <?php
                            $element = $form->get('supervisor_id');
                            $element->setOptions(['label' => 'LABEL_SUPERVISOR']);
                            $element->setAttributes(['class' => 'form-control']);
                            echo $this->formLabel($element);
                            echo $this->formSelect($element);
                            ?>
                        </div>
                        <div class="form-group">
                            <?php
                            $element = $form->get('employee_id');
                            $element->setOptions(['label' => 'LABEL_EMPLOYEE']);
                            $element->setAttributes(['class' => 'form-control']);
                            echo $this->formLabel($element);
                            echo $this->formSelect($element);
                            ?>
                        </div>
                    </div>


                    <div class="card-footer">
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
                        <button type="button" class="btn btn-default btn-evaluation-close">LABEL_CANCEL</button>
                    </div>
                    <?php echo $this->form()->closeTag($form); ?>
                </div>
            </div>
        </div>
    </div>
</section>