Rev 16932 | 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('reports/users-blocked');
$allowDownload = $acl->isAllowed($roleName, 'reports/users-blocked/download') ? 1 : 0;
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jsrender/jsrender.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->headStyle()->captureStart();
echo <<<CSS
#tableStudents {
display: flex;
flex-flow: column;
width: 100%;
}
#tableStudents thead {
flex: 0 0 auto;
}
#tableStudents tbody {
flex: 1 1 auto;
display: block;
overflow-y: auto;
overflow-x: hidden;
}
#tableStudents tr {
width: 100%;
display: table;
table-layout: fixed;
}
CSS;
$this->headStyle()->captureEnd();
$this->inlineScript()->captureStart();
echo <<<JS
jQuery( document ).ready(function( $ ) {
$.fn.loadData = function() {
NProgress.start();
$.ajax({
'dataType' : 'json',
'accept' : 'application/json',
'method' : 'get',
'url' : $('#form-filter').attr('action'),
'data' : $('#form-filter').serialize(),
}).done(function(response) {
if(response['success']) {
$('#gridTable tbody').empty();
if(response['data']['items']) {
$('#gridTable tbody').append(
$( "#itemRowTemplate" ).render( response['data']['items'] )
);
} else {
$('#gridTable tbody').append(
$( "#itemEmptyRowTemplate" ).render([])
);
}
} else {
if(jQuery.type(response['data']) == 'string') {
$.fn.showError(response['data']);
} else {
$.each(response['data'], function( fieldname, errors ) {
$.fn.showFormErrorValidator('#form-filter #' + fieldname, errors);
});
}
}
}).fail(function( jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
}).always(function() {
NProgress.done();
});
return false;
}
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();
},
'dataFilter': function(response) {
var response = jQuery.parseJSON( response );
var json = {};
json.recordsTotal = 0;
json.recordsFiltered = 0;
json.data = [];
if(response.success) {
$('button.btn-download').attr('href', response.data.link_download);
if(response.data.total == 0) {
$('button.btn-download').hide();
} else {
$('button.btn-download').show();
}
json.recordsTotal = response.data.total;
json.recordsFiltered = response.data.total;
json.data = response.data.items;
} else {
$('button.btn-download').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': 'last_activity_on' },
],
'columnDefs': [
{
'targets': 0,
'className' : 'text-vertical-middle',
},
{
'targets': 1,
'orderable': false,
'className' : 'text-vertical-middle',
},
],
});
$('button.btn-refresh').click(function(e) {
e.preventDefault();
gridTable.api().ajax.reload(null, false);
});
$('body').on('click', 'button.btn-download', function(e) {
e.preventDefault();
var action = $(this).attr('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();
});
});
});
JS;
$this->inlineScript()->captureEnd();
?>
<div class="container">
<div class="card" id="">
<div class="card-body">
<h6 class="card-title">LABEL_REPORTS_USERS_BLOCKED</h6>
<div class="row">
<div class="col-12 mt-3">
<table id="gridTable" class="table table-bordered">
<thead>
<tr>
<th style="width: 25%">LABEL_FIRST_NAME</th>
<th style="width: 25%">LABEL_LAST_NAME</th>
<th style="width: 30%">LABEL_EMAIL</th>
<th style="width: 20%">LABEL_REPORTS_LAST_ACTIVITY</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 ($allowDownload) : ?>
<button type="button" class="btn btn-info btn-download" style="display: none"><i class="fa fa-download"></i> LABEL_DOWNLOAD </button>
<?php endif; ?>
</div>
</div>
</div>