Vulcan/packages/telescope-posts/lib/client/templates/modules/post_vote.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-06-18 16:46:45 +09:00
Template.post_vote.helpers({
enableDownvotes: function () {
return Settings.get("enableDownvotes", false);
},
actionsClass: function () {
var user = Meteor.user();
var actionsClass = "";
if(!user) return false;
if (user.hasUpvoted(this)) {
actionsClass += " voted upvoted";
}
if (user.hasDownvoted(this)) {
actionsClass += " voted downvoted";
}
if (Settings.get("enableDownvotes", false)) {
actionsClass += " downvotes-enabled";
}
return actionsClass;
}
});
Template.post_vote.events({
'click .upvote-link': function(e){
var post = this;
var user = Meteor.user();
e.preventDefault();
if(!user){
2015-10-12 13:33:04 +09:00
FlowRouter.go('signIn');
2015-06-18 16:46:45 +09:00
Messages.flash(i18n.t("please_log_in_first"), "info");
2015-10-12 13:33:04 +09:00
} else if (user.hasUpvoted(post)) {
Meteor.call('cancelUpvotePost', post._id, function(){
2015-06-18 16:46:45 +09:00
Events.track("post upvote cancelled", {'_id': post._id});
});
} else {
Meteor.call('upvotePost', post._id, function(){
2015-06-18 16:46:45 +09:00
Events.track("post upvoted", {'_id': post._id});
});
}
},
'click .downvote-link': function(e){
var post = this;
var user = Meteor.user();
e.preventDefault();
if(!user){
2015-09-18 16:27:59 +09:00
FlowRouter.go('atSignIn');
2015-06-18 16:46:45 +09:00
Messages.flash(i18n.t("please_log_in_first"), "info");
}
if (user.hasDownvoted(post)) {
Meteor.call('cancelDownvotePost', post._id, function(){
2015-06-18 16:46:45 +09:00
Events.track("post downvote cancelled", {'_id': post._id});
});
} else {
Meteor.call('downvotePost', post._id, function(){
2015-06-18 16:46:45 +09:00
Events.track("post downvoted", {'_id': post._id});
});
}
}
});