03/03: use promise for get result
This is an automated email from the git hooks/post-receive script. unknown user pushed a commit to branch devel in repository Pollen. commit 21a929c8fc99154b4caa34ed5531f53a949d088d Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Fri May 23 15:02:39 2014 +0200 use promise for get result --- .../src/main/webapp/js/controllers/pollCtrl.js | 43 ++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js index 43ebe0d..1601454 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -286,20 +286,23 @@ angular.module('pollControllers', []) } }]) -.controller('PollVoteCtrl', ['$scope', '$filter', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', function ($scope, $filter, $controller, $routeParams, Poll, PollChoice, PollVote) { +.controller('PollVoteCtrl', ['$scope', '$q', '$filter', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', function ($scope, $q, $filter, $controller, $routeParams, Poll, PollChoice, PollVote) { $controller('PollCtrl', {$scope:$scope}); $scope.globalVariables.results = true; var initPoll = function () { - Poll.get({pollId:$routeParams.pollId}, function (poll) { + var pollPromise = Poll.get({pollId:$routeParams.pollId}, function (poll) { $scope.data.poll = poll; - }); - PollChoice.query({pollId:$routeParams.pollId}, function (choices) { + }).$promise; + + var choicesPromise = PollChoice.query({pollId:$routeParams.pollId}, function (choices) { $scope.data.choices = choices; initVote(); - }); - PollVote.query({pollId:$routeParams.pollId}, function (votes) { + }).$promise; + + + var votesPromise = PollVote.query({pollId:$routeParams.pollId}, function (votes) { $scope.data.votants = votes; angular.forEach($scope.data.votants, function (vote) { angular.forEach(vote.choice, function (choice) { @@ -311,19 +314,21 @@ angular.module('pollControllers', []) } }) }) - }); - - Poll.get({pollId:$routeParams.pollId, cmd:'results'}, function (result) { - $scope.data.result = result; - angular.forEach(result.scores, function(value, key) { - for (var i = 0; i < $scope.data.choices.length; i++) { - if ($scope.data.choices[i].id == value.choiceId) { - value.choice = $scope.data.choices[i]; - i = $scope.data.choices.length; + }).$promise; + + $q.all([choicesPromise, votesPromise]).then(function () { + Poll.get({pollId:$routeParams.pollId, cmd:'results'}, function (result) { + $scope.data.result = result; + angular.forEach(result.scores, function(value, key) { + for (var i = 0; i < $scope.data.choices.length; i++) { + if ($scope.data.choices[i].id == value.choiceId) { + value.choice = $scope.data.choices[i]; + i = $scope.data.choices.length; + } } - } - }) - $scope.data.result.nbVotant = $scope.data.votants.length; + }) + $scope.data.result.nbVotant = $scope.data.votants.length; + }); }); } initPoll(); @@ -349,7 +354,7 @@ angular.module('pollControllers', []) PollVote.add({pollId:$routeParams.pollId}, sendVote, function (returnRequest) { $scope.data.vote.id = returnRequest.id; $scope.data.vote.permission = returnRequest.permission; - + $scope.data.votants.push(angular.copy($scope.data.vote)); $scope.globalVariables.saved = true; initVote(); -- To stop receiving notification emails like this one, please contact Chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
Chorem.org scm