• Jump To … +
    auth.js comments.js glint.js ideas.js votes.js services.js commentController.js commentModel.js commentRoutes.js helpers.js middleware.js ideaController.js ideaModel.js ideaRoutes.js serverSetup.js serverSpec.js usersController.js usersModel.js usersRoutes.js voteController.js voteRoutes.js
  • votes.js

  • ¶

    Votes controller

  • ¶
    angular.module('glint.votes', [])
    
    .controller('VotesCtrl', function(Votes){
      var self = this;
  • ¶

    Display the user’s upvotes and pass them along to the db.

      self.upvote = function(idea){
        var ideaRef = idea;
    
        idea = JSON.stringify(idea);
        Votes.upvote(idea)
          .then(function (response){
  • ¶

    Update the specific idea’s vote count.

            ideaRef.votes++;
          })
          .catch(function (error){
            console.error('upvote error', error);
          });
      };
  • ¶

    Display the user’s downvotes and pass them along to the db.

      self.downvote = function(idea){
        var ideaRef = idea;
    
        idea = JSON.stringify(idea);
        Votes.downvote(idea)
          .then(function (response){
  • ¶

    Update the specific idea’s vote count.

            ideaRef.votes--;
          })
          .catch(function (error){
            console.error('downvote error', error);
          });
      };
    });