Rev 16845 | 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();
$routeDatatable = $this->url('self-evaluation/users');
$allowAdd = $acl->isAllowed($roleName, 'self-evaluation/users/add') ? 1 : 0;
$allowDelete = $acl->isAllowed($roleName, 'self-evaluation/users/delete') ? 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->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 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 ) {
d.form_uuid = $('#form-filter #form_uuid').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) {
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();
});
},
});
$('button.btn-add').click(function(e) {
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': 'first_name' },
{ 'mDataProp': 'last_name' },
{ 'mDataProp': 'email' },
{ 'mDataProp': 'actions' },
],
'columnDefs': [
{
'targets': -1,
'orderable': false,
'render' : function ( data, type, row ) {
s = '';
if(allowDelete && data['link_delete'] ) {
s = s + '<button class="btn btn-danger btn-sm btn-delete" data-href="' + data['link_delete']+ '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-times"></i> LABEL_DELETE </button> ';
}
if(allowAdd && data['link_add'] ) {
s = s + '<button class="btn btn-primary btn-sm btn-add" data-href="' + data['link_add']+ '" data-toggle="tooltip" title="LABEL_ADD"><i class="fa fa-plus"></i> LABEL_ADD </button> ';
}
return s;
}
}
],
});
$('#form-filter #form_uuid').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);
});
});
JS;
$this->inlineScript()->captureEnd();
?>
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-12">
<h1>LABEL_USERS_FOR_FORMS</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<?php
$form = $this->form;
$form->setAttributes([
'name' => 'form-filter',
'id' => 'form-filter',
]);
$form->prepare();
echo $this->form()->openTag($form);
?>
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="form-group">
<?php
$element = $form->get('form_uuid');
$element->setOptions(['label' => 'LABEL_FORM']);
$element->setAttributes(['class' => 'form-control']);
echo $this->formLabel($element);
echo $this->formSelect($element);
?>
</div>
</div>
</div>
<?php echo $this->form()->closeTag($form); ?>
</div>
<div class="card-body">
<table id="gridTable" class="table table-hover">
<thead>
<tr>
<th>LABEL_FIRST_NAME</th>
<th>LABEL_LAST_NAME</th>
<th>LABEL_EMAIL</th>
<th>LABEL_ACTIONS</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</section>