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 // 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({ self.setProperties({
uploading: true, uploadProgress: 0,
uploading: result,
imageIsNotASquare: false imageIsNotASquare: false
}); });
return result;
}); });
// when there is a progression for the upload // when there is a progression for the upload

View File

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