checking file upload response error and giving an error alert if there is one.
This commit is contained in:
parent
76c75af373
commit
3671f09b1d
2 changed files with 21 additions and 6 deletions
|
|
@ -60,13 +60,19 @@ app.views.PublisherUploader = Backbone.View.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
uploadCompleteHandler: function(id, fileName, response) {
|
uploadCompleteHandler: function(id, fileName, response) {
|
||||||
this.el_info.text(Diaspora.I18n.t('photo_uploader.completed', {file: fileName})).fadeTo(2000, 0);
|
if (response.success){
|
||||||
|
this.el_info.text(Diaspora.I18n.t('photo_uploader.completed', {file: fileName})).fadeTo(2000, 0);
|
||||||
|
|
||||||
var id = response.data.photo.id,
|
var id = response.data.photo.id,
|
||||||
url = response.data.photo.unprocessed_image.url;
|
url = response.data.photo.unprocessed_image.url;
|
||||||
|
|
||||||
this._addFinishedPhoto(id, url);
|
this._addFinishedPhoto(id, url);
|
||||||
this.trigger('change');
|
this.trigger('change');
|
||||||
|
} else {
|
||||||
|
this._cancelPhotoUpload();
|
||||||
|
this.trigger('change');
|
||||||
|
alert(Diaspora.I18n.t('photo_uploader.error', {file: fileName}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// replace the first photo placeholder with the finished uploaded image and
|
// replace the first photo placeholder with the finished uploaded image and
|
||||||
|
|
@ -79,7 +85,7 @@ app.views.PublisherUploader = Backbone.View.extend({
|
||||||
'<input type="hidden", value="'+id+'" name="photos[]" />'
|
'<input type="hidden", value="'+id+'" name="photos[]" />'
|
||||||
);
|
);
|
||||||
|
|
||||||
// replace placeholder
|
// // replace placeholder
|
||||||
var placeholder = publisher.el_photozone.find('li.loading').first();
|
var placeholder = publisher.el_photozone.find('li.loading').first();
|
||||||
placeholder
|
placeholder
|
||||||
.removeClass('loading')
|
.removeClass('loading')
|
||||||
|
|
@ -96,6 +102,14 @@ app.views.PublisherUploader = Backbone.View.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_cancelPhotoUpload: function() {
|
||||||
|
var publisher = this.options.publisher;
|
||||||
|
var placeholder = publisher.el_photozone.find('li.loading').first();
|
||||||
|
placeholder
|
||||||
|
.removeClass('loading')
|
||||||
|
.find('img').remove();
|
||||||
|
},
|
||||||
|
|
||||||
// remove an already uploaded photo
|
// remove an already uploaded photo
|
||||||
_removePhoto: function(evt) {
|
_removePhoto: function(evt) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ en:
|
||||||
photo_uploader:
|
photo_uploader:
|
||||||
looking_good: "OMG, you look awesome!"
|
looking_good: "OMG, you look awesome!"
|
||||||
completed: "<%= file %> completed"
|
completed: "<%= file %> completed"
|
||||||
|
error: "A problem occurred while uploading file <%= file %>"
|
||||||
invalid_ext: "{file} has invalid extension. Only {extensions} are allowed."
|
invalid_ext: "{file} has invalid extension. Only {extensions} are allowed."
|
||||||
size_error: "{file} is too large, maximum file size is {sizeLimit}."
|
size_error: "{file} is too large, maximum file size is {sizeLimit}."
|
||||||
empty: "{file} is empty, please select files again without it."
|
empty: "{file} is empty, please select files again without it."
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue