mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
fix dropzone when presupuesto is borrador
This commit is contained in:
@ -25,6 +25,7 @@ export const alertSuccessMessage = (title,type="primary") => {
|
||||
showConfirmButton : false,
|
||||
title: title,
|
||||
text: title,
|
||||
icon: "success"
|
||||
icon: "success",
|
||||
timer : 2000
|
||||
})
|
||||
}
|
||||
@ -38,25 +38,37 @@ class FileUploadDropzone {
|
||||
|
||||
}
|
||||
init() {
|
||||
this.btnSubmitFile.on('click', this._handleUploadFiles.bind(this))
|
||||
this.btnSelectFiles.on('click', () => {
|
||||
this.jqElement.trigger('click')
|
||||
})
|
||||
if (this.jqElement.length > 0) {
|
||||
this.btnSubmitFile.on('click', this._handleUploadFiles.bind(this))
|
||||
this.btnSelectFiles.on('click', () => {
|
||||
this.jqElement.trigger('click')
|
||||
})
|
||||
|
||||
this.dropzone = new Dropzone(this.domElement, {
|
||||
url: this.postUri,
|
||||
addRemoveLinks: true,
|
||||
previewTemplate: PREVIEW_TEMPLATE,
|
||||
paramName: "file",
|
||||
uploadMultiple: true,
|
||||
parallelUploads: 4, // Ajusta este número al máximo número de archivos que esperas subir a la vez
|
||||
maxFiles: 5, // Ajusta este número al máximo número de archivos que esperas subir a la vez
|
||||
autoProcessQueue: true,
|
||||
dictRemoveFile: "Eliminar",
|
||||
acceptedFiles: 'image/*, application/pdf',
|
||||
maxFilesize: 5e+7, // Bytes
|
||||
init: this._handleGetFiles.bind(this)
|
||||
});
|
||||
this.dropzone = new Dropzone(this.domElement, {
|
||||
url: this.postUri,
|
||||
addRemoveLinks: true,
|
||||
previewTemplate: PREVIEW_TEMPLATE,
|
||||
paramName: "file",
|
||||
uploadMultiple: true,
|
||||
parallelUploads: 4, // Ajusta este número al máximo número de archivos que esperas subir a la vez
|
||||
maxFiles: 5, // Ajusta este número al máximo número de archivos que esperas subir a la vez
|
||||
autoProcessQueue: true,
|
||||
dictRemoveFile: "Eliminar",
|
||||
acceptedFiles: 'image/*, application/pdf',
|
||||
maxFilesize: 5e+7, // Bytes
|
||||
init: this._handleGetFiles.bind(this)
|
||||
});
|
||||
this.dropzone.on("addedfile", function (file) {
|
||||
if (file.hash) {
|
||||
var viewButton = Dropzone.createElement("<span class='dz-remove'>Ver</span>");
|
||||
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');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_getDropzoneFilesFormData() {
|
||||
@ -82,6 +94,7 @@ class FileUploadDropzone {
|
||||
return formData;
|
||||
}
|
||||
_handleUploadFiles() {
|
||||
$("#loader").modal('show')
|
||||
let ajax = new Ajax(this.postUri,
|
||||
this._getDropzoneFilesFormData(),
|
||||
null,
|
||||
@ -91,12 +104,13 @@ class FileUploadDropzone {
|
||||
|
||||
}
|
||||
_handleUploadFilesSuccess(response) {
|
||||
this.dropZoneClean()
|
||||
this._handleGetFiles()
|
||||
alertSuccessMessage(response?.message ?? "Archivos subidos correctamente");
|
||||
}
|
||||
_handleUploadFilesError(errors) { }
|
||||
|
||||
_handleGetFiles() {
|
||||
|
||||
const ajax = new Ajax(
|
||||
this.getUri,
|
||||
this.dataPost,
|
||||
@ -108,26 +122,27 @@ class FileUploadDropzone {
|
||||
ajax.post()
|
||||
}
|
||||
_handelGetFilesSuccess(response) {
|
||||
const files = JSON.parse(response)
|
||||
this.dropZoneUpdateFiles(files)
|
||||
try {
|
||||
$("#loader").modal('hide')
|
||||
const files = JSON.parse(response)
|
||||
this.dropZoneUpdateFiles(files)
|
||||
} catch (error) {
|
||||
$("#loader").modal('hide')
|
||||
}
|
||||
}
|
||||
|
||||
dropZoneUpdateFiles(files) {
|
||||
this.dropzone.on("addedfile", function (file) {
|
||||
if (file.hash) {
|
||||
var viewButton = Dropzone.createElement("<span class='dz-remove'>Ver</span>");
|
||||
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');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
files.forEach(file => {
|
||||
this.dropZoneAddFile(file)
|
||||
});
|
||||
|
||||
}
|
||||
dropZoneClean() {
|
||||
this.dropzone.files.forEach(file => {
|
||||
this.dropzone.removeFile(file);
|
||||
})
|
||||
}
|
||||
dropZoneAddFile(mockFile) {
|
||||
this.dropzone.files.push(mockFile); // add to files array
|
||||
this.dropzone.emit("addedfile", mockFile);
|
||||
|
||||
@ -61,7 +61,9 @@ class PresupuestoAdminEdit {
|
||||
getUri: '/presupuestos/presupuestocliente/get_files',
|
||||
postUri: '/presupuestos/presupuestocliente/upload_files'
|
||||
}
|
||||
this.fileUploadDropzone = new FileUploadDropzone(this.configUploadDropzone)
|
||||
if ($(this.configUploadDropzone.domElement).length > 0) {
|
||||
this.fileUploadDropzone = new FileUploadDropzone(this.configUploadDropzone)
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
@ -128,7 +130,9 @@ class PresupuestoAdminEdit {
|
||||
|
||||
$('#lomo_cubierta').on('change', this.datosLibro.changeAnchoSolapasCubierta);
|
||||
$('#lomo_sobrecubierta').on('change', this.datosLibro.changeAnchoSolapasSobrecubierta);
|
||||
this.fileUploadDropzone.init()
|
||||
if ($(this.configUploadDropzone.domElement).length > 0) {
|
||||
this.fileUploadDropzone.init()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user