chore: version inicial del codigo fuente del LMS Estafeta
This commit is contained in:
@@ -0,0 +1,588 @@
|
||||
<section class="py-md-4 py-2 border-bottom border-secondary">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h1 class="text-secondary font-weight-bolder">Categorias</h1>
|
||||
<p>Sistema de gestión de categorias, se pueden agregar categorias, desactivar categorias y modificar categorias.</p>
|
||||
<p>Una categoría puede contener cero o mas recursos.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="py-md-4 py-2 controller">
|
||||
<div class="container-fluid">
|
||||
<div class="row align-items-center align-self-center">
|
||||
<div class="col-12">
|
||||
<table id="datatable" class="display table table-striped table-bordered" cellspacing="0" width="100%">
|
||||
<thead>
|
||||
<tr></tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="py-md-4 py-2 editor" style="display: none;">
|
||||
<div class="container-fluid">
|
||||
<div class="row align-items-center justify-content-start">
|
||||
<div class="col-12 text-left my-4">
|
||||
<h3 class="title-cat edit" style="display: none;">Editar Categoría</h3>
|
||||
<h3 class="title-cat crear" style="display: none;">Crear Categoría</h3>
|
||||
</div>
|
||||
<div class="col-12 col-md-10">
|
||||
<form class="formcontroller">
|
||||
<input type="hidden" name="idcat" id="idcat" value="">
|
||||
<input type="hidden" name="urlimgcat" id="urlimgcat" value="">
|
||||
<div class="form-group row">
|
||||
<label for="catsuperior" class="col-md-2 col-12 col-form-label">Categoría superior</label>
|
||||
<div class="col-8">
|
||||
<select id="catsuperior" name="catsuperior" class="col-12 selectpicker" data-live-search="true" required="required">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-md-2 col-12 col-form-label" for="nombre">Nombre</label>
|
||||
<div class="col-8">
|
||||
<textarea id="nombre" name="nombre" cols="40" rows="5" class="form-control" required="required"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="desc" class="col-md-2 col-12 col-form-label">Descripción</label>
|
||||
<div class="col-8">
|
||||
<textarea id="desc" name="desc" cols="40" rows="5" class="form-control"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="clave" class="col-md-2 col-12 col-form-label">Clave</label>
|
||||
<div class="col-8">
|
||||
<input id="clave" name="clave" placeholder="clave" type="text" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="habilitado" class="col-md-2 col-12 col-form-label">Habilitado</label>
|
||||
<div class="col-8">
|
||||
<select id="habilitado" name="habilitado" class="custom-select" required="required">
|
||||
<option value="1">SI</option>
|
||||
<option value="0">No</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="order" class="col-md-2 col-12 col-form-label">Orden del módulo</label>
|
||||
<div class="col-8">
|
||||
<input id="order" name="order" placeholder="Orden módulo" type="number" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-md-2 col-12 col-form-label">Imagen</label>
|
||||
<div class="col-8">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-6 py-2 py-md-0">
|
||||
<div class="UppyDragDrop"></div>
|
||||
<div class="w-100 my-3">
|
||||
<div class="for-ProgressBar"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-md-6 py-2 py-md-0 preview" style="display: none;">
|
||||
<div class="card h-100">
|
||||
<div class="card-body text-center">
|
||||
<div class="ThumbnailGenerator"></div>
|
||||
<div class="uploaded-files text-secondary">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row justify-content-center">
|
||||
<div class="col-12 col-md-6 text-right">
|
||||
<div class="btn btn-warning btn_cancelar">Cancelar</div>
|
||||
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Enviar</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<script type="text/javascript">
|
||||
$(".layer-load").show();
|
||||
var table;
|
||||
var categoriasList = [];
|
||||
jQuery(document).ready(function ($) {
|
||||
function parseJSON(resp) {
|
||||
if (resp == null) return null;
|
||||
if (typeof resp === 'object') return resp;
|
||||
try { return JSON.parse(resp); }
|
||||
catch (e) { console.error('Respuesta no-JSON del servidor:', String(resp).substring(0, 300)); return null; }
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************/
|
||||
/****************** UPLOAD ********************************************/
|
||||
/**********************************************************************/
|
||||
var uppy = Uppy.Core({
|
||||
debug: false,
|
||||
autoProceed: true,
|
||||
allowMultipleUploads: true,
|
||||
locale: Uppy.locales.Spanish,
|
||||
restrictions: {
|
||||
allowedFileTypes: ['image/*']
|
||||
}
|
||||
});
|
||||
uppy.use(Uppy.DragDrop, {
|
||||
target: '.UppyDragDrop',
|
||||
locale: {
|
||||
strings: {
|
||||
browse: 'Buscar',
|
||||
dropHereOr: "Arrastra el archivo aqu\xed o %{browse}",
|
||||
dropHint: "Arrastra el archivo aqu\xed",
|
||||
dropPaste: "Arrastra el archivo aqu\xed, pegar o %{browse}",
|
||||
dropPasteImport: "Arrastra el archivo aqu\xed, pegar, %{browse} o importar desde",
|
||||
}
|
||||
}
|
||||
}).use(Uppy.XHRUpload, {
|
||||
headers: { 'X-CSRF-Token': window.CSRF_TOKEN },
|
||||
endpoint: "categorias_upload.php",
|
||||
formData: true,
|
||||
method: 'post',
|
||||
fieldName: 'files[]'
|
||||
}).use(Uppy.ProgressBar, { target: '.for-ProgressBar', hideAfterFinish: false }).on('upload-success', function (file, response) { onUploadSuccess(file, response) });
|
||||
|
||||
function onUploadSuccess(file, response) {
|
||||
if (response.uploadURL) {
|
||||
var url = response.uploadURL;
|
||||
$("#urlimgcat").val(url);
|
||||
var fileName = file.name;
|
||||
$(".preview").show();
|
||||
$(".uploaded-files").show().addClass('newimg');
|
||||
$(".uploaded-files").html("");
|
||||
$(".uploaded-files").html('<a class="btn-link" href="' + response.uploadURL + '" target="_blank">' +
|
||||
'<img class="img-fluid" src="' + response.uploadURL + '"><br>' + fileName + '</a>');
|
||||
} else {
|
||||
Swal.fire(
|
||||
'',
|
||||
response.body.txt,
|
||||
'error'
|
||||
)
|
||||
uppy.reset();
|
||||
}
|
||||
}
|
||||
/**********************************************************************/
|
||||
/****************** DATATABLE *****************************************/
|
||||
/**********************************************************************/
|
||||
function getData() {
|
||||
listadoDeCategorias();
|
||||
$("#datatable").html('<thead><tr></tr></thead>');
|
||||
$.ajax({
|
||||
url: 'categorias.php',
|
||||
cache: false
|
||||
}).done(function (data) {
|
||||
var _data = JSON.parse(data);
|
||||
var tableName = "#datatable";
|
||||
var str;
|
||||
$.each(_data.columns, function (k, colObj) {
|
||||
str = '<th>' + colObj + '</th>';
|
||||
$(str).appendTo(tableName + '>thead>tr');
|
||||
});
|
||||
|
||||
table = $('#datatable').DataTable({
|
||||
dom: "Bfrtip",
|
||||
responsive: true,
|
||||
"drawCallback": function (settings) {
|
||||
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||||
addEventsCheck();
|
||||
|
||||
|
||||
$("#datatable td").each(function(index, el) {
|
||||
var txt = $.trim($(this).text());
|
||||
if (txt === "" || txt.indexOf("http") < 0) {
|
||||
return;
|
||||
}
|
||||
if (/\.(jpe?g|png|gif|webp|bmp|svg)(\?.*)?$/i.test(txt)) {
|
||||
$(this).html("<div class='text-center'><a href='" + txt + "' target='_blank'>" +
|
||||
"<img style='width:150px; max-width:100%; display:block; margin:0 auto;' src='" + txt + "' class='listimg p-3'></a></div>");
|
||||
} else if (txt.indexOf(".mp4") >= 0) {
|
||||
$(this).html("<div class='openanimacion text-center' style='cursor:pointer;' onclick='window.open(\"" + txt + "\");'>" +
|
||||
"<img style='width:150px; max-width:100%; display:block; margin:0 auto;' src='../img/icons/008-film.png' class='listimg p-3'></div>");
|
||||
} else {
|
||||
$(this).html("<div class='openanimacion text-center' style='cursor:pointer;' onclick='window.open(\"" + txt + "\");'>" +
|
||||
"<img style='width:150px; max-width:100%; display:block; margin:0 auto;' src='../img/icons/214-worldwide.png' class='listimg p-3'></div>");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
buttons: [{
|
||||
extend: 'excel',
|
||||
text: 'Exportar a Excel'
|
||||
},
|
||||
{
|
||||
text: 'Editar',
|
||||
action: function (e, dt, node, config) {
|
||||
editar(e, dt, node, config);
|
||||
},
|
||||
attr: {
|
||||
id: 'btn_edit'
|
||||
}
|
||||
},
|
||||
{
|
||||
text: 'Alternar habilitar',
|
||||
action: function (e, dt, node, config) {
|
||||
deshabilitar(e, dt, node, config)
|
||||
},
|
||||
attr: {
|
||||
id: 'btn_habilitar'
|
||||
}
|
||||
},
|
||||
{
|
||||
text: 'Crear',
|
||||
action: function (e, dt, node, config) {
|
||||
crear();
|
||||
},
|
||||
attr: {
|
||||
id: 'btn_crear'
|
||||
}
|
||||
}
|
||||
|
||||
],
|
||||
'columnDefs': [{
|
||||
'targets': 0,
|
||||
'checkboxes': { 'selectRow': true }
|
||||
}],
|
||||
|
||||
'order': [
|
||||
[1, 'asc']
|
||||
],
|
||||
data: _data.datos,
|
||||
"language": {
|
||||
"url": "../json/Spanish.json"
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$(".layer-load").hide();
|
||||
})
|
||||
.fail(function () {
|
||||
|
||||
})
|
||||
.always(function () {
|
||||
table.columns.adjust().draw();
|
||||
$(window).resize(function (event) {
|
||||
/* Act on the event */
|
||||
table.columns.adjust().draw();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function reloadData() {
|
||||
listadoDeCategorias();
|
||||
$.ajax({
|
||||
url: 'categorias.php',
|
||||
cache: false
|
||||
})
|
||||
.done(function (data) {
|
||||
var NewlyCreatedData = JSON.parse(data);
|
||||
table.clear();
|
||||
table.rows.add(NewlyCreatedData.datos); // Add new data
|
||||
table.columns.adjust().draw(); // Redraw the DataTable
|
||||
table.column(0).checkboxes.deselectAll();
|
||||
})
|
||||
.fail(function () {
|
||||
//console.log("error");
|
||||
})
|
||||
.always(function () {
|
||||
//console.log("complete");
|
||||
});
|
||||
}
|
||||
|
||||
function addEventsCheck() {
|
||||
$("#datatable_wrapper input[type='checkbox']").on('change', function (e) {
|
||||
setTimeout(function (){
|
||||
console.log($("#datatable_wrapper input[type='checkbox']:checked").length);
|
||||
if (table.column(0).checkboxes.selected().length == 0) {
|
||||
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||||
} else if (table.column(0).checkboxes.selected().length == 1) {
|
||||
$("#btn_edit, #btn_habilitar").removeClass('disabled');
|
||||
} else if (table.column(0).checkboxes.selected().length > 1) {
|
||||
$("#btn_edit").addClass('disabled');
|
||||
$("#btn_habilitar").removeClass('disabled');
|
||||
}
|
||||
}, 150);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************/
|
||||
/****************** Editar, Deshabilitar, Crear ***********************/
|
||||
/**********************************************************************/
|
||||
|
||||
function listadoDeCategorias() {
|
||||
$(".layer-load").show();
|
||||
$.ajax({
|
||||
url: 'categorias_list.php',
|
||||
type: 'POST'
|
||||
})
|
||||
.done(function (response) {
|
||||
var _data = parseJSON(response);
|
||||
if (_data.code == "1") {
|
||||
categoriasList = _data.datos;
|
||||
$("#catsuperior").html("");
|
||||
$("#catsuperior").append('<option value="0">Raíz</option>');
|
||||
var _padres = _.filter(_data.datos, function (n) {
|
||||
return n.padre == 0;
|
||||
});
|
||||
$.each(_padres, function (index, val) {
|
||||
$("#catsuperior").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||||
});
|
||||
} else {
|
||||
categoriasList = [];
|
||||
$("#catsuperior").html('<option value="0">Raíz</option>');
|
||||
}
|
||||
|
||||
$('#catsuperior').selectpicker('render');
|
||||
$("#catsuperior").selectpicker('refresh');
|
||||
$(".layer-load").hide();
|
||||
})
|
||||
.fail(function () {
|
||||
|
||||
})
|
||||
.always(function () {
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function editar(e, dt, node, config) {
|
||||
var $table = table.table().node();
|
||||
var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
|
||||
$($chkbox_checked).closest('tr')
|
||||
var data = table.row($($chkbox_checked).closest('tr')).data();
|
||||
$("#idcat").val(data[0]);
|
||||
|
||||
var catId = parseInt(data[0], 10);
|
||||
var padreId = null;
|
||||
$.each(categoriasList, function (i, c) {
|
||||
if (parseInt(c.id, 10) === catId) {
|
||||
padreId = parseInt(c.padre, 10) || 0;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (padreId === null) {
|
||||
var nombrePadre = $.trim(data[1]);
|
||||
if (nombrePadre === 'Raiz' || nombrePadre === 'Raíz') {
|
||||
padreId = 0;
|
||||
} else {
|
||||
$('#catsuperior option').each(function () {
|
||||
if ($.trim($(this).text()) === nombrePadre) {
|
||||
padreId = $(this).val();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (padreId !== null) {
|
||||
$('#catsuperior').selectpicker('val', String(padreId));
|
||||
$('#catsuperior').selectpicker('refresh');
|
||||
}
|
||||
$("#clave").val(data[2]);
|
||||
//$("#nombre").val(data[3]);
|
||||
//$("#desc").val(data[5]);
|
||||
$("#nombre").val(data[3]);
|
||||
$("#nombre").trumbowyg('html',data[3]);
|
||||
$("#desc").val(data[5]);
|
||||
$("#desc").trumbowyg('html',data[5]);
|
||||
|
||||
$("#habilitado").val(data[6]);
|
||||
if (data[4] != null && data[4] !== "") {
|
||||
var name = String(data[4]).split('/');
|
||||
$(".preview").show();
|
||||
$(".uploaded-files").show().html('<a class="btn-link" href="' + data[4] + '" target="_blank">' +
|
||||
'<img class="img-fluid" src="' + data[4] + '"><br>' + name[name.length - 1] + '</a>');
|
||||
$("#urlimgcat").val(data[4]);
|
||||
} else {
|
||||
$(".preview").hide();
|
||||
$(".uploaded-files").html("");
|
||||
$("#urlimgcat").val("");
|
||||
}
|
||||
|
||||
$("#order").val(data[7]);
|
||||
|
||||
$(".newimg").removeClass('newimg');
|
||||
$(".controller").hide();
|
||||
$(".editor").show();
|
||||
$(".edit").show();
|
||||
$(".crear").hide();
|
||||
}
|
||||
|
||||
function deshabilitar(e, dt, node, config) {
|
||||
var rows_selected = table.column(0).checkboxes.selected();
|
||||
|
||||
var ids = new Array();
|
||||
$.each(rows_selected, function (index, rowId) {
|
||||
ids.push(rowId);
|
||||
});
|
||||
$(".layer-load").show();
|
||||
$.ajax({
|
||||
url: 'categorias_delete.php',
|
||||
type: 'POST',
|
||||
data: { ids: ids },
|
||||
})
|
||||
.done(function (response) {
|
||||
Swal.fire({
|
||||
html: response,
|
||||
icon: "success",
|
||||
onBeforeOpen: function () {},
|
||||
onOpen: function () {},
|
||||
onRender: function () {},
|
||||
onClose: function () {
|
||||
reloadData();
|
||||
},
|
||||
onAfterClose: function () {}
|
||||
});
|
||||
})
|
||||
.fail(function () {
|
||||
|
||||
})
|
||||
.always(function () {
|
||||
$(".layer-load").hide();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
function crear() {
|
||||
listadoDeCategorias();
|
||||
|
||||
$("#idcat").val("");
|
||||
$("#nombre").val("");
|
||||
$("#desc").val("");
|
||||
$('#nombre').trumbowyg('empty');
|
||||
$('#desc').trumbowyg('empty');
|
||||
$("#urlimgcat").val("");
|
||||
$("#clave").val("");
|
||||
$("#habilitado").val(1);
|
||||
$("#catsuperior").val('0');
|
||||
$('#catsuperior').selectpicker('val','0');
|
||||
$(".newimg").removeClass('newimg');
|
||||
$(".controller").hide();
|
||||
$(".editor").show();
|
||||
$(".edit").hide();
|
||||
$(".crear").show();
|
||||
}
|
||||
$(".btn_cancelar").click(function (event) {
|
||||
//TODO Mejorar si un usuario subio, pero al fin se arrepiente
|
||||
$(".newimg").removeClass('newimg');
|
||||
if ($(".uploaded-files").hasClass('newimg')) {
|
||||
$(".layer-load").show();
|
||||
$.ajax({
|
||||
url: 'categorias_deletefile.php',
|
||||
type: 'POST',
|
||||
data: { file: $(".uploaded-files a").attr('href') },
|
||||
})
|
||||
.done(function (response) {
|
||||
|
||||
})
|
||||
.fail(function (error) {
|
||||
|
||||
})
|
||||
.always(function () {
|
||||
|
||||
$(".layer-load").hide();
|
||||
$(".preview").hide();
|
||||
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||
uppy.reset();
|
||||
$(".controller").show();
|
||||
$(".editor").hide();
|
||||
$(".uploaded-files").removeClass('newimg');
|
||||
});
|
||||
} else {
|
||||
$(".preview").hide();
|
||||
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||
uppy.reset();
|
||||
$(".preview").hide();
|
||||
$(".controller").show();
|
||||
$(".editor").hide();
|
||||
}
|
||||
});
|
||||
$(".formcontroller").validate({
|
||||
submitHandler: function (form) {
|
||||
|
||||
var controller = 'categorias_upadate.php';
|
||||
if ($(".crear").css("display") == "block") {
|
||||
controller = 'categorias_add.php';
|
||||
}
|
||||
$.ajax({
|
||||
url: controller,
|
||||
type: 'POST',
|
||||
data: $(".formcontroller").serializeArray(),
|
||||
})
|
||||
.done(function (response) {
|
||||
//console.log("success");
|
||||
Swal.fire({
|
||||
html: response,
|
||||
icon: 'success',
|
||||
onBeforeOpen: function () {},
|
||||
onOpen: function () {},
|
||||
onRender: function () {},
|
||||
onClose: function () {
|
||||
$(".preview").hide();
|
||||
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||
uppy.reset();
|
||||
$(".preview").hide();
|
||||
$(".controller").show();
|
||||
$(".editor").hide();
|
||||
reloadData();
|
||||
$(".mainseccion").load("categorias.html", function () {
|
||||
$(".layer-load").hide();
|
||||
});
|
||||
},
|
||||
onAfterClose: function () {}
|
||||
});
|
||||
})
|
||||
.fail(function () {
|
||||
//console.log("error");
|
||||
})
|
||||
.always(function () {
|
||||
//console.log("complete");
|
||||
});
|
||||
},
|
||||
rules: {
|
||||
nombre: {
|
||||
required: true,
|
||||
maxlength: 254,
|
||||
minlength: 7
|
||||
}
|
||||
},
|
||||
messages: {
|
||||
nombre: {
|
||||
required: "El nombre de categoría es obligatorio",
|
||||
minlength: jQuery.validator.format("El nombre de categoría es de al menos {0} caracteres"),
|
||||
maxlength: jQuery.validator.format("El nombre de categoría es de máximo {0} digitos"),
|
||||
number: "Solo se aceptan números"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
getData();
|
||||
|
||||
$("#desc, #nombre").trumbowyg({
|
||||
lang: 'es',
|
||||
btns: [
|
||||
['viewHTML'],
|
||||
['formatting'],
|
||||
['strong', 'em', 'del'],
|
||||
['superscript', 'subscript'],
|
||||
['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
|
||||
['unorderedList', 'orderedList'],
|
||||
['removeformat']
|
||||
]
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user