2014-12-08 14:53:26 +09:00
|
|
|
Template[getTemplate('userComments')].created = function () {
|
|
|
|
Session.set('commentsShown', 5);
|
2014-12-09 11:19:49 +09:00
|
|
|
|
2014-12-08 15:26:06 +09:00
|
|
|
var user = this.data;
|
2014-12-09 11:19:49 +09:00
|
|
|
var instance = this;
|
|
|
|
|
|
|
|
instance.commentsShown = new ReactiveVar(5);
|
|
|
|
instance.comments = new ReactiveVar({});
|
|
|
|
|
2014-12-18 10:36:41 +09:00
|
|
|
this.autorun(function () {
|
2014-12-09 11:19:49 +09:00
|
|
|
|
|
|
|
// get parameters
|
|
|
|
var limit = instance.commentsShown.get();
|
|
|
|
|
|
|
|
// subscribe
|
|
|
|
instance.subscription = Meteor.subscribe('userComments', user._id, limit);
|
|
|
|
|
|
|
|
// set cursor
|
|
|
|
instance.comments.set(Comments.find({userId: user._id}, {limit: limit}));
|
2014-12-08 15:26:06 +09:00
|
|
|
});
|
2014-12-08 14:53:26 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
Template[getTemplate('userComments')].helpers({
|
|
|
|
comments: function () {
|
2014-12-09 11:19:49 +09:00
|
|
|
var comments = Template.instance().comments.get();
|
2014-12-08 14:53:26 +09:00
|
|
|
if(!!comments){
|
|
|
|
// extend comments with each commented post
|
|
|
|
var extendedComments = comments.map(function (comment) {
|
|
|
|
var post = Posts.findOne(comment.postId);
|
|
|
|
if(post) // post might not be available anymore
|
|
|
|
comment.postTitle = post.title;
|
|
|
|
return comment;
|
|
|
|
});
|
|
|
|
return extendedComments;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hasMoreComments: function () {
|
2014-12-09 11:19:49 +09:00
|
|
|
return Template.instance().comments.get().count() >= Template.instance().commentsShown.get();
|
2014-12-08 14:53:26 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Template[getTemplate('userComments')].events({
|
|
|
|
'click .comments-more': function (e) {
|
|
|
|
e.preventDefault();
|
2014-12-09 11:19:49 +09:00
|
|
|
var commentsShown = Template.instance().commentsShown.get();
|
|
|
|
Template.instance().commentsShown.set(commentsShown+5);
|
2014-12-08 14:53:26 +09:00
|
|
|
}
|
|
|
|
});
|