This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See http://git.chorem.org/pollen.git commit da6bc80ed94a21af72b7ad2f2fb5b529439d8427 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Thu Jun 12 17:53:46 2014 +0200 edit Vote --- pollen-rest-api/src/main/resources/mapping | 14 +++---- .../src/main/webapp/js/controllers/pollCtrl.js | 48 +++++++++++++++++----- pollen-ui-angular/src/main/webapp/js/services.js | 4 +- .../src/main/webapp/partials/inline-poll.html | 3 +- 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/pollen-rest-api/src/main/resources/mapping b/pollen-rest-api/src/main/resources/mapping index 661740f..3d8011e 100644 --- a/pollen-rest-api/src/main/resources/mapping +++ b/pollen-rest-api/src/main/resources/mapping @@ -146,10 +146,10 @@ DELETE /v1/polls/{pollId}/voterLists/{voterListId}/members/{memberId} Vote # VoteApi -GET /v1/polls/{pollId}/votes VoteApi.getVotes -GET /v1/polls/{pollId}/votes/add VoteApi.addVote -GET /v1/polls/{pollId}/votes/{voteId}/edit VoteApi.editVote -POST /v1/polls/{pollId}/votes VoteApi.addVote -GET /v1/polls/{pollId}/votes/{voteId} VoteApi.getVote -PUT /v1/polls/{pollId}/votes/{voteId} VoteApi.editVote -DELETE /v1/polls/{pollId}/votes/{voteId} VoteApi.deleteVote +GET /v1/polls/{pollId}/votes VoteApi.getVotes +GET /v1/polls/{pollId}/votes/add VoteApi.addVote +GET /v1/polls/{pollId}/votes/{voteId}/edit VoteApi.editVote +POST /v1/polls/{pollId}/votes VoteApi.addVote +GET /v1/polls/{pollId}/votes/{voteId} VoteApi.getVote +PUT,POST /v1/polls/{pollId}/votes/{voteId} VoteApi.editVote +DELETE /v1/polls/{pollId}/votes/{voteId} VoteApi.deleteVote 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 0388b6d..6d298b4 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -657,12 +657,24 @@ angular.module('pollControllers', []) } initPoll(); + var initAuthor = function () { + if (angular.isDefined($scope.session.user)) { + if (angular.isDefined($scope.session.user.name)) { + $scope.data.vote.voterName = $scope.session.user.name; + } + else { + $scope.data.vote.voterName = $scope.session.user.email; + } + } + }; + $scope.globalVariables.editMode = false; $scope.globalVariables.voteMode = true; var initVote = function () { $scope.data.vote = {}; $scope.data.vote.voterName = ""; + initAuthor(); $scope.data.vote.anonymous = false; $scope.data.vote.choice = []; for (var i = 0; i < $scope.data.choices.length; ++i) { @@ -676,17 +688,33 @@ angular.module('pollControllers', []) choice.voteValue = (choice.voteValue) ? 1.0 : 0.0; }); - PollVote.add({pollId:$routeParams.pollId}, sendVote, function (returnRequest) { - $scope.data.vote.id = returnRequest.id; - $scope.data.vote.permission = returnRequest.permission; + if (angular.isDefined($scope.data.vote.id)) { + // edit vote + PollVote.update({pollId:$routeParams.pollId}, sendVote, function (data) { + $scope.globalVariables.saved = true; + }, function (error) { + $scope.data.vote.restError = { voterName : error.data["voter.name"]}; + }) + } + else { + // add vote + 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(); - }, function (error) { - $scope.data.vote.restError = { voterName : error.data["voter.name"]}; - }); + $scope.data.votants.push(angular.copy($scope.data.vote)); + $scope.globalVariables.saved = true; + initVote(); + }, function (error) { + $scope.data.vote.restError = { voterName : error.data["voter.name"]}; + }); + } } + + $scope.editVote = function (vote) { + $scope.data.vote = vote; + } + }]) .controller('PollCommentCtrl', @@ -709,7 +737,7 @@ angular.module('pollControllers', []) $scope.comment.authorName = $scope.session.user.name; } else { - $scope.comment.authorName = $scope.session.user.login; + $scope.comment.authorName = $scope.session.user.email; } } }; initAuthor(); diff --git a/pollen-ui-angular/src/main/webapp/js/services.js b/pollen-ui-angular/src/main/webapp/js/services.js index 3a82d25..c4dd105 100644 --- a/pollen-ui-angular/src/main/webapp/js/services.js +++ b/pollen-ui-angular/src/main/webapp/js/services.js @@ -77,7 +77,7 @@ angular.module('pollenServices', ['ngResource']) return 'vote='+encodeURIComponent(JSON.stringify(data)); }; - return $resource(conf.restURL+'/polls/:pollId/votes/:voteId', {voteId : '@id'}, + return $resource(conf.restURL+'/polls/:pollId/votes/:voteId', {voteId : '@id', permission : '@permission'}, { 'add' : { method:'POST', @@ -101,7 +101,7 @@ angular.module('pollenServices', ['ngResource']) return 'comment='+encodeURIComponent(JSON.stringify(data)); }; - return $resource(conf.restURL+'/polls/:pollId/comments/:commentId', {commentId : '@id'}, + return $resource(conf.restURL+'/polls/:pollId/comments/:commentId', {commentId : '@id', permission : '@permission'}, { 'add' : { method:'POST', diff --git a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html index 0b0b620..196300b 100644 --- a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html @@ -70,7 +70,8 @@ <input type="checkbox" ng-model="choice.voteValue" disabled /> </td> <td> - <a href="#/poll/vote/{{data.poll.id}}" ng-if="vote.permission"><span class="glyphicon glyphicon-pencil"></span></a> + <button class="btn btn-info" ng-if="vote.permission" ng-click="editVote(vote)"><span class="glyphicon glyphicon-pencil"></span></button> + <button class="btn btn-danger" ng-if="vote.permission" disabled><span class="glyphicon glyphicon-remove"></span></button> </td> </tr> <!-- end print vote --> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.