2014-09-03 09:46:39 +09:00
|
|
|
Template[getTemplate('user_profile')].created = function () {
|
|
|
|
Session.set('postsShown', 5);
|
|
|
|
Session.set('upvotedPostsShown', 5);
|
|
|
|
Session.set('downvotedPostsShown', 5);
|
2014-09-26 22:50:37 +03:00
|
|
|
Session.set('commentsShown', 5);
|
2014-09-16 15:18:27 -04:00
|
|
|
};
|
2014-09-03 09:46:39 +09:00
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('user_profile')].helpers({
|
2013-10-09 20:50:26 +09:00
|
|
|
canEditProfile: function() {
|
|
|
|
var currentUser = Meteor.user();
|
2014-09-26 22:50:37 +03:00
|
|
|
return currentUser && (this._id == currentUser._id || isAdmin(currentUser));
|
2013-10-23 19:43:42 +09:00
|
|
|
},
|
|
|
|
createdAtFormatted: function() {
|
|
|
|
return this.createdAt;
|
|
|
|
},
|
|
|
|
canInvite: function() {
|
|
|
|
// if the user is logged in, the target user hasn't been invited yet, invites are enabled, and user is not viewing their own profile
|
|
|
|
return Meteor.user() && Meteor.user()._id != this._id && !isInvited(this) && invitesEnabled() && canInvite(Meteor.user());
|
|
|
|
},
|
2013-11-14 10:49:37 +09:00
|
|
|
inviteCount: function() {
|
|
|
|
return Meteor.user().inviteCount;
|
2013-11-07 09:57:57 +09:00
|
|
|
},
|
2013-11-08 11:42:00 +09:00
|
|
|
getTwitterName: function () {
|
2013-11-07 09:57:57 +09:00
|
|
|
return getTwitterName(this);
|
|
|
|
},
|
2013-11-08 11:42:00 +09:00
|
|
|
getGitHubName: function () {
|
2013-11-07 09:57:57 +09:00
|
|
|
return getGitHubName(this);
|
2014-08-11 10:14:53 +09:00
|
|
|
},
|
2014-08-23 11:28:05 +09:00
|
|
|
posts: function () {
|
2014-09-03 09:46:39 +09:00
|
|
|
return Posts.find({userId: this._id}, {limit: Session.get('postsShown')});
|
|
|
|
},
|
|
|
|
hasMorePosts: function () {
|
|
|
|
return Posts.find({userId: this._id}).count() > Session.get('postsShown');
|
2014-08-23 11:28:05 +09:00
|
|
|
},
|
|
|
|
upvotedPosts: function () {
|
2014-08-11 10:14:53 +09:00
|
|
|
// extend upvotes with each upvoted post
|
2014-08-23 11:53:37 +09:00
|
|
|
if(!!this.votes.upvotedPosts){
|
|
|
|
var extendedVotes = this.votes.upvotedPosts.map(function (item) {
|
2014-08-22 17:06:22 +09:00
|
|
|
var post = Posts.findOne(item.itemId);
|
|
|
|
return _.extend(item, post);
|
|
|
|
});
|
2014-09-03 09:46:39 +09:00
|
|
|
return _.first(extendedVotes, Session.get('upvotedPostsShown'));
|
2014-08-22 17:06:22 +09:00
|
|
|
}
|
|
|
|
},
|
2014-09-03 09:46:39 +09:00
|
|
|
hasMoreUpvotedPosts: function () {
|
|
|
|
return !!this.votes.upvotedPosts && this.votes.upvotedPosts.length > Session.get('upvotedPostsShown');
|
|
|
|
},
|
2014-08-23 11:28:05 +09:00
|
|
|
downvotedPosts: function () {
|
|
|
|
// extend upvotes with each upvoted post
|
2014-08-23 11:53:37 +09:00
|
|
|
if(!!this.votes.downvotedPosts){
|
|
|
|
var extendedVotes = this.votes.downvotedPosts.map(function (item) {
|
2014-08-23 11:28:05 +09:00
|
|
|
var post = Posts.findOne(item.itemId);
|
|
|
|
return _.extend(item, post);
|
|
|
|
});
|
2014-09-03 09:46:39 +09:00
|
|
|
return _.first(extendedVotes, Session.get('downvotedPostsShown'));
|
2014-08-23 11:28:05 +09:00
|
|
|
}
|
2014-09-03 09:46:39 +09:00
|
|
|
},
|
|
|
|
hasMoreDownvotedPosts: function () {
|
|
|
|
return !!this.votes.downvotedPosts && this.votes.downvotedPosts.length > Session.get('downvotedPostsShown');
|
|
|
|
},
|
2014-08-22 17:06:22 +09:00
|
|
|
comments: function () {
|
2014-09-03 09:46:39 +09:00
|
|
|
var comments = Comments.find({userId: this._id}, {limit: Session.get('commentsShown')});
|
2014-08-23 11:53:37 +09:00
|
|
|
if(!!comments){
|
2014-08-22 17:06:22 +09:00
|
|
|
// extend comments with each commented post
|
|
|
|
var extendedComments = comments.map(function (comment) {
|
|
|
|
var post = Posts.findOne(comment.postId);
|
2014-09-01 09:52:40 +09:00
|
|
|
if(post) // post might not be available anymore
|
|
|
|
comment.postTitle = post.title;
|
2014-08-22 17:06:22 +09:00
|
|
|
return comment;
|
|
|
|
});
|
2014-09-26 22:50:37 +03:00
|
|
|
return extendedComments;
|
2014-08-22 17:06:22 +09:00
|
|
|
}
|
2014-09-03 09:46:39 +09:00
|
|
|
},
|
|
|
|
hasMoreComments: function () {
|
|
|
|
return Comments.find({userId: this._id}).count() > Session.get('commentsShown');
|
2013-10-09 20:50:26 +09:00
|
|
|
}
|
2013-10-26 10:37:32 +09:00
|
|
|
});
|
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('user_profile')].events({
|
2013-10-26 10:37:32 +09:00
|
|
|
'click .invite-link': function(e, instance){
|
|
|
|
Meteor.call('inviteUser', instance.data.user._id);
|
Replace "throwError" with "flashMessage" and type
Currently, ``throwError`` is used for all manner of messages, including
errors, "success" messages, and "info" messages. This makes appropriate
styling of the error message difficult. In addition, the name
``throwError`` seems to create confusion, implying that an error will
actually be thrown (e.g. stopping execution when a user isn't logged in
[0][1]), when in fact it just displays a message.
Replace ``throwError`` with ``flashMessage``, and reliably include a
message "type" (e.g. "error", "success", "info") every time. rename
``lib/errors.js`` to ``lib/messages.js`` to more accurately reflect its
function.
This commit doesn't rename the message collection (``Errors``), nor the
template responsible for rendering the messages (``error_item.html``) --
that should probably still be done, but has higher likelihood of
trouble for existing alternate themes and installations.
[0] https://github.com/TelescopeJS/Telescope/blob/6ccf7d7d4704d6a8e821fe48128f81c19983ffc9/client/views/users/user_edit.js#L43
[1] https://github.com/TelescopeJS/Telescope/blob/083a4c4dc48eca15fe9d4472e24e6b4e8adfc8d6/client/views/users/user_email.js#L13
2014-11-05 13:12:09 -07:00
|
|
|
flashMessage('Thanks, user has been invited.', "success");
|
2014-09-03 09:46:39 +09:00
|
|
|
},
|
|
|
|
'click .posts-more': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var postsShown = Session.get('postsShown');
|
|
|
|
Session.set('postsShown', postsShown + 10);
|
|
|
|
},
|
|
|
|
'click .upvotedposts-more': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var upvotedPostsShown = Session.get('upvotedPostsShown');
|
|
|
|
Session.set('upvotedPostsShown', upvotedPostsShown + 10);
|
|
|
|
},
|
|
|
|
'click .downvotedposts-more': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var downvotedPostsShown = Session.get('downvotedPostsShown');
|
|
|
|
Session.set('downvotedPostsShown', downvotedPostsShown + 10);
|
|
|
|
},
|
|
|
|
'click .comments-more': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var commentsShown = Session.get('commentsShown');
|
|
|
|
Session.set('commentsShown', commentsShown + 10);
|
2013-10-26 10:37:32 +09:00
|
|
|
}
|
Replace "throwError" with "flashMessage" and type
Currently, ``throwError`` is used for all manner of messages, including
errors, "success" messages, and "info" messages. This makes appropriate
styling of the error message difficult. In addition, the name
``throwError`` seems to create confusion, implying that an error will
actually be thrown (e.g. stopping execution when a user isn't logged in
[0][1]), when in fact it just displays a message.
Replace ``throwError`` with ``flashMessage``, and reliably include a
message "type" (e.g. "error", "success", "info") every time. rename
``lib/errors.js`` to ``lib/messages.js`` to more accurately reflect its
function.
This commit doesn't rename the message collection (``Errors``), nor the
template responsible for rendering the messages (``error_item.html``) --
that should probably still be done, but has higher likelihood of
trouble for existing alternate themes and installations.
[0] https://github.com/TelescopeJS/Telescope/blob/6ccf7d7d4704d6a8e821fe48128f81c19983ffc9/client/views/users/user_edit.js#L43
[1] https://github.com/TelescopeJS/Telescope/blob/083a4c4dc48eca15fe9d4472e24e6b4e8adfc8d6/client/views/users/user_email.js#L13
2014-11-05 13:12:09 -07:00
|
|
|
});
|