686 lines
24 KiB
HTML
686 lines
24 KiB
HTML
|
|
<section class="py-md-4 py-2">
|
||
|
|
<div class="container-fluid">
|
||
|
|
<div class="row">
|
||
|
|
<div class="col-12">
|
||
|
|
<h1 class="text-secondary font-weight-bolder">Recursos</h1>
|
||
|
|
<p>Sistema de gestión recursos por categoria, se pueden agregar recursos, desactivar recursos y modificar recursos.</p>
|
||
|
|
<p>Los recursos deben estar empaquetados en scorm 1.2, es muy importante que si es un recurso no calificable se marque como 100% y "completed" al ser visitado dicho recurso.</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 recurso</h3>
|
||
|
|
<h3 class="title-cat crear" style="display: none;">Crear recurso</h3>
|
||
|
|
</div>
|
||
|
|
<div class="col-12 col-md-10">
|
||
|
|
<form class="formcontroller">
|
||
|
|
<input type="hidden" name="idrecurso" id="idrecurso" value="">
|
||
|
|
<input type="hidden" name="urlimgrecurso" id="urlimgrecurso" value="">
|
||
|
|
<div class="form-group row">
|
||
|
|
<label for="catsuperior" class="col-md-2 col-12 col-form-label">Categoría</label>
|
||
|
|
<div class="col-8">
|
||
|
|
<select id="catsuperior" name="catsuperior" required="required" class="form-control col-12" data-live-search="true">
|
||
|
|
</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">
|
||
|
|
<input id="nombre" name="nombre" placeholder="Nombre" type="text" class="form-control" required="required">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label class="col-md-2 col-12 col-form-label" for="nombre">URL</label>
|
||
|
|
<div class="col-8">
|
||
|
|
<input id="url" name="url" placeholder="URL" type="text" class="form-control" required="required">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label class="col-md-2 col-12 col-form-label">Archivo SCORM (.zip)</label>
|
||
|
|
<div class="col-8">
|
||
|
|
<div class="row">
|
||
|
|
<div class="col-12">
|
||
|
|
<p class="text-dark font-weight-bold">Sube el paquete SCORM (.zip). Se descomprimirá en el servidor y la URL de inicio se colocará automáticamente en el campo URL.</p>
|
||
|
|
</div>
|
||
|
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||
|
|
<div class="UppyDragDropScorm"></div>
|
||
|
|
<div class="w-100 my-3">
|
||
|
|
<div class="for-ProgressBarScorm"></div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="col-12 col-md-6 py-2 py-md-0 previewscorm" style="display: none;">
|
||
|
|
<div class="card h-100">
|
||
|
|
<div class="card-body text-center">
|
||
|
|
<div class="uploaded-scorm text-secondary"></div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</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 class="col-md-2 col-12 col-form-label">Imagen</label>
|
||
|
|
<div class="col-8">
|
||
|
|
<div class="row">
|
||
|
|
<div class="col-12">
|
||
|
|
<p class="text-dark font-weight-bold">Se recomienda usar png y un tamaño de 512 x 512 px</p>
|
||
|
|
</div>
|
||
|
|
<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;
|
||
|
|
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: "recursos_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;
|
||
|
|
$("#urlimgrecurso").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();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**********************************************************************/
|
||
|
|
/****************** UPLOAD SCORM (.zip) *******************************/
|
||
|
|
/**********************************************************************/
|
||
|
|
var uppyScorm = Uppy.Core({
|
||
|
|
debug: false,
|
||
|
|
autoProceed: true,
|
||
|
|
allowMultipleUploads: false,
|
||
|
|
locale: Uppy.locales.Spanish,
|
||
|
|
restrictions: {
|
||
|
|
allowedFileTypes: ['.zip', 'application/zip', 'application/x-zip-compressed', 'application/octet-stream'],
|
||
|
|
maxNumberOfFiles: 1
|
||
|
|
}
|
||
|
|
});
|
||
|
|
uppyScorm.use(Uppy.DragDrop, {
|
||
|
|
target: '.UppyDragDropScorm',
|
||
|
|
locale: {
|
||
|
|
strings: {
|
||
|
|
browse: 'Buscar',
|
||
|
|
dropHereOr: "Arrastra el .zip aqu\xed o %{browse}",
|
||
|
|
dropHint: "Arrastra el .zip aqu\xed",
|
||
|
|
dropPaste: "Arrastra el .zip aqu\xed, pegar o %{browse}",
|
||
|
|
dropPasteImport: "Arrastra el .zip aqu\xed, pegar, %{browse} o importar desde",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).use(Uppy.XHRUpload, {
|
||
|
|
headers: { 'X-CSRF-Token': window.CSRF_TOKEN },
|
||
|
|
endpoint: "recursos_scorm_upload.php",
|
||
|
|
formData: true,
|
||
|
|
method: 'post',
|
||
|
|
fieldName: 'files[]'
|
||
|
|
}).use(Uppy.ProgressBar, { target: '.for-ProgressBarScorm', hideAfterFinish: false })
|
||
|
|
.on('upload-success', function (file, response) { onScormSuccess(file, response); })
|
||
|
|
.on('upload-error', function (file, error, response) {
|
||
|
|
Swal.fire('', (response && response.body && response.body.txt) ? response.body.txt : 'Error al subir el SCORM', 'error');
|
||
|
|
uppyScorm.reset();
|
||
|
|
});
|
||
|
|
|
||
|
|
uppyScorm.on('file-added', function (file) {
|
||
|
|
uppyScorm.setFileMeta(file.id, { catid: $("#catsuperior").val() });
|
||
|
|
});
|
||
|
|
|
||
|
|
function onScormSuccess(file, response) {
|
||
|
|
if (response.uploadURL) {
|
||
|
|
$("#url").val(response.uploadURL);
|
||
|
|
$(".previewscorm").show();
|
||
|
|
$(".uploaded-scorm").html('<a class="btn-link" href="' + response.uploadURL + '" target="_blank">' + file.name + '</a><br><small>' + response.uploadURL + '</small>');
|
||
|
|
Swal.fire('', 'Paquete SCORM cargado. La URL se actualizó.', 'success');
|
||
|
|
} else {
|
||
|
|
Swal.fire('', (response.body && response.body.txt) ? response.body.txt : 'Error al subir el SCORM', 'error');
|
||
|
|
uppyScorm.reset();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/**********************************************************************/
|
||
|
|
/****************** DATATABLE *****************************************/
|
||
|
|
/**********************************************************************/
|
||
|
|
function getData() {
|
||
|
|
listadoDeCategorias();
|
||
|
|
$("#datatable").html('<thead><tr></tr></thead>');
|
||
|
|
$.ajax({
|
||
|
|
url: 'recursos.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) {
|
||
|
|
if( $(this).text().indexOf("recursos") >= 0 ){
|
||
|
|
var dummiimg = '<img src="'+ $(this).text() + '" style="width:250px; max-width: 100%;display: block;margin: 0 auto;" class="listimg" >';
|
||
|
|
$(this).html(dummiimg);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
$("#datatable td").each(function(index, el) {
|
||
|
|
if( $(this).text().indexOf("http") >= 0 && $(this).text().indexOf(".mp4") <= 0){
|
||
|
|
var link = decodeURI($(el).html());
|
||
|
|
var dummiimg = "<div class='openanimacion text-center' style='cursor:pointer;' onclick='window.open(`"+ link +"`);' >"+
|
||
|
|
"<img style='width:150px; max-width: 100%;display: block;margin: 0 auto;' src='../img/icons/214-worldwide.png' class='listimg p-3'></div>";
|
||
|
|
$(this).html(dummiimg);
|
||
|
|
}else if($(this).text().indexOf(".mp4") >= 0) {
|
||
|
|
var link = decodeURI($(el).html());
|
||
|
|
var dummiimg = "<div class='openanimacion text-center' style='cursor:pointer;' onclick='window.open(`"+ link +"`);' >"+
|
||
|
|
"<img style='width:150px; max-width: 100%;display: block;margin: 0 auto;' src='../img/icons/008-film.png' class='listimg p-3'></div>";
|
||
|
|
$(this).html(dummiimg);
|
||
|
|
|
||
|
|
|
||
|
|
/*
|
||
|
|
var link = decodeURI($(el).html());
|
||
|
|
var dummiimg = "<div class='openanimacion text-center' style='cursor: pointer;' onclick='window.open(`"+ link +"`);' >"+
|
||
|
|
"<video autoplay muted loop style='width:130px; display: block;margin: 0 auto;' src='"+ $(this).text() + "' class='listimg p-3'></video></div>";
|
||
|
|
$(this).html(dummiimg);
|
||
|
|
*/
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
},
|
||
|
|
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 }
|
||
|
|
}, {
|
||
|
|
'targets': 10,
|
||
|
|
'visible': false
|
||
|
|
}],
|
||
|
|
|
||
|
|
'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: 'recursos.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 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',
|
||
|
|
cache: false
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == "1") {
|
||
|
|
$("#catsuperior").html("");
|
||
|
|
var _padres = _.filter(_data.datos, function (n) {
|
||
|
|
return n.padre == 0;
|
||
|
|
});
|
||
|
|
var _datos = _.groupBy(_data.datos, function (n) {
|
||
|
|
return n.padre;
|
||
|
|
});
|
||
|
|
|
||
|
|
$.each(_padres, function (index, val1) {
|
||
|
|
$("#catsuperior").append('<option disabled style="background-color: #959595; color: white;">' + val1.nombre + '</option>');
|
||
|
|
$.each(_datos, function (index, cats) {
|
||
|
|
$.each(cats, function (index, val) {
|
||
|
|
if (val.padre == val1.id || val.nombre == val1.nombre) {
|
||
|
|
if (val.nombre == val1.nombre) {
|
||
|
|
//$("[label='" + val1.nombre + "']").append('<option class="font-weight-bold" value="' + val.id + '">' + val.nombre + '</option>');
|
||
|
|
} else {
|
||
|
|
$("#catsuperior").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
} else {
|
||
|
|
|
||
|
|
Swal.fire({
|
||
|
|
html: "Sin categorias",
|
||
|
|
icon: "error",
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {
|
||
|
|
$(".btn_cancelar").click();
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
//$('#catsuperior').selectpicker();
|
||
|
|
//if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
|
||
|
|
//$('#catsuperior').selectpicker('mobile');
|
||
|
|
//}
|
||
|
|
|
||
|
|
})
|
||
|
|
.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();
|
||
|
|
$("#idrecurso").val(data[0]);
|
||
|
|
$("#clave").val(data[1]);
|
||
|
|
$("#nombre").val(data[2]);
|
||
|
|
$("#url").val(data[3]);
|
||
|
|
$("#habilitado").val(data[4]);
|
||
|
|
$("#desc").val(data[5]);
|
||
|
|
if (data[6] != null) {
|
||
|
|
var name = String(data[6]).split('/');
|
||
|
|
$(".preview").show();
|
||
|
|
$(".uploaded-files").html('<a class="btn-link" href="' + data[6] + '" target="_blank">' +
|
||
|
|
'<img class="img-fluid" src="' + data[6] + '"><br>' + name[name.length - 1] + '</a>');
|
||
|
|
$("#urlimgrecurso").val(data[6]);
|
||
|
|
}
|
||
|
|
console.log("catsup: "+data[9]);
|
||
|
|
var sel = $("#catsuperior");
|
||
|
|
var catid = (data[10] != null && data[10] !== "") ? String(data[10]) : "";
|
||
|
|
var nombreCat = (data[9] != null) ? $.trim(String(data[9])) : "";
|
||
|
|
sel.val("");
|
||
|
|
if (catid !== "" && sel.find("option[value='" + catid + "']").length) {
|
||
|
|
sel.val(catid);
|
||
|
|
} else {
|
||
|
|
var encontrado = false;
|
||
|
|
sel.find('option').each(function (index, el) {
|
||
|
|
if ($.trim($(this).text()) === nombreCat) {
|
||
|
|
sel.val($(this).attr('value'));
|
||
|
|
encontrado = true;
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
if (!encontrado && catid !== "") {
|
||
|
|
sel.append("<option value='" + catid + "'>" + nombreCat + "</option>");
|
||
|
|
sel.val(catid);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$(".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: 'recursos_delete.php',
|
||
|
|
type: 'POST',
|
||
|
|
data: { ids: ids },
|
||
|
|
cache: false
|
||
|
|
})
|
||
|
|
.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() {
|
||
|
|
|
||
|
|
$("#idrecurso").val("");
|
||
|
|
$("#nombre").val("");
|
||
|
|
$("#desc").val("");
|
||
|
|
$("#urlimgrecurso").val("");
|
||
|
|
$("#clave").val("");
|
||
|
|
$("#habilitado").val(1);
|
||
|
|
$("#url").val('');
|
||
|
|
$(".newimg").removeClass('newimg');
|
||
|
|
$(".controller").hide();
|
||
|
|
$(".editor").show();
|
||
|
|
$(".edit").hide();
|
||
|
|
$(".crear").show();
|
||
|
|
}
|
||
|
|
$(".btn_cancelar").click(function (event) {
|
||
|
|
$(".newimg").removeClass('newimg');
|
||
|
|
$(".previewscorm").hide();
|
||
|
|
$(".uploaded-scorm").html("");
|
||
|
|
uppyScorm.reset();
|
||
|
|
if ($(".uploaded-files").hasClass('newimg')) {
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'recursos_deletefile.php',
|
||
|
|
type: 'POST',
|
||
|
|
data: { file: $(".uploaded-files a").attr('href') },
|
||
|
|
cache: false
|
||
|
|
})
|
||
|
|
.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();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
$.validator.addMethod('validUrl', function(value, element) {
|
||
|
|
var url = $.validator.methods.url.bind(this);
|
||
|
|
var pattern = new RegExp("^(?:https?://|s?ftps?://)?(?!www | www\.)[A-Za-z0-9_-]+\.+[A-Za-z0-9.\/%&=\?_:;-]+$");
|
||
|
|
return pattern.test("http://localhost/git/estafeta-lms360/site/pkg/scorm_check/index.html");
|
||
|
|
}, 'Por favorsss, escribe una URL válida.');
|
||
|
|
|
||
|
|
$(".formcontroller").validate({
|
||
|
|
submitHandler: function (form) {
|
||
|
|
|
||
|
|
var controller = 'recursos_update.php';
|
||
|
|
if ($(".crear").css("display") == "block") {
|
||
|
|
controller = 'recursos_add.php';
|
||
|
|
}
|
||
|
|
$.ajax({
|
||
|
|
url: controller,
|
||
|
|
type: 'POST',
|
||
|
|
data: $(".formcontroller").serializeArray(),
|
||
|
|
cache: false
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
//console.log("success");
|
||
|
|
Swal.fire({
|
||
|
|
html: response,
|
||
|
|
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("recursos.html", function () {
|
||
|
|
$(".layer-load").hide();
|
||
|
|
});
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
//console.log("error");
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
//console.log("complete");
|
||
|
|
});
|
||
|
|
},
|
||
|
|
rules: {
|
||
|
|
nombre: {
|
||
|
|
required: true,
|
||
|
|
maxlength: 254,
|
||
|
|
minlength: 2,
|
||
|
|
normalizer: function( value ) {
|
||
|
|
return $.trim( value );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
url: {
|
||
|
|
required: true,
|
||
|
|
validUrl: true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
getData();
|
||
|
|
|
||
|
|
});
|
||
|
|
</script>
|