Dropzone edit opction adadded.

This commit is contained in:
Naida Vatric
2020-03-24 11:10:16 +01:00
parent 477424caa1
commit 3fa9804ca6
24 changed files with 9400 additions and 256 deletions

View File

@@ -19,7 +19,7 @@
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/validate.js/0.13.1/validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.0/dropzone.js"></script>
<script src="/assets/dropzone-5.7.0/dist/dropzone.js"></script>
<script type="text/javascript">
Dropzone.autoDiscover = false;
</script>

View File

@@ -108,7 +108,7 @@
//Move map and marker to already selected position if in editing mode
if( editingRealEstate===true) {
console.log('Editujem mapu!');
setMarkerToLocation(map);
setMarkerToLocation(map, editingRealEstate);
}
//Add event listener to position marker on map
@@ -132,11 +132,15 @@
}
}
function setMarkerToLocation(map) {
const ESTATE_COORDINATES = {
const ESTATE_COORDINATES = ( <%= locationLat %> !==0 && <%= locationLong %> !== 0 ) ?
{
lat: <%= locationLat %>,
lng: <%= locationLong %>
}:
{ lat: 43.85, //Set to Sarajevo if coordinates are not picked
lng: 18.41
};
marker = new google.maps.Marker({
position: ESTATE_COORDINATES,
map: map,

View File

@@ -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();
};
});