BUGFIX: check image size before uploading an avatar/background

This commit is contained in:
Régis Hanol 2014-04-03 19:19:38 +02:00
parent faa341148e
commit 7fd0db857f
2 changed files with 14 additions and 11 deletions

View File

@ -40,11 +40,14 @@ Discourse.AvatarSelectorView = Discourse.ModalBodyView.extend({
});
// when a file has been selected
$upload.on("fileuploadadd", function () {
$upload.on('fileuploadsubmit', function (e, data) {
var result = Discourse.Utilities.validateUploadedFiles(data.files);
self.setProperties({
uploading: true,
uploadProgress: 0,
uploading: result,
imageIsNotASquare: false
});
return result;
});
// when there is a progression for the upload

View File

@ -9,25 +9,27 @@
Discourse.PreferencesView = Discourse.View.extend({
templateName: 'user/preferences',
classNames: ['user-preferences'],
uploading: false,
uploadProgress: 0,
didInsertElement: function() {
var self = this;
var $upload = $("#profile-background-input");
this._super();
$upload.fileupload({
url: Discourse.getURL("/users/" + this.get('controller.model.username') + "/preferences/user_image"),
dataType: "json",
fileInput: $upload,
formData: { user_image_type: "profile_background" }
});
$upload.on("fileuploadadd", function() {
self.set("uploading", true);
$upload.on('fileuploadsubmit', function (e, data) {
var result = Discourse.Utilities.validateUploadedFiles(data.files);
self.setProperties({ uploadProgress: 0, uploading: result });
return result;
});
$upload.on("fileuploadprogressall", function(e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
@ -51,5 +53,3 @@ Discourse.PreferencesView = Discourse.View.extend({
$("#profile-background-input").fileupload("destroy");
}
});