Author: fdesbois Date: 2010-03-08 14:23:02 +0100 (Mon, 08 Mar 2010) New Revision: 2899 Log: Ano #131 : display a message if the list is greater than 20 persons when creating the poll Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_en.properties branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_fr.properties branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/webapp/js/pollen.js branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/webapp/poll/PollCreation.tml Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-05 17:42:37 UTC (rev 2898) +++ branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-08 13:23:02 UTC (rev 2899) @@ -47,6 +47,7 @@ import org.apache.tapestry5.ioc.annotations.Symbol; import org.apache.tapestry5.ioc.services.PropertyAccess; import org.apache.tapestry5.json.JSONObject; +import org.apache.tapestry5.services.Request; import org.apache.tapestry5.upload.services.UploadSymbols; import org.chorem.pollen.business.business.PreventRuleManager; import org.chorem.pollen.business.dto.ChoiceDTO; @@ -1013,6 +1014,7 @@ * zone. */ public JSONObject onChangeFromListSelect(String value) { + JSONObject result = new JSONObject(); if (!"".equals(value)) { personList = serviceList.findPersonListById(value); @@ -1024,11 +1026,45 @@ votingLists.get(currentList).setPollAccountDTOs( personList.getPollAccountDTOs()); + + int size = personList.getPollAccountDTOs().size(); + + if (log.isDebugEnabled()) { + log.debug("List size : " + size); + } + + // If the list size is too large, an alert message will be shown + if (size > LIST_MAX_SHOW_PERSONS) { + result.put("listAlert", messages.format("list-maxSize-alert", + personList.getName(), size)); + } } - return createParamsForCallback(); + return createParamsForCallback(result); } + /** TODO : move this value to pollen.properties, waiting for 1.3 version **/ + public static final int LIST_MAX_SHOW_PERSONS = 20; + /** + * Test if the list size made an alert (too large to be shown). + * + * @return true if the current list size is > to LIST_MAX_SHOW_PERSONS + */ + public boolean isListSizeAlert() { + return votingList.getPollAccountDTOs().size() > LIST_MAX_SHOW_PERSONS; + } + + /** + * Get the message to show when the too large list size is loaded. + * + * @return the localized message to show when big list is loaded. + */ + public String getListMaxSizeLoadedMessage() { + return messages.format("list-maxSize-loaded", votingList.getName(), + votingList.getPollAccountDTOs().size()); + } + + /** * Méthode appelée à la sélection d'un type de choix. Le mixin ck/OnEvent ne * permet pas de retourner le contenu d'une zone. Il faut donc passer par * une fonction JavaScript pour activer un event link. Un lien est créé. Il @@ -1040,7 +1076,7 @@ */ public JSONObject onChangeFromChoiceType(String value) { poll.setChoiceType(ChoiceType.valueOf(value)); - return createParamsForCallback(); + return createParamsForCallback(new JSONObject()); } /** @@ -1049,8 +1085,8 @@ * * @return un JSONObject contenant un zoneId et une url. */ - private JSONObject createParamsForCallback() { - JSONObject json = new JSONObject(); + private JSONObject createParamsForCallback(JSONObject json) { + //JSONObject json = new JSONObject(); Link link = resources.createEventLink("updatePollCreationZone"); json.put("link", link.toAbsoluteURI()); json.put("zoneId", "pollCreationZone"); Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_en.properties =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_en.properties 2010-03-05 17:42:37 UTC (rev 2898) +++ branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_en.properties 2010-03-08 13:23:02 UTC (rev 2899) @@ -83,6 +83,8 @@ noList-validate=A list must contain at least one person. list-validate=Persons names must be unique. lists-validate=Lists names must be unique. +list-maxSize-alert=The list %s contains too many persons (%d) to be shown. You can manage your list on page 'Voting Lists' in 'Polls' menu. +list-maxSize-loaded=List %s with %d persons is correctly loaded, you can go to the next step. #choices choicesLegend=Step %d : poll choices Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_fr.properties =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_fr.properties 2010-03-05 17:42:37 UTC (rev 2898) +++ branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_fr.properties 2010-03-08 13:23:02 UTC (rev 2899) @@ -83,6 +83,8 @@ noList-validate=Une liste doit contenir au moins un votant. list-validate=Les noms des votants doivent \u00EAtre uniques. lists-validate=Les noms des listes doivent \u00EAtre uniques. +list-maxSize-alert=La liste %s contient trop de votants (%d) pour \u00EAtre affich\u00E9e. Vous pouvez g\u00E9rer votre liste sur la page 'Liste de votants' dans le menu 'Sondages'. +list-maxSize-loaded=Liste %s de %d votants correctement charg\u00E9, vous pouvez passer \u00E0 l'\u00E9tape suivante. #choices choicesLegend=\u00C9tape %d : les choix de votre sondage Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/webapp/js/pollen.js =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/webapp/js/pollen.js 2010-03-05 17:42:37 UTC (rev 2898) +++ branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/webapp/js/pollen.js 2010-03-08 13:23:02 UTC (rev 2899) @@ -30,5 +30,10 @@ */ function onCompleteZoneUpdate(response) { var zoneManager = Tapestry.findZoneManagerForZone(response.zoneId); + + if (response.listAlert) { + alert(response.listAlert); + } + zoneManager.updateFromURL(response.link); } \ No newline at end of file Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/webapp/poll/PollCreation.tml =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-03-05 17:42:37 UTC (rev 2898) +++ branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-03-08 13:23:02 UTC (rev 2899) @@ -195,17 +195,22 @@ <t:label for="groupWeight" /> <t:textfield t:id="groupWeight" t:value="votingList.weight" t:size="1" validate="required,min=1" /> </div> - <div t:type="loop" t:source="votingList.pollAccountDTOs" t:value="votingListPerson" t:volatile="true"> - <t:label for="personName" /> - <t:textfield t:id="personName" t:value="votingListPerson.votingId" /> - - - <t:label for="personEmail" /> - <t:textfield t:id="personEmail" t:value="votingListPerson.email" validate="regexp" /> - - - <t:label for="personWeight" /> - <t:textfield t:id="personWeight" t:value="votingListPerson.weight" t:size="1" validate="required,min=1" /> - </div> - <t:submit t:id="addPerson" t:value="${message:addPerson}" t:context="${votingListIndex}" t:defer="false"/> + <t:unless t:test="listSizeAlert"> + <div t:type="loop" t:source="votingList.pollAccountDTOs" t:value="votingListPerson" t:volatile="true"> + <t:label for="personName" /> + <t:textfield t:id="personName" t:value="votingListPerson.votingId" /> + - + <t:label for="personEmail" /> + <t:textfield t:id="personEmail" t:value="votingListPerson.email" validate="regexp" /> + - + <t:label for="personWeight" /> + <t:textfield t:id="personWeight" t:value="votingListPerson.weight" t:size="1" validate="required,min=1" /> + </div> + <t:submit t:id="addPerson" t:value="${message:addPerson}" t:context="${votingListIndex}" t:defer="false"/> + <p:else> + ${listMaxSizeLoadedMessage} + </p:else> + </t:unless> </div> </fieldset> <div class="buttons">