2015-04-13 14:52:03 +09:00
|
|
|
Template.userDownvotedPosts.created = function () {
|
2014-12-08 18:03:30 +09:00
|
|
|
|
2014-12-08 15:26:06 +09:00
|
|
|
var user = this.data;
|
2014-12-08 18:03:30 +09:00
|
|
|
var instance = this;
|
|
|
|
|
|
|
|
// initialize the terms and posts local reactive variables
|
|
|
|
instance.terms = new ReactiveVar({
|
|
|
|
view: 'userDownvotedPosts',
|
|
|
|
userId: user._id,
|
|
|
|
limit: 5
|
|
|
|
});
|
|
|
|
instance.posts = new ReactiveVar({});
|
|
|
|
|
|
|
|
// will re-run when the "terms" local reactive variable changes
|
2014-12-18 10:36:41 +09:00
|
|
|
this.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
|
2014-12-09 11:19:49 +09:00
|
|
|
instance.subscription = Meteor.subscribe('userDownvotedPosts', terms);
|
2014-12-08 18:03:30 +09:00
|
|
|
|
|
|
|
// update the instance's "posts" cursor
|
|
|
|
instance.posts.set(Posts.find(parameters.find, parameters.options));
|
|
|
|
|
2014-12-08 17:25:11 +09:00
|
|
|
});
|
2014-12-08 14:53:26 +09:00
|
|
|
};
|
|
|
|
|
2015-04-13 14:52:03 +09:00
|
|
|
Template.userDownvotedPosts.helpers({
|
2014-12-08 18:03:30 +09:00
|
|
|
posts: function () {
|
2014-12-08 19:51:39 +09:00
|
|
|
var user = this;
|
|
|
|
var posts = Template.instance().posts.get().fetch();
|
|
|
|
posts = _.map(posts, function (post) {
|
|
|
|
var vote = _.findWhere(user.votes.downvotedPosts, {itemId: post._id});
|
|
|
|
post.votedAt = vote.votedAt;
|
|
|
|
return post;
|
|
|
|
});
|
|
|
|
return posts;
|
2014-12-08 14:53:26 +09:00
|
|
|
},
|
2014-12-08 18:03:30 +09:00
|
|
|
hasMorePosts: function () {
|
2014-12-08 18:16:44 +09:00
|
|
|
return Template.instance().posts.get().count() >= Template.instance().terms.get().limit;
|
2014-12-08 14:53:26 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-13 14:52:03 +09:00
|
|
|
Template.userDownvotedPosts.events({
|
2014-12-08 14:53:26 +09:00
|
|
|
'click .downvotedposts-more': function (e) {
|
|
|
|
e.preventDefault();
|
2014-12-08 18:03:30 +09:00
|
|
|
var terms = Template.instance().terms.get();
|
|
|
|
terms.limit += 5;
|
|
|
|
Template.instance().terms.set(terms)
|
2014-12-08 14:53:26 +09:00
|
|
|
}
|
|
|
|
});
|