Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.4 kB
3
Indexable
Never
var $sy = -1;
        Dropzone.autoDiscover = false;
        var dropzoneAreas = document.querySelectorAll('.dropzone');
        dropzoneAreas.forEach(function (ths){
            $sy++;
            if (ths.dropzone) {
                return ths.dropzone;
            }
            console.log('run')
            let name = ths.getAttribute('data-name');
            new Dropzone(ths, {
                url: "/yonetim/api/upload", // Set the url for your upload script location
                paramName: "file", // The name that will be used to transfer the file
                maxFiles: 1,
                maxFilesize: 8, // MB
                addRemoveLinks: true,
                acceptedFiles: ".jpeg,.jpg,.png,.gif",
                init: function (){
                    let ths = this;
                    this.on("maxfilesexceeded", function (file) {
                        this.removeFile(file);
                        Swal.fire({ text: "Bu alana yalnızca 1 adet dosya yüklenebilir. Farklı bir dosya eklemek için mevcut dosyayı kaldırın.", icon: "error", buttonsStyling: false, confirmButtonText: "Tamam", customClass: { confirmButton: "btn btn-primary" }
                        });
                    });
                    this.on("sending", function(file, xhr, formData) {
                        formData.append("type", "image");
                        formData.append("uploadPlugin", "dropzone");
                        formData.append("path", "personnel/");
                        formData.append("maxResize", '2000');
                        formData.append("file_name", generateUUID()+d);
                    });

                    this.on('addfileinput',function(file){
                        file.upload = {
                            uuid: Dropzone.uuidv4(),
                            progress: 0,
                            total: file.size,
                            bytesSent: 0,
                            url: file.url,
                            filename: ths._renameFile(file),
                        };
                        this.files.push(file);
                    })
                },
                accept: function (file, done) {
                    done();
                    $(ths).find('input').val()
                },
                success: function (file, response){
                    if (response.status){
                        $(file.previewElement).append('<input type="hidden" name="'+name+'" value=\'' + JSON.stringify(response.dropzone) + '\' data-uuid="' + file.upload.uuid + '">')
                    }
                },
                removedfile: function (file){
                    file.previewElement.remove();
                }
            });


            if (typeof identityImage !== "undefined" && identityImage != null){
                let k = identityImage;
                let file = { name: k.name, size: k.size, type: k.type, status: Dropzone.ADDED, accepted: true };
                ths.dropzone.emit("addedfile", file);
                ths.dropzone.emit("thumbnail", file, k.url)
                ths.dropzone.emit("complete", file);
                ths.dropzone.emit("addfileinput", file);
                $(ths).find('.dz-preview:eq(0)').append('<input type="hidden" name="'+name+'" value=\'' + JSON.stringify(k) + '\'>')
            }


        });