2015-06-18 16:46:45 +09:00
|
|
|
Template.post_vote.helpers({
|
|
|
|
enableDownvotes: function () {
|
2016-02-16 15:08:30 +09:00
|
|
|
return Telescope.settings.get("enableDownvotes", false);
|
2015-06-18 16:46:45 +09:00
|
|
|
},
|
|
|
|
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";
|
|
|
|
}
|
2016-02-16 15:08:30 +09:00
|
|
|
if (Telescope.settings.get("enableDownvotes", false)) {
|
2015-06-18 16:46:45 +09:00
|
|
|
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)) {
|
2015-07-10 11:06:40 +09:00
|
|
|
Meteor.call('cancelUpvotePost', post._id, function(){
|
2015-06-18 16:46:45 +09:00
|
|
|
Events.track("post upvote cancelled", {'_id': post._id});
|
|
|
|
});
|
|
|
|
} else {
|
2015-07-10 11:06:40 +09:00
|
|
|
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-12-30 15:52:24 +09:00
|
|
|
FlowRouter.go('signIn');
|
2015-06-18 16:46:45 +09:00
|
|
|
Messages.flash(i18n.t("please_log_in_first"), "info");
|
|
|
|
}
|
|
|
|
if (user.hasDownvoted(post)) {
|
2015-07-10 11:06:40 +09:00
|
|
|
Meteor.call('cancelDownvotePost', post._id, function(){
|
2015-06-18 16:46:45 +09:00
|
|
|
Events.track("post downvote cancelled", {'_id': post._id});
|
|
|
|
});
|
|
|
|
} else {
|
2015-07-10 11:06:40 +09:00
|
|
|
Meteor.call('downvotePost', post._id, function(){
|
2015-06-18 16:46:45 +09:00
|
|
|
Events.track("post downvoted", {'_id': post._id});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|