r3227 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll resources/i18n webapp/WEB-INF/jsp/poll
Author: fdesbois Date: 2012-04-02 18:42:32 +0200 (Mon, 02 Apr 2012) New Revision: 3227 Url: http://chorem.org/repositories/revision/pollen/3227 Log: Vote validation for maxChoiceNb and percentage Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-04-02 16:42:25 UTC (rev 3226) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-04-02 16:42:32 UTC (rev 3227) @@ -32,6 +32,7 @@ import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.business.persistence.Vote; +import org.chorem.pollen.business.persistence.VoteToChoice; /** * Votes to a poll. @@ -75,6 +76,29 @@ addFieldError("pollAccount.votingId", _("pollen.error.user.alreadyVoted")); } } + + + int nbVotes = 0; + int totalValues = 0; + for (VoteToChoice voteToChoice : vote.getChoiceVoteToChoice()) { + + Integer value = voteToChoice.getVoteValue(); + if (value != null && value != 0) { + nbVotes++; + totalValues += value; + } + } + + // check that the number of choices is not greater than maxChoiceNb + int maxChoice = getPoll().getMaxChoiceNb(); + if (maxChoice != 0 && nbVotes > maxChoice) { + addFieldError("vote.choices", _("pollen.error.vote.maxChoiceNb", maxChoice)); + } + + // check for percentage that the sum of all values equals 100 + if (isPercentageVoteCounting() && totalValues != 100) { + addFieldError("vote.choices", _("pollen.error.vote.percentage")); + } } @Override Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-04-02 16:42:25 UTC (rev 3226) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-04-02 16:42:32 UTC (rev 3227) @@ -161,6 +161,8 @@ pollen.error.user.not.found=User not found pollen.error.user.restrictedListsForbidden=The poll is restricted and you are not allowed to vote. Check if you have correctly used the link sent to you by email. pollen.error.userNotAllowed=You are not allowed to count the votes for this poll. +pollen.error.vote.maxChoiceNb=The maximal number of choices is %d. +pollen.error.vote.percentage=The sum of the values must be equals to 100. pollen.fieldset.connexionInformation=Connexion informations pollen.fieldset.login=Login pollen.fieldset.poll.choices=Choices Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-04-02 16:42:25 UTC (rev 3226) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-04-02 16:42:32 UTC (rev 3227) @@ -168,6 +168,8 @@ pollen.error.user.not.found=Utilisateur non trouvé pollen.error.user.restrictedListsForbidden=Le sondage est restreint et vous n'êtes pas autorisé à voter. Vérifiez que vous avez bien utiliser le lien qui vous a été envoyé. pollen.error.userNotAllowed=Vous n'êtes pas autorisé à dépouiller ce sondage. +pollen.error.vote.maxChoiceNb=Le nombre de choix maximal est de %d. +pollen.error.vote.percentage=La somme des valeurs doit être égale à 100. pollen.fieldset.connexionInformation=Information de connexion pollen.fieldset.login=Connexion pollen.fieldset.poll.choices=Les choix Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-04-02 16:42:25 UTC (rev 3226) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-04-02 16:42:32 UTC (rev 3227) @@ -413,7 +413,8 @@ </table> <div id="voteError"> <s:fielderror fieldName="pollAccount.votingId"/> - <%--<t:errors/>--%> + <s:fielderror fieldName="vote.choices"/> + <%--<t:errors/>--%> </div> <s:if test="voteAllowed">
participants (1)
-
fdesbois@users.chorem.org