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 ae7b9d2bf3e5f3978dc4b36c2facd12f505a6d56 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Tue Aug 12 12:10:59 2014 +0200 UI check the maxChoiceNumber for limitdVote in pollType Normal --- pollen-ui-angular/src/main/webapp/i18n/en.js | 1 + pollen-ui-angular/src/main/webapp/i18n/fr.js | 1 + .../src/main/webapp/js/controllers/pollCtrl.js | 99 ++++++++++++++-------- .../src/main/webapp/partials/poll-info.html | 4 + 4 files changed, 70 insertions(+), 35 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/i18n/en.js b/pollen-ui-angular/src/main/webapp/i18n/en.js index 78fd1e5..d7ebbaa 100644 --- a/pollen-ui-angular/src/main/webapp/i18n/en.js +++ b/pollen-ui-angular/src/main/webapp/i18n/en.js @@ -125,6 +125,7 @@ var translateEN = { 'poll.info.addChoiceAllowed.waring' : 'The period for adding choice and vote overlays', 'poll.info.addChoiceAllowed.waring.help' : 'Votes may can\'t be representative of reality', 'poll.info.vote.noViewChoice' : 'This choice does not exist in the vote', +'poll.info.limitedChoice' : 'This poll has limited the number of choices at {{nb}} choice(s)', 'poll.error.noResource' : 'No resource has send', 'poll.error.listEmpty' : 'No poll find', diff --git a/pollen-ui-angular/src/main/webapp/i18n/fr.js b/pollen-ui-angular/src/main/webapp/i18n/fr.js index c6670dd..6238511 100644 --- a/pollen-ui-angular/src/main/webapp/i18n/fr.js +++ b/pollen-ui-angular/src/main/webapp/i18n/fr.js @@ -125,6 +125,7 @@ var translateFR = { 'poll.info.addChoiceAllowed.waring' : 'La période d\'ajout de choix et de vote se superpose', 'poll.info.addChoiceAllowed.waring.help' : 'Les votes peuvent ne pas être représentatif de la réalité.', 'poll.info.vote.noViewChoice' : 'Ce choix n\'existait pas lors du vote', +'poll.info.limitedChoice' : 'Le nombre de choix est limité à {{nb}} choix', 'poll.error.noResource' : 'Aucune ressource a envoyer', 'poll.error.listEmpty' : 'Aucun sondage trouvé', 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 29d2336..d557d2a 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -140,6 +140,7 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr pollDeferred.promise.then(function () { setVoteCountingType(); + $scope.data.poll.limitedVote = $scope.data.poll.maxChoiceNumber > 0; }); pollDeferred.promise.then(function () { @@ -236,7 +237,7 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr if (angular.isDate(choice.choiceValue)) { choice.choiceValue = choice.choiceValue.getTime(); } - else { + else if (!angular.isNumber(choice.choiceValue)) { choice.choiceValue = null; } } @@ -778,8 +779,8 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr var poll = angular.copy($scope.data.poll); poll.choice = angular.copy($scope.data.choices); - angular.forEach(poll.choice, function(choice) { - choice = $scope.preSendChoice(choice); + angular.forEach(poll.choice, function(choice, key) { + poll.choice[key] = $scope.preSendChoice(choice); }); if (angular.isDate(poll.beginDate)) { @@ -796,6 +797,10 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr poll.endChoiceDate = poll.endChoiceDate.getTime(); } + if (! poll.limitedVote) { + poll.maxChoiceNumber = 0; + } + Poll.add(poll, function (data) { $rootScope.$broadcast('newInfo', $filter('translate')('poll.created.printLink', {url: @@ -936,7 +941,7 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr } var vl = {group: voterList.group, members:[]}; - angular.forEach(voterList.members, function(member, key) { + angular.forEach(voterList.members, function(member) { if (!$scope.memberIsEmpty(member)) { vl.members.push(member); } @@ -1027,7 +1032,7 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr }).then( function () { var confirmDelete = confirm(confirmMessage); if (confirmDelete == true) { - PollVoterList.remove({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken, voterListId:voterList.group.id}, function (data) { + PollVoterList.remove({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken, voterListId:voterList.group.id}, function () { var index = $scope.data.voterList.indexOf(voterList); $scope.data.voterList.splice(index, 1); if ($scope.data.voterList.length == 0 && $scope.data.poll.pollType == 'RESTRICTED') { @@ -1075,10 +1080,10 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr initVoterList(); PollChoice.query({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}).$promise.then(function (choices) { - $scope.data.choices = choices; - angular.forEach(choices, function (ch) { - ch = $scope.postReceiveChoice(ch); + angular.forEach(choices, function (ch, key) { + choices[key] = $scope.postReceiveChoice(ch); }); + $scope.data.choices = choices; $scope.data.vote = {}; $scope.data.vote.choice = angular.copy($scope.data.choices); }); @@ -1152,8 +1157,8 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr } var pollChoicePromise = PollChoice.query({pollId:$routeParams.pollId}, function (choices) { - angular.forEach(choices, function (ch) { - ch = $scope.postReceiveChoice(ch); + angular.forEach(choices, function (ch, key) { + choices[key] = $scope.postReceiveChoice(ch); }); $scope.data.choices = choices; @@ -1335,18 +1340,24 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr }; $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(); + if (onEdit && $scope.voteCountingIsBoolean()) { + if (choice.voteValue == false && $scope.data.poll.maxChoiceNumber > 0) { + // compte number of choice + var myVote = $.grep($scope.data.votants, function(e) { return e.id == oldVote.id; }); + myVote = myVote[0]; + var nbChoice = 0; + angular.forEach(myVote.choice, function (ch) { + if (ch.voteValue) { + nbChoice++; + } + }); + if (nbChoice < $scope.data.poll.maxChoiceNumber) { + toggleValue(choice,event); } } + else { + toggleValue(choice, event); + } } }; @@ -1372,17 +1383,33 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr $scope.toggleValue = function (choice, event) { if ($scope.voteCountingIsBoolean()) { - if (choice.voteValue == null) { - choice.voteValue = true; - } - else { - choice.voteValue = !choice.voteValue; - } - if (angular.isDefined(event)) { - event.stopPropagation(); + if (choice.voteValue == false && $scope.data.poll.maxChoiceNumber > 0) { + var nbChoice = 0; + angular.forEach($scope.data.vote.choice, function (ch) { + if (ch.voteValue) { + nbChoice++; + } + }); + if (nbChoice < $scope.data.poll.maxChoiceNumber) { + toggleValue(choice,event); + } + } else { + toggleValue(choice, event); } } - } + }; + + var toggleValue = function (choice, event) { + if (choice.voteValue == null) { + choice.voteValue = true; + } + else { + choice.voteValue = !choice.voteValue; + } + if (angular.isDefined(event)) { + event.stopPropagation(); + } + }; }]) @@ -1590,8 +1617,8 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr var choicesDeferred = $q.defer(); PollChoice.query({pollId:$routeParams.pollId}, function (choices) { $scope.data.choices = choices; - angular.forEach(choices, function (choice) { - choice = $scope.postReceiveChoice(choice); + angular.forEach(choices, function (choice, key) { + choices[key] = $scope.postReceiveChoice(choice); }); choicesDeferred.resolve('choices load'); }); @@ -1742,11 +1769,13 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr // check the global right $scope.globalVariables.hasAllRight = true; for (var pollIndex in $scope.data.polls) { - var poll = $scope.data.polls[pollIndex]; + if ($scope.data.polls.hasOwnProperty(pollIndex)) { + var poll = $scope.data.polls[pollIndex]; - if (angular.isUndefined(poll.permission)) { - $scope.globalVariables.hasAllRight = false; - break; + if (angular.isUndefined(poll.permission)) { + $scope.globalVariables.hasAllRight = false; + break; + } } } diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-info.html b/pollen-ui-angular/src/main/webapp/partials/poll-info.html index 377d2f0..62f4ad3 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll-info.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll-info.html @@ -30,4 +30,8 @@ <p> {{ 'poll.info.addChoiceAllowed.waring.help' | translate }} </p> +</div> + +<div ng-if="data.poll.limitedVote"> + <h4>{{ 'poll.info.limitedChoice' | translate:{'nb':data.poll.maxChoiceNumber} }}</h4> </div> \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.