1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- Template.website_item.events({
- "click .js-upvote": function () {
-
-
- const websiteId = this._id;
- console.log("Up voting website with id " + websiteId);
-
- const userId = Meteor.userId();
- let modifiers = {};
- let increments = {};
- if (!_.contains(this.plus, userId)) {
- modifiers.$addToSet = { plus: userId };
- increments.plusScore = 1;
- }
- if (_.contains(this.minus, userId)) {
- modifiers.$pull = { minus: userId };
- increments.minusScore = -1;
- }
- if (!_.isEmpty(increments)) {
- modifiers.$inc = increments;
- }
- if (!_.isEmpty(modifiers)) {
- Websites.update({ _id: websiteId }, modifiers);
- }
-
- return false;
- },
- "click .js-downvote": function () {
-
-
- const websiteId = this._id;
- console.log("Down voting website with id " + websiteId);
-
- const userId = Meteor.userId();
- let modifiers = {};
- let increments = {};
- if (!_.contains(this.minus, userId)) {
- modifiers.$addToSet = { minus: userId };
- increments.minusScore = 1;
- }
- if (_.contains(this.plus, userId)) {
- modifiers.$pull = { plus: userId };
- increments.plusScore = -1;
- }
- if (!_.isEmpty(increments)) {
- modifiers.$inc = increments;
- }
- if (!_.isEmpty(modifiers)) {
- Websites.update({ _id: websiteId }, modifiers);
- }
-
- return false;
- }
- });
- Template.website_item.helpers({
- upVoted: function () {
- return _.contains(this.plus, Meteor.userId()) ? "btn-success" : "";
- },
- downVoted: function () {
- return _.contains(this.minus, Meteor.userId()) ? "btn-danger" : "";
- },
- postDate: function () {
- return this.postDate ? this.postDate : "Application launch";
- },
- poster: function () {
- return this.poster && this.poster.name ? this.poster.name : "Application setup";
- },
- minusVotes: function () {
- return this.minusScore ? this.minusScore : 0;
- },
- plusVotes: function () {
- return this.plusScore ? this.plusScore : 0;
- },
- score: function () {
- const plus = this.plusScore ? this.plusScore : 0;
- const minus = this.minusScore ? this.minusScore : 0;
- return plus - minus;
- }
- });
|