summaryrefslogtreecommitdiffstats
path: root/client/components/users/userAvatar.js
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-08-28 19:08:54 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-08-28 19:08:54 +0200
commit53018baeb2dd04d053dbb2c4fd872a9f28505f95 (patch)
treef4e1b5a4ff06494b925cdc4987cd6a592120ab0d /client/components/users/userAvatar.js
parentdc3cbdd20e59c2cc92a4acfeb1230ce71ac4a7c1 (diff)
downloadwekan-53018baeb2dd04d053dbb2c4fd872a9f28505f95.tar.gz
wekan-53018baeb2dd04d053dbb2c4fd872a9f28505f95.tar.bz2
wekan-53018baeb2dd04d053dbb2c4fd872a9f28505f95.zip
Increase the avatar max size and show an error if it is too big
Fixes #190
Diffstat (limited to 'client/components/users/userAvatar.js')
-rw-r--r--client/components/users/userAvatar.js45
1 files changed, 30 insertions, 15 deletions
diff --git a/client/components/users/userAvatar.js b/client/components/users/userAvatar.js
index 73b2631a..a35415e2 100644
--- a/client/components/users/userAvatar.js
+++ b/client/components/users/userAvatar.js
@@ -47,6 +47,10 @@ BlazeComponent.extendComponent({
return 'changeAvatarPopup';
},
+ onCreated: function() {
+ this.error = new ReactiveVar('');
+ },
+
avatarUrlOptions: function() {
return {
auth: false,
@@ -79,28 +83,39 @@ BlazeComponent.extendComponent({
});
},
+ setError: function(error) {
+ this.error.set(error);
+ },
+
events: function() {
return [{
'click .js-upload-avatar': function() {
this.$('.js-upload-avatar-input').click();
},
'change .js-upload-avatar-input': function(evt) {
- var self = this;
- var file, fileUrl;
-
- FS.Utility.eachFile(evt, function(f) {
- file = Avatars.insert(new FS.File(f));
- fileUrl = file.url(self.avatarUrlOptions());
+ let file, fileUrl;
+
+ FS.Utility.eachFile(evt, (f) => {
+ try {
+ file = Avatars.insert(new FS.File(f));
+ fileUrl = file.url(this.avatarUrlOptions());
+ } catch (e) {
+ this.setError('avatar-too-big');
+ }
});
- var fetchAvatarInterval = window.setInterval(function() {
- $.ajax({
- url: fileUrl,
- success: function() {
- self.setAvatar(file.url(self.avatarUrlOptions()));
- window.clearInterval(fetchAvatarInterval);
- }
- });
- }, 100);
+
+ if (fileUrl) {
+ this.setError('');
+ let fetchAvatarInterval = window.setInterval(() => {
+ $.ajax({
+ url: fileUrl,
+ success: () => {
+ this.setAvatar(file.url(this.avatarUrlOptions()));
+ window.clearInterval(fetchAvatarInterval);
+ }
+ });
+ }, 100);
+ }
},
'click .js-select-avatar': function() {
var avatarUrl = this.currentData().url(this.avatarUrlOptions());