mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Añadida funcionalidad de descarga por archivo
This commit is contained in:
@ -16,6 +16,8 @@ const PREVIEW_TEMPLATE = `
|
||||
</div>
|
||||
</div>
|
||||
<div class="dz-filename" data-dz-name></div>
|
||||
<!-- Estilo uniforme con Eliminar / Ver -->
|
||||
<a class="dz-download dz-remove" href="javascript:void(0);" style="text-align:center;">Descargar</a>
|
||||
<div class="dz-size" data-dz-size></div>
|
||||
</div>
|
||||
</div>
|
||||
@ -64,14 +66,29 @@ class FileUploadDropzone {
|
||||
this.dropzone.on("addedfile", this._handleAddedFile.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
_handleAddedFile(file) {
|
||||
if (file.hash) {
|
||||
var viewButton = Dropzone.createElement("<span class='dz-remove'>Ver</span>");
|
||||
// Botón Ver
|
||||
const viewButton = Dropzone.createElement("<a class='dz-remove' style='text-align:center;'>Ver</a>");
|
||||
file.previewElement.appendChild(viewButton);
|
||||
// Listen to the view button click event
|
||||
viewButton.addEventListener("click", this.onViewButton.bind(this, file));
|
||||
|
||||
// Botón Descargar
|
||||
const downloadButton = Dropzone.createElement("<a class='dz-download dz-remove' style='text-align:center;'>Descargar</a>");
|
||||
file.previewElement.appendChild(downloadButton);
|
||||
downloadButton.addEventListener("click", () => {
|
||||
const fileUrl = `${window.location.protocol}//${window.location.host}/sistema/intranet/${this.resourcePath}/${file.hash}`;
|
||||
const a = document.createElement("a");
|
||||
a.href = fileUrl;
|
||||
a.download = file.name;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onViewButton(file) {
|
||||
console.log(window.location.protocol + "//" + window.location.host + "/sistema/intranet/" + this.resourcePath + "/" + file.hash)
|
||||
window.open(window.location.protocol + "//" + window.location.host + "/sistema/intranet/" + this.resourcePath + "/" + file.hash, '_blank');
|
||||
|
||||
Reference in New Issue
Block a user