diff --git a/client/views/userProfile.js b/client/views/userProfile.js index 81dc399..c4a62ea 100644 --- a/client/views/userProfile.js +++ b/client/views/userProfile.js @@ -1,21 +1,23 @@ Template.userProfile.isOwner = function() { return Meteor.userId() == this._id; -} +}; Template.userProfile.rendered = function() { Session.setDefault("showEditAvatarBar",false); -} +}; Template.userProfile.userFriends = function() { - return Meteor.users.find({_id: {$in: this.profile.friends}}); -} + var friends = this.profile.friends || []; + return Meteor.users.find({_id: {$in: friends}}); +}; + Template.userProfile.avatarUrl = function() { - if(this.profile.avatar) { + if(this.profile.avatar) { return this.profile.avatar; } else { return "/img/avatar.jpg"; } -} +}; Template.userProfile.events = { 'click [data-action="set-username"]': function() { @@ -32,7 +34,7 @@ Template.userProfile.events = { 'click div.avatar': function() { Router.go('userProfile', {_id: this._id}); } -} +}; Template.userPlaylist.songCount = function() { if(this.songs) { @@ -42,7 +44,7 @@ Template.userPlaylist.songCount = function() { return this.songs.length + " songs"; } } -} +}; Template.editAvatar.events = { 'click [data-action="update-avatar"]': function() { @@ -53,11 +55,11 @@ Template.editAvatar.events = { {$set: {'profile.avatar':avatar}}); Session.set("showEditAvatarBar",false); } -} +}; Template.addRemoveFriend.isFriend = function() { return _.contains(Meteor.user().profile.friends,this._id); -} +}; Template.addRemoveFriend.events = { 'click [data-action="add-friend"]': function() { @@ -72,4 +74,4 @@ Template.addRemoveFriend.events = { { $pull : { 'profile.friends': this._id }} ); } -} \ No newline at end of file +};