Author: garandel Date: 2014-05-15 17:22:51 +0200 (Thu, 15 May 2014) New Revision: 3951 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3951 Log: fix vote persitence Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js trunk/pollen-ui-angular/src/main/webapp/js/services.js trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-15 15:06:28 UTC (rev 3950) +++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-15 15:22:51 UTC (rev 3951) @@ -317,23 +317,21 @@ $scope.data.vote.anonymous = false; $scope.data.vote.choice = []; for (var i = 0; i < $scope.data.choices.length; ++i) { - $scope.data.vote.choice.push({choiceId:$scope.data.choices[i].topiaId, voteValue:1}); + $scope.data.vote.choice.push({choiceId:$scope.data.choices[i].topiaId, voteValue:false}); } } $scope.voter = function () { - if ($scope.data.vote.name != '') { - PollVote.add({pollId:$routeParams.pollId}, $scope.data.vote, function (returnRequest) { - console.log(returnRequest); - }); + var sendVote = angular.copy($scope.data.vote); + angular.forEach(sendVote.choice, function (choice) { + choice.voteValue = (choice.voteValue) ? 1 : 0; + }); + PollVote.add({pollId:$routeParams.pollId}, sendVote, function (returnRequest) { + console.log(returnRequest); $scope.globalVariables.saved = true; - $scope.globalVariables.errorForm = false; initVote(); - } - else { - $scope.globalVariables.errorForm = true; - } + }); } }]) Modified: trunk/pollen-ui-angular/src/main/webapp/js/services.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-15 15:06:28 UTC (rev 3950) +++ trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-15 15:22:51 UTC (rev 3951) @@ -67,15 +67,6 @@ .factory('PollVote', ['$resource', function ($resource) { var transformParam = function (data) { - angular.forEach(data.choice, function (choice) { - delete choice.$$hashKey; - if (choice.voteValue != null && !choice.voteValue) { - choice.voteValue = 1; - } - else { - choice.voteValue = 0; - } - }); return 'vote='+encodeURIComponent(JSON.stringify(data)); }; Modified: trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-15 15:06:28 UTC (rev 3950) +++ trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-15 15:22:51 UTC (rev 3951) @@ -52,6 +52,7 @@ <tr ng-show="!globalVariables.editMode"> <td class="pollChoice"> <input type="text" class="form-control" placeholder="votre nom" ng-model="data.vote.voter.name" /> </td> <td ng-repeat="choice in data.vote.choice" class="pollChoice"> + {{choice.voteValue}} <input type="checkbox" name="{{choice.choice.topiaId}}" ng-model="choice.voteValue" /> </td> <td>