Author: tchemit Date: 2012-01-24 17:50:44 +0100 (Tue, 24 Jan 2012) New Revision: 3120 Url: http://chorem.org/repositories/revision/pollen/3120 Log: add poll screen Modified: branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll.jsp Modified: branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java =================================================================== --- branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-01-24 16:49:31 UTC (rev 3119) +++ branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-01-24 16:50:44 UTC (rev 3120) @@ -23,49 +23,142 @@ */ package org.chorem.pollen.ui.actions.poll; +import com.google.common.collect.Maps; +import com.opensymphony.xwork2.Preparable; +import org.chorem.pollen.common.ChoiceType; +import org.chorem.pollen.common.PollType; +import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.entity.Poll; +import org.chorem.pollen.entity.UserAccount; import org.chorem.pollen.services.PollService; import org.chorem.pollen.ui.actions.PollenActionSupport; -import org.nuiton.topia.TopiaException; +import java.util.Map; + /** * Creates a new poll. * * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class CreatePoll extends PollenActionSupport { +public class CreatePoll extends PollenActionSupport implements Preparable { private static final long serialVersionUID = 1L; protected Poll poll; + protected Map<String, String> pollTypes; + + protected Map<String, String> voteCountingTypes; + + protected Map<String, String> choiceTypes; + + protected boolean notification; + + protected boolean reminder; + + protected boolean limitChoice; + + protected int reminderHourCountdown; + + protected int notificationNumber; + public String getPageLogo() { return "Creation"; } public Poll getPoll() { if (poll == null) { - poll = newService(PollService.class).getNewPoll(); + UserAccount userAccount = getPollenSession().getUserAccount(); + poll = newService(PollService.class).getNewPoll(userAccount); } return poll; } + public Map<String, String> getPollTypes() { + return pollTypes; + } + + public Map<String, String> getVoteCountingTypes() { + return voteCountingTypes; + } + + public Map<String, String> getChoiceTypes() { + return choiceTypes; + } + + public boolean isNotification() { + return notification; + } + + public void setNotification(boolean notification) { + this.notification = notification; + } + + public boolean isReminder() { + return reminder; + } + + public void setReminder(boolean reminder) { + this.reminder = reminder; + } + + public boolean isLimitChoice() { + return limitChoice; + } + + public void setLimitChoice(boolean limitChoice) { + this.limitChoice = limitChoice; + } + + public int getReminderHourCountdown() { + return reminderHourCountdown; + } + + public void setReminderHourCountdown(int reminderHourCountdown) { + this.reminderHourCountdown = reminderHourCountdown; + } + + public int getNotificationNumber() { + return notificationNumber; + } + + public void setNotificationNumber(int notificationNumber) { + this.notificationNumber = notificationNumber; + } + @Override public String execute() throws Exception { PollService service = newService(PollService.class); - try { - Poll basicPoll = service.createBasicPoll(poll); +// try { +// Poll basicPoll = service.createBasicPoll(poll); +// +// return SUCCESS; +// } catch (TopiaException e) { +// +// } - return SUCCESS; - } catch (TopiaException e) { + // back to input + return INPUT; + } + @Override + public void prepare() throws Exception { + + pollTypes = Maps.newHashMap(); + for (PollType pollType : PollType.values()) { + pollTypes.put(pollType.name(), _(pollType.getI18nKey())); } + voteCountingTypes = Maps.newHashMap(); + for (VoteCountingType voteCountingType : VoteCountingType.values()) { + voteCountingTypes.put(voteCountingType.name(), _(voteCountingType.getI18nKey())); + } - // back to input - return INPUT; - + choiceTypes = Maps.newHashMap(); + for (ChoiceType choiceType : ChoiceType.values()) { + choiceTypes.put(choiceType.name(), _(choiceType.getI18nKey())); + } } } Modified: branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties =================================================================== --- branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-01-24 16:49:31 UTC (rev 3119) +++ branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-01-24 16:50:44 UTC (rev 3120) @@ -1,3 +1,4 @@ +poll.common.select.choiceType=Select the type of choice pollen.action.create=Create pollen.action.createUser=Create a new user pollen.action.delete=Delete @@ -8,8 +9,13 @@ pollen.action.register=Register pollen.action.validate=Submit pollen.common.admin=Admin +pollen.common.beginChoiceDate=Begin choice date +pollen.common.beginDate=Begin date pollen.common.bugReport=Bug report +pollen.common.description=Description pollen.common.email=Em@il +pollen.common.endChoiceDate=end choice date +pollen.common.endDate=End date pollen.common.firstName=First name pollen.common.lastName=Last name pollen.common.license=Licence @@ -19,7 +25,23 @@ pollen.common.or=or pollen.common.password=Password pollen.common.password2=Renter your password +pollen.common.pollOption.anonymous=Anonymous +pollen.common.pollOption.anonymousVoteAllowed=Anonymous vote allowed +pollen.common.pollOption.continuousResults=Continous results +pollen.common.pollOption.limitChoice=Limit number of choice per vote +pollen.common.pollOption.notification=Receive notification emails +pollen.common.pollOption.publicResults=Public results +pollen.common.pollOption.reminder=Send reminder emails +pollen.common.pollOption.notificationNumber=After each n votes +pollen.common.pollOption.reminderHourCountdown=Hours before end +pollen.common.pollOption.choiceAddAllowed=Allow adding choices +pollen.common.pollOption.maxChoiceNb=Limit +pollen.common.pollType=Poll type +pollen.action.createPoll=Create the poll + +pollen.common.title=Title pollen.common.userSupport=User support +pollen.common.voteCountingType=Counting type pollen.error.email.required=You must provide a email pollen.error.login.required=You must provide a login pollen.error.password.required=Your must provide a password @@ -31,6 +53,10 @@ pollen.error.user.login.already.used=This login is already used pollen.fieldset.connexionInformation=Information de connexion pollen.fieldset.login=Login +pollen.fieldset.poll.choices=Choices +pollen.fieldset.poll.general=Your poll +pollen.fieldset.poll.options=Options +pollen.fieldset.poll.you=You pollen.fieldset.userInformation=Informations de l'utilisateur pollen.fieldset.userInformation.toCreate=User informations to create pollen.fieldset.userInformation.toDelete=User informations to delete Modified: branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties =================================================================== --- branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-01-24 16:49:31 UTC (rev 3119) +++ branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-01-24 16:50:44 UTC (rev 3120) @@ -1,3 +1,4 @@ +poll.common.select.choiceType=Sélectionner le type de choix pollen.action.create=Créer pollen.action.createUser=Créer un nouvel utilisateur pollen.action.delete=Supprimer @@ -8,8 +9,13 @@ pollen.action.register=S'enregistrer pollen.action.validate=Valider pollen.common.admin=Admin +pollen.common.beginChoiceDate=Date de début des choix +pollen.common.beginDate=Date de début pollen.common.bugReport=Rapport de bug +pollen.common.description=Description pollen.common.email=Em@il +pollen.common.endChoiceDate=Date de fin des choix +pollen.common.endDate=Date de fin pollen.common.firstName=Prénom pollen.common.lastName=Nom pollen.common.license=Licence @@ -19,7 +25,22 @@ pollen.common.or=ou pollen.common.password=Mot de passe pollen.common.password2=Répétez votre mot de passe +pollen.common.pollOption.anonymous=Sondage anonyme +pollen.common.pollOption.anonymousVoteAllowed=Autoriser le vote anonyme +pollen.common.pollOption.continuousResults=Résultats continus +pollen.common.pollOption.limitChoice=Limiter le nombre de choix par vote +pollen.common.pollOption.notification=Recevoir des emails de notification +pollen.common.pollOption.publicResults=Résultats publics +pollen.common.pollOption.reminder=Envoyer des emails de rappel +pollen.common.pollOption.reminderHourCountdown=heures avant la fin du sondage +pollen.common.pollOption.notificationNumber=Tous les n votes +pollen.common.pollOption.choiceAddAllowed=Autoriser l'ajout de choix +pollen.action.createPoll=Créer le sondage +pollen.common.pollOption.maxChoiceNb=Limite +pollen.common.pollType=Type de sondage +pollen.common.title=Titre pollen.common.userSupport=Support utilisateur +pollen.common.x=Dépouillement pollen.error.email.required=Courriel obligatoire pollen.error.login.required=Login obligatoire pollen.error.password.required=Mot de passe obligatoire @@ -31,6 +52,10 @@ pollen.error.user.login.already.used=Le login saisie est déjà utilisé par un autre utilisateur pollen.fieldset.connexionInformation=Information de connexion pollen.fieldset.login=Connexion +pollen.fieldset.poll.choices=Les choix +pollen.fieldset.poll.general=Votre sondage +pollen.fieldset.poll.options=Les options +pollen.fieldset.poll.you=Vous pollen.fieldset.userInformation=Informations de l'utilisateur pollen.fieldset.userInformation.toCreate=Informations de l'utilisateur à créer pollen.fieldset.userInformation.toDelete=Informations de l'utilisateur à supprimer Modified: branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll.jsp =================================================================== --- branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll.jsp 2012-01-24 16:49:31 UTC (rev 3119) +++ branches/pollen-2.0-beta-1/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll.jsp 2012-01-24 16:50:44 UTC (rev 3120) @@ -23,28 +23,115 @@ --%> <%@ page language="java" contentType="text/html" pageEncoding="utf-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> +<%@ taglib prefix="sj" uri="/struts-jquery-tags" %> +<script type="text/javascript"> + jQuery(document).ready(function () { + $('[name="poll.choiceAddAllowed"]').change(function(event) { + var val = $(this).prop('checked'); + if (val) { + $('#addChoiceAddAllowedPanel').show(); + } else { + $('#addChoiceAddAllowedPanel').hide(); + } + }); + + $('[name="limitChoice"]').change(function(event) { + var val = $(this).prop('checked'); + if (val) { + $('#maxChoiceNbPanel').show(); + } else { + $('#maxChoiceNbPanel').hide(); + } + }); + + $('[name="reminder"]').change(function(event) { + var val = $(this).prop('checked'); + if (val) { + $('#reminderPanel').show(); + } else { + $('#reminderPanel').hide(); + } + }); + + $('[name="notification"]').change(function(event) { + var val = $(this).prop('checked'); + if (val) { + $('#notificationPanel').show(); + } else { + $('#notificationPanel').hide(); + } + }); + + $('[name="poll.anonymous"]').change(function(event) { + var val = $(this).prop('checked'); + $('[name="poll.anonymousVoteAllowed"]').prop('checked', val); + }); + $('[name="poll.continuousResults"]').change(function(event) { + var val = $(this).prop('checked'); + $('[name="poll.publicResults"]').prop('checked', val); + }); + }); +</script> <title><s:text name="pollen.title.createPoll"/></title> <h1 class="title${pageLogo}"><s:text name="pollen.title.createPoll"/></h1> -<s:form method="POST" key="registerForm"> +<s:form method="POST" key="registerForm" namespace="/poll"> <fieldset> - <legend><s:text name="pollen.fieldset.connexionInformation"/></legend> + <legend><s:text name="pollen.fieldset.poll.you"/></legend> + <s:textfield key="poll.creator.name" label="%{getText('pollen.common.login')}" required="true"/> + <s:textfield key="poll.creator.email" label="%{getText('pollen.common.email')}"/> + </fieldset> - <s:textfield name="user.login" key="pollen.common.login" required="true"/> - <s:password name="user.password" key="pollen.common.password" required="true"/> - <s:password name="password2" key="pollen.common.password2" required="true"/> + <fieldset> + <legend><s:text name="pollen.fieldset.poll.general"/></legend> + + <s:textfield key="poll.title" label="%{getText('pollen.common.title')}" required="true"/> + <s:textfield key="poll.description" label="%{getText('pollen.common.description')}"/> + <sj:datepicker key="poll.beginDate" label="%{getText('pollen.common.beginDate')}" displayFormat="dd/mm/yy"/> + <sj:datepicker key="poll.endDate" label="%{getText('pollen.common.endDate')}" displayFormat="dd/mm/yy"/> + <s:radio key='poll.type' list="pollTypes" label='%{getText("pollen.common.pollType")}' /> + <s:radio key='poll.voteCounting' list="voteCountingTypes" label='%{getText("pollen.common.voteCountingType")}' /> </fieldset> <fieldset> - <legend><s:text name="pollen.fieldset.userInformation"/></legend> + <legend><s:text name="pollen.fieldset.poll.options"/></legend> - <s:textfield name="user.email" key="pollen.common.email" required="true"/> - <s:textfield name="user.firstName" key="pollen.common.firstName"/> - <s:textfield name="user.lastName" key="pollen.common.lastName"/> + <s:checkbox key="poll.anonymous" label="%{getText('pollen.common.pollOption.anonymous')}" /> + <s:checkbox key="poll.anonymousVoteAllowed" label="%{getText('pollen.common.pollOption.anonymousVoteAllowed')}" /> + <s:checkbox key="poll.continuousResults" label="%{getText('pollen.common.pollOption.continuousResults')}" /> + <s:checkbox key="poll.publicResults" label="%{getText('pollen.common.pollOption.publicResults')}" /> + <s:checkbox key="poll.choiceAddAllowed" label="%{getText('pollen.common.pollOption.choiceAddAllowed')}" /> + <div id='addChoiceAddAllowedPanel' class="hidden"> + <sj:datepicker key="poll.beginChoiceDate" label="%{getText('pollen.common.beginChoiceDate')}" displayFormat="dd/mm/yy"/> + <sj:datepicker key="poll.endChoiceDate" label="%{getText('pollen.common.endChoiceDate')}" displayFormat="dd/mm/yy"/> + </div> + <s:checkbox key="limitChoice" label="%{getText('pollen.common.pollOption.limitChoice')}" /> + <div id='maxChoiceNbPanel' class="hidden"> + <s:textfield key="poll.maxChoiceNb" label="%{getText('pollen.common.pollOption.maxChoiceNb')}"/> + </div> + <s:checkbox key="notification" label="%{getText('pollen.common.pollOption.notification')}" /> + <div id='notificationPanel' class="hidden"> + <s:textfield key="notificationNumber" + label="%{getText('pollen.common.pollOption.notificationNumber')}" /> + </div> + <s:checkbox key="reminder" label="%{getText('pollen.common.pollOption.reminder')}" /> + <div id='reminderPanel' class="hidden"> + <s:textfield key="reminderHourCountdown" + label="%{getText('pollen.common.pollOption.reminderHourCountdown')}" /> + </div> + </fieldset> + + <fieldset> + <legend><s:text name="pollen.fieldset.poll.choices"/></legend> + <s:select key="poll.choiceType" label='%{getText("poll.common.select.choiceType")}' + list="choiceTypes" headerKey="" headerValue=""/> + + </fieldset> + <br/> - <s:submit action="registerUser" key="pollen.action.register" align="center"/> + <s:submit action="createPoll" key="pollen.action.createPoll" align="center"/> </s:form>