File manager - Edit - /home/gzbnyc5/pty-app/realstate/public/js/pty.v2.dropzone.js
Back
"use strict"; // Class definition var KTAppDropZone = (function () { let existingFiles; let form; // Private functions const initForm = (files) => { existingFiles = files; form = document.querySelector("#kt_page_add_form"); // Init dropzone initDropzone(); }; // Init dropzone const initDropzone = () => { const el = form; const uploadUrl = viewUrls["upload-file"]; const deleteUrl = viewUrls["delete-file"]; const formDropZone = el.querySelector("#kt_form_attachment"); const inputTarget = el.querySelector(formDropZone.dataset.inputTarget); const maxFiles = formDropZone.dataset.maxFiles ? Number(formDropZone.dataset.maxFiles) : 10; const modelId = el.querySelector('[name="model_id"]').value; const myDropzone = new Dropzone("#kt_form_attachment", { headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content") }, url: uploadUrl, paramName: "file", maxFiles, maxFilesize: 10, // MB addRemoveLinks: true, init: function () { if (existingFiles && existingFiles.length > 0) { for (const file of existingFiles) { const existingFile = { name: file.originalName, size: file.size, type: file.type, accepted: true, serverResponse: { file: { id: file.id, name: file.path, }, }, }; this.files.push(existingFile); this.emit("addedfile", existingFile); if (file.type.indexOf("image") >= 0) { this.emit( "thumbnail", existingFile, viewUrls["download-file"] + `?fileName=${encodeURIComponent(file.path)}` ); } this.emit("complete", existingFile); this.emit("success", existingFile, existingFile.serverResponse); } } }, accept: function (file, done) { done(); }, success(file, response) { file.serverResponse = response; updateDropzoneInput(inputTarget, file, true); if (file.previewElement) { var a = document.createElement("a"); a.setAttribute( "href", viewUrls["download-file"] + `?fileName=${encodeURIComponent(response.file.name)}` ); a.setAttribute("target", "_blank"); a.innerHTML = "<br>Download"; file.previewTemplate.appendChild(a); return file.previewElement.classList.add("dz-success"); } }, removedfile(file) { console.log({ file, id: file.serverResponse.file.id, fileName: file.serverResponse.file.name, }); $.ajax({ url: deleteUrl, dataType: "JSON", type: "POST", data: { id: file.serverResponse.file.id, file_name: file.serverResponse.file.name, model_id: modelId, }, success: function (response, status, xhr, $form) { if ( file.previewElement != null && file.previewElement.parentNode != null ) { file.previewElement.parentNode.removeChild(file.previewElement); } updateDropzoneInput(inputTarget, file, false); }, error: function (error) {}, }); }, }); myDropzone.on("sending", function (file, xhr, formData) { formData.append("model_id", modelId); }); }; const updateDropzoneInput = (target, file, adding) => { const currentValue = target.value; const currentImages = currentValue.length === 0 ? [] : JSON.parse(currentValue); if (adding) { currentImages.push({ id: file.serverResponse.file.id, original_name: file.serverResponse.file.original_name, name: file.serverResponse.file.name, ext: file.serverResponse.file.ext, type: file.serverResponse.file.type, }); } else { const indexToDelete = currentImages .map((image) => image.name) .indexOf(file.serverResponse.file.name); currentImages.splice(indexToDelete, 1); } target.value = JSON.stringify(currentImages); }; // Public methods return { init: function (files) { console.log("Dropzone files", { files }); initForm(files); }, }; })(); // On document ready KTUtil.onDOMContentLoaded(function () {});
| ver. 1.4 |
Github
|
.
| PHP 8.2.31 | Generation time: 0 |
proxy
|
phpinfo
|
Settings