(Re-)implement default avatar using user initials

We use a embedded svg to scale the initials text to its container
size. The user is free to overwrite its initials in the profile form.
This commit is contained in:
Maxime Quandalle 2015-06-10 17:10:32 +02:00
parent 0b6c229b6c
commit 765b0168ea
6 changed files with 91 additions and 43 deletions

View file

@ -26,6 +26,18 @@ Template.userAvatar.helpers({
}
});
Template.userAvatarInitials.helpers({
initials: function() {
var user = Users.findOne(this.userId);
return user && user.getInitials();
},
viewPortWidth: function() {
var user = Users.findOne(this.userId);
return (user && user.getInitials().length || 1) * 12;
}
});
BlazeComponent.extendComponent({
template: function() {
return 'changeAvatarPopup';
@ -49,6 +61,12 @@ BlazeComponent.extendComponent({
return avatarUrl === currentAvatarUrl;
},
noAvatarUrl: function() {
var userProfile = Meteor.user().profile;
var avatarUrl = userProfile && userProfile.avatarUrl;
return ! avatarUrl;
},
setAvatar: function(avatarUrl) {
Meteor.users.update(Meteor.userId(), {
$set: {
@ -84,6 +102,9 @@ BlazeComponent.extendComponent({
var avatarUrl = this.currentData().url(this.avatarUrlOptions());
this.setAvatar(avatarUrl);
},
'click .js-select-initials': function() {
this.setAvatar('');
},
'click .js-delete-avatar': function() {
Avatars.remove(this.currentData()._id);
}