Pollen-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
April 2012
- 5 participants
- 111 discussions
Author: tchemit
Date: 2012-04-06 18:46:00 +0200 (Fri, 06 Apr 2012)
New Revision: 3242
Url: http://chorem.org/repositories/revision/pollen/3242
Log:
updates deps
Modified:
branches/pollen-1.2.6-struts2/pom.xml
Modified: branches/pollen-1.2.6-struts2/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pom.xml 2012-04-06 16:21:51 UTC (rev 3241)
+++ branches/pollen-1.2.6-struts2/pom.xml 2012-04-06 16:46:00 UTC (rev 3242)
@@ -37,11 +37,11 @@
<version>3.6.10.Final</version>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.1</version>
- </dependency>
+ </dependency-->
<dependency>
<groupId>org.apache.commons</groupId>
@@ -57,7 +57,7 @@
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
- <version>1.4.4</version>
+ <version>1.4.5</version>
</dependency>
<dependency>
@@ -229,7 +229,7 @@
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
- <version>1.1</version>
+ <version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
@@ -244,7 +244,7 @@
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
- <version>3.10.0.GA</version>
+ <version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
@@ -447,16 +447,16 @@
<projectId>pollen</projectId>
<!-- customized versions -->
- <topiaVersion>2.6.9-SNAPSHOT</topiaVersion>
+ <topiaVersion>2.6.9</topiaVersion>
<eugenePluginVersion>2.4.2</eugenePluginVersion>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
<tapestryVersion>5.1.0.5</tapestryVersion>
<nuitonWebVersion>1.10</nuitonWebVersion>
- <nuitonUtilsVersion>2.4.4</nuitonUtilsVersion>
- <h2Version>1.3.164</h2Version>
+ <nuitonUtilsVersion>2.4.7</nuitonUtilsVersion>
+ <h2Version>1.3.165</h2Version>
<postgresqlVersion>9.1-901-1.jdbc4</postgresqlVersion>
<struts2Version>2.3.1.2</struts2Version>
- <jqueryPluginVersion>3.2.1</jqueryPluginVersion>
+ <jqueryPluginVersion>3.3.0</jqueryPluginVersion>
<shiroVersion>1.2.0</shiroVersion>
<slf4jVersion>1.6.4</slf4jVersion>
<jettyVersion>${jettyPluginVersion}</jettyVersion>
1
0
r3241 - branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll
by fdesbois@users.chorem.org 06 Apr '12
by fdesbois@users.chorem.org 06 Apr '12
06 Apr '12
Author: fdesbois
Date: 2012-04-06 18:21:51 +0200 (Fri, 06 Apr 2012)
New Revision: 3241
Url: http://chorem.org/repositories/revision/pollen/3241
Log:
problem with create, need to check pollUri
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-06 15:46:09 UTC (rev 3240)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-06 16:21:51 UTC (rev 3241)
@@ -61,7 +61,8 @@
prepareFormPage();
UserAccount userAccount = getPollenUserAccount();
- poll = getPollService().getPollEditable(pollUri.getPollId(), userAccount, clone);
+ String pollUid = pollUri == null ? null : pollUri.getPollId();
+ poll = getPollService().getPollEditable(pollUid, userAccount, clone);
List<Choice> pollChoices = poll.getChoice();
List<VotingList> pollVotingLists = poll.getVotingList();
1
0
r3240 - in branches/pollen-1.2.6-struts2: pollen-services/src/main/java/org/chorem/pollen/services pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll
by fdesbois@users.chorem.org 06 Apr '12
by fdesbois@users.chorem.org 06 Apr '12
06 Apr '12
Author: fdesbois
Date: 2012-04-06 17:46:09 +0200 (Fri, 06 Apr 2012)
New Revision: 3240
Url: http://chorem.org/repositories/revision/pollen/3240
Log:
- remove useless serviceContext in creators
- problem with choice topiaId in jsp
- simple merge for the moment : remove all and create new
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-04-06 12:56:20 UTC (rev 3239)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-04-06 15:46:09 UTC (rev 3240)
@@ -81,14 +81,12 @@
}
public static Function<VotingList, VotingList> newVotingListCreator(
- PollenServiceContext serviceContext,
Function<PersonToList, PersonToList> persontoListCreator) {
- return new VotingListCreator(serviceContext, persontoListCreator);
+ return new VotingListCreator(persontoListCreator);
}
- public static Function<PersonToList, PersonToList> newPersonToListCreator(
- PollenServiceContext serviceContext) {
- return new PersonToListCreator(serviceContext);
+ public static Function<PersonToList, PersonToList> newPersonToListCreator() {
+ return new PersonToListCreator();
}
public static class TextChoiceCreator implements Function<Choice, Choice> {
@@ -137,13 +135,9 @@
public static class VotingListCreator implements Function<VotingList, VotingList> {
- protected final PollenServiceContext serviceContext;
-
protected final Function<PersonToList, PersonToList> persontoListCreator;
- protected VotingListCreator(PollenServiceContext serviceContext,
- Function<PersonToList, PersonToList> persontoListCreator) {
- this.serviceContext = serviceContext;
+ protected VotingListCreator(Function<PersonToList, PersonToList> persontoListCreator) {
this.persontoListCreator = persontoListCreator;
}
@@ -176,12 +170,6 @@
public static class PersonToListCreator implements Function<PersonToList, PersonToList> {
- protected final PollenServiceContext serviceContext;
-
- protected PersonToListCreator(PollenServiceContext serviceContext) {
- this.serviceContext = serviceContext;
- }
-
@Override
public PersonToList apply(PersonToList input) {
PersonToList result = new PersonToListImpl();
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-06 12:56:20 UTC (rev 3239)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-06 15:46:09 UTC (rev 3240)
@@ -24,6 +24,7 @@
package org.chorem.pollen.services.impl;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@@ -196,14 +197,16 @@
for (VotingList votingListLoaded : source.getVotingList()) {
VotingList votingListEditable = newInstance(votingListDAO);
result.addVotingList(votingListEditable);
+ // Do not keep votingLists topiaId, to simplify the update will delete old votingLists and create new ones
PollenBinderHelper.simpleCopy(
- votingListLoaded, votingListEditable, !clone);
+ votingListLoaded, votingListEditable, false);
for (PersonToList personToListLoaded : votingListLoaded.getPollAccountPersonToList()) {
PersonToList personToListEditable = newInstance(personToListDAO);
votingListEditable.addPollAccountPersonToList(personToListEditable);
+ // Do not keep personToLists topiaId, to simplify the update will delete old personToLists and create new ones
PollenBinderHelper.simpleCopy(
- personToListLoaded, personToListEditable, !clone);
+ personToListLoaded, personToListEditable, false);
PollAccount personLoaded = personToListLoaded.getPollAccount();
PollAccount personEditable = newInstance(pollAccountDAO);
@@ -274,8 +277,8 @@
}
// -- PreventRule -- //
- for (Choice choice : poll.getChoice()) {
- saveChoice(result, choice);
+ for (PreventRule choice : poll.getPreventRule()) {
+ savePreventRule(result, choice);
}
// -- VotingList -- //
@@ -321,7 +324,6 @@
creatorToUpdate.setEmail(creator.getEmail());
// -- Choices -- //
-
if (!voteStarted) {
pollToUpdate.clearChoice();
@@ -336,11 +338,9 @@
}
// -- VotingLists -- //
-
- // FIXME-fdesbois-2012-04-05 : missing delete-orphan on VotingList, if PollType change, VotingList must be deleted
- // FIXME-fdesbois-2012-04-05 : manage remove
-
if (!voteStarted) {
+
+ pollToUpdate.clearVotingList();
for (VotingList votingList : poll.getVotingList()) {
saveVotingList(pollToUpdate, votingList);
}
@@ -856,6 +856,19 @@
createThumbnail(pollChoiceImage, pollChoiceImageThumb, 100);
}
+ public void addVoteToPoll(Poll poll, Vote vote) {
+
+ String pollId = poll.getTopiaId();
+ String voteId = vote.getTopiaId();
+
+ Poll pollToUpdate = getEntityById(Poll.class, pollId);
+ Vote voteToAdd = getEntityById(Vote.class, voteId);
+
+ pollToUpdate.addVote(voteToAdd);
+
+ commitTransaction("Can't add the vote [" + voteId + "] to the poll [" + pollId + "]");
+ }
+
public PersonToList getNewPersonToList(PollAccount pollAccount) {
PersonToList result = newInstance(getDAO(PersonToList.class));
result.setWeight(1);
@@ -872,50 +885,6 @@
return result;
}
- public void addVoteToPoll(Poll poll, Vote vote) {
-
- String pollId = poll.getTopiaId();
- String voteId = vote.getTopiaId();
-
- Poll pollToUpdate = getEntityById(Poll.class, pollId);
- Vote voteToAdd = getEntityById(Vote.class, voteId);
-
- pollToUpdate.addVote(voteToAdd);
-
- commitTransaction("Can't add the vote [" + voteId + "] to the poll [" + pollId + "]");
-
-
-// TopiaContext transaction = null;
-// try {
-// transaction = rootContext.beginTransaction();
-//
-// pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
-// Poll pollEntity = pollDAO.findByTopiaId(pollId);
-// VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
-// Vote voteEntity = voteDAO.findByTopiaId(voteId);
-//
-// if (log.isDebugEnabled()) {
-// log.debug(pollEntity + " " + voteEntity);
-// }
-//
-// pollEntity.addVote(voteEntity);
-// pollDAO.update(pollEntity);
-//
-// transaction.commitTransaction();
-//
-// if (log.isDebugEnabled()) {
-// log.debug("Entity updated: " + pollId);
-// }
-//
-// return true;
-// } catch (Exception e) {
-// ContextUtil.doCatch(e, transaction);
-// return false;
-// } finally {
-// ContextUtil.doFinally(transaction);
-// }
- }
-
protected void saveVotingList(Poll poll, VotingList votingList) {
VotingListDAO votingListDAO = getDAO(VotingList.class);
@@ -923,54 +892,51 @@
PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
// Prepare the VotingList and add it to the poll
- VotingList votingListLoaded;
+ VotingList result;
if (votingList.getTopiaId() == null) {
- votingListLoaded = create(votingListDAO);
- poll.addVotingList(votingListLoaded);
+ result = create(votingListDAO);
+ poll.addVotingList(result);
} else {
- votingListLoaded = poll.getVotingListByTopiaId(votingList.getTopiaId());
+ result = poll.getVotingListByTopiaId(votingList.getTopiaId());
- // FIXME-fdesbois-2012-04-05 : why the poll association is not keeped ?!?
- votingListLoaded.setPoll(poll);
+ // FIXME-fdesbois-2012-04-05 : why the poll association is not keeped ?!? because of the clear
+ result.setPoll(poll);
}
- votingListLoaded.setName(votingList.getName());
- votingListLoaded.setWeight(votingList.getWeight());
+ result.setName(votingList.getName());
+ result.setWeight(votingList.getWeight());
// Merge PersonToList
+ List<PersonToList> personToListsUpdated = Lists.newArrayList();
for (PersonToList personToList : votingList.getPollAccountPersonToList()) {
+ PollAccount pollAccount = personToList.getPollAccount();
+
PersonToList personToListLoaded;
+ PollAccount pollAccountLoaded;
if (personToList.getTopiaId() == null) {
personToListLoaded = create(personToListDAO);
- votingListLoaded.addPollAccountPersonToList(personToListLoaded);
// The model doesn't have any composition for this relation,
// the link must be set in both objects
- personToListLoaded.setVotingList(votingListLoaded);
+ personToListLoaded.setVotingList(result);
- } else {
- personToListLoaded = votingListLoaded.getPollAccountPersonToListByTopiaId(personToList.getTopiaId());
- }
-
-// personToListLoaded.setHasVoted(personToList.isHasVoted());
- personToListLoaded.setWeight(personToList.getWeight());
-
- PollAccount pollAccount = personToList.getPollAccount();
- PollAccount pollAccountLoaded = personToListLoaded.getPollAccount();
-
- // Create the pollAccount if not exists
- if (pollAccountLoaded == null) {
pollAccountLoaded = create(pollAccountDAO);
pollAccountLoaded.setAccountId(pollAccount.getAccountId());
personToListLoaded.setPollAccount(pollAccountLoaded);
+
+ } else {
+ personToListLoaded = getEntityById(PersonToList.class, personToList.getTopiaId());
+ pollAccountLoaded = personToListLoaded.getPollAccount();
}
+ personToListsUpdated.add(personToListLoaded);
+ personToListLoaded.setWeight(personToList.getWeight());
pollAccountLoaded.setEmail(pollAccount.getEmail());
-// pollAccountLoaded.setUserAccount(pollAccount.getUserAccount());
pollAccountLoaded.setVotingId(pollAccount.getVotingId());
}
+ result.setPollAccountPersonToList(personToListsUpdated);
}
protected void savePreventRule(Poll poll, PreventRule preventRule) {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-06 12:56:20 UTC (rev 3239)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-06 15:46:09 UTC (rev 3240)
@@ -220,6 +220,11 @@
_("pollen.action.createPoll");
}
+ public String getPageTitle() {
+ return isEdit() ? getPoll().getTitle() :
+ _("pollen.title.createPoll");
+ }
+
public boolean isVoteStarted() {
return isEdit() && poll.sizeVote() > 0;
}
@@ -261,15 +266,14 @@
public Function<PersonToList, PersonToList> getPersontoListCreator() {
if (persontoListCreator == null) {
- persontoListCreator = PollenServiceFunctions.newPersonToListCreator(serviceContext);
+ persontoListCreator = PollenServiceFunctions.newPersonToListCreator();
}
return persontoListCreator;
}
public Function<VotingList, VotingList> getVotingListCreator() {
if (votingListCreator == null) {
- votingListCreator = PollenServiceFunctions.newVotingListCreator(serviceContext,
- getPersontoListCreator());
+ votingListCreator = PollenServiceFunctions.newVotingListCreator(getPersontoListCreator());
}
return votingListCreator;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java 2012-04-06 12:56:20 UTC (rev 3239)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java 2012-04-06 15:46:09 UTC (rev 3240)
@@ -104,9 +104,9 @@
public String execute() throws Exception {
Function<PersonToList, PersonToList> persontoListCreator =
- PollenServiceFunctions.newPersonToListCreator(serviceContext);
+ PollenServiceFunctions.newPersonToListCreator();
Function<VotingList, VotingList> votingListCreator =
- PollenServiceFunctions.newVotingListCreator(serviceContext, persontoListCreator);
+ PollenServiceFunctions.newVotingListCreator(persontoListCreator);
// if (StringUtils.isNotEmpty(tokenId)) {
//
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-06 12:56:20 UTC (rev 3239)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-06 15:46:09 UTC (rev 3240)
@@ -311,15 +311,16 @@
if (isEdit()) {
service.updatePoll(poll);
+ addActionMessage(_("pollen.information.poll.updated"));
} else {
service.createPoll(poll);
+ addActionMessage(_("pollen.information.poll.created"));
}
// remove all stuff from session
getPollenSession().clearDynamicData();
- addActionMessage(_("pollen.information.poll.created"));
return SUCCESS;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-06 12:56:20 UTC (rev 3239)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-06 15:46:09 UTC (rev 3240)
@@ -61,7 +61,7 @@
<title><s:text name="pollen.title.createPoll"/></title>
-<h1 class="title${pageLogo}"><s:text name="pollen.title.createPoll"/></h1>
+<h1 class="title${pageLogo}"><s:property value="%{pageTitle}"/></h1>
<s:form method="POST" id="registerForm" namespace="/poll"
enctype="multipart/form-data">
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp 2012-04-06 12:56:20 UTC (rev 3239)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp 2012-04-06 15:46:09 UTC (rev 3240)
@@ -40,7 +40,7 @@
<s:set name="choiceNumber"><s:property value="%{#status.index}"/></s:set>
<s:set name="prefix">textChoice_<s:property value="%{#choiceNumber}"/></s:set>
<div id='choicesTEXT_<s:property value="choiceNumber"/>'>
- <s:hidden key='%{#prefix}.topiaId' value='%{choice.topiaId}' label=''/>
+ <s:hidden key='%{#prefix}.topiaId' value='%{#choice.topiaId}' label=''/>
<div class="fleft choiceName">
<s:label for="%{#prefix}.name" id="choicesTEXT_label_%{#choiceNumber}"
theme="simple" value=''/>
@@ -84,7 +84,7 @@
<s:set name="prefix">dateChoice_<s:property value="%{#choiceNumber}"/></s:set>
<div id='choicesDATE_<s:property value="choiceNumber"/>'>
<s:hidden key='%{#prefix}.topiaId' id='%{#prefix}.topiaId'
- value='%{choice.topiaId}' label='' theme="simple" />
+ value='%{#choice.topiaId}' label='' theme="simple" />
<div class="fleft choiceName">
<s:label for="%{#prefix}.name" id="choicesDATE_label_%{choiceNumber}"
theme="simple" value=''/>
@@ -129,7 +129,7 @@
<s:set name="choiceNumber"><s:property value="%{#status.index}"/></s:set>
<s:set name="prefix">imageChoice_<s:property value="%{#choiceNumber}"/></s:set>
<div id='choicesIMAGE_<s:property value="choiceNumber"/>'>
- <s:hidden key='%{#prefix}.topiaId' value='%{choice.topiaId}' label=''/>
+ <s:hidden key='%{#prefix}.topiaId' value='%{#choice.topiaId}' label=''/>
<div class="fleft choiceName">
<s:label for="%{#prefix}.name" id="choicesIMAGE_label_%{choiceNumber}"
theme="simple" value=''/>
1
0
r3239 - in branches/pollen-1.2.6-struts2: pollen-services/src/main/java/org/chorem/pollen/services pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll
by fdesbois@users.chorem.org 06 Apr '12
by fdesbois@users.chorem.org 06 Apr '12
06 Apr '12
Author: fdesbois
Date: 2012-04-06 14:56:20 +0200 (Fri, 06 Apr 2012)
New Revision: 3239
Url: http://chorem.org/repositories/revision/pollen/3239
Log:
- clean clone flag
- use getPollEditable for load and save poll
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-04-06 12:56:13 UTC (rev 3238)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-04-06 12:56:20 UTC (rev 3239)
@@ -68,49 +68,36 @@
}
}
- public static TextChoiceCreator newTextChoiceCreator(boolean clone) {
- return new TextChoiceCreator(clone);
+ public static TextChoiceCreator newTextChoiceCreator() {
+ return new TextChoiceCreator();
}
- public static ImageChoiceCreator newImageChoiceCreator(boolean clone) {
- return new ImageChoiceCreator(clone);
+ public static ImageChoiceCreator newImageChoiceCreator() {
+ return new ImageChoiceCreator();
}
- public static DateChoiceCreator newDateChoiceCreator(boolean clone) {
- return new DateChoiceCreator(clone);
+ public static DateChoiceCreator newDateChoiceCreator() {
+ return new DateChoiceCreator();
}
public static Function<VotingList, VotingList> newVotingListCreator(
- boolean clone,
PollenServiceContext serviceContext,
Function<PersonToList, PersonToList> persontoListCreator) {
- return new VotingListCreator(clone, serviceContext, persontoListCreator);
+ return new VotingListCreator(serviceContext, persontoListCreator);
}
public static Function<PersonToList, PersonToList> newPersonToListCreator(
- boolean clone,
PollenServiceContext serviceContext) {
- return new PersonToListCreator(clone, serviceContext);
+ return new PersonToListCreator(serviceContext);
}
public static class TextChoiceCreator implements Function<Choice, Choice> {
-
- protected final boolean clone;
-
- protected TextChoiceCreator(boolean clone) {
- this.clone = clone;
- }
-
@Override
public Choice apply(Choice input) {
Choice result = new ChoiceImpl();
if (input != null) {
- if (clone) {
- // do not copy topia id
- } else {
- result.setTopiaId(input.getTopiaId());
- }
+ result.setTopiaId(input.getTopiaId());
result.setName(input.getName());
result.setDescription(input.getDescription());
}
@@ -120,22 +107,11 @@
public static class ImageChoiceCreator implements Function<Choice, Choice> {
- protected final boolean clone;
-
- protected ImageChoiceCreator(boolean clone) {
- this.clone = clone;
- }
-
-
@Override
public Choice apply(Choice input) {
PollImageChoice result = new PollImageChoice();
if (input != null) {
- if (clone) {
- // do not copy topia id
- } else {
- result.setTopiaId(input.getTopiaId());
- }
+ result.setTopiaId(input.getTopiaId());
result.setName(input.getName());
result.setDescription(input.getDescription());
result.setLocation(input.getName());
@@ -146,22 +122,11 @@
public static class DateChoiceCreator implements Function<Choice, Choice> {
- protected final boolean clone;
-
- protected DateChoiceCreator(boolean clone) {
- this.clone = clone;
- }
-
@Override
public Choice apply(Choice input) {
PollDateChoice result = new PollDateChoice();
if (input != null) {
- if (clone) {
- // do not copy topia id
- } else {
- result.setTopiaId(input.getTopiaId());
- }
-
+ result.setTopiaId(input.getTopiaId());
result.setName(input.getName());
result.setDescription(input.getDescription());
result.setDate(new Date(Long.valueOf(input.getName())));
@@ -172,16 +137,12 @@
public static class VotingListCreator implements Function<VotingList, VotingList> {
- protected final boolean clone;
-
protected final PollenServiceContext serviceContext;
protected final Function<PersonToList, PersonToList> persontoListCreator;
- protected VotingListCreator(boolean clone,
- PollenServiceContext serviceContext,
+ protected VotingListCreator(PollenServiceContext serviceContext,
Function<PersonToList, PersonToList> persontoListCreator) {
- this.clone = clone;
this.serviceContext = serviceContext;
this.persontoListCreator = persontoListCreator;
}
@@ -197,11 +158,7 @@
result.setWeight(1);
} else {
- if (clone) {
- // do not copy topia id
- } else {
- result.setTopiaId(input.getTopiaId());
- }
+ result.setTopiaId(input.getTopiaId());
result.setName(input.getName());
result.setWeight(input.getWeight());
@@ -219,12 +176,9 @@
public static class PersonToListCreator implements Function<PersonToList, PersonToList> {
- protected final boolean clone;
-
protected final PollenServiceContext serviceContext;
- protected PersonToListCreator(boolean clone, PollenServiceContext serviceContext) {
- this.clone = clone;
+ protected PersonToListCreator(PollenServiceContext serviceContext) {
this.serviceContext = serviceContext;
}
@@ -232,25 +186,13 @@
public PersonToList apply(PersonToList input) {
PersonToList result = new PersonToListImpl();
if (input != null) {
- if (clone) {
- // do not copy topia id
- } else {
- result.setTopiaId(input.getTopiaId());
- }
+ result.setTopiaId(input.getTopiaId());
result.setWeight(input.getWeight());
PollAccount pollAccount = input.getPollAccount();
if (pollAccount != null) {
PollAccount pollAccount2 = new PollAccountImpl();
- String accountId;
- if (clone) {
- // do not copy topia id
- // generate a new accountId
- accountId = serviceContext.createPollenUrlId();
- } else {
- pollAccount2.setTopiaId(pollAccount.getTopiaId());
- accountId = pollAccount.getAccountId();
- }
- pollAccount2.setAccountId(accountId);
+ pollAccount2.setTopiaId(pollAccount.getTopiaId());
+ pollAccount2.setAccountId(pollAccount.getAccountId());
pollAccount2.setVotingId(pollAccount.getVotingId());
result.setPollAccount(pollAccount2);
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-06 12:56:13 UTC (rev 3238)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-06 12:56:20 UTC (rev 3239)
@@ -76,10 +76,10 @@
private static final Log log = LogFactory.getLog(PollService.class);
/**
- * Build a new Poll instance with given {@code user} as administrator
+ * Build a new Poll instance with given {@code user} as creator
*
- * @param user Build a new Poll instance with given {@code user} as administrator
- * @return Build a new Poll instance with given {@code user} as administrator
+ * @param user Build a new Poll instance with given {@code user} as creator
+ * @return Build a new Poll instance with given {@code user} as creator
*/
public Poll getNewPoll(UserAccount user) {
@@ -93,11 +93,10 @@
result.setVoteCountingType(configuration.getDefaultVoteCountingType());
result.setPollType(configuration.getDefaultPollType());
- // Initialize creator as an admin for the poll
+ // Initialize creator of the poll
PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
PollAccount creator = newInstance(pollAccountDAO);
creator.setAccountId(serviceContext.createPollenUrlId());
-// creator.setAdmin(true);
if (user != null) {
@@ -121,12 +120,13 @@
* and ensure business ids (accountUid, pollUid) with new values. If {@code userId}
* matches an existing {@link UserAccount}, the resulting poll creator will
* be attached to it.
- *
+ *
* @param pollUid Uid of the poll to edit, if not defined, a new poll is instanciated
* @param userAccount User account to attach to the creator
* @param clone Flag to copy or not ids in case of poll cloning
- * @return the Poll ready for edition (no longer linked to the topia context)
+ * @return the Poll ready for edition (no longer linked to the topia context)
* @see #getNewPoll(UserAccount)
+ * @see #getNewPollCopy(Poll, UserAccount, boolean)
*/
public Poll getPollEditable(String pollUid, UserAccount userAccount, boolean clone) {
@@ -136,81 +136,96 @@
} else {
- Poll pollLoaded = getPollByPollId(pollUid);
-
- PollDAO pollDAO = getDAO(Poll.class);
- result = newInstance(pollDAO);
+ Poll poll = getPollByPollId(pollUid);
- PollenBinderHelper.simpleCopy(pollLoaded, result, !clone);
- if (clone) {
- result.setPollId(serviceContext.createPollenUrlId());
+ if (poll == null) {
+ result = getNewPoll(userAccount);
+
+ } else {
+ result = getNewPollCopy(poll, userAccount, clone);
}
-
- // -- Creator -- //
- PollAccount creatorLoaded = pollLoaded.getCreator();
- PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
- PollAccount creatorEditable = newInstance(pollAccountDAO);
- result.setCreator(creatorEditable);
+ }
+ return result;
+ }
+
+ protected Poll getNewPollCopy(Poll source, UserAccount userAccount, boolean clone) {
+
+ Preconditions.checkNotNull(source);
+
+ PollDAO pollDAO = getDAO(Poll.class);
+ Poll result = newInstance(pollDAO);
+ PollenBinderHelper.simpleCopy(source, result, !clone);
+ if (clone) {
+ result.setPollId(serviceContext.createPollenUrlId());
+ }
+
+ // -- Creator -- //
+ PollAccount creatorLoaded = source.getCreator();
+ PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
+ PollAccount creatorEditable = newInstance(pollAccountDAO);
+ result.setCreator(creatorEditable);
+
+ PollenBinderHelper.simpleCopy(
+ creatorLoaded, creatorEditable, !clone);
+ if (clone) {
+ creatorEditable.setAccountId(serviceContext.createPollenUrlId());
+ }
+
+ if (creatorLoaded.getUserAccount() != null) {
+ creatorEditable.setUserAccount(creatorLoaded.getUserAccount());
+
+ // Set userAccount from arguments
+ } else if (userAccount != null) {
+ creatorEditable.setUserAccount(userAccount);
+ }
+
+ // -- Choice -- //
+ ChoiceDAO choiceDAO = getDAO(Choice.class);
+ for (Choice choiceLoaded : source.getChoice()) {
+ Choice choiceEditable = newInstance(choiceDAO);
+ result.addChoice(choiceEditable);
+ // Do not keep choices topiaId, to simplify the update will delete old choices and create new ones
PollenBinderHelper.simpleCopy(
- creatorLoaded, creatorEditable, !clone);
- if (clone) {
- creatorEditable.setAccountId(serviceContext.createPollenUrlId());
- }
-
- if (creatorLoaded.getUserAccount() != null) {
- creatorEditable.setUserAccount(creatorLoaded.getUserAccount());
+ choiceLoaded, choiceEditable, false);
+ }
- // Set userAccount from arguments
- } else if (userAccount != null) {
- creatorEditable.setUserAccount(userAccount);
- }
-
- // -- Choice -- //
- ChoiceDAO choiceDAO = getDAO(Choice.class);
- for (Choice choiceLoaded : pollLoaded.getChoice()) {
- Choice choiceEditable = newInstance(choiceDAO);
- result.addChoice(choiceEditable);
+ // -- VotingList -- //
+ VotingListDAO votingListDAO = getDAO(VotingList.class);
+ PersonToListDAO personToListDAO = getDAO(PersonToList.class);
+ for (VotingList votingListLoaded : source.getVotingList()) {
+ VotingList votingListEditable = newInstance(votingListDAO);
+ result.addVotingList(votingListEditable);
+ PollenBinderHelper.simpleCopy(
+ votingListLoaded, votingListEditable, !clone);
+
+ for (PersonToList personToListLoaded : votingListLoaded.getPollAccountPersonToList()) {
+ PersonToList personToListEditable = newInstance(personToListDAO);
+ votingListEditable.addPollAccountPersonToList(personToListEditable);
PollenBinderHelper.simpleCopy(
- choiceLoaded, choiceEditable, !clone);
- }
+ personToListLoaded, personToListEditable, !clone);
- // -- VotingList -- //
- VotingListDAO votingListDAO = getDAO(VotingList.class);
- PersonToListDAO personToListDAO = getDAO(PersonToList.class);
- for (VotingList votingListLoaded : pollLoaded.getVotingList()) {
- VotingList votingListEditable = newInstance(votingListDAO);
- result.addVotingList(votingListLoaded);
+ PollAccount personLoaded = personToListLoaded.getPollAccount();
+ PollAccount personEditable = newInstance(pollAccountDAO);
+ personToListEditable.setPollAccount(personEditable);
+ // copy the person, keeping topiaId is useless because we have the link with PersonToList
PollenBinderHelper.simpleCopy(
- votingListLoaded, votingListEditable, !clone);
-
- for (PersonToList personToListLoaded : votingListLoaded.getPollAccountPersonToList()) {
- PersonToList personToListEditable = newInstance(personToListDAO);
- votingListEditable.addPollAccountPersonToList(personToListEditable);
- PollenBinderHelper.simpleCopy(
- personToListLoaded, personToListEditable, !clone);
-
- PollAccount personLoaded = personToListLoaded.getPollAccount();
- PollAccount personEditable = newInstance(pollAccountDAO);
- personToListEditable.setPollAccount(personEditable);
- // copy the person, keeping topiaId is useless because we have the link with PersonToList
- PollenBinderHelper.simpleCopy(
- personLoaded, personEditable, false);
- if (clone) {
- personEditable.setAccountId(serviceContext.createPollenUrlId());
- }
+ personLoaded, personEditable, false);
+ if (clone) {
+ personEditable.setAccountId(serviceContext.createPollenUrlId());
}
}
-
- // -- PreventRule -- //
- PreventRuleDAO preventRuleDAO = getDAO(PreventRule.class);
- for (PreventRule preventRuleLoaded : pollLoaded.getPreventRule()) {
- PreventRule preventRuleEditable = newInstance(preventRuleDAO);
- PollenBinderHelper.simpleCopy(
- preventRuleLoaded, preventRuleEditable, !clone);
- result.addPreventRule(preventRuleEditable);
- }
}
+
+ // -- PreventRule -- //
+ PreventRuleDAO preventRuleDAO = getDAO(PreventRule.class);
+ for (PreventRule preventRuleLoaded : source.getPreventRule()) {
+ PreventRule preventRuleEditable = newInstance(preventRuleDAO);
+ PollenBinderHelper.simpleCopy(
+ preventRuleLoaded, preventRuleEditable, !clone);
+ result.addPreventRule(preventRuleEditable);
+ }
+
return result;
}
@@ -283,15 +298,17 @@
return result;
}
-
+
public void updatePoll(Poll poll) throws PollNotFoundException {
-
+
Poll pollToUpdate = getEntityById(Poll.class, poll.getTopiaId());
if (pollToUpdate == null) {
throw new PollNotFoundException();
}
+ boolean voteStarted = pollToUpdate.sizeVote() > 0;
+
PollAccount creatorToUpdate = pollToUpdate.getCreator();
// FIXME-fdesbois-2012-04-05 : improve binder to avoid creator copy
@@ -305,10 +322,12 @@
// -- Choices -- //
- // FIXME-fdesbois-2012-04-05 : manage remove
+ if (!voteStarted) {
- for (Choice choice : poll.getChoice()) {
- saveChoice(pollToUpdate, choice);
+ pollToUpdate.clearChoice();
+ for (Choice choice : poll.getChoice()) {
+ saveChoice(pollToUpdate, choice);
+ }
}
// -- PreventRules -- //
@@ -319,9 +338,12 @@
// -- VotingLists -- //
// FIXME-fdesbois-2012-04-05 : missing delete-orphan on VotingList, if PollType change, VotingList must be deleted
+ // FIXME-fdesbois-2012-04-05 : manage remove
- for (VotingList votingList : poll.getVotingList()) {
- saveVotingList(pollToUpdate, votingList);
+ if (!voteStarted) {
+ for (VotingList votingList : poll.getVotingList()) {
+ saveVotingList(pollToUpdate, votingList);
+ }
}
commitTransaction("Could not update poll [" + poll.getTopiaId() + "]");
@@ -511,14 +533,14 @@
));
}
}
-
- if (result == null) {
+
+ if (result == null) {
result = getNewPollAccount(userAccount);
}
}
return result;
}
-
+
protected PollAccount copyPollAccount(PollAccount source) {
PollAccountDAO dao = getDAO(PollAccount.class);
PollAccount result = newInstance(dao);
@@ -545,7 +567,7 @@
if (result == null) {
throw new PollAccountNotFound();
}
-
+
return result;
} catch (TopiaException e) {
throw new PollenTechnicalException("Could not botain account with this id", e);
@@ -619,19 +641,19 @@
commitTransaction("Could not close poll " + poll.getTitle());
}
-
+
public Choice getNewChoice(ChoiceType choiceType) {
Choice result;
switch (choiceType) {
-
+
case DATE:
result = new PollDateChoice();
break;
-
+
case IMAGE:
result = new PollImageChoice();
break;
-
+
case TEXT:
default:
ChoiceDAO dao = getDAO(Choice.class);
@@ -639,25 +661,25 @@
}
return result;
}
-
+
public void createChoice(String pollId, Choice choice) throws PollNotFoundException {
-
+
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(choice);
-
+
Poll poll = getPollByPollId(pollId);
-
+
if (poll == null) {
throw new PollNotFoundException();
}
-
+
saveChoice(poll, choice);
-
+
commitTransaction("Can't create new choice [" + poll.getChoiceType() + "] for poll '" + pollId + "'");
}
-
+
protected void saveChoice(Poll poll, Choice choice) {
-
+
ChoiceType choiceType = poll.getChoiceType();
ChoiceDAO dao = getDAO(Choice.class);
Choice choiceLoaded;
@@ -695,7 +717,7 @@
choiceLoaded.setDescription(choice.getDescription());
choiceLoaded.setValidate(choice.isValidate());
choiceLoaded.setName(choice.getName());
- }
+ }
}
public void deleteChoice(String pollId, String choiceId)
@@ -741,7 +763,7 @@
if (poll == null) {
throw new PollNotFoundException();
}
-
+
PollAccountDAO dao = getDAO(PollAccount.class);
if (poll.getPollType() != PollType.FREE) {
@@ -772,9 +794,9 @@
}
} catch (TopiaException e) {
throw new PollenTechnicalException(
- "Could not check pollAccount existence from poll '" +
+ "Could not check pollAccount existence from poll '" +
pollId + "' and account '" + accountId + "'", e);
- }
+ }
}
}
@@ -893,9 +915,9 @@
// ContextUtil.doFinally(transaction);
// }
}
-
+
protected void saveVotingList(Poll poll, VotingList votingList) {
-
+
VotingListDAO votingListDAO = getDAO(VotingList.class);
PersonToListDAO personToListDAO = getDAO(PersonToList.class);
PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
@@ -905,11 +927,11 @@
if (votingList.getTopiaId() == null) {
votingListLoaded = create(votingListDAO);
poll.addVotingList(votingListLoaded);
-
+
} else {
votingListLoaded = poll.getVotingListByTopiaId(votingList.getTopiaId());
-
- // It's seems stupid, but it doesn't work without it
+
+ // FIXME-fdesbois-2012-04-05 : why the poll association is not keeped ?!?
votingListLoaded.setPoll(poll);
}
@@ -924,7 +946,8 @@
personToListLoaded = create(personToListDAO);
votingListLoaded.addPollAccountPersonToList(personToListLoaded);
- // The model doesn't have any composition for this relation, the link must be set in both objects
+ // The model doesn't have any composition for this relation,
+ // the link must be set in both objects
personToListLoaded.setVotingList(votingListLoaded);
} else {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-06 12:56:13 UTC (rev 3238)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-06 12:56:20 UTC (rev 3239)
@@ -238,10 +238,6 @@
return 1;
}
- public boolean isClone() {
- return false;
- }
-
protected boolean isEdit() {
return StringUtils.isNotEmpty(getPoll().getTopiaId());
}
@@ -265,15 +261,14 @@
public Function<PersonToList, PersonToList> getPersontoListCreator() {
if (persontoListCreator == null) {
- persontoListCreator = PollenServiceFunctions.newPersonToListCreator(isClone(), serviceContext);
+ persontoListCreator = PollenServiceFunctions.newPersonToListCreator(serviceContext);
}
return persontoListCreator;
}
public Function<VotingList, VotingList> getVotingListCreator() {
if (votingListCreator == null) {
- votingListCreator = PollenServiceFunctions.newVotingListCreator(isClone(),
- serviceContext,
+ votingListCreator = PollenServiceFunctions.newVotingListCreator(serviceContext,
getPersontoListCreator());
}
return votingListCreator;
@@ -281,21 +276,21 @@
public Function<Choice, Choice> getTextChoiceCreator() {
if (textChoiceCreator == null) {
- textChoiceCreator = PollenServiceFunctions.newTextChoiceCreator(isClone());
+ textChoiceCreator = PollenServiceFunctions.newTextChoiceCreator();
}
return textChoiceCreator;
}
public Function<Choice, Choice> getDateChoiceCreator() {
if (dateChoiceCreator == null) {
- dateChoiceCreator = PollenServiceFunctions.newDateChoiceCreator(isClone());
+ dateChoiceCreator = PollenServiceFunctions.newDateChoiceCreator();
}
return dateChoiceCreator;
}
public Function<Choice, Choice> getImageChoiceCreator() {
if (imageChoiceCreator == null) {
- imageChoiceCreator = PollenServiceFunctions.newImageChoiceCreator(isClone());
+ imageChoiceCreator = PollenServiceFunctions.newImageChoiceCreator();
}
return imageChoiceCreator;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java 2012-04-06 12:56:13 UTC (rev 3238)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java 2012-04-06 12:56:20 UTC (rev 3239)
@@ -104,11 +104,9 @@
public String execute() throws Exception {
Function<PersonToList, PersonToList> persontoListCreator =
- PollenServiceFunctions.newPersonToListCreator(
- false, serviceContext);
+ PollenServiceFunctions.newPersonToListCreator(serviceContext);
Function<VotingList, VotingList> votingListCreator =
- PollenServiceFunctions.newVotingListCreator(
- false, serviceContext, persontoListCreator);
+ PollenServiceFunctions.newVotingListCreator(serviceContext, persontoListCreator);
// if (StringUtils.isNotEmpty(tokenId)) {
//
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-06 12:56:13 UTC (rev 3238)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-06 12:56:20 UTC (rev 3239)
@@ -25,7 +25,6 @@
import org.chorem.pollen.bean.PollUri;
import org.chorem.pollen.business.persistence.Choice;
-import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.VotingList;
@@ -52,11 +51,6 @@
this.pollUri = pollUri;
}
- @Override
- public boolean isClone() {
- return clone;
- }
-
public void setClone(boolean clone) {
this.clone = clone;
}
@@ -66,31 +60,9 @@
prepareFormPage();
- if (pollUri == null) {
+ UserAccount userAccount = getPollenUserAccount();
+ poll = getPollService().getPollEditable(pollUri.getPollId(), userAccount, clone);
- // create a new poll
-
- UserAccount userAccount = getPollenUserAccount();
- poll = getPollService().getNewPoll(userAccount);
- } else {
-
- // update or clone an existing poll
-
- poll = getPollService().getPollByPollId(pollUri.getPollId());
-
- if (clone) {
-
- poll.setTopiaId(null);
- poll.setPollId(serviceContext.createPollenUrlId());
-
- // Reset creator but keep userAccount link
- PollAccount creator = poll.getCreator();
- creator.setTopiaId(null);
- creator.setAccountId(serviceContext.createPollenUrlId());
- }
- }
-
-
List<Choice> pollChoices = poll.getChoice();
List<VotingList> pollVotingLists = poll.getVotingList();
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-06 12:56:13 UTC (rev 3238)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-06 12:56:20 UTC (rev 3239)
@@ -41,7 +41,6 @@
import org.chorem.pollen.business.persistence.ChoiceImpl;
import org.chorem.pollen.business.persistence.PersonToList;
import org.chorem.pollen.business.persistence.PersonToListImpl;
-import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.PollAccountImpl;
import org.chorem.pollen.business.persistence.PreventRule;
@@ -52,7 +51,6 @@
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.services.impl.PollService;
import org.chorem.pollen.services.impl.PreventRuleService;
-import org.chorem.pollen.services.impl.UserService;
import org.chorem.pollen.ui.actions.FileUploadAware;
import org.nuiton.util.StringUtil;
@@ -89,8 +87,6 @@
private static final Pattern IMAGE_CHOICE_NAME_PATTERN =
Pattern.compile("imageChoice_(\\d+)\\.name");
- private String userId;
-
/** Uploaded images (for choice type poll). */
private List<File> imageChoice;
@@ -106,7 +102,6 @@
/** Flag when there is some errors on the options panel. */
private boolean optionsError;
-
/**
* All the parameters send by request used to build back choices of the
* poll.
@@ -125,24 +120,25 @@
*/
private Map<Integer, VotingList> votingLists;
- public void setUserId(String userId) {
- this.userId = userId;
- }
-
@Override
public void prepare() throws Exception {
prepareFormPage();
- String pollId = getNonEmptyParameterValue("poll.topiaId");
+ String pollUid = getNonEmptyParameterValue("poll.pollId");
- if (pollId != null) {
- poll = getPollService().getEntityById(Poll.class, pollId);
+ // Retrieve userAccount to attach to the poll
+ UserAccount userAccount = getPollenUserAccount();
+ if (userAccount == null) {
- } else {
- UserAccount userAccount = getPollenUserAccount();
- poll = getPollService().getNewPoll(userAccount);
+ // from parameter userId if defined during update loading
+ String userId = getNonEmptyParameterValue("userId");
+ if (userId != null) {
+ userAccount = getPollService().getEntityById(UserAccount.class, userId);
+ }
}
+
+ poll = getPollService().getPollEditable(pollUid, userAccount, false);
// Retrieve choiceType from parameters, the poll object will be updated after prepare
String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType");
@@ -192,11 +188,11 @@
public String input() {
Collection<Choice> pollChoices = choices.values();
- Collection<VotingList> pollVotinLists = votingLists.values();
+ Collection<VotingList> pollVotingLists = votingLists.values();
loadChoicesAndvotingLists(poll,
pollChoices,
- pollVotinLists,
+ pollVotingLists,
true);
return INPUT;
}
@@ -275,16 +271,6 @@
poll.clearPreventRule();
poll.clearVotingList();
- // Load userAccount from the form
- if (!isCreatorUserAccountDefined() && StringUtils.isNotBlank(userId)) {
-
- UserService userService = newService(UserService.class);
- UserAccount userAccount = userService.getEntityById(
- UserAccount.class, userId);
-
- poll.getCreator().setUserAccount(userAccount);
- }
-
Map<Integer, Choice> orderedChoices = choices;
for (Integer index : orderedChoices.keySet()) {
1
0
r3238 - in branches/pollen-1.2.6-struts2: pollen-persistence/src/main/java/org/chorem/pollen/business/persistence pollen-services/src/main/java/org/chorem/pollen/services/impl
by fdesbois@users.chorem.org 06 Apr '12
by fdesbois@users.chorem.org 06 Apr '12
06 Apr '12
Author: fdesbois
Date: 2012-04-06 14:56:13 +0200 (Fri, 06 Apr 2012)
New Revision: 3238
Url: http://chorem.org/repositories/revision/pollen/3238
Log:
- create empty list instance if collections from entities are null
- add method getPollEditable for update
Added:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VotingListImpl.java
Modified:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java 2012-04-06 07:51:35 UTC (rev 3237)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java 2012-04-06 12:56:13 UTC (rev 3238)
@@ -24,13 +24,64 @@
package org.chorem.pollen.business.persistence;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
import java.util.Date;
+import java.util.List;
public class PollImpl extends PollAbstract {
private static final long serialVersionUID = 1L;
+ @Override
+ public List<Vote> getVote() {
+ if (vote == null) {
+ vote = Lists.newArrayList();
+ }
+ return vote;
+ }
+
+ @Override
+ public List<Choice> getChoice() {
+ if (choice == null) {
+ choice = Lists.newArrayList();
+ }
+ return choice;
+ }
+
+ @Override
+ public List<Result> getResult() {
+ if (result == null) {
+ result = Lists.newArrayList();
+ }
+ return result;
+ }
+
+ @Override
+ public List<Comment> getComment() {
+ if (comment == null) {
+ comment = Lists.newArrayList();
+ }
+ return comment;
+ }
+
+ @Override
+ public List<PreventRule> getPreventRule() {
+ if (preventRule == null) {
+ preventRule = Lists.newArrayList();
+ }
+ return preventRule;
+ }
+
+ @Override
+ public List<VotingList> getVotingList() {
+ if (votingList == null) {
+ votingList = Lists.newArrayList();
+ }
+ return votingList;
+ }
+
+ @Override
public Vote getVoteByPollAccount(PollAccount account) {
Preconditions.checkNotNull(account);
Vote resultVote = null;
@@ -88,5 +139,15 @@
public boolean isAddChoiceFinished(Date currentDate) {
return !choiceAddAllowed || (endChoiceDate != null && endChoiceDate.after(currentDate));
}
+
+ public PreventRule getPreventRuleByScope(String scope) {
+ Preconditions.checkNotNull(scope);
+ for (PreventRule value : getPreventRule()) {
+ if (scope.equals(value.getScope())) {
+ return value;
+ }
+ }
+ return null;
+ }
} //PollImpl
Added: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VotingListImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VotingListImpl.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VotingListImpl.java 2012-04-06 12:56:13 UTC (rev 3238)
@@ -0,0 +1,23 @@
+package org.chorem.pollen.business.persistence;
+
+import com.google.common.collect.Lists;
+
+import java.util.List;
+
+/**
+ * Created: 05/04/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ */
+public class VotingListImpl extends VotingListAbstract {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public List<PersonToList> getPollAccountPersonToList() {
+ if (pollAccountPersonToList == null) {
+ pollAccountPersonToList = Lists.newArrayList();
+ }
+ return pollAccountPersonToList;
+ }
+}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-06 07:51:35 UTC (rev 3237)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-06 12:56:13 UTC (rev 3238)
@@ -114,6 +114,106 @@
return result;
}
+ /**
+ * Retrieve a Poll for edition. It is loaded from database if {@code pollUid}
+ * is defined, otherwise a new instance is returned. The {@code clone}
+ * parameter will return the {@code poll} without any technical properties (topiaId)
+ * and ensure business ids (accountUid, pollUid) with new values. If {@code userId}
+ * matches an existing {@link UserAccount}, the resulting poll creator will
+ * be attached to it.
+ *
+ * @param pollUid Uid of the poll to edit, if not defined, a new poll is instanciated
+ * @param userAccount User account to attach to the creator
+ * @param clone Flag to copy or not ids in case of poll cloning
+ * @return the Poll ready for edition (no longer linked to the topia context)
+ * @see #getNewPoll(UserAccount)
+ */
+ public Poll getPollEditable(String pollUid, UserAccount userAccount, boolean clone) {
+
+ Poll result;
+ if (pollUid == null) {
+ result = getNewPoll(userAccount);
+
+ } else {
+
+ Poll pollLoaded = getPollByPollId(pollUid);
+
+ PollDAO pollDAO = getDAO(Poll.class);
+ result = newInstance(pollDAO);
+
+ PollenBinderHelper.simpleCopy(pollLoaded, result, !clone);
+ if (clone) {
+ result.setPollId(serviceContext.createPollenUrlId());
+ }
+
+ // -- Creator -- //
+ PollAccount creatorLoaded = pollLoaded.getCreator();
+ PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
+ PollAccount creatorEditable = newInstance(pollAccountDAO);
+ result.setCreator(creatorEditable);
+
+ PollenBinderHelper.simpleCopy(
+ creatorLoaded, creatorEditable, !clone);
+ if (clone) {
+ creatorEditable.setAccountId(serviceContext.createPollenUrlId());
+ }
+
+ if (creatorLoaded.getUserAccount() != null) {
+ creatorEditable.setUserAccount(creatorLoaded.getUserAccount());
+
+ // Set userAccount from arguments
+ } else if (userAccount != null) {
+ creatorEditable.setUserAccount(userAccount);
+ }
+
+ // -- Choice -- //
+ ChoiceDAO choiceDAO = getDAO(Choice.class);
+ for (Choice choiceLoaded : pollLoaded.getChoice()) {
+ Choice choiceEditable = newInstance(choiceDAO);
+ result.addChoice(choiceEditable);
+ PollenBinderHelper.simpleCopy(
+ choiceLoaded, choiceEditable, !clone);
+ }
+
+ // -- VotingList -- //
+ VotingListDAO votingListDAO = getDAO(VotingList.class);
+ PersonToListDAO personToListDAO = getDAO(PersonToList.class);
+ for (VotingList votingListLoaded : pollLoaded.getVotingList()) {
+ VotingList votingListEditable = newInstance(votingListDAO);
+ result.addVotingList(votingListLoaded);
+ PollenBinderHelper.simpleCopy(
+ votingListLoaded, votingListEditable, !clone);
+
+ for (PersonToList personToListLoaded : votingListLoaded.getPollAccountPersonToList()) {
+ PersonToList personToListEditable = newInstance(personToListDAO);
+ votingListEditable.addPollAccountPersonToList(personToListEditable);
+ PollenBinderHelper.simpleCopy(
+ personToListLoaded, personToListEditable, !clone);
+
+ PollAccount personLoaded = personToListLoaded.getPollAccount();
+ PollAccount personEditable = newInstance(pollAccountDAO);
+ personToListEditable.setPollAccount(personEditable);
+ // copy the person, keeping topiaId is useless because we have the link with PersonToList
+ PollenBinderHelper.simpleCopy(
+ personLoaded, personEditable, false);
+ if (clone) {
+ personEditable.setAccountId(serviceContext.createPollenUrlId());
+ }
+ }
+ }
+
+ // -- PreventRule -- //
+ PreventRuleDAO preventRuleDAO = getDAO(PreventRule.class);
+ for (PreventRule preventRuleLoaded : pollLoaded.getPreventRule()) {
+ PreventRule preventRuleEditable = newInstance(preventRuleDAO);
+ PollenBinderHelper.simpleCopy(
+ preventRuleLoaded, preventRuleEditable, !clone);
+ result.addPreventRule(preventRuleEditable);
+ }
+ }
+ return result;
+ }
+
public Poll createPoll(Poll poll) {
PollDAO pollDAO = getDAO(Poll.class);
@@ -153,71 +253,19 @@
result.setCreator(creatorCreated);
- if (!poll.isPreventRuleEmpty()) {
-
- // create prevent rules
-
- PreventRuleDAO preventRuleDAO = getDAO(PreventRule.class);
- for (PreventRule preventRule : poll.getPreventRule()) {
- PreventRule preventRuleCreated = create(preventRuleDAO);
- preventRuleCreated.setActive(preventRule.isActive());
- preventRuleCreated.setMethod(preventRule.getMethod());
- preventRuleCreated.setOneTime(preventRule.isOneTime());
- preventRuleCreated.setRepeated(preventRule.isRepeated());
- preventRuleCreated.setScope(preventRule.getScope());
- preventRuleCreated.setSensibility(preventRule.getSensibility());
- result.addPreventRule(preventRuleCreated);
- }
+ // -- Choice -- //
+ for (Choice choice : poll.getChoice()) {
+ saveChoice(result, choice);
}
- if (!poll.isVotingListEmpty()) {
-
- // create voting list
-
- VotingListDAO votingListDAO = getDAO(VotingList.class);
- PersonToListDAO personToListDAO = getDAO(PersonToList.class);
-
- for (VotingList votingList : poll.getVotingList()) {
- VotingList votingListCreated = create(votingListDAO);
-
- votingListCreated.setName(votingList.getName());
- votingListCreated.setWeight(votingList.getWeight());
-
- if (!votingList.isPollAccountPersonToListEmpty()) {
-
- // create poll account of the voting list
-
- for (PersonToList personToList : votingList.getPollAccountPersonToList()) {
-
- PersonToList personToListCreated = create(personToListDAO);
- personToListCreated.setHasVoted(personToList.isHasVoted());
- personToListCreated.setWeight(personToList.getWeight());
-
- PollAccount pollAccount = personToList.getPollAccount();
- PollAccount pollAccountCreated = create(pollAccountDAO);
- pollAccountCreated.setAccountId(pollAccount.getAccountId());
- pollAccountCreated.setEmail(pollAccount.getEmail());
- pollAccountCreated.setUserAccount(pollAccount.getUserAccount());
- pollAccountCreated.setVotingId(pollAccount.getVotingId());
-
- personToListCreated.setPollAccount(pollAccountCreated);
-
- // The model doesn't have any composition for this relation, the link must be set in both objects
- personToListCreated.setVotingList(votingListCreated);
- votingListCreated.addPollAccountPersonToList(personToListCreated);
- }
- }
- result.addVotingList(votingListCreated);
- }
+ // -- PreventRule -- //
+ for (Choice choice : poll.getChoice()) {
+ saveChoice(result, choice);
}
- if (!poll.isChoiceEmpty()) {
-
- // create choices
- for (Choice choice : poll.getChoice()) {
-
- addChoice(result, choice);
- }
+ // -- VotingList -- //
+ for (VotingList votingList : poll.getVotingList()) {
+ saveVotingList(result, votingList);
}
commitTransaction("Could not create poll " + poll.getTitle());
@@ -238,67 +286,45 @@
public void updatePoll(Poll poll) throws PollNotFoundException {
-// Poll result;
-// try {
-//
-// PollDAO dao = getDAO(Poll.class);
-//
-// if (!dao.existByTopiaId(poll.getTopiaId())) {
-// throw new PollNotFoundException();
-// }
-//
-// result = dao.update(poll);
-//
-// } catch (TopiaException e) {
-// throw new PollenTechnicalException("Can't update poll [" + poll.getTopiaId() + "]", e);
-// }
-// return result;
-
Poll pollToUpdate = getEntityById(Poll.class, poll.getTopiaId());
if (pollToUpdate == null) {
throw new PollNotFoundException();
}
- PollenBinderHelper.copy("", poll, pollToUpdate, false);
+ PollAccount creatorToUpdate = pollToUpdate.getCreator();
+ // FIXME-fdesbois-2012-04-05 : improve binder to avoid creator copy
+ PollenBinderHelper.simpleCopy(poll, pollToUpdate, false);
+
// -- Creator -- //
PollAccount creator = poll.getCreator();
- PollAccount creatorToUpdate = pollToUpdate.getCreator();
creatorToUpdate.setUserAccount(creator.getUserAccount());
creatorToUpdate.setVotingId(creator.getVotingId());
creatorToUpdate.setEmail(creator.getEmail());
- pollToUpdate.setCreator(creatorToUpdate);
// -- Choices -- //
- pollToUpdate.clearChoice();
+
+ // FIXME-fdesbois-2012-04-05 : manage remove
+
for (Choice choice : poll.getChoice()) {
- addChoice(pollToUpdate, choice);
+ saveChoice(pollToUpdate, choice);
}
// -- PreventRules -- //
-
- // We assume that all previous preventRules will be deleted
- pollToUpdate.clearPreventRule();
-
- // Create the new preventRules
- PreventRuleDAO preventRuleDAO = getDAO(PreventRule.class);
for (PreventRule preventRule : poll.getPreventRule()) {
- PreventRule preventRuleCreated = create(preventRuleDAO);
- preventRuleCreated.setActive(preventRule.isActive());
- preventRuleCreated.setMethod(preventRule.getMethod());
- preventRuleCreated.setOneTime(preventRule.isOneTime());
- preventRuleCreated.setRepeated(preventRule.isRepeated());
- preventRuleCreated.setScope(preventRule.getScope());
- preventRuleCreated.setSensibility(preventRule.getSensibility());
- pollToUpdate.addPreventRule(preventRuleCreated);
+ savePreventRule(pollToUpdate, preventRule);
}
// -- VotingLists -- //
- pollToUpdate.clearVotingList();
+
+ // FIXME-fdesbois-2012-04-05 : missing delete-orphan on VotingList, if PollType change, VotingList must be deleted
+
for (VotingList votingList : poll.getVotingList()) {
- addVotingList(pollToUpdate, votingList);
+ saveVotingList(pollToUpdate, votingList);
}
+
+ commitTransaction("Could not update poll [" + poll.getTopiaId() + "]");
}
public String getPollVoteUrl(Poll poll) {
@@ -625,22 +651,23 @@
throw new PollNotFoundException();
}
- addChoice(poll, choice);
+ saveChoice(poll, choice);
commitTransaction("Can't create new choice [" + poll.getChoiceType() + "] for poll '" + pollId + "'");
}
- protected void addChoice(Poll poll, Choice choice) {
+ protected void saveChoice(Poll poll, Choice choice) {
ChoiceType choiceType = poll.getChoiceType();
ChoiceDAO dao = getDAO(Choice.class);
Choice choiceLoaded;
if (choice.getTopiaId() == null) {
choiceLoaded = create(dao);
+ poll.addChoice(choiceLoaded);
+
} else {
- choiceLoaded = getEntityById(Choice.class, choice.getTopiaId());
+ choiceLoaded = poll.getChoiceByTopiaId(choice.getTopiaId());
}
- poll.addChoice(choiceLoaded);
if (choiceType == ChoiceType.IMAGE) {
@@ -867,7 +894,7 @@
// }
}
- protected void addVotingList(Poll poll, VotingList votingList) {
+ protected void saveVotingList(Poll poll, VotingList votingList) {
VotingListDAO votingListDAO = getDAO(VotingList.class);
PersonToListDAO personToListDAO = getDAO(PersonToList.class);
@@ -877,10 +904,14 @@
VotingList votingListLoaded;
if (votingList.getTopiaId() == null) {
votingListLoaded = create(votingListDAO);
+ poll.addVotingList(votingListLoaded);
+
} else {
- votingListLoaded = getEntityById(VotingList.class, votingList.getTopiaId());
+ votingListLoaded = poll.getVotingListByTopiaId(votingList.getTopiaId());
+
+ // It's seems stupid, but it doesn't work without it
+ votingListLoaded.setPoll(poll);
}
- poll.addVotingList(votingListLoaded);
votingListLoaded.setName(votingList.getName());
votingListLoaded.setWeight(votingList.getWeight());
@@ -891,8 +922,13 @@
PersonToList personToListLoaded;
if (personToList.getTopiaId() == null) {
personToListLoaded = create(personToListDAO);
+ votingListLoaded.addPollAccountPersonToList(personToListLoaded);
+
+ // The model doesn't have any composition for this relation, the link must be set in both objects
+ personToListLoaded.setVotingList(votingListLoaded);
+
} else {
- personToListLoaded = getEntityById(PersonToList.class, personToList.getTopiaId());
+ personToListLoaded = votingListLoaded.getPollAccountPersonToListByTopiaId(personToList.getTopiaId());
}
// personToListLoaded.setHasVoted(personToList.isHasVoted());
@@ -911,11 +947,27 @@
pollAccountLoaded.setEmail(pollAccount.getEmail());
// pollAccountLoaded.setUserAccount(pollAccount.getUserAccount());
pollAccountLoaded.setVotingId(pollAccount.getVotingId());
+ }
+ }
+
+ protected void savePreventRule(Poll poll, PreventRule preventRule) {
- // The model doesn't have any composition for this relation, the link must be set in both objects
- personToListLoaded.setVotingList(votingListLoaded);
- votingListLoaded.addPollAccountPersonToList(personToListLoaded);
+ PreventRuleDAO preventRuleDAO = getDAO(PreventRule.class);
+
+ PreventRule preventRuleLoaded;
+ if (preventRule.getTopiaId() == null) {
+ preventRuleLoaded = create(preventRuleDAO);
+ poll.addPreventRule(preventRuleLoaded);
+
+ } else {
+ preventRuleLoaded = poll.getPreventRuleByTopiaId(preventRule.getTopiaId());
}
+ preventRuleLoaded.setActive(preventRule.isActive());
+ preventRuleLoaded.setMethod(preventRule.getMethod());
+ preventRuleLoaded.setOneTime(preventRule.isOneTime());
+ preventRuleLoaded.setRepeated(preventRule.isRepeated());
+ preventRuleLoaded.setScope(preventRule.getScope());
+ preventRuleLoaded.setSensibility(preventRule.getSensibility());
}
/**
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-04-06 07:51:35 UTC (rev 3237)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-04-06 12:56:13 UTC (rev 3238)
@@ -97,8 +97,10 @@
Vote result;
if (voteLoaded != null) {
- result = copyVote(voteLoaded);
+ result = newInstance(dao);
+ PollenBinderHelper.simpleCopy(voteLoaded, result, true);
+
// Attach the given accountEditable instead of the loaded one
result.setPollAccount(accountEditable);
@@ -129,6 +131,7 @@
result = getNewVote(poll, accountEditable);
}
+ // Retrieve weight for Restricted Poll with existing account
if (poll.getPollType() != PollType.FREE && accountEditable.getTopiaId() != null) {
PersonToListDAO personToListDAO = getDAO(PersonToList.class);
PersonToList personToList = personToListDAO.findByPollAndAccount(poll, accountEditable);
@@ -136,13 +139,6 @@
}
return result;
}
-
- protected Vote copyVote(Vote source) {
- VoteDAO dao = getDAO(Vote.class);
- Vote result = newInstance(dao);
- PollenBinderHelper.copy("", source, result, true);
- return result;
- }
/**
* Retrieve the URL to update a vote based on {@link PollUri}.
1
0
r3237 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll webapp/WEB-INF/jsp/poll
by tchemit@users.chorem.org 06 Apr '12
by tchemit@users.chorem.org 06 Apr '12
06 Apr '12
Author: tchemit
Date: 2012-04-06 09:51:35 +0200 (Fri, 06 Apr 2012)
New Revision: 3237
Url: http://chorem.org/repositories/revision/pollen/3237
Log:
refactor LoadPoll and SavePoll
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-05 23:47:56 UTC (rev 3236)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-06 07:51:35 UTC (rev 3237)
@@ -23,17 +23,27 @@
*/
package org.chorem.pollen.ui.actions.poll;
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.business.persistence.PersonToList;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.business.persistence.VotingList;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.I18nAble;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
+import org.chorem.pollen.services.PollenServiceFunctions;
import org.chorem.pollen.services.impl.PollService;
import org.chorem.pollen.ui.actions.PollenActionSupport;
+import java.util.Collection;
+import java.util.List;
import java.util.Map;
/**
@@ -54,6 +64,21 @@
private Map<String, String> choiceTypes;
+ /** Text choices. */
+ private List<Choice> textChoices;
+
+ /** Image choices. */
+ private List<Choice> imageChoices;
+
+ /** Date choices. */
+ private List<Choice> dateChoices;
+
+ /** restricted Voting lists. */
+ private List<VotingList> restrictedVotingList;
+
+ /** Group voting lists. */
+ private List<VotingList> groupVotingList;
+
private boolean notification;
private boolean reminder;
@@ -62,27 +87,23 @@
private int reminderHourCountdown = 2;
-// private String textChoiceTokenId;
-//
-// private String dateChoiceTokenId;
-//
-// private String imageChoiceTokenId;
-//
-// private String votingListTokenId;
+ private transient PollService pollService;
-// private int nbTextChoices;
-//
-// private int nbDateChoices;
-//
-// private int nbImageChoices;
-//
-// private int nbVotingLists;
+ /** To create a new personToList. */
+ private transient Function<PersonToList, PersonToList> persontoListCreator;
-// private String actionLabel;
+ /** To create a new votingList. */
+ private transient Function<VotingList, VotingList> votingListCreator;
- private transient PollService pollService;
+ /** To create a new text choice. */
+ private transient Function<Choice, Choice> textChoiceCreator;
+ /** To create a new date choice. */
+ private transient Function<Choice, Choice> dateChoiceCreator;
+ /** To create a new image choice. */
+ private transient Function<Choice, Choice> imageChoiceCreator;
+
@Override
public String getPageLogo() {
return "Creation";
@@ -99,38 +120,6 @@
return poll;
}
-// public int getNbTextChoices() {
-// return nbTextChoices;
-// }
-//
-// public String getTextChoiceTokenId() {
-// return textChoiceTokenId;
-// }
-//
-// public int getNbDateChoices() {
-// return nbDateChoices;
-// }
-//
-// public String getDateChoiceTokenId() {
-// return dateChoiceTokenId;
-// }
-//
-// public int getNbImageChoices() {
-// return nbImageChoices;
-// }
-//
-// public String getImageChoiceTokenId() {
-// return imageChoiceTokenId;
-// }
-//
-// public int getNbVotingLists() {
-// return nbVotingLists;
-// }
-//
-// public String getVotingListTokenId() {
-// return votingListTokenId;
-// }
-
public boolean isInformationsError() {
return false;
}
@@ -151,6 +140,26 @@
return choiceTypes;
}
+ public List<Choice> getTextChoices() {
+ return textChoices;
+ }
+
+ public List<Choice> getImageChoices() {
+ return imageChoices;
+ }
+
+ public List<Choice> getDateChoices() {
+ return dateChoices;
+ }
+
+ public List<VotingList> getRestrictedVotingList() {
+ return restrictedVotingList;
+ }
+
+ public List<VotingList> getGroupVotingList() {
+ return groupVotingList;
+ }
+
public boolean isNotification() {
return notification;
}
@@ -229,6 +238,10 @@
return 1;
}
+ public boolean isClone() {
+ return false;
+ }
+
protected boolean isEdit() {
return StringUtils.isNotEmpty(getPoll().getTopiaId());
}
@@ -238,70 +251,55 @@
// remove all stuff from session
getPollenSession().clearDynamicData();
-// actionLabel = isEdit() ? _("pollen.action.editPoll") :
-// _("pollen.action.createPoll");
-
pollTypes = decorateToName(PollType.values());
choiceTypes = decorateToName(ChoiceType.values());
voteCountingTypes = decorateToName(VoteCountingType.values());
-// nbTextChoices = nbDateChoices = nbImageChoices = getNbChoices();
-// nbVotingLists = getDefaultNbVotingLists();
-//
-// String tokenSuffix = getServiceContext().createPollenUrlId();
-//
-// textChoiceTokenId = DisplayTextChoice.CHOICE_TOKEN + "_" +
-// tokenSuffix;
-//
-// dateChoiceTokenId = DisplayDateChoice.CHOICE_TOKEN + "_" +
-// tokenSuffix;
-//
-// imageChoiceTokenId = DisplayImageChoice.CHOICE_TOKEN + "_" +
-// tokenSuffix;
-//
-// ChoiceType pollChoiceType;
-// // Retrieve choiceType from parameters, the poll object will be updated after prepare
-// String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType");
-// if (choiceTypeParam == null) {
-//
-// // Default value will be initiliazed on poll instanciation
-// pollChoiceType = getPoll().getChoiceType();
-//
-// } else {
-// pollChoiceType = ChoiceType.valueOf(choiceTypeParam);
-// }
-//
-// if (log.isInfoEnabled()) {
-// log.info("choice type " + pollChoiceType);
-// }
-//
-// Map<Integer, Choice> choices = null;
-// String tokenId = null;
-//
-// switch (pollChoiceType) {
-// case TEXT:
-// choices = buildTextChoices(nbTextChoices);
-// tokenId = textChoiceTokenId;
-// break;
-// case DATE:
-// choices = buildDateChoices(nbDateChoices);
-// tokenId = dateChoiceTokenId;
-// break;
-// case IMAGE:
-// choices = buildImageChoices(nbImageChoices);
-// tokenId = imageChoiceTokenId;
-// break;
-// }
-//// getPollenSession().putDynamicData(tokenId, choices);
-//
-// // load votingLists
-//
-// votingListTokenId = DisplayVotingList.VOTING_LIST_TOKEN + "_" +
-// tokenSuffix;
-// Map<Integer, VotingList> votingLists = buildVotingLists(nbVotingLists);
-// getPollenSession().putDynamicData(votingListTokenId, votingLists);
+ textChoices = Lists.newArrayList();
+ imageChoices = Lists.newArrayList();
+ dateChoices = Lists.newArrayList();
+
+ restrictedVotingList = Lists.newArrayList();
+ groupVotingList = Lists.newArrayList();
}
+ public Function<PersonToList, PersonToList> getPersontoListCreator() {
+ if (persontoListCreator == null) {
+ persontoListCreator = PollenServiceFunctions.newPersonToListCreator(isClone(), serviceContext);
+ }
+ return persontoListCreator;
+ }
+
+ public Function<VotingList, VotingList> getVotingListCreator() {
+ if (votingListCreator == null) {
+ votingListCreator = PollenServiceFunctions.newVotingListCreator(isClone(),
+ serviceContext,
+ getPersontoListCreator());
+ }
+ return votingListCreator;
+ }
+
+ public Function<Choice, Choice> getTextChoiceCreator() {
+ if (textChoiceCreator == null) {
+ textChoiceCreator = PollenServiceFunctions.newTextChoiceCreator(isClone());
+ }
+ return textChoiceCreator;
+ }
+
+ public Function<Choice, Choice> getDateChoiceCreator() {
+ if (dateChoiceCreator == null) {
+ dateChoiceCreator = PollenServiceFunctions.newDateChoiceCreator(isClone());
+ }
+ return dateChoiceCreator;
+ }
+
+ public Function<Choice, Choice> getImageChoiceCreator() {
+ if (imageChoiceCreator == null) {
+ imageChoiceCreator = PollenServiceFunctions.newImageChoiceCreator(isClone());
+ }
+ return imageChoiceCreator;
+ }
+
private <E extends Enum<E> & I18nAble> Map<String, String> decorateToName(E... values) {
Map<String, String> result = Maps.newLinkedHashMap();
for (E value : values) {
@@ -309,4 +307,94 @@
}
return result;
}
+
+ protected void loadChoicesAndvotingLists(Poll poll,
+ Collection<Choice> pollChoices,
+ Collection<VotingList> pollVotinLists,
+ boolean fillLists) {
+
+ Preconditions.checkNotNull(poll);
+ Preconditions.checkNotNull(poll.getChoiceType());
+ Preconditions.checkNotNull(poll.getPollType());
+
+
+ if (CollectionUtils.isNotEmpty(pollChoices)) {
+
+ //push back choices
+
+ switch (poll.getChoiceType()) {
+
+ case TEXT:
+ getTextChoices().addAll(pollChoices);
+ break;
+ case DATE:
+ getDateChoices().addAll(pollChoices);
+ break;
+ case IMAGE:
+ getImageChoices().addAll(pollChoices);
+ break;
+ }
+ }
+
+ if (CollectionUtils.isNotEmpty(pollVotinLists)) {
+
+ // push back voting lists
+
+ switch (poll.getPollType()) {
+
+ case FREE:
+ // not voting lists
+ break;
+ case RESTRICTED:
+ getRestrictedVotingList().addAll(pollVotinLists);
+ break;
+ case GROUP:
+ getGroupVotingList().addAll(pollVotinLists);
+ break;
+ }
+ }
+
+ if (fillLists) {
+
+ // refill lists
+
+ int defaultMaxChoices = 5;
+ int defaultMaxVoting = 5;
+
+ fillLists(defaultMaxChoices, defaultMaxVoting);
+ }
+ }
+
+ protected void fillLists(int defaultMaxChoices, int defaultMaxVoting) {
+
+ PollenServiceFunctions.fillChoiceList(textChoices,
+ defaultMaxChoices,
+ getTextChoiceCreator());
+
+ PollenServiceFunctions.fillChoiceList(dateChoices,
+ defaultMaxChoices,
+ getDateChoiceCreator());
+
+ PollenServiceFunctions.fillChoiceList(imageChoices,
+ defaultMaxChoices,
+ getImageChoiceCreator());
+
+ if (CollectionUtils.isEmpty(restrictedVotingList)) {
+ restrictedVotingList.add(getVotingListCreator().apply(null));
+ }
+ for (VotingList votingList : restrictedVotingList) {
+ PollenServiceFunctions.fillVotingList(votingList,
+ getPersontoListCreator(),
+ defaultMaxVoting);
+ }
+ if (CollectionUtils.isEmpty(groupVotingList)) {
+ groupVotingList.add(getVotingListCreator().apply(null));
+ }
+ for (VotingList votingList : groupVotingList) {
+ PollenServiceFunctions.fillVotingList(votingList,
+ getPersontoListCreator(),
+ defaultMaxVoting);
+ }
+
+ }
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-05 23:47:56 UTC (rev 3236)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-06 07:51:35 UTC (rev 3237)
@@ -23,17 +23,11 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import org.apache.commons.collections.CollectionUtils;
import org.chorem.pollen.bean.PollUri;
import org.chorem.pollen.business.persistence.Choice;
-import org.chorem.pollen.business.persistence.PersonToList;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.VotingList;
-import org.chorem.pollen.common.PollType;
-import org.chorem.pollen.services.PollenServiceFunctions;
import java.util.List;
@@ -50,21 +44,6 @@
private boolean clone;
- /** Text choices. */
- private List<Choice> textChoices;
-
- /** Image choices. */
- private List<Choice> imageChoices;
-
- /** Date choices. */
- private List<Choice> dateChoices;
-
- /** restricted Voting lists. */
- private List<VotingList> restrictedVotingList;
-
- /** Group voting lists. */
- private List<VotingList> groupVotingList;
-
public PollUri getUriId() {
return pollUri;
}
@@ -73,6 +52,7 @@
this.pollUri = pollUri;
}
+ @Override
public boolean isClone() {
return clone;
}
@@ -81,51 +61,11 @@
this.clone = clone;
}
- public List<Choice> getTextChoices() {
- return textChoices;
- }
-
- public List<Choice> getImageChoices() {
- return imageChoices;
- }
-
- public List<Choice> getDateChoices() {
- return dateChoices;
- }
-
- public List<VotingList> getRestrictedVotingList() {
- return restrictedVotingList;
- }
-
- public List<VotingList> getGroupVotingList() {
- return groupVotingList;
- }
-
@Override
public String execute() throws Exception {
prepareFormPage();
- textChoices = Lists.newArrayList();
- imageChoices = Lists.newArrayList();
- dateChoices = Lists.newArrayList();
- restrictedVotingList = Lists.newArrayList();
- groupVotingList = Lists.newArrayList();
-
- Function<PersonToList, PersonToList> persontoListCreator =
- PollenServiceFunctions.newPersonToListCreator(clone, serviceContext);
- Function<VotingList, VotingList> votingListCreator =
- PollenServiceFunctions.newVotingListCreator(clone,
- serviceContext,
- persontoListCreator);
-
- Function<Choice, Choice> textChoiceCreator =
- PollenServiceFunctions.newTextChoiceCreator(clone);
- Function<Choice, Choice> dateChoiceCreator =
- PollenServiceFunctions.newDateChoiceCreator(clone);
- Function<Choice, Choice> imageChoiceCreator =
- PollenServiceFunctions.newImageChoiceCreator(clone);
-
if (pollUri == null) {
// create a new poll
@@ -148,78 +88,19 @@
creator.setTopiaId(null);
creator.setAccountId(serviceContext.createPollenUrlId());
}
-
- // -- Choice -- //
- if (!poll.isChoiceEmpty()) {
-
- // reload choices
-
- switch (poll.getChoiceType()) {
-
- case TEXT:
- textChoices.addAll(Lists.transform(poll.getChoice(), textChoiceCreator));
- break;
- case DATE:
- dateChoices.addAll(Lists.transform(poll.getChoice(), dateChoiceCreator));
- break;
- case IMAGE:
- imageChoices.addAll(Lists.transform(poll.getChoice(), imageChoiceCreator));
- break;
- }
- }
-
- // -- VotingList -- //
- if (poll.getPollType() != PollType.FREE) {
-
- // reload voting lists
- if (!poll.isVotingListEmpty()) {
- switch (poll.getPollType()) {
-
- case FREE:
- // nothing to load
- break;
- case RESTRICTED:
- restrictedVotingList.addAll(Lists.transform(
- poll.getVotingList(), votingListCreator));
- break;
- case GROUP:
- groupVotingList.addAll(Lists.transform(
- poll.getVotingList(), votingListCreator));
- break;
- }
-
- }
- }
}
- if (!isVoteStarted()) {
- // can edit choices and voting lists, so fill them
+ List<Choice> pollChoices = poll.getChoice();
+ List<VotingList> pollVotingLists = poll.getVotingList();
- int defaultMaxChoices = 5;
- PollenServiceFunctions.fillChoiceList(textChoices, defaultMaxChoices, textChoiceCreator);
- PollenServiceFunctions.fillChoiceList(dateChoices, defaultMaxChoices, dateChoiceCreator);
- PollenServiceFunctions.fillChoiceList(imageChoices, defaultMaxChoices, imageChoiceCreator);
+ loadChoicesAndvotingLists(poll,
+ pollChoices,
+ pollVotingLists,
+ !isVoteStarted());
- int defaultMaxVoting = 5;
- if (CollectionUtils.isEmpty(restrictedVotingList)) {
- restrictedVotingList.add(votingListCreator.apply(null));
- }
- for (VotingList votingList : restrictedVotingList) {
- PollenServiceFunctions.fillVotingList(votingList,
- persontoListCreator,
- defaultMaxVoting);
- }
- if (CollectionUtils.isEmpty(groupVotingList)) {
- groupVotingList.add(votingListCreator.apply(null));
- }
- for (VotingList votingList : groupVotingList) {
- PollenServiceFunctions.fillVotingList(votingList,
- persontoListCreator,
- defaultMaxVoting);
- }
- }
return SUCCESS;
}
+
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-05 23:47:56 UTC (rev 3236)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-06 07:51:35 UTC (rev 3237)
@@ -23,14 +23,12 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
-import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@@ -52,7 +50,6 @@
import org.chorem.pollen.business.persistence.VotingListImpl;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
-import org.chorem.pollen.services.PollenServiceFunctions;
import org.chorem.pollen.services.impl.PollService;
import org.chorem.pollen.services.impl.PreventRuleService;
import org.chorem.pollen.services.impl.UserService;
@@ -61,6 +58,7 @@
import java.io.File;
import java.text.ParseException;
+import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@@ -91,9 +89,6 @@
private static final Pattern IMAGE_CHOICE_NAME_PATTERN =
Pattern.compile("imageChoice_(\\d+)\\.name");
-// private static final Pattern VOTING_LIST_NAME_PATTERN =
-// Pattern.compile("votingList_(\\d+)\\.name");
-
private String userId;
/** Uploaded images (for choice type poll). */
@@ -105,10 +100,13 @@
/** Uploaded images name (from use desktop) (for choice type poll). */
private List<String> imageChoiceFileName;
+ /** Flag when there is some errors on the information panel. */
protected boolean informationsError;
- protected boolean optionsError;
+ /** Flag when there is some errors on the options panel. */
+ private boolean optionsError;
+
/**
* All the parameters send by request used to build back choices of the
* poll.
@@ -122,50 +120,15 @@
private Map<Integer, Choice> choices;
/**
- * Indexed voting lists retreive from parameters the pollType selected in
- * form . (Other voting lists are lost).
+ * Indexed voting lists retreive from parameters for the pollType selected
+ * in form. (Other voting lists are lost).
*/
private Map<Integer, VotingList> votingLists;
- /** Text choices. */
- private List<Choice> textChoices;
-
- /** Image choices. */
- private List<Choice> imageChoices;
-
- /** Date choices. */
- private List<Choice> dateChoices;
-
- /** restricted Voting lists. */
- private List<VotingList> restrictedVotingList;
-
- /** Group voting lists. */
- private List<VotingList> groupVotingList;
-
public void setUserId(String userId) {
this.userId = userId;
}
- public List<Choice> getTextChoices() {
- return textChoices;
- }
-
- public List<Choice> getImageChoices() {
- return imageChoices;
- }
-
- public List<Choice> getDateChoices() {
- return dateChoices;
- }
-
- public List<VotingList> getRestrictedVotingList() {
- return restrictedVotingList;
- }
-
- public List<VotingList> getGroupVotingList() {
- return groupVotingList;
- }
-
@Override
public void prepare() throws Exception {
@@ -191,15 +154,12 @@
switch (pollChoiceType) {
case TEXT:
-
choices = buildTextChoices();
break;
case DATE:
-
choices = buildDateChoices();
break;
case IMAGE:
-
choices = buildImageChoices();
break;
}
@@ -214,7 +174,6 @@
// empty voting list
votingLists = Maps.newTreeMap();
-
break;
case RESTRICTED:
@@ -225,7 +184,6 @@
// group voting lists
votingLists = buildVotingLists(pollType);
-
break;
}
}
@@ -233,84 +191,17 @@
@Override
public String input() {
- //push back choices
+ Collection<Choice> pollChoices = choices.values();
+ Collection<VotingList> pollVotinLists = votingLists.values();
- textChoices = Lists.newArrayList();
- imageChoices = Lists.newArrayList();
- dateChoices = Lists.newArrayList();
-
- switch (poll.getChoiceType()) {
-
- case TEXT:
- textChoices.addAll(choices.values());
- break;
- case DATE:
- dateChoices.addAll(choices.values());
- break;
- case IMAGE:
- imageChoices.addAll(choices.values());
- break;
- }
-
- // push back voting lists
-
- restrictedVotingList = Lists.newArrayList();
- groupVotingList = Lists.newArrayList();
-
- switch (poll.getPollType()) {
-
- case FREE:
- // not voting lists
- break;
- case RESTRICTED:
- restrictedVotingList.addAll(votingLists.values());
- break;
- case GROUP:
- groupVotingList.addAll(votingLists.values());
- break;
- }
-
- // refill lists
-
- Function<PersonToList, PersonToList> persontoListCreator =
- PollenServiceFunctions.newPersonToListCreator(false, serviceContext);
- Function<VotingList, VotingList> votingListCreator =
- PollenServiceFunctions.newVotingListCreator(false,
- serviceContext,
- persontoListCreator);
-
- Function<Choice, Choice> textChoiceCreator =
- PollenServiceFunctions.newTextChoiceCreator(false);
- Function<Choice, Choice> dateChoiceCreator =
- PollenServiceFunctions.newDateChoiceCreator(false);
- Function<Choice, Choice> imageChoiceCreator =
- PollenServiceFunctions.newImageChoiceCreator(false);
-
- int defaultMaxChoices = 5;
- PollenServiceFunctions.fillChoiceList(textChoices, defaultMaxChoices, textChoiceCreator);
- PollenServiceFunctions.fillChoiceList(dateChoices, defaultMaxChoices, dateChoiceCreator);
- PollenServiceFunctions.fillChoiceList(imageChoices, defaultMaxChoices, imageChoiceCreator);
-
- int defaultMaxVoting = 5;
- if (CollectionUtils.isEmpty(restrictedVotingList)) {
- restrictedVotingList.add(votingListCreator.apply(null));
- }
- for (VotingList votingList : restrictedVotingList) {
- PollenServiceFunctions.fillVotingList(votingList,
- persontoListCreator,
- defaultMaxVoting);
- }
- if (CollectionUtils.isEmpty(groupVotingList)) {
- groupVotingList.add(votingListCreator.apply(null));
- }
- for (VotingList votingList : groupVotingList) {
- PollenServiceFunctions.fillVotingList(votingList,
- persontoListCreator,
- defaultMaxVoting);
- }
+ loadChoicesAndvotingLists(poll,
+ pollChoices,
+ pollVotinLists,
+ true);
return INPUT;
}
+
@Override
public void validate() {
@@ -352,7 +243,6 @@
// nothing to validate
} else {
-// Map<Integer, VotingList> votingLists = getOrderedVotingLists();
Set<String> groups = Sets.newHashSet();
Set<String> voters = Sets.newHashSet();
@@ -404,7 +294,6 @@
if (!isFreePoll()) {
-// Map<Integer, VotingList> votingLists = getOrderedVotingLists();
for (Integer index : votingLists.keySet()) {
VotingList votingList = votingLists.get(index);
poll.addVotingList(votingList);
@@ -508,30 +397,6 @@
return result;
}
-// protected Map<Integer, Choice> getOrderedChoices() {
-// Map<Integer, Choice> result = null;
-//// switch (getPoll().getChoiceType()) {
-//// case TEXT:
-//// result = getPollenSession().getDynamicData(getTextChoiceTokenId());
-//// break;
-//// case DATE:
-//// result = getPollenSession().getDynamicData(getDateChoiceTokenId());
-//// break;
-//// case IMAGE:
-//// result = getPollenSession().getDynamicData(getImageChoiceTokenId());
-//// break;
-//// }
-// return result;
-// }
-
-// protected Map<Integer, VotingList> getOrderedVotingLists() {
-//
-// Map<Integer, VotingList> result = null;
-//// result = getPollenSession().getDynamicData(
-//// getVotingListTokenId());
-// return result;
-// }
-
protected boolean validateVotingList(int votingListNumber,
VotingList votingList,
Set<String> groups,
@@ -736,7 +601,6 @@
result = reindexMap(result, maxNumber);
int size = result.size();
-// nbTextChoices = Math.max(nbDefault, size);
log.info("nbTextChoices (from request) = " + size);
logChoice(result);
return result;
@@ -773,7 +637,6 @@
result = reindexMap(result, maxNumber);
int size = result.size();
-// nbDateChoices = Math.max(nbDefault, size);
log.info("nbDateChoices (from request) = " + size);
logChoice(result);
return result;
@@ -824,7 +687,6 @@
}
result = reindexMap(result, maxNumber);
int size = result.size();
-// nbImageChoices = Math.max(nbDefault, size);
log.info("nbImageChoices (from request) = " + size);
logChoice(result);
return result;
@@ -868,7 +730,6 @@
result = reindexMap(result, maxNumber);
int size = result.size();
-// nbVotingLists = Math.max(nbDefault, size);
log.info("nbVotingList [" + pollType + "] (from request) = " + size);
// add personToList maps to session (but just now, since votingList
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-05 23:47:56 UTC (rev 3236)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-06 07:51:35 UTC (rev 3237)
@@ -169,8 +169,6 @@
<br/>
- <%--<%@include file="createPoll_votingLists.jsp" %>--%>
-
<fieldset>
<legend><s:text name="pollen.common.pollType"/></legend>
<s:radio key='poll.pollType' list="pollTypes"
1
0
05 Apr '12
Author: tchemit
Date: 2012-04-06 01:47:56 +0200 (Fri, 06 Apr 2012)
New Revision: 3236
Url: http://chorem.org/repositories/revision/pollen/3236
Log:
rethink the poll form (use less ajax request), need to be continued (validation not finished)
Added:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/createPoll.js
Removed:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/choiceHelper.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/PersonToList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/VotingList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
Added: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-04-05 23:47:56 UTC (rev 3236)
@@ -0,0 +1,263 @@
+/*
+ * #%L
+ * Pollen :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.services;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import org.chorem.pollen.bean.PollDateChoice;
+import org.chorem.pollen.bean.PollImageChoice;
+import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.business.persistence.ChoiceImpl;
+import org.chorem.pollen.business.persistence.PersonToList;
+import org.chorem.pollen.business.persistence.PersonToListImpl;
+import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.business.persistence.PollAccountImpl;
+import org.chorem.pollen.business.persistence.VotingList;
+import org.chorem.pollen.business.persistence.VotingListImpl;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Usefull functions for the service (and higher) layers.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class PollenServiceFunctions {
+
+ protected PollenServiceFunctions() {
+ // no instance for helper class
+ }
+
+ public static void fillChoiceList(List<Choice> choiceList, int max,
+ Function<Choice, Choice> function) {
+ while (choiceList.size() < max) {
+ Choice newChoice = function.apply(null);
+ choiceList.add(newChoice);
+ }
+ }
+
+ public static void fillVotingList(VotingList votingList,
+ Function<PersonToList, PersonToList> persontoListCreator,
+ int max) {
+ while (votingList.sizePollAccountPersonToList() < max) {
+ PersonToList newPersontoList = persontoListCreator.apply(null);
+ votingList.addPollAccountPersonToList(newPersontoList);
+ }
+ }
+
+ public static TextChoiceCreator newTextChoiceCreator(boolean clone) {
+ return new TextChoiceCreator(clone);
+ }
+
+ public static ImageChoiceCreator newImageChoiceCreator(boolean clone) {
+ return new ImageChoiceCreator(clone);
+ }
+
+ public static DateChoiceCreator newDateChoiceCreator(boolean clone) {
+ return new DateChoiceCreator(clone);
+ }
+
+ public static Function<VotingList, VotingList> newVotingListCreator(
+ boolean clone,
+ PollenServiceContext serviceContext,
+ Function<PersonToList, PersonToList> persontoListCreator) {
+ return new VotingListCreator(clone, serviceContext, persontoListCreator);
+ }
+
+ public static Function<PersonToList, PersonToList> newPersonToListCreator(
+ boolean clone,
+ PollenServiceContext serviceContext) {
+ return new PersonToListCreator(clone, serviceContext);
+ }
+
+ public static class TextChoiceCreator implements Function<Choice, Choice> {
+
+
+ protected final boolean clone;
+
+ protected TextChoiceCreator(boolean clone) {
+ this.clone = clone;
+ }
+
+ @Override
+ public Choice apply(Choice input) {
+ Choice result = new ChoiceImpl();
+ if (input != null) {
+ if (clone) {
+ // do not copy topia id
+ } else {
+ result.setTopiaId(input.getTopiaId());
+ }
+ result.setName(input.getName());
+ result.setDescription(input.getDescription());
+ }
+ return result;
+ }
+ }
+
+ public static class ImageChoiceCreator implements Function<Choice, Choice> {
+
+ protected final boolean clone;
+
+ protected ImageChoiceCreator(boolean clone) {
+ this.clone = clone;
+ }
+
+
+ @Override
+ public Choice apply(Choice input) {
+ PollImageChoice result = new PollImageChoice();
+ if (input != null) {
+ if (clone) {
+ // do not copy topia id
+ } else {
+ result.setTopiaId(input.getTopiaId());
+ }
+ result.setName(input.getName());
+ result.setDescription(input.getDescription());
+ result.setLocation(input.getName());
+ }
+ return result;
+ }
+ }
+
+ public static class DateChoiceCreator implements Function<Choice, Choice> {
+
+ protected final boolean clone;
+
+ protected DateChoiceCreator(boolean clone) {
+ this.clone = clone;
+ }
+
+ @Override
+ public Choice apply(Choice input) {
+ PollDateChoice result = new PollDateChoice();
+ if (input != null) {
+ if (clone) {
+ // do not copy topia id
+ } else {
+ result.setTopiaId(input.getTopiaId());
+ }
+
+ result.setName(input.getName());
+ result.setDescription(input.getDescription());
+ result.setDate(new Date(Long.valueOf(input.getName())));
+ }
+ return result;
+ }
+ }
+
+ public static class VotingListCreator implements Function<VotingList, VotingList> {
+
+ protected final boolean clone;
+
+ protected final PollenServiceContext serviceContext;
+
+ protected final Function<PersonToList, PersonToList> persontoListCreator;
+
+ protected VotingListCreator(boolean clone,
+ PollenServiceContext serviceContext,
+ Function<PersonToList, PersonToList> persontoListCreator) {
+ this.clone = clone;
+ this.serviceContext = serviceContext;
+ this.persontoListCreator = persontoListCreator;
+ }
+
+ @Override
+ public VotingList apply(VotingList input) {
+ VotingList result = new VotingListImpl();
+ result.setPollAccountPersonToList(
+ Lists.<PersonToList>newArrayList());
+ if (input == null) {
+
+ // new votingList
+ result.setWeight(1);
+ } else {
+
+ if (clone) {
+ // do not copy topia id
+ } else {
+ result.setTopiaId(input.getTopiaId());
+ }
+ result.setName(input.getName());
+ result.setWeight(input.getWeight());
+
+ if (!input.isPollAccountPersonToListEmpty()) {
+
+ // copy person to lists
+ result.addAllPollAccountPersonToList(Lists.transform(
+ input.getPollAccountPersonToList(),
+ persontoListCreator));
+ }
+ }
+ return result;
+ }
+ }
+
+ public static class PersonToListCreator implements Function<PersonToList, PersonToList> {
+
+ protected final boolean clone;
+
+ protected final PollenServiceContext serviceContext;
+
+ protected PersonToListCreator(boolean clone, PollenServiceContext serviceContext) {
+ this.clone = clone;
+ this.serviceContext = serviceContext;
+ }
+
+ @Override
+ public PersonToList apply(PersonToList input) {
+ PersonToList result = new PersonToListImpl();
+ if (input != null) {
+ if (clone) {
+ // do not copy topia id
+ } else {
+ result.setTopiaId(input.getTopiaId());
+ }
+ result.setWeight(input.getWeight());
+ PollAccount pollAccount = input.getPollAccount();
+ if (pollAccount != null) {
+ PollAccount pollAccount2 = new PollAccountImpl();
+ String accountId;
+ if (clone) {
+ // do not copy topia id
+ // generate a new accountId
+ accountId = serviceContext.createPollenUrlId();
+ } else {
+ pollAccount2.setTopiaId(pollAccount.getTopiaId());
+ accountId = pollAccount.getAccountId();
+ }
+ pollAccount2.setAccountId(accountId);
+ pollAccount2.setVotingId(pollAccount.getVotingId());
+ result.setPollAccount(pollAccount2);
+ }
+ } else {
+ result.setWeight(1);
+ }
+ return result;
+ }
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-05 23:47:56 UTC (rev 3236)
@@ -1,41 +1,40 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
package org.chorem.pollen.ui.actions.poll;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.struts2.interceptor.ParameterAware;
-import org.chorem.pollen.bean.PollDateChoice;
-import org.chorem.pollen.bean.PollImageChoice;
-import org.chorem.pollen.business.persistence.Choice;
-import org.chorem.pollen.business.persistence.ChoiceImpl;
-import org.chorem.pollen.business.persistence.PersonToList;
-import org.chorem.pollen.business.persistence.PersonToListImpl;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
-import org.chorem.pollen.business.persistence.PollAccountImpl;
-import org.chorem.pollen.business.persistence.VotingList;
-import org.chorem.pollen.business.persistence.VotingListImpl;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.I18nAble;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
import org.chorem.pollen.services.impl.PollService;
-import org.chorem.pollen.ui.actions.FileUploadAware;
import org.chorem.pollen.ui.actions.PollenActionSupport;
-import java.io.File;
-import java.text.ParseException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Created: 04/04/12
@@ -43,27 +42,12 @@
* @author fdesbois <desbois(a)codelutin.com>
* $Id$
*/
-public abstract class AbstractPollForm extends PollenActionSupport implements ParameterAware, FileUploadAware {
+public abstract class AbstractPollForm extends PollenActionSupport {
private static final long serialVersionUID = 1L;
- /** Logger. */
- private static final Log log = LogFactory.getLog(AbstractPollForm.class);
+ protected Poll poll;
- private static final Pattern TEXT_CHOICE_NAME_PATTERN =
- Pattern.compile("textChoice_(\\d+)\\.name");
-
- private static final Pattern DATE_CHOICE_NAME_PATTERN =
- Pattern.compile("dateChoice_(\\d+)\\.name");
-
- private static final Pattern IMAGE_CHOICE_NAME_PATTERN =
- Pattern.compile("imageChoice_(\\d+)\\.name");
-
- private static final Pattern VOTING_LIST_NAME_PATTERN =
- Pattern.compile("votingList_(\\d+)\\.name");
-
- private Poll poll;
-
private Map<String, String> pollTypes;
private Map<String, String> voteCountingTypes;
@@ -78,47 +62,27 @@
private int reminderHourCountdown = 2;
- private String textChoiceTokenId;
+// private String textChoiceTokenId;
+//
+// private String dateChoiceTokenId;
+//
+// private String imageChoiceTokenId;
+//
+// private String votingListTokenId;
- private String dateChoiceTokenId;
+// private int nbTextChoices;
+//
+// private int nbDateChoices;
+//
+// private int nbImageChoices;
+//
+// private int nbVotingLists;
- private String imageChoiceTokenId;
+// private String actionLabel;
- private String votingListTokenId;
-
- private int nbTextChoices;
-
- private int nbDateChoices;
-
- private int nbImageChoices;
-
- private int nbVotingLists;
-
- /** Uploaded images (for choice type poll). */
- private List<File> imageChoice;
-
- /** Uploaded images content type (for choice type poll). */
- private List<String> imageChoiceContentType;
-
- /** Uploaded images name (from use desktop) (for choice type poll). */
- private List<String> imageChoiceFileName;
-
- private String actionLabel;
-
private transient PollService pollService;
- /**
- * All the parameters send by request used to build back choices of the
- * poll.
- */
- protected Map<String, String[]> parameters;
- protected boolean informationsError;
-
- protected boolean optionsError;
-
- protected abstract Poll initPoll();
-
@Override
public String getPageLogo() {
return "Creation";
@@ -132,44 +96,49 @@
}
public Poll getPoll() {
- if (poll == null) {
- poll = initPoll();
- }
return poll;
}
- public int getNbTextChoices() {
- return nbTextChoices;
- }
+// public int getNbTextChoices() {
+// return nbTextChoices;
+// }
+//
+// public String getTextChoiceTokenId() {
+// return textChoiceTokenId;
+// }
+//
+// public int getNbDateChoices() {
+// return nbDateChoices;
+// }
+//
+// public String getDateChoiceTokenId() {
+// return dateChoiceTokenId;
+// }
+//
+// public int getNbImageChoices() {
+// return nbImageChoices;
+// }
+//
+// public String getImageChoiceTokenId() {
+// return imageChoiceTokenId;
+// }
+//
+// public int getNbVotingLists() {
+// return nbVotingLists;
+// }
+//
+// public String getVotingListTokenId() {
+// return votingListTokenId;
+// }
- public String getTextChoiceTokenId() {
- return textChoiceTokenId;
+ public boolean isInformationsError() {
+ return false;
}
- public int getNbDateChoices() {
- return nbDateChoices;
+ public boolean isOptionsError() {
+ return false;
}
- public String getDateChoiceTokenId() {
- return dateChoiceTokenId;
- }
-
- public int getNbImageChoices() {
- return nbImageChoices;
- }
-
- public String getImageChoiceTokenId() {
- return imageChoiceTokenId;
- }
-
- public int getNbVotingLists() {
- return nbVotingLists;
- }
-
- public String getVotingListTokenId() {
- return votingListTokenId;
- }
-
public Map<String, String> getPollTypes() {
return pollTypes;
}
@@ -214,42 +183,6 @@
this.reminderHourCountdown = reminderHourCountdown;
}
- @Override
- public void setFiles(String paramName, List<File> files) {
- this.imageChoice = Lists.newArrayList(files);
- }
-
- @Override
- public void setFileContentTypes(String paramName, List<String> contentTypes) {
- this.imageChoiceContentType = Lists.newArrayList(contentTypes);
- }
-
- @Override
- public void setFileNames(String paramName, List<String> fileNames) {
- this.imageChoiceFileName = Lists.newArrayList(fileNames);
- }
-
- public List<File> getImageChoice() {
- if (imageChoice == null) {
- imageChoice = Lists.newArrayList();
- }
- return imageChoice;
- }
-
- public List<String> getImageChoiceContentType() {
- if (imageChoiceContentType == null) {
- imageChoiceContentType = Lists.newArrayList();
- }
- return imageChoiceContentType;
- }
-
- public List<String> getImageChoiceFileName() {
- if (imageChoiceFileName == null) {
- imageChoiceFileName = Lists.newArrayList();
- }
- return imageChoiceFileName;
- }
-
public boolean isFreePoll() {
PollType pollType = poll.getPollType();
return pollType == PollType.FREE;
@@ -268,41 +201,25 @@
return getPollService().getPollEditUrl(poll);
}
- public boolean isInformationsError() {
- return informationsError;
- }
-
- public boolean isOptionsError() {
- return optionsError;
- }
-
public int getSelectedTab() {
- int result;
- if (isInformationsError()) {
- result = 0;
- } else {
- if (isOptionsError()) {
- result = 1;
- } else {
- result = 0;
- }
- }
+ int result = 0;
return result;
}
public String getActionLabel() {
- return actionLabel;
+ return isEdit() ? _("pollen.action.editPoll") :
+ _("pollen.action.createPoll");
}
public boolean isVoteStarted() {
- return isEdit() && getPoll().sizeVote() > 0;
+ return isEdit() && poll.sizeVote() > 0;
}
-
+
public boolean isCreatorUserAccountDefined() {
- PollAccount creator = getPoll().getCreator();
+ PollAccount creator = poll.getCreator();
return creator.getUserAccount() != null;
}
-
+
protected int getNbChoices() {
//TODO tchemit-2012-03-05 use a default value from configuration
return 5;
@@ -321,473 +238,70 @@
// remove all stuff from session
getPollenSession().clearDynamicData();
- actionLabel = isEdit() ? _("pollen.action.editPoll") : _("pollen.action.createPoll");
+// actionLabel = isEdit() ? _("pollen.action.editPoll") :
+// _("pollen.action.createPoll");
pollTypes = decorateToName(PollType.values());
choiceTypes = decorateToName(ChoiceType.values());
voteCountingTypes = decorateToName(VoteCountingType.values());
- nbTextChoices = nbDateChoices = nbImageChoices = getNbChoices();
- nbVotingLists = getDefaultNbVotingLists();
-
- String tokenSuffix = getServiceContext().createPollenUrlId();
-
- textChoiceTokenId = DisplayTextChoice.CHOICE_TOKEN + "_" +
- tokenSuffix;
-
- dateChoiceTokenId = DisplayDateChoice.CHOICE_TOKEN + "_" +
- tokenSuffix;
-
- imageChoiceTokenId = DisplayImageChoice.CHOICE_TOKEN + "_" +
- tokenSuffix;
-
- ChoiceType pollChoiceType;
- // Retrieve choiceType from parameters, the poll object will be updated after prepare
- String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType");
- if (choiceTypeParam == null) {
-
- // Default value will be initiliazed on poll instanciation
- pollChoiceType = getPoll().getChoiceType();
-
- } else {
- pollChoiceType = ChoiceType.valueOf(choiceTypeParam);
- }
-
- if (log.isInfoEnabled()) {
- log.info("choice type " + pollChoiceType);
- }
-
- Map<Integer, Choice> choices = null;
- String tokenId = null;
-
- switch (pollChoiceType) {
- case TEXT:
- choices = buildTextChoices(nbTextChoices);
- tokenId = textChoiceTokenId;
- break;
- case DATE:
- choices = buildDateChoices(nbDateChoices);
- tokenId = dateChoiceTokenId;
- break;
- case IMAGE:
- choices = buildImageChoices(nbImageChoices);
- tokenId = imageChoiceTokenId;
- break;
- }
- getPollenSession().putDynamicData(tokenId, choices);
-
- // load votingLists
-
- votingListTokenId = DisplayVotingList.VOTING_LIST_TOKEN + "_" +
- tokenSuffix;
- Map<Integer, VotingList> votingLists = buildVotingLists(nbVotingLists);
- getPollenSession().putDynamicData(votingListTokenId, votingLists);
+// nbTextChoices = nbDateChoices = nbImageChoices = getNbChoices();
+// nbVotingLists = getDefaultNbVotingLists();
+//
+// String tokenSuffix = getServiceContext().createPollenUrlId();
+//
+// textChoiceTokenId = DisplayTextChoice.CHOICE_TOKEN + "_" +
+// tokenSuffix;
+//
+// dateChoiceTokenId = DisplayDateChoice.CHOICE_TOKEN + "_" +
+// tokenSuffix;
+//
+// imageChoiceTokenId = DisplayImageChoice.CHOICE_TOKEN + "_" +
+// tokenSuffix;
+//
+// ChoiceType pollChoiceType;
+// // Retrieve choiceType from parameters, the poll object will be updated after prepare
+// String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType");
+// if (choiceTypeParam == null) {
+//
+// // Default value will be initiliazed on poll instanciation
+// pollChoiceType = getPoll().getChoiceType();
+//
+// } else {
+// pollChoiceType = ChoiceType.valueOf(choiceTypeParam);
+// }
+//
+// if (log.isInfoEnabled()) {
+// log.info("choice type " + pollChoiceType);
+// }
+//
+// Map<Integer, Choice> choices = null;
+// String tokenId = null;
+//
+// switch (pollChoiceType) {
+// case TEXT:
+// choices = buildTextChoices(nbTextChoices);
+// tokenId = textChoiceTokenId;
+// break;
+// case DATE:
+// choices = buildDateChoices(nbDateChoices);
+// tokenId = dateChoiceTokenId;
+// break;
+// case IMAGE:
+// choices = buildImageChoices(nbImageChoices);
+// tokenId = imageChoiceTokenId;
+// break;
+// }
+//// getPollenSession().putDynamicData(tokenId, choices);
+//
+// // load votingLists
+//
+// votingListTokenId = DisplayVotingList.VOTING_LIST_TOKEN + "_" +
+// tokenSuffix;
+// Map<Integer, VotingList> votingLists = buildVotingLists(nbVotingLists);
+// getPollenSession().putDynamicData(votingListTokenId, votingLists);
}
- @Override
- public void setParameters(Map<String, String[]> parameters) {
- this.parameters = parameters;
- }
-
- protected Map<Integer, Choice> buildTextChoices(int nbDefault) {
- Map<Integer, Choice> result = Maps.newTreeMap();
-
- int maxNumber = 0;
-
- for (String paramName : parameters.keySet()) {
-
- Matcher matcher = TEXT_CHOICE_NAME_PATTERN.matcher(paramName);
- if (matcher.matches()) {
-
- // found a text choice name
-
- String paramValue = getNonEmptyParameterValue(paramName);
- if (paramValue != null) {
-
- // can keep this none empty text choice name
-
- Integer choiceNumber = Integer.valueOf(matcher.group(1));
- if (choiceNumber > maxNumber) {
- maxNumber = choiceNumber;
- }
- Choice choice = new ChoiceImpl();
- createChoice(choice, "textChoice_" + choiceNumber,
- paramValue);
- result.put(choiceNumber, choice);
- }
- }
- }
- result = reindexMap(result, maxNumber);
-
- int size = result.size();
- nbTextChoices = Math.max(nbDefault, size);
- log.info("nbTextChoices (from request) = " + size);
- logChoice(result);
- return result;
- }
-
- protected Map<Integer, Choice> buildDateChoices(int nbDefault) {
- Map<Integer, Choice> result = Maps.newTreeMap();
-
- int maxNumber = 0;
- for (String paramName : parameters.keySet()) {
-
- Matcher matcher = DATE_CHOICE_NAME_PATTERN.matcher(paramName);
- if (matcher.matches()) {
-
- // found a text choice name
-
- String paramValue = getNonEmptyParameterValue(paramName);
- if (paramValue != null) {
-
- // can keep this none empty text choice name
-
- Integer choiceNumber = Integer.valueOf(matcher.group(1));
- if (choiceNumber > maxNumber) {
- maxNumber = choiceNumber;
- }
- PollDateChoice choice = new PollDateChoice();
- createDateChoice(choice,
- "dateChoice_" + choiceNumber,
- paramValue);
- result.put(choiceNumber, choice);
- }
- }
- }
- result = reindexMap(result, maxNumber);
-
- int size = result.size();
- nbDateChoices = Math.max(nbDefault, size);
- log.info("nbDateChoices (from request) = " + size);
- logChoice(result);
- return result;
- }
-
- protected Map<Integer, Choice> buildImageChoices(int nbDefault) {
- Map<Integer, Choice> result = Maps.newTreeMap();
-
- // push back in parameters stuff from uploaded files
- int index = 0;
-
- for (String fileName : getImageChoiceFileName()) {
- if (fileName != null) {
- parameters.put("imageChoice_" + index + ".name",
- new String[]{fileName});
- parameters.put(
- "imageChoice_" + index + ".location",
- new String[]{getImageChoice().get(index).getAbsolutePath()});
- }
- index++;
- }
-
- int maxNumber = 0;
- for (String paramName : parameters.keySet()) {
-
- Matcher matcher = IMAGE_CHOICE_NAME_PATTERN.matcher(paramName);
- if (matcher.matches()) {
-
- // found an image choice name
-
- String paramValue = getNonEmptyParameterValue(paramName);
- if (paramValue != null) {
-
- // can keep this none empty text choice name
-
- Integer choiceNumber = Integer.valueOf(matcher.group(1));
- if (choiceNumber > maxNumber) {
- maxNumber = choiceNumber;
- }
- PollImageChoice choice = new PollImageChoice();
- createImageChoice(choice,
- "imageChoice_" + choiceNumber,
- paramValue);
-
- result.put(choiceNumber, choice);
- }
- }
- }
- result = reindexMap(result, maxNumber);
- int size = result.size();
- nbImageChoices = Math.max(nbDefault, size);
- log.info("nbImageChoices (from request) = " + size);
- logChoice(result);
- return result;
- }
-
- protected Map<Integer, VotingList> buildVotingLists(int nbDefault) {
- Map<Integer, VotingList> result = Maps.newTreeMap();
-
- int maxNumber = 0;
-
- // get all votingList_ parameters
- Set<String> votingListParameterNames = Sets.filter(
- parameters.keySet(),
- new StringStartWithPredicate("votingList_"));
-
- for (String paramName : votingListParameterNames) {
-
- Matcher matcher = VOTING_LIST_NAME_PATTERN.matcher(paramName);
-
- if (matcher.matches()) {
-
- // found a voting list name
-
- int votingListNumber = buildVotingList(paramName,
- matcher,
- result
- );
- maxNumber = Math.max(maxNumber, votingListNumber);
- }
- }
-
- result = reindexMap(result, maxNumber);
-
- int size = result.size();
- nbVotingLists = Math.max(nbDefault, size);
- log.info("nbVotingList (from request) = " + size);
-
- // add personToList maps to session (but just now, since votingList
- // could have been reindex)
- for (Map.Entry<Integer, VotingList> entry : result.entrySet()) {
- Integer votingListNumber = entry.getKey();
- VotingList votingList = entry.getValue();
-
- if (!votingList.isPollAccountPersonToListEmpty()) {
- List<PersonToList> personToList =
- votingList.getPollAccountPersonToList();
-
- Map<Integer, PersonToList> personToListMap = Maps.newTreeMap();
- int index = 0;
- for (PersonToList toList : personToList) {
- personToListMap.put(index++, toList);
- }
-
- String token = DisplayPersonToList.getPersonToListTokenId(
- votingListTokenId, votingListNumber);
- if (log.isInfoEnabled()) {
- log.info("Add " + token + " with " +
- personToListMap.size() + " personToList");
- }
- getPollenSession().putDynamicData(token, personToListMap);
- }
- }
-
- return result;
- }
-
- private double getDoubleValue(String parameterName) {
- String parameterValue = getNonEmptyParameterValue(parameterName);
- double result = 0;
- if (StringUtils.isNotEmpty(parameterValue)) {
-
- try {
- result = Double.valueOf(parameterValue);
- } catch (NumberFormatException e) {
- //bad conversion, will be treated later
- if (log.isDebugEnabled()) {
- log.debug("Bad double conversion from param [" +
- parameterName + "] : " + parameterValue);
- }
- }
- }
- return result;
- }
-
- private int buildVotingList(String votingListParameterName,
- Matcher votingListMatcher,
- Map<Integer, VotingList> result) {
-
- String paramValue = getNonEmptyParameterValue(votingListParameterName);
- int votingListNumber = Integer.valueOf(votingListMatcher.group(1));
-
- VotingList votingList = new VotingListImpl();
-
- votingList.setName(paramValue);
-
- String prefix = "votingList_" + votingListNumber;
-
- double weight = getDoubleValue(prefix + ".weight");
- votingList.setWeight(weight);
-
- String topiaId = getNonEmptyParameterValue(prefix + ".topiaId");
- votingList.setTopiaId(topiaId);
-
- result.put(votingListNumber, votingList);
-
- String personToListPrefix = "personToList_" + votingListNumber + "_";
-
- // get all personToList parameters
- Set<String> votingListParameterNames = Sets.filter(
- parameters.keySet(), new StringStartWithPredicate(personToListPrefix));
-
- Pattern personToListNamePattern = Pattern.compile(
- personToListPrefix + "(\\d+)\\.votingId");
-
- Map<Integer, PersonToList> personToLists = Maps.newTreeMap();
-
- int maxPersonToListNumber = 0;
-
- // let's build personToList list
- for (String personToListNameParameter : votingListParameterNames) {
-
- Matcher matcher = personToListNamePattern.matcher(
- personToListNameParameter);
-
- if (matcher.matches()) {
-
- int personToListNumber = buildPersonToList(
- personToListPrefix,
- personToListNameParameter,
- matcher,
- votingListNumber,
- personToLists);
-
- maxPersonToListNumber = Math.max(maxPersonToListNumber, personToListNumber);
- }
- }
-
- personToLists = reindexMap(personToLists, maxPersonToListNumber);
-
- for (PersonToList personToList : personToLists.values()) {
- votingList.addPollAccountPersonToList(personToList);
- }
-
- return votingListNumber;
- }
-
- private int buildPersonToList(String personToListPrefix,
- String paramName,
- Matcher personToListMatcher,
- int votingListNumber,
- Map<Integer, PersonToList> result) {
-
- String paramValue = getNonEmptyParameterValue(paramName);
-
- int personToListNumber = 0;
-
- if (paramValue != null) {
-
- // found a PersonToList none empty name, keep it
-
- personToListNumber = Integer.valueOf(personToListMatcher.group(1));
-
- PersonToList personToList = new PersonToListImpl();
-
- PollAccount account = new PollAccountImpl();
- personToList.setPollAccount(account);
-
- account.setVotingId(paramValue);
-
- String prefix = personToListPrefix + personToListNumber;
-
- double weight = getDoubleValue(prefix + ".weight");
- personToList.setWeight(weight);
-
- String topiaId = getNonEmptyParameterValue(prefix + ".topiaId");
- personToList.setTopiaId(topiaId);
-
- String email = getNonEmptyParameterValue(prefix + ".email");
- account.setEmail(email);
-
- String accountId = getNonEmptyParameterValue(prefix + ".accountId");
- account.setAccountId(accountId);
-
- result.put(personToListNumber, personToList);
- }
- return personToListNumber;
- }
-
- private Choice createImageChoice(PollImageChoice choice,
- String prefix,
- String name) {
- createChoice(choice, prefix, name);
- String locationName = prefix + ".location";
- String location = getNonEmptyParameterValue(locationName);
- choice.setLocation(location);
- if (log.isInfoEnabled()) {
- log.info("image location [" + name + "] =" + location);
- }
- return choice;
- }
-
- private Choice createDateChoice(PollDateChoice choice,
- String prefix,
- String name) {
- createChoice(choice, prefix, name);
- if (StringUtils.isNotEmpty(name)) {
- Date date = null;
- try {
- date = parseDateTime(name);
- } catch (ParseException e) {
- if (log.isErrorEnabled()) {
- log.error("Unparseable date " + name, e);
- }
- }
- choice.setDate(date);
- }
- return choice;
- }
-
- private Choice createChoice(Choice choice, String prefix, String name) {
- String descriptionName = prefix + ".description";
- String topiaIdName = prefix + ".topiaId";
- String description = getNonEmptyParameterValue(descriptionName);
- String topiaId = getNonEmptyParameterValue(topiaIdName);
- choice.setName(name);
- choice.setDescription(description);
- choice.setTopiaId(topiaId);
- return choice;
- }
-
- private void logChoice(Map<Integer, Choice> result) {
- for (Map.Entry<Integer, Choice> e : result.entrySet()) {
- Integer choiceId = e.getKey();
- Choice choice = e.getValue();
- if (log.isInfoEnabled()) {
- log.info("Choice [" + choiceId + "] = " +
- choice.getName() + " -- " +
- choice.getDescription());
- }
- }
- }
-
- private <T> Map<Integer, T> reindexMap(Map<Integer, T> result, int maxNumber) {
- Map<Integer, T> result2;
-
- if (maxNumber != result.size() - 1) {
-
- // means there is a hole inside the result (a empty choice was
- // submitted)
-
- // le'ts remove this
- List<Integer> numbers = Lists.newArrayList(result.keySet());
-
- Collections.sort(numbers);
-
- result2 = Maps.newTreeMap();
- int i = 0;
- for (Integer number : numbers) {
- T choice = result.get(number);
- result2.put(i++, choice);
- }
- } else {
- result2 = result;
- }
- return result2;
- }
-
- protected String getNonEmptyParameterValue(String paramName) {
- String[] paramValues = parameters.get(paramName);
- String result = null;
- if (paramValues != null && paramValues.length == 1) {
- String paramValue = paramValues[0];
- if (StringUtils.isNotEmpty(paramValue)) {
- result = paramValue;
- }
- }
- return result;
- }
-
private <E extends Enum<E> & I18nAble> Map<String, String> decorateToName(E... values) {
Map<String, String> result = Maps.newLinkedHashMap();
for (E value : values) {
@@ -795,17 +309,4 @@
}
return result;
}
-
- private static class StringStartWithPredicate implements Predicate<String> {
- private final String prefix;
-
- public StringStartWithPredicate(String prefix) {
- this.prefix = prefix;
- }
-
- @Override
- public boolean apply(String input) {
- return input.startsWith(prefix);
- }
- }
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayPersonToList.java 2012-04-05 23:47:56 UTC (rev 3236)
@@ -23,16 +23,12 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.business.persistence.PersonToList;
import org.chorem.pollen.services.impl.PollService;
import org.chorem.pollen.ui.actions.PollenActionSupport;
-import java.util.Map;
-
/**
* To display a personToList (use at a poll creation).
*
@@ -64,8 +60,8 @@
return personToListTokenId + "_error_" + personToListNumber;
}
- /** Where to find dynamic data (says choices in this case). */
- protected String tokenId;
+ /** Type of the voting list. */
+ protected String votingListType;
/** Number of the vontingList container. */
protected int votingListNumber;
@@ -75,14 +71,6 @@
protected PersonToList personToList;
- public String getTokenId() {
- return tokenId;
- }
-
- public void setTokenId(String tokenId) {
- this.tokenId = tokenId;
- }
-
public int getVotingListNumber() {
return votingListNumber;
}
@@ -91,6 +79,14 @@
this.votingListNumber = votingListNumber;
}
+ public String getVotingListType() {
+ return votingListType;
+ }
+
+ public void setVotingListType(String votingListType) {
+ this.votingListType = votingListType;
+ }
+
public int getPersonToListNumber() {
return personToListNumber;
}
@@ -105,49 +101,26 @@
@Override
public String execute() throws Exception {
- if (StringUtils.isNotEmpty(tokenId)) {
- Map<Integer, PersonToList> personToLists =
- getPollenSession().getDynamicData(tokenId);
-
- if (personToLists != null) {
-
- // get choices from datas
- personToList = personToLists.get(personToListNumber);
-
- if (personToList != null) {
-
- // remove this choice from session
- personToLists.remove(personToListNumber);
- }
- }
-
- if (MapUtils.isEmpty(personToLists)) {
-
- // remove it from session
- getPollenSession().removeDynamicData(tokenId);
- }
- }
-
if (personToList == null) {
personToList = newService(PollService.class).getNewPersonToList(null);
}
- // consume personToList errors
- String token = getPersonToListErrorTokenId(tokenId, personToListNumber);
- Map<String, String> errors = getPollenSession().getDynamicData(token);
- if (MapUtils.isNotEmpty(errors)) {
- // transmit them as field errors
- for (Map.Entry<String, String> e : errors.entrySet()) {
- String fieldName = e.getKey();
- String errorMessage = e.getValue();
- if (log.isInfoEnabled()) {
- log.info("Transmit error on " + fieldName + " [" + errorMessage + "]");
- }
- addFieldError(fieldName, errorMessage);
- }
- }
- getPollenSession().removeDynamicData(token);
+// // consume personToList errors
+// String token = getPersonToListErrorTokenId(tokenId, personToListNumber);
+// Map<String, String> errors = getPollenSession().getDynamicData(token);
+// if (MapUtils.isNotEmpty(errors)) {
+// // transmit them as field errors
+// for (Map.Entry<String, String> e : errors.entrySet()) {
+// String fieldName = e.getKey();
+// String errorMessage = e.getValue();
+// if (log.isInfoEnabled()) {
+// log.info("Transmit error on " + fieldName + " [" + errorMessage + "]");
+// }
+// addFieldError(fieldName, errorMessage);
+// }
+// }
+// getPollenSession().removeDynamicData(token);
return SUCCESS;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java 2012-04-05 23:47:56 UTC (rev 3236)
@@ -23,16 +23,12 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import com.google.common.base.Function;
+import org.chorem.pollen.business.persistence.PersonToList;
import org.chorem.pollen.business.persistence.VotingList;
-import org.chorem.pollen.business.persistence.VotingListImpl;
+import org.chorem.pollen.services.PollenServiceFunctions;
import org.chorem.pollen.ui.actions.PollenActionSupport;
-import java.util.Map;
-
/**
* To display a voting list of a poll (use at a poll creation).
*
@@ -45,42 +41,45 @@
public static final String VOTING_LIST_TOKEN = "votingList";
- /** Logger. */
- private static final Log log = LogFactory.getLog(DisplayVotingList.class);
+// /** Logger. */
+// private static final Log log = LogFactory.getLog(DisplayVotingList.class);
public static String getVotingListErrorTokenId(String votingListTokenId,
int votingListNumber) {
return votingListTokenId + "_" + votingListNumber + "_errors";
}
- /** Where to find dynamic data (says choices in this case). */
- protected String tokenId;
+// /** Where to find dynamic data (says choices in this case). */
+// protected String tokenId;
+ /** Type of the voting list. */
+ protected String votingListType;
+
/** Number of person to display. */
protected int votingListNumber;
- /** Count of personToList for this votingList. */
- protected int nbPersonToLists;
+// /** Count of personToList for this votingList. */
+// protected int nbPersonToLists;
/** The voting list ot display. */
protected VotingList votingList;
- public String getPersonToListTokenId() {
- return DisplayPersonToList.getPersonToListTokenId(tokenId, votingListNumber);
- }
+// public String getPersonToListTokenId() {
+// return DisplayPersonToList.getPersonToListTokenId(tokenId, votingListNumber);
+// }
+//
+// public int getNbPersonToLists() {
+// return nbPersonToLists;
+// }
- public int getNbPersonToLists() {
- return nbPersonToLists;
- }
+// public String getTokenId() {
+// return tokenId;
+// }
+//
+// public void setTokenId(String tokenId) {
+// this.tokenId = tokenId;
+// }
- public String getTokenId() {
- return tokenId;
- }
-
- public void setTokenId(String tokenId) {
- this.tokenId = tokenId;
- }
-
public int getVotingListNumber() {
return votingListNumber;
}
@@ -93,58 +92,76 @@
return votingList;
}
+ public String getVotingListType() {
+ return votingListType;
+ }
+
+ public void setVotingListType(String votingListType) {
+ this.votingListType = votingListType;
+ }
+
@Override
public String execute() throws Exception {
- if (StringUtils.isNotEmpty(tokenId)) {
- Map<Integer, VotingList> votingLists =
- getPollenSession().getDynamicData(tokenId);
+ Function<PersonToList, PersonToList> persontoListCreator =
+ PollenServiceFunctions.newPersonToListCreator(
+ false, serviceContext);
+ Function<VotingList, VotingList> votingListCreator =
+ PollenServiceFunctions.newVotingListCreator(
+ false, serviceContext, persontoListCreator);
- if (votingLists != null) {
+// if (StringUtils.isNotEmpty(tokenId)) {
+//
+// Map<Integer, VotingList> votingLists =
+// getPollenSession().getDynamicData(tokenId);
+//
+// if (votingLists != null) {
+//
+// // get choices from datas
+// votingList = votingLists.get(votingListNumber);
+//
+// if (votingList != null) {
+//
+// // remove this choice from session
+// votingLists.remove(votingListNumber);
+// }
+// }
+//
+// if (MapUtils.isEmpty(votingLists)) {
+//
+// // remove it from session
+// getPollenSession().removeDynamicData(tokenId);
+// }
+// }
- // get choices from datas
- votingList = votingLists.get(votingListNumber);
+ votingList = votingListCreator.apply(null);
+// if (votingList == null) {
+//
- if (votingList != null) {
+// nbPersonToLists = 5;
+// }
+// else {
+// nbPersonToLists = votingList.sizePollAccountPersonToList();
+// }
- // remove this choice from session
- votingLists.remove(votingListNumber);
- }
- }
+ PollenServiceFunctions.fillVotingList(votingList,
+ persontoListCreator, 5);
- if (MapUtils.isEmpty(votingLists)) {
-
- // remove it from session
- getPollenSession().removeDynamicData(tokenId);
- }
- }
-
- if (votingList == null) {
- votingList = new VotingListImpl();
- votingList.setWeight(1);
-
- //TODO tchemit use a default value from configuration
- nbPersonToLists = 5;
- } else {
- nbPersonToLists = votingList.sizePollAccountPersonToList();
- }
- nbPersonToLists = Math.max(5, nbPersonToLists);
-
- // consume votingList errors
- String token = getVotingListErrorTokenId(tokenId, votingListNumber);
- Map<String, String> errors = getPollenSession().getDynamicData(token);
- if (MapUtils.isNotEmpty(errors)) {
- // transmit them as field errors
- for (Map.Entry<String, String> e : errors.entrySet()) {
- String fieldName = e.getKey();
- String errorMessage = e.getValue();
- if (log.isInfoEnabled()) {
- log.info("Transmit error on " + fieldName + " [" + errorMessage + "]");
- }
- addFieldError(fieldName, errorMessage);
- }
- }
- getPollenSession().removeDynamicData(token);
+// // consume votingList errors
+// String token = getVotingListErrorTokenId(tokenId, votingListNumber);
+// Map<String, String> errors = getPollenSession().getDynamicData(token);
+// if (MapUtils.isNotEmpty(errors)) {
+// // transmit them as field errors
+// for (Map.Entry<String, String> e : errors.entrySet()) {
+// String fieldName = e.getKey();
+// String errorMessage = e.getValue();
+// if (log.isInfoEnabled()) {
+// log.info("Transmit error on " + fieldName + " [" + errorMessage + "]");
+// }
+// addFieldError(fieldName, errorMessage);
+// }
+// }
+// getPollenSession().removeDynamicData(token);
return SUCCESS;
}
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-05 23:47:56 UTC (rev 3236)
@@ -1,19 +1,39 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
package org.chorem.pollen.ui.actions.poll;
import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
-import com.opensymphony.xwork2.Preparable;
-import org.chorem.pollen.bean.PollImageChoice;
+import org.apache.commons.collections.CollectionUtils;
import org.chorem.pollen.bean.PollUri;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.PersonToList;
-import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.VotingList;
-import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
+import org.chorem.pollen.services.PollenServiceFunctions;
import java.util.List;
@@ -22,18 +42,29 @@
*
* @author fdesbois <desbois(a)codelutin.com>
*/
-public class LoadPoll extends AbstractPollForm implements Preparable {
+public class LoadPoll extends AbstractPollForm {
- private static final String PREFIX_CHOICE = "%sChoice_%d";
+ private static final long serialVersionUID = 1L;
- private static final String PREFIX_VOTING_LIST = "votingList_%d";
-
- private static final String PREFIX_PERSON_TO_LIST = "personToList_%d_%d";
-
private PollUri pollUri;
private boolean clone;
+ /** Text choices. */
+ private List<Choice> textChoices;
+
+ /** Image choices. */
+ private List<Choice> imageChoices;
+
+ /** Date choices. */
+ private List<Choice> dateChoices;
+
+ /** restricted Voting lists. */
+ private List<VotingList> restrictedVotingList;
+
+ /** Group voting lists. */
+ private List<VotingList> groupVotingList;
+
public PollUri getUriId() {
return pollUri;
}
@@ -50,168 +81,145 @@
this.clone = clone;
}
- @Override
- protected Poll initPoll() {
- Poll result;
- if (pollUri != null) {
- result = getPollService().getPollByPollId(pollUri.getPollId());
-
- if (clone) {
- result.setTopiaId(null);
- result.setPollId(serviceContext.createPollenUrlId());
+ public List<Choice> getTextChoices() {
+ return textChoices;
+ }
- // Reset creator but keep userAccount link
- PollAccount creator = result.getCreator();
- creator.setTopiaId(null);
- creator.setAccountId(serviceContext.createPollenUrlId());
- }
-
- } else {
- UserAccount userAccount = getPollenUserAccount();
- result = getPollService().getNewPoll(userAccount);
- }
- return result;
+ public List<Choice> getImageChoices() {
+ return imageChoices;
}
- @Override
- public void prepare() throws Exception {
-
- if (pollUri != null) {
+ public List<Choice> getDateChoices() {
+ return dateChoices;
+ }
- // -- Choice -- //
- ChoiceType choiceType = getPoll().getChoiceType();
- prepareParams(getPoll().getChoice(), withChoicePrefix(choiceType));
+ public List<VotingList> getRestrictedVotingList() {
+ return restrictedVotingList;
+ }
- // -- VotingList -- //
- if (getPoll().getPollType() != PollType.FREE) {
- prepareParams(getPoll().getVotingList(), withVotingListPrefix());
- }
- }
-
- prepareFormPage();
+ public List<VotingList> getGroupVotingList() {
+ return groupVotingList;
}
- private Function<Choice, String> withChoicePrefix(final ChoiceType choiceType) {
- final String choiceTypeName = choiceType.name().toLowerCase();
- return new IndexedFunction<Choice, String>() {
+ @Override
+ public String execute() throws Exception {
- @Override
- protected String apply(Choice input, int index) {
+ prepareFormPage();
- String prefix = String.format(PREFIX_CHOICE, choiceTypeName, index);
- if (!clone) {
- putParameter(prefix, Choice.TOPIA_ID, input.getTopiaId());
- }
- putParameter(prefix, Choice.PROPERTY_NAME, input.getName());
- putParameter(prefix, Choice.PROPERTY_DESCRIPTION, input.getDescription());
+ textChoices = Lists.newArrayList();
+ imageChoices = Lists.newArrayList();
+ dateChoices = Lists.newArrayList();
+ restrictedVotingList = Lists.newArrayList();
+ groupVotingList = Lists.newArrayList();
- if (choiceType == ChoiceType.IMAGE) {
- putParameter(prefix, PollImageChoice.PROPERTY_LOCATION, input.getName());
- }
+ Function<PersonToList, PersonToList> persontoListCreator =
+ PollenServiceFunctions.newPersonToListCreator(clone, serviceContext);
+ Function<VotingList, VotingList> votingListCreator =
+ PollenServiceFunctions.newVotingListCreator(clone,
+ serviceContext,
+ persontoListCreator);
- return prefix;
- }
- };
- }
+ Function<Choice, Choice> textChoiceCreator =
+ PollenServiceFunctions.newTextChoiceCreator(clone);
+ Function<Choice, Choice> dateChoiceCreator =
+ PollenServiceFunctions.newDateChoiceCreator(clone);
+ Function<Choice, Choice> imageChoiceCreator =
+ PollenServiceFunctions.newImageChoiceCreator(clone);
- private Function<VotingList, String> withVotingListPrefix() {
- return new IndexedFunction<VotingList, String>() {
+ if (pollUri == null) {
- @Override
- protected String apply(VotingList input, int index) {
+ // create a new poll
- String prefix = String.format(PREFIX_VOTING_LIST, index);
- if (!clone) {
- putParameter(prefix, VotingList.TOPIA_ID, input.getTopiaId());
- }
- putParameter(prefix, VotingList.PROPERTY_NAME, input.getName());
- putParameter(prefix, VotingList.PROPERTY_WEIGHT, String.valueOf(input.getWeight()));
+ UserAccount userAccount = getPollenUserAccount();
+ poll = getPollService().getNewPoll(userAccount);
+ } else {
- prepareParams(input.getPollAccountPersonToList(), withPersonToListPrefix(index));
+ // update or clone an existing poll
- return prefix;
+ poll = getPollService().getPollByPollId(pollUri.getPollId());
+
+ if (clone) {
+
+ poll.setTopiaId(null);
+ poll.setPollId(serviceContext.createPollenUrlId());
+
+ // Reset creator but keep userAccount link
+ PollAccount creator = poll.getCreator();
+ creator.setTopiaId(null);
+ creator.setAccountId(serviceContext.createPollenUrlId());
}
- };
- }
- private Function<PersonToList, String> withPersonToListPrefix(final int votingListIndex) {
- return new IndexedFunction<PersonToList, String>() {
+ // -- Choice -- //
+ if (!poll.isChoiceEmpty()) {
- @Override
- protected String apply(PersonToList input, int index) {
+ // reload choices
- PollAccount pollAccount = input.getPollAccount();
+ switch (poll.getChoiceType()) {
- String prefix = String.format(PREFIX_PERSON_TO_LIST, votingListIndex, index);
- String accountId;
- if (!clone) {
- putParameter(prefix, PersonToList.TOPIA_ID, input.getTopiaId());
- accountId = pollAccount.getAccountId();
- } else {
- accountId = serviceContext.createPollenUrlId();
+ case TEXT:
+ textChoices.addAll(Lists.transform(poll.getChoice(), textChoiceCreator));
+ break;
+ case DATE:
+ dateChoices.addAll(Lists.transform(poll.getChoice(), dateChoiceCreator));
+ break;
+ case IMAGE:
+ imageChoices.addAll(Lists.transform(poll.getChoice(), imageChoiceCreator));
+ break;
}
- putParameter(prefix, PersonToList.PROPERTY_WEIGHT, String.valueOf(input.getWeight()));
- putParameter(prefix, PollAccount.PROPERTY_ACCOUNT_ID, accountId);
- putParameter(prefix, PollAccount.PROPERTY_VOTING_ID, pollAccount.getVotingId());
- putParameter(prefix, PollAccount.PROPERTY_EMAIL, pollAccount.getEmail());
+ }
- return prefix;
+ // -- VotingList -- //
+ if (poll.getPollType() != PollType.FREE) {
+
+ // reload voting lists
+ if (!poll.isVotingListEmpty()) {
+ switch (poll.getPollType()) {
+
+ case FREE:
+ // nothing to load
+ break;
+ case RESTRICTED:
+ restrictedVotingList.addAll(Lists.transform(
+ poll.getVotingList(), votingListCreator));
+ break;
+ case GROUP:
+ groupVotingList.addAll(Lists.transform(
+ poll.getVotingList(), votingListCreator));
+ break;
+ }
+
+ }
}
- };
- }
+ }
- /**
- * Prepare the {@code source} for parameters using the {@code function} to
- * push necessary data.
- *
- * @param source List of elements
- * @param function Function used to push element data using {@link #putParameter(String, String, String)}
- * @param <T> Type of data
- * @see #putParameter(String, String, String)
- */
- private <T> void prepareParams(List<T> source, Function<T, String> function) {
- ImmutableList.copyOf(Lists.transform(source, function));
- }
+ if (!isVoteStarted()) {
- /**
- * Put some data in the {@code parameters} with name built using
- * {@code prefix} and {@code property}. The {@code value} will be put for
- * this parameter.
- *
- * @param prefix Prefix to use for the parameter name
- * @param property Name of the {@code property} to push in parameters
- * @param value Value of this {@code property}
- */
- private void putParameter(String prefix, String property, String value) {
- parameters.put(prefix + "." + property, new String[]{value});
- }
+ // can edit choices and voting lists, so fill them
- /**
- * Guava {@link Function} that keeps index on each {@link Function#apply(Object)} call.
- * You just have to implement {@link #apply(Object, int)} to have the current
- * index of the {@code input} value.
- *
- * @param <F> Type of data where function will be applied on
- * @param <T> Resulting type
- */
- private abstract static class IndexedFunction<F, T> implements Function<F, T> {
+ int defaultMaxChoices = 5;
+ PollenServiceFunctions.fillChoiceList(textChoices, defaultMaxChoices, textChoiceCreator);
+ PollenServiceFunctions.fillChoiceList(dateChoices, defaultMaxChoices, dateChoiceCreator);
+ PollenServiceFunctions.fillChoiceList(imageChoices, defaultMaxChoices, imageChoiceCreator);
- private int index;
-
- @Override
- public T apply(F input) {
- T result = apply(input, index);
- index++;
- return result;
+ int defaultMaxVoting = 5;
+ if (CollectionUtils.isEmpty(restrictedVotingList)) {
+ restrictedVotingList.add(votingListCreator.apply(null));
+ }
+ for (VotingList votingList : restrictedVotingList) {
+ PollenServiceFunctions.fillVotingList(votingList,
+ persontoListCreator,
+ defaultMaxVoting);
+ }
+ if (CollectionUtils.isEmpty(groupVotingList)) {
+ groupVotingList.add(votingListCreator.apply(null));
+ }
+ for (VotingList votingList : groupVotingList) {
+ PollenServiceFunctions.fillVotingList(votingList,
+ persontoListCreator,
+ defaultMaxVoting);
+ }
}
+ return SUCCESS;
+ }
- /**
- * Called during {@link #apply(Object)} method with current {@code index}.
- *
- * @param input current value
- * @param index current index
- * @return the result of the function applied on the {@code input} object
- */
- protected abstract T apply(F input, int index);
- }
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-05 23:47:56 UTC (rev 3236)
@@ -23,29 +23,51 @@
*/
package org.chorem.pollen.ui.actions.poll;
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.opensymphony.xwork2.Preparable;
+import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.interceptor.ParameterAware;
import org.chorem.pollen.bean.ChoiceHelper;
+import org.chorem.pollen.bean.PollDateChoice;
+import org.chorem.pollen.bean.PollImageChoice;
import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.business.persistence.ChoiceImpl;
import org.chorem.pollen.business.persistence.PersonToList;
+import org.chorem.pollen.business.persistence.PersonToListImpl;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.business.persistence.PollAccountImpl;
import org.chorem.pollen.business.persistence.PreventRule;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.VotingList;
+import org.chorem.pollen.business.persistence.VotingListImpl;
import org.chorem.pollen.common.ChoiceType;
+import org.chorem.pollen.common.PollType;
+import org.chorem.pollen.services.PollenServiceFunctions;
import org.chorem.pollen.services.impl.PollService;
import org.chorem.pollen.services.impl.PreventRuleService;
import org.chorem.pollen.services.impl.UserService;
+import org.chorem.pollen.ui.actions.FileUploadAware;
import org.nuiton.util.StringUtil;
+import java.io.File;
+import java.text.ParseException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Creates a new poll.
@@ -53,46 +75,244 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
-public class SavePoll extends AbstractPollForm implements Preparable {
+public class SavePoll extends AbstractPollForm implements Preparable, ParameterAware, FileUploadAware {
private static final long serialVersionUID = 1L;
/** Logger. */
private static final Log log = LogFactory.getLog(SavePoll.class);
-
+
+ private static final Pattern TEXT_CHOICE_NAME_PATTERN =
+ Pattern.compile("textChoice_(\\d+)\\.name");
+
+ private static final Pattern DATE_CHOICE_NAME_PATTERN =
+ Pattern.compile("dateChoice_(\\d+)\\.name");
+
+ private static final Pattern IMAGE_CHOICE_NAME_PATTERN =
+ Pattern.compile("imageChoice_(\\d+)\\.name");
+
+// private static final Pattern VOTING_LIST_NAME_PATTERN =
+// Pattern.compile("votingList_(\\d+)\\.name");
+
private String userId;
-
- private String pollId;
+ /** Uploaded images (for choice type poll). */
+ private List<File> imageChoice;
+
+ /** Uploaded images content type (for choice type poll). */
+ private List<String> imageChoiceContentType;
+
+ /** Uploaded images name (from use desktop) (for choice type poll). */
+ private List<String> imageChoiceFileName;
+
+ protected boolean informationsError;
+
+ protected boolean optionsError;
+
+ /**
+ * All the parameters send by request used to build back choices of the
+ * poll.
+ */
+ protected Map<String, String[]> parameters;
+
+ /**
+ * Indexed choices retreive from parameters for the choiceType selected in
+ * form. (Other choices are lost).
+ */
+ private Map<Integer, Choice> choices;
+
+ /**
+ * Indexed voting lists retreive from parameters the pollType selected in
+ * form . (Other voting lists are lost).
+ */
+ private Map<Integer, VotingList> votingLists;
+
+ /** Text choices. */
+ private List<Choice> textChoices;
+
+ /** Image choices. */
+ private List<Choice> imageChoices;
+
+ /** Date choices. */
+ private List<Choice> dateChoices;
+
+ /** restricted Voting lists. */
+ private List<VotingList> restrictedVotingList;
+
+ /** Group voting lists. */
+ private List<VotingList> groupVotingList;
+
public void setUserId(String userId) {
this.userId = userId;
}
+ public List<Choice> getTextChoices() {
+ return textChoices;
+ }
+
+ public List<Choice> getImageChoices() {
+ return imageChoices;
+ }
+
+ public List<Choice> getDateChoices() {
+ return dateChoices;
+ }
+
+ public List<VotingList> getRestrictedVotingList() {
+ return restrictedVotingList;
+ }
+
+ public List<VotingList> getGroupVotingList() {
+ return groupVotingList;
+ }
+
@Override
- protected Poll initPoll() {
- Poll result;
+ public void prepare() throws Exception {
+
+ prepareFormPage();
+
+ String pollId = getNonEmptyParameterValue("poll.topiaId");
+
if (pollId != null) {
- result = getPollService().getEntityById(Poll.class, pollId);
-
+ poll = getPollService().getEntityById(Poll.class, pollId);
+
} else {
UserAccount userAccount = getPollenUserAccount();
- result = getPollService().getNewPoll(userAccount);
+ poll = getPollService().getNewPoll(userAccount);
}
- return result;
+
+ // Retrieve choiceType from parameters, the poll object will be updated after prepare
+ String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType");
+ ChoiceType pollChoiceType = ChoiceType.valueOf(choiceTypeParam);
+ poll.setChoiceType(pollChoiceType);
+
+ // build poll choices
+
+ switch (pollChoiceType) {
+
+ case TEXT:
+
+ choices = buildTextChoices();
+ break;
+ case DATE:
+
+ choices = buildDateChoices();
+ break;
+ case IMAGE:
+
+ choices = buildImageChoices();
+ break;
+ }
+
+ String pollTypeParam = getNonEmptyParameterValue("poll.pollType");
+ PollType pollType = PollType.valueOf(pollTypeParam);
+ poll.setPollType(pollType);
+
+ switch (pollType) {
+
+ case FREE:
+
+ // empty voting list
+ votingLists = Maps.newTreeMap();
+
+ break;
+ case RESTRICTED:
+
+ // restricted voting list
+ votingLists = buildVotingLists(pollType);
+ break;
+ case GROUP:
+
+ // group voting lists
+ votingLists = buildVotingLists(pollType);
+
+ break;
+ }
}
@Override
- public void prepare() throws Exception {
+ public String input() {
- pollId = getNonEmptyParameterValue("poll.topiaId");
+ //push back choices
- prepareFormPage();
+ textChoices = Lists.newArrayList();
+ imageChoices = Lists.newArrayList();
+ dateChoices = Lists.newArrayList();
+
+ switch (poll.getChoiceType()) {
+
+ case TEXT:
+ textChoices.addAll(choices.values());
+ break;
+ case DATE:
+ dateChoices.addAll(choices.values());
+ break;
+ case IMAGE:
+ imageChoices.addAll(choices.values());
+ break;
+ }
+
+ // push back voting lists
+
+ restrictedVotingList = Lists.newArrayList();
+ groupVotingList = Lists.newArrayList();
+
+ switch (poll.getPollType()) {
+
+ case FREE:
+ // not voting lists
+ break;
+ case RESTRICTED:
+ restrictedVotingList.addAll(votingLists.values());
+ break;
+ case GROUP:
+ groupVotingList.addAll(votingLists.values());
+ break;
+ }
+
+ // refill lists
+
+ Function<PersonToList, PersonToList> persontoListCreator =
+ PollenServiceFunctions.newPersonToListCreator(false, serviceContext);
+ Function<VotingList, VotingList> votingListCreator =
+ PollenServiceFunctions.newVotingListCreator(false,
+ serviceContext,
+ persontoListCreator);
+
+ Function<Choice, Choice> textChoiceCreator =
+ PollenServiceFunctions.newTextChoiceCreator(false);
+ Function<Choice, Choice> dateChoiceCreator =
+ PollenServiceFunctions.newDateChoiceCreator(false);
+ Function<Choice, Choice> imageChoiceCreator =
+ PollenServiceFunctions.newImageChoiceCreator(false);
+
+ int defaultMaxChoices = 5;
+ PollenServiceFunctions.fillChoiceList(textChoices, defaultMaxChoices, textChoiceCreator);
+ PollenServiceFunctions.fillChoiceList(dateChoices, defaultMaxChoices, dateChoiceCreator);
+ PollenServiceFunctions.fillChoiceList(imageChoices, defaultMaxChoices, imageChoiceCreator);
+
+ int defaultMaxVoting = 5;
+ if (CollectionUtils.isEmpty(restrictedVotingList)) {
+ restrictedVotingList.add(votingListCreator.apply(null));
+ }
+ for (VotingList votingList : restrictedVotingList) {
+ PollenServiceFunctions.fillVotingList(votingList,
+ persontoListCreator,
+ defaultMaxVoting);
+ }
+ if (CollectionUtils.isEmpty(groupVotingList)) {
+ groupVotingList.add(votingListCreator.apply(null));
+ }
+ for (VotingList votingList : groupVotingList) {
+ PollenServiceFunctions.fillVotingList(votingList,
+ persontoListCreator,
+ defaultMaxVoting);
+ }
+ return INPUT;
}
@Override
public void validate() {
-
- Poll poll = getPoll();
informationsError = false;
@@ -101,11 +321,9 @@
addFieldError("poll.title", _("pollen.error.poll.required.title"));
}
-
// validate choices
- Map<Integer, Choice> orderedChoices = getOrderedChoices();
- if (MapUtils.isEmpty(orderedChoices)) {
+ if (MapUtils.isEmpty(choices)) {
// poll must have at least one choice
addFieldError("poll.choices",
@@ -113,13 +331,15 @@
} else {
ChoiceType choiceType = poll.getChoiceType();
- int inputChoicesSize = orderedChoices.size();
+ int inputChoicesSize = choices.size();
Set<Object> choiceValues =
- Sets.newHashSet(ChoiceHelper.toValues(orderedChoices.values(), choiceType));
+ Sets.newHashSet(ChoiceHelper.toValues(choices.values(),
+ choiceType));
if (inputChoicesSize > choiceValues.size()) {
- addFieldError("poll.choices",
- _("pollen.error.poll.detected.duplicate.choice.name"));
+ addFieldError(
+ "poll.choices",
+ _("pollen.error.poll.detected.duplicate.choice.name"));
}
}
@@ -132,7 +352,7 @@
// nothing to validate
} else {
- Map<Integer, VotingList> votingLists = getOrderedVotingLists();
+// Map<Integer, VotingList> votingLists = getOrderedVotingLists();
Set<String> groups = Sets.newHashSet();
Set<String> voters = Sets.newHashSet();
@@ -157,25 +377,25 @@
}
@Override
+ @InputConfig(methodName = "input")
public String execute() throws Exception {
- Poll poll = getPoll();
-
// Clear previous collections to save those from the form
poll.clearChoice();
poll.clearPreventRule();
poll.clearVotingList();
-
+
// Load userAccount from the form
if (!isCreatorUserAccountDefined() && StringUtils.isNotBlank(userId)) {
UserService userService = newService(UserService.class);
- UserAccount userAccount = userService.getEntityById(UserAccount.class, userId);
+ UserAccount userAccount = userService.getEntityById(
+ UserAccount.class, userId);
poll.getCreator().setUserAccount(userAccount);
}
- Map<Integer, Choice> orderedChoices = getOrderedChoices();
+ Map<Integer, Choice> orderedChoices = choices;
for (Integer index : orderedChoices.keySet()) {
Choice choice = orderedChoices.get(index);
@@ -184,7 +404,7 @@
if (!isFreePoll()) {
- Map<Integer, VotingList> votingLists = getOrderedVotingLists();
+// Map<Integer, VotingList> votingLists = getOrderedVotingLists();
for (Integer index : votingLists.keySet()) {
VotingList votingList = votingLists.get(index);
poll.addVotingList(votingList);
@@ -228,29 +448,90 @@
return SUCCESS;
}
- protected Map<Integer, Choice> getOrderedChoices() {
- Map<Integer, Choice> result = null;
- switch (getPoll().getChoiceType()) {
- case TEXT:
- result = getPollenSession().getDynamicData(getTextChoiceTokenId());
- break;
- case DATE:
- result = getPollenSession().getDynamicData(getDateChoiceTokenId());
- break;
- case IMAGE:
- result = getPollenSession().getDynamicData(getImageChoiceTokenId());
- break;
+ @Override
+ public void setFiles(String paramName, List<File> files) {
+ this.imageChoice = Lists.newArrayList(files);
+ }
+
+ @Override
+ public void setFileContentTypes(String paramName, List<String> contentTypes) {
+ this.imageChoiceContentType = Lists.newArrayList(contentTypes);
+ }
+
+ @Override
+ public void setFileNames(String paramName, List<String> fileNames) {
+ this.imageChoiceFileName = Lists.newArrayList(fileNames);
+ }
+
+ @Override
+ public void setParameters(Map<String, String[]> parameters) {
+ this.parameters = parameters;
+ }
+
+ public List<File> getImageChoice() {
+ return imageChoice;
+ }
+
+ public List<String> getImageChoiceContentType() {
+ if (imageChoiceContentType == null) {
+ imageChoiceContentType = Lists.newArrayList();
}
- return result;
+ return imageChoiceContentType;
}
- protected Map<Integer, VotingList> getOrderedVotingLists() {
+ public List<String> getImageChoiceFileName() {
+ if (imageChoiceFileName == null) {
+ imageChoiceFileName = Lists.newArrayList();
+ }
+ return imageChoiceFileName;
+ }
- Map<Integer, VotingList> result = getPollenSession().getDynamicData(
- getVotingListTokenId());
+ public boolean isInformationsError() {
+ return informationsError;
+ }
+
+ public boolean isOptionsError() {
+ return optionsError;
+ }
+
+ public int getSelectedTab() {
+ int result;
+ if (isInformationsError()) {
+ result = 0;
+ } else {
+ if (isOptionsError()) {
+ result = 1;
+ } else {
+ result = 0;
+ }
+ }
return result;
}
+// protected Map<Integer, Choice> getOrderedChoices() {
+// Map<Integer, Choice> result = null;
+//// switch (getPoll().getChoiceType()) {
+//// case TEXT:
+//// result = getPollenSession().getDynamicData(getTextChoiceTokenId());
+//// break;
+//// case DATE:
+//// result = getPollenSession().getDynamicData(getDateChoiceTokenId());
+//// break;
+//// case IMAGE:
+//// result = getPollenSession().getDynamicData(getImageChoiceTokenId());
+//// break;
+//// }
+// return result;
+// }
+
+// protected Map<Integer, VotingList> getOrderedVotingLists() {
+//
+// Map<Integer, VotingList> result = null;
+//// result = getPollenSession().getDynamicData(
+//// getVotingListTokenId());
+// return result;
+// }
+
protected boolean validateVotingList(int votingListNumber,
VotingList votingList,
Set<String> groups,
@@ -308,41 +589,41 @@
// check there is at least one voter
- String persontoListToken = DisplayPersonToList.getPersonToListTokenId(
- getVotingListTokenId(), votingListNumber);
-
- Map<Integer, PersonToList> personToLists =
- getPollenSession().getDynamicData(persontoListToken);
-
- if (MapUtils.isEmpty(personToLists)) {
-
- // no personToList found for unique votingList 0
- errors.put(votingListErrorPrefix,
- _("pollen.error.poll.required.one.personToList"));
- } else {
-
- // check no doublon on voter names
- // check no doublon on voter emails
-
- for (Map.Entry<Integer, PersonToList> entry :
- personToLists.entrySet()) {
-
- result |= validatePersonList(entry.getKey(), entry.getValue(),
- voters, emails);
- }
- }
-
- if (MapUtils.isNotEmpty(errors)) {
-
- // keep errors to display them in correct action
- String errorToken = DisplayVotingList.getVotingListErrorTokenId(
- getVotingListTokenId(), votingListNumber);
- if (log.isInfoEnabled()) {
- log.info("Add " + errors.size() + " errors to " + errorToken);
- }
- getPollenSession().putDynamicData(errorToken, errors);
- result = true;
- }
+// String persontoListToken = DisplayPersonToList.getPersonToListTokenId(
+// getVotingListTokenId(), votingListNumber);
+//
+// Map<Integer, PersonToList> personToLists =
+// getPollenSession().getDynamicData(persontoListToken);
+//
+// if (MapUtils.isEmpty(personToLists)) {
+//
+// // no personToList found for unique votingList 0
+// errors.put(votingListErrorPrefix,
+// _("pollen.error.poll.required.one.personToList"));
+// } else {
+//
+// // check no doublon on voter names
+// // check no doublon on voter emails
+//
+// for (Map.Entry<Integer, PersonToList> entry :
+// personToLists.entrySet()) {
+//
+// result |= validatePersonList(entry.getKey(), entry.getValue(),
+// voters, emails);
+// }
+// }
+//
+// if (MapUtils.isNotEmpty(errors)) {
+//
+// // keep errors to display them in correct action
+// String errorToken = DisplayVotingList.getVotingListErrorTokenId(
+// getVotingListTokenId(), votingListNumber);
+// if (log.isInfoEnabled()) {
+// log.info("Add " + errors.size() + " errors to " + errorToken);
+// }
+// getPollenSession().putDynamicData(errorToken, errors);
+// result = true;
+// }
return result;
}
@@ -412,15 +693,436 @@
}
if (MapUtils.isNotEmpty(errors)) {
- String errorToken =
- DisplayPersonToList.getPersonToListErrorTokenId(
- getVotingListTokenId(), 0, personToListNumber);
+// String errorToken =
+// DisplayPersonToList.getPersonToListErrorTokenId(
+// getVotingListTokenId(), 0, personToListNumber);
+// if (log.isInfoEnabled()) {
+// log.info("Add " + errors.size() + " errors to " + errorToken);
+// }
+// getPollenSession().putDynamicData(errorToken, errors);
+ result = true;
+ }
+ return result;
+ }
+
+ protected Map<Integer, Choice> buildTextChoices() {
+ Map<Integer, Choice> result = Maps.newTreeMap();
+
+ int maxNumber = 0;
+
+ for (String paramName : parameters.keySet()) {
+
+ Matcher matcher = TEXT_CHOICE_NAME_PATTERN.matcher(paramName);
+ if (matcher.matches()) {
+
+ // found a text choice name
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+ if (paramValue != null) {
+
+ // can keep this none empty text choice name
+
+ Integer choiceNumber = Integer.valueOf(matcher.group(1));
+ if (choiceNumber > maxNumber) {
+ maxNumber = choiceNumber;
+ }
+ Choice choice = new ChoiceImpl();
+ createChoice(choice, "textChoice_" + choiceNumber,
+ paramValue);
+ result.put(choiceNumber, choice);
+ }
+ }
+ }
+ result = reindexMap(result, maxNumber);
+
+ int size = result.size();
+// nbTextChoices = Math.max(nbDefault, size);
+ log.info("nbTextChoices (from request) = " + size);
+ logChoice(result);
+ return result;
+ }
+
+ protected Map<Integer, Choice> buildDateChoices() {
+ Map<Integer, Choice> result = Maps.newTreeMap();
+
+ int maxNumber = 0;
+ for (String paramName : parameters.keySet()) {
+
+ Matcher matcher = DATE_CHOICE_NAME_PATTERN.matcher(paramName);
+ if (matcher.matches()) {
+
+ // found a text choice name
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+ if (paramValue != null) {
+
+ // can keep this none empty text choice name
+
+ Integer choiceNumber = Integer.valueOf(matcher.group(1));
+ if (choiceNumber > maxNumber) {
+ maxNumber = choiceNumber;
+ }
+ PollDateChoice choice = new PollDateChoice();
+ createDateChoice(choice,
+ "dateChoice_" + choiceNumber,
+ paramValue);
+ result.put(choiceNumber, choice);
+ }
+ }
+ }
+ result = reindexMap(result, maxNumber);
+
+ int size = result.size();
+// nbDateChoices = Math.max(nbDefault, size);
+ log.info("nbDateChoices (from request) = " + size);
+ logChoice(result);
+ return result;
+ }
+
+ protected Map<Integer, Choice> buildImageChoices() {
+ Map<Integer, Choice> result = Maps.newTreeMap();
+
+ // push back in parameters stuff from uploaded files
+ int index = 0;
+
+ for (String fileName : getImageChoiceFileName()) {
+ if (fileName != null) {
+ parameters.put("imageChoice_" + index + ".name",
+ new String[]{fileName});
+ parameters.put(
+ "imageChoice_" + index + ".location",
+ new String[]{getImageChoice().get(index).getAbsolutePath()});
+ }
+ index++;
+ }
+
+ int maxNumber = 0;
+ for (String paramName : parameters.keySet()) {
+
+ Matcher matcher = IMAGE_CHOICE_NAME_PATTERN.matcher(paramName);
+ if (matcher.matches()) {
+
+ // found an image choice name
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+ if (paramValue != null) {
+
+ // can keep this none empty text choice name
+
+ Integer choiceNumber = Integer.valueOf(matcher.group(1));
+ if (choiceNumber > maxNumber) {
+ maxNumber = choiceNumber;
+ }
+ PollImageChoice choice = new PollImageChoice();
+ createImageChoice(choice,
+ "imageChoice_" + choiceNumber,
+ paramValue);
+
+ result.put(choiceNumber, choice);
+ }
+ }
+ }
+ result = reindexMap(result, maxNumber);
+ int size = result.size();
+// nbImageChoices = Math.max(nbDefault, size);
+ log.info("nbImageChoices (from request) = " + size);
+ logChoice(result);
+ return result;
+ }
+
+ protected Map<Integer, VotingList> buildVotingLists(PollType pollType) {
+ Map<Integer, VotingList> result = Maps.newTreeMap();
+
+ int maxNumber = 0;
+
+ String votingListPrefix = "votingList" + pollType.name();
+
+ // get all votingList_ parameters
+ Set<String> votingListParameterNames = Sets.filter(
+ parameters.keySet(),
+ new StringStartWithPredicate(votingListPrefix));
+
+ Pattern votingListPattern = Pattern.compile(
+ "(" + votingListPrefix + ")_(\\d+)\\.name");
+
+ for (String paramName : votingListParameterNames) {
+
+ Matcher matcher = votingListPattern.matcher(paramName);
+
+ if (matcher.matches()) {
+
+ // found a voting list name
+
+ int votingListNumber = Integer.valueOf(matcher.group(2));
+
+ votingListPrefix += "_" + votingListNumber;
+ buildVotingList(paramName,
+ votingListPrefix,
+ votingListNumber,
+ result
+ );
+ maxNumber = Math.max(maxNumber, votingListNumber);
+ }
+ }
+
+ result = reindexMap(result, maxNumber);
+
+ int size = result.size();
+// nbVotingLists = Math.max(nbDefault, size);
+ log.info("nbVotingList [" + pollType + "] (from request) = " + size);
+
+ // add personToList maps to session (but just now, since votingList
+ // could have been reindex)
+ for (Map.Entry<Integer, VotingList> entry : result.entrySet()) {
+ Integer votingListNumber = entry.getKey();
+ VotingList votingList = entry.getValue();
+
+ if (!votingList.isPollAccountPersonToListEmpty()) {
+ List<PersonToList> personToList =
+ votingList.getPollAccountPersonToList();
+
+ Map<Integer, PersonToList> personToListMap = Maps.newTreeMap();
+ int index = 0;
+ for (PersonToList toList : personToList) {
+ personToListMap.put(index++, toList);
+ }
+
+// String token = DisplayPersonToList.getPersonToListTokenId(
+// votingListTokenId, votingListNumber);
+// if (log.isInfoEnabled()) {
+// log.info("Add " + token + " with " +
+// personToListMap.size() + " personToList");
+// }
+// getPollenSession().putDynamicData(token, personToListMap);
+ }
+ }
+
+ return result;
+ }
+
+ private double getDoubleValue(String parameterName) {
+ String parameterValue = getNonEmptyParameterValue(parameterName);
+ double result = 0;
+ if (StringUtils.isNotEmpty(parameterValue)) {
+
+ try {
+ result = Double.valueOf(parameterValue);
+ } catch (NumberFormatException e) {
+ //bad conversion, will be treated later
+ if (log.isDebugEnabled()) {
+ log.debug("Bad double conversion from param [" +
+ parameterName + "] : " + parameterValue);
+ }
+ }
+ }
+ return result;
+ }
+
+ private int buildVotingList(String votingListParameterName,
+ String votingListPrefix,
+ int votingListNumber,
+ Map<Integer, VotingList> result) {
+
+ String paramValue = getNonEmptyParameterValue(votingListParameterName);
+
+ VotingList votingList = new VotingListImpl();
+
+ votingList.setName(paramValue);
+
+ double weight = getDoubleValue(votingListPrefix + ".weight");
+ votingList.setWeight(weight);
+
+ String topiaId = getNonEmptyParameterValue(votingListPrefix + ".topiaId");
+ votingList.setTopiaId(topiaId);
+
+ result.put(votingListNumber, votingList);
+
+ String personToListPrefix = votingListPrefix + "PersonToList_";
+
+ // get all personToList parameters
+ Set<String> votingListParameterNames = Sets.filter(
+ parameters.keySet(),
+ new StringStartWithPredicate(personToListPrefix));
+
+ Pattern personToListNamePattern = Pattern.compile(
+ personToListPrefix + "(\\d+)\\.votingId");
+
+ Map<Integer, PersonToList> personToLists = Maps.newTreeMap();
+
+ int maxPersonToListNumber = 0;
+
+ // let's build personToList list
+ for (String personToListNameParameter : votingListParameterNames) {
+
+ Matcher matcher = personToListNamePattern.matcher(
+ personToListNameParameter);
+
+ if (matcher.matches()) {
+
+ int personToListNumber = buildPersonToList(
+ personToListPrefix,
+ personToListNameParameter,
+ matcher,
+ votingListNumber,
+ personToLists);
+
+ maxPersonToListNumber = Math.max(maxPersonToListNumber,
+ personToListNumber);
+ }
+ }
+
+ personToLists = reindexMap(personToLists, maxPersonToListNumber);
+
+ for (PersonToList personToList : personToLists.values()) {
+ votingList.addPollAccountPersonToList(personToList);
+ }
+
+ return votingListNumber;
+ }
+
+ private int buildPersonToList(String personToListPrefix,
+ String paramName,
+ Matcher personToListMatcher,
+ int votingListNumber,
+ Map<Integer, PersonToList> result) {
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+
+ int personToListNumber = 0;
+
+ if (paramValue != null) {
+
+ // found a PersonToList none empty name, keep it
+
+ personToListNumber = Integer.valueOf(personToListMatcher.group(1));
+
+ PersonToList personToList = new PersonToListImpl();
+
+ PollAccount account = new PollAccountImpl();
+ personToList.setPollAccount(account);
+
+ account.setVotingId(paramValue);
+
+ String prefix = personToListPrefix + personToListNumber;
+
+ double weight = getDoubleValue(prefix + ".weight");
+ personToList.setWeight(weight);
+
+ String topiaId = getNonEmptyParameterValue(prefix + ".topiaId");
+ personToList.setTopiaId(topiaId);
+
+ String email = getNonEmptyParameterValue(prefix + ".email");
+ account.setEmail(email);
+
+ String accountId = getNonEmptyParameterValue(prefix + ".accountId");
+ account.setAccountId(accountId);
+
+ result.put(personToListNumber, personToList);
+ }
+ return personToListNumber;
+ }
+
+ private Choice createImageChoice(PollImageChoice choice,
+ String prefix,
+ String name) {
+ createChoice(choice, prefix, name);
+ String locationName = prefix + ".location";
+ String location = getNonEmptyParameterValue(locationName);
+ choice.setLocation(location);
+ if (log.isInfoEnabled()) {
+ log.info("image location [" + name + "] =" + location);
+ }
+ return choice;
+ }
+
+ private Choice createDateChoice(PollDateChoice choice,
+ String prefix,
+ String name) {
+ createChoice(choice, prefix, name);
+ if (StringUtils.isNotEmpty(name)) {
+ Date date = null;
+ try {
+ date = parseDateTime(name);
+ } catch (ParseException e) {
+ if (log.isErrorEnabled()) {
+ log.error("Unparseable date " + name, e);
+ }
+ }
+ choice.setDate(date);
+ }
+ return choice;
+ }
+
+ private Choice createChoice(Choice choice, String prefix, String name) {
+ String descriptionName = prefix + ".description";
+ String topiaIdName = prefix + ".topiaId";
+ String description = getNonEmptyParameterValue(descriptionName);
+ String topiaId = getNonEmptyParameterValue(topiaIdName);
+ choice.setName(name);
+ choice.setDescription(description);
+ choice.setTopiaId(topiaId);
+ return choice;
+ }
+
+ private void logChoice(Map<Integer, Choice> result) {
+ for (Map.Entry<Integer, Choice> e : result.entrySet()) {
+ Integer choiceId = e.getKey();
+ Choice choice = e.getValue();
if (log.isInfoEnabled()) {
- log.info("Add " + errors.size() + " errors to " + errorToken);
+ log.info("Choice [" + choiceId + "] = " +
+ choice.getName() + " -- " +
+ choice.getDescription());
}
- getPollenSession().putDynamicData(errorToken, errors);
- result = true;
}
+ }
+
+ protected <T> Map<Integer, T> reindexMap(Map<Integer, T> result, int maxNumber) {
+ Map<Integer, T> result2;
+
+ if (maxNumber != result.size() - 1) {
+
+ // means there is a hole inside the result (a empty choice was
+ // submitted)
+
+ // le'ts remove this
+ List<Integer> numbers = Lists.newArrayList(result.keySet());
+
+ Collections.sort(numbers);
+
+ result2 = Maps.newTreeMap();
+ int i = 0;
+ for (Integer number : numbers) {
+ T choice = result.get(number);
+ result2.put(i++, choice);
+ }
+ } else {
+ result2 = result;
+ }
+ return result2;
+ }
+
+ protected String getNonEmptyParameterValue(String paramName) {
+ String[] paramValues = parameters.get(paramName);
+ String result = null;
+ if (paramValues != null && paramValues.length == 1) {
+ String paramValue = paramValues[0];
+ if (StringUtils.isNotEmpty(paramValue)) {
+ result = paramValue;
+ }
+ }
return result;
}
+
+ private static class StringStartWithPredicate implements Predicate<String> {
+ private final String prefix;
+
+ public StringStartWithPredicate(String prefix) {
+ this.prefix = prefix;
+ }
+
+ @Override
+ public boolean apply(String input) {
+ return input.startsWith(prefix);
+ }
+ }
}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-04-05 23:47:56 UTC (rev 3236)
@@ -42,47 +42,15 @@
</result-types>
<!-- create poll -->
- <action name="create"
- class="org.chorem.pollen.ui.actions.poll.LoadPoll">
+ <action name="create" class="org.chorem.pollen.ui.actions.poll.LoadPoll">
<result>/WEB-INF/jsp/poll/create.jsp</result>
</action>
<!-- display * -->
- <action name="display*"
- class="org.chorem.pollen.ui.actions.poll.Display{1}">
+ <action name="display*" class="org.chorem.pollen.ui.actions.poll.Display{1}">
<result>/WEB-INF/jsp/poll/{1}.jsp</result>
</action>
- <!--<!– display text choice –>-->
- <!--<action name="displayTextChoice"-->
- <!--class="org.chorem.pollen.ui.actions.poll.DisplayTextChoice">-->
- <!--<result>/WEB-INF/jsp/poll/TextChoice.jsp</result>-->
- <!--</action>-->
-
- <!--<!– display date choice –>-->
- <!--<action name="displayDateChoice"-->
- <!--class="org.chorem.pollen.ui.actions.poll.DisplayDateChoice">-->
- <!--<result>/WEB-INF/jsp/poll/DateChoice.jsp</result>-->
- <!--</action>-->
-
- <!--<!– display image choice –>-->
- <!--<action name="displayImageChoice"-->
- <!--class="org.chorem.pollen.ui.actions.poll.DisplayImageChoice">-->
- <!--<result>/WEB-INF/jsp/poll/ImageChoice.jsp</result>-->
- <!--</action>-->
-
- <!--<!– display a votingList –>-->
- <!--<action name="displayVotingList"-->
- <!--class="org.chorem.pollen.ui.actions.poll.DisplayVotingList">-->
- <!--<result>/WEB-INF/jsp/poll/VotingList.jsp</result>-->
- <!--</action>-->
-
- <!--<!– display a personToList –>-->
- <!--<action name="displayPersonToList"-->
- <!--class="org.chorem.pollen.ui.actions.poll.DisplayPersonToList">-->
- <!--<result>/WEB-INF/jsp/poll/PersonToList.jsp</result>-->
- <!--</action>-->
-
<!-- edit poll -->
<action name="modification/*"
class="org.chorem.pollen.ui.actions.poll.LoadPoll">
@@ -99,8 +67,7 @@
</action>
<!-- save poll -->
- <action name="save"
- class="org.chorem.pollen.ui.actions.poll.SavePoll">
+ <action name="save" class="org.chorem.pollen.ui.actions.poll.SavePoll">
<result name="input">/WEB-INF/jsp/poll/create.jsp</result>
<result>/WEB-INF/jsp/poll/resume.jsp</result>
</action>
@@ -253,7 +220,7 @@
</action>
<!-- Load in session a personList to be imported into a voting list -->
- <action name="displayPersonListToVotingList"
+ <action name="importPersonListToVotingList"
class="org.chorem.pollen.ui.actions.poll.ImportPersonListToVotingList">
<result type="json"/>
</action>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-04-05 23:47:56 UTC (rev 3236)
@@ -43,7 +43,7 @@
<constant name="struts.ui.theme" value="css_xhtml"/>
<constant name="struts.multipart.maxSize" value="209715200"/>
<constant name="struts.enable.SlashesInActionNames" value="true"/>
- <constant name="struts.devMode" value="true"/>
+ <constant name="struts.devMode" value="false"/>
<!--Performance tuning-->
<!--see http://struts.apache.org/2.2.3/docs/performance-tuning.html-->
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/choiceHelper.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/choiceHelper.jsp 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/choiceHelper.jsp 2012-04-05 23:47:56 UTC (rev 3236)
@@ -1,191 +0,0 @@
-<%--
- #%L
- Pollen :: UI (strust2)
-
- $Id$
- $HeadURL$
- %%
- Copyright (C) 2009 - 2012 CodeLutin
- %%
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- #L%
- --%>
-<%@ 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">
-
- var choiceText = '<s:text name="pollen.common.choice"/>';
-
- function getFirstChoice(containerId) {
- var result = 65535;
-
- getAllChoices(containerId).each(function () {
- var currentChoiceNumber = $(this).data('choiceNumber');
- if (currentChoiceNumber < result) {
- result = currentChoiceNumber;
- }
- });
- return result;
- }
-
- function getLastChoice(containerId) {
- var result = 0;
- getAllChoices(containerId).each(function () {
- var currentChoiceNumber = $(this).data('choiceNumber');
- if (currentChoiceNumber > result) {
- result = currentChoiceNumber;
- }
- });
- return result;
- }
-
- function getAllChoices(containerId) {
- return $("div[id^='" + containerId + "_']");
- }
-
- function updateUpdownActions(containerId) {
-
- var firstChoice = getFirstChoice(containerId);
- var lastChoice = getLastChoice(containerId);
-
- getAllChoices(containerId).each(function (index) {
-
- var currentChoiceNumber = $(this).data('choiceNumber');
-
- var labelWidget = $('#' + containerId + "_label_" + currentChoiceNumber);
- labelWidget.html(choiceText + ' ' + (index+1));
-
- /*var upWidget = $('#' + containerId + "_up_" + currentChoiceNumber);
- if (firstChoice == currentChoiceNumber) {
- // hide up
- upWidget.addClass('hidden');
- } else {
- //show up
- upWidget.removeClass('hidden');
- }
-
- var downWidget = $('#' + containerId + "_down_" + currentChoiceNumber);
- if (lastChoice == currentChoiceNumber) {
- // hide down
- downWidget.addClass('hidden');
- } else {
- //show down
- downWidget.removeClass('hidden');
- }*/
- });
-
- }
-
- function loadChoice(containerId, url, choiceNumber, nbChoices, tokenId) {
- if (choiceNumber == -1) {
-
- // to add a new choice
- // get new choiceNumber
-
- choiceNumber = 1 + getLastChoice(containerId);
- }
- $.ajax(
- {
- url:url,
- data:{ tokenId:tokenId, choiceNumber:choiceNumber },
- async:false,
- dataType:"html",
- success:function (data, textStatus) {
- var container = $("#" + containerId);
- container.append(data);
- // store choiceNumber and choiceType
- var choice = $("#" + containerId + "_" + choiceNumber);
- choice.data('choiceType', containerId);
- choice.data('choiceNumber', choiceNumber);
- if (choiceNumber == nbChoices) {
-
- updateUpdownActions(containerId);
- // end it can show it
- var classes = container.attr("class");
- if (classes.indexOf("thischoice") > -1) {
- // show it
- container.removeClass('hidden');
- }
- }
- if (!tokenId) {
- updateUpdownActions(containerId);
- }
- }
- });
- }
-
- function addTextChoice(choiceNumber, nbChoices, tokenId) {
- loadChoice(
- 'choicesTEXT',
- '<s:url namespace="/poll" action="displayTextChoice"/>',
- choiceNumber, nbChoices, tokenId
- );
- }
-
- function addDateChoice(choiceNumber, nbChoices, tokenId) {
- loadChoice(
- 'choicesDATE',
- '<s:url namespace="/poll" action="displayDateChoice"/>',
- choiceNumber, nbChoices, tokenId
- );
- }
-
- function addImageChoice(choiceNumber, nbChoices, tokenId) {
- loadChoice(
- 'choicesIMAGE',
- '<s:url namespace="/poll" action="displayImageChoice"/>',
- choiceNumber, nbChoices, tokenId
- );
- }
-
- function addNewChoice() {
- var type = $('[name="poll.choiceType"][checked="checked"]').val();
- if ("TEXT" == type) {
- addTextChoice(-1, -1);
- } else if ("DATE" == type) {
- addDateChoice(-1, -1);
- } else if ("IMAGE" == type) {
- addImageChoice(-1, -1);
- }
- return false;
- }
-
- function deleteChoice(choiceId) {
- var choice = $('#' + choiceId);
- var containerId = choice.data('choiceType');
- choice.remove();
- updateUpdownActions(containerId);
- return false;
- }
-
- function upChoice(choiceId) {
- var choice = $('#' + choiceId);
- var containerId = choice.data('choiceType');
- var choiceNumber = choice.data('choiceNumber');
- console.info("will up [" + containerId + "-" + choiceNumber + "]");
- updateUpdownActions(containerId);
- return false;
- }
-
- function downChoice(choiceId) {
- var choice = $('#' + choiceId);
- var containerId = choice.data('choiceType');
- var choiceNumber = choice.data('choiceNumber');
- console.info("will down [" + containerId + "-" + choiceNumber + "]");
- updateUpdownActions(containerId);
- return false;
- }
-</script>
\ No newline at end of file
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/PersonToList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/PersonToList.jsp 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/PersonToList.jsp 2012-04-05 23:47:56 UTC (rev 3236)
@@ -24,36 +24,37 @@
<%@ page language="java" contentType="text/html" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
-<s:set name="prefix">personToList_<s:property
- value="votingListNumber"/>_<s:property value="personToListNumber"/>
+<s:set name="personPrefix">votingList<s:property value="votingListType"/>_<s:property value="votingListNumber"/>PersonToList_<s:property value="personToListNumber"/>
</s:set>
-<s:set id='deleteTitle'>
+<s:set name="personToList" value="%{personToList}"/>
+
+<s:set id='deletePersonTitle'>
<s:text name="pollen.action.pollPersonToListDelete"/>
</s:set>
-<s:div id='%{#prefix}'>
+<s:div id='%{#personPrefix}' cssClass="personToList">
<s:fielderror/>
- <s:hidden key='%{#prefix}.topiaId' value='%{personToList.topiaId}' label=''/>
- <s:hidden key='%{#prefix}.accountId' value='%{personToList.pollAccount.accountId}' label=''/>
+ <s:hidden key='%{#personPrefix}.topiaId' value='%{#personToList.topiaId}' label=''/>
+ <s:hidden key='%{#personPrefix}.accountId' value='%{#personToList.pollAccount.accountId}' label=''/>
<div class="fleft choiceName">
- <s:label for="%{#prefix}.votingId" id="%{#prefix}_label" theme="simple"
+ <s:label for="%{#personPrefix}.votingId" id="%{#personPrefix}_label" theme="simple"
value=''/>
- <s:textfield cssClass="nameField" id='%{#prefix}.votingId'
- key="%{#prefix}.votingId" label='' theme="simple"
- value="%{personToList.pollAccount.votingId}"/>
+ <s:textfield cssClass="nameField" id='%{#personPrefix}.votingId'
+ key="%{#personPrefix}.votingId" label='' theme="simple"
+ value="%{#personToList.pollAccount.votingId}"/>
-
- <s:label for="%{#prefix}.email" key="pollen.common.email" theme="simple"/>
- <s:textfield cols="30" id="%{#prefix}.email" key="%{#prefix}.email"
+ <s:label for="%{#personPrefix}.email" key="pollen.common.email" theme="simple"/>
+ <s:textfield cols="30" id="%{#personPrefix}.email" key="%{#personPrefix}.email"
label='' theme="simple" size="30"
- value="%{personToList.pollAccount.email}"/>
+ value="%{#personToList.pollAccount.email}"/>
-
- <s:label for="%{#prefix}.weight" key="pollen.common.weight" theme="simple"/>
- <s:textfield id="%{#prefix}.weight" key="%{#prefix}.weight" size="1"
- label='' theme="simple" value="%{personToList.weight}"/>
+ <s:label for="%{#personPrefix}.weight" key="pollen.common.weight" theme="simple"/>
+ <s:textfield id="%{#personPrefix}.weight" key="%{#personPrefix}.weight" size="1"
+ label='' theme="simple" value="%{#personToList.weight}"/>
</div>
<div class="fright">
- <s:a href='#' onclick="return deletePersonToList('%{#prefix}')">
- <image alt='<s:property value="deleteTitle"/>'
- title='<s:property value="deleteTitle"/>'
+ <s:a href='#' onclick="return deletePersonToList('%{#personPrefix}')">
+ <image alt='<s:property value="%{#deletePersonTitle}"/>'
+ title='<s:property value="%{#deletePersonTitle}"/>'
src="<s:url value='/img/delete.png'/>"></image>
</s:a>
</div>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/VotingList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/VotingList.jsp 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/VotingList.jsp 2012-04-05 23:47:56 UTC (rev 3236)
@@ -24,67 +24,115 @@
<%@ page language="java" contentType="text/html" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
-<s:set name="prefix">votingList_<s:property value="votingListNumber"/></s:set>
-<s:set id='deleteTitle'>
+<s:set name="prefix">votingList<s:property value="votingListType"/>_<s:property
+ value="votingListNumber"/></s:set>
+<s:set name="votingList" value="%{votingList}"/>
+<s:set name="votingListType" value="%{votingListType}"/>
+
+<s:set id='deleteVotingListTitle'>
<s:text name="pollen.action.pollVotingListDelete"/>
</s:set>
-<script type="text/javascript">
- jQuery(document).ready(function () {
- // personToList loading
- <s:iterator begin="1" end="nbPersonToLists" status="status">
- addPersonToList(<s:property value="votingListNumber"/>, <s:property value='%{#status.index}'/>, <s:property value="nbPersonToLists - 1"/>, '<s:property value="personToListTokenId" />');
- </s:iterator>
- });
-</script>
-<s:div id='votingLists_%{votingListNumber}'>
+<s:div id='%{#prefix}' cssClass="votingList">
<fieldset class="ui-widget-content ui-corner-all">
<s:fielderror/>
- <div class="groupPoll">
- <div class="fleft choiceName">
- <s:label for="%{#prefix}.name" theme="simple"
- id="votingLists_%{votingListNumber}_label"/>
- <s:textfield id='%{#prefix}.name' key="%{#prefix}.name" label=''
- theme="simple" value="%{votingList.name}"/>
- -
- <s:label for="%{#prefix}.weight" key="pollen.common.weight"
- theme="simple"/>
- <s:textfield id="%{#prefix}.weight" key="%{#prefix}.weight"
- value="%{votingList.weight}"
- size="1" label='' theme="simple"/>
- </div>
- <div id='<s:property value="%{#prefix}"/>_actions' class="fright">
- <s:a href='#'
- onclick="return deleteVotingList('votingLists_%{votingListNumber}')">
- <image alt='<s:property value="deleteTitle"/>'
- title='<s:property value="deleteTitle"/>'
- src="<s:url value='/img/delete.png'/>"></image>
- </s:a>
- </div>
- <hr/>
- </div>
+ <s:if test='%{#votingListType == "GROUP"}'>
+ <%--<div>--%>
+ <div class="fleft choiceName">
+ <s:label for="%{#prefix}.name" theme="simple" id="%{#prefix}_label"/>
+ <s:textfield id='%{#prefix}.name' key="%{#prefix}.name" label=''
+ theme="simple" value="%{#votingList.name}"/>
+ -
+ <s:label for="%{#prefix}.weight" key="pollen.common.weight"
+ theme="simple"/>
+ <s:textfield id="%{#prefix}.weight" key="%{#prefix}.weight"
+ value="%{#votingList.weight}"
+ size="1" label='' theme="simple"/>
+ </div>
+ <div id='<s:property value="%{#prefix}"/>_actions' class="fright">
+ <s:a href='#' onclick="return deleteVotingList('%{#prefix}')">
+ <image alt='<s:property value="deleteVotingListTitle"/>'
+ title='<s:property value="deleteVotingListTitle"/>'
+ src="<s:url value='/img/delete.png'/>"></image>
+ </s:a>
+ </div>
+ <hr/>
+ <%--</div>--%>
+ </s:if>
+ <s:else>
+ <%--Readd the name even if it is empty to detect voting list--%>
+ <s:hidden key='%{#prefix}.name' label='' value="%{#votingList.name}"/>
+ <s:hidden key='%{#prefix}.weight' label='' value="%{#votingList.weight}"/>
+ </s:else>
<div class="cleanBoth"></div>
- <s:hidden key='%{#prefix}.topiaId' value='%{votingList.topiaId}' label=''/>
+ <s:hidden key='%{#prefix}.topiaId' value='%{#votingList.topiaId}' label=''/>
- <s:div id='personToList_%{votingListNumber}'>
- <%--Where to load personToList--%>
+ <s:div id='%{#prefix}PersonToList'>
+ <s:iterator value="%{#votingList.pollAccountPersonToList}"
+ status="pstatus" var="personToList">
+
+ <s:set name="personToListNumber"><s:property value="%{#pstatus.index}"/></s:set>
+ <s:set name="personPrefix"><s:property value="%{#prefix}"/>PersonToList_<s:property value="%{#personToListNumber}"/></s:set>
+ <%@include file="PersonToList.jsp" %>
+
+ <%--<s:div id='%{#personPrefix}' cssClass="personToList">--%>
+ <%--<s:fielderror/>--%>
+ <%--<s:hidden key='%{#personPrefix}.topiaId'--%>
+ <%--value='%{#personToList.topiaId}' label=''/>--%>
+ <%--<s:hidden key='%{#personPrefix}.accountId'--%>
+ <%--value='%{#personToList.pollAccount.accountId}'--%>
+ <%--label=''/>--%>
+ <%--<div class="fleft choiceName">--%>
+ <%--<s:label for="%{#personPrefix}.votingId"--%>
+ <%--id="%{#personPrefix}_label" theme="simple"--%>
+ <%--value=''/>--%>
+ <%--<s:textfield cssClass="nameField"--%>
+ <%--id='%{#personPrefix}.votingId'--%>
+ <%--key="%{#personPrefix}.votingId" label=''--%>
+ <%--theme="simple"--%>
+ <%--value="%{#personToList.pollAccount.votingId}"/>--%>
+ <%-----%>
+ <%--<s:label for="%{#personPrefix}.email"--%>
+ <%--key="pollen.common.email" theme="simple"/>--%>
+ <%--<s:textfield cols="30" id="%{#personPrefix}.email"--%>
+ <%--key="%{#personPrefix}.email"--%>
+ <%--label='' theme="simple" size="30"--%>
+ <%--value="%{personToList.pollAccount.email}"/>--%>
+ <%-----%>
+ <%--<s:label for="%{#personPrefix}.weight"--%>
+ <%--key="pollen.common.weight" theme="simple"/>--%>
+ <%--<s:textfield id="%{#personPrefix}.weight"--%>
+ <%--key="%{#personPrefix}.weight" size="1"--%>
+ <%--label='' theme="simple"--%>
+ <%--value="%{#personToList.weight}"/>--%>
+ <%--</div>--%>
+ <%--<div class="fright">--%>
+ <%--<s:a href='#'--%>
+ <%--onclick="return deletePersonToList('%{#personPrefix}')">--%>
+ <%--<image alt='<s:property value="deletePersonTitle"/>'--%>
+ <%--title='<s:property value="deletePersonTitle"/>'--%>
+ <%--src="<s:url value='/img/delete.png'/>"></image>--%>
+ <%--</s:a>--%>
+ <%--</div>--%>
+
+ <%--<div class="cleanBoth"></div>--%>
+ <%--</s:div>--%>
+ </s:iterator>
</s:div>
<hr/>
<div class="cleanBoth" align="center">
<s:submit id='%{#prefix}_addPersonToList'
name='%{#prefix}_addPersonToList'
key="pollen.action.addPersonToList" theme="simple"
- onclick='return addNewPersonToList("%{votingListNumber}");'/>
+ onclick='return addNewPersonToList("%{votingListType}","%{#prefix}PersonToList","%{votingListNumber}");'/>
<s:if test="userLoggued">
<s:submit id='%{#prefix}_addPersonToList' theme="simple"
name='%{#prefix}_addPersonToList'
key="pollen.action.addPersonListFromVotingList"
onclick='return selectPersonListToAddToVotingList("%{votingListNumber}");'/>
</s:if>
-
</div>
-
</fieldset>
<br/>
</s:div>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-05 23:47:56 UTC (rev 3236)
@@ -27,157 +27,38 @@
<link rel="stylesheet" type="text/css"
href="<s:url value='/css/pollCreation.css'/>"/>
-<%@include file="/WEB-INF/jsp/choiceHelper.jsp" %>
-<%@include file="/WEB-INF/jsp/votingListHelper.jsp" %>
-
-<s:url id='errorImg' value='/img/exclamation.png'/>
-
<script type="text/javascript">
- function selectPersonListToAddToVotingList(votingListNumber) {
- $('.ui-dialog-title').html('<s:text name="pollen.title.selectPersonListToAddVotingList"/>')
- var dialog = $("#selectPersonListDialog");
- var url = "<s:url action='selectPersonListToAddToVotingList' namespace='/poll'/>";
- url += '?'+ $.param({votingListNumber:votingListNumber});
- dialog.load(url);
- dialog.dialog('open');
- return false;
- }
+ $(document).data(
+ {
+ selectPersonListToAddToVotingListTitle:'<s:text name="pollen.title.selectPersonListToAddVotingList"/>',
+ selectPersonListToCreateNewVotingListTitle:'<s:text name="pollen.title.selectPersonListToCreateVotingList"/>',
- function selectPersonListToCreateNewVotingList() {
- $('.ui-dialog-title').html('<s:text name="pollen.title.selectPersonListToCreateVotingList"/>')
- var dialog = $("#selectPersonListDialog");
- var url = "<s:url action='selectPersonListToCreateNewVotingList' namespace='/poll'/>";
- dialog.load(url);
- dialog.dialog('open');
- return false;
- }
+ votingListText:'<s:text name="pollen.common.votingList"/>',
+ personToListText:'<s:text name="pollen.common.personToList"/>',
+ choiceText:'<s:text name="pollen.common.choice"/>',
- jQuery(document).ready(function () {
- $('[name="poll.choiceAddAllowed"]').change(function (event) {
- var val = $(this).prop('checked');
- if (val) {
- $('#addChoiceAddAllowedPanel').show();
- } else {
- $('#addChoiceAddAllowedPanel').hide();
- }
- });
+ displayVotingListUrl:'<s:url namespace="/poll" action="displayVotingList"/>',
+ displayPersonToListUrl:'<s:url namespace="/poll" action="displayPersonToList"/>',
+ importPersonListToVotingListUrl:'<s:url namespace="/poll" action="importPersonListToVotingList"/>',
+ displayImageChoiceUrl:'<s:url namespace="/poll" action="displayImageChoice"/>',
+ displayDateChoiceUrl:'<s:url namespace="/poll" action="displayDateChoice"/>',
+ displayTextChoiceUrl:'<s:url namespace="/poll" action="displayTextChoice"/>',
+ selectPersonListToAddToVotingListUrl:'<s:url action="selectPersonListToAddToVotingList" namespace="/poll"/>',
+ selectPersonListToCreateNewVotingListUrl:'<s:url action="selectPersonListToCreateNewVotingList" namespace="/poll"/>',
- $('[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="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);
- });
-
- function changeChoiceType(type) {
- $('.choices').addClass('hidden');
- $('.choices').removeClass('thischoice');
- $('#choices' + type).removeClass('hidden');
- $('#choices' + type).addClass('thischoice');
- $('[name="poll.choiceType"]').attr('checked', false);
- $('[name="poll.choiceType"][value="' + type + '"]').attr('checked', 'checked');
+ voteCountingType:'<s:property value="%{poll.voteCountingType.name()}"/>',
+ choiceType:'<s:property value="%{poll.choiceType.name()}"/>',
+ pollType:'<s:property value="%{poll.pollType.name()}"/>'
}
+ );
+</script>
- function changePollType(type, loading) {
+<script type="text/javascript"
+ src='<s:url value="/js/createPoll.js"/>'></script>
- if (!loading) {
+<s:url id='errorImg' value='/img/exclamation.png'/>
- // remove extra votingLists
- var containerId = "votingLists";
- var lastVotingList = getLastVotingList(containerId);
- while (lastVotingList > -1) {
- deleteVotingList(containerId + "_" + lastVotingList);
- lastVotingList -= 1;
- }
- }
-
- if (type == 'FREE') {
-
- // hide everything
- $('.restrictedPoll').addClass("hidden");
- $('.groupPoll').addClass("hidden");
-
- } else if (type == 'RESTRICTED') {
-
- if (!loading) {
- addNewVotingList(containerId);
- }
-
- // show restricted sutff
- $('.restrictedPoll').removeClass("hidden");
- // remove all group stuff
- $('.groupPoll').addClass("hidden");
-
- } else if (type == 'GROUP') {
-
- if (!loading) {
- addNewVotingList(containerId);
- }
-
- $('.restrictedPoll').removeClass("hidden");
- $('.groupPoll').removeClass("hidden");
- }
- }
-
- $('[name="poll.choiceType"]').change(function (event) {
- changeChoiceType($(this).val());
- });
-
- $('[name="poll.pollType"]').change(function (event) {
- changePollType($(this).val(), false);
- });
-
- $('[name="poll.voteCountingType"][value="<s:property value="%{poll.voteCountingType.name()}"/>"]').attr('checked', 'checked');
-
- changeChoiceType('<s:property value="%{poll.choiceType.name()}"/>');
-
- // before loading all choices let's hide everything, it will be shown later
- $('.choices').addClass('hidden');
-
- // text choices loading
- <s:iterator begin="1" end="nbTextChoices" status="status">
- addTextChoice(<s:property value='%{#status.index}'/>, <s:property value="nbTextChoices - 1"/>, '<s:property value="textChoiceTokenId" />');
- </s:iterator>
-
- // date choices loading
- <s:iterator begin="1" end="nbDateChoices" status="status">
- addDateChoice(<s:property value='%{#status.index}'/>, <s:property value="nbDateChoices - 1"/>, '<s:property value="dateChoiceTokenId" />');
- </s:iterator>
-
- // image choices loading
- <s:iterator begin="1" end="nbImageChoices" status="status">
- addImageChoice(<s:property value='%{#status.index}'/>, <s:property value="nbImageChoices - 1"/>, '<s:property value="imageChoiceTokenId" />');
- </s:iterator>
-
- // votingLists loading
- <s:iterator begin="1" end="nbVotingLists" status="status">
- addVotingList(<s:property value='%{#status.index}'/>, <s:property value="nbVotingLists - 1"/>, '<s:property value="votingListTokenId" />');
- </s:iterator>
-
- changePollType('<s:property value="%{poll.pollType.name()}"/>', true);
- });
-</script>
<title><s:text name="pollen.title.createPoll"/></title>
<h1 class="title${pageLogo}"><s:text name="pollen.title.createPoll"/></h1>
@@ -185,7 +66,7 @@
<s:form method="POST" id="registerForm" namespace="/poll"
enctype="multipart/form-data">
- <s:hidden key="poll.topiaId"/>
+ <s:hidden key="poll.topiaId" label=""/>
<sj:tabbedpanel id="formTabs" selectedTab="%{selectedTab}">
@@ -201,7 +82,7 @@
required="true" size="80"/>
<s:textarea key="poll.description" rows="3" cols="54"
label="%{getText('pollen.common.description')}"/>
- <s:hidden key="poll.pollId"/>
+ <s:hidden key="poll.pollId" label=""/>
</fieldset>
<br/>
@@ -213,27 +94,8 @@
</fieldset>
<br/>
- <fieldset>
- <legend><s:text name="pollen.fieldset.poll.choices"/></legend>
- <s:radio key='poll.choiceType' list="choiceTypes" label=''
- theme="simple" disabled="%{voteStarted}"/>
- <hr/>
- <s:fielderror fieldName="poll.choices"/>
+ <%@include file="createPoll_choices.jsp" %>
- <div id="choicesTEXT" class="choices">
- <%--Where to load text choices --%>
- </div>
- <div id="choicesDATE" class="choices">
- <%--Where to load date choices --%>
- </div>
- <div id="choicesIMAGE" class="choices">
- <%--Where to load image choices --%>
- </div>
- <hr/>
- <s:submit key="pollen.action.addChoice" align="center"
- onclick="return addNewChoice();" disabled="%{voteStarted}"/>
- </fieldset>
-
</div>
<div id="toptions">
@@ -244,8 +106,8 @@
label="%{getText('pollen.common.login')}"/>
<s:textfield key="poll.creator.email" size="80"
label="%{getText('pollen.common.email')}"/>
- <s:hidden key="poll.creator.accountId"/>
- <s:hidden key="poll.creator.topiaId"/>
+ <s:hidden key="poll.creator.accountId" label=""/>
+ <s:hidden key="poll.creator.topiaId" label=""/>
<s:if test="creatorUserAccountDefined">
<s:hidden name="userId" value="%{poll.creator.userAccount.topiaId}"/>
</s:if>
@@ -257,15 +119,18 @@
<legend><s:text name="pollen.fieldset.poll.options"/></legend>
<s:checkbox key="poll.anonymous"
- label="%{getText('pollen.common.pollOption.anonymous')}" disabled="%{voteStarted}"/>
+ label="%{getText('pollen.common.pollOption.anonymous')}"
+ disabled="%{voteStarted}"/>
<s:checkbox key="poll.anonymousVoteAllowed"
- label="%{getText('pollen.common.pollOption.anonymousVoteAllowed')}" disabled="%{voteStarted}"/>
+ label="%{getText('pollen.common.pollOption.anonymousVoteAllowed')}"
+ disabled="%{voteStarted}"/>
<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')}" disabled="%{voteStarted}"/>
+ label="%{getText('pollen.common.pollOption.choiceAddAllowed')}"
+ disabled="%{voteStarted}"/>
<div id='addChoiceAddAllowedPanel' class="hidden">
<sj:datepicker key="poll.beginChoiceDate"
label="%{getText('pollen.common.beginChoiceDate')}"
@@ -275,7 +140,8 @@
displayFormat="dd/mm/yy"/>
</div>
<s:checkbox key="limitChoice"
- label="%{getText('pollen.common.pollOption.limitChoice')}" disabled="%{voteStarted}"/>
+ label="%{getText('pollen.common.pollOption.limitChoice')}"
+ disabled="%{voteStarted}"/>
<div id='maxChoiceNbPanel' class="hidden">
<s:textfield key="poll.maxChoiceNb"
label="%{getText('pollen.common.pollOption.maxChoiceNb')}"/>
@@ -295,28 +161,52 @@
<legend><s:text name="pollen.fieldset.poll.general"/></legend>
<sj:datepicker key="poll.beginDate" displayFormat="dd/mm/yy"
- label="%{getText('pollen.common.beginDate')}" disabled="%{voteStarted}"/>
+ label="%{getText('pollen.common.beginDate')}"
+ disabled="%{voteStarted}"/>
<sj:datepicker key="poll.endDate" displayFormat="dd/mm/yy"
label="%{getText('pollen.common.endDate')}"/>
</fieldset>
<br/>
+
+ <%--<%@include file="createPoll_votingLists.jsp" %>--%>
+
<fieldset>
<legend><s:text name="pollen.common.pollType"/></legend>
<s:radio key='poll.pollType' list="pollTypes"
- label='%{getText("pollen.common.pollType")}' disabled="%{voteStarted}"/>
+ label='%{getText("pollen.common.pollType")}'
+ disabled="%{voteStarted}"/>
<hr/>
- <div class="restrictedPoll">
- <div id="votingLists">
- <%--Where to load voting lists --%>
+
+ <div id="pollTypeFREE" class="pollType">
+ <%--Nothing to show for a free poll--%>
+ </div>
+
+ <div id="pollTypeRESTRICTED" class="pollType">
+ <s:iterator value="restrictedVotingList" status="status" var="votingList">
+ <s:set name="votingListNumber"><s:property value="%{#status.index}"/></s:set>
+ <s:set name="votingListType">RESTRICTED</s:set>
+ <%@include file="VotingList.jsp" %>
+ </s:iterator>
+ </div>
+
+ <div id="pollTypeGROUP" class="pollType">
+ <div id="votingListGROUP">
+ <s:iterator value="groupVotingList" status="status" var="votingList">
+ <s:set name="votingListNumber"><s:property value="%{#status.index}"/></s:set>
+ <s:set name="votingListType">GROUP</s:set>
+ <%@include file="VotingList.jsp" %>
+ </s:iterator>
</div>
- <div class="groupPoll" align="center">
+ <div align="center">
<s:submit key="pollen.action.addVotingList" theme="simple"
- onclick="return addNewVotingList();" disabled="%{voteStarted}"/>
+ onclick="return addNewVotingList();"
+ disabled="%{voteStarted}"/>
<s:if test="userLoggued">
<s:submit key="pollen.action.addVotingListFromPersonList"
theme="simple"
- onclick="return selectPersonListToCreateNewVotingList();" disabled="%{voteStarted}"/>
+ onclick="return selectPersonListToCreateNewVotingList();"
+ disabled="%{voteStarted}"/>
</s:if>
</div>
</div>
@@ -326,7 +216,7 @@
</sj:tabbedpanel>
<br/>
- <s:submit action="save" key="pollen.action.savePoll" value="%{actionLabel}" align="center"/>
+ <s:submit action="save" value="%{actionLabel}" align="center"/>
</s:form>
<script type="text/javascript">
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp 2012-04-05 23:47:56 UTC (rev 3236)
@@ -0,0 +1,188 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page language="java" contentType="text/html" pageEncoding="utf-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
+<fieldset>
+ <legend><s:text name="pollen.fieldset.poll.choices"/></legend>
+ <s:radio key='poll.choiceType' list="choiceTypes" label=''
+ theme="simple" disabled="%{voteStarted}"/>
+ <hr/>
+ <s:fielderror fieldName="poll.choices"/>
+
+ <s:set id='deleteTitle'><s:text name="pollen.action.pollChoiceDelete"/></s:set>
+ <s:set id='upTitle'><s:text name="pollen.action.pollChoiceUp"/></s:set>
+ <s:set id='downTitle'><s:text name="pollen.action.pollChoiceDown"/></s:set>
+
+ <div id="choicesTEXT" class="choices">
+ <s:iterator value="textChoices" status="status" var="choice">
+ <s:set name="choiceNumber"><s:property value="%{#status.index}"/></s:set>
+ <s:set name="prefix">textChoice_<s:property value="%{#choiceNumber}"/></s:set>
+ <div id='choicesTEXT_<s:property value="choiceNumber"/>'>
+ <s:hidden key='%{#prefix}.topiaId' value='%{choice.topiaId}' label=''/>
+ <div class="fleft choiceName">
+ <s:label for="%{#prefix}.name" id="choicesTEXT_label_%{#choiceNumber}"
+ theme="simple" value=''/>
+ <s:textfield cssClass="nameField" id='%{#prefix}.name' key="%{#prefix}.name"
+ label='' theme="simple" value="%{#choice.name}"/>
+ -
+ <s:label for="%{#prefix}.description" key="pollen.common.description"
+ theme="simple"/>
+ <%--/div>
+ <div class="fleft"--%>
+ <s:textarea cols="30" id="%{#prefix}.description" label='' theme="simple"
+ key="%{#prefix}.description" value="%{#choice.description}"/>
+ </div>
+ <div class="fright">
+ <s:a href='#' onclick="return deleteChoice('choicesTEXT_%{#choiceNumber}')">
+ <image alt='<s:property value="deleteTitle"/>'
+ title='<s:property value="deleteTitle"/>'
+ src="<s:url value='/img/delete.png'/>"></image>
+ </s:a>
+ <%--s:a id='choicesTEXT_down_%{choiceNumber}'
+ cssClass="hidden" href='#'
+ onclick="return downChoice('choicesTEXT_%{choiceNumber}')">
+ <image alt='<s:property value="downTitle"/>'
+ title='<s:property value="downTitle"/>'
+ src="<s:url value='/img/1downarrow.png'/>"></image>
+ </s:a>
+ <s:a id='choicesTEXT_up_%{choiceNumber}' href='#' cssClass="hidden"
+ onclick="return upChoice('choicesTEXT_%{choiceNumber}')">
+ <image alt='<s:property value="upTitle"/>'
+ title='<s:property value="upTitle"/>'
+ src="<s:url value='/img/1uparrow.png'/>"></image>
+ </s:a--%>
+ </div>
+ <div class="cleanBoth"></div>
+ </div>
+ </s:iterator>
+ </div>
+ <div id="choicesDATE" class="choices">
+ <s:iterator value="dateChoices" status="status" var="choice">
+ <s:set name="choiceNumber"><s:property value="%{#status.index}"/></s:set>
+ <s:set name="prefix">dateChoice_<s:property value="%{#choiceNumber}"/></s:set>
+ <div id='choicesDATE_<s:property value="choiceNumber"/>'>
+ <s:hidden key='%{#prefix}.topiaId' id='%{#prefix}.topiaId'
+ value='%{choice.topiaId}' label='' theme="simple" />
+ <div class="fleft choiceName">
+ <s:label for="%{#prefix}.name" id="choicesDATE_label_%{choiceNumber}"
+ theme="simple" value=''/>
+ <sj:datepicker id='%{#prefix}.name' key="%{#prefix}.name" changeMonth="true"
+ changeYear="true" labelSeparator="" theme="simple" label=""
+ timepicker="true" value="%{choice.date}" displayFormat="dd/mm/yy"/>
+ -
+ <s:label for="%{#prefix}.description" key="pollen.common.description"
+ theme="simple"/>
+ </div>
+ <div class="fleft">
+ <s:textarea cols="30" id="%{#prefix}.description"
+ key="%{#prefix}.description" label='' theme="simple"
+ value="%{choice.description}"/>
+ </div>
+ <div class="fright">
+ <s:a href='#' onclick="return deleteChoice('choicesDATE_%{choiceNumber}')">
+ <image alt='<s:property value="deleteTitle"/>'
+ title='<s:property value="deleteTitle"/>'
+ src="<s:url value='/img/delete.png'/>"></image>
+ </s:a>
+ <%--s:a id='choicesDATE_down_%{choiceNumber}'
+ cssClass="hidden" href='#'
+ onclick="return downChoice('choicesDATE_%{choiceNumber}')">
+ <image alt='<s:property value="downTitle"/>'
+ title='<s:property value="downTitle"/>'
+ src="<s:url value='/img/1downarrow.png'/>"></image>
+ </s:a>
+ <s:a id='choicesDATE_up_%{choiceNumber}' href='#' cssClass="hidden"
+ onclick="return upChoice('choicesDATE_%{choiceNumber}')">
+ <image alt='<s:property value="upTitle"/>'
+ title='<s:property value="upTitle"/>'
+ src="<s:url value='/img/1uparrow.png'/>"></image>
+ </s:a--%>
+ </div>
+ <div class="cleanBoth"></div>
+ </div>
+ </s:iterator>
+ </div>
+ <div id="choicesIMAGE" class="choices">
+ <s:iterator value="imageChoices" status="status" var="choice">
+ <s:set name="choiceNumber"><s:property value="%{#status.index}"/></s:set>
+ <s:set name="prefix">imageChoice_<s:property value="%{#choiceNumber}"/></s:set>
+ <div id='choicesIMAGE_<s:property value="choiceNumber"/>'>
+ <s:hidden key='%{#prefix}.topiaId' value='%{choice.topiaId}' label=''/>
+ <div class="fleft choiceName">
+ <s:label for="%{#prefix}.name" id="choicesIMAGE_label_%{choiceNumber}"
+ theme="simple" value=''/>
+ <s:if test="choice.name != ''">
+
+ <%--Uploaded image--%>
+ <s:hidden id="%{#prefix}.name" name="%{#prefix}.name"
+ value="%{choice.name}" label='' theme="simple"/>
+
+ <s:hidden id="%{#prefix}.location" name="%{#prefix}.location"
+ value="%{choice.location}" label='' theme="simple"/>
+
+ <s:label label='' theme="simple" cssClass="nameField"
+ value="%{choice.name}" readonly="true"/>
+ </s:if>
+ <s:else>
+ <%--New image--%>
+ <s:file key='%{#prefix2}' label='' theme="simple" cssClass="nameField"/>
+ </s:else>
+ -
+ <s:label for="%{#prefix}.description" key="pollen.common.description"
+ theme="simple"/>
+ </div>
+ <div class="fleft">
+ <s:textarea cols="30" id="%{#prefix}.description" label='' theme="simple"
+ key="%{#prefix}.description" value="%{choice.description}"/>
+ </div>
+ <div class="fright">
+ <s:a href='#' onclick="return deleteChoice('choicesIMAGE_%{choiceNumber}')">
+ <image alt='<s:property value="deleteTitle"/>'
+ title='<s:property value="deleteTitle"/>'
+ src="<s:url value='/img/delete.png'/>"></image>
+ </s:a>
+ <%--s:a id='choicesIMAGE_down_%{choiceNumber}'
+ cssClass="hidden" href='#'
+ onclick="return downChoice('choicesIMAGE_%{choiceNumber}')">
+ <image alt='<s:property value="downTitle"/>'
+ title='<s:property value="downTitle"/>'
+ src="<s:url value='/img/1downarrow.png'/>"></image>
+ </s:a>
+ <s:a id='choicesIMAGE_up_%{choiceNumber}' href='#' cssClass="hidden"
+ onclick="return upChoice('choicesIMAGE_%{choiceNumber}')">
+ <image alt='<s:property value="upTitle"/>'
+ title='<s:property value="upTitle"/>'
+ src="<s:url value='/img/1uparrow.png'/>"></image>
+ </s:a--%>
+ </div>
+
+ <div class="cleanBoth"></div>
+ </div>
+ </s:iterator>
+ </div>
+ <hr/>
+ <s:submit key="pollen.action.addChoice" align="center"
+ onclick="return addNewChoice();" disabled="%{voteStarted}"/>
+</fieldset>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp 2012-04-05 07:50:52 UTC (rev 3235)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp 2012-04-05 23:47:56 UTC (rev 3236)
@@ -1,256 +0,0 @@
-<%--
- #%L
- Pollen :: UI (strust2)
-
- $Id$
- $HeadURL$
- %%
- Copyright (C) 2009 - 2012 CodeLutin
- %%
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- #L%
- --%>
-<%@ 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">
-
-var votingListText = '<s:text name="pollen.common.votingList"/>';
-var personToListText = '<s:text name="pollen.common.personToList"/>';
-
-function getFirstVotingList(containerId) {
- var result = 65535;
- getAllVotingLists(containerId).each(function () {
- var current = $(this).data('votingListNumber');
- if (current < result) {
- result = current;
- }
- });
- return result;
-}
-
-function getLastVotingList(containerId) {
- var result = 0;
- getAllVotingLists(containerId).each(function () {
- var current = $(this).data('votingListNumber');
- if (current > result) {
- result = current;
- }
- });
- return result;
-}
-
-function getAllVotingLists(containerId) {
- return $("div[id^='" + containerId + "_']");
-}
-
-function updateUpdownVotingListActions(containerId) {
- getAllVotingLists(containerId).each(function (index) {
- var currentVotingListNumber = $(this).data('votingListNumber');
- var labelWidget = $('#' + containerId + "_" + currentVotingListNumber + "_label");
- labelWidget.html(votingListText + ' ' + (index + 1));
- });
-}
-
-function loadVotingList(containerId, votingListNumber, nbVotingLists, tokenId) {
- if (votingListNumber == -1) {
- // to add a new votingList, get the new available votingListNumber
- votingListNumber = 1 + getLastVotingList(containerId);
- }
- $.ajax(
- {
- url:'<s:url namespace="/poll" action="displayVotingList"/>',
- data:{ tokenId:tokenId, votingListNumber:votingListNumber },
- async:false,
- dataType:"html",
- success:function (data, textStatus) {
- var container = $("#" + containerId);
- container.append(data);
- // store votingListNumber
- var votingList = $("#" + containerId + "_" + votingListNumber);
- votingList.data('votingListNumber', votingListNumber);
- votingList.data('votingListContainerId', containerId);
- if (votingListNumber == nbVotingLists || !tokenId) {
- updateUpdownVotingListActions(containerId);
- }
- }
- });
-}
-
-function addVotingList(votingListNumber, nbVotingLists, tokenId) {
- loadVotingList('votingLists', votingListNumber, nbVotingLists, tokenId);
-}
-
-function addNewVotingList() {
- addVotingList(-1, -1);
- return false;
-}
-
-function deleteVotingList(votingListId) {
- var votingList = $('#' + votingListId);
- var containerId = votingList.data('votingListContainerId');
- votingList.remove();
- updateUpdownVotingListActions(containerId);
- return false;
-}
-
-function getFirstPersonToList(containerId) {
- var result = 65535;
- getAllPersonToLists(containerId).each(function () {
- var current = $(this).data('personToListNumber');
- if (current < result) {
- result = current;
- }
- });
- return result;
-}
-
-function getLastPersonToList(containerId) {
- var result = 0;
- getAllPersonToLists(containerId).each(function () {
- var current = $(this).data('personToListNumber');
- if (current > result) {
- result = current;
- }
- });
- return result;
-}
-
-function getAllPersonToLists(containerId) {
- return $("div[id^='" + containerId + "_']");
-}
-
-function getAllPersonToListNumbers(containerId) {
- var result = [];
- getAllPersonToLists(containerId).each(function () {
- var current = $(this).data('personToListNumber');
- result.push(current);
- });
- return result;
-}
-
-function getFirstEmptyPersonToList(containerId) {
- var result = -1;
- var numbers = getAllPersonToListNumbers(containerId);
- for (var n in numbers) {
- var nameInput = $('[name="' + containerId + '_' + n + '.votingId"]');
- var emailInput = $('[name="' + containerId + '_' + n + '.email"]');
-
- var name = nameInput.val();
- var email = emailInput.val();
- if (name == '' && email == '') {
- result = n;
- break;
- }
- }
- return result;
-}
-
-function updateUpdownPersonToListActions(containerId) {
- getAllPersonToLists(containerId).each(function (index) {
- var currentPersonToListNumber = $(this).data('personToListNumber');
- var labelWidget = $('#' + containerId + "_" + currentPersonToListNumber + "_label");
- labelWidget.html(personToListText + ' ' + (index + 1));
- });
-}
-
-function loadPersonToList(containerId, votingListNumber, personToListNumber, nbPersonToLists, tokenId) {
- if (personToListNumber == -1) {
- // to add a new personToList, get the new available personToListNumber
- personToListNumber = 1 + getLastPersonToList(containerId);
- }
- $.ajax(
- {
- url:'<s:url namespace="/poll" action="displayPersonToList"/>',
- data:{
- tokenId:tokenId,
- votingListNumber:votingListNumber,
- personToListNumber:personToListNumber
- },
- async:false,
- dataType:"html",
- success:function (data, textStatus) {
- var container = $("#" + containerId);
- container.append(data);
- // store personToListNumber
- var personToList = $("#" + containerId + "_" + personToListNumber);
- personToList.data('votingListNumber', votingListNumber);
- personToList.data('personToListNumber', personToListNumber);
- personToList.data('personToListContainerId', containerId);
- if (personToListNumber == nbPersonToLists || !tokenId) {
- updateUpdownPersonToListActions(containerId);
- }
- }
- });
-}
-
-function addPersonToList(votingListNumber, personToListNumber, nbPersonToLists, tokenId) {
- loadPersonToList(
- 'personToList_' + votingListNumber,
- votingListNumber, personToListNumber, nbPersonToLists, tokenId
- );
-}
-
-function addNewPersonToList(votingListNumber) {
- addPersonToList(votingListNumber, -1, -1);
- return false;
-}
-
-function deletePersonToList(personToListId) {
- var personToList = $('#' + personToListId);
- var containerId = personToList.data('personToListContainerId');
- personToList.remove();
- updateUpdownPersonToListActions(containerId);
- return false;
-}
-
-
-function loadPersonListToVotingList(votingListNumber, personToListNumber, personListId) {
-
- $.ajax(
- {
- url:'<s:url namespace="/poll" action="displayPersonListToVotingList"/>',
- data:{
- votingListNumber:votingListNumber,
- personToListNumber:personToListNumber,
- personListId:personListId },
- async:false,
- dataType:"json",
- success:function (data, textStatus) {
- var token = data.tokenId;
- var nbPersonToLists = parseInt(data.nbPersonToLists);
- var personToListNumber = parseInt(data.personToListNumber);
- var maxPersonToListNumber = parseInt(personToListNumber) + nbPersonToLists - 1;
- console.info(">> token = " + token);
- console.info(">> personListId = " + personListId);
- console.info(">> incoming votingListNumber = " + votingListNumber);
- console.info(">> nb personToList to import = " + nbPersonToLists);
- console.info(">> first personToListNumber = " + personToListNumber);
- console.info(">> last PersonToListNumber = " + maxPersonToListNumber);
-
- var index = personToListNumber;
- while (index <= maxPersonToListNumber) {
- console.info("Will load personToList = " + index + " / " + maxPersonToListNumber);
- addPersonToList(votingListNumber,
- index,
- maxPersonToListNumber,
- token
- );
- index += 1;
- }
- }
- });
-}
-</script>
\ No newline at end of file
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/createPoll.js
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/createPoll.js (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/createPoll.js 2012-04-05 23:47:56 UTC (rev 3236)
@@ -0,0 +1,591 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+var datas = $(document).data();
+
+function selectPersonListToAddToVotingList(votingListNumber) {
+ $('.ui-dialog-title').html(datas['selectPersonListToAddToVotingListTitle']);
+ var dialog = $("#selectPersonListDialog");
+ var url = datas['selectPersonListToAddToVotingListUrl'];
+ url += '?' + $.param({votingListNumber:votingListNumber});
+ dialog.load(url);
+ dialog.dialog('open');
+ return false;
+}
+
+function selectPersonListToCreateNewVotingList() {
+ $('.ui-dialog-title').html(datas['selectPersonListToCreateNewVotingListTitle']);
+ var dialog = $("#selectPersonListDialog");
+ var url = datas['selectPersonListToCreateNewVotingListUrl'];
+ dialog.load(url);
+ dialog.dialog('open');
+ return false;
+}
+
+
+//----------------------------------------------------------------------------
+//-- Voting List methods
+//----------------------------------------------------------------------------
+
+/*function getFirstVotingList(containerId) {
+ var result = 65535;
+ getAllVotingLists(containerId).each(function () {
+ var current = $(this).data('votingListNumber');
+ if (current < result) {
+ result = current;
+ }
+ });
+ return result;
+ }*/
+
+function getLastVotingList(containerId) {
+ var result = 0;
+ getAllVotingLists(containerId).each(function () {
+ var current = $(this).data('votingListNumber');
+ if (current > result) {
+ result = current;
+ }
+ });
+ return result;
+}
+
+function getAllVotingLists(containerId) {
+ return $("div[id^='" + containerId + "_'].votingList");
+}
+
+function prepareVotingLists(containerId) {
+
+ getAllVotingLists(containerId).each(function (index) {
+
+ var votingListId = containerId + "_" + index;
+ var votingList = $("#" + votingListId);
+ votingList.data('votingListNumber', index);
+ votingList.data('votingListContainerId', containerId);
+
+ preparePersonToLists(index, votingListId + 'PersonToList');
+
+ });
+ updateUpdownVotingListActions(containerId);
+}
+
+function updateUpdownVotingListActions(containerId) {
+ getAllVotingLists(containerId).each(function (index) {
+ var currentVotingListNumber = $(this).data('votingListNumber');
+ var labelWidget = $('#' + containerId + "_" + currentVotingListNumber + "_label");
+ labelWidget.html(datas['votingListText'] + ' ' + (index + 1));
+ });
+}
+
+function addNewVotingList() {
+
+ var containerId = 'votingListGROUP';
+ var votingListNumber = 1 + getLastVotingList(containerId);
+
+ $.ajax({
+ url:datas['displayVotingListUrl'],
+ data:{
+ votingListType:'GROUP',
+ votingListNumber:votingListNumber
+ },
+ async:false,
+ dataType:"html",
+ success:function (data) {
+ var container = $("#" + containerId);
+ container.append(data);
+ // store votingListNumber
+ var votingListId = containerId + "_" + votingListNumber;
+ var votingList = $("#" + votingListId);
+ votingList.data('votingListNumber', votingListNumber);
+ votingList.data('votingListContainerId', containerId);
+ preparePersonToLists(votingListNumber, votingListId + 'PersonToList');
+ updateUpdownVotingListActions(containerId);
+ }
+ });
+ return false;
+}
+
+function deleteVotingList(votingListId) {
+ var votingList = $('#' + votingListId);
+ var containerId = votingList.data('votingListContainerId');
+ votingList.remove();
+ updateUpdownVotingListActions(containerId);
+ return false;
+}
+
+
+//----------------------------------------------------------------------------
+//-- PersonToList methods
+//----------------------------------------------------------------------------
+
+/*function getFirstPersonToList(containerId) {
+ var result = 65535;
+ getAllPersonToLists(containerId).each(function () {
+ var current = $(this).data('personToListNumber');
+ if (current < result) {
+ result = current;
+ }
+ });
+ return result;
+ }*/
+
+function getLastPersonToList(containerId) {
+ var result = 0;
+ getAllPersonToLists(containerId).each(function () {
+ var current = $(this).data('personToListNumber');
+ if (current > result) {
+ result = current;
+ }
+ });
+ return result;
+}
+
+function getAllPersonToLists(containerId) {
+ return $("div[id^='" + containerId + "_'].personToList");
+}
+
+function getAllPersonToListNumbers(containerId) {
+ var result = [];
+ getAllPersonToLists(containerId).each(function () {
+ var current = $(this).data('personToListNumber');
+ result.push(current);
+ });
+ return result;
+}
+
+/*function getFirstEmptyPersonToList(containerId) {
+ var result = -1;
+ var numbers = getAllPersonToListNumbers(containerId);
+ for (var n in numbers) {
+ var nameInput = $('[name="' + containerId + '_' + n + '.votingId"]');
+ var emailInput = $('[name="' + containerId + '_' + n + '.email"]');
+
+ var name = nameInput.val();
+ var email = emailInput.val();
+ if (name == '' && email == '') {
+ result = n;
+ break;
+ }
+ }
+ return result;
+ }*/
+
+function preparePersonToLists(votingListNumber, containerId) {
+ getAllPersonToLists(containerId).each(function (index) {
+
+ var personToListId = containerId + "_" + index;
+ var personToList = $("#" + personToListId);
+
+ personToList.data('votingListNumber', votingListNumber);
+ personToList.data('personToListNumber', index);
+ personToList.data('personToListContainerId', containerId);
+ });
+ updateUpdownPersonToListActions(containerId);
+}
+function updateUpdownPersonToListActions(containerId) {
+ getAllPersonToLists(containerId).each(function (index) {
+ var currentPersonToListNumber = $(this).data('personToListNumber');
+ var labelWidget = $('#' + containerId + "_" + currentPersonToListNumber + "_label");
+ labelWidget.html(datas['personToListText'] + ' ' + (index + 1));
+ });
+}
+
+function addNewPersonToList(votingListType, containerId, votingListNumber) {
+
+ var personToListNumber = 1 + getLastPersonToList(containerId);
+ $.ajax({
+ url:datas['displayPersonToListUrl'],
+ data:{
+ votingListNumber:votingListNumber,
+ votingListType:votingListType,
+ personToListNumber:personToListNumber
+ },
+ async:false,
+ dataType:"html",
+ success:function (data) {
+ var container = $("#" + containerId);
+ container.append(data);
+ // store personToListNumber
+ var personToList = $("#" + containerId + "_" + personToListNumber);
+ personToList.data('votingListNumber', votingListNumber);
+ personToList.data('personToListNumber', personToListNumber);
+ personToList.data('personToListContainerId', containerId);
+ updateUpdownPersonToListActions(containerId);
+ }
+ });
+ return false;
+}
+
+function addPersonToList(votingListType, containerId, votingListNumber, personToListNumber, nbPersonToLists, tokenId) {
+ loadPersonToList(
+ votingListType,
+ containerId,
+ votingListNumber, personToListNumber, nbPersonToLists, tokenId
+ );
+}
+
+function loadPersonToList(votingListType, containerId, votingListNumber, personToListNumber, nbPersonToLists, tokenId) {
+ if (personToListNumber == -1) {
+ // to add a new personToList, get the new available personToListNumber
+ personToListNumber = 1 + getLastPersonToList(containerId);
+ }
+ $.ajax(
+ {
+ url:datas['displayPersonToListUrl'],
+ data:{
+ tokenId:tokenId,
+ votingListNumber:votingListNumber,
+ votingListType:votingListType,
+ personToListNumber:personToListNumber
+ },
+ async:false,
+ dataType:"html",
+ success:function (data) {
+ var container = $("#" + containerId);
+ container.append(data);
+ // store personToListNumber
+ var personToList = $("#" + containerId + "_" + personToListNumber);
+ personToList.data('votingListNumber', votingListNumber);
+ personToList.data('personToListNumber', personToListNumber);
+ personToList.data('personToListContainerId', containerId);
+ if (personToListNumber == nbPersonToLists || !tokenId) {
+ updateUpdownPersonToListActions(containerId);
+ }
+ }
+ });
+}
+
+function deletePersonToList(personToListId) {
+ var personToList = $('#' + personToListId);
+ var containerId = personToList.data('personToListContainerId');
+ personToList.remove();
+ updateUpdownPersonToListActions(containerId);
+ return false;
+}
+
+function loadPersonListToVotingList(votingListNumber, personToListNumber, personListId) {
+
+ $.ajax(
+ {
+ url:datas['importPersonListToVotingListUrl'],
+ data:{
+ votingListNumber:votingListNumber,
+ personToListNumber:personToListNumber,
+ personListId:personListId },
+ async:false,
+ dataType:"json",
+ success:function (data) {
+ var token = data.tokenId;
+ var nbPersonToLists = parseInt(data['nbPersonToLists']);
+ var personToListNumber = parseInt(data.personToListNumber);
+ var maxPersonToListNumber = parseInt(personToListNumber) + nbPersonToLists - 1;
+ console.info(">> token = " + token);
+ console.info(">> personListId = " + personListId);
+ console.info(">> incoming votingListNumber = " + votingListNumber);
+ console.info(">> nb personToList to import = " + nbPersonToLists);
+ console.info(">> first personToListNumber = " + personToListNumber);
+ console.info(">> last PersonToListNumber = " + maxPersonToListNumber);
+
+ var index = personToListNumber;
+ while (index <= maxPersonToListNumber) {
+ console.info("Will load personToList = " + index + " / " + maxPersonToListNumber);
+ addPersonToList(votingListNumber,
+ index,
+ maxPersonToListNumber,
+ token
+ );
+ index += 1;
+ }
+ }
+ });
+}
+
+
+//----------------------------------------------------------------------------
+//-- Choice methods
+//----------------------------------------------------------------------------
+
+/*function getFirstChoice(containerId) {
+ var result = 65535;
+
+ getAllChoices(containerId).each(function () {
+ var currentChoiceNumber = $(this).data('choiceNumber');
+ if (currentChoiceNumber < result) {
+ result = currentChoiceNumber;
+ }
+ });
+ return result;
+ }*/
+
+function getLastChoice(containerId) {
+ var result = 0;
+ getAllChoices(containerId).each(function () {
+ var currentChoiceNumber = $(this).data('choiceNumber');
+ if (currentChoiceNumber > result) {
+ result = currentChoiceNumber;
+ }
+ });
+ return result;
+}
+
+function getAllChoices(containerId) {
+ return $("div[id^='" + containerId + "_']");
+}
+
+function prepareChoices(containerId) {
+
+ getAllChoices(containerId).each(function (index) {
+
+ var choice = $("#" + containerId + "_" + index);
+ choice.data('choiceType', containerId);
+ choice.data('choiceNumber', index);
+ });
+
+ if (containerId == 'choicesDATE') {
+
+ getAllChoices(containerId).each(function (index) {
+ var choice = $("#" + containerId + "_" + index + " script");
+ $('[id="wwctrl_dateChoice_' + index + '.name"] input').detach().insertBefore(choice);
+ $('[id="wwctrl_dateChoice_' + index + '.name"] button').detach().insertBefore(choice);
+
+ });
+
+ $('#choicesDATE .wwgrp').remove();
+ }
+ updateUpdownActions(containerId);
+}
+
+function updateUpdownActions(containerId) {
+
+// var firstChoice = getFirstChoice(containerId);
+// var lastChoice = getLastChoice(containerId);
+
+ getAllChoices(containerId).each(function (index) {
+
+ var currentChoiceNumber = $(this).data('choiceNumber');
+
+ var labelWidget = $('#' + containerId + "_label_" + currentChoiceNumber);
+ labelWidget.html(datas['choiceText'] + ' ' + (index + 1));
+
+ /*var upWidget = $('#' + containerId + "_up_" + currentChoiceNumber);
+ if (firstChoice == currentChoiceNumber) {
+ // hide up
+ upWidget.addClass('hidden');
+ } else {
+ //show up
+ upWidget.removeClass('hidden');
+ }
+
+ var downWidget = $('#' + containerId + "_down_" + currentChoiceNumber);
+ if (lastChoice == currentChoiceNumber) {
+ // hide down
+ downWidget.addClass('hidden');
+ } else {
+ //show down
+ downWidget.removeClass('hidden');
+ }*/
+ });
+
+}
+
+function loadChoice(containerId, url, choiceNumber, nbChoices, tokenId) {
+ if (choiceNumber == -1) {
+
+ // to add a new choice
+ // get new choiceNumber
+
+ choiceNumber = 1 + getLastChoice(containerId);
+ }
+ $.ajax(
+ {
+ url:url,
+ data:{ tokenId:tokenId, choiceNumber:choiceNumber },
+ async:false,
+ dataType:"html",
+ success:function (data) {
+ var container = $("#" + containerId);
+ container.append(data);
+ // store choiceNumber and choiceType
+ var choice = $("#" + containerId + "_" + choiceNumber);
+ choice.data('choiceType', containerId);
+ choice.data('choiceNumber', choiceNumber);
+ if (choiceNumber == nbChoices) {
+
+ updateUpdownActions(containerId);
+ // end it can show it
+ var classes = container.attr("class");
+ if (classes.indexOf("thischoice") > -1) {
+ // show it
+ container.removeClass('hidden');
+ }
+ }
+ if (!tokenId) {
+ updateUpdownActions(containerId);
+ }
+ }
+ });
+}
+
+function addTextChoice(choiceNumber, nbChoices, tokenId) {
+ loadChoice(
+ 'choicesTEXT',
+ datas['displayTextChoiceUrl'],
+ choiceNumber, nbChoices, tokenId
+ );
+}
+
+function addDateChoice(choiceNumber, nbChoices, tokenId) {
+ loadChoice(
+ 'choicesDATE',
+ datas['displayDateChoiceUrl'],
+ choiceNumber, nbChoices, tokenId
+ );
+}
+
+function addImageChoice(choiceNumber, nbChoices, tokenId) {
+ loadChoice('choicesIMAGE',
+ datas['displayImageChoiceUrl'],
+ choiceNumber, nbChoices, tokenId
+ );
+}
+
+function addNewChoice() {
+ var type = $('[name="poll.choiceType"][checked="checked"]').val();
+ if ("TEXT" == type) {
+ addTextChoice(-1, -1);
+ } else if ("DATE" == type) {
+ addDateChoice(-1, -1);
+ } else if ("IMAGE" == type) {
+ addImageChoice(-1, -1);
+ }
+ return false;
+}
+
+function deleteChoice(choiceId) {
+ var choice = $('#' + choiceId);
+ var containerId = choice.data('choiceType');
+ choice.remove();
+ updateUpdownActions(containerId);
+ return false;
+}
+
+/*function upChoice(choiceId) {
+ var choice = $('#' + choiceId);
+ var containerId = choice.data('choiceType');
+ var choiceNumber = choice.data('choiceNumber');
+ console.info("will up [" + containerId + "-" + choiceNumber + "]");
+ updateUpdownActions(containerId);
+ return false;
+ }
+
+ function downChoice(choiceId) {
+ var choice = $('#' + choiceId);
+ var containerId = choice.data('choiceType');
+ var choiceNumber = choice.data('choiceNumber');
+ console.info("will down [" + containerId + "-" + choiceNumber + "]");
+ updateUpdownActions(containerId);
+ return false;
+ }*/
+
+jQuery(document).ready(function () {
+
+ function changePollType(type) {
+
+ $('.pollType').addClass('hidden');
+ $('.pollType').removeClass('thispoll');
+ $('#pollType' + type).removeClass('hidden');
+ $('#pollType' + type).addClass('thispoll');
+
+ $('[name="poll.pollType"]').attr('checked', false);
+ $('[name="poll.pollType"][value="' + type + '"]').attr('checked', 'checked');
+ }
+
+ function changeChoiceType(type) {
+ $('.choices').addClass('hidden');
+ $('.choices').removeClass('thischoice');
+ $('#choices' + type).removeClass('hidden');
+ $('#choices' + type).addClass('thischoice');
+ $('[name="poll.choiceType"]').attr('checked', false);
+ $('[name="poll.choiceType"][value="' + type + '"]').attr('checked', 'checked');
+ }
+
+ $('[name="poll.choiceAddAllowed"]').change(function () {
+ var val = $(this).prop('checked');
+ if (val) {
+ $('#addChoiceAddAllowedPanel').show();
+ } else {
+ $('#addChoiceAddAllowedPanel').hide();
+ }
+ });
+
+ $('[name="limitChoice"]').change(function () {
+ var val = $(this).prop('checked');
+ if (val) {
+ $('#maxChoiceNbPanel').show();
+ } else {
+ $('#maxChoiceNbPanel').hide();
+ }
+ });
+
+ $('[name="reminder"]').change(function () {
+ var val = $(this).prop('checked');
+ if (val) {
+ $('#reminderPanel').show();
+ } else {
+ $('#reminderPanel').hide();
+ }
+ });
+
+ $('[name="poll.anonymous"]').change(function () {
+ var val = $(this).prop('checked');
+ $('[name="poll.anonymousVoteAllowed"]').prop('checked', val);
+ });
+ $('[name="poll.continuousResults"]').change(function () {
+ var val = $(this).prop('checked');
+ $('[name="poll.publicResults"]').prop('checked', val);
+ });
+
+ $('[name="poll.choiceType"]').change(function () {
+ changeChoiceType($(this).val());
+ });
+
+ $('[name="poll.pollType"]').change(function () {
+ changePollType($(this).val());
+ });
+
+ $('[name="poll.voteCountingType"][value="' + datas['voteCountingType'] + '"]').attr('checked', 'checked');
+
+ // before loading all choices let's hide everything, it will be shown later
+ $('.choices').addClass('hidden');
+
+ prepareChoices('choicesTEXT');
+ prepareChoices('choicesDATE');
+ prepareChoices('choicesIMAGE');
+ prepareVotingLists('votingListRESTRICTED');
+ prepareVotingLists('votingListGROUP');
+
+ changeChoiceType(datas['choiceType']);
+
+
+ changePollType(datas['pollType']);
+
+});
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/createPoll.js
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r3235 - in branches/pollen-1.2.6-struts2: pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll pollen-ui-struts2/src/main/webapp/WEB-INF/decorators pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll
by fdesbois@users.chorem.org 05 Apr '12
by fdesbois@users.chorem.org 05 Apr '12
05 Apr '12
Author: fdesbois
Date: 2012-04-05 09:50:52 +0200 (Thu, 05 Apr 2012)
New Revision: 3235
Url: http://chorem.org/repositories/revision/pollen/3235
Log:
- start implement updatePoll (not working yet)
- add disabled when vote is started (missing disabled for votingList and choice)
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-05 07:50:42 UTC (rev 3234)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-05 07:50:52 UTC (rev 3235)
@@ -214,43 +214,9 @@
if (!poll.isChoiceEmpty()) {
// create choices
-
-// ChoiceType choiceType = result.getChoiceType();
-//
-// ChoiceDAO choiceDAO = getDAO(Choice.class);
-//
for (Choice choice : poll.getChoice()) {
addChoice(result, choice);
-//
-// Choice choiceCreated = create(choiceDAO);
-// result.addChoice(choiceCreated);
-//
-// if (choiceType == ChoiceType.IMAGE) {
-//
-// // copy image where it belong and generate the thumb
-//
-// PollImageChoice imageChoice = (PollImageChoice) choice;
-// imageChoice.toChoice(choiceCreated);
-// try {
-// saveImages(result, imageChoice);
-// } catch (IOException e) {
-// throw new PollenTechnicalException(
-// "Could not create image choice", e);
-// }
-// } else if (choiceType == ChoiceType.DATE) {
-//
-// // date choice
-//
-// PollDateChoice dateChoice = (PollDateChoice) choice;
-// dateChoice.toChoice(choiceCreated);
-// } else {
-//
-// // text choice
-// choiceCreated.setDescription(choice.getDescription());
-// choiceCreated.setValidate(choice.isValidate());
-// choiceCreated.setName(choice.getName());
-// }
}
}
@@ -269,7 +235,72 @@
return result;
}
+
+ public void updatePoll(Poll poll) throws PollNotFoundException {
+
+// Poll result;
+// try {
+//
+// PollDAO dao = getDAO(Poll.class);
+//
+// if (!dao.existByTopiaId(poll.getTopiaId())) {
+// throw new PollNotFoundException();
+// }
+//
+// result = dao.update(poll);
+//
+// } catch (TopiaException e) {
+// throw new PollenTechnicalException("Can't update poll [" + poll.getTopiaId() + "]", e);
+// }
+// return result;
+
+ Poll pollToUpdate = getEntityById(Poll.class, poll.getTopiaId());
+ if (pollToUpdate == null) {
+ throw new PollNotFoundException();
+ }
+
+ PollenBinderHelper.copy("", poll, pollToUpdate, false);
+
+ // -- Creator -- //
+ PollAccount creator = poll.getCreator();
+ PollAccount creatorToUpdate = pollToUpdate.getCreator();
+ creatorToUpdate.setUserAccount(creator.getUserAccount());
+ creatorToUpdate.setVotingId(creator.getVotingId());
+ creatorToUpdate.setEmail(creator.getEmail());
+ pollToUpdate.setCreator(creatorToUpdate);
+
+ // -- Choices -- //
+ pollToUpdate.clearChoice();
+ for (Choice choice : poll.getChoice()) {
+ addChoice(pollToUpdate, choice);
+ }
+
+ // -- PreventRules -- //
+
+ // We assume that all previous preventRules will be deleted
+ pollToUpdate.clearPreventRule();
+
+ // Create the new preventRules
+ PreventRuleDAO preventRuleDAO = getDAO(PreventRule.class);
+ for (PreventRule preventRule : poll.getPreventRule()) {
+ PreventRule preventRuleCreated = create(preventRuleDAO);
+ preventRuleCreated.setActive(preventRule.isActive());
+ preventRuleCreated.setMethod(preventRule.getMethod());
+ preventRuleCreated.setOneTime(preventRule.isOneTime());
+ preventRuleCreated.setRepeated(preventRule.isRepeated());
+ preventRuleCreated.setScope(preventRule.getScope());
+ preventRuleCreated.setSensibility(preventRule.getSensibility());
+ pollToUpdate.addPreventRule(preventRuleCreated);
+ }
+
+ // -- VotingLists -- //
+ pollToUpdate.clearVotingList();
+ for (VotingList votingList : poll.getVotingList()) {
+ addVotingList(pollToUpdate, votingList);
+ }
+ }
+
public String getPollVoteUrl(Poll poll) {
URL applicationUrl = serviceContext.getApplicationURL();
StringBuilder url = new StringBuilder(applicationUrl.toString());
@@ -603,15 +634,20 @@
ChoiceType choiceType = poll.getChoiceType();
ChoiceDAO dao = getDAO(Choice.class);
- Choice choiceCreated = create(dao);
- poll.addChoice(choiceCreated);
+ Choice choiceLoaded;
+ if (choice.getTopiaId() == null) {
+ choiceLoaded = create(dao);
+ } else {
+ choiceLoaded = getEntityById(Choice.class, choice.getTopiaId());
+ }
+ poll.addChoice(choiceLoaded);
if (choiceType == ChoiceType.IMAGE) {
// copy image where it belong and generate the thumb
PollImageChoice imageChoice = (PollImageChoice) choice;
- imageChoice.toChoice(choiceCreated);
+ imageChoice.toChoice(choiceLoaded);
try {
saveImages(poll, imageChoice);
} catch (IOException e) {
@@ -624,14 +660,14 @@
// date choice
PollDateChoice dateChoice = (PollDateChoice) choice;
- dateChoice.toChoice(choiceCreated);
+ dateChoice.toChoice(choiceLoaded);
} else {
// text choice
- choiceCreated.setDescription(choice.getDescription());
- choiceCreated.setValidate(choice.isValidate());
- choiceCreated.setName(choice.getName());
+ choiceLoaded.setDescription(choice.getDescription());
+ choiceLoaded.setValidate(choice.isValidate());
+ choiceLoaded.setName(choice.getName());
}
}
@@ -830,7 +866,58 @@
// ContextUtil.doFinally(transaction);
// }
}
+
+ protected void addVotingList(Poll poll, VotingList votingList) {
+
+ VotingListDAO votingListDAO = getDAO(VotingList.class);
+ PersonToListDAO personToListDAO = getDAO(PersonToList.class);
+ PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
+ // Prepare the VotingList and add it to the poll
+ VotingList votingListLoaded;
+ if (votingList.getTopiaId() == null) {
+ votingListLoaded = create(votingListDAO);
+ } else {
+ votingListLoaded = getEntityById(VotingList.class, votingList.getTopiaId());
+ }
+ poll.addVotingList(votingListLoaded);
+
+ votingListLoaded.setName(votingList.getName());
+ votingListLoaded.setWeight(votingList.getWeight());
+
+ // Merge PersonToList
+ for (PersonToList personToList : votingList.getPollAccountPersonToList()) {
+
+ PersonToList personToListLoaded;
+ if (personToList.getTopiaId() == null) {
+ personToListLoaded = create(personToListDAO);
+ } else {
+ personToListLoaded = getEntityById(PersonToList.class, personToList.getTopiaId());
+ }
+
+// personToListLoaded.setHasVoted(personToList.isHasVoted());
+ personToListLoaded.setWeight(personToList.getWeight());
+
+ PollAccount pollAccount = personToList.getPollAccount();
+ PollAccount pollAccountLoaded = personToListLoaded.getPollAccount();
+
+ // Create the pollAccount if not exists
+ if (pollAccountLoaded == null) {
+ pollAccountLoaded = create(pollAccountDAO);
+ pollAccountLoaded.setAccountId(pollAccount.getAccountId());
+ personToListLoaded.setPollAccount(pollAccountLoaded);
+ }
+
+ pollAccountLoaded.setEmail(pollAccount.getEmail());
+// pollAccountLoaded.setUserAccount(pollAccount.getUserAccount());
+ pollAccountLoaded.setVotingId(pollAccount.getVotingId());
+
+ // The model doesn't have any composition for this relation, the link must be set in both objects
+ personToListLoaded.setVotingList(votingListLoaded);
+ votingListLoaded.addPollAccountPersonToList(personToListLoaded);
+ }
+ }
+
/**
* Création d'une miniature.
*
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-05 07:50:42 UTC (rev 3234)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-05 07:50:52 UTC (rev 3235)
@@ -776,7 +776,7 @@
return result2;
}
- private String getNonEmptyParameterValue(String paramName) {
+ protected String getNonEmptyParameterValue(String paramName) {
String[] paramValues = parameters.get(paramName);
String result = null;
if (paramValues != null && paramValues.length == 1) {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-05 07:50:42 UTC (rev 3234)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-05 07:50:52 UTC (rev 3235)
@@ -143,11 +143,15 @@
PollAccount pollAccount = input.getPollAccount();
String prefix = String.format(PREFIX_PERSON_TO_LIST, votingListIndex, index);
+ String accountId;
if (!clone) {
putParameter(prefix, PersonToList.TOPIA_ID, input.getTopiaId());
+ accountId = pollAccount.getAccountId();
+ } else {
+ accountId = serviceContext.createPollenUrlId();
}
putParameter(prefix, PersonToList.PROPERTY_WEIGHT, String.valueOf(input.getWeight()));
- putParameter(prefix, PollAccount.PROPERTY_ACCOUNT_ID, pollAccount.getAccountId());
+ putParameter(prefix, PollAccount.PROPERTY_ACCOUNT_ID, accountId);
putParameter(prefix, PollAccount.PROPERTY_VOTING_ID, pollAccount.getVotingId());
putParameter(prefix, PollAccount.PROPERTY_EMAIL, pollAccount.getEmail());
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-05 07:50:42 UTC (rev 3234)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-05 07:50:52 UTC (rev 3235)
@@ -61,6 +61,8 @@
private static final Log log = LogFactory.getLog(SavePoll.class);
private String userId;
+
+ private String pollId;
public void setUserId(String userId) {
this.userId = userId;
@@ -68,14 +70,22 @@
@Override
protected Poll initPoll() {
- UserAccount userAccount = getPollenUserAccount();
- Poll result = getPollService().getNewPoll(userAccount);
+ Poll result;
+ if (pollId != null) {
+ result = getPollService().getEntityById(Poll.class, pollId);
+
+ } else {
+ UserAccount userAccount = getPollenUserAccount();
+ result = getPollService().getNewPoll(userAccount);
+ }
return result;
}
@Override
public void prepare() throws Exception {
+ pollId = getNonEmptyParameterValue("poll.topiaId");
+
prepareFormPage();
}
@@ -150,6 +160,11 @@
public String execute() throws Exception {
Poll poll = getPoll();
+
+ // Clear previous collections to save those from the form
+ poll.clearChoice();
+ poll.clearPreventRule();
+ poll.clearVotingList();
// Load userAccount from the form
if (!isCreatorUserAccountDefined() && StringUtils.isNotBlank(userId)) {
@@ -200,7 +215,7 @@
}
if (isEdit()) {
-// service.createPoll(poll);
+ service.updatePoll(poll);
} else {
service.createPoll(poll);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp 2012-04-05 07:50:42 UTC (rev 3234)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp 2012-04-05 07:50:52 UTC (rev 3235)
@@ -166,7 +166,7 @@
<div class="top_left${pageLogo}"></div>
<ul class="top_middle${pageLogo}">
<li>
- <s:a action="create" method="input" namespace="/poll">
+ <s:a action="create" namespace="/poll">
<s:text name="pollen.menu.createPoll"/>
</s:a>
</li>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-05 07:50:42 UTC (rev 3234)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-05 07:50:52 UTC (rev 3235)
@@ -209,14 +209,14 @@
<fieldset>
<legend><s:text name="pollen.common.voteCountingType"/></legend>
<s:radio key='poll.voteCountingType' list="voteCountingTypes"
- label='' theme="simple"/>
+ label='' theme="simple" disabled="%{voteStarted}"/>
</fieldset>
<br/>
<fieldset>
<legend><s:text name="pollen.fieldset.poll.choices"/></legend>
<s:radio key='poll.choiceType' list="choiceTypes" label=''
- theme="simple"/>
+ theme="simple" disabled="%{voteStarted}"/>
<hr/>
<s:fielderror fieldName="poll.choices"/>
@@ -231,7 +231,7 @@
</div>
<hr/>
<s:submit key="pollen.action.addChoice" align="center"
- onclick="return addNewChoice();"/>
+ onclick="return addNewChoice();" disabled="%{voteStarted}"/>
</fieldset>
</div>
@@ -257,15 +257,15 @@
<legend><s:text name="pollen.fieldset.poll.options"/></legend>
<s:checkbox key="poll.anonymous"
- label="%{getText('pollen.common.pollOption.anonymous')}"/>
+ label="%{getText('pollen.common.pollOption.anonymous')}" disabled="%{voteStarted}"/>
<s:checkbox key="poll.anonymousVoteAllowed"
- label="%{getText('pollen.common.pollOption.anonymousVoteAllowed')}"/>
+ label="%{getText('pollen.common.pollOption.anonymousVoteAllowed')}" disabled="%{voteStarted}"/>
<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')}"/>
+ label="%{getText('pollen.common.pollOption.choiceAddAllowed')}" disabled="%{voteStarted}"/>
<div id='addChoiceAddAllowedPanel' class="hidden">
<sj:datepicker key="poll.beginChoiceDate"
label="%{getText('pollen.common.beginChoiceDate')}"
@@ -275,7 +275,7 @@
displayFormat="dd/mm/yy"/>
</div>
<s:checkbox key="limitChoice"
- label="%{getText('pollen.common.pollOption.limitChoice')}"/>
+ label="%{getText('pollen.common.pollOption.limitChoice')}" disabled="%{voteStarted}"/>
<div id='maxChoiceNbPanel' class="hidden">
<s:textfield key="poll.maxChoiceNb"
label="%{getText('pollen.common.pollOption.maxChoiceNb')}"/>
@@ -295,7 +295,7 @@
<legend><s:text name="pollen.fieldset.poll.general"/></legend>
<sj:datepicker key="poll.beginDate" displayFormat="dd/mm/yy"
- label="%{getText('pollen.common.beginDate')}"/>
+ label="%{getText('pollen.common.beginDate')}" disabled="%{voteStarted}"/>
<sj:datepicker key="poll.endDate" displayFormat="dd/mm/yy"
label="%{getText('pollen.common.endDate')}"/>
</fieldset>
@@ -304,7 +304,7 @@
<fieldset>
<legend><s:text name="pollen.common.pollType"/></legend>
<s:radio key='poll.pollType' list="pollTypes"
- label='%{getText("pollen.common.pollType")}'/>
+ label='%{getText("pollen.common.pollType")}' disabled="%{voteStarted}"/>
<hr/>
<div class="restrictedPoll">
<div id="votingLists">
@@ -312,11 +312,11 @@
</div>
<div class="groupPoll" align="center">
<s:submit key="pollen.action.addVotingList" theme="simple"
- onclick="return addNewVotingList();"/>
+ onclick="return addNewVotingList();" disabled="%{voteStarted}"/>
<s:if test="userLoggued">
<s:submit key="pollen.action.addVotingListFromPersonList"
theme="simple"
- onclick="return selectPersonListToCreateNewVotingList();"/>
+ onclick="return selectPersonListToCreateNewVotingList();" disabled="%{voteStarted}"/>
</s:if>
</div>
</div>
@@ -327,12 +327,6 @@
<br/>
<s:submit action="save" key="pollen.action.savePoll" value="%{actionLabel}" align="center"/>
-
- <!--<div id="wwctrl_registerForm_pollen_action_<s:property value='%{actionLabel}'/>Poll" align="center">
- <input type="submit" id="registerForm_pollen_action_<s:property value='%{actionLabel}'/>Poll"
- name="action:<s:property value='%{actionName}'/>"
- value="<s:text name='pollen.action.%{actionLabel}Poll'/>"/>
- </div>-->
</s:form>
<script type="text/javascript">
1
0
r3234 - in branches/pollen-1.2.6-struts2: pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll pollen-ui-struts2/src/main/resources/config pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll
by fdesbois@users.chorem.org 05 Apr '12
by fdesbois@users.chorem.org 05 Apr '12
05 Apr '12
Author: fdesbois
Date: 2012-04-05 09:50:42 +0200 (Thu, 05 Apr 2012)
New Revision: 3234
Url: http://chorem.org/repositories/revision/pollen/3234
Log:
- move validation methods in SavePoll
- use prepare in LoadPoll, SUCCESS is used by default
- manage existing userAccount for clone
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-05 07:50:32 UTC (rev 3233)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-05 07:50:42 UTC (rev 3234)
@@ -98,13 +98,16 @@
PollAccount creator = newInstance(pollAccountDAO);
creator.setAccountId(serviceContext.createPollenUrlId());
// creator.setAdmin(true);
+
if (user != null) {
+
// Link the creator with the user
creator.setVotingId(user.getDisplayName());
creator.setEmail(user.getEmail());
creator.setUserAccount(user);
}
result.setCreator(creator);
+
// Generate Uid to have a unique poll. Will avoid multi-submit, existing
// poll will be check by its uid.
result.setPollId(serviceContext.createPollenUrlId());
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-05 07:50:32 UTC (rev 3233)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-05 07:50:42 UTC (rev 3234)
@@ -1,16 +1,13 @@
package org.chorem.pollen.ui.actions.poll;
-import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.ParameterAware;
-import org.chorem.pollen.bean.ChoiceHelper;
import org.chorem.pollen.bean.PollDateChoice;
import org.chorem.pollen.bean.PollImageChoice;
import org.chorem.pollen.business.persistence.Choice;
@@ -29,7 +26,6 @@
import org.chorem.pollen.services.impl.PollService;
import org.chorem.pollen.ui.actions.FileUploadAware;
import org.chorem.pollen.ui.actions.PollenActionSupport;
-import org.nuiton.util.StringUtil;
import java.io.File;
import java.text.ParseException;
@@ -107,20 +103,20 @@
/** Uploaded images name (from use desktop) (for choice type poll). */
private List<String> imageChoiceFileName;
- private boolean informationsError;
-
- private boolean optionsError;
-
private String actionLabel;
+ private transient PollService pollService;
+
/**
* All the parameters send by request used to build back choices of the
* poll.
*/
protected Map<String, String[]> parameters;
- private transient PollService pollService;
+ protected boolean informationsError;
+ protected boolean optionsError;
+
protected abstract Poll initPoll();
@Override
@@ -128,6 +124,13 @@
return "Creation";
}
+ protected PollService getPollService() {
+ if (pollService == null) {
+ pollService = newService(PollService.class);
+ }
+ return pollService;
+ }
+
public Poll getPoll() {
if (poll == null) {
poll = initPoll();
@@ -247,14 +250,6 @@
return imageChoiceFileName;
}
- public boolean isInformationsError() {
- return informationsError;
- }
-
- public boolean isOptionsError() {
- return optionsError;
- }
-
public boolean isFreePoll() {
PollType pollType = poll.getPollType();
return pollType == PollType.FREE;
@@ -273,6 +268,14 @@
return getPollService().getPollEditUrl(poll);
}
+ public boolean isInformationsError() {
+ return informationsError;
+ }
+
+ public boolean isOptionsError() {
+ return optionsError;
+ }
+
public int getSelectedTab() {
int result;
if (isInformationsError()) {
@@ -291,6 +294,15 @@
return actionLabel;
}
+ public boolean isVoteStarted() {
+ return isEdit() && getPoll().sizeVote() > 0;
+ }
+
+ public boolean isCreatorUserAccountDefined() {
+ PollAccount creator = getPoll().getCreator();
+ return creator.getUserAccount() != null;
+ }
+
protected int getNbChoices() {
//TODO tchemit-2012-03-05 use a default value from configuration
return 5;
@@ -301,7 +313,7 @@
}
protected boolean isEdit() {
- return getPoll().getTopiaId() != null;
+ return StringUtils.isNotEmpty(getPoll().getTopiaId());
}
public void prepareFormPage() throws Exception {
@@ -373,297 +385,10 @@
}
@Override
- public void validate() {
-
- Preconditions.checkNotNull(poll);
-
- informationsError = false;
-
- // poll must have a title
- if (StringUtils.isEmpty(poll.getTitle())) {
- addFieldError("poll.title", _("pollen.error.poll.required.title"));
- }
-
-
- // validate choices
- Map<Integer, Choice> orderedChoices = getOrderedChoices();
-
- if (MapUtils.isEmpty(orderedChoices)) {
-
- // poll must have at least one choice
- addFieldError("poll.choices",
- _("pollen.error.poll.required.one.choice"));
- } else {
-//
-// //TODO tchemit improve this (from different cases text-date-image)
-// // check there is no choice with same name
-// boolean duplicateNameDetected = false;
-// Set<String> names = Sets.newHashSet();
-// for (Choice choice : orderedChoices.values()) {
-// String choiceName = choice.getName();
-// if (!names.add(choiceName)) {
-// duplicateNameDetected = true;
-// break;
-// }
-// }
-// if (duplicateNameDetected) {
-// addFieldError("poll.choices",
-// _("pollen.error.poll.detected.duplicate.choice.name"));
-// }
-
- ChoiceType choiceType = poll.getChoiceType();
- int inputChoicesSize = orderedChoices.size();
- Set<Object> choiceValues =
- Sets.newHashSet(ChoiceHelper.toValues(orderedChoices.values(), choiceType));
-
- if (inputChoicesSize > choiceValues.size()) {
- addFieldError("poll.choices",
- _("pollen.error.poll.detected.duplicate.choice.name"));
- }
- }
-
-
- optionsError = false;
-
- // validate security stuff
-
- if (isFreePoll()) {
-
- // nothing to validate
-
- } else {
- Map<Integer, VotingList> votingLists = getOrderedVotingLists();
-
- Set<String> groups = Sets.newHashSet();
- Set<String> voters = Sets.newHashSet();
- Set<String> emails = Sets.newHashSet();
-
- for (Map.Entry<Integer, VotingList> entry : votingLists.entrySet()) {
- optionsError |= validateVotingList(entry.getKey(),
- entry.getValue(),
- groups,
- voters,
- emails);
- }
- }
-
- informationsError = hasFieldErrors();
-
- if (!informationsError && optionsError) {
-
- // trick to force to go back to form
- addFieldError("", "");
- }
- }
-
- protected boolean validateVotingList(int votingListNumber,
- VotingList votingList,
- Set<String> groups,
- Set<String> voters,
- Set<String> emails) {
-
- boolean result = false;
- Map<String, String> errors = Maps.newHashMap();
-
- String votingListErrorPrefix = "poll.votingList_" + votingListNumber;
-
- if (isGroupPoll()) {
-
- // group poll
-
- // check there is at least one group
- // check no doublon on group names
- // check there is at least one voter on each group
- // check no doublon on voter names
- // check no doublon on voter emails
-
- { // validate votingList name
- String votingListName = votingList.getName();
-
- if (StringUtils.isEmpty(votingListName)) {
-
- errors.put(votingListErrorPrefix + ".name",
- _("pollen.error.poll.required.votingList.name"));
- } else {
-
- // check no votingList name doublon
- boolean add = groups.add(votingListName);
- if (!add) {
-
- // name doublon
- errors.put(
- votingListErrorPrefix + ".name",
- _("pollen.error.poll.votingList.name.doublon"));
- }
-
- }
- }
-
- { // validate votingList weight
-
- if (votingList.getWeight() == 0) {
-
- // no weight filled (can be a bad conversion)
- errors.put(
- votingListErrorPrefix + ".weight",
- _("pollen.error.poll.votingList.weight.not.valid"));
- }
- }
- }
-
- // check there is at least one voter
-
- String persontoListToken = DisplayPersonToList.getPersonToListTokenId(
- votingListTokenId, votingListNumber);
-
- Map<Integer, PersonToList> personToLists =
- getPollenSession().getDynamicData(persontoListToken);
-
- if (MapUtils.isEmpty(personToLists)) {
-
- // no personToList found for unique votingList 0
- errors.put(votingListErrorPrefix,
- _("pollen.error.poll.required.one.personToList"));
- } else {
-
- // check no doublon on voter names
- // check no doublon on voter emails
-
- for (Map.Entry<Integer, PersonToList> entry :
- personToLists.entrySet()) {
-
- result |= validatePersonList(entry.getKey(), entry.getValue(),
- voters, emails);
- }
- }
-
- if (MapUtils.isNotEmpty(errors)) {
-
- // keep errors to display them in correct action
- String errorToken = DisplayVotingList.getVotingListErrorTokenId(
- votingListTokenId, votingListNumber);
- if (log.isInfoEnabled()) {
- log.info("Add " + errors.size() + " errors to " + errorToken);
- }
- getPollenSession().putDynamicData(errorToken, errors);
- result = true;
- }
- return result;
- }
-
- protected boolean validatePersonList(int personToListNumber,
- PersonToList personToList,
- Set<String> voters,
- Set<String> emails) {
-
- boolean result = false;
- Map<String, String> errors = Maps.newHashMap();
- String fieldNamePrefix =
- "personToList_0_" + personToListNumber;
- PollAccount pollAccount = personToList.getPollAccount();
-
- { // validate votingId
-
- String votingId = pollAccount.getVotingId();
- // check voter is not doublon
- boolean add = voters.add(votingId);
- if (!add) {
-
- // voter doublon
- errors.put(
- fieldNamePrefix + ".votingId",
- _("pollen.error.poll.personToList.votingId.doublon"));
- }
- }
- { // validate email
- String email = pollAccount.getEmail();
-
- if (StringUtils.isEmpty(email)) {
- errors.put(
- fieldNamePrefix + ".email",
- _("pollen.error.poll.personToList.email.required"));
- } else {
-
-
- boolean validEmail = StringUtil.isEmail(email);
- if (!validEmail) {
-
- // not a valid email
- errors.put(
- fieldNamePrefix + ".email",
- _("pollen.error.poll.personToList.email.not.valid"));
- } else {
-
- // check email not doublon
- boolean add = emails.add(email);
- if (!add) {
-
- // email doublon
- errors.put(
- fieldNamePrefix + ".email",
- _("pollen.error.poll.personToList.email.doublon"));
- }
- }
- }
- }
- { // validate weight
- if (personToList.getWeight() == 0) {
-
- // no weight filled (can be a bad conversion)
- errors.put(
- fieldNamePrefix + ".weight",
- _("pollen.error.poll.personToList.weight.not.valid"));
- }
- }
-
- if (MapUtils.isNotEmpty(errors)) {
- String errorToken =
- DisplayPersonToList.getPersonToListErrorTokenId(
- votingListTokenId, 0, personToListNumber);
- if (log.isInfoEnabled()) {
- log.info("Add " + errors.size() + " errors to " + errorToken);
- }
- getPollenSession().putDynamicData(errorToken, errors);
- result = true;
- }
- return result;
- }
-
- @Override
public void setParameters(Map<String, String[]> parameters) {
this.parameters = parameters;
}
- protected PollService getPollService() {
- if (pollService == null) {
- pollService = newService(PollService.class);
- }
- return pollService;
- }
-
- protected Map<Integer, Choice> getOrderedChoices() {
- Map<Integer, Choice> result = null;
- switch (poll.getChoiceType()) {
- case TEXT:
- result = getPollenSession().getDynamicData(textChoiceTokenId);
- break;
- case DATE:
- result = getPollenSession().getDynamicData(dateChoiceTokenId);
- break;
- case IMAGE:
- result = getPollenSession().getDynamicData(imageChoiceTokenId);
- break;
- }
- return result;
- }
-
- protected Map<Integer, VotingList> getOrderedVotingLists() {
-
- Map<Integer, VotingList> result = getPollenSession().getDynamicData(
- votingListTokenId);
- return result;
- }
-
protected Map<Integer, Choice> buildTextChoices(int nbDefault) {
Map<Integer, Choice> result = Maps.newTreeMap();
@@ -1026,7 +751,6 @@
}
}
-
private <T> Map<Integer, T> reindexMap(Map<Integer, T> result, int maxNumber) {
Map<Integer, T> result2;
@@ -1052,15 +776,6 @@
return result2;
}
- private <O> void addtoList(List<O> list, int index, O object) {
-
- while (list.size() < index) {
- list.add(null);
- }
- list.add(index, object);
- }
-
-
private String getNonEmptyParameterValue(String paramName) {
String[] paramValues = parameters.get(paramName);
String result = null;
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-05 07:50:32 UTC (rev 3233)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-05 07:50:42 UTC (rev 3234)
@@ -3,6 +3,7 @@
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
+import com.opensymphony.xwork2.Preparable;
import org.chorem.pollen.bean.PollImageChoice;
import org.chorem.pollen.bean.PollUri;
import org.chorem.pollen.business.persistence.Choice;
@@ -21,7 +22,7 @@
*
* @author fdesbois <desbois(a)codelutin.com>
*/
-public class LoadPoll extends AbstractPollForm {
+public class LoadPoll extends AbstractPollForm implements Preparable {
private static final String PREFIX_CHOICE = "%sChoice_%d";
@@ -57,14 +58,15 @@
if (clone) {
result.setTopiaId(null);
+ result.setPollId(serviceContext.createPollenUrlId());
- // Use a new pollUid
- String pollUid = serviceContext.createPollenUrlId();
- result.setPollId(pollUid);
+ // Reset creator but keep userAccount link
+ PollAccount creator = result.getCreator();
+ creator.setTopiaId(null);
+ creator.setAccountId(serviceContext.createPollenUrlId());
}
} else {
-
UserAccount userAccount = getPollenUserAccount();
result = getPollService().getNewPoll(userAccount);
}
@@ -72,7 +74,7 @@
}
@Override
- public String input() throws Exception {
+ public void prepare() throws Exception {
if (pollUri != null) {
@@ -87,8 +89,6 @@
}
prepareFormPage();
-
- return INPUT;
}
private Function<Choice, String> withChoicePrefix(final ChoiceType choiceType) {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-05 07:50:32 UTC (rev 3233)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-05 07:50:42 UTC (rev 3234)
@@ -23,18 +23,29 @@
*/
package org.chorem.pollen.ui.actions.poll;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import com.opensymphony.xwork2.Preparable;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.bean.ChoiceHelper;
import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.business.persistence.PersonToList;
import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.PreventRule;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.VotingList;
+import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.services.impl.PollService;
import org.chorem.pollen.services.impl.PreventRuleService;
+import org.chorem.pollen.services.impl.UserService;
+import org.nuiton.util.StringUtil;
import java.util.Map;
+import java.util.Set;
/**
* Creates a new poll.
@@ -48,10 +59,16 @@
/** Logger. */
private static final Log log = LogFactory.getLog(SavePoll.class);
+
+ private String userId;
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
@Override
protected Poll initPoll() {
- UserAccount userAccount = getPollenUserAccount();
+ UserAccount userAccount = getPollenUserAccount();
Poll result = getPollService().getNewPoll(userAccount);
return result;
}
@@ -63,10 +80,86 @@
}
@Override
+ public void validate() {
+
+ Poll poll = getPoll();
+
+ informationsError = false;
+
+ // poll must have a title
+ if (StringUtils.isEmpty(poll.getTitle())) {
+ addFieldError("poll.title", _("pollen.error.poll.required.title"));
+ }
+
+
+ // validate choices
+ Map<Integer, Choice> orderedChoices = getOrderedChoices();
+
+ if (MapUtils.isEmpty(orderedChoices)) {
+
+ // poll must have at least one choice
+ addFieldError("poll.choices",
+ _("pollen.error.poll.required.one.choice"));
+ } else {
+
+ ChoiceType choiceType = poll.getChoiceType();
+ int inputChoicesSize = orderedChoices.size();
+ Set<Object> choiceValues =
+ Sets.newHashSet(ChoiceHelper.toValues(orderedChoices.values(), choiceType));
+
+ if (inputChoicesSize > choiceValues.size()) {
+ addFieldError("poll.choices",
+ _("pollen.error.poll.detected.duplicate.choice.name"));
+ }
+ }
+
+ optionsError = false;
+
+ // validate security stuff
+
+ if (isFreePoll()) {
+
+ // nothing to validate
+
+ } else {
+ Map<Integer, VotingList> votingLists = getOrderedVotingLists();
+
+ Set<String> groups = Sets.newHashSet();
+ Set<String> voters = Sets.newHashSet();
+ Set<String> emails = Sets.newHashSet();
+
+ for (Map.Entry<Integer, VotingList> entry : votingLists.entrySet()) {
+ optionsError |= validateVotingList(entry.getKey(),
+ entry.getValue(),
+ groups,
+ voters,
+ emails);
+ }
+ }
+
+ informationsError = hasFieldErrors();
+
+ if (!informationsError && optionsError) {
+
+ // trick to force to go back to form
+ addFieldError("", "");
+ }
+ }
+
+ @Override
public String execute() throws Exception {
Poll poll = getPoll();
+ // Load userAccount from the form
+ if (!isCreatorUserAccountDefined() && StringUtils.isNotBlank(userId)) {
+
+ UserService userService = newService(UserService.class);
+ UserAccount userAccount = userService.getEntityById(UserAccount.class, userId);
+
+ poll.getCreator().setUserAccount(userAccount);
+ }
+
Map<Integer, Choice> orderedChoices = getOrderedChoices();
for (Integer index : orderedChoices.keySet()) {
@@ -119,4 +212,200 @@
addActionMessage(_("pollen.information.poll.created"));
return SUCCESS;
}
+
+ protected Map<Integer, Choice> getOrderedChoices() {
+ Map<Integer, Choice> result = null;
+ switch (getPoll().getChoiceType()) {
+ case TEXT:
+ result = getPollenSession().getDynamicData(getTextChoiceTokenId());
+ break;
+ case DATE:
+ result = getPollenSession().getDynamicData(getDateChoiceTokenId());
+ break;
+ case IMAGE:
+ result = getPollenSession().getDynamicData(getImageChoiceTokenId());
+ break;
+ }
+ return result;
+ }
+
+ protected Map<Integer, VotingList> getOrderedVotingLists() {
+
+ Map<Integer, VotingList> result = getPollenSession().getDynamicData(
+ getVotingListTokenId());
+ return result;
+ }
+
+ protected boolean validateVotingList(int votingListNumber,
+ VotingList votingList,
+ Set<String> groups,
+ Set<String> voters,
+ Set<String> emails) {
+
+ boolean result = false;
+ Map<String, String> errors = Maps.newHashMap();
+
+ String votingListErrorPrefix = "poll.votingList_" + votingListNumber;
+
+ if (isGroupPoll()) {
+
+ // group poll
+
+ // check there is at least one group
+ // check no doublon on group names
+ // check there is at least one voter on each group
+ // check no doublon on voter names
+ // check no doublon on voter emails
+
+ { // validate votingList name
+ String votingListName = votingList.getName();
+
+ if (StringUtils.isEmpty(votingListName)) {
+
+ errors.put(votingListErrorPrefix + ".name",
+ _("pollen.error.poll.required.votingList.name"));
+ } else {
+
+ // check no votingList name doublon
+ boolean add = groups.add(votingListName);
+ if (!add) {
+
+ // name doublon
+ errors.put(
+ votingListErrorPrefix + ".name",
+ _("pollen.error.poll.votingList.name.doublon"));
+ }
+
+ }
+ }
+
+ { // validate votingList weight
+
+ if (votingList.getWeight() == 0) {
+
+ // no weight filled (can be a bad conversion)
+ errors.put(
+ votingListErrorPrefix + ".weight",
+ _("pollen.error.poll.votingList.weight.not.valid"));
+ }
+ }
+ }
+
+ // check there is at least one voter
+
+ String persontoListToken = DisplayPersonToList.getPersonToListTokenId(
+ getVotingListTokenId(), votingListNumber);
+
+ Map<Integer, PersonToList> personToLists =
+ getPollenSession().getDynamicData(persontoListToken);
+
+ if (MapUtils.isEmpty(personToLists)) {
+
+ // no personToList found for unique votingList 0
+ errors.put(votingListErrorPrefix,
+ _("pollen.error.poll.required.one.personToList"));
+ } else {
+
+ // check no doublon on voter names
+ // check no doublon on voter emails
+
+ for (Map.Entry<Integer, PersonToList> entry :
+ personToLists.entrySet()) {
+
+ result |= validatePersonList(entry.getKey(), entry.getValue(),
+ voters, emails);
+ }
+ }
+
+ if (MapUtils.isNotEmpty(errors)) {
+
+ // keep errors to display them in correct action
+ String errorToken = DisplayVotingList.getVotingListErrorTokenId(
+ getVotingListTokenId(), votingListNumber);
+ if (log.isInfoEnabled()) {
+ log.info("Add " + errors.size() + " errors to " + errorToken);
+ }
+ getPollenSession().putDynamicData(errorToken, errors);
+ result = true;
+ }
+ return result;
+ }
+
+ protected boolean validatePersonList(int personToListNumber,
+ PersonToList personToList,
+ Set<String> voters,
+ Set<String> emails) {
+
+ boolean result = false;
+ Map<String, String> errors = Maps.newHashMap();
+ String fieldNamePrefix =
+ "personToList_0_" + personToListNumber;
+ PollAccount pollAccount = personToList.getPollAccount();
+
+ { // validate votingId
+
+ String votingId = pollAccount.getVotingId();
+ // check voter is not doublon
+ boolean add = voters.add(votingId);
+ if (!add) {
+
+ // voter doublon
+ errors.put(
+ fieldNamePrefix + ".votingId",
+ _("pollen.error.poll.personToList.votingId.doublon"));
+ }
+ }
+ { // validate email
+ String email = pollAccount.getEmail();
+
+ if (StringUtils.isEmpty(email)) {
+ errors.put(
+ fieldNamePrefix + ".email",
+ _("pollen.error.poll.personToList.email.required"));
+ } else {
+
+
+ boolean validEmail = StringUtil.isEmail(email);
+ if (!validEmail) {
+
+ // not a valid email
+ errors.put(
+ fieldNamePrefix + ".email",
+ _("pollen.error.poll.personToList.email.not.valid"));
+ } else {
+
+ // check email not doublon
+ boolean add = emails.add(email);
+ if (!add) {
+
+ // email doublon
+ errors.put(
+ fieldNamePrefix + ".email",
+ _("pollen.error.poll.personToList.email.doublon"));
+ }
+ }
+ }
+ }
+ { // validate weight
+ if (personToList.getWeight() == 0) {
+
+ // no weight filled (can be a bad conversion)
+ errors.put(
+ fieldNamePrefix + ".weight",
+ _("pollen.error.poll.personToList.weight.not.valid"));
+ }
+ }
+
+ if (MapUtils.isNotEmpty(errors)) {
+ String errorToken =
+ DisplayPersonToList.getPersonToListErrorTokenId(
+ getVotingListTokenId(), 0, personToListNumber);
+ if (log.isInfoEnabled()) {
+ log.info("Add " + errors.size() + " errors to " + errorToken);
+ }
+ getPollenSession().putDynamicData(errorToken, errors);
+ result = true;
+ }
+ return result;
+ }
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-04-05 07:50:32 UTC (rev 3233)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-04-05 07:50:42 UTC (rev 3234)
@@ -43,9 +43,8 @@
<!-- create poll -->
<action name="create"
- class="org.chorem.pollen.ui.actions.poll.LoadPoll"
- method="input">
- <result name="input">/WEB-INF/jsp/poll/create.jsp</result>
+ class="org.chorem.pollen.ui.actions.poll.LoadPoll">
+ <result>/WEB-INF/jsp/poll/create.jsp</result>
</action>
<!-- display * -->
@@ -86,19 +85,17 @@
<!-- edit poll -->
<action name="modification/*"
- class="org.chorem.pollen.ui.actions.poll.LoadPoll"
- method="input">
+ class="org.chorem.pollen.ui.actions.poll.LoadPoll">
<param name="uriId">{1}</param>
- <result name="input">/WEB-INF/jsp/poll/create.jsp</result>
+ <result>/WEB-INF/jsp/poll/create.jsp</result>
</action>
<!-- clone poll -->
<action name="clone/*"
- class="org.chorem.pollen.ui.actions.poll.LoadPoll"
- method="input">
+ class="org.chorem.pollen.ui.actions.poll.LoadPoll">
<param name="uriId">{1}</param>
<param name="clone">true</param>
- <result name="input">/WEB-INF/jsp/poll/create.jsp</result>
+ <result>/WEB-INF/jsp/poll/create.jsp</result>
</action>
<!-- save poll -->
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-05 07:50:32 UTC (rev 3233)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-05 07:50:42 UTC (rev 3234)
@@ -201,7 +201,7 @@
required="true" size="80"/>
<s:textarea key="poll.description" rows="3" cols="54"
label="%{getText('pollen.common.description')}"/>
- <s:hidden key="poll.pollId" label=''/>
+ <s:hidden key="poll.pollId"/>
</fieldset>
<br/>
@@ -244,7 +244,11 @@
label="%{getText('pollen.common.login')}"/>
<s:textfield key="poll.creator.email" size="80"
label="%{getText('pollen.common.email')}"/>
- <s:hidden key="poll.creator.accountId" label=''/>
+ <s:hidden key="poll.creator.accountId"/>
+ <s:hidden key="poll.creator.topiaId"/>
+ <s:if test="creatorUserAccountDefined">
+ <s:hidden name="userId" value="%{poll.creator.userAccount.topiaId}"/>
+ </s:if>
</fieldset>
<br/>
1
0
r3233 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll resources resources/config resources/i18n webapp/WEB-INF/jsp webapp/WEB-INF/jsp/poll
by fdesbois@users.chorem.org 05 Apr '12
by fdesbois@users.chorem.org 05 Apr '12
05 Apr '12
Author: fdesbois
Date: 2012-04-05 09:50:32 +0200 (Thu, 05 Apr 2012)
New Revision: 3233
Url: http://chorem.org/repositories/revision/pollen/3233
Log:
improve CreatePoll/EditPoll/ClonePoll using different actions for loading (LoadPoll) and execution (SavePoll)
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
Removed:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java (from rev 3232, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-05 07:50:32 UTC (rev 3233)
@@ -0,0 +1,1096 @@
+package org.chorem.pollen.ui.actions.poll;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.interceptor.ParameterAware;
+import org.chorem.pollen.bean.ChoiceHelper;
+import org.chorem.pollen.bean.PollDateChoice;
+import org.chorem.pollen.bean.PollImageChoice;
+import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.business.persistence.ChoiceImpl;
+import org.chorem.pollen.business.persistence.PersonToList;
+import org.chorem.pollen.business.persistence.PersonToListImpl;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.business.persistence.PollAccountImpl;
+import org.chorem.pollen.business.persistence.VotingList;
+import org.chorem.pollen.business.persistence.VotingListImpl;
+import org.chorem.pollen.common.ChoiceType;
+import org.chorem.pollen.common.I18nAble;
+import org.chorem.pollen.common.PollType;
+import org.chorem.pollen.common.VoteCountingType;
+import org.chorem.pollen.services.impl.PollService;
+import org.chorem.pollen.ui.actions.FileUploadAware;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+import org.nuiton.util.StringUtil;
+
+import java.io.File;
+import java.text.ParseException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Created: 04/04/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ * $Id$
+ */
+public abstract class AbstractPollForm extends PollenActionSupport implements ParameterAware, FileUploadAware {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(AbstractPollForm.class);
+
+ private static final Pattern TEXT_CHOICE_NAME_PATTERN =
+ Pattern.compile("textChoice_(\\d+)\\.name");
+
+ private static final Pattern DATE_CHOICE_NAME_PATTERN =
+ Pattern.compile("dateChoice_(\\d+)\\.name");
+
+ private static final Pattern IMAGE_CHOICE_NAME_PATTERN =
+ Pattern.compile("imageChoice_(\\d+)\\.name");
+
+ private static final Pattern VOTING_LIST_NAME_PATTERN =
+ Pattern.compile("votingList_(\\d+)\\.name");
+
+ private Poll poll;
+
+ private Map<String, String> pollTypes;
+
+ private Map<String, String> voteCountingTypes;
+
+ private Map<String, String> choiceTypes;
+
+ private boolean notification;
+
+ private boolean reminder;
+
+ private boolean limitChoice;
+
+ private int reminderHourCountdown = 2;
+
+ private String textChoiceTokenId;
+
+ private String dateChoiceTokenId;
+
+ private String imageChoiceTokenId;
+
+ private String votingListTokenId;
+
+ private int nbTextChoices;
+
+ private int nbDateChoices;
+
+ private int nbImageChoices;
+
+ private int nbVotingLists;
+
+ /** Uploaded images (for choice type poll). */
+ private List<File> imageChoice;
+
+ /** Uploaded images content type (for choice type poll). */
+ private List<String> imageChoiceContentType;
+
+ /** Uploaded images name (from use desktop) (for choice type poll). */
+ private List<String> imageChoiceFileName;
+
+ private boolean informationsError;
+
+ private boolean optionsError;
+
+ private String actionLabel;
+
+ /**
+ * All the parameters send by request used to build back choices of the
+ * poll.
+ */
+ protected Map<String, String[]> parameters;
+
+ private transient PollService pollService;
+
+ protected abstract Poll initPoll();
+
+ @Override
+ public String getPageLogo() {
+ return "Creation";
+ }
+
+ public Poll getPoll() {
+ if (poll == null) {
+ poll = initPoll();
+ }
+ return poll;
+ }
+
+ public int getNbTextChoices() {
+ return nbTextChoices;
+ }
+
+ public String getTextChoiceTokenId() {
+ return textChoiceTokenId;
+ }
+
+ public int getNbDateChoices() {
+ return nbDateChoices;
+ }
+
+ public String getDateChoiceTokenId() {
+ return dateChoiceTokenId;
+ }
+
+ public int getNbImageChoices() {
+ return nbImageChoices;
+ }
+
+ public String getImageChoiceTokenId() {
+ return imageChoiceTokenId;
+ }
+
+ public int getNbVotingLists() {
+ return nbVotingLists;
+ }
+
+ public String getVotingListTokenId() {
+ return votingListTokenId;
+ }
+
+ 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;
+ }
+
+ @Override
+ public void setFiles(String paramName, List<File> files) {
+ this.imageChoice = Lists.newArrayList(files);
+ }
+
+ @Override
+ public void setFileContentTypes(String paramName, List<String> contentTypes) {
+ this.imageChoiceContentType = Lists.newArrayList(contentTypes);
+ }
+
+ @Override
+ public void setFileNames(String paramName, List<String> fileNames) {
+ this.imageChoiceFileName = Lists.newArrayList(fileNames);
+ }
+
+ public List<File> getImageChoice() {
+ if (imageChoice == null) {
+ imageChoice = Lists.newArrayList();
+ }
+ return imageChoice;
+ }
+
+ public List<String> getImageChoiceContentType() {
+ if (imageChoiceContentType == null) {
+ imageChoiceContentType = Lists.newArrayList();
+ }
+ return imageChoiceContentType;
+ }
+
+ public List<String> getImageChoiceFileName() {
+ if (imageChoiceFileName == null) {
+ imageChoiceFileName = Lists.newArrayList();
+ }
+ return imageChoiceFileName;
+ }
+
+ public boolean isInformationsError() {
+ return informationsError;
+ }
+
+ public boolean isOptionsError() {
+ return optionsError;
+ }
+
+ public boolean isFreePoll() {
+ PollType pollType = poll.getPollType();
+ return pollType == PollType.FREE;
+ }
+
+ public boolean isGroupPoll() {
+ PollType pollType = poll.getPollType();
+ return pollType == PollType.GROUP;
+ }
+
+ public String getPollVoteUrl() {
+ return getPollService().getPollVoteUrl(poll);
+ }
+
+ public String getPollEditUrl() {
+ return getPollService().getPollEditUrl(poll);
+ }
+
+ public int getSelectedTab() {
+ int result;
+ if (isInformationsError()) {
+ result = 0;
+ } else {
+ if (isOptionsError()) {
+ result = 1;
+ } else {
+ result = 0;
+ }
+ }
+ return result;
+ }
+
+ public String getActionLabel() {
+ return actionLabel;
+ }
+
+ protected int getNbChoices() {
+ //TODO tchemit-2012-03-05 use a default value from configuration
+ return 5;
+ }
+
+ protected int getDefaultNbVotingLists() {
+ return 1;
+ }
+
+ protected boolean isEdit() {
+ return getPoll().getTopiaId() != null;
+ }
+
+ public void prepareFormPage() throws Exception {
+
+ // remove all stuff from session
+ getPollenSession().clearDynamicData();
+
+ actionLabel = isEdit() ? _("pollen.action.editPoll") : _("pollen.action.createPoll");
+
+ pollTypes = decorateToName(PollType.values());
+ choiceTypes = decorateToName(ChoiceType.values());
+ voteCountingTypes = decorateToName(VoteCountingType.values());
+
+ nbTextChoices = nbDateChoices = nbImageChoices = getNbChoices();
+ nbVotingLists = getDefaultNbVotingLists();
+
+ String tokenSuffix = getServiceContext().createPollenUrlId();
+
+ textChoiceTokenId = DisplayTextChoice.CHOICE_TOKEN + "_" +
+ tokenSuffix;
+
+ dateChoiceTokenId = DisplayDateChoice.CHOICE_TOKEN + "_" +
+ tokenSuffix;
+
+ imageChoiceTokenId = DisplayImageChoice.CHOICE_TOKEN + "_" +
+ tokenSuffix;
+
+ ChoiceType pollChoiceType;
+ // Retrieve choiceType from parameters, the poll object will be updated after prepare
+ String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType");
+ if (choiceTypeParam == null) {
+
+ // Default value will be initiliazed on poll instanciation
+ pollChoiceType = getPoll().getChoiceType();
+
+ } else {
+ pollChoiceType = ChoiceType.valueOf(choiceTypeParam);
+ }
+
+ if (log.isInfoEnabled()) {
+ log.info("choice type " + pollChoiceType);
+ }
+
+ Map<Integer, Choice> choices = null;
+ String tokenId = null;
+
+ switch (pollChoiceType) {
+ case TEXT:
+ choices = buildTextChoices(nbTextChoices);
+ tokenId = textChoiceTokenId;
+ break;
+ case DATE:
+ choices = buildDateChoices(nbDateChoices);
+ tokenId = dateChoiceTokenId;
+ break;
+ case IMAGE:
+ choices = buildImageChoices(nbImageChoices);
+ tokenId = imageChoiceTokenId;
+ break;
+ }
+ getPollenSession().putDynamicData(tokenId, choices);
+
+ // load votingLists
+
+ votingListTokenId = DisplayVotingList.VOTING_LIST_TOKEN + "_" +
+ tokenSuffix;
+ Map<Integer, VotingList> votingLists = buildVotingLists(nbVotingLists);
+ getPollenSession().putDynamicData(votingListTokenId, votingLists);
+ }
+
+ @Override
+ public void validate() {
+
+ Preconditions.checkNotNull(poll);
+
+ informationsError = false;
+
+ // poll must have a title
+ if (StringUtils.isEmpty(poll.getTitle())) {
+ addFieldError("poll.title", _("pollen.error.poll.required.title"));
+ }
+
+
+ // validate choices
+ Map<Integer, Choice> orderedChoices = getOrderedChoices();
+
+ if (MapUtils.isEmpty(orderedChoices)) {
+
+ // poll must have at least one choice
+ addFieldError("poll.choices",
+ _("pollen.error.poll.required.one.choice"));
+ } else {
+//
+// //TODO tchemit improve this (from different cases text-date-image)
+// // check there is no choice with same name
+// boolean duplicateNameDetected = false;
+// Set<String> names = Sets.newHashSet();
+// for (Choice choice : orderedChoices.values()) {
+// String choiceName = choice.getName();
+// if (!names.add(choiceName)) {
+// duplicateNameDetected = true;
+// break;
+// }
+// }
+// if (duplicateNameDetected) {
+// addFieldError("poll.choices",
+// _("pollen.error.poll.detected.duplicate.choice.name"));
+// }
+
+ ChoiceType choiceType = poll.getChoiceType();
+ int inputChoicesSize = orderedChoices.size();
+ Set<Object> choiceValues =
+ Sets.newHashSet(ChoiceHelper.toValues(orderedChoices.values(), choiceType));
+
+ if (inputChoicesSize > choiceValues.size()) {
+ addFieldError("poll.choices",
+ _("pollen.error.poll.detected.duplicate.choice.name"));
+ }
+ }
+
+
+ optionsError = false;
+
+ // validate security stuff
+
+ if (isFreePoll()) {
+
+ // nothing to validate
+
+ } else {
+ Map<Integer, VotingList> votingLists = getOrderedVotingLists();
+
+ Set<String> groups = Sets.newHashSet();
+ Set<String> voters = Sets.newHashSet();
+ Set<String> emails = Sets.newHashSet();
+
+ for (Map.Entry<Integer, VotingList> entry : votingLists.entrySet()) {
+ optionsError |= validateVotingList(entry.getKey(),
+ entry.getValue(),
+ groups,
+ voters,
+ emails);
+ }
+ }
+
+ informationsError = hasFieldErrors();
+
+ if (!informationsError && optionsError) {
+
+ // trick to force to go back to form
+ addFieldError("", "");
+ }
+ }
+
+ protected boolean validateVotingList(int votingListNumber,
+ VotingList votingList,
+ Set<String> groups,
+ Set<String> voters,
+ Set<String> emails) {
+
+ boolean result = false;
+ Map<String, String> errors = Maps.newHashMap();
+
+ String votingListErrorPrefix = "poll.votingList_" + votingListNumber;
+
+ if (isGroupPoll()) {
+
+ // group poll
+
+ // check there is at least one group
+ // check no doublon on group names
+ // check there is at least one voter on each group
+ // check no doublon on voter names
+ // check no doublon on voter emails
+
+ { // validate votingList name
+ String votingListName = votingList.getName();
+
+ if (StringUtils.isEmpty(votingListName)) {
+
+ errors.put(votingListErrorPrefix + ".name",
+ _("pollen.error.poll.required.votingList.name"));
+ } else {
+
+ // check no votingList name doublon
+ boolean add = groups.add(votingListName);
+ if (!add) {
+
+ // name doublon
+ errors.put(
+ votingListErrorPrefix + ".name",
+ _("pollen.error.poll.votingList.name.doublon"));
+ }
+
+ }
+ }
+
+ { // validate votingList weight
+
+ if (votingList.getWeight() == 0) {
+
+ // no weight filled (can be a bad conversion)
+ errors.put(
+ votingListErrorPrefix + ".weight",
+ _("pollen.error.poll.votingList.weight.not.valid"));
+ }
+ }
+ }
+
+ // check there is at least one voter
+
+ String persontoListToken = DisplayPersonToList.getPersonToListTokenId(
+ votingListTokenId, votingListNumber);
+
+ Map<Integer, PersonToList> personToLists =
+ getPollenSession().getDynamicData(persontoListToken);
+
+ if (MapUtils.isEmpty(personToLists)) {
+
+ // no personToList found for unique votingList 0
+ errors.put(votingListErrorPrefix,
+ _("pollen.error.poll.required.one.personToList"));
+ } else {
+
+ // check no doublon on voter names
+ // check no doublon on voter emails
+
+ for (Map.Entry<Integer, PersonToList> entry :
+ personToLists.entrySet()) {
+
+ result |= validatePersonList(entry.getKey(), entry.getValue(),
+ voters, emails);
+ }
+ }
+
+ if (MapUtils.isNotEmpty(errors)) {
+
+ // keep errors to display them in correct action
+ String errorToken = DisplayVotingList.getVotingListErrorTokenId(
+ votingListTokenId, votingListNumber);
+ if (log.isInfoEnabled()) {
+ log.info("Add " + errors.size() + " errors to " + errorToken);
+ }
+ getPollenSession().putDynamicData(errorToken, errors);
+ result = true;
+ }
+ return result;
+ }
+
+ protected boolean validatePersonList(int personToListNumber,
+ PersonToList personToList,
+ Set<String> voters,
+ Set<String> emails) {
+
+ boolean result = false;
+ Map<String, String> errors = Maps.newHashMap();
+ String fieldNamePrefix =
+ "personToList_0_" + personToListNumber;
+ PollAccount pollAccount = personToList.getPollAccount();
+
+ { // validate votingId
+
+ String votingId = pollAccount.getVotingId();
+ // check voter is not doublon
+ boolean add = voters.add(votingId);
+ if (!add) {
+
+ // voter doublon
+ errors.put(
+ fieldNamePrefix + ".votingId",
+ _("pollen.error.poll.personToList.votingId.doublon"));
+ }
+ }
+ { // validate email
+ String email = pollAccount.getEmail();
+
+ if (StringUtils.isEmpty(email)) {
+ errors.put(
+ fieldNamePrefix + ".email",
+ _("pollen.error.poll.personToList.email.required"));
+ } else {
+
+
+ boolean validEmail = StringUtil.isEmail(email);
+ if (!validEmail) {
+
+ // not a valid email
+ errors.put(
+ fieldNamePrefix + ".email",
+ _("pollen.error.poll.personToList.email.not.valid"));
+ } else {
+
+ // check email not doublon
+ boolean add = emails.add(email);
+ if (!add) {
+
+ // email doublon
+ errors.put(
+ fieldNamePrefix + ".email",
+ _("pollen.error.poll.personToList.email.doublon"));
+ }
+ }
+ }
+ }
+ { // validate weight
+ if (personToList.getWeight() == 0) {
+
+ // no weight filled (can be a bad conversion)
+ errors.put(
+ fieldNamePrefix + ".weight",
+ _("pollen.error.poll.personToList.weight.not.valid"));
+ }
+ }
+
+ if (MapUtils.isNotEmpty(errors)) {
+ String errorToken =
+ DisplayPersonToList.getPersonToListErrorTokenId(
+ votingListTokenId, 0, personToListNumber);
+ if (log.isInfoEnabled()) {
+ log.info("Add " + errors.size() + " errors to " + errorToken);
+ }
+ getPollenSession().putDynamicData(errorToken, errors);
+ result = true;
+ }
+ return result;
+ }
+
+ @Override
+ public void setParameters(Map<String, String[]> parameters) {
+ this.parameters = parameters;
+ }
+
+ protected PollService getPollService() {
+ if (pollService == null) {
+ pollService = newService(PollService.class);
+ }
+ return pollService;
+ }
+
+ protected Map<Integer, Choice> getOrderedChoices() {
+ Map<Integer, Choice> result = null;
+ switch (poll.getChoiceType()) {
+ case TEXT:
+ result = getPollenSession().getDynamicData(textChoiceTokenId);
+ break;
+ case DATE:
+ result = getPollenSession().getDynamicData(dateChoiceTokenId);
+ break;
+ case IMAGE:
+ result = getPollenSession().getDynamicData(imageChoiceTokenId);
+ break;
+ }
+ return result;
+ }
+
+ protected Map<Integer, VotingList> getOrderedVotingLists() {
+
+ Map<Integer, VotingList> result = getPollenSession().getDynamicData(
+ votingListTokenId);
+ return result;
+ }
+
+ protected Map<Integer, Choice> buildTextChoices(int nbDefault) {
+ Map<Integer, Choice> result = Maps.newTreeMap();
+
+ int maxNumber = 0;
+
+ for (String paramName : parameters.keySet()) {
+
+ Matcher matcher = TEXT_CHOICE_NAME_PATTERN.matcher(paramName);
+ if (matcher.matches()) {
+
+ // found a text choice name
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+ if (paramValue != null) {
+
+ // can keep this none empty text choice name
+
+ Integer choiceNumber = Integer.valueOf(matcher.group(1));
+ if (choiceNumber > maxNumber) {
+ maxNumber = choiceNumber;
+ }
+ Choice choice = new ChoiceImpl();
+ createChoice(choice, "textChoice_" + choiceNumber,
+ paramValue);
+ result.put(choiceNumber, choice);
+ }
+ }
+ }
+ result = reindexMap(result, maxNumber);
+
+ int size = result.size();
+ nbTextChoices = Math.max(nbDefault, size);
+ log.info("nbTextChoices (from request) = " + size);
+ logChoice(result);
+ return result;
+ }
+
+ protected Map<Integer, Choice> buildDateChoices(int nbDefault) {
+ Map<Integer, Choice> result = Maps.newTreeMap();
+
+ int maxNumber = 0;
+ for (String paramName : parameters.keySet()) {
+
+ Matcher matcher = DATE_CHOICE_NAME_PATTERN.matcher(paramName);
+ if (matcher.matches()) {
+
+ // found a text choice name
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+ if (paramValue != null) {
+
+ // can keep this none empty text choice name
+
+ Integer choiceNumber = Integer.valueOf(matcher.group(1));
+ if (choiceNumber > maxNumber) {
+ maxNumber = choiceNumber;
+ }
+ PollDateChoice choice = new PollDateChoice();
+ createDateChoice(choice,
+ "dateChoice_" + choiceNumber,
+ paramValue);
+ result.put(choiceNumber, choice);
+ }
+ }
+ }
+ result = reindexMap(result, maxNumber);
+
+ int size = result.size();
+ nbDateChoices = Math.max(nbDefault, size);
+ log.info("nbDateChoices (from request) = " + size);
+ logChoice(result);
+ return result;
+ }
+
+ protected Map<Integer, Choice> buildImageChoices(int nbDefault) {
+ Map<Integer, Choice> result = Maps.newTreeMap();
+
+ // push back in parameters stuff from uploaded files
+ int index = 0;
+
+ for (String fileName : getImageChoiceFileName()) {
+ if (fileName != null) {
+ parameters.put("imageChoice_" + index + ".name",
+ new String[]{fileName});
+ parameters.put(
+ "imageChoice_" + index + ".location",
+ new String[]{getImageChoice().get(index).getAbsolutePath()});
+ }
+ index++;
+ }
+
+ int maxNumber = 0;
+ for (String paramName : parameters.keySet()) {
+
+ Matcher matcher = IMAGE_CHOICE_NAME_PATTERN.matcher(paramName);
+ if (matcher.matches()) {
+
+ // found an image choice name
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+ if (paramValue != null) {
+
+ // can keep this none empty text choice name
+
+ Integer choiceNumber = Integer.valueOf(matcher.group(1));
+ if (choiceNumber > maxNumber) {
+ maxNumber = choiceNumber;
+ }
+ PollImageChoice choice = new PollImageChoice();
+ createImageChoice(choice,
+ "imageChoice_" + choiceNumber,
+ paramValue);
+
+ result.put(choiceNumber, choice);
+ }
+ }
+ }
+ result = reindexMap(result, maxNumber);
+ int size = result.size();
+ nbImageChoices = Math.max(nbDefault, size);
+ log.info("nbImageChoices (from request) = " + size);
+ logChoice(result);
+ return result;
+ }
+
+ protected Map<Integer, VotingList> buildVotingLists(int nbDefault) {
+ Map<Integer, VotingList> result = Maps.newTreeMap();
+
+ int maxNumber = 0;
+
+ // get all votingList_ parameters
+ Set<String> votingListParameterNames = Sets.filter(
+ parameters.keySet(),
+ new StringStartWithPredicate("votingList_"));
+
+ for (String paramName : votingListParameterNames) {
+
+ Matcher matcher = VOTING_LIST_NAME_PATTERN.matcher(paramName);
+
+ if (matcher.matches()) {
+
+ // found a voting list name
+
+ int votingListNumber = buildVotingList(paramName,
+ matcher,
+ result
+ );
+ maxNumber = Math.max(maxNumber, votingListNumber);
+ }
+ }
+
+ result = reindexMap(result, maxNumber);
+
+ int size = result.size();
+ nbVotingLists = Math.max(nbDefault, size);
+ log.info("nbVotingList (from request) = " + size);
+
+ // add personToList maps to session (but just now, since votingList
+ // could have been reindex)
+ for (Map.Entry<Integer, VotingList> entry : result.entrySet()) {
+ Integer votingListNumber = entry.getKey();
+ VotingList votingList = entry.getValue();
+
+ if (!votingList.isPollAccountPersonToListEmpty()) {
+ List<PersonToList> personToList =
+ votingList.getPollAccountPersonToList();
+
+ Map<Integer, PersonToList> personToListMap = Maps.newTreeMap();
+ int index = 0;
+ for (PersonToList toList : personToList) {
+ personToListMap.put(index++, toList);
+ }
+
+ String token = DisplayPersonToList.getPersonToListTokenId(
+ votingListTokenId, votingListNumber);
+ if (log.isInfoEnabled()) {
+ log.info("Add " + token + " with " +
+ personToListMap.size() + " personToList");
+ }
+ getPollenSession().putDynamicData(token, personToListMap);
+ }
+ }
+
+ return result;
+ }
+
+ private double getDoubleValue(String parameterName) {
+ String parameterValue = getNonEmptyParameterValue(parameterName);
+ double result = 0;
+ if (StringUtils.isNotEmpty(parameterValue)) {
+
+ try {
+ result = Double.valueOf(parameterValue);
+ } catch (NumberFormatException e) {
+ //bad conversion, will be treated later
+ if (log.isDebugEnabled()) {
+ log.debug("Bad double conversion from param [" +
+ parameterName + "] : " + parameterValue);
+ }
+ }
+ }
+ return result;
+ }
+
+ private int buildVotingList(String votingListParameterName,
+ Matcher votingListMatcher,
+ Map<Integer, VotingList> result) {
+
+ String paramValue = getNonEmptyParameterValue(votingListParameterName);
+ int votingListNumber = Integer.valueOf(votingListMatcher.group(1));
+
+ VotingList votingList = new VotingListImpl();
+
+ votingList.setName(paramValue);
+
+ String prefix = "votingList_" + votingListNumber;
+
+ double weight = getDoubleValue(prefix + ".weight");
+ votingList.setWeight(weight);
+
+ String topiaId = getNonEmptyParameterValue(prefix + ".topiaId");
+ votingList.setTopiaId(topiaId);
+
+ result.put(votingListNumber, votingList);
+
+ String personToListPrefix = "personToList_" + votingListNumber + "_";
+
+ // get all personToList parameters
+ Set<String> votingListParameterNames = Sets.filter(
+ parameters.keySet(), new StringStartWithPredicate(personToListPrefix));
+
+ Pattern personToListNamePattern = Pattern.compile(
+ personToListPrefix + "(\\d+)\\.votingId");
+
+ Map<Integer, PersonToList> personToLists = Maps.newTreeMap();
+
+ int maxPersonToListNumber = 0;
+
+ // let's build personToList list
+ for (String personToListNameParameter : votingListParameterNames) {
+
+ Matcher matcher = personToListNamePattern.matcher(
+ personToListNameParameter);
+
+ if (matcher.matches()) {
+
+ int personToListNumber = buildPersonToList(
+ personToListPrefix,
+ personToListNameParameter,
+ matcher,
+ votingListNumber,
+ personToLists);
+
+ maxPersonToListNumber = Math.max(maxPersonToListNumber, personToListNumber);
+ }
+ }
+
+ personToLists = reindexMap(personToLists, maxPersonToListNumber);
+
+ for (PersonToList personToList : personToLists.values()) {
+ votingList.addPollAccountPersonToList(personToList);
+ }
+
+ return votingListNumber;
+ }
+
+ private int buildPersonToList(String personToListPrefix,
+ String paramName,
+ Matcher personToListMatcher,
+ int votingListNumber,
+ Map<Integer, PersonToList> result) {
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+
+ int personToListNumber = 0;
+
+ if (paramValue != null) {
+
+ // found a PersonToList none empty name, keep it
+
+ personToListNumber = Integer.valueOf(personToListMatcher.group(1));
+
+ PersonToList personToList = new PersonToListImpl();
+
+ PollAccount account = new PollAccountImpl();
+ personToList.setPollAccount(account);
+
+ account.setVotingId(paramValue);
+
+ String prefix = personToListPrefix + personToListNumber;
+
+ double weight = getDoubleValue(prefix + ".weight");
+ personToList.setWeight(weight);
+
+ String topiaId = getNonEmptyParameterValue(prefix + ".topiaId");
+ personToList.setTopiaId(topiaId);
+
+ String email = getNonEmptyParameterValue(prefix + ".email");
+ account.setEmail(email);
+
+ String accountId = getNonEmptyParameterValue(prefix + ".accountId");
+ account.setAccountId(accountId);
+
+ result.put(personToListNumber, personToList);
+ }
+ return personToListNumber;
+ }
+
+ private Choice createImageChoice(PollImageChoice choice,
+ String prefix,
+ String name) {
+ createChoice(choice, prefix, name);
+ String locationName = prefix + ".location";
+ String location = getNonEmptyParameterValue(locationName);
+ choice.setLocation(location);
+ if (log.isInfoEnabled()) {
+ log.info("image location [" + name + "] =" + location);
+ }
+ return choice;
+ }
+
+ private Choice createDateChoice(PollDateChoice choice,
+ String prefix,
+ String name) {
+ createChoice(choice, prefix, name);
+ if (StringUtils.isNotEmpty(name)) {
+ Date date = null;
+ try {
+ date = parseDateTime(name);
+ } catch (ParseException e) {
+ if (log.isErrorEnabled()) {
+ log.error("Unparseable date " + name, e);
+ }
+ }
+ choice.setDate(date);
+ }
+ return choice;
+ }
+
+ private Choice createChoice(Choice choice, String prefix, String name) {
+ String descriptionName = prefix + ".description";
+ String topiaIdName = prefix + ".topiaId";
+ String description = getNonEmptyParameterValue(descriptionName);
+ String topiaId = getNonEmptyParameterValue(topiaIdName);
+ choice.setName(name);
+ choice.setDescription(description);
+ choice.setTopiaId(topiaId);
+ return choice;
+ }
+
+ private void logChoice(Map<Integer, Choice> result) {
+ for (Map.Entry<Integer, Choice> e : result.entrySet()) {
+ Integer choiceId = e.getKey();
+ Choice choice = e.getValue();
+ if (log.isInfoEnabled()) {
+ log.info("Choice [" + choiceId + "] = " +
+ choice.getName() + " -- " +
+ choice.getDescription());
+ }
+ }
+ }
+
+
+ private <T> Map<Integer, T> reindexMap(Map<Integer, T> result, int maxNumber) {
+ Map<Integer, T> result2;
+
+ if (maxNumber != result.size() - 1) {
+
+ // means there is a hole inside the result (a empty choice was
+ // submitted)
+
+ // le'ts remove this
+ List<Integer> numbers = Lists.newArrayList(result.keySet());
+
+ Collections.sort(numbers);
+
+ result2 = Maps.newTreeMap();
+ int i = 0;
+ for (Integer number : numbers) {
+ T choice = result.get(number);
+ result2.put(i++, choice);
+ }
+ } else {
+ result2 = result;
+ }
+ return result2;
+ }
+
+ private <O> void addtoList(List<O> list, int index, O object) {
+
+ while (list.size() < index) {
+ list.add(null);
+ }
+ list.add(index, object);
+ }
+
+
+ private String getNonEmptyParameterValue(String paramName) {
+ String[] paramValues = parameters.get(paramName);
+ String result = null;
+ if (paramValues != null && paramValues.length == 1) {
+ String paramValue = paramValues[0];
+ if (StringUtils.isNotEmpty(paramValue)) {
+ result = paramValue;
+ }
+ }
+ return result;
+ }
+
+ private <E extends Enum<E> & I18nAble> Map<String, String> decorateToName(E... values) {
+ Map<String, String> result = Maps.newLinkedHashMap();
+ for (E value : values) {
+ result.put(value.name(), getText(value.getI18nKey()));
+ }
+ return result;
+ }
+
+ private static class StringStartWithPredicate implements Predicate<String> {
+ private final String prefix;
+
+ public StringStartWithPredicate(String prefix) {
+ this.prefix = prefix;
+ }
+
+ @Override
+ public boolean apply(String input) {
+ return input.startsWith(prefix);
+ }
+ }
+}
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java 2012-04-03 18:16:13 UTC (rev 3232)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java 2012-04-05 07:50:32 UTC (rev 3233)
@@ -1,226 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import org.chorem.pollen.bean.PollImageChoice;
-import org.chorem.pollen.bean.PollUri;
-import org.chorem.pollen.business.persistence.Choice;
-import org.chorem.pollen.business.persistence.PersonToList;
-import org.chorem.pollen.business.persistence.Poll;
-import org.chorem.pollen.business.persistence.PollAccount;
-import org.chorem.pollen.business.persistence.VotingList;
-import org.chorem.pollen.common.ChoiceType;
-import org.chorem.pollen.common.PollType;
-
-import java.util.List;
-
-/**
- * Creates a new poll by cloning an existing one.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @author fdesbois <desbois(a)codelutin.com>
- * @since 1.2.6
- */
-public class ClonePoll extends CreatePoll {
-
- private static final long serialVersionUID = 1L;
-
- private static final String PREFIX_CHOICE = "%sChoice_%d";
-
- private static final String PREFIX_VOTING_LIST = "votingList_%d";
-
- private static final String PREFIX_PERSON_TO_LIST = "personToList_%d_%d";
-
- protected PollUri pollUri;
-
- public final PollUri getUriId() {
- return pollUri;
- }
-
- public final void setUriId(PollUri pollUri) {
- this.pollUri = pollUri;
- }
-
- public String getPollUid() {
- return pollUri.getPollId();
- }
-
- protected boolean keepTopiaId() {
- return false;
- }
-
- @Override
- public Poll getPoll() {
- if (poll == null) {
- poll = getPollService().getPollByPollId(getPollUid());
-
- if (!keepTopiaId()) {
- poll.setTopiaId(null);
-
- // Use a new pollId
- String pollUid = serviceContext.createPollenUrlId();
- poll.setPollId(pollUid);
- }
- }
- return poll;
- }
-
- @Override
- public void prepare() throws Exception {
-
- // -- Choice --
- ChoiceType choiceType = getPoll().getChoiceType();
- prepareParams(getPoll().getChoice(), withChoicePrefix(choiceType));
-
- // -- VotingList --
- if (getPoll().getPollType() != PollType.FREE) {
- prepareParams(getPoll().getVotingList(), withVotingListPrefix());
- }
-
- super.prepare();
- }
-
- private Function<Choice, String> withChoicePrefix(final ChoiceType choiceType) {
- final String choiceTypeName = choiceType.name().toLowerCase();
- return new IndexedFunction<Choice, String>() {
-
- @Override
- protected String apply(Choice input, int index) {
-
- String prefix = String.format(PREFIX_CHOICE, choiceTypeName, index);
- if (keepTopiaId()) {
- putParameter(prefix, Choice.TOPIA_ID, input.getTopiaId());
- }
- putParameter(prefix, Choice.PROPERTY_NAME, input.getName());
- putParameter(prefix, Choice.PROPERTY_DESCRIPTION, input.getDescription());
-
- if (choiceType == ChoiceType.IMAGE) {
- putParameter(prefix, PollImageChoice.PROPERTY_LOCATION, input.getName());
- }
-
- return prefix;
- }
- };
- }
-
- private Function<VotingList, String> withVotingListPrefix() {
- return new IndexedFunction<VotingList, String>() {
-
- @Override
- protected String apply(VotingList input, int index) {
-
- String prefix = String.format(PREFIX_VOTING_LIST, index);
- if (keepTopiaId()) {
- putParameter(prefix, VotingList.TOPIA_ID, input.getTopiaId());
- }
- putParameter(prefix, VotingList.PROPERTY_NAME, input.getName());
- putParameter(prefix, VotingList.PROPERTY_WEIGHT, String.valueOf(input.getWeight()));
-
- prepareParams(input.getPollAccountPersonToList(), withPersonToListPrefix(index));
-
- return prefix;
- }
- };
- }
-
- private Function<PersonToList, String> withPersonToListPrefix(final int votingListIndex) {
- return new IndexedFunction<PersonToList, String>() {
-
- @Override
- protected String apply(PersonToList input, int index) {
-
- PollAccount pollAccount = input.getPollAccount();
-
- String prefix = String.format(PREFIX_PERSON_TO_LIST, votingListIndex, index);
- if (keepTopiaId()) {
- putParameter(prefix, PersonToList.TOPIA_ID, input.getTopiaId());
- }
- putParameter(prefix, PersonToList.PROPERTY_WEIGHT, String.valueOf(input.getWeight()));
- putParameter(prefix, PollAccount.PROPERTY_ACCOUNT_ID, pollAccount.getAccountId());
- putParameter(prefix, PollAccount.PROPERTY_VOTING_ID, pollAccount.getVotingId());
- putParameter(prefix, PollAccount.PROPERTY_EMAIL, pollAccount.getEmail());
-
- return prefix;
- }
- };
- }
-
- /**
- * Prepare the {@code source} for parameters using the {@code function} to
- * push necessary data.
- *
- * @param source List of elements
- * @param function Function used to push element data using {@link #putParameter(String, String, String)}
- * @param <T> Type of data
- * @see #putParameter(String, String, String)
- */
- private <T> void prepareParams(List<T> source, Function<T, String> function) {
- ImmutableList.copyOf(Lists.transform(source, function));
- }
-
- /**
- * Put some data in the {@code parameters} with name built using
- * {@code prefix} and {@code property}. The {@code value} will be put for
- * this parameter.
- *
- * @param prefix Prefix to use for the parameter name
- * @param property Name of the {@code property} to push in parameters
- * @param value Value of this {@code property}
- */
- private void putParameter(String prefix, String property, String value) {
- parameters.put(prefix + "." + property, new String[]{value});
- }
-
- /**
- * Guava {@link Function} that keeps index on each {@link Function#apply(Object)} call.
- * You just have to implement {@link #apply(Object, int)} to have the current
- * index of the {@code input} value.
- *
- * @param <F> Type of data where function will be applied on
- * @param <T> Resulting type
- */
- private abstract static class IndexedFunction<F, T> implements Function<F, T> {
-
- private int index;
-
- @Override
- public T apply(F input) {
- T result = apply(input, index);
- index++;
- return result;
- }
-
- /**
- * Called during {@link #apply(Object)} method with current {@code index}.
- *
- * @param input current value
- * @param index current index
- * @return the result of the function applied on the {@code input} object
- */
- protected abstract T apply(F input, int index);
- }
-}
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-04-03 18:16:13 UTC (rev 3232)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-04-05 07:50:32 UTC (rev 3233)
@@ -1,1163 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.opensymphony.xwork2.Preparable;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.struts2.interceptor.ParameterAware;
-import org.chorem.pollen.bean.ChoiceHelper;
-import org.chorem.pollen.bean.PollDateChoice;
-import org.chorem.pollen.bean.PollImageChoice;
-import org.chorem.pollen.business.persistence.Choice;
-import org.chorem.pollen.business.persistence.ChoiceImpl;
-import org.chorem.pollen.business.persistence.PersonToList;
-import org.chorem.pollen.business.persistence.PersonToListImpl;
-import org.chorem.pollen.business.persistence.Poll;
-import org.chorem.pollen.business.persistence.PollAccount;
-import org.chorem.pollen.business.persistence.PollAccountImpl;
-import org.chorem.pollen.business.persistence.PreventRule;
-import org.chorem.pollen.business.persistence.UserAccount;
-import org.chorem.pollen.business.persistence.VotingList;
-import org.chorem.pollen.business.persistence.VotingListImpl;
-import org.chorem.pollen.common.ChoiceType;
-import org.chorem.pollen.common.I18nAble;
-import org.chorem.pollen.common.PollType;
-import org.chorem.pollen.common.VoteCountingType;
-import org.chorem.pollen.services.impl.PollService;
-import org.chorem.pollen.services.impl.PreventRuleService;
-import org.chorem.pollen.ui.actions.FileUploadAware;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
-import org.nuiton.util.StringUtil;
-
-import java.io.File;
-import java.text.ParseException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Creates a new poll.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.2.6
- */
-public class CreatePoll extends PollenActionSupport implements Preparable, ParameterAware, FileUploadAware {
-
- private static final long serialVersionUID = 1L;
-
- /** Logger. */
- private static final Log log = LogFactory.getLog(CreatePoll.class);
-
- public static final Pattern TEXT_CHOICE_NAME_PATTERN =
- Pattern.compile("textChoice_(\\d+)\\.name");
-
- public static final Pattern DATE_CHOICE_NAME_PATTERN =
- Pattern.compile("dateChoice_(\\d+)\\.name");
-
- public static final Pattern IMAGE_CHOICE_NAME_PATTERN =
- Pattern.compile("imageChoice_(\\d+)\\.name");
-
- public static final Pattern VOTING_LIST_NAME_PATTERN =
- Pattern.compile("votingList_(\\d+)\\.name");
-
- 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 = 2;
-
- private String textChoiceTokenId;
-
- private String dateChoiceTokenId;
-
- private String imageChoiceTokenId;
-
- private String votingListTokenId;
-
- private int nbTextChoices;
-
- private int nbDateChoices;
-
- private int nbImageChoices;
-
- private int nbVotingLists;
-
- /** Uploaded images (for choice type poll). */
- private List<File> imageChoice;
-
- /** Uploaded images content type (for choice type poll). */
- private List<String> imageChoiceContentType;
-
- /** Uploaded images name (from use desktop) (for choice type poll). */
- private List<String> imageChoiceFileName;
-
- /**
- * All the parameters send by request used to build back choices of the
- * poll.
- */
- protected Map<String, String[]> parameters;
-
- private boolean informationsError;
-
- private boolean optionsError;
-
- protected transient PollService pollService;
-
- @Override
- public String getPageLogo() {
- return "Creation";
- }
-
- public Poll getPoll() {
- if (poll == null) {
- // create poll
- UserAccount userAccount = getPollenUserAccount();
- poll = getPollService().getNewPoll(userAccount);
- }
- return poll;
- }
-
- public int getNbTextChoices() {
- return nbTextChoices;
- }
-
- public String getTextChoiceTokenId() {
- return textChoiceTokenId;
- }
-
- public int getNbDateChoices() {
- return nbDateChoices;
- }
-
- public String getDateChoiceTokenId() {
- return dateChoiceTokenId;
- }
-
- public int getNbImageChoices() {
- return nbImageChoices;
- }
-
- public String getImageChoiceTokenId() {
- return imageChoiceTokenId;
- }
-
- public int getNbVotingLists() {
- return nbVotingLists;
- }
-
- public String getVotingListTokenId() {
- return votingListTokenId;
- }
-
- 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;
- }
-
- @Override
- public void setFiles(String paramName, List<File> files) {
- this.imageChoice = Lists.newArrayList(files);
- }
-
- @Override
- public void setFileContentTypes(String paramName, List<String> contentTypes) {
- this.imageChoiceContentType = Lists.newArrayList(contentTypes);
- }
-
- @Override
- public void setFileNames(String paramName, List<String> fileNames) {
- this.imageChoiceFileName = Lists.newArrayList(fileNames);
- }
-
- public List<File> getImageChoice() {
- if (imageChoice == null) {
- imageChoice = Lists.newArrayList();
- }
- return imageChoice;
- }
-
- public List<String> getImageChoiceContentType() {
- if (imageChoiceContentType == null) {
- imageChoiceContentType = Lists.newArrayList();
- }
- return imageChoiceContentType;
- }
-
- public List<String> getImageChoiceFileName() {
- if (imageChoiceFileName == null) {
- imageChoiceFileName = Lists.newArrayList();
- }
- return imageChoiceFileName;
- }
-
- public boolean isInformationsError() {
- return informationsError;
- }
-
- public boolean isOptionsError() {
- return optionsError;
- }
-
- public boolean isFreePoll() {
- PollType pollType = poll.getPollType();
- return pollType == PollType.FREE;
- }
-
- public boolean isGroupPoll() {
- PollType pollType = poll.getPollType();
- return pollType == PollType.GROUP;
- }
-
- public String getPollVoteUrl() {
- return getPollService().getPollVoteUrl(poll);
- }
-
- public String getPollEditUrl() {
- return getPollService().getPollEditUrl(poll);
- }
-
- public int getSelectedTab() {
- int result;
- if (isInformationsError()) {
- result = 0;
- } else {
- if (isOptionsError()) {
- result = 1;
- } else {
- result = 0;
- }
- }
- return result;
- }
-
- protected int getNbChoices() {
- //TODO tchemit-2012-03-05 use a default value from configuration
- return 5;
- }
-
- protected int getDefaultNbVotingLists() {
- return 1;
- }
-
- @Override
- public void prepare() throws Exception {
-
- // remove all stuff from session
- getPollenSession().clearDynamicData();
-
- pollTypes = decorateToName(PollType.values());
- choiceTypes = decorateToName(ChoiceType.values());
- voteCountingTypes = decorateToName(VoteCountingType.values());
-
- nbTextChoices = nbDateChoices = nbImageChoices = getNbChoices();
- nbVotingLists = getDefaultNbVotingLists();
-
- String tokenSuffix = getServiceContext().createPollenUrlId();
-
- textChoiceTokenId = DisplayTextChoice.CHOICE_TOKEN + "_" +
- tokenSuffix;
-
- dateChoiceTokenId = DisplayDateChoice.CHOICE_TOKEN + "_" +
- tokenSuffix;
-
- imageChoiceTokenId = DisplayImageChoice.CHOICE_TOKEN + "_" +
- tokenSuffix;
-
- ChoiceType pollChoiceType;
- // Retrieve choiceType from parameters, the poll object will be updated after prepare
- String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType");
- if (choiceTypeParam == null) {
-
- // Default value will be initiliazed on poll instanciation
- pollChoiceType = getPoll().getChoiceType();
-
- } else {
- pollChoiceType = ChoiceType.valueOf(choiceTypeParam);
- }
-
- if (log.isInfoEnabled()) {
- log.info("choice type " + pollChoiceType);
- }
-
- Map<Integer, Choice> choices = null;
- String tokenId = null;
-
- switch (pollChoiceType) {
- case TEXT:
- choices = buildTextChoices(nbTextChoices);
- tokenId = textChoiceTokenId;
- break;
- case DATE:
- choices = buildDateChoices(nbDateChoices);
- tokenId = dateChoiceTokenId;
- break;
- case IMAGE:
- choices = buildImageChoices(nbImageChoices);
- tokenId = imageChoiceTokenId;
- break;
- }
- getPollenSession().putDynamicData(tokenId, choices);
-
- // load votingLists
-
- votingListTokenId = DisplayVotingList.VOTING_LIST_TOKEN + "_" +
- tokenSuffix;
- Map<Integer, VotingList> votingLists = buildVotingLists(nbVotingLists);
- getPollenSession().putDynamicData(votingListTokenId, votingLists);
- }
-
- @Override
- public void validate() {
-
- Preconditions.checkNotNull(poll);
-
- informationsError = false;
-
- // poll must have a title
- if (StringUtils.isEmpty(poll.getTitle())) {
- addFieldError("poll.title", _("pollen.error.poll.required.title"));
- }
-
-
- // validate choices
- Map<Integer, Choice> orderedChoices = getOrderedChoices();
-
- if (MapUtils.isEmpty(orderedChoices)) {
-
- // poll must have at least one choice
- addFieldError("poll.choices",
- _("pollen.error.poll.required.one.choice"));
- } else {
-//
-// //TODO tchemit improve this (from different cases text-date-image)
-// // check there is no choice with same name
-// boolean duplicateNameDetected = false;
-// Set<String> names = Sets.newHashSet();
-// for (Choice choice : orderedChoices.values()) {
-// String choiceName = choice.getName();
-// if (!names.add(choiceName)) {
-// duplicateNameDetected = true;
-// break;
-// }
-// }
-// if (duplicateNameDetected) {
-// addFieldError("poll.choices",
-// _("pollen.error.poll.detected.duplicate.choice.name"));
-// }
-
- ChoiceType choiceType = poll.getChoiceType();
- int inputChoicesSize = orderedChoices.size();
- Set<Object> choiceValues =
- Sets.newHashSet(ChoiceHelper.toValues(orderedChoices.values(), choiceType));
-
- if (inputChoicesSize > choiceValues.size()) {
- addFieldError("poll.choices",
- _("pollen.error.poll.detected.duplicate.choice.name"));
- }
- }
-
-
- optionsError = false;
-
- // validate security stuff
-
- if (isFreePoll()) {
-
- // nothing to validate
-
- } else {
- Map<Integer, VotingList> votingLists = getOrderedVotingLists();
-
- Set<String> groups = Sets.newHashSet();
- Set<String> voters = Sets.newHashSet();
- Set<String> emails = Sets.newHashSet();
-
- for (Map.Entry<Integer, VotingList> entry : votingLists.entrySet()) {
- optionsError |= validateVotingList(entry.getKey(),
- entry.getValue(),
- groups,
- voters,
- emails);
- }
- }
-
- informationsError = hasFieldErrors();
-
- if (!informationsError && optionsError) {
-
- // trick to force to go back to form
- addFieldError("", "");
- }
- }
-
- @Override
- public String execute() throws Exception {
-
- Map<Integer, Choice> orderedChoices = getOrderedChoices();
-
- for (Integer index : orderedChoices.keySet()) {
- Choice choice = orderedChoices.get(index);
- poll.addChoice(choice);
- }
-
- if (!isFreePoll()) {
-
- Map<Integer, VotingList> votingLists = getOrderedVotingLists();
- for (Integer index : votingLists.keySet()) {
- VotingList votingList = votingLists.get(index);
- poll.addVotingList(votingList);
- }
- }
-
- PollService service = getPollService();
-
- PreventRuleService preventRuleService =
- newService(PreventRuleService.class);
- if (isNotification()) {
-
- // add a notification rule
-
- PreventRule rule = preventRuleService.createAddVotePreventRule();
- poll.addPreventRule(rule);
- }
-
- if (isReminder()) {
-
- // add a reminder rule
-
- PreventRule rule = preventRuleService.createRemindPreventRule(
- getReminderHourCountdown()
- );
-
- poll.addPreventRule(rule);
- }
-
- poll = service.createPoll(poll);
-
- // remove all stuff from session
- getPollenSession().clearDynamicData();
-
- addActionMessage(_("pollen.information.poll.created"));
- return SUCCESS;
- }
-
- protected boolean validateVotingList(int votingListNumber,
- VotingList votingList,
- Set<String> groups,
- Set<String> voters,
- Set<String> emails) {
-
- boolean result = false;
- Map<String, String> errors = Maps.newHashMap();
-
- String votingListErrorPrefix = "poll.votingList_" + votingListNumber;
-
- if (isGroupPoll()) {
-
- // group poll
-
- // check there is at least one group
- // check no doublon on group names
- // check there is at least one voter on each group
- // check no doublon on voter names
- // check no doublon on voter emails
-
- { // validate votingList name
- String votingListName = votingList.getName();
-
- if (StringUtils.isEmpty(votingListName)) {
-
- errors.put(votingListErrorPrefix + ".name",
- _("pollen.error.poll.required.votingList.name"));
- } else {
-
- // check no votingList name doublon
- boolean add = groups.add(votingListName);
- if (!add) {
-
- // name doublon
- errors.put(
- votingListErrorPrefix + ".name",
- _("pollen.error.poll.votingList.name.doublon"));
- }
-
- }
- }
-
- { // validate votingList weight
-
- if (votingList.getWeight() == 0) {
-
- // no weight filled (can be a bad conversion)
- errors.put(
- votingListErrorPrefix + ".weight",
- _("pollen.error.poll.votingList.weight.not.valid"));
- }
- }
- }
-
- // check there is at least one voter
-
- String persontoListToken = DisplayPersonToList.getPersonToListTokenId(
- votingListTokenId, votingListNumber);
-
- Map<Integer, PersonToList> personToLists =
- getPollenSession().getDynamicData(persontoListToken);
-
- if (MapUtils.isEmpty(personToLists)) {
-
- // no personToList found for unique votingList 0
- errors.put(votingListErrorPrefix,
- _("pollen.error.poll.required.one.personToList"));
- } else {
-
- // check no doublon on voter names
- // check no doublon on voter emails
-
- for (Map.Entry<Integer, PersonToList> entry :
- personToLists.entrySet()) {
-
- result |= validatePersonList(entry.getKey(), entry.getValue(),
- voters, emails);
- }
- }
-
- if (MapUtils.isNotEmpty(errors)) {
-
- // keep errors to display them in correct action
- String errorToken = DisplayVotingList.getVotingListErrorTokenId(
- votingListTokenId, votingListNumber);
- if (log.isInfoEnabled()) {
- log.info("Add " + errors.size() + " errors to " + errorToken);
- }
- getPollenSession().putDynamicData(errorToken, errors);
- result = true;
- }
- return result;
- }
-
- protected boolean validatePersonList(int personToListNumber,
- PersonToList personToList,
- Set<String> voters,
- Set<String> emails) {
-
- boolean result = false;
- Map<String, String> errors = Maps.newHashMap();
- String fieldNamePrefix =
- "personToList_0_" + personToListNumber;
- PollAccount pollAccount = personToList.getPollAccount();
-
- { // validate votingId
-
- String votingId = pollAccount.getVotingId();
- // check voter is not doublon
- boolean add = voters.add(votingId);
- if (!add) {
-
- // voter doublon
- errors.put(
- fieldNamePrefix + ".votingId",
- _("pollen.error.poll.personToList.votingId.doublon"));
- }
- }
- { // validate email
- String email = pollAccount.getEmail();
-
- if (StringUtils.isEmpty(email)) {
- errors.put(
- fieldNamePrefix + ".email",
- _("pollen.error.poll.personToList.email.required"));
- } else {
-
-
- boolean validEmail = StringUtil.isEmail(email);
- if (!validEmail) {
-
- // not a valid email
- errors.put(
- fieldNamePrefix + ".email",
- _("pollen.error.poll.personToList.email.not.valid"));
- } else {
-
- // check email not doublon
- boolean add = emails.add(email);
- if (!add) {
-
- // email doublon
- errors.put(
- fieldNamePrefix + ".email",
- _("pollen.error.poll.personToList.email.doublon"));
- }
- }
- }
- }
- { // validate weight
- if (personToList.getWeight() == 0) {
-
- // no weight filled (can be a bad conversion)
- errors.put(
- fieldNamePrefix + ".weight",
- _("pollen.error.poll.personToList.weight.not.valid"));
- }
- }
-
- if (MapUtils.isNotEmpty(errors)) {
- String errorToken =
- DisplayPersonToList.getPersonToListErrorTokenId(
- votingListTokenId, 0, personToListNumber);
- if (log.isInfoEnabled()) {
- log.info("Add " + errors.size() + " errors to " + errorToken);
- }
- getPollenSession().putDynamicData(errorToken, errors);
- result = true;
- }
- return result;
- }
-
- @Override
- public void setParameters(Map<String, String[]> parameters) {
- this.parameters = parameters;
- }
-
- protected PollService getPollService() {
- if (pollService == null) {
- pollService = newService(PollService.class);
- }
- return pollService;
- }
-
- protected Map<Integer, Choice> getOrderedChoices() {
- Map<Integer, Choice> result = null;
- switch (poll.getChoiceType()) {
- case TEXT:
- result = getPollenSession().getDynamicData(textChoiceTokenId);
- break;
- case DATE:
- result = getPollenSession().getDynamicData(dateChoiceTokenId);
- break;
- case IMAGE:
- result = getPollenSession().getDynamicData(imageChoiceTokenId);
- break;
- }
- return result;
- }
-
- protected Map<Integer, VotingList> getOrderedVotingLists() {
-
- Map<Integer, VotingList> result = getPollenSession().getDynamicData(
- votingListTokenId);
- return result;
- }
-
- protected Map<Integer, Choice> buildTextChoices(int nbDefault) {
- Map<Integer, Choice> result = Maps.newTreeMap();
-
- int maxNumber = 0;
-
- for (String paramName : parameters.keySet()) {
-
- Matcher matcher = TEXT_CHOICE_NAME_PATTERN.matcher(paramName);
- if (matcher.matches()) {
-
- // found a text choice name
-
- String paramValue = getNonEmptyParameterValue(paramName);
- if (paramValue != null) {
-
- // can keep this none empty text choice name
-
- Integer choiceNumber = Integer.valueOf(matcher.group(1));
- if (choiceNumber > maxNumber) {
- maxNumber = choiceNumber;
- }
- Choice choice = new ChoiceImpl();
- createChoice(choice, "textChoice_" + choiceNumber,
- paramValue);
- result.put(choiceNumber, choice);
- }
- }
- }
- result = reindexMap(result, maxNumber);
-
- int size = result.size();
- nbTextChoices = Math.max(nbDefault, size);
- log.info("nbTextChoices (from request) = " + size);
- logChoice(result);
- return result;
- }
-
- protected Map<Integer, Choice> buildDateChoices(int nbDefault) {
- Map<Integer, Choice> result = Maps.newTreeMap();
-
- int maxNumber = 0;
- for (String paramName : parameters.keySet()) {
-
- Matcher matcher = DATE_CHOICE_NAME_PATTERN.matcher(paramName);
- if (matcher.matches()) {
-
- // found a text choice name
-
- String paramValue = getNonEmptyParameterValue(paramName);
- if (paramValue != null) {
-
- // can keep this none empty text choice name
-
- Integer choiceNumber = Integer.valueOf(matcher.group(1));
- if (choiceNumber > maxNumber) {
- maxNumber = choiceNumber;
- }
- PollDateChoice choice = new PollDateChoice();
- createDateChoice(choice,
- "dateChoice_" + choiceNumber,
- paramValue);
- result.put(choiceNumber, choice);
- }
- }
- }
- result = reindexMap(result, maxNumber);
-
- int size = result.size();
- nbDateChoices = Math.max(nbDefault, size);
- log.info("nbDateChoices (from request) = " + size);
- logChoice(result);
- return result;
- }
-
- protected Map<Integer, Choice> buildImageChoices(int nbDefault) {
- Map<Integer, Choice> result = Maps.newTreeMap();
-
- // push back in parameters stuff from uploaded files
- int index = 0;
-
- for (String fileName : getImageChoiceFileName()) {
- if (fileName != null) {
- parameters.put("imageChoice_" + index + ".name",
- new String[]{fileName});
- parameters.put(
- "imageChoice_" + index + ".location",
- new String[]{getImageChoice().get(index).getAbsolutePath()});
- }
- index++;
- }
-
- int maxNumber = 0;
- for (String paramName : parameters.keySet()) {
-
- Matcher matcher = IMAGE_CHOICE_NAME_PATTERN.matcher(paramName);
- if (matcher.matches()) {
-
- // found an image choice name
-
- String paramValue = getNonEmptyParameterValue(paramName);
- if (paramValue != null) {
-
- // can keep this none empty text choice name
-
- Integer choiceNumber = Integer.valueOf(matcher.group(1));
- if (choiceNumber > maxNumber) {
- maxNumber = choiceNumber;
- }
- PollImageChoice choice = new PollImageChoice();
- createImageChoice(choice,
- "imageChoice_" + choiceNumber,
- paramValue);
-
- result.put(choiceNumber, choice);
- }
- }
- }
- result = reindexMap(result, maxNumber);
- int size = result.size();
- nbImageChoices = Math.max(nbDefault, size);
- log.info("nbImageChoices (from request) = " + size);
- logChoice(result);
- return result;
- }
-
- protected Map<Integer, VotingList> buildVotingLists(int nbDefault) {
- Map<Integer, VotingList> result = Maps.newTreeMap();
-
- int maxNumber = 0;
-
- // get all votingList_ parameters
- Set<String> votingListParameterNames = Sets.filter(
- parameters.keySet(),
- new StringStartWithPredicate("votingList_"));
-
- for (String paramName : votingListParameterNames) {
-
- Matcher matcher = VOTING_LIST_NAME_PATTERN.matcher(paramName);
-
- if (matcher.matches()) {
-
- // found a voting list name
-
- int votingListNumber = buildVotingList(paramName,
- matcher,
- result
- );
- maxNumber = Math.max(maxNumber, votingListNumber);
- }
- }
-
- result = reindexMap(result, maxNumber);
-
- int size = result.size();
- nbVotingLists = Math.max(nbDefault, size);
- log.info("nbVotingList (from request) = " + size);
-
- // add personToList maps to session (but just now, since votingList
- // could have been reindex)
- for (Map.Entry<Integer, VotingList> entry : result.entrySet()) {
- Integer votingListNumber = entry.getKey();
- VotingList votingList = entry.getValue();
-
- if (!votingList.isPollAccountPersonToListEmpty()) {
- List<PersonToList> personToList =
- votingList.getPollAccountPersonToList();
-
- Map<Integer, PersonToList> personToListMap = Maps.newTreeMap();
- int index = 0;
- for (PersonToList toList : personToList) {
- personToListMap.put(index++, toList);
- }
-
- String token = DisplayPersonToList.getPersonToListTokenId(
- votingListTokenId, votingListNumber);
- if (log.isInfoEnabled()) {
- log.info("Add " + token + " with " +
- personToListMap.size() + " personToList");
- }
- getPollenSession().putDynamicData(token, personToListMap);
- }
- }
-
- return result;
- }
-
- private double getDoubleValue(String parameterName) {
- String parameterValue = getNonEmptyParameterValue(parameterName);
- double result = 0;
- if (StringUtils.isNotEmpty(parameterValue)) {
-
- try {
- result = Double.valueOf(parameterValue);
- } catch (NumberFormatException e) {
- //bad conversion, will be treated later
- if (log.isDebugEnabled()) {
- log.debug("Bad double conversion from param [" +
- parameterName + "] : " + parameterValue);
- }
- }
- }
- return result;
- }
-
- private int buildVotingList(String votingListParameterName,
- Matcher votingListMatcher,
- Map<Integer, VotingList> result) {
-
- String paramValue = getNonEmptyParameterValue(votingListParameterName);
- int votingListNumber = Integer.valueOf(votingListMatcher.group(1));
-
- VotingList votingList = new VotingListImpl();
-
- votingList.setName(paramValue);
-
- String prefix = "votingList_" + votingListNumber;
-
- double weight = getDoubleValue(prefix + ".weight");
- votingList.setWeight(weight);
-
- String topiaId = getNonEmptyParameterValue(prefix + ".topiaId");
- votingList.setTopiaId(topiaId);
-
- result.put(votingListNumber, votingList);
-
- String personToListPrefix = "personToList_" + votingListNumber + "_";
-
- // get all personToList parameters
- Set<String> votingListParameterNames = Sets.filter(
- parameters.keySet(), new StringStartWithPredicate(personToListPrefix));
-
- Pattern personToListNamePattern = Pattern.compile(
- personToListPrefix + "(\\d+)\\.votingId");
-
- Map<Integer, PersonToList> personToLists = Maps.newTreeMap();
-
- int maxPersonToListNumber = 0;
-
- // let's build personToList list
- for (String personToListNameParameter : votingListParameterNames) {
-
- Matcher matcher = personToListNamePattern.matcher(
- personToListNameParameter);
-
- if (matcher.matches()) {
-
- int personToListNumber = buildPersonToList(
- personToListPrefix,
- personToListNameParameter,
- matcher,
- votingListNumber,
- personToLists);
-
- maxPersonToListNumber = Math.max(maxPersonToListNumber, personToListNumber);
- }
- }
-
- personToLists = reindexMap(personToLists, maxPersonToListNumber);
-
- for (PersonToList personToList : personToLists.values()) {
- votingList.addPollAccountPersonToList(personToList);
- }
-
- return votingListNumber;
- }
-
- private int buildPersonToList(String personToListPrefix,
- String paramName,
- Matcher personToListMatcher,
- int votingListNumber,
- Map<Integer, PersonToList> result) {
-
- String paramValue = getNonEmptyParameterValue(paramName);
-
- int personToListNumber = 0;
-
- if (paramValue != null) {
-
- // found a PersonToList none empty name, keep it
-
- personToListNumber = Integer.valueOf(personToListMatcher.group(1));
-
- PersonToList personToList = new PersonToListImpl();
-
- PollAccount account = new PollAccountImpl();
- personToList.setPollAccount(account);
-
- account.setVotingId(paramValue);
-
- String prefix = personToListPrefix + personToListNumber;
-
- double weight = getDoubleValue(prefix + ".weight");
- personToList.setWeight(weight);
-
- String topiaId = getNonEmptyParameterValue(prefix + ".topiaId");
- personToList.setTopiaId(topiaId);
-
- String email = getNonEmptyParameterValue(prefix + ".email");
- account.setEmail(email);
-
- String accountId = getNonEmptyParameterValue(prefix + ".accountId");
- account.setAccountId(accountId);
-
- result.put(personToListNumber, personToList);
- }
- return personToListNumber;
- }
-
- private Choice createImageChoice(PollImageChoice choice,
- String prefix,
- String name) {
- createChoice(choice, prefix, name);
- String locationName = prefix + ".location";
- String location = getNonEmptyParameterValue(locationName);
- choice.setLocation(location);
- if (log.isInfoEnabled()) {
- log.info("image location [" + name + "] =" + location);
- }
- return choice;
- }
-
- private Choice createDateChoice(PollDateChoice choice,
- String prefix,
- String name) {
- createChoice(choice, prefix, name);
- if (StringUtils.isNotEmpty(name)) {
- Date date = null;
- try {
- date = parseDateTime(name);
- } catch (ParseException e) {
- if (log.isErrorEnabled()) {
- log.error("Unparseable date " + name, e);
- }
- }
- choice.setDate(date);
- }
- return choice;
- }
-
- private Choice createChoice(Choice choice, String prefix, String name) {
- String descriptionName = prefix + ".description";
- String topiaIdName = prefix + ".topiaId";
- String description = getNonEmptyParameterValue(descriptionName);
- String topiaId = getNonEmptyParameterValue(topiaIdName);
- choice.setName(name);
- choice.setDescription(description);
- choice.setTopiaId(topiaId);
- return choice;
- }
-
- private void logChoice(Map<Integer, Choice> result) {
- for (Map.Entry<Integer, Choice> e : result.entrySet()) {
- Integer choiceId = e.getKey();
- Choice choice = e.getValue();
- if (log.isInfoEnabled()) {
- log.info("Choice [" + choiceId + "] = " +
- choice.getName() + " -- " +
- choice.getDescription());
- }
- }
- }
-
-
- private <T> Map<Integer, T> reindexMap(Map<Integer, T> result, int maxNumber) {
- Map<Integer, T> result2;
-
- if (maxNumber != result.size() - 1) {
-
- // means there is a hole inside the result (a empty choice was
- // submitted)
-
- // le'ts remove this
- List<Integer> numbers = Lists.newArrayList(result.keySet());
-
- Collections.sort(numbers);
-
- result2 = Maps.newTreeMap();
- int i = 0;
- for (Integer number : numbers) {
- T choice = result.get(number);
- result2.put(i++, choice);
- }
- } else {
- result2 = result;
- }
- return result2;
- }
-
- private <O> void addtoList(List<O> list, int index, O object) {
-
- while (list.size() < index) {
- list.add(null);
- }
- list.add(index, object);
- }
-
-
- private String getNonEmptyParameterValue(String paramName) {
- String[] paramValues = parameters.get(paramName);
- String result = null;
- if (paramValues != null && paramValues.length == 1) {
- String paramValue = paramValues[0];
- if (StringUtils.isNotEmpty(paramValue)) {
- result = paramValue;
- }
- }
- return result;
- }
-
- private <E extends Enum<E> & I18nAble> Map<String, String> decorateToName(E... values) {
- Map<String, String> result = Maps.newLinkedHashMap();
- for (E value : values) {
- result.put(value.name(), getText(value.getI18nKey()));
- }
- return result;
- }
-
- private static class StringStartWithPredicate implements Predicate<String> {
- private final String prefix;
-
- public StringStartWithPredicate(String prefix) {
- this.prefix = prefix;
- }
-
- @Override
- public boolean apply(String input) {
- return input.startsWith(prefix);
- }
- }
-}
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java 2012-04-03 18:16:13 UTC (rev 3232)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java 2012-04-05 07:50:32 UTC (rev 3233)
@@ -1,76 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-import org.chorem.pollen.ui.actions.PollUriConverter;
-
-import java.util.Map;
-
-/**
- * Edit a poll.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @author fdesbois <desbois(a)codelutin.com>
- * @since 1.2.6
- */
-public class EditPoll extends ClonePoll {
-
- private static final long serialVersionUID = 1L;
-
- protected void preparePollUri(Map<String, String[]> parameters) {
- if (pollUri == null) {
- String[] values = parameters.get("uriId");
- pollUri = PollUriConverter.convertFromString(values);
- }
- }
-
- @Override
- protected boolean keepTopiaId() {
- return true;
- }
-
- public boolean isVoteStarted() {
- return getPoll().sizeVote() > 0;
- }
-
- @Override
- public void prepare() throws Exception {
-
- preparePollUri(parameters);
-
- super.prepare();
- }
-
- @Override
- public String execute() throws Exception {
-
-// getPollService().updatePoll(poll):
-
- // remove all stuff from session
- getPollenSession().clearDynamicData();
-
- addActionMessage(_("pollen.information.poll.updated"));
- return SUCCESS;
- }
-}
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java (from rev 3232, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-05 07:50:32 UTC (rev 3233)
@@ -0,0 +1,213 @@
+package org.chorem.pollen.ui.actions.poll;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import org.chorem.pollen.bean.PollImageChoice;
+import org.chorem.pollen.bean.PollUri;
+import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.business.persistence.PersonToList;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.business.persistence.VotingList;
+import org.chorem.pollen.common.ChoiceType;
+import org.chorem.pollen.common.PollType;
+
+import java.util.List;
+
+/**
+ * Created: 04/04/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ */
+public class LoadPoll extends AbstractPollForm {
+
+ private static final String PREFIX_CHOICE = "%sChoice_%d";
+
+ private static final String PREFIX_VOTING_LIST = "votingList_%d";
+
+ private static final String PREFIX_PERSON_TO_LIST = "personToList_%d_%d";
+
+ private PollUri pollUri;
+
+ private boolean clone;
+
+ public PollUri getUriId() {
+ return pollUri;
+ }
+
+ public void setUriId(PollUri pollUri) {
+ this.pollUri = pollUri;
+ }
+
+ public boolean isClone() {
+ return clone;
+ }
+
+ public void setClone(boolean clone) {
+ this.clone = clone;
+ }
+
+ @Override
+ protected Poll initPoll() {
+ Poll result;
+ if (pollUri != null) {
+ result = getPollService().getPollByPollId(pollUri.getPollId());
+
+ if (clone) {
+ result.setTopiaId(null);
+
+ // Use a new pollUid
+ String pollUid = serviceContext.createPollenUrlId();
+ result.setPollId(pollUid);
+ }
+
+ } else {
+
+ UserAccount userAccount = getPollenUserAccount();
+ result = getPollService().getNewPoll(userAccount);
+ }
+ return result;
+ }
+
+ @Override
+ public String input() throws Exception {
+
+ if (pollUri != null) {
+
+ // -- Choice -- //
+ ChoiceType choiceType = getPoll().getChoiceType();
+ prepareParams(getPoll().getChoice(), withChoicePrefix(choiceType));
+
+ // -- VotingList -- //
+ if (getPoll().getPollType() != PollType.FREE) {
+ prepareParams(getPoll().getVotingList(), withVotingListPrefix());
+ }
+ }
+
+ prepareFormPage();
+
+ return INPUT;
+ }
+
+ private Function<Choice, String> withChoicePrefix(final ChoiceType choiceType) {
+ final String choiceTypeName = choiceType.name().toLowerCase();
+ return new IndexedFunction<Choice, String>() {
+
+ @Override
+ protected String apply(Choice input, int index) {
+
+ String prefix = String.format(PREFIX_CHOICE, choiceTypeName, index);
+ if (!clone) {
+ putParameter(prefix, Choice.TOPIA_ID, input.getTopiaId());
+ }
+ putParameter(prefix, Choice.PROPERTY_NAME, input.getName());
+ putParameter(prefix, Choice.PROPERTY_DESCRIPTION, input.getDescription());
+
+ if (choiceType == ChoiceType.IMAGE) {
+ putParameter(prefix, PollImageChoice.PROPERTY_LOCATION, input.getName());
+ }
+
+ return prefix;
+ }
+ };
+ }
+
+ private Function<VotingList, String> withVotingListPrefix() {
+ return new IndexedFunction<VotingList, String>() {
+
+ @Override
+ protected String apply(VotingList input, int index) {
+
+ String prefix = String.format(PREFIX_VOTING_LIST, index);
+ if (!clone) {
+ putParameter(prefix, VotingList.TOPIA_ID, input.getTopiaId());
+ }
+ putParameter(prefix, VotingList.PROPERTY_NAME, input.getName());
+ putParameter(prefix, VotingList.PROPERTY_WEIGHT, String.valueOf(input.getWeight()));
+
+ prepareParams(input.getPollAccountPersonToList(), withPersonToListPrefix(index));
+
+ return prefix;
+ }
+ };
+ }
+
+ private Function<PersonToList, String> withPersonToListPrefix(final int votingListIndex) {
+ return new IndexedFunction<PersonToList, String>() {
+
+ @Override
+ protected String apply(PersonToList input, int index) {
+
+ PollAccount pollAccount = input.getPollAccount();
+
+ String prefix = String.format(PREFIX_PERSON_TO_LIST, votingListIndex, index);
+ if (!clone) {
+ putParameter(prefix, PersonToList.TOPIA_ID, input.getTopiaId());
+ }
+ putParameter(prefix, PersonToList.PROPERTY_WEIGHT, String.valueOf(input.getWeight()));
+ putParameter(prefix, PollAccount.PROPERTY_ACCOUNT_ID, pollAccount.getAccountId());
+ putParameter(prefix, PollAccount.PROPERTY_VOTING_ID, pollAccount.getVotingId());
+ putParameter(prefix, PollAccount.PROPERTY_EMAIL, pollAccount.getEmail());
+
+ return prefix;
+ }
+ };
+ }
+
+ /**
+ * Prepare the {@code source} for parameters using the {@code function} to
+ * push necessary data.
+ *
+ * @param source List of elements
+ * @param function Function used to push element data using {@link #putParameter(String, String, String)}
+ * @param <T> Type of data
+ * @see #putParameter(String, String, String)
+ */
+ private <T> void prepareParams(List<T> source, Function<T, String> function) {
+ ImmutableList.copyOf(Lists.transform(source, function));
+ }
+
+ /**
+ * Put some data in the {@code parameters} with name built using
+ * {@code prefix} and {@code property}. The {@code value} will be put for
+ * this parameter.
+ *
+ * @param prefix Prefix to use for the parameter name
+ * @param property Name of the {@code property} to push in parameters
+ * @param value Value of this {@code property}
+ */
+ private void putParameter(String prefix, String property, String value) {
+ parameters.put(prefix + "." + property, new String[]{value});
+ }
+
+ /**
+ * Guava {@link Function} that keeps index on each {@link Function#apply(Object)} call.
+ * You just have to implement {@link #apply(Object, int)} to have the current
+ * index of the {@code input} value.
+ *
+ * @param <F> Type of data where function will be applied on
+ * @param <T> Resulting type
+ */
+ private abstract static class IndexedFunction<F, T> implements Function<F, T> {
+
+ private int index;
+
+ @Override
+ public T apply(F input) {
+ T result = apply(input, index);
+ index++;
+ return result;
+ }
+
+ /**
+ * Called during {@link #apply(Object)} method with current {@code index}.
+ *
+ * @param input current value
+ * @param index current index
+ * @return the result of the function applied on the {@code input} object
+ */
+ protected abstract T apply(F input, int index);
+ }
+}
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-05 07:50:32 UTC (rev 3233)
@@ -0,0 +1,122 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import com.opensymphony.xwork2.Preparable;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.PreventRule;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.business.persistence.VotingList;
+import org.chorem.pollen.services.impl.PollService;
+import org.chorem.pollen.services.impl.PreventRuleService;
+
+import java.util.Map;
+
+/**
+ * Creates a new poll.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class SavePoll extends AbstractPollForm implements Preparable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(SavePoll.class);
+
+ @Override
+ protected Poll initPoll() {
+ UserAccount userAccount = getPollenUserAccount();
+ Poll result = getPollService().getNewPoll(userAccount);
+ return result;
+ }
+
+ @Override
+ public void prepare() throws Exception {
+
+ prepareFormPage();
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ Poll poll = getPoll();
+
+ Map<Integer, Choice> orderedChoices = getOrderedChoices();
+
+ for (Integer index : orderedChoices.keySet()) {
+ Choice choice = orderedChoices.get(index);
+ poll.addChoice(choice);
+ }
+
+ if (!isFreePoll()) {
+
+ Map<Integer, VotingList> votingLists = getOrderedVotingLists();
+ for (Integer index : votingLists.keySet()) {
+ VotingList votingList = votingLists.get(index);
+ poll.addVotingList(votingList);
+ }
+ }
+
+ PollService service = getPollService();
+
+ PreventRuleService preventRuleService =
+ newService(PreventRuleService.class);
+ if (isNotification()) {
+
+ // add a notification rule
+
+ PreventRule rule = preventRuleService.createAddVotePreventRule();
+ poll.addPreventRule(rule);
+ }
+
+ if (isReminder()) {
+
+ // add a reminder rule
+
+ PreventRule rule = preventRuleService.createRemindPreventRule(
+ getReminderHourCountdown()
+ );
+
+ poll.addPreventRule(rule);
+ }
+
+ if (isEdit()) {
+// service.createPoll(poll);
+
+ } else {
+ service.createPoll(poll);
+ }
+
+ // remove all stuff from session
+ getPollenSession().clearDynamicData();
+
+ addActionMessage(_("pollen.information.poll.created"));
+ return SUCCESS;
+ }
+}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-04-03 18:16:13 UTC (rev 3232)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-04-05 07:50:32 UTC (rev 3233)
@@ -43,9 +43,9 @@
<!-- create poll -->
<action name="create"
- class="org.chorem.pollen.ui.actions.poll.CreatePoll">
+ class="org.chorem.pollen.ui.actions.poll.LoadPoll"
+ method="input">
<result name="input">/WEB-INF/jsp/poll/create.jsp</result>
- <result>/WEB-INF/jsp/poll/resume.jsp</result>
</action>
<!-- display * -->
@@ -86,24 +86,25 @@
<!-- edit poll -->
<action name="modification/*"
- class="org.chorem.pollen.ui.actions.poll.EditPoll">
+ class="org.chorem.pollen.ui.actions.poll.LoadPoll"
+ method="input">
<param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/create.jsp</result>
- <result>/WEB-INF/jsp/poll/resume.jsp</result>
</action>
- <!-- confirm clone poll -->
- <action name="confirmClonePoll/*"
- class="org.chorem.pollen.ui.actions.poll.ConfirmPollAction">
- <param name="uriId">{1}</param>
- <result>/WEB-INF/jsp/poll/confirmClonePoll.jsp</result>
- </action>
-
<!-- clone poll -->
<action name="clone/*"
- class="org.chorem.pollen.ui.actions.poll.ClonePoll">
+ class="org.chorem.pollen.ui.actions.poll.LoadPoll"
+ method="input">
<param name="uriId">{1}</param>
+ <param name="clone">true</param>
<result name="input">/WEB-INF/jsp/poll/create.jsp</result>
+ </action>
+
+ <!-- save poll -->
+ <action name="save"
+ class="org.chorem.pollen.ui.actions.poll.SavePoll">
+ <result name="input">/WEB-INF/jsp/poll/create.jsp</result>
<result>/WEB-INF/jsp/poll/resume.jsp</result>
</action>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-04-03 18:16:13 UTC (rev 3232)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-04-05 07:50:32 UTC (rev 3233)
@@ -179,8 +179,6 @@
pollen.fieldset.userInformation.toCreate=User informations to create
pollen.fieldset.userInformation.toDelete=User informations to delete
pollen.fieldset.userInformation.toUpdate=User informations to update
-pollen.information.poll.created=Poll created
-pollen.information.poll.updated=Poll modified
pollen.information.confirmClonePoll=Confirm clone of poll\:
pollen.information.confirmClosePoll=Confirm close of poll\:
pollen.information.confirmDeleteChoice=Confirm delete of choice %s
@@ -192,6 +190,8 @@
pollen.information.favoriteList.deleted=Favorite list %s deleted.
pollen.information.irreversible.operation=Be ware, this operation is irreversible.
pollen.information.need.login=You must be logged to access this page. Please fill the form below.
+pollen.information.poll.created=Poll created
+pollen.information.poll.updated=Poll modified
pollen.information.pollAccount.addedTofavoriteList=Member '%s was added to favorite list.
pollen.information.pollAccount.removedFromFavoriteList=Member %s was removed from favorite list.
pollen.information.pollAccount.updatedTofavoriteList=Member %s was updated in favorite list.
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-04-03 18:16:13 UTC (rev 3232)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-04-05 07:50:32 UTC (rev 3233)
@@ -186,8 +186,6 @@
pollen.fieldset.userInformation.toCreate=Informations de l'utilisateur à créer
pollen.fieldset.userInformation.toDelete=Informations de l'utilisateur à supprimer
pollen.fieldset.userInformation.toUpdate=Informations de l'utilisateur à mettre à jour
-pollen.information.poll.created=Sondage créé
-pollen.information.poll.updated=Sondage mise à jour
pollen.information.confirmClonePoll=Confirmer le clonage du sondage \:
pollen.information.confirmClosePoll=Confirmer la fermeture du sondage \:
pollen.information.confirmDeleteFavoriteList=Confirmer la suppression de la liste de votants \:
@@ -200,6 +198,8 @@
pollen.information.favoriteList.deleted=La liste %s a été supprimée.
pollen.information.irreversible.operation=Attention, Cette opération est irréversible.
pollen.information.need.login=Vous devez être identifié pour pouvoir accéder à cette page. Veuillez remplir le formulaire ci-dessous.
+pollen.information.poll.created=Sondage créé
+pollen.information.poll.updated=Sondage mise à jour
pollen.information.pollAccount.addedTofavoriteList=Le membre %s a été ajoutée à la liste des favoris.
pollen.information.pollAccount.removedFromFavoriteList=Le membre %s a été supprimé de la liste des favoris.
pollen.information.pollAccount.updatedTofavoriteList=Le membre %s a été mise à jour dans la liste des favoris.
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini 2012-04-03 18:16:13 UTC (rev 3232)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini 2012-04-05 07:50:32 UTC (rev 3233)
@@ -42,4 +42,5 @@
/poll/results/**=poll,pollAccess
# is pollCreator (can admin a poll)
-/poll/modification/**=poll,pollCreator
\ No newline at end of file
+/poll/modification/**=poll,pollCreator
+/poll/clone/**=poll,pollCreator
\ No newline at end of file
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-03 18:16:13 UTC (rev 3232)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-05 07:50:32 UTC (rev 3233)
@@ -322,7 +322,13 @@
</sj:tabbedpanel>
<br/>
- <s:submit action="create" key="pollen.action.createPoll" align="center"/>
+ <s:submit action="save" key="pollen.action.savePoll" value="%{actionLabel}" align="center"/>
+
+ <!--<div id="wwctrl_registerForm_pollen_action_<s:property value='%{actionLabel}'/>Poll" align="center">
+ <input type="submit" id="registerForm_pollen_action_<s:property value='%{actionLabel}'/>Poll"
+ name="action:<s:property value='%{actionName}'/>"
+ value="<s:text name='pollen.action.%{actionLabel}Poll'/>"/>
+ </div>-->
</s:form>
<script type="text/javascript">
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp 2012-04-03 18:16:13 UTC (rev 3232)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp 2012-04-05 07:50:32 UTC (rev 3233)
@@ -40,7 +40,6 @@
<s:url id="editUrl" action="modification/" namespace="/poll"/>
<s:url id='editImg' value='/img/edit.png'/>
-<s:set id="editMethod" value="input"/>
<s:set id='editTitle'><s:text name="pollen.action.pollEdit"/></s:set>
<s:url id="closeUrl" action="confirmClosePoll/" namespace="/poll"/>
@@ -53,7 +52,6 @@
<s:url id="cloneUrl" action="clone/" namespace="/poll"/>
<s:url id='cloneImg' value='/img/copy.png'/>
-<s:set id="cloneMethod" value="input"/>
<s:set id='cloneTitle'><s:text name="pollen.action.pollClone"/></s:set>
<s:url id="deleteUrl" action="confirmDeletePoll/" namespace="/poll"/>
@@ -82,16 +80,6 @@
return false;
}
-// function confirmClone(id) {
-// $('.ui-dialog-title').html("<s:text name="pollen.title.clone.poll"/>")
-// var dialog = $("#confirmDialog");
-// var url = "<s:url action='confirmClonePoll/' namespace='/poll'/>";
-// url += id + '?' + $.param({redirectUrl:redirectUrl});
-// dialog.load(url);
-// dialog.dialog('open');
-// return false;
-// }
-
function pollFunctions(cellvalue, options, rowObject) {
var id = rowObject.pollId;
@@ -110,7 +98,7 @@
result += formatLink("${resultUrl}" + id, "${resultImg}", "Result", "${resultTitle}")
}
if (cellvalue.indexOf('edit') > -1) {
- result += formatLink("${editUrl}" + adminId + "!${editMethod}", "${editImg}", "Edit", "${editTitle}")
+ result += formatLink("${editUrl}" + adminId, "${editImg}", "Edit", "${editTitle}")
}
if (cellvalue.indexOf('close') > -1) {
var script = 'return confirmClose("' + adminId + '");'
@@ -120,9 +108,7 @@
result += formatLink("${exportUrl}" + id, "${exportImg}", "Export", "${exportTitle}")
}
if (cellvalue.indexOf('clone') > -1) {
-// var script = 'return confirmClone("' + adminId + '");'
-// result += formatLinkByScript(script, "${cloneImg}", "Clone", "${cloneTitle}")
- result += formatLink("${cloneUrl}" + id + "!${cloneMethod}", "${cloneImg}", "Clone", "${cloneTitle}")
+ result += formatLink("${cloneUrl}" + adminId, "${cloneImg}", "Clone", "${cloneTitle}")
}
if (cellvalue.indexOf('delete') > -1) {
var script = 'return confirmDelete("' + adminId + '");'
1
0