Vulcan/client/views/users/profile/user_posts.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-12-08 14:53:26 +09:00
Template[getTemplate('userPosts')].created = function () {
var user = this.data;
var instance = this;
2014-12-08 18:03:30 +09:00
// initialize the terms and posts local reactive variables
instance.terms = new ReactiveVar({
view: 'userPosts',
userId: user._id,
limit: 5
});
2014-12-08 18:03:30 +09:00
instance.posts = new ReactiveVar({});
// will re-run when the "terms" local reactive variable changes
Tracker.autorun(function () {
2014-12-08 18:03:30 +09:00
// get the new terms and generate new parameters from them
var terms = instance.terms.get();
var parameters = getPostsParameters(terms);
// subscribe to the userPosts publication
coreSubscriptions.subscribe('userPosts', terms);
// update the instance's "posts" cursor
instance.posts.set(Posts.find(parameters.find, parameters.options));
});
2014-12-08 14:53:26 +09:00
};
Template[getTemplate('userPosts')].helpers({
posts: function () {
2014-12-08 18:03:30 +09:00
return Template.instance().posts.get();
2014-12-08 14:53:26 +09:00
},
hasMorePosts: function () {
return Template.instance().posts.get().count() >= Template.instance().terms.get().limit;
2014-12-08 14:53:26 +09:00
}
});
Template[getTemplate('userPosts')].events({
'click .posts-more': function (e) {
e.preventDefault();
var terms = Template.instance().terms.get();
terms.limit += 5;
Template.instance().terms.set(terms)
2014-12-08 14:53:26 +09:00
}
});