Removing existing photos wip.
This commit is contained in:
@@ -92,6 +92,9 @@
|
||||
|
||||
const editingRealEstate = <%- editingRealEstate %>;
|
||||
$("#editingRealEstate").val(editingRealEstate);
|
||||
|
||||
const realEstatePhotosUrls = <%-JSON.stringify(realEstatePhotosUrls)%>;
|
||||
|
||||
|
||||
// Manual dropzone init
|
||||
const dropzoneOptions = {
|
||||
@@ -113,8 +116,42 @@
|
||||
dictRemoveFile: 'Izbriši ',
|
||||
dictFileTooBig: 'Fajl je prevelik!',
|
||||
dictInvalidFileType: 'Iabrani fajl nije fotografija!',
|
||||
dictMaxFilesExceeded: 'Dostigli ste maksimalan broj fotografija!'
|
||||
};
|
||||
dictMaxFilesExceeded: 'Dostigli ste maksimalan broj fotografija!',
|
||||
init: function () {
|
||||
let fileCountOnServer = realEstatePhotosUrls.length; // The number of files already uploaded
|
||||
this.options.maxFiles = this.options.maxFiles - fileCountOnServer;
|
||||
|
||||
if (editingRealEstate) {
|
||||
for (let i=0; i<realEstatePhotosUrls.length; i++) {
|
||||
let fileName = realEstatePhotosUrls[i].replace("https://storage.cloud.google.com/marketalarm-photos/", "");
|
||||
var mockFile = { name: fileName, size: 12345, type: 'image/jpeg', accepted: true, status: Dropzone.ACCEPTED };
|
||||
this.options.addedfile.call(this, mockFile);
|
||||
this.options.thumbnail.call(this, mockFile, realEstatePhotosUrls[i]);
|
||||
|
||||
this.files.push(mockFile);
|
||||
mockFile.previewElement.classList.add('dz-success');
|
||||
mockFile.previewElement.classList.add('dz-complete');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.on("addedfile", function(event) {
|
||||
while (this.files.length > this.options.maxFiles) {
|
||||
this.removeFile(this.files[0]);
|
||||
}
|
||||
console.log('Files:', this.files);
|
||||
});
|
||||
|
||||
this.on("removedfile", function(event) {
|
||||
let fileCountOnPreview = this.files.length;
|
||||
this.options.maxFiles = 10;
|
||||
this._updateMaxFilesReachedClass();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var photosUploader = new Dropzone('#photos-upload', dropzoneOptions);
|
||||
|
||||
|
||||
@@ -279,6 +316,11 @@
|
||||
|
||||
validate (input);
|
||||
} */
|
||||
|
||||
//
|
||||
console.log('All files:', photosUploader.files);
|
||||
|
||||
|
||||
const addedFiles = photosUploader.files.filter(file => file.status!=="error");
|
||||
const asyncUpload =[];
|
||||
|
||||
@@ -288,6 +330,8 @@
|
||||
|
||||
if (!hasErrors) {
|
||||
await Promise.all(asyncUpload);
|
||||
alert($("#imageUrls").val());
|
||||
|
||||
$("#publishForm").submit();
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user