Skip to content

Commit

Permalink
Allow image replacement on a Dropzone of one photo
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jul 13, 2023
1 parent 812a66f commit 894b382
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions web/cobrands/fixmystreet/fixmystreet.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ $.extend(fixmystreet.set_up, {
if ($("html").hasClass("mobile")) {
default_message = translation_strings.upload_default_message_mobile;
}
var prevFile;
var photodrop = new Dropzone($dropzone[0], {
url: '/photo/upload',
paramName: 'photo',
Expand All @@ -822,6 +823,9 @@ $.extend(fixmystreet.set_up, {
},
init: function() {
this.on("addedfile", function(file) {
if (max_photos == 1 && prevFile) {
this.removeFile(prevFile);
}
$('input[type=submit]', $context).prop("disabled", true).removeClass('green-btn');
});
this.on("queuecomplete", function() {
Expand All @@ -839,6 +843,9 @@ $.extend(fixmystreet.set_up, {
l = ids.push(id);
newstr = ids.join(',');
$upload_fileids.val(newstr);
if (max_photos == 1) {
prevFile = file;
}
});
this.on("error", function(file, errorMessage, xhrResponse) {
});
Expand All @@ -847,6 +854,9 @@ $.extend(fixmystreet.set_up, {
var ids = $upload_fileids.val().split(','),
newstr = $.grep(ids, function(n) { return (n!=file.server_id); }).join(',');
$upload_fileids.val(newstr);
if (max_photos == 1) {
prevFile = null;
}
});
this.on("maxfilesexceeded", function(file) {
this.removeFile(file);
Expand Down

0 comments on commit 894b382

Please sign in to comment.