2014-12-08 14:53:26 +09:00
|
|
|
Template[getTemplate('userPosts')].created = function () {
|
|
|
|
Session.set('postsShown', 5);
|
2014-12-08 15:26:06 +09:00
|
|
|
var user = this.data;
|
2014-12-08 17:25:11 +09:00
|
|
|
var terms = {};
|
2014-12-08 15:26:06 +09:00
|
|
|
Tracker.autorun(function () {
|
2014-12-08 17:25:11 +09:00
|
|
|
terms = {
|
|
|
|
view: 'userPosts',
|
|
|
|
userId: user._id,
|
|
|
|
limit: Session.get('postsShown')
|
|
|
|
}
|
|
|
|
coreSubscriptions.subscribe('userPosts', terms);
|
2014-12-08 15:26:06 +09:00
|
|
|
});
|
2014-12-08 14:53:26 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
Template[getTemplate('userPosts')].helpers({
|
|
|
|
posts: function () {
|
|
|
|
return Posts.find({userId: this._id}, {limit: Session.get('postsShown')});
|
|
|
|
},
|
|
|
|
hasMorePosts: function () {
|
2014-12-08 15:26:06 +09:00
|
|
|
return Posts.find({userId: this._id}).count() >= Session.get('postsShown');
|
2014-12-08 14:53:26 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Template[getTemplate('userPosts')].events({
|
|
|
|
'click .posts-more': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var postsShown = Session.get('postsShown');
|
|
|
|
Session.set('postsShown', postsShown + 10);
|
|
|
|
}
|
|
|
|
});
|