Commit d2243aa00f7804926c04ec88db733a2159df6f9f

Authored by Caio Almeida
1 parent d37fd0f4

Revert "Revert "Ticket #99: Support proposal, part 1""

This reverts commit ca190d013c68c13bd32de49063c2e4a2004a8f08.
Showing 2 changed files with 75 additions and 1 deletions   Show diff stats
www/html/_proposal.html
... ... @@ -24,6 +24,9 @@
24 24 <button class="button follow" ng-click="follow(proposal)" ng-hide="isFollowing(proposal) || proposal.author.id == profile.id">
25 25 <i class="icon ion-eye"></i> <span>Seguir</span>
26 26 </button>
  27 + <button class="button vote" ng-click="vote(proposal)" ng-hide="alreadyVoted(proposal) || proposal.author.id == profile.id">
  28 + <i class="icon ion-thumbsup"></i> <span>Votar</span>
  29 + </button>
27 30 <br />
28 31 <button class="button" onclick="window.open(ConfJuvAppUtils.shareOnTwitter(), '_system')">
29 32 <i class="icon ion-social-twitter"></i> <span>Compartilhar no Twitter</span>
... ...
www/js/controllers.js
... ... @@ -569,7 +569,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
569 569 }
570 570 else {
571 571 // Initiate the modal
572   - $ionicModal.fromTemplateUrl('html/_proposal.html?19', {
  572 + $ionicModal.fromTemplateUrl('html/_proposal.html?20', {
573 573 scope: $scope,
574 574 animation: 'slide-in-up'
575 575 }).then(function(modal) {
... ... @@ -1168,6 +1168,76 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
1168 1168 };
1169 1169  
1170 1170 /******************************************************************************
  1171 + V O T E P R O P O S A L
  1172 + ******************************************************************************/
  1173 +
  1174 +//FIXME Adapt this method for votes
  1175 + $scope.showVotedProposals = function() {
  1176 +// $scope.cardsBackup = [];
  1177 +// $scope.showBackupProposalsLink = false;
  1178 +//FIXME put this to works
  1179 +// $scope.cards = $scope.following.slice();
  1180 + }
  1181 +
  1182 +//FIXME Adapt this method for votes
  1183 + $scope.loadVotedProposals = function() {
  1184 + $scope.loading = true;
  1185 + var config = {
  1186 + headers: {
  1187 + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  1188 + },
  1189 + timeout: 10000
  1190 + };
  1191 +
  1192 + $http.get(ConfJuvAppUtils.pathTo('/articles/followed_by_me?fields=title,image,body,abstract,id,tag_list,categories,created_by&private_token=' + $scope.token + '&_=' + new Date().getTime()), config)
  1193 + .then(function(resp) {
  1194 + $scope.following = [];
  1195 + $scope.followingIds = [];
  1196 + var followed = resp.data.articles;
  1197 + for (var i = 0; i < followed.length; i++) {
  1198 + var p = followed[i];
  1199 + $scope.following.push(p);
  1200 + $scope.followingIds.push(p.id);
  1201 + }
  1202 + $scope.loading = false;
  1203 + }, function(err) {
  1204 + $scope.loading = false;
  1205 + $ionicPopup.alert({ title: 'Propostas seguidas', template: 'Erro ao carregar propostas seguidas' });
  1206 + });
  1207 + };
  1208 +
  1209 +//FIXME adapt this method for votes
  1210 + $scope.alreadyVoted = function(proposal) {
  1211 +// if ($scope.hasOwnProperty('followingIds')) {
  1212 +// return ($scope.followingIds.indexOf(proposal.id) > -1);
  1213 +// }
  1214 +// else {
  1215 + return false;
  1216 +// }
  1217 + };
  1218 +
  1219 + $scope.vote = function(proposal) {
  1220 + $scope.loading = true;
  1221 +
  1222 + var config = {
  1223 + headers: {
  1224 + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  1225 + },
  1226 + timeout: 10000
  1227 + }
  1228 +
  1229 + $http.post(ConfJuvAppUtils.pathTo('articles/' + proposal.id + '/vote'), jQuery.param({ private_token: $scope.token}), config)
  1230 + .then(function(resp) {
  1231 + $ionicPopup.alert({ title: 'Votar em proposta', template: 'Pronto! Você já votou nesta proposta.' });
  1232 + $scope.loading = false;
  1233 + }, function(err) {
  1234 + $ionicPopup.alert({ title: 'Votar em proposta', template: 'Erro ao votar na proposta.' });
  1235 + $scope.loading = false;
  1236 + });
  1237 + };
  1238 +
  1239 +
  1240 + /******************************************************************************
1171 1241 F O L L O W P R O P O S A L
1172 1242 ******************************************************************************/
1173 1243  
... ... @@ -1235,6 +1305,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
1235 1305 });
1236 1306 };
1237 1307  
  1308 +
1238 1309 /******************************************************************************
1239 1310 P R O F I L E
1240 1311 ******************************************************************************/
... ...