Dropzone edit opction adadded.
This commit is contained in:
@@ -90,11 +90,10 @@
|
||||
$(document).ready(function(){
|
||||
$('.tabs').tabs();
|
||||
|
||||
const editingRealEstate = <%- editingRealEstate %>;
|
||||
const editingRealEstate = <%- JSON.stringify(editingRealEstate) %>;
|
||||
$("#editingRealEstate").val(editingRealEstate);
|
||||
|
||||
const realEstatePhotosUrls = <%-JSON.stringify(realEstatePhotosUrls)%>;
|
||||
|
||||
const currentRealEstatePhotosUrls = <%-JSON.stringify(realEstatePhotosUrls)%>;
|
||||
|
||||
// Manual dropzone init
|
||||
const dropzoneOptions = {
|
||||
@@ -118,36 +117,32 @@
|
||||
dictInvalidFileType: 'Iabrani fajl nije fotografija!',
|
||||
dictMaxFilesExceeded: 'Dostigli ste maksimalan broj fotografija!',
|
||||
init: function () {
|
||||
let fileCountOnServer = realEstatePhotosUrls.length; // The number of files already uploaded
|
||||
let fileCountOnServer = currentRealEstatePhotosUrls.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/", "");
|
||||
for (let i=0; i<currentRealEstatePhotosUrls.length; i++) {
|
||||
let fileName = currentRealEstatePhotosUrls[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.options.thumbnail.call(this, mockFile, currentRealEstatePhotosUrls[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]);
|
||||
this.removeFile(this.files[0]); //automaticly removing if more then 10 files
|
||||
}
|
||||
console.log('Files:', this.files);
|
||||
});
|
||||
|
||||
this.on("removedfile", function(event) {
|
||||
let fileCountOnPreview = this.files.length;
|
||||
this.options.maxFiles = 10;
|
||||
this.options.maxFiles = 10; //resets allowed number of files
|
||||
this._updateMaxFilesReachedClass();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -313,27 +308,42 @@
|
||||
})
|
||||
for (const input of basicInputInputs ) {
|
||||
alert(input.getAttribute(name));
|
||||
|
||||
validate (input);
|
||||
} */
|
||||
|
||||
//
|
||||
console.log('All files:', photosUploader.files);
|
||||
//Filter all files to exclude ones that are already uploaded during the ad publish
|
||||
//But keep them stored to know that they are not deleted from ad
|
||||
let filesForUpload =[];
|
||||
if(editingRealEstate) {
|
||||
let currentPhotosFilenames = currentRealEstatePhotosUrls.map( url => {
|
||||
return url.replace("https://storage.cloud.google.com/marketalarm-photos/", "");
|
||||
})
|
||||
|
||||
photosUploader.files.map( file => {
|
||||
if ( currentPhotosFilenames.includes(file.name) ) {
|
||||
return $("#imageUrls").val($("#imageUrls").val()+ file.name+"|");
|
||||
} else if (file.status!=="error") {
|
||||
return filesForUpload.push(file);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
photosUploader.files.map( file => {
|
||||
if (file.status!=="error") {
|
||||
return filesForUpload.push(file);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const addedFiles = photosUploader.files.filter(file => file.status!=="error");
|
||||
const asyncUpload =[];
|
||||
|
||||
addedFiles.forEach( file => {
|
||||
const asyncUpload =[];
|
||||
filesForUpload.forEach( file => {
|
||||
asyncUpload.push(generateSignedURL(file));
|
||||
})
|
||||
|
||||
|
||||
if (!hasErrors) {
|
||||
await Promise.all(asyncUpload);
|
||||
alert($("#imageUrls").val());
|
||||
|
||||
$("#publishForm").submit();
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user