Creating a leaderboard in JavaScript that immediately updates to MongoDB. In order to increase the amount of points someone has on the leaderboard, you click on the respective <div>
and it increases their score by 5 "points".
This is done by using this function
Template.leaderboard.events({
'click div.inc': function () {
Players.update(Session.get("selected_player"), {$inc: {score: 5}});
}
});
I want the user to only update one player, but to allow changes. So for example, if the user selects "John Smith", "John Smith" should only be able to be increased 5 points. In addition to that, if the user decides he wants to give the points to "Janie Smith", "John Smith" should lose 5 points and "Janie Smith" should gain.
What's the best way to do this? Can I do this by figuring out the previous "selected_div"?