diff --git a/www/html/_proposal.html b/www/html/_proposal.html index b7ace1a..7c33d40 100644 --- a/www/html/_proposal.html +++ b/www/html/_proposal.html @@ -30,6 +30,9 @@ +

diff --git a/www/html/_proposal_list.html b/www/html/_proposal_list.html index 584d9ce..4254f91 100644 --- a/www/html/_proposal_list.html +++ b/www/html/_proposal_list.html @@ -52,6 +52,7 @@ diff --git a/www/js/controllers.js b/www/js/controllers.js index 5676827..c5f9f2b 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -144,6 +144,7 @@ angular.module('confjuvapp.controllers', []) $scope.loadTopics(token); $scope.loadStages(); $scope.parseURLParams(); + $scope.loadFollowedProposals(); }; // Function to retrieve password @@ -1111,4 +1112,61 @@ angular.module('confjuvapp.controllers', []) } }; + /****************************************************************************** + F O L L O W P R O P O S A L + ******************************************************************************/ + + $scope.loadFollowedProposals = function() { + $scope.loading = true; + var config = { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', + }, + timeout: 10000 + }; + + $http.get(ConfJuvAppUtils.pathTo('/articles/followed_by_me?fields=id&private_token=' + $scope.token + '&_=' + new Date().getTime()), config) + .then(function(resp) { + $scope.loading = false; + $scope.following = []; + var followed = resp.data.articles; + for (var i = 0; i < followed.length; i++) { + $scope.following.push(followed[i].id); + } + }, function(err) { + $scope.loading = false; + $ionicPopup.alert({ title: 'Propostas seguidas', template: 'Erro ao carregar propostas seguidas' }); + }); + }; + + $scope.isFollowing = function(proposal) { + if ($scope.hasOwnProperty('following')) { + return ($scope.following.indexOf(proposal.id) > -1); + } + else { + return false; + } + }; + + $scope.follow = function(proposal) { + $scope.loading = true; + + var config = { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', + }, + timeout: 10000 + } + + $http.post(ConfJuvAppUtils.pathTo('articles/' + proposal.id + '/follow'), jQuery.param({ private_token: $scope.token }), config) + .then(function(resp) { + $ionicPopup.alert({ title: 'Seguir proposta', template: 'Pronto! Você pode acompanhar suas propostas seguidas através do menu lateral esquerdo.' }); + $scope.following.push(proposal.id); + $scope.loading = false; + }, function(err) { + $ionicPopup.alert({ title: 'Seguir proposta', template: 'Erro ao seguir proposta.' }); + $scope.loading = false; + }); + }; + }); // Ends controller -- libgit2 0.21.2