Rev 16942 | 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('knowledge-area/categories/users');
$allowAdd = $acl->isAllowed($roleName, 'knowledge-area/categories/users/add') ? 1 : 0;
$allowEdit = $acl->isAllowed($roleName, 'knowledge-area/categories/users/edit') ? 1 : 0;
$allowDelete = $acl->isAllowed($roleName, 'knowledge-area/categories/users/delete') ? 1 : 0;
$allowUpload = $acl->isAllowed($roleName, 'knowledge-area/categories/users/upload') ? 1 : 0;
$allowJobDescription = $acl->isAllowed($roleName, 'knowledge-area/categories/users/jobs-description') ? 1 : 0;
$allowUpload = false;
$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->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->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/select2/js/select2.js'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/select2/js/i18n/es.js'));
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/select2/css/select2.css'));
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/select2-bootstrap5-theme/select2-bootstrap-5-theme.css'));
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/treeflex/treeflex.css'));
$this->inlineScript()->captureStart();
echo <<<JS
jQuery( document ).ready(function( $ ) {
var routeAdd = '';
var routeUpload = '';
var allowEdit = $allowEdit;
var allowDelete = $allowDelete;
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',
'beforeSend': function (request) {
NProgress.start();
},
'data': function ( d ) {
d.category_id = $('#form-filter #category_id').val();
},
'dataFilter': function(response) {
var response = jQuery.parseJSON( response );
var json = {};
json.recordsTotal = 0;
json.recordsFiltered = 0;
json.data = [];
if(response.success) {
$('#form #role').empty();
if(typeof response.data.roles === 'object') {
var rolesArray = $.map(response.data.roles, function(text, value) {
return [{value : value, text: text}];
});
if(rolesArray.length > 0) {
$.each(rolesArray, function(index, item) {
$('#form #role').append(new Option(item.text, item.value));
});
}
} else {
console.log('is_array');
if(response.data.roles.length > 0) {
$.each(response.data.roles, function(value, text) {
$('#form #role').append(new Option(text, value));
});
}
}
$('#form #role').trigger('change');
if(response.data.link_add) {
$('button.btn-add').data('href', response.data.link_add);
$('button.btn-add').show();
} else {
$('button.btn-add').hide();
}
if(response.data.link_upload) {
$('button.btn-upload').data('href', response.data.link_upload);
$('button.btn-upload').show();
} else {
$('button.btn-upload').hide();
}
if(response.data.link_jobs_description) {
$('#form-jobs-description').attr('action', response.data.link_jobs_description);
$('#form-jobs-description input[type="checkbox"]').each(function(i, item) {
$(item).removeAttr('disabled');
});
} else {
$('#form-jobs-description').attr('action', '');
$('#form-jobs-description input[type="checkbox"]').each(function(i, item) {
$(item).attr('disabled','disabled');
});
}
$('#form-jobs-description input[type="checkbox"]').prop('checked', false);
if(response.data.jobs_description.length > 0) {
$.each(response.data.jobs_description, function(i, uuid) {
$('#form-jobs-description #job_description_id' + uuid).prop('checked', true);
});
}
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();
},
'aoColumns': [
{ 'mDataProp': 'first_name' },
{ 'mDataProp': 'last_name' },
{ 'mDataProp': 'email' },
{ 'mDataProp': 'role' },
{ 'mDataProp': 'actions' },
],
'columnDefs': [
{
'targets': 0,
'className' : 'text-vertical-middle',
},
{
'targets': 1,
'orderable': false,
'className' : 'text-vertical-middle',
},
{
'targets': 2,
'orderable': false,
'className' : 'text-vertical-middle',
},
{
'targets': 3,
'orderable': false,
'className' : 'text-vertical-middle',
},
{
'targets': -1,
'orderable': false,
'render' : function ( data, type, row ) {
s = '';
if(allowEdit) {
s = s + '<button class="btn btn-primary btn-edit" data-href="' + data['link_edit']+ '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pen"></i> LABEL_EDIT </button> ';
}
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> ';
}
return s;
}
}
],
});
var validator = $('#form').validate({
debug: true,
onclick: false,
onkeyup: false,
ignore: [],
rules: {
'user_id': {
required: true,
},
'role': {
required: false,
},
},
submitHandler: function(form)
{
NProgress.start();
$('#submitBtn').prop('disabled', true);
$.ajax({
'dataType' : 'json',
'accept' : 'application/json',
'method' : 'post',
'url' : $('#form').attr('action'),
'data' : {
'role' : $('#form #role').val(),
'user_id' : $('#form #user_id').val(),
}
}).done(function(response) {
if(response['success']) {
$.fn.showSuccess(response['data']);
$('#modal').modal('hide');
gridTable.api().ajax.reload(null, false);
} else {
validator.resetForm();
if(jQuery.type(response['data']) == 'string') {
$.fn.showError(response['data']);
} else {
$.each(response['data'], function( fieldname, errors ) {
$.fn.showFormErrorValidator('#form #' + fieldname, errors);
});
}
}
$('#submitBtn').prop('disabled', false);
}).fail(function( jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
}).always(function() {
$('#submitBtn').prop('disabled', false);
NProgress.done();
});
return false;
},
invalidHandler: function(form, validator) {
}
});
$('#form-filter #category_id').change(function(e) {
e.preventDefault();
gridTable.api().ajax.reload(null, false);
});
$('body').on('click', 'button.btn-add', function(e) {
e.preventDefault();
var action = $(this).data('href');
$('#form').attr('action', action);
$('#form #user_id').val('');
$('#form #user_id').trigger('change');
$('#form #user_id').prop('disabled', false);
$('#form #role').val('');
$('#form #role').trigger('change');
validator.resetForm();
$('#modal').modal('show');
return false;
});
$('body').on('click', 'button.btn-edit', function(e) {
e.preventDefault();
NProgress.start();
var action = $(this).data('href');
$('#submitBtn').prop('disabled', true);
$.ajax({
'dataType' : 'json',
'method' : 'get',
'url' : action,
}).done(function(response) {
if(response['success']) {
$('#form').attr('action', action);
$('#form #user_id').val( response['data']['user_id'] );
$('#form #user_id').trigger('change');
$('#form #user_id').prop('disabled', true);
$('#form #role').val(response['data']['role']);
$('#form #role').trigger('change');
validator.resetForm();
$('#modal').modal('show');
} else {
$.fn.showError(response['data']);
}
$('#submitBtn').prop('disabled', false);
}).fail(function( jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
}).always(function() {
NProgress.done();
$('#submitBtn').prop('disabled', false);
});
return false;
});
$('body').on('click', 'button.btn-refresh', function(e) {
e.preventDefault();
gridTable.api().ajax.reload(null, false);
return false;
});
$('body').on('click', 'button.btn-cancel', function(e) {
e.preventDefault();
$('#modal').modal('hide');
});
$('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', 'button.btn-save-job-description', function(e) {
e.preventDefault();
NProgress.start();
$.ajax({
'dataType' : 'json',
'accept' : 'application/json',
'method' : 'post',
'url' : $('#form-jobs-description').attr('action'),
'data' : $('#form-jobs-description').serialize()
}).done(function(response) {
if(response['success']) {
$.fn.showSuccess(response['data']);
} else {
$.fn.showError(response['data']);
}
}).fail(function( jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
}).always(function() {
NProgress.done();
});
});
$('#form #user_id').select2({
theme: 'bootstrap-5',
width: '100%',
dropdownParent: $('#modal'),
});
$('#form #role').select2({
theme: 'bootstrap-5',
width: '100%',
dropdownParent: $('#modal'),
});
});
JS;
$this->inlineScript()->captureEnd();
?>
<div class="container">
<div class="card" id="">
<div class="card-header">
<h6 class="card-title">LABEL_KNOWLEDGE_AREA_CATEGORY_USERS</h6>
</div>
<div class="card-body">
<div class="row">
<div class="col-12 mt-3">
<?php
$form = $this->formFilter;
$form->setAttributes([
'name' => 'form-filter',
'id' => 'form-filter',
]);
$form->prepare();
echo $this->form()->openTag($form);
?>
<?php
$element = $form->get('category_id');
$element->setAttributes(['class' => 'form-control']);
$element->setLabel('LABEL_CATEGORY');
echo $this->formLabel($element);
echo $this->formSelect($element);
?>
<?php echo $this->form()->closeTag($form); ?>
</div>
</div>
<div class="row">
<div class="col-12 mt-3">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="custom-content-user-tab" data-bs-toggle="tab" href="#custom-content-user" role="tab" aria-controls="custom-content-user" aria-selected="true">LABEL_USERS</a>
</li>
<li class="nav-item">
<a class="nav-link" id="custom-content-job-description-tab" data-bs-toggle="tab" href="#custom-content-job-description" role="tab" aria-controls="custom-content-job-description" aria-selected="false">LABEL_JOBS_DESCRIPTION</a>
</li>
</ul>
<div class="tab-content border border-top-0 p-3" id="myTabContent">
<div class="tab-pane fade show active" id="custom-content-user" role="tabpanel" aria-labelledby="custom-content-user-tab">
<div class="card" id="">
<div class="card-header">
<h6 class="card-title"></h6>
</div>
<div class="card-body">
<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_ROLE</th>
<th>LABEL_ACTIONS</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<div class="card-footer text-right">
<?php if ($allowAdd) : ?>
<button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
<?php endif; ?>
<?php if ($allowUpload) : ?>
<button type="button" class="btn btn-primary btn-upload"><i class="fa fa-upload"></i> LABEL_UPLOAD </button>
<?php endif; ?>
<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-sync"></i> LABEL_REFRESH </button>
</div>
</div>
</div>
<div class="tab-pane fade" id="custom-content-job-description" role="tabpanel" aria-labelledby="custom-content-job-description-tab">
<div class="card" id="">
<div class="card-header">
<h6 class="card-title"></h6>
</div>
<div class="card-body">
<div class="row">
<div class="col-12 mt-3">
<div class="tf-tree">
<form name="form-jobs-description" id="form-jobs-description">
<ul>
<li> <span class="tf-nc"><?php echo $companyName ?></span>
<ul>
<?php
function render_recursive($nodes)
{
$s = '';
foreach ($nodes as $node) {
$s .= '<li> <span class="tf-nc">';
$s .= '<input type="checkbox" class="job-description-checkbox" name="job_description_id[]" id="job_description_id' . $node['uuid'] . '" value="' . $node['uuid'] . '">';
$s .= ' ' . $node['name'] . '</span>';
if (!empty($node['children'])) {
$s .= '<ul>';
$s .= render_recursive($node['children']);
$s .= '</ul>';
}
$s .= '</li>';
}
return $s;
}
echo render_recursive($jobsDescription)
?>
</ul>
</li>
</ul>
</form>
</div>
</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 ($allowJobDescription) : ?>
<button type="button" class="btn btn-info btn-save-job-description"><i class="fa fa-save"></i> LABEL_SAVE </button>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--
<div class="card-footer text-right">
</div>
-->
</div>
</div>
<!-- The Modal -->
<div class="modal" id="modal">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h6 class="modal-title">LABEL_KNOWLEDGE_AREA_CATEGORY_USERS</h6>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button>
</div>
<!-- Modal body -->
<div class="modal-body">
<?php
$form = $this->form;
$form->setAttributes([
'method' => 'post',
'name' => 'form',
'id' => 'form'
]);
$form->prepare();
echo $this->form()->openTag($form);
?>
<div class="card-body">
<div class="row">
<div class="col-12 mt-3">
<?php
$element = $form->get('user_id');
$element->setOptions(['label' => 'LABEL_USER']);
$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('role');
$element->setOptions(['label' => 'LABEL_ROLE']);
$element->setAttributes(['class' => 'form-control']);
echo $this->formLabel($element);
echo $this->formSelect($element);
?>
</div>
</div>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer text-right">
<button type="submit" id="submitBtn" form="form" class="btn btn-primary">LABEL_SAVE</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal">LABEL_CLOSE</button>
</div>
<?php echo $this->form()->closeTag($form); ?>
</div>
</div>
</div>