Rev 1 | Rev 4689 | 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('microlearning/content/topics/add');
$routeDatatable = $this->url('microlearning/content/topics');
$allowAdd = $acl->isAllowed($roleName, 'microlearning/content/topics/add') ? 1 : 0;
$allowEdit = $acl->isAllowed($roleName, 'microlearning/content/topics/edit') ? 1 : 0;
$allowDelete = $acl->isAllowed($roleName, 'microlearning/content/topics/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/ckeditor/ckeditor.js'));
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-fileinput/css/fileinput.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-fileinput/themes/explorer-fas/theme.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/plugins/piexif.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/plugins/sortable.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/fileinput.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/locales/es.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/themes/fas/theme.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/themes/explorer-fas/theme.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/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'));
$status_active = \LeadersLinked\Model\Degree::STATUS_ACTIVE;
$this->inlineScript()->captureStart();
echo <<<JS
jQuery( document ).ready(function( $ ) {
$.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('.btn-file').length) {
error.insertAfter(element.parent().parent());
} 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(element.parent('.btn-file').length) {
error.insertAfter(element.parent().parent());
} else if(element.parent('.toggle').length) {
error.insertAfter(element.parent().parent());
} else {
error.insertAfter(element.parent());
}
}
};
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();
},
'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': 'status' },
{ 'mDataProp': 'image' },
{ 'mDataProp': 'actions' },
],
'columnDefs': [
{
'targets': 0,
'className' : 'text-vertical-middle',
},
{
'targets': -2,
'orderable': false,
'render' : function ( data, type, row ) {
s = ' ';
if( data ) {
s = s + ' <img class="btn-view-image-app" data-href="' + data + '" data-toggle="tooltip" src="'+data+'" title="LABEL_VIEW" style="width: 40px; object-fit: cover; height: 40px;" /> '
} else {
s = s + ' LABEL_IMAGE: <br>';
}
return s;
}
},
{
'targets': -1,
'orderable': false,
'render' : function ( data, type, row ) {
s = '';
if(allowEdit && data['link_edit'] ) {
s = s + '<button class="btn btn-info btn-sm 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-sm 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 validatorAdd = $('#form-topic-add').validate({
debug: true,
onclick: false,
onkeyup: false,
ignore: [],
rules: {
'name': {
required: true,
maxlength: 128,
},
'description': {
updateCkeditor:function() {
CKEDITOR.instances.description_add.updateElement();
},
required: true
},
'file': {
required: true,
extension: 'jpg|jpeg|png',
accept: 'image/jpg,image/jpeg,image/png'
},
'order' : {
required: true,
digits: true,
min: 1,
max: 250
},
'status' : {
required: true,
},
},
submitHandler: function(form)
{
var formdata = false;
if (window.FormData){
formdata = new FormData(form); //form[0]);
}
$('input[type="submit"]').prop('disabled', true);
$.ajax({
'dataType' : 'json',
'accept' : 'application/json',
'method' : 'post',
'url' : $('#form-topic-add').attr('action'),
'data' : formdata,
'processData': false,
'contentType': false,
}).done(function(response) {
if(response['success']) {
$.fn.showSuccess(response['data']);
$('#modalTopicAdd').modal('hide');
gridTable.api().ajax.reload(null, false);
} else {
validatorAdd.resetForm();
if(jQuery.type(response['data']) == 'string') {
$.fn.showError(response['data']);
} else {
$.each(response['data'], function( fieldname, errors ) {
$.fn.showFormErrorValidator('#form-topic-add #' + fieldname, errors);
});
}
}
}).fail(function( jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
}).always(function() {
NProgress.done();
});
return false;
},
invalidHandler: function(form, validator) {
}
});
var validatorEdit = $('#form-topic-edit').validate({
debug: true,
onclick: false,
onkeyup: false,
ignore: [],
rules: {
'name': {
required: true,
maxlength: 128,
},
'description': {
updateCkeditor:function() {
CKEDITOR.instances.description_edit.updateElement();
},
required: true
},
'file': {
required: false,
extension: 'jpg|jpeg|png',
accept: 'image/jpg,image/jpeg,image/png'
},
'order' : {
required: true,
digits: true,
min: 1,
max: 250
},
'status' : {
required: true,
},
},
submitHandler: function(form)
{
var formdata = false;
if (window.FormData){
formdata = new FormData(form); //form[0]);
}
$('input[type="submit"]').prop('disabled', true);
$.ajax({
'dataType' : 'json',
'accept' : 'application/json',
'method' : 'post',
'url' : $('#form-topic-edit').attr('action'),
'data' : formdata,
'processData': false,
'contentType': false,
}).done(function(response) {
if(response['success']) {
$.fn.showSuccess(response['data']);
$('#modalTopicEdit').modal('hide');
gridTable.api().ajax.reload(null, false);
} else {
validatorAdd.resetForm();
if(jQuery.type(response['data']) == 'string') {
$.fn.showError(response['data']);
} else {
$.each(response['data'], function( fieldname, errors ) {
$.fn.showFormErrorValidator('#form-topic-edit #' + fieldname, errors);
});
}
}
}).fail(function( jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
}).always(function() {
NProgress.done();
});
return false;
},
invalidHandler: function(form, validator) {
}
});
$('body').on('click', '.btn-view-image-app', function(e) {
e.preventDefault();
$('#image-app').attr('src', $(this).data('href'));
$('#modalImageApp').modal('show');
return false;
});
$('#form-topic-add #order').inputNumberFormat({decimal: 0});
$('#form-topic-add #file').fileinput({
theme: 'fas',
language: 'es',
showUpload: false,
dropZoneEnabled: false,
maxFileCount: 1,
allowedFileExtensions: ['jpeg', 'jpg', 'png'],
msgPlaceholder: 'LABEL_RECOMMENDED_SIZE $image_size',
});
$('body').on('click', 'button.btn-add', function(e) {
e.preventDefault();
$('#form-topic-add #name').val('');
$('#form-topic-add #order').val('1');
$('#form-topic-add #file').fileinput('reset');
$('#form-topic-add #file').val('');
$('#form-topic-add #status').val('');
CKEDITOR.instances.description_add.setData('');
validatorAdd.resetForm();
$('#modalTopicAdd').modal('show');
return false;
});
$('#form-topic-edit #order').inputNumberFormat({decimal: 0});
$('#form-topic-edit #file').fileinput({
theme: 'fas',
language: 'es',
showUpload: false,
dropZoneEnabled: false,
maxFileCount: 1,
allowedFileExtensions: ['jpeg', 'jpg', 'png'],
msgPlaceholder: 'LABEL_RECOMMENDED_SIZE $image_size',
});
$('body').on('click', 'button.btn-edit', function(e) {
e.preventDefault();
var url = $(this).data('href');
$.ajax({
'dataType' : 'json',
'accept' : 'application/json',
'method' : 'get',
'url' : url,
}).done(function(response) {
if(response['success']) {
$('#form-topic-edit')[0].reset();
$('#form-topic-edit').attr('action',url);
$('#form-topic-edit #name').val(response['data']['name']);
$('#form-topic-edit #order').val(response['data']['order']);
$('#form-topic-edit #file').fileinput('reset');
$('#form-topic-edit #file').val('');
$('#form-topic-edit #status').val(response['data']['status']);
CKEDITOR.instances.description_edit.setData(response['data']['description']);
validatorEdit.resetForm();
$('#modalTopicEdit').modal('show');
} else {
validatorEdit.resetForm();
if(jQuery.type(response['data']) == 'string') {
$.fn.showError(response['data']);
} else {
$.each(response['data'], function( fieldname, errors ) {
$.fn.showFormErrorValidator('#form-topic-edit #' + fieldname, errors);
});
}
}
}).fail(function( jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
}).always(function() {
NProgress.done();
});
});
$('body').on('click', 'button.btn-cancel', function(e) {
e.preventDefault();
$('#modalTopicAdd').modal('hide');
$('#modalTopicEdit').modal('hide');
});
$('body').on('click', 'button.btn-refresh', function(e) {
e.preventDefault();
gridTable.api().ajax.reload(null, false);
});
CKEDITOR.replace('description_add');
CKEDITOR.replace('description_edit');
});
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_TOPICS</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-body">
<table id="gridTable" class="table table-hover">
<thead>
<tr>
<th>LABEL_NAME</th>
<th>LABEL_STATUS</th>
<th>LABEL_DETAILS</th>
<th>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>
<!-- The Modal -->
<div class="modal" id="modalTopicAdd">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">LABEL_ADD_TOPIC</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<?php
$form = $this->formAdd;
$form->setAttributes([
'method' => 'post',
'action' => $routeAdd,
'name' => 'form-topic-add',
'id' => 'form-topic-add',
]);
$form->prepare();
echo $this->form()->openTag($form);
?>
<div class="form-group">
<?php
$element = $form->get('name');
$element->setAttributes(['class' => 'form-control']);
$element->setOptions(['label' => 'LABEL_NAME']);
echo $this->formLabel($element);
echo $this->formText($element);
?>
</div>
<div class="form-group">
<?php
$element = $form->get('description');
$element->setAttributes(['id' => 'description_add', 'class' => 'form-control', 'rows' => '2','class' => 'form-control']);
$element->setOptions(['label' => 'LABEL_DESCRIPTION']);
echo $this->formLabel($element);
echo $this->formTextArea($element);
?>
</div>
<div class="form-group">
<?php
$element = $form->get('order');
$element->setAttributes(['class' => 'form-control']);
$element->setOptions(['label' => 'LABEL_ORDER']);
echo $this->formLabel($element);
echo $this->formText($element);
?>
</div>
<div class="form-group">
<?php
$element = $form->get('file');
$element->setAttributes(['class' => 'form-control', 'accept' => 'image/jpg,image/jpeg,image/png']);
$element->setOptions(['label' => 'LABEL_IMAGE']);
echo $this->formLabel($element);
?>
<div class="file-loading">
<?php echo $this->formFile($element); ?>
</div>
</div>
<div class="form-group">
<?php
$element = $form->get('status');
$element->setAttributes(['class' => 'form-control']);
$element->setOptions(['label' => 'LABEL_STATUS']);
echo $this->formLabel($element);
echo $this->formSelect($element);
?>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
<button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
</div>
<?php echo $this->form()->closeTag($form); ?>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
<!-- The Modal -->
<div class="modal" id="modalTopicEdit">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">LABEL_EDIT_TOPIC</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<?php
$form = $this->formEdit;
$form->setAttributes([
'method' => 'post',
'name' => 'form-topic-edit',
'id' => 'form-topic-edit'
]);
$form->prepare();
echo $this->form()->openTag($form);
?>
<div class="form-group">
<?php
$element = $form->get('name');
$element->setAttributes(['class' => 'form-control']);
$element->setOptions(['label' => 'LABEL_NAME']);
echo $this->formLabel($element);
echo $this->formText($element);
?>
</div>
<div class="form-group">
<?php
$element = $form->get('description');
$element->setAttributes(['id' => 'description_edit', 'rows' => '2', 'class' => 'form-control', 'class' => 'form-control']);
$element->setOptions(['label' => 'LABEL_DESCRIPTION']);
echo $this->formLabel($element);
echo $this->formTextArea($element);
?>
</div>
<div class="form-group">
<?php
$element = $form->get('order');
$element->setAttributes(['class' => 'form-control']);
$element->setOptions(['label' => 'LABEL_ORDER']);
echo $this->formLabel($element);
echo $this->formText($element);
?>
</div>
<div class="form-group">
<?php
$element = $form->get('file');
$element->setOptions(['label' => 'LABEL_IMAGE']);
echo $this->formLabel($element);
?>
<div class="file-loading">
<?php
$element->setAttributes(['class' => 'form-control', 'accept' => 'image/jpg,image/jpeg,image/png']);
echo $this->formFile($element);
?>
</div>
</div>
<div class="form-group">
<?php
$element = $form->get('status');
$element->setAttributes(['class' => 'form-control']);
$element->setOptions(['label' => 'LABEL_STATUS']);
echo $this->formLabel($element);
echo $this->formSelect($element);
?>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
<button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
</div>
<?php echo $this->form()->closeTag($form); ?>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
<!-- The Modal -->
<!-- The Modal -->
<div class="modal" id="modalImageApp">
<div class="modal-dialog ">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">LABEL_IMAGE</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body text-center">
<img src="" class="img img-responsive" style="width: 300px; height: auto" id="image-app" />
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>