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 905a613422ee182ba371cd25f70a4c4c278b26e0 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Fri Aug 1 14:40:01 2014 +0200 edit vote on oneline not in form for new vote --- .../src/main/webapp/js/controllers/pollCtrl.js | 144 ++++++++++++++------- .../src/main/webapp/partials/inline-poll.html | 25 +++- 2 files changed, 116 insertions(+), 53 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 4982fd1..e1e4241 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -1160,65 +1160,117 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr }); } - if (angular.isDefined($scope.data.vote.id)) { - // edit vote - PollVote.update({pollId:$routeParams.pollId}, sendVote, function (data) { - $rootScope.$broadcast('newSuccess', 'vote.added'); - $location.url('/poll/vote/'+$routeParams.pollId+'/'+ data.permission); - }, function (error) { - $scope.data.vote.restError = { voterName : error.data["voter.name"]}; + PollVote.add({pollId:$routeParams.pollId}, sendVote, function (returnRequest) { + $scope.data.vote.id = returnRequest.id; + $scope.data.vote.permission = returnRequest.permission; + + angular.forEach($scope.data.vote.choice, function (choice) { + if (choice.voteValue == "") { + delete choice.voteValue; + } + }); + + PollVote.get({pollId:$routeParams.pollId, voteId:returnRequest.id, permission:returnRequest.permission}, function (newVote) { + $scope.data.votants.push(newVote); }) - } - else { - // add vote - PollVote.add({pollId:$routeParams.pollId}, sendVote, function (returnRequest) { - $scope.data.vote.id = returnRequest.id; - $scope.data.vote.permission = returnRequest.permission; - - angular.forEach($scope.data.vote.choice, function (choice) { - if (choice.voteValue == "") { - delete choice.voteValue; - } - }); - PollVote.get({pollId:$routeParams.pollId, voteId:returnRequest.id, permission:returnRequest.permission}, function (newVote) { - $scope.data.votants.push(newVote); - }) + $rootScope.$broadcast('newInfo', + $filter('translate')('vote.added.printLink', {url: + '<input type="text" class="form-control" value="' + + $scope.globalVariables.baseUrl+'#/poll/vote/'+$routeParams.pollId+'/'+ returnRequest.permission + + '" readonly />'}) + , -1); - $rootScope.$broadcast('newInfo', - $filter('translate')('vote.added.printLink', {url: - '<input type="text" class="form-control" value="' + - $scope.globalVariables.baseUrl+'#/poll/vote/'+$routeParams.pollId+'/'+ returnRequest.permission + - '" readonly />'}) - , -1); + $rootScope.$broadcast('newSuccess', 'vote.added'); + initVote(); + + $location.url('/poll/vote/'+$routeParams.pollId+'/'+ returnRequest.permission); + }, function (error) { + if (angular.isDefined(error.data["voter.name"])) { + $scope.data.vote.restError = { voterName : error.data["voter.name"]}; + } - $rootScope.$broadcast('newSuccess', 'vote.added'); - initVote(); + if (angular.isDefined(error.data["vote.totalVoteValue"])) { + $rootScope.$broadcast('newError', error.data["vote.totalVoteValue"][0]); + } - $location.url('/poll/vote/'+$routeParams.pollId+'/'+ returnRequest.permission); - }, function (error) { - if (angular.isDefined(error.data["voter.name"])) { - $scope.data.vote.restError = { voterName : error.data["voter.name"]}; + angular.forEach($scope.data.vote.choice, function (choice, key) { + if (angular.isDefined(error.data["vote.voteValue["+choice.choiceId+"]"])) { + choice.restError = error.data["vote.voteValue["+choice.choiceId+"]"]; + } + else { + delete choice.restError; } + }); + }); + } + + var oldVote - if (angular.isDefined(error.data["vote.totalVoteValue"])) { - $rootScope.$broadcast('newError', error.data["vote.totalVoteValue"][0]); + $scope.editVote = function (vote) { + if (angular.isDefined(oldVote)) { + angular.forEach($scope.data.votants, function(oneVote) { + if (oneVote != vote) { + $scope.cancelVote(oneVote); } + }); + } - angular.forEach($scope.data.vote.choice, function (choice, key) { - if (angular.isDefined(error.data["vote.voteValue["+choice.choiceId+"]"])) { - choice.restError = error.data["vote.voteValue["+choice.choiceId+"]"]; - } - else { - delete choice.restError; - } - }); + oldVote = angular.copy(vote); + vote.onEdit = true; + } + + $scope.cancelVote = function (vote) { + if (angular.isDefined(oldVote) && vote.id == oldVote.id) { + vote.onEdit = false; + + for (var i = 0; i < vote.choice.length; i++) { + vote.choice[i].voteValue = oldVote.choice[i].voteValue; + } + } + } + + $scope.saveVote = function (vote) { + var sendVote = angular.copy(vote); + if ($scope.voteCountingIsBoolean()) { + angular.forEach(sendVote.choice, function (choice) { + choice.voteValue = (choice.voteValue)?1.0:0.0; + }); + } else { + angular.forEach(sendVote.choice, function (choice) { + if (choice.voteValue == "") { + choice.voteValue = null; + } }); } + + + // edit vote + PollVote.update({pollId:$routeParams.pollId}, sendVote, function (data) { + vote.onEdit = false; + + delete $scope.data.vote.restError; + $rootScope.$broadcast('newSuccess', 'vote.added'); + $location.url('/poll/vote/'+$routeParams.pollId+'/'+ data.permission); + }, function (error) { + $scope.data.vote.restError = { voterName : error.data["voter.name"]}; + }) } - $scope.editVote = function (vote) { - $scope.data.vote = vote; + $scope.toggleVoteValue = function (choice, onEdit, event) { + if (onEdit) { + if ($scope.voteCountingIsBoolean()) { + if (choice.voteValue == null) { + choice.voteValue = true; + } + else { + choice.voteValue = !choice.voteValue; + } + if (angular.isDefined(event)) { + event.stopPropagation(); + } + } + } } $scope.deleteVote = function (vote) { 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 d255389..c38d63a 100644 --- a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html @@ -84,22 +84,33 @@ <!-- begin print vote --> <tr ng-repeat="vote in data.votants track by $index" class="pollAnim"> - <td class="pollChoice"> {{vote.voterName}}</td> + <td class="pollChoice text-muted"> {{vote.voterName}}</td> <td ng-repeat="choice in vote.choice" class="pollChoice" + ng-click="toggleVoteValue(choice, vote.onEdit, $event);" ng-class="{ voteTrue:choice.voteValue != null, voteFalse:(choice.voteValue == null || (choice.voteValue == false && data.voteCountingType.renderType == 'checkbox'))}"> - <div ng-show="data.voteCountingType.renderType == 'checkbox'"> - <input type="checkbox" ng-model="choice.voteValue" disabled /> + + <div ng-hide="vote.onEdit"> + <div ng-show="data.voteCountingType.renderType == 'checkbox'" > + <span class="glyphicon glyphicon-ok text-success" ng-show="choice.voteValue"></span> + </div> + <div ng-show="data.voteCountingType.renderType != 'checkbox'"> + {{choice.voteValue}} + </div> </div> - <div ng-show="data.voteCountingType.renderType != 'checkbox'"> - {{choice.voteValue}} + <div ng-show="vote.onEdit"> + <input-error error="choice.restError[0]" data="choice.voteValue"> + <input type="{{data.voteCountingType.renderType}}" ng-model="choice.voteValue" ng-disabled="!vote.onEdit" ng-click="toggleVoteValue(choice, vote.onEdit, $event);" /> + </input-error> </div> </td> <td> - <button class="btn btn-info" ng-if="vote.permission && !globalVariables.editMode" ng-click="editVote(vote)"><span class="glyphicon glyphicon-pencil"></span></button> - <button class="btn btn-danger" ng-if="vote.permission && !globalVariables.editMode" ng-click="deleteVote(vote)"><span class="glyphicon glyphicon-trash"></span></button> + <button class="btn btn-primary" ng-if="vote.permission && !globalVariables.editMode && vote.onEdit" ng-click="saveVote(vote)"><span class="glyphicon glyphicon-ok"></span></button> + <button class="btn btn-default" ng-if="vote.permission && !globalVariables.editMode && vote.onEdit" ng-click="cancelVote(vote)"><span class="glyphicon glyphicon-remove"></span></button> + <button class="btn btn-info" ng-if="vote.permission && !globalVariables.editMode && !vote.onEdit" ng-click="editVote(vote)"><span class="glyphicon glyphicon-pencil"></span></button> + <button class="btn btn-danger" ng-if="vote.permission && !globalVariables.editMode && !vote.onEdit" ng-click="deleteVote(vote)"><span class="glyphicon glyphicon-trash"></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>.