diff --git a/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js b/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js index 4741f218..5de39541 100644 --- a/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js +++ b/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js @@ -16,6 +16,8 @@ const PREVIEW_TEMPLATE = `
+ + Descargar @@ -64,14 +66,29 @@ class FileUploadDropzone { this.dropzone.on("addedfile", this._handleAddedFile.bind(this)); } } + _handleAddedFile(file) { if (file.hash) { - var viewButton = Dropzone.createElement("Ver"); + // Botón Ver + const viewButton = Dropzone.createElement("Ver"); 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("Descargar"); + 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');