Rev 15074 | Rev 16822 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
$acl = $this->viewModel()->getRoot()->getVariable('acl');
$currentUser = $this->currentUserHelper();
$roleName = $currentUser->getUserTypeId();
$routeAdd = $this->url('performance-evaluation/forms/add');
$routeDatatable = $this->url('performance-evaluation/forms');
$routeDashboard = $this->url('dashboard');
$allowAdd = $acl->isAllowed($roleName, 'performance-evaluation/forms/add') ? 1 : 0;
$allowEdit = $acl->isAllowed($roleName, 'performance-evaluation/forms/edit') ? 1 : 0;
$allowDelete = $acl->isAllowed($roleName, 'performance-evaluation/forms/delete') ? 1 : 0;
$allowReport = $acl->isAllowed($roleName, 'performance-evaluation/forms/report') ? 1 : 0;
$allowActive = $acl->isAllowed($roleName, 'performance-evaluation/forms/active') ? 1 : 0;
$allowInactive = $acl->isAllowed($roleName, 'performance-evaluation/forms/inactive') ? 1 : 0;
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-maxlenght/bootstrap-maxlength.min.js'));
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.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->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.full.min.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->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()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));
$status_active = \LeadersLinked\Model\PerformanceEvaluationForm::STATUS_ACTIVE;
$status_inactive = \LeadersLinked\Model\PerformanceEvaluationForm::STATUS_INACTIVE;
$vars = "var jobs_description = new Array(); \r\n";
foreach($jobsDescription as $uuid => $link)
{
$vars .= "jobs_description.push({uuid: '$uuid', link: '$link'}); \r\n";
}
$this->inlineScript()->captureStart();
echo <<<JS
jQuery(document).ready(function($) {
$vars
var allowEdit = $allowEdit;
var allowDelete = $allowDelete;
var allowReport = $allowReport;
var allowActive = $allowActive;
var allowInactive = $allowInactive;
var competencies_selected = new Array();
var subordinates_selected = new Array();
var competency_types = new Array();
var competencies = new Array();
var behaviors = new Array();
var subordinates = new Array();
$.fn.renderCompetencies = function() {
if(competencies_selected.length > 0) {
$('#competencies-to-job').show();
$('#rows-job-competencies').html($('#competencyTemplate').render(competencies_selected, {
getCompetencyType: (uuid) => competency_types.filter((item) => item.uuid == uuid ? item : false)[0],
getCompetency: (uuid) => competencies.filter((item) => item.uuid == uuid ? item : false)[0],
getBehavior: (uuid) => behaviors.filter((item) => item.uuid == uuid ? item : false)[0]
}));
} else {
$('#competencies-to-job').hide();
$('#rows-job-competencies').empty();
}
}
$.fn.renderSubordinates = function() {
if(subordinates_selected.length > 0) {
$('#renderSubordinates').html($('#subordinateTemplate').render(subordinates_selected, {
getSubordinate: (uuid) => subordinates.filter((item) => item.uuid == uuid ? item : false)[0],
}));
} else {
$('#renderSubordinates').html('');
}
}
$.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('is-invalid');
var error = $('<span id="' + fieldname + '-error" class="error invalid-feedback">' + errors + '</div>');
if (field.parent('.form-group').length) {
error.insertAfter(field);
} else if (field.parent('.toggle').length) {
error.insertAfter(field.parent().parent());
} else {
error.insertAfter(field.parent());
}
}
};
var gridTable = $('#gridTable').dataTable({
'processing': true,
'serverSide': true,
'searching': true,
'order': [
[0, 'asc']
],
'ordering': false,
'ordenable': false,
'responsive': true,
'select': false,
'paging': true,
'pagingType': 'simple_numbers',
'ajax': {
'url': '$routeDatatable',
'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);
}
},
'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': 'name'
},
{
'mDataProp': 'tests'
},
{
'mDataProp': 'date'
},
{
'mDataProp': 'status'
},
{
'mDataProp': 'actions'
},
],
'columnDefs': [
{
'targets': 0,
'orderable': false,
'render': function(data, type, row) {
return row['name'] + '<br>' + row['job_description'];
}
},
{
'targets': 1,
'orderable': false,
'className': 'text-right',
},
{
'targets': 2,
'orderable': false,
},
{
'targets': -2,
'orderable': false,
'className': 'text-center',
'render': function(data, type, row) {
checked = data == 'a' ? ' checked="checked" ' : '';
return '<div class="checkbox checkbox-success">' +
'<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
'<label ></label></div>';
}
},
{
'targets': -1,
'orderable': false,
'render': function(data, type, row) {
s = '';
if (allowEdit && data['link_edit']) {
s = s + '<button class="btn btn-primary btn-edit" data-href="' + data['link_edit'] + '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button> ';
}
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> ';
}
if (allowActive && data['link_active']) {
s = s + '<button class="btn btn-default btn-active" data-href="' + data['link_active'] + '" data-toggle="tooltip" title="LABEL_ACTIVE"><i class="fa fa-check"></i> LABEL_ACTIVE </button> ';
}
if (allowInactive && data['link_inactive']) {
s = s + '<button class="btn btn-default btn-inactive" data-href="' + data['link_inactive'] + '" data-toggle="tooltip" title="LABEL_INACTIVE"><i class="fa fa-times"></i> LABEL_INACTIVE </button> ';
}
if (allowReport && data['link_report'] ) {
s = s + '<button class="btn btn-primary btn-pdf" data-href="' + data['link_report'] + '" data-toggle="tooltip" title="LABEL_PDF"><i class="fa fa-file-o"></i> LABEL_PDF </button> ';
}
return s;
}
}
],
});
var validator = $('#form').validate({
debug: true,
onclick: false,
onkeyup: false,
ignore: [],
rules: {
'name': {
required: true,
maxlength: 128,
},
'description': {
required: true,
maxlength: 1024,
},
'job_description_id' : {
required: true,
},
'status': {
required: false,
},
},
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']) {
$.fn.showSuccess(response['data']);
$('#row-form').hide();
$('#row-list').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) {}
});
$('body').on('click', 'button.btn-active', 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']) {
gridTable.api().ajax.reload(null, false);
} else {
$.fn.showError(response['message']);
}
}).fail(function(jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
});
});
$('body').on('click', 'button.btn-inactive', 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']) {
gridTable.api().ajax.reload(null, false);
} else {
$.fn.showError(response['message']);
}
}).fail(function(jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
});
});
$('body').on('click', 'button.btn-edit', 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').attr('action', action);
$('#form #name').val(response['data']['name']);
$('#form #description').val(response['data']['description']);
$('#form #job_description_id').val(response['data']['job_description_id']).trigger('change');
$('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
$('#row-list').hide();
$('#row-header').hide();
$('#row-form').show();
} else {
$.fn.showError(response['message']);
}
}).fail(function(jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
});
});
$('button.btn-add').click(function(e) {
e.preventDefault();
$('span[id="form-title"]').html('LABEL_ADD');
$('#form').attr('action', '$routeAdd');
$('#form #name').val('');
$('#form #job_description_id').val('').trigger('change');
$('#form #job_description_id').prop('disabled', false);
$('#form #status').bootstrapToggle('on');
$('#form #description').val('');
$.fn.renderCompetencies();
$('#row-header').hide();
$('#row-list').hide();
$('#row-form').show();
});
$('button.btn-cancel').click(function(e) {
e.preventDefault();
$('#row-form').hide();
$('#row-list').show();
$('#row-header').show();
});
$('#form #description').maxlength({
alwaysShow: true,
validate: true
});
$('#form #status').bootstrapToggle({
'on': 'LABEL_ACTIVE',
'off': 'LABEL_INACTIVE',
'width': '160px',
'height': '40px'
});
$('body').on('click', 'button.btn-refresh', function(e) {
e.preventDefault();
gridTable.api().ajax.reload(null, false);
});
$('#job_description_id').select2({
theme: 'bootstrap4',
width: '100%',
});
$('#job_description_id').on('change', function(e) {
e.preventDefault();
var uuid = $('#job_description_id').val();
var job_description = jobs_description.filter((item) => item.uuid == uuid ? item : false)[0];
if (job_description) {
NProgress.start();
$.getJSON(job_description.link, function(response) {
if (response['success']) {
behaviors = response['data']['behaviors'];
competency_types = response['data']['competency_types'];
competencies = response['data']['competencies'];
competencies_selected = response['data']['competencies_selected'];
subordinates_selected = response['data']['subordinates_selected'];
$.fn.renderCompetencies();
} else {
$.fn.showError(response['data'])
}
}).fail(function( jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
}).always(function() {
NProgress.done();
});
}
});
$('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();
});
});
$('#form #description').maxlength({
alwaysShow: true,
validate: true
});
});
JS;
$this->inlineScript()->captureEnd();
?>
<!-- Content Header (Page header) -->
<section class="content-header" id="row-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-12">
<h1>LABEL_PERFORMANCE_EVALUATIONS</h1>
</div>
</div>
</div>
<!-- /.container-fluid -->
</section>
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12" id="row-list">
<div class="card">
<div class="card-body">
<table id="gridTable" class="table table-hover">
<thead>
<tr>
<th style="width:30%">LABEL_NAME</th>
<th style="width:15%">LABEL_EVALUATIONS</th>
<th style="width:15%">LABEL_DATE</th>
<th style="width:10%">LABEL_ACTIVE</th>
<th style="width:30%">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 class="row" id="row-form" style="display: none">
<div class="col-12">
<div class="card">
<?php
$form = $this->form;
$form->setAttributes([
'method' => 'post',
'name' => 'form',
'id' => 'form'
]);
$form->prepare();
echo $this->form()->openTag($form);
?>
<div class="card-header">
<h4 class="modal-title">LABEL_PERFORMANCE_EVALUATION - <span id="form-title"></span></h4>
</div>
<div class="card-body">
<div class="form-group">
<?php
$element = $form->get('job_description_id');
$element->setOptions(['label' => 'LABEL_JOB_DESCRIPTION']);
$element->setAttributes(['class' => 'form-control']);
echo $this->formLabel($element);
echo $this->formSelect($element);
?>
</div>
<div class="form-group">
<?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 class="form-group">
<?php
$element = $form->get('description');
$element->setOptions(['label' => 'LABEL_DESCRIPTION']);
$element->setAttributes(['class' => 'form-control']);
echo $this->formLabel($element);
echo $this->formTextArea($element);
?>
</div>
<div class="form-group">
<?php
$element = $form->get('status');
$element->setAttributes(['class' => 'form-control']);
echo $this->formCheckbox($element);
?>
</div>
<div class="form-group" id="competencies-to-job" style="display:none">
<div class="row">
<div class="col-xs-12 col-md-12">
<hr>
<h4 style="font-size: 18px;font-weight: bold;">LABEL_COMPETENCIES_TO_JOB:</h4>
<br>
<div class="panel-group" id="rows-job-competencies"></div>
</div>
</div>
</div>
</div>
<div class="card-footer clearfix">
<div style="float:right;">
<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
<button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
</div>
</div>
<?php echo $this->form()->closeTag($form); ?>
</div>
</div>
</div>
</div>
</section>
<script id="competencyTemplate" type="text/x-jsrender">
<div class="panel panel-default panel-competency" id="panel-{{:uuid}}" data-competency="{{:uuid}}">
<div class="panel-heading">
<h4 class="panel-title" style=" font-size: 18px;">
<a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:uuid}}" href="#collapse-{{:uuid}}">
<span class="section-name{{:uuid}}">
{{:~getCompetencyType(competency_type_uuid).name}} - {{:~getCompetency(uuid).name}}
</span>
</a>
</h4>
</div>
<div id="collapse-{{:uuid}}" class="panel-collapse in collapse show">
<div class="panel-body">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th style="width: 30%;">LABEL_ELEMENT</th>
<th style="width: 60%;">LABEL_TITLE</th>
<th style="width: 10%;">LABEL_LEVEL</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-left">LABEL_COMPETENCY</td>
<td class="text-left">{{:name}}</td>
<td> </td>
</tr>
{{for behaviors}}
<tr >
<td class="text-left">--LABEL_BEHAVIOR</td>
<td class="text-left">
{{:~getBehavior(uuid).description}}
</td>
<td class="text-right">
{{:level}}
</td>
</tr>
{{/for}}
</tbody>
</table>
</div>
</div>
</div>
</div>
</script>
<script id="competencyTemplateWithNivel" type="text/x-jsrender">
<div class="panel panel-default panel-competency" id="panel-{{:uuid}}" data-competency="{{:uuid}}">
<div class="panel-heading">
<h4 class="panel-title" style=" font-size: 18px;">
<a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:uuid}}" href="#collapse-{{:uuid}}">
<span class="section-name{{:uuid}}">
{{:~getCompetencyType(competency_type_uuid).name}} - {{:~getCompetency(uuid).name}}
</span>
</a>
</h4>
</div>
<div id="collapse-{{:uuid}}" class="panel-collapse in collapse show">
<div class="panel-body">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th style="width: 30%;">LABEL_ELEMENT</th>
<th style="width: 60%;">LABEL_TITLE</th>
<th style="width: 10%;">LABEL_LEVEL</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-left">LABEL_COMPETENCY</td>
<td class="text-left">{{:name}}</td>
<td> </td>
</tr>
{{for behaviors}}
<tr >
<td class="text-left">--LABEL_BEHAVIOR</td>
<td class="text-left">
{{:~getBehavior(uuid).description}}
</td>
<td>
{{if level == '0'}} LABEL_NA {{/if}}
{{if level == '1' }} LABEL_LEVEL_ONE {{/if}}
{{if level == '2' }} LABEL_LEVEL_TWO {{/if}}
{{if level == '3' }} LABEL_LEVEL_THREE {{/if}}
{{if level == '4' }} LABEL_LEVEL_FOUR {{/if}}
</td>
</tr>
{{/for}}
</tbody>
</table>
</div>
</div>
</div>
</div>
</script>