From 60b77453d9c69dd136f4fc93fca1621fdbf55a82 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Sat, 5 Apr 2025 09:40:38 +0200 Subject: [PATCH] resourcePath config value --- .../components/forms/fileUploadDropzone.js | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js b/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js index edfc9bb4..6f2ec78b 100644 --- a/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js +++ b/httpdocs/assets/js/safekat/components/forms/fileUploadDropzone.js @@ -23,7 +23,7 @@ const PREVIEW_TEMPLATE = ` class FileUploadDropzone { - constructor({ domElement, nameId = "presupuesto_id", getUri = null, postUri = null }) { + constructor({ domElement, nameId = "presupuesto_id", getUri = null, postUri = null, resourcePath = "presupuestos" }) { Dropzone.autoDiscover = false; this.domElement = domElement this.jqElement = $(domElement) @@ -35,6 +35,7 @@ class FileUploadDropzone { this.getUri = getUri this.postUri = postUri this.dataPost[nameId] = this.modelId; + this.resourcePath = resourcePath } init() { @@ -58,19 +59,21 @@ class FileUploadDropzone { maxFilesize: 5e+7, // Bytes init: this._handleGetFiles.bind(this) }); - this.dropzone.on("addedfile", function (file) { - if (file.hash) { - var viewButton = Dropzone.createElement("Ver"); - file.previewElement.appendChild(viewButton); - // Listen to the view button click event - viewButton.addEventListener("click", function (e) { - window.open(window.location.protocol + "//" + window.location.host + "/sistema/intranet/presupuestos/" + file.hash, '_blank'); - }); - } - }); + this.dropzone.on("addedfile", this._handleAddedFile.bind(this)); } } - + _handleAddedFile(file) { + if (file.hash) { + var viewButton = Dropzone.createElement("Ver"); + file.previewElement.appendChild(viewButton); + // Listen to the view button click event + viewButton.addEventListener("click", this.onViewButton.bind(this,file)); + } + } + onViewButton(file) { + console.log(window.location.protocol + "//" + window.location.host + this.resourcePath + "/" + file.hash) + window.open(window.location.protocol + "//" + window.location.host + this.resourcePath + "/" + file.hash, '_blank'); + } _getDropzoneFilesFormData() { var files = this.dropzone.files; @@ -146,7 +149,7 @@ class FileUploadDropzone { dropZoneAddFile(mockFile) { this.dropzone.files.push(mockFile); // add to files array this.dropzone.emit("addedfile", mockFile); - this.dropzone.emit("thumbnail", mockFile, window.location.host + "/sistema/intranet/presupuestos/" + mockFile.hash); + this.dropzone.emit("thumbnail", mockFile, window.location.host + "/sistema/intranet/" + this.resourcePath + "/" + mockFile.hash); this.dropzone.emit("complete", mockFile); this.dropzone.options.success.call(this.dropzone, mockFile);