diff --git a/src/app/components/article-service/article.service.js b/src/app/components/article-service/article.service.js index de20aca..b2662a6 100644 --- a/src/app/components/article-service/article.service.js +++ b/src/app/components/article-service/article.service.js @@ -23,6 +23,7 @@ getProposalById: getProposalById, getProposalsByTopicId: getProposalsByTopicId, createProposal: createProposal, + voteProposal: voteProposal, getEvents: getEvents, subscribeToEvent: subscribeToEvent, searchTopics: searchTopics, @@ -172,6 +173,19 @@ } } + function voteProposal (proposal_id, params, cbSuccess, cbError){ + var url = service.apiArticles + proposal_id + '/vote'; + var paramsExtended = angular.extend({ + private_token: $rootScope.currentUser.private_token + }, params); + + UtilService.post(url, paramsExtended).then(function(response){ + cbSuccess(response); + }).catch(function(error){ + cbError(error); + }); + } + function getEvents (community_id, params, cbSuccess, cbError) { // Ex.: /api/v1/communities/19195/articles?categories_ids[]=' + cat_id + '&content_type=Event'; // Ex.: /api/v1/communities/' + community_id + '/articles?categories_ids[]=' + cat_id + '&content_type=Event'; diff --git a/src/app/components/proposal-box/proposal-box.directive.js b/src/app/components/proposal-box/proposal-box.directive.js index 22f6416..5553a47 100644 --- a/src/app/components/proposal-box/proposal-box.directive.js +++ b/src/app/components/proposal-box/proposal-box.directive.js @@ -9,11 +9,12 @@ function proposalBox() { /** @ngInject */ - function ProposalBoxController($scope, $state, VOTE_STATUS, VOTE_OPTIONS, $log) { + function ProposalBoxController($scope, $rootScope, $state, VOTE_STATUS, VOTE_OPTIONS, $log) { $log.debug('ProposalBoxController'); var vm = this; vm.$scope = $scope; + vm.$rootScope = $rootScope; vm.$state = $state; vm.VOTE_STATUS = VOTE_STATUS; vm.VOTE_OPTIONS = VOTE_OPTIONS; @@ -30,12 +31,26 @@ vm.canVote = vm.canVote || false; vm.focus = vm.focus || false; vm.STATE = null; + vm.errorOnSkip = false; }; ProposalBoxController.prototype.addListeners = function () { var vm = this; - vm.$scope.$on('proposal-box:vote-response', function(e, data){ + vm.$scope.$on('proposal-box:proposal-loaded', function(event, data){ + if(data.success){ + vm.STATE = null; + } + + if(data.error){ + vm.errorOnSkip = true; + } + }); + vm.$scope.$on('proposal-box:vote-response', function(event, data){ + vm.$log.debug('proposal-box:vote-response'); + vm.$log.debug('event', event); + vm.$log.debug('data', data); + if(data.success) { vm.STATE = vm.VOTE_STATUS.SUCCESS; } @@ -59,15 +74,19 @@ }); }; - ProposalBoxController.prototype.voteUp = function () { + ProposalBoxController.prototype.vote = function (value) { var vm = this; - vm.STATE = vm.VOTE_STATUS.LOADING; - vm.$scope.$emit('proposal-box:vote', { - OPTION: vm.VOTE_OPTIONS.UP, - proposal_id: vm.proposal.id - }); - vm.$log.debug('Sending vote'); + if(vm.$rootScope.currentUser){ + vm.$scope.$emit('proposal-box:vote', { + OPTION: value, + proposal_id: vm.proposal.id + }); + vm.$log.debug('Sending vote', value); + }else{ + vm.$log.info('Must be logged in...'); + + } }; ProposalBoxController.prototype.voteDown = function () { @@ -84,6 +103,7 @@ ProposalBoxController.prototype.skip = function () { var vm = this; + vm.errorOnSkip = false; vm.STATE = vm.VOTE_STATUS.LOADING; vm.$scope.$emit('proposal-box:vote', { OPTION: vm.VOTE_OPTIONS.SKIP, diff --git a/src/app/components/proposal-box/proposal-box.html b/src/app/components/proposal-box/proposal-box.html index 8ab1d6c..1cd98c3 100644 --- a/src/app/components/proposal-box/proposal-box.html +++ b/src/app/components/proposal-box/proposal-box.html @@ -6,18 +6,21 @@