Author: fdesbois Date: 2010-03-20 16:30:29 +0100 (Sat, 20 Mar 2010) New Revision: 2952 Log: - Rename pollId by pollUId in PollDTO - Evo #151 : using i18n tapestry-bundle and use keys from i18n - Evo #150 : place image managment in a new service - Refactor VoteForPoll page (70%) Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/Confirm.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java trunk/pollen-ui/src/main/webapp/js/confirm.js trunk/pollen-ui/src/main/webapp/js/zoneUpdater.js Removed: trunk/pollen-ui/src/main/webapp/js/ZoneUpdater.js Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoice.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccount.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVote.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties trunk/pollen-business/src/main/resources/pollen.properties trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/ContextLink.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/Polls.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/ZoneUpdater.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CloseValidation.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CreationValidation.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ModificationValidation.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/ImageUtil.java trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties trunk/pollen-ui/src/main/webapp/WEB-INF/web.xml trunk/pollen-ui/src/main/webapp/img/1leftarrow.png trunk/pollen-ui/src/main/webapp/img/1rightarrow.png trunk/pollen-ui/src/main/webapp/img/2leftarrow.png trunk/pollen-ui/src/main/webapp/img/2rightarrow.png trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -151,7 +151,7 @@ String name = entity.getName(); dto.setHidden(name != null && name.startsWith(NumberMethod.HIDDEN_PREFIX)); - dto.setPollId(entity.getPoll().getTopiaId()); + dto.setPollUId(entity.getPoll().getPollId()); return dto; } @@ -166,7 +166,7 @@ public static PollDTO convert(Poll entity, PollDTO dto) { BinderProvider.getBinder(Poll.class, PollDTO.class).copy(entity, dto); dto.setId(entity.getTopiaId()); - dto.setPollId(entity.getPollId()); + dto.setPollUId(entity.getPollId()); dto.setChoiceType(ChoiceType.valueOf(entity.getChoiceType())); dto.setPollType(PollType.valueOf(entity.getPollType())); dto.setVoteCounting(VoteCountingType.valueOf(entity.getVoteCounting())); @@ -244,12 +244,17 @@ //if (!entity.getAnonymous()) { PollAccount account = entity.getPollAccount(); VotingList list = entity.getVotingList(); + // Set references // vote for a list if (list != null) { dto.setVotingListId(list.getTopiaId()); // vote for a person (pollAccount) - } else if (account != null) { + } else {/*if (account != null) { must have a pollaccount */ dto.setPollAccountId(account.getTopiaId()); + dto.setName(account.getVotingId()); +// if (account.getUserAccount() != null) { +// dto.setUserId(account.getUserAccount().getTopiaId()); +// } } //} Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -41,13 +41,16 @@ * * @param choiceDTO Le dto choix * @param eChoice L'entité choix + * @deprecated use {@link org.chorem.pollen.business.PollenConverter} */ + @Deprecated public void populateChoiceEntity(ChoiceDTO choiceDTO, Choice eChoice) throws TopiaException { eChoice.setName(choiceDTO.getName()); eChoice.setDescription(choiceDTO.getDescription()); eChoice.setValidate(choiceDTO.isValidate()); + // Very bad, must create the choice on the poll not the inverse if (choiceDTO.getPollId().length() > 0) { PollDAO pollDAO = PollenModelDAOHelper .getPollDAO(super.transaction); @@ -61,7 +64,7 @@ * * @param eChoice L'entité choix * @return Le dto choix - * @deprecated use {@link ConverterHelper} + * @deprecated use {@link org.chorem.pollen.business.PollenConverter} */ @Deprecated public ChoiceDTO createChoiceDTO(Choice eChoice) { @@ -75,7 +78,7 @@ choiceDTO.setValidate(eChoice.getValidate()); if (eChoice.getPoll() != null) { - choiceDTO.setPollId(eChoice.getPoll().getTopiaId()); + choiceDTO.setPollUId(eChoice.getPoll().getPollId()); } return choiceDTO; Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -61,6 +61,11 @@ */ private String pollId = ""; + /** + * pollUId of the poll owner of this choice + */ + private String pollUId; + /** used for specific choice in Number VoteCounting **/ private Boolean hidden = false; @@ -68,14 +73,16 @@ } + @Deprecated public ChoiceDTO(String id) { this.id = id; } + @Deprecated public ChoiceDTO(String name, String voteId, String pollId) { this.name = name; this.voteId = voteId; - this.pollId = pollId; + //this.pollId = pollId; } public String getId() { @@ -138,6 +145,14 @@ this.pollId = pollId; } + public String getPollUId() { + return pollUId; + } + + public void setPollUId(String pollUId) { + this.pollUId = pollUId; + } + public Boolean isHidden() { return hidden; } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -37,7 +37,7 @@ private String id = ""; - private String pollId = ""; + private String pollUId; private String title = ""; @@ -90,7 +90,7 @@ private List<PreventRuleDTO> preventRuleDTOs = new ArrayList<PreventRuleDTO>(); - private List<ChoiceDTO> choiceDTOs = new ArrayList<ChoiceDTO>(); + private List<ChoiceDTO> choices = new ArrayList<ChoiceDTO>(); private List<ResultDTO> resultDTOs = new ArrayList<ResultDTO>(); @@ -120,12 +120,12 @@ this.id = id; } - public String getPollId() { - return pollId; + public String getPollUId() { + return pollUId; } - public void setPollId(String pollId) { - this.pollId = pollId; + public void setPollUId(String pollId) { + this.pollUId = pollId; } public String getTitle() { @@ -384,20 +384,35 @@ } public List<ChoiceDTO> getChoices() { - return choiceDTOs; + return choices; } public void setChoices(List<ChoiceDTO> choiceDTOs) { - this.choiceDTOs = choiceDTOs; + this.choices = choiceDTOs; } public void addChoice(ChoiceDTO choice) { - if (choiceDTOs == null) { - choiceDTOs = new ArrayList<ChoiceDTO>(); + if (choices == null) { + choices = new ArrayList<ChoiceDTO>(); } - choiceDTOs.add(choice); + choices.add(choice); } + public boolean removeChoice(String choiceId) { + if (choices == null) { + return false; + } + Iterator<ChoiceDTO> it = choices.iterator(); + while (it.hasNext()) { + ChoiceDTO choice = it.next(); + if (choiceId.equals(choice.getId())) { + it.remove(); + return true; + } + } + return false; + } + public List<ResultDTO> getResultDTOs() { return resultDTOs; } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoice.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoice.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoice.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -40,17 +40,6 @@ public String createChoice(ChoiceDTO choice); /** - * Création des choix du sondage - * - * @param choices les dtos choix - * @param pollId l'identifiant du sondage - * @param transaction la transaction du sondage - * @return les choix créés - */ - public List<Choice> createChoices(List<ChoiceDTO> choices, String pollId, - TopiaContext transaction); - - /** * Mise à jour d'un choix pour un sondage * * @param choiceDTO @@ -63,7 +52,9 @@ * * @param choiceId l'identifiant du choix * @return true si le choix a été mis à jours + * @deprecated use {@link org.chorem.pollen.business.services.ServicePoll#deleteChoice(org.chorem.pollen.business.dto.PollDTO, java.lang.String) } */ + @Deprecated public boolean deleteChoice(String choiceId); /** Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -81,34 +81,34 @@ } } - @Override - public List<Choice> createChoices(List<ChoiceDTO> choices, String pollId, - TopiaContext transaction) { - if (choices.isEmpty() || pollId.length() == 0) { - return null; - } +// @Override +// public List<Choice> createChoices(List<ChoiceDTO> choices, String pollId, +// TopiaContext transaction) { +// if (choices.isEmpty() || pollId.length() == 0) { +// return null; +// } +// +// List<Choice> result = null; +// try { +// choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction); +// converter.setTransaction(transaction); +// +// result = new ArrayList<Choice>(); +// for (ChoiceDTO choice : choices) { +// Choice choiceEntity = choiceDAO.create(); +// choice.setId(choiceEntity.getTopiaId()); +// //choice.setPollUId(pollId); +// converter.populateChoiceEntity(choice, choiceEntity); +// result.add(choiceEntity); +// } +// +// return result; +// } catch (Exception e) { +// ContextUtil.doCatch(e, transaction); +// return null; +// } +// } - List<Choice> result = null; - try { - choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction); - converter.setTransaction(transaction); - - result = new ArrayList<Choice>(); - for (ChoiceDTO choice : choices) { - Choice choiceEntity = choiceDAO.create(); - choice.setId(choiceEntity.getTopiaId()); - choice.setPollId(pollId); - converter.populateChoiceEntity(choice, choiceEntity); - result.add(choiceEntity); - } - - return result; - } catch (Exception e) { - ContextUtil.doCatch(e, transaction); - return null; - } - } - @Override public boolean updateChoice(ChoiceDTO choiceDTO) { TopiaContext transaction = null; Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -18,6 +18,7 @@ import java.util.List; import java.util.Map; +import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.business.dto.CommentDTO; import org.chorem.pollen.business.dto.PollAccountDTO; import org.chorem.pollen.business.dto.PollDTO; @@ -75,7 +76,7 @@ * @param pollId identifiant du sondage (différent du topiaId) * @return le sondage */ - public PollDTO findPollByPollId(String pollId); + public PollDTO getPoll(String pollId); /** * Récupération des sondages d'un utilisateur @@ -154,4 +155,8 @@ * pollAccount in poll restriction for the accountUId in argument */ public PollAccountDTO getRestrictedAccount(String accountUId, PollDTO poll); + + public ChoiceDTO getNewHiddenChoice(ChoiceDTO choice, String votingId); + + public void deleteChoice(PollDTO poll, String choiceId); } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccount.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccount.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccount.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -17,9 +17,9 @@ package org.chorem.pollen.business.services; import java.util.List; -import java.util.Map; import org.chorem.pollen.business.dto.PollAccountDTO; +import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.persistence.PollAccount; import org.nuiton.topia.TopiaContext; Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -18,20 +18,17 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.UUID; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenBusinessException; import org.chorem.pollen.business.PollenContext; import org.chorem.pollen.business.converters.DataPollAccountConverter; import org.chorem.pollen.business.dto.PollAccountDTO; +import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.business.persistence.PollAccountDAO; import org.chorem.pollen.business.persistence.PollenModelDAOHelper; -import org.chorem.pollen.business.persistence.UserAccount; -import org.chorem.pollen.business.persistence.UserAccountDAO; import org.chorem.pollen.business.utils.ContextUtil; import org.nuiton.topia.TopiaContext; Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -56,6 +56,7 @@ import org.chorem.pollen.business.persistence.PersonToListDAO; import org.chorem.pollen.common.PollType; import org.chorem.pollen.common.VoteCountingType; +import org.chorem.pollen.votecounting.business.NumberMethod; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; @@ -77,7 +78,7 @@ private DataPollConverter converter = new DataPollConverter(); /** log. */ private static final Log log = LogFactory.getLog(ServicePollImpl.class); - + public ServicePollImpl() { rootContext = PollenContext.getRootContext(); @@ -95,12 +96,17 @@ TopiaContext transaction = null; String result = null; try { + + if (log.isInfoEnabled()) { + log.info("P:[ createPoll ] : " + pollDTO); + } + transaction = rootContext.beginTransaction(); pollDAO = PollenModelDAOHelper.getPollDAO(transaction); // Create with the pollId from dto - String pollId = pollDTO.getPollId(); + String pollId = pollDTO.getPollUId(); Poll entity = pollDAO.create(pollId); PollenConverter.convert(pollDTO, entity); @@ -243,6 +249,11 @@ public boolean updatePoll(PollDTO pollDTO) { TopiaContext transaction = null; try { + + if (log.isInfoEnabled()) { + log.info("P:[ updatePoll ] : " + pollDTO); + } + transaction = rootContext.beginTransaction(); pollDAO = PollenModelDAOHelper.getPollDAO(transaction); @@ -276,7 +287,7 @@ } catch (Exception eee) { PollenContext.doCatch(transaction, eee, n_("pollen.error.servicePoll.updatePoll"), - pollDTO.getTitle(), pollDTO.getPollId()); + pollDTO.getTitle(), pollDTO.getPollUId()); return false; } finally { PollenContext.doFinally(transaction); @@ -288,7 +299,7 @@ PollDTO newPoll = new PollDTO(); newPoll.setVoteCounting(VoteCountingType.NORMAL); newPoll.setPollType(PollType.FREE); - newPoll.setPollId(PollenContext.createPollenUrlId()); + newPoll.setPollUId(PollenContext.createPollenUrlId()); return newPoll; } @@ -302,6 +313,11 @@ public boolean deletePoll(String pollId) { TopiaContext transaction = null; try { + + if (log.isInfoEnabled()) { + log.info("P:[ deletePoll ] : pollId = " + pollId); + } + transaction = rootContext.beginTransaction(); pollDAO = PollenModelDAOHelper.getPollDAO(transaction); @@ -326,12 +342,12 @@ } @Override - public PollDTO findPollByPollId(String pollId) { + public PollDTO getPoll(String pollId) { TopiaContext transaction = null; PollDTO result = null; try { if (log.isInfoEnabled()) { - log.info("findPollByPollId : pollUId = " + pollId); + log.info("P:[ getPoll ] : pollUId = " + pollId); } transaction = rootContext.beginTransaction(); @@ -628,7 +644,7 @@ TopiaContext transaction = null; try { if (log.isInfoEnabled()) { - log.info("createComment : pollUId = " + poll.getPollId() + + log.info("P:[ createComment ] : pollUId = " + poll.getPollUId() + " _ comment = " + comment); } transaction = rootContext.beginTransaction(); @@ -665,7 +681,7 @@ TopiaContext transaction = null; try { if (log.isInfoEnabled()) { - log.info("deleteComment : pollUId = " + poll.getPollId() + + log.info("P:[ deleteComment ] : pollUId = " + poll.getPollUId() + " _ commentId = " + commentId); } transaction = rootContext.beginTransaction(); @@ -702,13 +718,13 @@ List<CommentDTO> results = new ArrayList<CommentDTO>(); try { if (log.isInfoEnabled()) { - log.info("getComments : pollUId = " + poll.getPollId()); + log.info("P:[ getComments ] : pollUId = " + poll.getPollUId()); } transaction = rootContext.beginTransaction(); CommentDAO dao = PollenModelDAOHelper.getCommentDAO(transaction); TopiaQuery query = dao.createQuery(). - add(Comment.POLL + "." + Poll.POLL_ID, poll.getPollId()); + add(Comment.POLL + "." + Poll.POLL_ID, poll.getPollUId()); List<Comment> entities = dao.findAllByQuery(query); @@ -736,8 +752,8 @@ transaction = rootContext.beginTransaction(); if (log.isInfoEnabled()) { - log.info("getRestrictedAccount : accountUId = " + accountUId + - " _ pollUId = " + poll.getPollId()); + log.info("P:[ getRestrictedAccount ] : accountUId = " + accountUId + + " _ pollUId = " + poll.getPollUId()); } // Use PersonToList association entity to find coherence between @@ -755,7 +771,7 @@ add(PersonToList.POLL_ACCOUNT + "." + PollAccount.ACCOUNT_ID, accountUId). add(PersonToList.VOTING_LIST + "." + - VotingList.POLL + "." + Poll.POLL_ID, poll.getPollId()); + VotingList.POLL + "." + Poll.POLL_ID, poll.getPollUId()); PersonToList assoc = dao.findByQuery(query); @@ -767,10 +783,59 @@ } catch (Exception eee) { PollenContext.doCatch(transaction, eee, n_("pollen.error.servicePoll.getRestrictedAccount"), - accountUId, poll.getPollId()); + accountUId, poll.getPollUId()); } finally { PollenContext.doFinally(transaction); } return result; } + + @Override + public ChoiceDTO getNewHiddenChoice(ChoiceDTO choice, String votingId) { + ChoiceDTO hiddenChoice = new ChoiceDTO(); + hiddenChoice.setName(NumberMethod.HIDDEN_PREFIX + + choice.getName() + "#" + votingId); + hiddenChoice.setHidden(true); + hiddenChoice.setValue(choice.getValue()); // ?? + hiddenChoice.setPollUId(choice.getPollUId()); + hiddenChoice.setVoteId(choice.getVoteId()); // ?? + hiddenChoice.setValidate(false); + return hiddenChoice; + } + + @Override + public void deleteChoice(PollDTO poll, String choiceId) { + TopiaContext transaction = null; + try { + if (log.isInfoEnabled()) { + log.info("P:[ deleteChoice ] : pollUId = " + poll.getPollUId() + + " _ choiceId = " + choiceId); + } + transaction = rootContext.beginTransaction(); + + // Find the comment + ChoiceDAO dao = PollenModelDAOHelper.getChoiceDAO(transaction); + Choice eChoice = dao.findByTopiaId(choiceId); + + // Get the poll entity corresponding + Poll ePoll = PollenModelDAOHelper.getPollDAO(transaction). + findByTopiaId(poll.getId()); + + // The remove will delete the choice because no poll will be + // attached to him (delete-orphan) + ePoll.removeChoice(eChoice); + + transaction.commitTransaction(); + + // Update change in dto + poll.removeChoice(choiceId); + + } catch (Exception eee) { + PollenContext.doCatch(transaction, eee, + n_("pollen.error.servicePoll.deleteChoice"), choiceId, + poll.getTitle(), poll.getId()); + } finally { + PollenContext.doFinally(transaction); + } + } } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVote.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVote.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVote.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -21,6 +21,7 @@ import org.chorem.pollen.business.dto.PollAccountDTO; import org.chorem.pollen.business.dto.PollDTO; +import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.dto.VoteDTO; /** @@ -68,6 +69,8 @@ public List<VoteDTO> getVotesByPoll(PollDTO poll, int startIndex, int endIndex); + public PollAccountDTO getNewPollAccount(UserDTO user); + /** * Test if the {@code votingId} has already voted for the {@code poll}. * Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -23,10 +23,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenConverter; import org.chorem.pollen.business.converters.DataPollAccountConverter; import org.chorem.pollen.business.converters.DataVoteConverter; import org.chorem.pollen.business.dto.PollAccountDTO; import org.chorem.pollen.business.dto.PollDTO; +import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.dto.VoteDTO; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; @@ -56,6 +58,8 @@ public ServiceVoteImpl() { rootContext = PollenContext.getRootContext(); + + PollenConverter.prepareVoteConverters(); } @Override @@ -195,7 +199,8 @@ List<VoteDTO> results = new ArrayList<VoteDTO>(); try { if (log.isInfoEnabled()) { - log.info("getVotesByPoll : pollUId = " + poll.getPollId() + + log.info("P:[ getVotesByPoll ] : " + + "pollUId = " + poll.getPollUId() + " _ startIndex = " + startIndex + " _ endIndex = " + endIndex); } @@ -221,22 +226,26 @@ // Order the results by creation date (the last vote done will be // at the end of the list) TopiaQuery query = voteDAO.createQuery(). - add(Vote.POLL + "." + Poll.POLL_ID, poll.getPollId()). + add(Vote.POLL + "." + Poll.POLL_ID, poll.getPollUId()). addOrder(TopiaEntity.TOPIA_CREATE_DATE). setLimit(startIndex, endIndex); - List<Vote> votes = voteDAO.findAllByQuery(query); + List<Vote> eVotes = voteDAO.findAllByQuery(query); if (log.isDebugEnabled()) { - log.debug("Nb votes found : " + votes.size()); + log.debug("Nb votes found : " + eVotes.size()); } - converter.setTransaction(transaction); - results = converter.createVoteDTOs(votes); + for (Vote eVote : eVotes) { + VoteDTO vote = PollenConverter.convert(eVote, new VoteDTO()); + results.add(vote); + } +// converter.setTransaction(transaction); +// results = converter.createVoteDTOs(votes); } catch (Exception eee) { PollenContext.doCatch(transaction, eee, n_("pollen.error.serviceVote.getVotesByPoll"), - poll.getPollId()); + poll.getPollUId()); } finally { PollenContext.doFinally(transaction); } @@ -244,13 +253,32 @@ } @Override + public PollAccountDTO getNewPollAccount(UserDTO user) { + PollAccountDTO result = new PollAccountDTO(); + if (user == null) { + return result; + } + if (user.getFirstName() != null && user.getLastName() != null) { + result.setVotingId( + user.getFirstName() + " " + user.getLastName()); + + } else if (user.getFirstName() != null) { + result.setVotingId(user.getFirstName()); + + } else if (user.getLastName() != null) { + result.setVotingId(user.getLastName()); + } + return result; + } + + @Override public boolean hasAlreadyVoted(String votingId, PollDTO poll) { TopiaContext transaction = null; boolean result = false; try { if (log.isInfoEnabled()) { - log.info("hasAlreadyVoted : votingId = " + votingId + - " _ pollUId = " + poll.getPollId()); + log.info("P:[ hasAlreadyVoted ] : votingId = " + votingId + + " _ pollUId = " + poll.getPollUId()); } transaction = rootContext.beginTransaction(); @@ -265,7 +293,7 @@ // Test using a count on votes TopiaQuery query = new TopiaQuery(Vote.class). - add(Vote.POLL + "." + Poll.POLL_ID, poll.getPollId()). + add(Vote.POLL + "." + Poll.POLL_ID, poll.getPollUId()). add(Vote.POLL_ACCOUNT + "." + PollAccount.VOTING_ID, votingId); @@ -278,7 +306,7 @@ } catch (Exception eee) { PollenContext.doCatch(transaction, eee, n_("pollen.error.serviceVote.hasAlreadyVoted"), - votingId, poll.getPollId()); + votingId, poll.getPollUId()); } finally { PollenContext.doFinally(transaction); } @@ -298,8 +326,7 @@ if (properties == null) { voteEntities = voteDAO.findAll(); if (log.isWarnEnabled()) { - log - .warn("Attention : tous les votes ont été sélectionnés !"); + log.warn("Attention : tous les votes ont été sélectionnés !"); } } else { voteEntities = voteDAO.findAllByProperties(properties); Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties =================================================================== --- trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-03-20 15:30:29 UTC (rev 2952) @@ -9,6 +9,7 @@ pollen.error.servicePoll.addComment= pollen.error.servicePoll.createPoll= pollen.error.servicePoll.delete= +pollen.error.servicePoll.deleteChoice= pollen.error.servicePoll.deleteComment= pollen.error.servicePoll.deletePoll= pollen.error.servicePoll.getAllPolls= Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties =================================================================== --- trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-03-20 15:30:29 UTC (rev 2952) @@ -8,6 +8,7 @@ pollen.error.serviceList.deleteAccountFromPersonList= pollen.error.servicePoll.addComment=Impossible d'ajouter un nouveau commentaire cr\u00E9\u00E9 par %1$s pour le sondage %2$s (%3$s) pollen.error.servicePoll.createPoll=Impossible d'enregistrer le sondage %1$s cr\u00E9\u00E9 par %2$s +pollen.error.servicePoll.deleteChoice= pollen.error.servicePoll.deleteComment=Impossible de supprimer le commentaire ayant pour identifiant "%1$s", appartenenant au sondage %2$s (%3$s) pollen.error.servicePoll.deletePoll=Impossible de supprimer le sondage ayant pou identifiant "%1$s" pollen.error.servicePoll.getAllPolls= Modified: trunk/pollen-business/src/main/resources/pollen.properties =================================================================== --- trunk/pollen-business/src/main/resources/pollen.properties 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/main/resources/pollen.properties 2010-03-20 15:30:29 UTC (rev 2952) @@ -20,7 +20,7 @@ topia.service.migration.mappingsdir=oldmappings topia.service.migration.modelnames=pollen -## Initialisation de la base de donn\u00C3\u00A9es +## Initialisation de la base de donn\u00E9es #choiceType=DATE,IMAGE,TEXT #pollType=RESTRICTED,FREE,GROUP #voteCounting=NORMAL,PERCENTAGE,CONDORCET,NUMBER @@ -31,7 +31,7 @@ adminEmail=admin@domain.com ## R\u00C3\u00A9pertoire des images transf\u00C3\u00A9r\u00C3\u00A9es -upImgDir=.pollen/uploadedImages +upImgDir=${HOME}/.pollen/uploadedImages ## Taille maximal des images transf\u00C3\u00A9r\u00C3\u00A9es (en octets) upload.filesize-max=1048576 @@ -42,11 +42,11 @@ email_port=25 email_from=bot@pollen.org -## R\u00C3\u00A9pertoire des flux de syndication (Atom) -feedDir=.pollen/feeds +## R\u00E9pertoire des flux de syndication (Atom) +feedDir=${HOME}/.pollen/feeds ## Repertoire de stockage des mails a envoyer -pollen.emails.directory=.pollen/emails +pollen.emails.directory=${HOME}/.pollen/emails ## Nombre de votes a afficher par page pollen.ui.nbVotesPerPage=25 Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -47,6 +47,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.nuiton.util.beans.BinderProvider; /** * Tests du service de gestion des sondages. @@ -78,6 +79,7 @@ @After public void tearDown() throws IOException { TestManager.stop(); + BinderProvider.clear(); } /** @@ -203,9 +205,9 @@ dto.setChoiceType(ChoiceType.TEXT); dto.setVoteCounting(VoteCountingType.NORMAL); pollId = instance.createPoll(dto); - String pollUID = dto.getPollId(); + String pollUID = dto.getPollUId(); log.debug("pollUID : " + pollUID); - PollDTO result = instance.findPollByPollId(pollUID); + PollDTO result = instance.getPoll(pollUID); log.debug("title : " + result.getTitle()); assertEquals(pollId, result.getId()); assertEquals(VoteCountingType.NORMAL, result.getVoteCounting()); Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/ContextLink.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/ContextLink.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/ContextLink.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -21,16 +21,16 @@ /** * ContextPath for the link + * * @return a String contextPath - * @ */ public String getContextPath() ; /** * Get a file from context with name defined by filename. + * * @param filename name of the file to get * @return a File with absolutePath corresponding to contextPath + filename - * @ */ public File getFile(String filename) ; } Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/Polls.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/Polls.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/Polls.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -135,7 +135,7 @@ public String getAdminId() { PollAccountDTO creator = servicePollAccount.findPollAccountById(poll .getCreatorId()); - return poll.getPollId() + ":" + creator.getAccountId(); + return poll.getPollUId() + ":" + creator.getAccountId(); } /** @@ -170,7 +170,7 @@ } confirmPoll.setBackPage(backPage); confirmPoll.setAction(pollAction); - confirmPoll.setPoll(servicePoll.findPollByPollId(pollId)); + confirmPoll.setPoll(servicePoll.getPoll(pollId)); return confirmPoll; } Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -49,7 +49,9 @@ * * @author rannou * @version $Id$ + * @deprecated use links + event + serviceImage depends on page */ +@Deprecated public class Image extends ImageContextLink { /** Chemin de l'image */ Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -34,7 +34,9 @@ * * Mise a jour: $Date$ * par : $Author$ + * @deprecated use {@link org.chorem.pollen.ui.services.ServiceImage } instead */ +@Deprecated public class ImageContextLink implements ContextLink { public static final String THUMB_PREFIX = "thumb_"; Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -92,6 +92,7 @@ void beginRender(MarkupWriter writer) { if (log.isDebugEnabled()) { log.debug("pager from : " + getFirstValue() + " to " + getLastValue()); + log.debug("nb rows per page : " + nbRowsPerPage); log.debug("current page : " + currentPage); log.debug("max nb rows : " + nbTotalRows); log.debug("has previous : " + hasPrevious()); @@ -101,7 +102,7 @@ } writer.element("div", "class", "p-pager"); // If firstPage and lastPage are the same, no need to use the pager - if (getFirstPage() == getLastPage()) { + if (getFirstPage() >= getLastPage()) { writer.write(noPagerText); } else { if (hasPrevious()) { Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -7,11 +7,13 @@ import java.text.SimpleDateFormat; import java.util.Date; import org.apache.commons.fileupload.FileUploadException; +import org.apache.tapestry5.StreamResponse; import org.apache.tapestry5.upload.services.UploadedFile; import org.chorem.pollen.business.PollenProperty; import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.ui.utils.ImageUtil; +import org.nuiton.util.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,6 +35,7 @@ * * @author fdesbois * @version $Revision$ + * @since 1.3 * * Mise a jour: $Date$ * par : $Author$ @@ -43,26 +46,57 @@ protected ChoiceType type; - protected DateFormat dateFormat; - protected Date date; protected UploadedFile image; + protected String imageFileName; + protected String imageDir; protected String text; + public ChoiceField() { + + } + + public ChoiceField(ChoiceDTO dto, ChoiceType type) { + if (log.isDebugEnabled()) { + log.debug("Instanciate ChoiceField : type = " + type + + " _ name = " + dto.getName()); + } + switch (type) { + case DATE: + setDateType(); + setDate(new Date(Long.parseLong(dto.getName()))); + break; + case TEXT: + setTextType(); + setText(dto.getName()); + break; + case IMAGE: + setImageType(dto.getPollUId()); + setImageFileName(dto.getName()); + } + setDescription(dto.getDescription()); + setHidden(dto.getHidden()); + setId(dto.getId()); + setValidate(dto.getValidate()); + setPollUId(dto.getPollUId()); + setName(dto.getName()); + //setValue(dto.getValue()); + //setVoteId(dto.getVoteId()); + } + /** * Instantiate a new choiceField for a Date ChoiceType. * - * @param pattern date pattern to format the date when name will be saved * @return the ChoiceField which is date typed * @see #setDateType(java.lang.String) */ - public static ChoiceField getChoiceDate(String pattern) { + public static ChoiceField getChoiceDate() { ChoiceField result = new ChoiceField(); - result.setDateType(pattern); + result.setDateType(); return result; } @@ -96,12 +130,10 @@ * Change type of the choice to date type. The date type need a * {@code pattern} to format the date when saving the choice. * - * @param pattern * @see #saveName() */ - public void setDateType(String pattern) { + public void setDateType() { this.type = ChoiceType.DATE; - dateFormat = new SimpleDateFormat(pattern); image = null; } @@ -149,6 +181,21 @@ return image; } + public void setImageFileName(String filename) { + this.imageFileName = filename; + } + + public String getImageFileName() { + if (imageFileName == null && image != null) { + imageFileName = image.getFileName(); + } + return imageFileName; + } + + public String getImageDir() { + return imageDir; + } + public void setText(String text) { this.text = text; } @@ -160,7 +207,7 @@ /** * Save name of the choice depends on ChoiceType : * <pre> - * - DATE : the date will be formated ; + * - DATE : the date will be formated (only full time is used) ; * - IMAGE : the image file will be saved and the choice name will * correspond to the image file name ; * - TEXT : the text becomes the choice name. @@ -169,29 +216,29 @@ public void saveName() { String name = ""; switch (type) { - case DATE: - name = dateFormat.format(getDate()); + case DATE: + name = String.valueOf(date.getTime()); break; case IMAGE: - // Get directory to save the image using the context from - // pollen properties. - File dir = new File(PollenProperty.IMG_DIR.getValue(), imageDir); - if (!dir.exists()) { - dir.mkdirs(); - } - // Save the image file - File file = new File(dir, image.getFileName()); - image.write(file); - if (log.isDebugEnabled()) { - log.debug("Image saved: " + image.getFileName() + - " (size=" + image.getSize() + ")"); - } - // Create image thumbnail - ImageUtil.createThumbnail(dir, file, 100); - if (log.isDebugEnabled()) { - log.debug("save name for image : " + file.getName()); - } - name = file.getName(); +// // Get directory to save the image using the context from +// // pollen properties. +// File dir = new File(PollenProperty.IMG_DIR.getValue(), imageDir); +// if (!dir.exists()) { +// dir.mkdirs(); +// } +// // Save the image file +// File file = new File(dir, getImageFileName()); +// image.write(file); +// if (log.isDebugEnabled()) { +// log.debug("Image saved: " + getImageFileName() + +// " (size=" + image.getSize() + ")"); +// } +// // Create image thumbnail +// ImageUtil.createThumbnail(dir, file, 100); +// if (log.isDebugEnabled()) { +// log.debug("save name for image : " + file.getName()); +// } + //name = serviceImage.saveImage(getImage(), getImageDir()); break; case TEXT: name = getText(); Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/Confirm.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/Confirm.java (rev 0) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/Confirm.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -0,0 +1,47 @@ +package org.chorem.pollen.ui.mixins; + +import org.apache.tapestry5.BindingConstants; +import org.apache.tapestry5.ClientElement; +import org.apache.tapestry5.RenderSupport; +import org.apache.tapestry5.annotations.AfterRender; +import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary; +import org.apache.tapestry5.annotations.InjectContainer; +import org.apache.tapestry5.annotations.Parameter; +import org.apache.tapestry5.ioc.annotations.Inject; + +/** + * Confirm.java + * + * A simple mixin for attaching a javascript confirmation box to the onclick + * event of any component that implements ClientElement. + * + * @author fdesbois + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author: fdesbois $ + */ +@IncludeJavaScriptLibrary("context:js/confirm.js") +public class Confirm { + + @Parameter(value = "Are you sure?", defaultPrefix = BindingConstants.MESSAGE) + private String message; + + @Inject + private RenderSupport renderSupport; + + @InjectContainer + private ClientElement element; + + @Parameter + private boolean wDisabled; + + @AfterRender + public void afterRender() { + if (!wDisabled) { + renderSupport.addScript(String.format("new Confirm('%s', '%s');", + element.getClientId(), message)); + } + } + +} Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/Confirm.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/ZoneUpdater.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/ZoneUpdater.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/ZoneUpdater.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -43,7 +43,7 @@ * Last update: $Date$ * by : $Author: fdesbois $ */ -@IncludeJavaScriptLibrary("context:js/ZoneUpdater.js") +@IncludeJavaScriptLibrary("context:js/zoneUpdater.js") public class ZoneUpdater { public static final String PLACEHOLDER = "XXX"; Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CloseValidation.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CloseValidation.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CloseValidation.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -103,7 +103,7 @@ * @return l'identifiant. */ public String getAdminId() { - return poll.getPollId() + ":" + creator.getAccountId(); + return poll.getPollUId() + ":" + creator.getAccountId(); } void onActivate() { Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CreationValidation.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CreationValidation.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CreationValidation.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -103,7 +103,7 @@ * @return l'identifiant. */ public String getAdminId() { - return poll.getPollId() + ":" + creator.getAccountId(); + return poll.getPollUId() + ":" + creator.getAccountId(); } void onActivate() { Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ModificationValidation.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ModificationValidation.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ModificationValidation.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -103,7 +103,7 @@ * @return l'identifiant. */ public String getAdminId() { - return poll.getPollId() + ":" + creator.getAccountId(); + return poll.getPollUId() + ":" + creator.getAccountId(); } void onActivate() { Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -73,8 +73,8 @@ import org.chorem.pollen.ui.data.PollStep; import org.chorem.pollen.ui.data.uio.DateChoiceUIO; import org.chorem.pollen.ui.data.uio.ImageChoiceUIO; +import org.chorem.pollen.ui.services.ServiceImage; import org.chorem.pollen.ui.utils.FeedUtil; -import org.chorem.pollen.ui.utils.ImageUtil; import org.chorem.pollen.ui.utils.UnitConverter; import org.slf4j.Logger; @@ -371,7 +371,7 @@ /** * Méthode appelée lorsqu'on souhaite valider la création du sondage. */ - Object onSuccessFromChoicesCreationForm() { + Object onSuccessFromChoicesCreationForm() throws FileUploadException { if (!addChoiceSelected) { // Préparation et création du sondage @@ -741,13 +741,14 @@ return true; } + @Inject + private ServiceImage serviceImage; + /** * Création du sondage. */ - private void createPoll() { + private void createPoll() throws FileUploadException { - // Création du sondage - servicePoll.createPoll(poll); // FD-20100226 : Can't be null, an exception will be thrown if a // problem comes from createPoll @@ -755,10 +756,24 @@ // Création des images if (poll.getChoiceType() == ChoiceType.IMAGE) { - File dir = imgContext.getImageDir(); - ImageUtil.saveImages(imgTypeChoices, dir); + for (ImageChoiceUIO image : imgTypeChoices) { + if (image.getImg() != null) { +// String contentType = image.getImg().getContentType(); +// if (!contentType.equals("image") || +// !contentType.equals("IMAGE")) { +// throw new FileUploadException("wrong type for image upload"); +// } + serviceImage.saveImage(image.getImg(), poll.getPollUId()); + } + } + //File dir = imgContext.getImageDir(); + //ImageUtil.saveImages(imgTypeChoices, dir); } + + // Création du sondage + servicePoll.createPoll(poll); + // FD-20100226 : not necessary, the service will update // automatically the poll when it was created // Mise à jour du sondage : @@ -790,8 +805,8 @@ /** Ajout d'une entrée dans le flux de syndication */ private void addFeedEntry() { PollAccountDTO creator = servicePollAccount.findPollAccountById(poll.getCreatorId()); - String voteURL = siteURL + "poll/votefor/" + poll.getPollId(); - File feedFile = feedContext.getFile(poll.getPollId()); + String voteURL = siteURL + "poll/votefor/" + poll.getPollUId(); + File feedFile = feedContext.getFile(poll.getPollUId()); FeedUtil.createFeed(feedFile, "atom_1.0", messages.format( "pollFeed_title", poll.getTitle()), siteURL, messages.format( @@ -804,8 +819,8 @@ private void sendMailNotification(String siteURL, ServicePollAccount servicePollAccount, PollDTO poll, Messages messages) { PollAccountDTO creator = servicePollAccount.findPollAccountById(poll.getCreatorId()); - String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId(); - String modifURL = siteURL + "poll/Modification/" + poll.getPollId() + ":" + creator.getAccountId(); + String voteURL = siteURL + "poll/VoteFor/" + poll.getPollUId(); + String modifURL = siteURL + "poll/Modification/" + poll.getPollUId() + ":" + creator.getAccountId(); Map<String, String> data = new HashMap<String, String>(); data.put("host", PollenProperty.EMAIL_HOST.getValue()); data.put("port", PollenProperty.EMAIL_PORT.getValue()); @@ -1161,8 +1176,8 @@ // Réinitialisation des variables de session // Si l'ancien sondage n'existe pas ou est différent de celui fourni - if (oldPoll == null || !id.equals(oldPoll.getPollId())) { - oldPoll = servicePoll.findPollByPollId(id); + if (oldPoll == null || !id.equals(oldPoll.getPollUId())) { + oldPoll = servicePoll.getPoll(id); if (oldPoll != null) { initWithExistingPoll(oldPoll); oldPoll = null; @@ -1198,7 +1213,8 @@ private void initPoll() { // Initialisation du sondage - poll = new PollDTO(); + //poll = new PollDTO(); + poll = servicePoll.getNewPoll(); if (userExists) { poll.setCreatorName(user.getLogin()); poll.setCreatorEmail(user.getEmail()); Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -108,7 +108,7 @@ if (log.isDebugEnabled()) { log.debug("Get existing poll with pollUID = " + pollUID); } - poll = servicePoll.findPollByPollId(pollUID); + poll = servicePoll.getPoll(pollUID); // TODO : init advancedOptions } else { if (log.isDebugEnabled()) { Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -532,7 +532,7 @@ /** Envoi du mail de notification */ private void sendMailNotification(List<PollAccountDTO> modifiedAccounts) { - String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId(); + String voteURL = siteURL + "poll/VoteFor/" + poll.getPollUId(); Map<String, String> data = new HashMap<String, String>(); data.put("host", PollenProperty.EMAIL_HOST.getValue()); data.put("port", PollenProperty.EMAIL_PORT.getValue()); @@ -592,8 +592,8 @@ String pollId = id.split(":", 2)[0]; // Réinitialisation des variables de session - if (poll == null || !pollId.equals(poll.getPollId())) { - poll = servicePoll.findPollByPollId(pollId); + if (poll == null || !pollId.equals(poll.getPollUId())) { + poll = servicePoll.getPoll(pollId); creator = null; newRule = null; } @@ -649,7 +649,7 @@ // Réinitialisation des variables de session if (poll != null) { - poll = servicePoll.findPollByPollId(poll.getPollId()); + poll = servicePoll.getPoll(poll.getPollUId()); creator = servicePollAccount.findPollAccountById(poll .getCreatorId()); initNotificationRule(); Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -366,9 +366,9 @@ ResultListDTO resultListDTO = null; if (byGroup) { - resultListDTO = serviceResults.getGroupResults(poll.getPollId()); + resultListDTO = serviceResults.getGroupResults(poll.getPollUId()); } else { - resultListDTO = serviceResults.getNormalResults(poll.getPollId()); + resultListDTO = serviceResults.getNormalResults(poll.getPollUId()); } results = resultListDTO.getResultDTOs(); @@ -471,7 +471,7 @@ if (id != null && !"".equals(id)) { pollId = id.split(":", 2)[0]; - poll = servicePoll.findPollByPollId(pollId); + poll = servicePoll.getPoll(pollId); if (poll != null) { Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -25,10 +25,13 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.UUID; import org.apache.tapestry5.BindingConstants; +import org.apache.tapestry5.Block; +import org.apache.tapestry5.ComponentResources; import org.apache.tapestry5.EventContext; +import org.apache.tapestry5.Link; +import org.apache.tapestry5.StreamResponse; import org.apache.tapestry5.ValidationException; import org.apache.tapestry5.annotations.Component; import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary; @@ -42,11 +45,9 @@ import org.apache.tapestry5.annotations.SessionState; import org.apache.tapestry5.beaneditor.BeanModel; import org.apache.tapestry5.corelib.components.Form; -import org.apache.tapestry5.corelib.components.TextField; import org.apache.tapestry5.corelib.components.Zone; import org.apache.tapestry5.ioc.Messages; import org.apache.tapestry5.ioc.annotations.Inject; -import org.apache.tapestry5.ioc.util.AbstractMessages; import org.apache.tapestry5.upload.services.UploadedFile; import org.chenillekit.tapestry.core.components.DateTimeField; import org.chorem.pollen.business.PollenBusinessException; @@ -77,14 +78,15 @@ import org.chorem.pollen.ui.components.ImageContextLink; import org.chorem.pollen.ui.components.Pager; import org.chorem.pollen.ui.data.AddressBar; +import org.chorem.pollen.ui.data.ChoiceField; import org.chorem.pollen.ui.data.EvenOdd; import org.chorem.pollen.ui.data.PollAction; import org.chorem.pollen.ui.data.PollUri; import org.chorem.pollen.ui.data.uio.DateChoiceUIO; import org.chorem.pollen.ui.data.uio.ImageChoiceUIO; +import org.chorem.pollen.ui.services.ServiceImage; import org.chorem.pollen.ui.utils.FeedUtil; import org.chorem.pollen.ui.utils.ImageUtil; -import org.chorem.pollen.votecounting.business.NumberMethod; import org.slf4j.Logger; /** @@ -112,13 +114,6 @@ @Component(id = "feedback") private FeedBack feedback; - /** - * Objet de session représentant l'utilisateur identifié. - */ - @SessionState - private UserDTO user; - @Property - private boolean userExists; /** * Objet de session représentant l'url du site. @@ -130,8 +125,8 @@ @Component private Form voteForm; - @Component(id = "pollAccountName") - private TextField nameField; +// @Component(id = "pollAccountName") +// private TextField nameField; /** Composant DateTimeField pour les choix du sondage */ @SuppressWarnings("unused") @@ -176,8 +171,8 @@ /*@InjectPage private ImageDisplay imageDisplay;*/ - @InjectComponent - private Zone pollZone; +// @InjectComponent +// private Zone pollZone; /** * Objet servant à changer la couleur à chaque ligne de la liste des @@ -201,11 +196,11 @@ // private List<ChoiceDTO> voteChoices = new ArrayList<ChoiceDTO>(); /** Identifiant du compte correspondant à l'adresse forgée */ - private String pollAccountId; +// private String pollAccountId; /** Compte du votant */ - @Property - private PollAccountDTO pollAccount; +// @Property +// private PollAccountDTO pollAccount; /** Nouveau choix de type texte */ @Property @@ -275,239 +270,236 @@ } /** Méthode appelée après la soumission du vote. */ - @Log - Object onSuccessFromVoteForm() throws PollenBusinessException { - if (initPollAccount()) { - List<ChoiceDTO> choiceDTOs = new ArrayList<ChoiceDTO>(); - if (getPoll().getVoteCounting() == VoteCountingType.NORMAL) { - int nbChoices = 0; - for (ChoiceDTO choice : getPoll().getChoices()) { - if (choice.getValue() == 1) { - nbChoices++; - } - choiceDTOs.add(choice); - } - if (nbChoices > getPoll().getMaxChoiceNb()) { - voteForm.recordError(messages.format(("tooManyChoices"), - getPoll().getMaxChoiceNb())); - return pollZone.getBody(); - } - - } else if (getPoll().getVoteCounting() == VoteCountingType.PERCENTAGE) { - int total = 0; - for (ChoiceDTO choice : getPoll().getChoices()) { - total = total + choice.getValue(); - choiceDTOs.add(choice); - } - if (total != 100) { - voteForm.recordError(messages.get("not100percent")); - return pollZone.getBody(); - } - - } else if (getPoll().getVoteCounting() == VoteCountingType.CONDORCET) { - for (ChoiceDTO choice : getPoll().getChoices()) { - if (choice.getValue() == 0) { - choice.setValue(100); - } - choiceDTOs.add(choice); - } - - } else if (getPoll().getVoteCounting() == VoteCountingType.NUMBER) { - String votingId = pollAccount.getVotingId(); - if (anonymousVote) { - votingId = "anonymous" + UUID.randomUUID().toString().replaceAll("-", ""); - } - - for (ChoiceDTO choice : getPoll().getChoices()) { - if (!choice.isHidden()) { - choiceDTOs.add(choice); - - // creates a new hidden choice - ChoiceDTO hiddenChoice = new ChoiceDTO(); - hiddenChoice.setName(NumberMethod.HIDDEN_PREFIX + - choice.getName() + "#" + votingId); - hiddenChoice.setHidden(true); - hiddenChoice.setValue(choice.getValue()); - hiddenChoice.setPollId(choice.getPollId()); - hiddenChoice.setVoteId(choice.getVoteId()); - hiddenChoice.setValidate(false); - - String choiceId = serviceChoice.createChoice(hiddenChoice); - hiddenChoice.setId(choiceId); - choiceDTOs.add(hiddenChoice); - } - } - } - - VoteDTO vote = new VoteDTO(null, getPoll().getId(), null); - vote.setChoiceDTOs(choiceDTOs); - vote.setWeight(pollAccount.getWeight()); - vote.setAnonymous(anonymousVote); - - // mise à jour du vote ou création d'un nouveau vote - if (alreadyVoted) { - for (VoteDTO v : getVotes()) { - PollAccountDTO voteAccount = servicePollAccount - .findPollAccountById(v.getPollAccountId()); - - if (voteAccount.getVotingId().equals(pollAccount.getVotingId())) { - vote.setId(v.getId()); - deleteVote(vote.getId()); - serviceVote.createVote(vote, pollAccount); - } - } - } else { - serviceVote.createVote(vote, pollAccount); - } - - // Mise à jour du sondage et des résultats - //poll = servicePoll.findPollByPollId(getPoll().getPollId()); - poll = null; - countPoll(); - - addFeedEntry(PollAction.ADDVOTE, pollAccount.getVotingId(), - getResultsAsString()); - sendMailNotification(); - voteFeedback.addInfo(messages.get("vote-success")); - page = pager.getLastPage(); - // Reset votes to reload them depends on page change. - votes = null; - return this; - } -// voteChoices.clear(); - return pollZone.getBody(); - } +// @Log +// Object onSuccessFromVoteForm() throws PollenBusinessException { +// if (initPollAccount()) { +// List<ChoiceDTO> choiceDTOs = new ArrayList<ChoiceDTO>(); +// if (getPoll().getVoteCounting() == VoteCountingType.NORMAL) { +// int nbChoices = 0; +// for (ChoiceDTO choice : getPoll().getChoices()) { +// if (choice.getValue() == 1) { +// nbChoices++; +// } +// choiceDTOs.add(choice); +// } +// if (nbChoices > getPoll().getMaxChoiceNb()) { +// voteForm.recordError(messages.format(("tooManyChoices"), +// getPoll().getMaxChoiceNb())); +// return pollZone.getBody(); +// } +// +// } else if (getPoll().getVoteCounting() == VoteCountingType.PERCENTAGE) { +// int total = 0; +// for (ChoiceDTO choice : getPoll().getChoices()) { +// total = total + choice.getValue(); +// choiceDTOs.add(choice); +// } +// if (total != 100) { +// voteForm.recordError(messages.get("not100percent")); +// return pollZone.getBody(); +// } +// +// } else if (getPoll().getVoteCounting() == VoteCountingType.CONDORCET) { +// for (ChoiceDTO choice : getPoll().getChoices()) { +// if (choice.getValue() == 0) { +// choice.setValue(100); +// } +// choiceDTOs.add(choice); +// } +// +// } else if (getPoll().getVoteCounting() == VoteCountingType.NUMBER) { +// String votingId = pollAccount.getVotingId(); +// if (anonymousVote) { +// votingId = "anonymous" + UUID.randomUUID().toString().replaceAll("-", ""); +// } +// +// for (ChoiceDTO choice : getPoll().getChoices()) { +// if (!choice.isHidden()) { +// choiceDTOs.add(choice); +// +// // creates a new hidden choice +//// ChoiceDTO hiddenChoice = new ChoiceDTO(); +//// hiddenChoice.setName(NumberMethod.HIDDEN_PREFIX + +//// choice.getName() + "#" + votingId); +//// hiddenChoice.setHidden(true); +//// hiddenChoice.setValue(choice.getValue()); +//// hiddenChoice.setPollId(choice.getPollId()); +//// hiddenChoice.setVoteId(choice.getVoteId()); +//// hiddenChoice.setValidate(false); +// ChoiceDTO hiddenChoice = +// servicePoll.getNewHiddenChoice(choice, votingId); +// +// String choiceId = +// serviceChoice.createChoice(hiddenChoice); +// hiddenChoice.setId(choiceId); +// choiceDTOs.add(hiddenChoice); +// } +// } +// } +// +// VoteDTO vote = new VoteDTO(null, getPoll().getId(), null); +// vote.setChoiceDTOs(choiceDTOs); +// vote.setWeight(pollAccount.getWeight()); +// vote.setAnonymous(anonymousVote); +// +// // mise à jour du vote ou création d'un nouveau vote +// if (alreadyVoted) { +// for (VoteDTO v : getVotes()) { +// PollAccountDTO voteAccount = servicePollAccount +// .findPollAccountById(v.getPollAccountId()); +// +// if (voteAccount.getVotingId().equals(getPollAccount().getVotingId())) { +// vote.setId(v.getId()); +// deleteVote(vote.getId()); +// serviceVote.createVote(vote, getPollAccount()); +// } +// } +// } else { +// serviceVote.createVote(vote, getPollAccount()); +// } +// +// // Mise à jour du sondage et des résultats +// //poll = servicePoll.findPollByPollId(getPoll().getPollId()); +// poll = null; +// countPoll(); +// +// addFeedEntry(PollAction.ADDVOTE, getPollAccount().getVotingId(), +// getResultsAsString()); +// sendMailNotification(); +// voteFeedback.addInfo(messages.get("vote-success")); +// page = pager.getLastPage(); +// // Reset votes to reload them depends on page change. +// votes = null; +// return this; +// } +//// voteChoices.clear(); +// return pollZone.getBody(); +// } - private void deleteVote(String voteId) throws PollenBusinessException { - for (VoteDTO vote : getVotes()) { - if (vote.getId().equals(voteId)) { +// private void deleteVote(String voteId) throws PollenBusinessException { +// for (VoteDTO vote : getVotes()) { +// if (vote.getId().equals(voteId)) { +// +// List<ChoiceDTO> choiceDTOs = vote.getChoiceDTOs(); +// for (ChoiceDTO choiceDTO : choiceDTOs) { +// +// if (choiceDTO.isHidden()) { +// serviceChoice.deleteChoice(choiceDTO.getId()); +// } +// } +// +// break; +// } +// } +// +// serviceVote.deleteVote(voteId); +// } +// +// /** Méthode appelée lors de la suppression d'un vote. */ +// Object onActionFromDeleteVote(String voteId) throws PollenBusinessException { +// deleteVote(voteId); +// +// // Mise à jour du sondage et des résultats +//// poll = servicePoll.findPollByPollId(poll.getPollId()); +// poll = null; +// countPoll(); +// +// return pollZone.getBody(); +// } - List<ChoiceDTO> choiceDTOs = vote.getChoiceDTOs(); - for (ChoiceDTO choiceDTO : choiceDTOs) { - - if (choiceDTO.isHidden()) { - serviceChoice.deleteChoice(choiceDTO.getId()); - } - } - - break; - } - } - - serviceVote.deleteVote(voteId); - } - - /** Méthode appelée lors de la suppression d'un vote. */ - Object onActionFromDeleteVote(String voteId) throws PollenBusinessException { - deleteVote(voteId); - - // Mise à jour du sondage et des résultats -// poll = servicePoll.findPollByPollId(poll.getPollId()); - poll = null; - countPoll(); - - return pollZone.getBody(); - } - - /** Méthode appelée lors de l'édition d'un vote. */ - Object onActionFromEditVote(String votingId) { - pollAccount.setVotingId(votingId); - return pollZone.getBody(); - } - /** Initialisation du pollAccount et contrôle du nom. */ - private boolean initPollAccount() throws PollenBusinessException { - - //// Contrôle et définition du votingId - alreadyVoted = false; - boolean modifAllowed = false; - boolean restrictedListsForbidden = false; - - // Suppression des espaces pouvant provoquer un double vote - String votingId = pollAccount.getVotingId().trim(); - pollAccount.setVotingId(votingId); - - // Contrôle de la présence du votant dans les listes de votants - // du sondage (si le sondage n'est pas libre) -// if (!isFreePoll()) { -// restrictedListsForbidden = true; -// for (VotingListDTO list : poll.getVotingListDTOs()) { -// for (PollAccountDTO account : list.getPollAccountDTOs()) { -// if (pollAccount.getVotingId().equals(account.getVotingId())) { -// restrictedListsForbidden = false; -// pollAccount = servicePollAccount -// .findPollAccountById(account.getId()); -// pollAccount.setVotingListId(list.getId()); -// pollAccount.setWeight(account.getWeight()); -// logger.debug("Compte \"" + account.getVotingId() -// + "\" présent dans la liste \"" -// + list.getName() + "\" (poids=" -// + account.getWeight() + ")"); -// } +// private boolean initPollAccount() throws PollenBusinessException { +// +// //// Contrôle et définition du votingId +// alreadyVoted = false; +// boolean modifAllowed = false; +// boolean restrictedListsForbidden = false; +// +// // Suppression des espaces pouvant provoquer un double vote +// String votingId = getPollAccount().getVotingId().trim(); +// getPollAccount().setVotingId(votingId); +// +// // Contrôle de la présence du votant dans les listes de votants +// // du sondage (si le sondage n'est pas libre) +//// if (!isFreePoll()) { +//// restrictedListsForbidden = true; +//// for (VotingListDTO list : poll.getVotingListDTOs()) { +//// for (PollAccountDTO account : list.getPollAccountDTOs()) { +//// if (pollAccount.getVotingId().equals(account.getVotingId())) { +//// restrictedListsForbidden = false; +//// pollAccount = servicePollAccount +//// .findPollAccountById(account.getId()); +//// pollAccount.setVotingListId(list.getId()); +//// pollAccount.setWeight(account.getWeight()); +//// logger.debug("Compte \"" + account.getVotingId() +//// + "\" présent dans la liste \"" +//// + list.getName() + "\" (poids=" +//// + account.getWeight() + ")"); +//// } +//// } +//// } +//// } +// +// // The calcul of alreadyVoted will be needed for no double votingId +// // Carefull, not correct for an anonymous vote +// alreadyVoted = serviceVote.hasAlreadyVoted(votingId, getPoll()); +// +// // Check for restricted poll +// if (!alreadyVoted && !isFreePoll()) { +// if (uri.getAccountUId() != null) { +// // The accountUId must be valid for the poll +// PollAccountDTO restrictedAccount = +// servicePoll.getRestrictedAccount(uri.getAccountUId(), getPoll()); +// +// if (restrictedAccount != null) { +// // PollAccount is replaced by the good account from db +// pollAccount = restrictedAccount; +// // Refresh alreadyVoted value depends on getPollAccount() +// alreadyVoted = getPollAccount().isHasVoted(); +// // Existing account is null is forbidden for a restricted poll +// } else { +// restrictedListsForbidden = true; // } +// // Not allowed to vote without an accountUId +// } else { +// restrictedListsForbidden = true; // } +// +// if (restrictedListsForbidden) { +//// voteForm.recordError(nameField, +//// messages.get("restrictedListsForbidden")); +// } // } +// +// // Génération d'un identifiant de vote (si le sondage est libre et anonyme) +// if (getPoll().isAnonymous()) { +// anonymousVote = true; +// if (isFreePoll()) { +// getPollAccount().setVotingId("anonymous" +// + UUID.randomUUID().toString().replaceAll("-", "")); +// } +// } +// +// //// Définition de l'userId +// if (userExists) { +// getPollAccount().setUserId(user.getId()); +// } else { +// getPollAccount().setUserId(""); +// } +// +// modifAllowed = isModifAllowed(getPollAccount().getVotingId()); +// if (alreadyVoted && !modifAllowed) { +//// voteForm.recordError(nameField, messages.format("alreadyVoted", +//// getPollAccount().getVotingId())); +// } +// +// logger.debug("votingId: " + getPollAccount().getVotingId()); +// logger.debug("alreadyVoted: " + alreadyVoted); +// logger.debug("modifAllowed: " + modifAllowed); +// logger.debug("restrictedListsForbidden: " + restrictedListsForbidden); +// return ((!alreadyVoted || modifAllowed) && !restrictedListsForbidden); +// } - // The calcul of alreadyVoted will be needed for no double votingId - // Carefull, not correct for an anonymous vote - alreadyVoted = serviceVote.hasAlreadyVoted(votingId, getPoll()); - - // Check for restricted poll - if (!alreadyVoted && !isFreePoll()) { - if (uri.getAccountUId() != null) { - // The accountUId must be valid for the poll - PollAccountDTO restrictedAccount = - servicePoll.getRestrictedAccount(uri.getAccountUId(), getPoll()); - - if (restrictedAccount != null) { - // PollAccount is replaced by the good account from db - pollAccount = restrictedAccount; - // Refresh alreadyVoted value depends on pollAccount - alreadyVoted = pollAccount.isHasVoted(); - // Existing account is null is forbidden for a restricted poll - } else { - restrictedListsForbidden = true; - } - // Not allowed to vote without an accountUId - } else { - restrictedListsForbidden = true; - } - - if (restrictedListsForbidden) { - voteForm.recordError(nameField, - messages.get("restrictedListsForbidden")); - } - } - - // Génération d'un identifiant de vote (si le sondage est libre et anonyme) - if (getPoll().isAnonymous()) { - anonymousVote = true; - if (isFreePoll()) { - pollAccount.setVotingId("anonymous" - + UUID.randomUUID().toString().replaceAll("-", "")); - } - } - - //// Définition de l'userId - if (userExists) { - pollAccount.setUserId(user.getId()); - } else { - pollAccount.setUserId(""); - } - - modifAllowed = isModifAllowed(pollAccount.getVotingId()); - if (alreadyVoted && !modifAllowed) { - voteForm.recordError(nameField, messages.format("alreadyVoted", - pollAccount.getVotingId())); - } - - logger.debug("votingId: " + pollAccount.getVotingId()); - logger.debug("alreadyVoted: " + alreadyVoted); - logger.debug("modifAllowed: " + modifAllowed); - logger.debug("restrictedListsForbidden: " + restrictedListsForbidden); - return ((!alreadyVoted || modifAllowed) && !restrictedListsForbidden); - } - /** * Retourne vrai si la modification du vote est autorisée. C'est à dire si * l'utilisateur connecté est l'auteur du vote ou si le votant défini par @@ -516,50 +508,50 @@ * @param votingId le votant a rechercher * @return vrai si la modification du vote est autorisée */ - public boolean isModifAllowed(String votingId) throws PollenBusinessException { - boolean modifAllowed = false; - int i = 0; +// public boolean isModifAllowed(String votingId) throws PollenBusinessException { +// boolean modifAllowed = false; +// int i = 0; +// +// // parcours des votes pour trouver celui correspondant au votingId +// // et contrôle du droit de modification +// while (i < getVotes().size() && !modifAllowed) { +// +// // account : compte associé au vote courant +// //String id = getVotes().get(i).getPollAccountId(); +// //PollAccountDTO account = servicePollAccount.findPollAccountById(id); +// VoteDTO curr = getVotes().get(i); +// +// // si le votant du vote correspond au votingId +// if (curr.getName().equals(votingId)) { +// if (logger.isDebugEnabled()) { +// logger.debug("vote name: " + curr.getName()); +// logger.debug("vote account: " + curr.getPollAccountId()); +//// logger.debug("voting account: " + pollAccountId); +// } +// +// // si le votant du vote correspond au votant actuel (pollAccountId) +//// if (pollAccountId != null +//// && pollAccountId.equals(curr.getPollAccountId())) { +//// modifAllowed = true; +//// } +// +// // si l'utilisateur du vote correspond à l'utilisateur actuel (user) +// if (userExists && user.getId().length() > 0) { +// modifAllowed = user.getId().equals(curr.getUserId()); +// } +// } +// +// i++; +// } +// +// return modifAllowed; +// } - // parcours des votes pour trouver celui correspondant au votingId - // et contrôle du droit de modification - while (i < getVotes().size() && !modifAllowed) { - - // account : compte associé au vote courant - //String id = getVotes().get(i).getPollAccountId(); - //PollAccountDTO account = servicePollAccount.findPollAccountById(id); - VoteDTO curr = getVotes().get(i); - - // si le votant du vote correspond au votingId - if (curr.getName().equals(votingId)) { - if (logger.isDebugEnabled()) { - logger.debug("vote name: " + curr.getName()); - logger.debug("vote account: " + curr.getPollAccountId()); - logger.debug("voting account: " + pollAccountId); - } - - // si le votant du vote correspond au votant actuel (pollAccountId) - if (pollAccountId != null - && pollAccountId.equals(curr.getPollAccountId())) { - modifAllowed = true; - } - - // si l'utilisateur du vote correspond à l'utilisateur actuel (user) - if (userExists && user.getId().length() > 0) { - modifAllowed = user.getId().equals(curr.getUserId()); - } - } - - i++; - } - - return modifAllowed; - } - /** Ajout d'une entrée dans le flux de syndication */ private void addFeedEntry(PollAction pollAction, String titleStr, String contentStr) throws PollenBusinessException { - String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollId(); - File feedFile = getFeedContext().getFile(getPoll().getPollId()); + String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollUId(); + File feedFile = getFeedContext().getFile(getPoll().getPollUId()); String title = null; String content = null; @@ -591,8 +583,8 @@ /** Envoi du mail de notification */ private void sendMailNotification() throws PollenBusinessException { - String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollId(); - String modifURL = siteURL + "poll/Modification/" + getPoll().getPollId() + String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollUId(); + String modifURL = siteURL + "poll/Modification/" + getPoll().getPollUId() + ":" + MD5.encode(getPoll().getCreatorId()); Map<String, String> data = new HashMap<String, String>(); data.put("host", PollenProperty.EMAIL_HOST.getValue()); @@ -702,7 +694,7 @@ */ @Log public boolean isFeedFileExisting() throws PollenBusinessException { - File feedFile = getFeedContext().getFile(getPoll().getPollId()); + File feedFile = getFeedContext().getFile(getPoll().getPollUId()); if (log.isDebugEnabled()) { log.debug("feed context path : " + getFeedContext().getContextPath()); log.debug("feed absolute path : " + feedFile.getAbsolutePath()); @@ -810,7 +802,7 @@ if (isTextType()) { if (newChoice.getName() != null) { newChoice.setValidate(true); - newChoice.setPollId(getPoll().getId()); + newChoice.setPollUId(getPoll().getPollUId()); getPoll().getChoices().add(newChoice); choiceName = newChoice.getName(); choiceDesc = newChoice.getDescription(); @@ -818,7 +810,7 @@ } else if (isDateType()) { if (newDateChoice.getDate() != null) { newDateChoice.setValidate(true); - newDateChoice.setPollId(getPoll().getId()); + newDateChoice.setPollUId(getPoll().getPollUId()); newDateChoice.setName(String.valueOf(newDateChoice.getDate() .getTime())); getPoll().getChoices().add(newDateChoice); @@ -829,7 +821,7 @@ } else if (isImageType()) { if (newImageChoice.getImg() != null) { newImageChoice.setValidate(true); - newImageChoice.setPollId(getPoll().getId()); + newImageChoice.setPollUId(getPoll().getPollUId()); newImageChoice.setName(newImageChoice.getImg().getFileName() .replace(' ', '_')); getPoll().getChoices().add(newImageChoice); @@ -851,32 +843,10 @@ return this; } - /** Méthode appelée lors de la suppression d'un choix. */ - Object onActionFromDeleteChoice(String choiceId) throws PollenBusinessException { - Iterator<ChoiceDTO> itChoice = getPoll().getChoices().iterator(); - while (itChoice.hasNext()) { - ChoiceDTO choice = itChoice.next(); - if (choiceId.equals(choice.getId())) { - itChoice.remove(); - } - } - servicePoll.updatePoll(getPoll()); - poll = null; -// poll = servicePoll.findPollByPollId(poll.getPollId()); - return pollZone.getBody(); - } - // public boolean isPollNull() { // return poll == null; // } - public boolean isPollChoiceStarted() throws PollenBusinessException { - Date now = new Date(); - boolean started = getPoll().getBeginChoiceDate() == null || getPoll().getBeginChoiceDate().before(now); - boolean ended = getPoll().getEndChoiceDate() != null && getPoll().getEndChoiceDate().before(now); - return started && !ended; - } - public boolean isPollStarted() throws PollenBusinessException { Date now = new Date(); return getPoll().getBeginDate() == null || getPoll().getBeginDate().before(now); @@ -891,19 +861,14 @@ return isPollChoiceStarted() || isPollStarted(); } - public boolean isPollChoiceRunning() throws PollenBusinessException { - return getPoll().isChoiceAddAllowed() && isPollChoiceStarted(); - //&& !isPollStarted(); - } - public boolean isPollRunning() throws PollenBusinessException { return isPollStarted() && !isPollFinished() && !getPoll().isClosed(); } - public boolean isDescNull() { - return choiceOfPoll.getDescription() == null - || "".equals(choiceOfPoll.getDescription()); - } +// public boolean isDescNull() { +// return choiceOfPoll.getDescription() == null +// || "".equals(choiceOfPoll.getDescription()); +// } /** Retourne vrai si le champs pollAccount doit apparaître. */ public boolean isAccountFieldDisplayed() throws PollenBusinessException { @@ -949,14 +914,6 @@ public boolean isNumberVoteCounting() throws PollenBusinessException { return getPoll().getVoteCounting() == VoteCountingType.NUMBER; } - - /** retourne vrai si l'utilisateur est le créateur du sondage */ - public boolean isCreatorUser() throws PollenBusinessException { - if (userExists && user.getId().equals(getPoll().getUserId())) { - return true; - } - return false; - } /** Retourne le message d'aide correspondant au type de sondage. */ public String getHelpMessage() throws PollenBusinessException { @@ -989,9 +946,9 @@ if (getPoll().getContinuousResults()) { if (isGroupPoll()) { - resultListDTO = serviceResults.getGroupResults(getPoll().getPollId()); + resultListDTO = serviceResults.getGroupResults(getPoll().getPollUId()); } else { - resultListDTO = serviceResults.getNormalResults(getPoll().getPollId()); + resultListDTO = serviceResults.getNormalResults(getPoll().getPollUId()); } results = resultListDTO.getResultDTOs(); @@ -1006,9 +963,26 @@ } } + + + + + + + + + ////////////////// NEW IMPLEMENTATION + + + + + @Property private PollUri uri; + @InjectComponent + private Border border; + /** * Sondage pour lequel l'utilisateur vote */ @@ -1017,9 +991,17 @@ @Property private boolean pollNull; + + /** + * Objet de session représentant l'utilisateur identifié. + */ + @SessionState + private UserDTO user; + @Property + private boolean userExists; - @InjectComponent - private Border border; + /** Compte du votant */ + private PollAccountDTO pollAccount; /** Format des dates */ private DateFormat dateFormat; @@ -1029,7 +1011,6 @@ * * @param id l'identifiant du sondage et du votant */ - @Log void onActivate(EventContext ec) throws PollenBusinessException { uri = ec.get(PollUri.class, 0); if (ec.getCount() > 1) { @@ -1079,8 +1060,6 @@ * @return the address bar of the page. */ public AddressBar getAddress() { -// address = new AddressBarItem[] { new AddressBarItem("Pollen", "Index"), -// new AddressBarItem(title, null) }; return new AddressBar().appendCurrent(title); } @@ -1099,33 +1078,10 @@ public PollDTO getPoll() throws PollenBusinessException { if (poll == null) { - poll = servicePoll.findPollByPollId(uri.getPollUId()); + poll = servicePoll.getPoll(uri.getPollUId()); if (poll != null) { - // Identification du votant - if (uri.getAccountUId() != null) { - pollAccount = servicePollAccount - .findPollAccountByAccountId(uri.getAccountUId()); - pollAccountId = pollAccount.getId(); - } - - if (pollAccount == null) { - pollAccount = new PollAccountDTO(); - if (userExists) { - if (user.getFirstName() != null && user.getLastName() != null) { - pollAccount.setVotingId( - user.getFirstName() + " " + user.getLastName()); - - } else if (user.getFirstName() != null) { - pollAccount.setVotingId(user.getFirstName()); - - } else if (user.getLastName() != null) { - pollAccount.setVotingId(user.getLastName()); - } - } - } - // Initialisations pour les formulaires newChoice = new ChoiceDTO(); newDateChoice = new DateChoiceUIO(); @@ -1138,13 +1094,197 @@ return poll; } - /************** PAGER AND VOTES MANAGMENT *********************************/ + /** + * Use a PollAccount to represent the current session user. + * The existing account is used if accountUId is present in the uri. + * Otherwise a new account is instanciate with user properties + * (for vote name). + * + * @return + */ + public PollAccountDTO getPollAccount() { + if (pollAccount == null) { + // Identification du votant + if (uri.getAccountUId() != null) { + pollAccount = servicePollAccount + .findPollAccountByAccountId(uri.getAccountUId()); +// pollAccountId = pollAccount.getId(); + } + if (pollAccount == null) { + pollAccount = serviceVote.getNewPollAccount(user);//new PollAccountDTO(); +// if (userExists) { +// if (user.getFirstName() != null && user.getLastName() != null) { +// pollAccount.setVotingId( +// user.getFirstName() + " " + user.getLastName()); +// +// } else if (user.getFirstName() != null) { +// pollAccount.setVotingId(user.getFirstName()); +// +// } else if (user.getLastName() != null) { +// pollAccount.setVotingId(user.getLastName()); +// } +// } + } + } + return pollAccount; + } + + /** + * Test if the current connected user is the poll creator. + * + * @return true if connected user is the poll creator + * @throws PollenBusinessException + */ + public boolean isCreatorUser() throws PollenBusinessException { + return userExists && user.getId().equals(getPoll().getUserId()); + } + + /************** CHOICES ***************************************************/ + + private List<ChoiceField> choices; + + @Property + private ChoiceField choice; + + @Inject + private Block choiceText; + + @Inject + private Block choiceImage; + + @Inject + private Block choiceDate; + + @Inject + private ComponentResources resources; + + @Inject + private ServiceImage serviceImage; + + /** + * Get choices of the poll. The ChoiceDTO from poll will be converted + * to ChoiceField to easily managed different type of choice (image, + * date, text). + * + * @return a list of ChoiceField corresponding to poll choices + * @throws PollenBusinessException + */ + public List<ChoiceField> getChoices() throws PollenBusinessException { + if (choices == null) { + if (log.isInfoEnabled()) { + log.info("Prepare choices for render"); + } + choices = new ArrayList<ChoiceField>(); + for (ChoiceDTO curr : getPoll().getChoices()) { + ChoiceField field = new ChoiceField(curr, + getPoll().getChoiceType()); + choices.add(field); + } + } + if (log.isDebugEnabled()) { + log.debug("nb choices loaded : " + choices.size()); + } + return choices; + } + + /** + * Delegator : return the correct choice block depends on poll choiceType. + * + * @return the choice block to display + * @throws PollenBusinessException + */ + public Block getChoiceBlock() throws PollenBusinessException { + switch(getPoll().getChoiceType()) { + case IMAGE: + return choiceImage; + case DATE: + return choiceDate; + case TEXT: + default: + return choiceText; + } + } + + /** + * Image link to show the miniature (thumb) of current choice image. + * + * @return the image link for current choice image. + */ + public Link getImageThumb() { + return getImageLink(true); + } + + /** + * Image link to show the normal (not thumb) image of current choice image. + * + * @return the image link for current choice image. + */ + public Link getImageLink() { + return getImageLink(false); + } + + private Link getImageLink(boolean thumb) { + return resources.createEventLink("showImage", + choice.getImageFileName(), choice.getImageDir(), thumb); + } + + /** + * Event for showing image. + * + * @param src of the image + * @param imageDir directory of the image + * @param thumb to show the thumb image or not + * @return the streamResponse to display + * @see ServiceImage#createImageStream(String, String, boolean) + */ + @Log + public StreamResponse onShowImage(String src, String imageDir, + boolean thumb) { + return serviceImage.createImageStream(src, imageDir, thumb); + } + + public boolean isPollChoiceRunning() throws PollenBusinessException { + return getPoll().isChoiceAddAllowed() && isPollChoiceStarted(); + } + + /** + * TODO : whithout DTO, this method can be place in PollEntity + * + * @return true if adding choice is started, false otherwise + * @throws PollenBusinessException + */ + public boolean isPollChoiceStarted() throws PollenBusinessException { + Date now = new Date(); + boolean started = getPoll().getBeginChoiceDate() == null + || getPoll().getBeginChoiceDate().before(now); + boolean ended = getPoll().getEndChoiceDate() != null + && getPoll().getEndChoiceDate().before(now); + return started && !ended; + } + + public boolean canDeleteChoice() throws PollenBusinessException { + return isPollChoiceRunning() && isCreatorUser(); + } + + /** + * ACTION EVENT :: delete selected choice + */ + void onActionFromDeleteChoice(String choiceId) + throws PollenBusinessException { + if (canDeleteChoice()) { + servicePoll.deleteChoice(getPoll(), choiceId); + // Reset choices (ChoiceField list) to retrieve the updated one + // from poll + choices = null; + } + } + + /************** PAGER *****************************************************/ + @InjectComponent private Pager pager; - private List<VoteDTO> votes; - private Integer page; @Persist @@ -1183,9 +1323,20 @@ } public String getNoPagerText() throws PollenBusinessException { - return messages.format("vote-noPagerText", getPoll().getNbVotes()); + if (getPoll().getNbVotes() == 0) { + return messages.get("pollen.ui.vote.noVotes"); + } + return messages.format("pollen.ui.vote.noPager", + getPoll().getNbVotes()); } + /************** VOTES *****************************************************/ + + private List<VoteDTO> votes; + + @Property + private int voteIndex; + /** * Retrieve votes of the current poll from business module. * The votes are ordered by creation date, only the ones to display are @@ -1202,6 +1353,28 @@ return votes; } + public boolean canEditVote() throws PollenBusinessException { + // If the current account exist from uri and equals to the current vote + String newAccountId = getPollAccount().getId(); + if (newAccountId != null && newAccountId.equals(vote.getPollAccountId())) { + return true; + // If the connected user is an admin + } else if (userExists && user.isAdministrator()) { + return true; + // If the connected user is the poll creator + } else if (isCreatorUser()) { + return true; + } + return false; + } + + /** Méthode appelée lors de l'édition d'un vote. */ +// Object onActionFromEditVote(int voteIndex) throws PollenBusinessException { +//// getPollAccount().setVotingId(votingId); +// vote = getVotes().get(voteIndex); +// return pollZone.getBody(); +// } + /************** COMMENTS **************************************************/ @InjectComponent Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -74,11 +74,11 @@ for (VotingListDTO list : poll.getVotingListDTOs()) { for (PollAccountDTO account : list.getPollAccountDTOs()) { if (account.getEmail().equals(user.getEmail())) { - return poll.getPollId() + ":" + account.getAccountId(); + return poll.getPollUId() + ":" + account.getAccountId(); } } } - return poll.getPollId(); + return poll.getPollUId(); } /** Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -72,6 +72,7 @@ binder.bind(ServiceResults.class); binder.bind(ServiceVote.class); binder.bind(ServiceChoice.class); + binder.bind(ServiceImage.class); } public static void contributeApplicationDefaults( Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -127,7 +127,7 @@ */ private void sendMailNotification(PollDTO poll, Long timeValue) { String voteURL = PollenProperty.SERVER_URL.getValue() + "/poll/VoteFor/" - + poll.getPollId(); + + poll.getPollUId(); Map<String, String> data = new HashMap<String, String>(); data.put("host", PollenProperty.EMAIL_HOST.getValue()); data.put("port", PollenProperty.EMAIL_PORT.getValue()); Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java (rev 0) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -0,0 +1,63 @@ + +package org.chorem.pollen.ui.services; + +import org.apache.tapestry5.StreamResponse; +import org.apache.tapestry5.upload.services.UploadedFile; + +/** + * This service is used to manage images in pollen application. + * + * Saving process : + * <pre> + * - Use the upload component of Tapestry to retrieve the uploaded file + * - After file type validation use saveImage method to create the image, + * folders and thumbnail + * </pre> + * Display process : + * <pre> + * - Create eventLink for the src property of an img tag + * (<img src=${myLink}... />) + * - On event method, return the streamResponse created by createImageStream + * method + * </pre> + * + * Created: 20 mars 2010 + * + * @author fdesbois + * @version $Revision$ + * @since 1.3 + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public interface ServiceImage { + + /** + * Return the context path for pollen image managment. + * + * @return the context path for images + */ + String getContextPath(); + + /** + * Create a StreamResponse represent the image to display. + * + * @param filename the filename of the image + * @param filedir the directory where the image is defined + * @param thumb to return a stream for the thumb image + * @return the StreamResponse to display (using eventLink) + */ + StreamResponse createImageStream(String filename, String filedir, + boolean thumb); + + /** + * Save an image in {@code filedir} from uploaded {@code tmpfile}. + * + * @param tmpfile which contains the image stream + * @param filedir where the image will be saved (not need to precise + * the context) + * @return the filename of the saved file + */ + String saveImage(UploadedFile tmpfile, String filedir); + +} Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java (rev 0) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -0,0 +1,162 @@ + +package org.chorem.pollen.ui.services; + +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import javax.activation.MimetypesFileTypeMap; +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import org.apache.commons.lang.StringUtils; +import org.apache.tapestry5.StreamResponse; +import org.apache.tapestry5.services.Response; +import org.apache.tapestry5.upload.services.UploadedFile; +import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenProperty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ServiceImageImpl + * + * Created: 20 mars 2010 + * + * @author fdesbois + * @version $Revision$ + * @since 1.3 + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ServiceImageImpl implements ServiceImage { + + private static final String THUMB_PREFIX = "thumb_"; + + private static final int THUMB_WIDTH = 100; + + private static final Logger logger = LoggerFactory.getLogger(ServiceImageImpl.class); + + public ServiceImageImpl() { + + } + + @Override + public String getContextPath() { + return PollenContext.getProperty(PollenProperty.IMG_DIR); + } + + /** + * Get the directory where are uploaded the images from the context. + * + * @param imageDir + * @return a File corresponding to the image directory + */ + public File getImagePathDir(String imageDir) { + File result = null; + if (StringUtils.isNotEmpty(imageDir)) { + result = new File(getContextPath(), imageDir); + } else { + result = new File(getContextPath()); + } + return result; + } + + public File getImageFile(String filename, String imageDir, boolean thumb) { + if (thumb) { + filename = THUMB_PREFIX + filename; + } + return new File(getImagePathDir(imageDir), filename); + } + + @Override + public StreamResponse createImageStream(String filename, String filedir, boolean thumb) { + if (StringUtils.isEmpty(filename) || filename.contains("..")) { + return null; + } + + final File file = getImageFile(filename, filedir, thumb); + if (!file.exists()) { + logger.error("Fichier inexistant : " + file.getAbsolutePath()); + } + + return new StreamResponse() { + + @Override + public String getContentType() { + MimetypesFileTypeMap mimes = new MimetypesFileTypeMap(); + return mimes.getContentType(file); + } + + @Override + public InputStream getStream() throws IOException { + return new FileInputStream(file); + } + + @Override + public void prepareResponse(Response response) { + + } + }; + } + + @Override + public String saveImage(UploadedFile tmpfile, String filedir) { + File dir = getImagePathDir(filedir); + if (!dir.exists()) { + if (logger.isDebugEnabled()) { + logger.debug("Create image directory : " + + dir.getAbsolutePath()); + } + dir.mkdirs(); + } + String filename = tmpfile.getFileName(); + + File image = new File(dir, filename); + tmpfile.write(image); + if (logger.isDebugEnabled()) { + logger.debug("Image saved: " + filename + + " (size=" + tmpfile.getSize() + ")"); + } + + createThumbnail(image, dir); + return image.getName(); + } + + /** + * Création d'une miniature. + * + * @param img + * @param dir Le répertoire de destination. + */ + public void createThumbnail(File img, File dir) { + + ImageIcon ii = new ImageIcon(img.getAbsolutePath()); + Image image = ii.getImage(); + double imageRatio = (double) image.getHeight(null) + / (double) image.getWidth(null); + int height = (int) (THUMB_WIDTH * imageRatio); + + BufferedImage thumbImage = new BufferedImage(THUMB_WIDTH, height, + BufferedImage.TYPE_INT_RGB); + Graphics2D graphics2D = thumbImage.createGraphics(); + graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, + RenderingHints.VALUE_INTERPOLATION_BILINEAR); + graphics2D.drawImage(image, 0, 0, THUMB_WIDTH, height, null); + File thumbCopied = new File(dir, THUMB_PREFIX + img.getName()); + try { + ImageIO.write(thumbImage, "jpg", thumbCopied); + } catch (IOException e) { + logger.error("Erreur à l'enregistrement de la miniature", e); + } + if (logger.isDebugEnabled()) { + logger.debug("Thumbnail created: " + thumbCopied.getName() + " " + + "(size=" + thumbCopied.length() + ")"); + } + } + +} Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/ImageUtil.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/ImageUtil.java 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/ImageUtil.java 2010-03-20 15:30:29 UTC (rev 2952) @@ -39,7 +39,9 @@ * * @author rannou * @version $Id$ + * @deprecated use {@link org.chorem.pollen.ui.services.ServiceImage} instead */ +@Deprecated public class ImageUtil { /** log. */ Modified: trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties =================================================================== --- trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties 2010-03-20 15:30:29 UTC (rev 2952) @@ -39,4 +39,9 @@ validate=Validate cancel=Cancel return=Return -help=Help \ No newline at end of file +help=Help + +pollen.ui.choice.delete.confirm=Are you sure you want to delete this choice ? +pollen.ui.choice.delete.title=Delete this choice +pollen.ui.vote.noVotes=Aucune personne n'a encore particip\u00E9 au sondage +pollen.ui.vote.noPager=%d existing votes \ No newline at end of file Modified: trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties =================================================================== --- trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-03-20 15:30:29 UTC (rev 2952) @@ -1,35 +1,35 @@ # User registration emails -registerEmail_subject=[Pollen] Confirmation de cr\u00e9ation du compte %s -registerEmail_msg=Bienvenue %s %s. Vous venez de cr\u00e9er un compte sur l'application de sondage en ligne Pollen.\n\nIdentifiant : %s\nMot de passe : %s\n\nVous pouvez d\u00e8s maintenant g\u00e9rer vos sondages en vous identifiant sur le site : \n%s +registerEmail_subject=[Pollen] Confirmation de cr\u00E9ation du compte %s +registerEmail_msg=Bienvenue %s %s. Vous venez de cr\u00E9er un compte sur l'application de sondage en ligne Pollen.\n\nIdentifiant : %s\nMot de passe : %s\n\nVous pouvez d\u00E8s maintenant g\u00E9rer vos sondages en vous identifiant sur le site : \n%s # Poll creation emails -creatorEmail_subject=[Pollen] Cr\u00e9ation d'un sondage (%s) -creatorEmail_msg=Vous venez de cr\u00e9er le sondage "%s".\nVous pouvez y acc\u00e9der en suivant les liens ci-dessous.\n\nPage de vote : \n%s\nPage de modification : \n%s +creatorEmail_subject=[Pollen] Cr\u00E9ation d'un sondage (%s) +creatorEmail_msg=Vous venez de cr\u00E9er le sondage "%s".\nVous pouvez y acc\u00E9der en suivant les liens ci-dessous.\n\nPage de vote : \n%s\nPage de modification : \n%s votingEmail_subject=[Pollen] Invitation au vote (%s) -votingEmail_msg=Un nouveau sondage a \u00e9t\u00e9 cr\u00e9\u00e9 : "%s".\nVous pouvez y participer avec l'identifiant %s \u00e0 l'adresse suivante : \n%s +votingEmail_msg=Un nouveau sondage a \u00E9t\u00E9 cr\u00E9\u00E9 : "%s".\nVous pouvez y participer avec l'identifiant %s \u00E0 l'adresse suivante : \n%s # Notification emails voteEmail_subject=[Pollen] Notification de vote (%s) -voteEmail_msg=Un vote vient d'\u00eatre enregistr\u00e9 pour le sondage "%s". Ce sondage compte d\u00e9sormais %d votes.\nVous pouvez acc\u00e9der \u00e0 ce sondage en suivant les liens ci-dessous.\n\nPage de vote : \n%s\nPage de modification : \n%s +voteEmail_msg=Un vote vient d'\u00EAtre enregistr\u00E9 pour le sondage "%s". Ce sondage compte d\u00E9sormais %d votes.\nVous pouvez acc\u00E9der \u00E0 ce sondage en suivant les liens ci-dessous.\n\nPage de vote : \n%s\nPage de modification : \n%s # Reminder emails reminderEmail_subject=[Pollen] Rappel (%s) -reminderEmail_msg=Vous n'avez pas encore vot\u00e9 pour le sondage "%s".\nVous pouvez encore y participer avec l'identifiant %s \u00e0 l'adresse suivante : \n%s +reminderEmail_msg=Vous n'avez pas encore vot\u00E9 pour le sondage "%s".\nVous pouvez encore y participer avec l'identifiant %s \u00E0 l'adresse suivante : \n%s # Poll feed pollFeed_title=Pollen : %s pollFeed_desc=%s -pollFeed_createTitle=Sondage cr\u00e9\u00e9 par %s +pollFeed_createTitle=Sondage cr\u00E9\u00E9 par %s pollFeed_createContent= pollFeed_voteTitle=Nouveau vote de %s -pollFeed_voteContent=\u00c9tat du sondage : %s +pollFeed_voteContent=\u00C9tat du sondage : %s pollFeed_choiceTitle=Nouveau choix : %s pollFeed_choiceContent=%s pollFeed_commentTitle=Nouveau commentaire de %s pollFeed_commentContent=%s # Actions -create=Cr\u00e9er +create=Cr\u00E9er edit=Modifier delete=Supprimer add=Ajouter @@ -40,3 +40,8 @@ cancel=Annuler return=Retour help=Aide + +pollen.ui.choice.delete.confirm=Etes-vous s\u00FBr de vouloir d\u00E9finitivement supprimer ce choix ? +pollen.ui.choice.delete.title=Supprimer ce choix +pollen.ui.vote.noVotes=Aucune personne n'a encore particip\u00E9 au sondage +pollen.ui.vote.noPager=%d votes existants Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties =================================================================== --- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties 2010-03-20 15:30:29 UTC (rev 2952) @@ -20,7 +20,7 @@ anonymousVote-label=Anonymous vote submitVote=Vote vote-success=Your vote has been correctly saved -vote-noPagerText=%d existing votes +#vote-noPagerText=%d existing votes #choices addChoice=Adding a choice @@ -59,4 +59,4 @@ pollNotStarted=This poll has not started yet. pollFinished=This poll is finished. You can not vote anymore. pollClosed=This poll is closed. You can not vote anymore. -pollChoiceRunning=Adding choices is allowed. \ No newline at end of file +pollChoiceRunning=Adding choices is allowed. Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties =================================================================== --- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties 2010-03-20 15:30:29 UTC (rev 2952) @@ -20,7 +20,7 @@ anonymousVote-label=Vote anonyme submitVote=Voter vote-success=Votre vote a bien \u00E9t\u00E9 enregistr\u00E9 -vote-noPagerText=%d votes existants +#vote-noPagerText=%d votes existants #choices addChoice=Ajout d'un choix @@ -59,4 +59,4 @@ pollNotStarted=Ce sondage n'a pas encore commenc\u00E9. pollFinished=Ce sondage est termin\u00E9. Vous ne pouvez plus voter. pollClosed=Ce sondage est clos. Vous ne pouvez plus voter. -pollChoiceRunning=L'ajout de choix est possible. \ No newline at end of file +pollChoiceRunning=L'ajout de choix est possible. Modified: trunk/pollen-ui/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/pollen-ui/src/main/webapp/WEB-INF/web.xml 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/webapp/WEB-INF/web.xml 2010-03-20 15:30:29 UTC (rev 2952) @@ -30,14 +30,14 @@ <filter-name>app</filter-name> <filter-class>org.apache.tapestry5.TapestryFilter</filter-class> </filter> - <filter> +<!-- <filter> <filter-name>appExceptions</filter-name> <filter-class>org.chorem.pollen.ui.filters.PollenExceptionsFilter</filter-class> - </filter> - <filter-mapping> + </filter>--> +<!-- <filter-mapping> <filter-name>appExceptions</filter-name> <url-pattern>/*</url-pattern> - </filter-mapping> + </filter-mapping>--> <filter-mapping> <filter-name>app</filter-name> <url-pattern>/*</url-pattern> Modified: trunk/pollen-ui/src/main/webapp/img/1leftarrow.png =================================================================== (Binary files differ) Modified: trunk/pollen-ui/src/main/webapp/img/1rightarrow.png =================================================================== (Binary files differ) Modified: trunk/pollen-ui/src/main/webapp/img/2leftarrow.png =================================================================== (Binary files differ) Modified: trunk/pollen-ui/src/main/webapp/img/2rightarrow.png =================================================================== (Binary files differ) Deleted: trunk/pollen-ui/src/main/webapp/js/ZoneUpdater.js =================================================================== --- trunk/pollen-ui/src/main/webapp/js/ZoneUpdater.js 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/webapp/js/ZoneUpdater.js 2010-03-20 15:30:29 UTC (rev 2952) @@ -1,103 +0,0 @@ -var ZoneUpdater = Class.create(); - -ZoneUpdater.prototype = { - - initialize: function(zoneElementId, listeningElement, event, link, zone, placeholder) { - - this.zoneElement = $(zoneElementId); - - this.event = event; - - this.link = link; - - this.placeholder = placeholder; - - $T(this.zoneElement).zoneId = zone; - - listeningElement.observe(this.event, this.updateZone.bindAsEventListener(this)); - - }, - - updateZone: function(event) { - - var zoneObject = Tapestry.findZoneManager(this.zoneElement); - - if ( !zoneObject ) return; - - var param; - - if (this.zoneElement.value) { - - param = this.zoneElement.value; - - } - - if (!param) param = ' '; - - param = this.encodeForUrl(param); - - var updatedLink = this.link.gsub(this.placeholder, param); - - zoneObject.updateFromURL(updatedLink); - - }, - - encodeForUrl: function(string) { - - /** - - * See equanda.js for updated version of this - - */ - - string = string.replace(/\r\n/g,"\n"); - - var res = ""; - - for (var n = 0; n < string.length; n++) - - { - - var c = string.charCodeAt( n ); - - if ( '$' == string.charAt( n ) ) - - { - - res += '$$'; - - } - - else if ( this.inRange( c, "AZ" ) || this.inRange( c, "az" ) || this.inRange( c, "09" ) || this.inRange( c, ".." ) ) - - { - - res += string.charAt( n ) - - } - - else - - { - - var tmp = c.toString(16); - - while ( tmp.length < 4 ) tmp = "0" + tmp; - - res += '$' + tmp; - - } - - } - - return res; - - }, - - inRange: function(code, range) { - - return code >= range.charCodeAt( 0 ) && code <= range.charCodeAt( 1 ); - - } - -} \ No newline at end of file Added: trunk/pollen-ui/src/main/webapp/js/confirm.js =================================================================== --- trunk/pollen-ui/src/main/webapp/js/confirm.js (rev 0) +++ trunk/pollen-ui/src/main/webapp/js/confirm.js 2010-03-20 15:30:29 UTC (rev 2952) @@ -0,0 +1,20 @@ +/** + * Dialogue de confirmation + */ +var Confirm = Class.create({ + /** + * element : Element DOM depuis lequel le dialogue de confirmation va s'ouvrir + * message : Message à afficher dans la boîte de dialogue + */ + initialize: function(element, message) { + this.message = message; + Event.observe($(element), 'click', this.doConfirm.bindAsEventListener(this)); + }, + doConfirm: function(e) { + //Tapestry.debug('click ' + element); + if(! confirm(this.message)) { + //Tapestry.debug('STOP ' + e); + Event.stop(e); + } + } +}); \ No newline at end of file Copied: trunk/pollen-ui/src/main/webapp/js/zoneUpdater.js (from rev 2950, trunk/pollen-ui/src/main/webapp/js/ZoneUpdater.js) =================================================================== --- trunk/pollen-ui/src/main/webapp/js/zoneUpdater.js (rev 0) +++ trunk/pollen-ui/src/main/webapp/js/zoneUpdater.js 2010-03-20 15:30:29 UTC (rev 2952) @@ -0,0 +1,103 @@ +var ZoneUpdater = Class.create(); + +ZoneUpdater.prototype = { + + initialize: function(zoneElementId, listeningElement, event, link, zone, placeholder) { + + this.zoneElement = $(zoneElementId); + + this.event = event; + + this.link = link; + + this.placeholder = placeholder; + + $T(this.zoneElement).zoneId = zone; + + listeningElement.observe(this.event, this.updateZone.bindAsEventListener(this)); + + }, + + updateZone: function(event) { + + var zoneObject = Tapestry.findZoneManager(this.zoneElement); + + if ( !zoneObject ) return; + + var param; + + if (this.zoneElement.value) { + + param = this.zoneElement.value; + + } + + if (!param) param = ' '; + + param = this.encodeForUrl(param); + + var updatedLink = this.link.gsub(this.placeholder, param); + + zoneObject.updateFromURL(updatedLink); + + }, + + encodeForUrl: function(string) { + + /** + + * See equanda.js for updated version of this + + */ + + string = string.replace(/\r\n/g,"\n"); + + var res = ""; + + for (var n = 0; n < string.length; n++) + + { + + var c = string.charCodeAt( n ); + + if ( '$' == string.charAt( n ) ) + + { + + res += '$$'; + + } + + else if ( this.inRange( c, "AZ" ) || this.inRange( c, "az" ) || this.inRange( c, "09" ) || this.inRange( c, ".." ) ) + + { + + res += string.charAt( n ) + + } + + else + + { + + var tmp = c.toString(16); + + while ( tmp.length < 4 ) tmp = "0" + tmp; + + res += '$' + tmp; + + } + + } + + return res; + + }, + + inRange: function(code, range) { + + return code >= range.charCodeAt( 0 ) && code <= range.charCodeAt( 1 ); + + } + +} \ No newline at end of file Property changes on: trunk/pollen-ui/src/main/webapp/js/zoneUpdater.js ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml =================================================================== --- trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml 2010-03-20 15:30:29 UTC (rev 2952) @@ -8,8 +8,8 @@ <img src="${asset:context:img/vote.png}" alt="${message:vote}" style="margin-right: 18px;"/> ${message:votePage} <br /> - <t:PageLink t:context="poll.pollId" t:page="poll/VoteForPoll" style="margin-left:50px;"> - ${siteURL}poll/VoteFor/${poll.pollId} + <t:PageLink t:context="poll.pollUId" t:page="poll/VoteForPoll" style="margin-left:50px;"> + ${siteURL}poll/VoteFor/${poll.pollUId} </t:PageLink> </div> <div style="margin-top: 10px;"> Modified: trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml =================================================================== --- trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-03-20 15:30:29 UTC (rev 2952) @@ -275,7 +275,7 @@ </div> </t:formfragment> <t:formfragment t:id="imgChoiceFragment" visible="isImgChoices()"> - <t:ImageContextLink t:id="imgContext" t:dir="poll.pollId" /> + <t:ImageContextLink t:id="imgContext" t:dir="poll.pollUId" /> <div t:type="loop" t:source="imgTypeChoices" t:value="imgTypeChoice" t:volatile="true"> <div class="fleft choiceName"> <t:label for="imgFile" /> Modified: trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml =================================================================== --- trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-03-19 15:05:04 UTC (rev 2951) +++ trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-03-20 15:30:29 UTC (rev 2952) @@ -14,13 +14,13 @@ <legend>${message:about}</legend> <div style="float: right"> <t:if test="poll.publicResults"> - <t:PageLink t:page="poll/Results" t:context="poll.pollId"> + <t:PageLink t:page="poll/Results" t:context="poll.pollUId"> <img src="${asset:context:img/count.png}" title="${message:results-help}" alt="${message:results}"/> </t:PageLink> </t:if> <t:FeedContextLink t:id="feedContext" /> <t:if test="feedFileExisting"> - <t:FileLink filename="${poll.pollId}" type="literal:application/atom+xml" t:context="feedContext"> + <t:FileLink filename="${poll.pollUId}" type="literal:application/atom+xml" t:context="feedContext"> <img src="${asset:context:img/feed.png}" title="Atom" alt="Atom"/> </t:FileLink> </t:if> @@ -44,7 +44,7 @@ <!-- Sondage --> - <t:zone t:id="pollZone" t:show="show" t:update="show"> + <!--<t:zone t:id="pollZone" t:show="show" t:update="show">--> <t:if t:test="poll.anonymous"> <p>${voteSizeMessage}</p> <t:feedback t:id="voteFeedback"/> @@ -63,72 +63,42 @@ <th></th> </p:else> </t:if> - <t:if test="textType"> - <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true"> - <t:if test="!isChoiceHidden()"> - <th> - <t:unless test="isDescNull()"> - <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind"> - <span class="desc">${choiceOfPoll.name}</span> - </span> - <p:else> - ${choiceOfPoll.name} - </p:else> - </t:unless> - <t:if test="${pollChoiceRunning}"> - <t:if test="creatorUser"> - <t:actionlink t:id="deleteChoice" context="choiceOfPoll.id" t:zone="pollZone"> - <img src="${asset:context:img/delete.png}" title="${message:delete}" alt="${message:delete}"/> - </t:actionlink> - </t:if> - </t:if> - </th> - </t:if> - </t:loop> - </t:if> - <t:if test="dateType"> - <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true"> - <t:unless test="choiceHidden"> - <t:unless test="isDescNull()"> - <th class="desc"> - <span t:type="ck/Tooltip" t:value="choiceOfPoll.description" t:effect="blind"> - <t:output value="choiceNameAsDate" format="dateFormat"/> - </span> - </th> - <p:else> - <th> - <t:output value="choiceNameAsDate" format="dateFormat"/> - </th> - </p:else> - </t:unless> - </t:unless> - </t:loop> - </t:if> - <t:if test="imageType"> - - <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true"> - <t:if test="!isChoiceHidden()"> - <t:unless test="isDescNull()"> - <th class="desc"> - <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind"> - <t:image t:src="choiceOfPoll.name" alt="choiceOfPoll.description" t:dir="poll.pollId"/> - </span> - </th> - <p:else> - <th> - <t:image t:src="choiceOfPoll.name" alt="choiceOfPoll.name" t:dir="poll.pollId"/> - </th> - </p:else> - </t:unless> - </t:if> - </t:loop> - </t:if> + <th t:type="loop" t:source="choices" t:value="choice" t:volatile="true"> + <t:unless test="choice.hidden"> + <t:block t:id="choiceText"> + <span class="desc">${choice.text}</span> + </t:block> + <t:block t:id="choiceImage"> + <a rel="lightbox[pollChoiceImages]" href="${imageLink}"> + <img src="${imageThumb}" alt="${choice.description}"/> + </a> + </t:block> + <t:block t:id="choiceDate"> + <t:output value="choice.date" format="dateFormat"/> + </t:block> + <t:if t:test="choice.description"> + <span t:type="ck/Tooltip" t:value="choice.description" t:effect="blind"> + <t:delegate to="choiceBlock" /> + </span> + <p:else> + <t:delegate to="choiceBlock" /> + </p:else> + </t:if> + <t:if test="canDeleteChoice()"> + <t:actionlink t:id="deleteChoice" context="choice.id" + t:mixins="confirm" t:message="message:pollen.ui.choice.delete.confirm"> + <img src="${asset:context:img/delete.png}" title="message:pollen.ui.choice.delete.title" + alt="message:pollen.ui.choice.delete.title"/> + </t:actionlink> + </t:if> + </t:unless> + </th> </tr> - </thead> - <t:if test="pollRunning"> - <tfoot> + </thead><!-- + <t:if test="pollRunning">--> +<!-- <tfoot> <tr> - <t:if test="${accountFieldDisplayed}"> + <t:if test="accountFieldDisplayed"> <th id="voterName"> <t:textField t:value="pollAccount.votingId" t:id="pollAccountName" t:validate="required"/> </th> @@ -136,7 +106,7 @@ <th></th> </p:else> </t:if> - <t:loop t:source="poll.choices" t:value="choiceOfVote" volatile="true"> + <t:loop t:source="choices" t:value="choice" volatile="true"> <t:if test="!choiceOfVote.hidden"> <th> <t:if test="isNormalVoteCounting()"> @@ -155,24 +125,24 @@ </t:if> </t:loop> </tr> - </tfoot> - </t:if> + </tfoot>--> + <!--</t:if>--> <tbody> <t:unless t:test="poll.anonymous"> - <t:loop t:source="votes" t:value="vote" volatile="true"> + <t:loop t:source="votes" t:value="vote" t:rowIndex="voteIndex" volatile="true"> <tr> <td class="${evenodd.next}"> <t:if test="${AccountFieldDisplayed}"> <t:unless test="${currentVoteAnonymous}"> - ${currentVotingId} + ${vote.name} <p:else> ? </p:else> </t:unless> </t:if> <t:unless test="${poll.anonymous}"> - <t:if test="isModifAllowed(currentVotingId)"> - <t:actionlink t:id="editVote" context="${currentVotingId}" t:zone="pollZone"> + <t:if test="canEditVote()"> + <t:actionlink t:id="editVote" context="voteIndex" t:zone="pollZone"> <img src="${asset:context:img/editSmall.png}" title="${message:edit}" alt="${message:edit}"/> </t:actionlink> </t:if> @@ -231,7 +201,7 @@ <t:if test="poll.continuousResults"> <tr> <td> - <t:PageLink t:page="poll/results" t:context="${poll.pollId}">${message:results}</t:PageLink> + <t:PageLink t:page="poll/results" t:context="${poll.pollUId}">${message:results}</t:PageLink> </td> <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true"> <t:if test="!isChoiceHidden()"> @@ -256,11 +226,11 @@ </div> </t:if> </t:form> - </t:zone> + <!--</t:zone>--> <!-- Ajout de choix --> - <t:ImageContextLink t:id="imgContext" t:thumb="true" t:dir="poll.pollId"/> + <t:ImageContextLink t:id="imgContext" t:thumb="true" t:dir="poll.pollUId"/> <t:if test="${pollChoiceRunning}"> <h4>${message:addChoice}</h4> <div id="choiceFormDiv">