Commit 07cb7dcbeed52aa0bfd25d353e4cb397ff403640
1 parent
c7412c19
Exists in
master
and in
2 other branches
Ticket #56: Follow proposals
Showing
3 changed files
with
62 additions
and
0 deletions
Show diff stats
www/html/_proposal.html
@@ -30,6 +30,9 @@ | @@ -30,6 +30,9 @@ | ||
30 | <button class="button" ng-click="share(proposal)"> | 30 | <button class="button" ng-click="share(proposal)"> |
31 | <i class="icon ion-shuffle"></i> <span>Compartilhar</span> | 31 | <i class="icon ion-shuffle"></i> <span>Compartilhar</span> |
32 | </button> | 32 | </button> |
33 | + <button class="button" ng-click="follow(proposal)" ng-hide="isFollowing(proposal)"> | ||
34 | + <i class="icon ion-eye"></i> <span>Seguir</span> | ||
35 | + </button> | ||
33 | </p> | 36 | </p> |
34 | 37 | ||
35 | <p style="clear: both;"></p> | 38 | <p style="clear: both;"></p> |
www/html/_proposal_list.html
@@ -52,6 +52,7 @@ | @@ -52,6 +52,7 @@ | ||
52 | </div> | 52 | </div> |
53 | <div class="card-footer"> | 53 | <div class="card-footer"> |
54 | <a ng-click="openProposal(proposal)" class="icon-left ion-android-open"> Leia Mais</a> | 54 | <a ng-click="openProposal(proposal)" class="icon-left ion-android-open"> Leia Mais</a> |
55 | + <a ng-click="follow(proposal)" class="icon-left ion-eye" ng-hide="isFollowing(proposal)"> Seguir</a> | ||
55 | </div> | 56 | </div> |
56 | </div> | 57 | </div> |
57 | </td-card> | 58 | </td-card> |
www/js/controllers.js
@@ -144,6 +144,7 @@ angular.module('confjuvapp.controllers', []) | @@ -144,6 +144,7 @@ angular.module('confjuvapp.controllers', []) | ||
144 | $scope.loadTopics(token); | 144 | $scope.loadTopics(token); |
145 | $scope.loadStages(); | 145 | $scope.loadStages(); |
146 | $scope.parseURLParams(); | 146 | $scope.parseURLParams(); |
147 | + $scope.loadFollowedProposals(); | ||
147 | }; | 148 | }; |
148 | 149 | ||
149 | // Function to retrieve password | 150 | // Function to retrieve password |
@@ -1111,4 +1112,61 @@ angular.module('confjuvapp.controllers', []) | @@ -1111,4 +1112,61 @@ angular.module('confjuvapp.controllers', []) | ||
1111 | } | 1112 | } |
1112 | }; | 1113 | }; |
1113 | 1114 | ||
1115 | + /****************************************************************************** | ||
1116 | + F O L L O W P R O P O S A L | ||
1117 | + ******************************************************************************/ | ||
1118 | + | ||
1119 | + $scope.loadFollowedProposals = function() { | ||
1120 | + $scope.loading = true; | ||
1121 | + var config = { | ||
1122 | + headers: { | ||
1123 | + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
1124 | + }, | ||
1125 | + timeout: 10000 | ||
1126 | + }; | ||
1127 | + | ||
1128 | + $http.get(ConfJuvAppUtils.pathTo('/articles/followed_by_me?fields=id&private_token=' + $scope.token + '&_=' + new Date().getTime()), config) | ||
1129 | + .then(function(resp) { | ||
1130 | + $scope.loading = false; | ||
1131 | + $scope.following = []; | ||
1132 | + var followed = resp.data.articles; | ||
1133 | + for (var i = 0; i < followed.length; i++) { | ||
1134 | + $scope.following.push(followed[i].id); | ||
1135 | + } | ||
1136 | + }, function(err) { | ||
1137 | + $scope.loading = false; | ||
1138 | + $ionicPopup.alert({ title: 'Propostas seguidas', template: 'Erro ao carregar propostas seguidas' }); | ||
1139 | + }); | ||
1140 | + }; | ||
1141 | + | ||
1142 | + $scope.isFollowing = function(proposal) { | ||
1143 | + if ($scope.hasOwnProperty('following')) { | ||
1144 | + return ($scope.following.indexOf(proposal.id) > -1); | ||
1145 | + } | ||
1146 | + else { | ||
1147 | + return false; | ||
1148 | + } | ||
1149 | + }; | ||
1150 | + | ||
1151 | + $scope.follow = function(proposal) { | ||
1152 | + $scope.loading = true; | ||
1153 | + | ||
1154 | + var config = { | ||
1155 | + headers: { | ||
1156 | + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
1157 | + }, | ||
1158 | + timeout: 10000 | ||
1159 | + } | ||
1160 | + | ||
1161 | + $http.post(ConfJuvAppUtils.pathTo('articles/' + proposal.id + '/follow'), jQuery.param({ private_token: $scope.token }), config) | ||
1162 | + .then(function(resp) { | ||
1163 | + $ionicPopup.alert({ title: 'Seguir proposta', template: 'Pronto! Você pode acompanhar suas propostas seguidas através do menu lateral esquerdo.' }); | ||
1164 | + $scope.following.push(proposal.id); | ||
1165 | + $scope.loading = false; | ||
1166 | + }, function(err) { | ||
1167 | + $ionicPopup.alert({ title: 'Seguir proposta', template: 'Erro ao seguir proposta.' }); | ||
1168 | + $scope.loading = false; | ||
1169 | + }); | ||
1170 | + }; | ||
1171 | + | ||
1114 | }); // Ends controller | 1172 | }); // Ends controller |