mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 12:36:39 -04:00
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
Template.post_vote.helpers({
|
|
enableDownvotes: function () {
|
|
return Telescope.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 (Telescope.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){
|
|
FlowRouter.go('signIn');
|
|
Messages.flash(i18n.t("please_log_in_first"), "info");
|
|
} else if (user.hasUpvoted(post)) {
|
|
Meteor.call('cancelUpvotePost', post._id, function(){
|
|
Events.track("post upvote cancelled", {'_id': post._id});
|
|
});
|
|
} else {
|
|
Meteor.call('upvotePost', post._id, function(){
|
|
Events.track("post upvoted", {'_id': post._id});
|
|
});
|
|
}
|
|
},
|
|
'click .downvote-link': function(e){
|
|
var post = this;
|
|
var user = Meteor.user();
|
|
e.preventDefault();
|
|
if(!user){
|
|
FlowRouter.go('signIn');
|
|
Messages.flash(i18n.t("please_log_in_first"), "info");
|
|
}
|
|
if (user.hasDownvoted(post)) {
|
|
Meteor.call('cancelDownvotePost', post._id, function(){
|
|
Events.track("post downvote cancelled", {'_id': post._id});
|
|
});
|
|
} else {
|
|
Meteor.call('downvotePost', post._id, function(){
|
|
Events.track("post downvoted", {'_id': post._id});
|
|
});
|
|
}
|
|
}
|
|
});
|