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
- 3196 discussions
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
r3232 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll java/org/chorem/pollen/ui/security resources/config resources/i18n webapp/WEB-INF/jsp webapp/WEB-INF/jsp/poll
by fdesbois@users.chorem.org 03 Apr '12
by fdesbois@users.chorem.org 03 Apr '12
03 Apr '12
Author: fdesbois
Date: 2012-04-03 20:16:13 +0200 (Tue, 03 Apr 2012)
New Revision: 3232
Url: http://chorem.org/repositories/revision/pollen/3232
Log:
- implement ClonePoll action based on EditPoll code
- manage input method for edit and clone actions
Modified:
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
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.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/i18n/pollen-ui-struts2_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp
Modified: 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:07 UTC (rev 3231)
+++ 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)
@@ -23,36 +23,204 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import org.chorem.pollen.services.impl.PollService;
+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 AbstractPollUriIdAction {
+public class ClonePoll extends CreatePoll {
private static final long serialVersionUID = 1L;
- protected String redirectUrl;
+ private static final String PREFIX_CHOICE = "%sChoice_%d";
- public String getRedirectUrl() {
- return redirectUrl;
+ 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 void setRedirectUrl(String redirectUrl) {
- this.redirectUrl = redirectUrl;
+ public final void setUriId(PollUri pollUri) {
+ this.pollUri = pollUri;
}
+ public String getPollUid() {
+ return pollUri.getPollId();
+ }
+
+ protected boolean keepTopiaId() {
+ return false;
+ }
+
@Override
- public String execute() throws Exception {
+ 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;
+ }
- PollService service = newService(PollService.class);
+ @Override
+ public void prepare() throws Exception {
- //TODO
-// service.clonePoll(pollId, getPollenUserAccount(), accountId);
+ // -- Choice --
+ ChoiceType choiceType = getPoll().getChoiceType();
+ prepareParams(getPoll().getChoice(), withChoicePrefix(choiceType));
- return SUCCESS;
+ // -- 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);
+ }
}
Modified: 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:07 UTC (rev 3231)
+++ 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)
@@ -519,7 +519,7 @@
// remove all stuff from session
getPollenSession().clearDynamicData();
- addActionMessage(_("pollen.info.poll.created"));
+ addActionMessage(_("pollen.information.poll.created"));
return SUCCESS;
}
Modified: 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:07 UTC (rev 3231)
+++ 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)
@@ -23,21 +23,8 @@
*/
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 org.chorem.pollen.ui.actions.PollUriConverter;
-import java.util.List;
import java.util.Map;
/**
@@ -47,26 +34,10 @@
* @author fdesbois <desbois(a)codelutin.com>
* @since 1.2.6
*/
-public class EditPoll extends CreatePoll {
+public class EditPoll extends ClonePoll {
- 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 static final long serialVersionUID = 1L;
- protected PollUri pollUri;
-
- public final PollUri getUriId() {
- return pollUri;
- }
-
- public final void setUriId(PollUri pollUri) {
- this.pollUri = pollUri;
- }
-
protected void preparePollUri(Map<String, String[]> parameters) {
if (pollUri == null) {
String[] values = parameters.get("uriId");
@@ -74,39 +45,20 @@
}
}
- protected boolean needTopiaId() {
+ @Override
+ protected boolean keepTopiaId() {
return true;
}
public boolean isVoteStarted() {
return getPoll().sizeVote() > 0;
}
-
+
@Override
- public Poll getPoll() {
- if (poll == null) {
- poll = getPollService().getPollByPollId(pollUri.getPollId());
- if (!needTopiaId()) {
- poll.setTopiaId(null);
- }
- }
- return poll;
- }
-
- @Override
public void prepare() throws Exception {
preparePollUri(parameters);
- // -- Choice --
- ChoiceType choiceType = getPoll().getChoiceType();
- prepareParams(getPoll().getChoice(), withChoicePrefix(choiceType));
-
- // -- VotingList --
- if (getPoll().getPollType() != PollType.FREE) {
- prepareParams(getPoll().getVotingList(), withVotingListPrefix());
- }
-
super.prepare();
}
@@ -118,127 +70,7 @@
// remove all stuff from session
getPollenSession().clearDynamicData();
- addActionMessage(_("pollen.info.poll.created"));
+ addActionMessage(_("pollen.information.poll.updated"));
return SUCCESS;
}
-
- 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 (needTopiaId()) {
- 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 (needTopiaId()) {
- 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 (needTopiaId()) {
- 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);
- }
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java 2012-04-03 18:16:07 UTC (rev 3231)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java 2012-04-03 18:16:13 UTC (rev 3232)
@@ -50,7 +50,7 @@
public abstract class AbstractPollenAuthorization extends AuthorizationFilter {
public static final Pattern URI_PATTERN =
- Pattern.compile("/.*/(.[^/]+)/(.+)");
+ Pattern.compile("/.*/(.[^/]+)/(.[^!]+)");
/** Logger. */
private static final Log log =
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:07 UTC (rev 3231)
+++ 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)
@@ -103,7 +103,8 @@
<action name="clone/*"
class="org.chorem.pollen.ui.actions.poll.ClonePoll">
<param name="uriId">{1}</param>
- <result type="redirect2"/>
+ <result name="input">/WEB-INF/jsp/poll/create.jsp</result>
+ <result>/WEB-INF/jsp/poll/resume.jsp</result>
</action>
<!-- export poll -->
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:07 UTC (rev 3231)
+++ 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)
@@ -18,6 +18,7 @@
pollen.action.deleteUser=Delete selected user
pollen.action.deleteVote=Supprimer ce vote
pollen.action.editFavoriteList=Edit a list
+pollen.action.editPoll=Edit the poll
pollen.action.editPollAccount=Edit selected member
pollen.action.editUser=Edit selected user
pollen.action.editVote=Modifier le vote
@@ -178,8 +179,8 @@
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.info.poll.created=Poll created
-pollen.info.poll.updated=Poll modified
+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
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:07 UTC (rev 3231)
+++ 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)
@@ -21,6 +21,7 @@
pollen.action.deleteUser=Supprimer un utilisateur sélectionné
pollen.action.deleteVote=Supprimer ce vote
pollen.action.editFavoriteList=Editer une liste sélectionnée
+pollen.action.editPoll=Modifier le sondage
pollen.action.editPollAccount=Editer le membre sélectionné
pollen.action.editUser=Editer un utilisateur sélectionné
pollen.action.editVote=Modifier le vote
@@ -185,8 +186,8 @@
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.info.poll.created=Sondage créé
-pollen.info.poll.updated=Sondage mise à 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 \:
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:07 UTC (rev 3231)
+++ 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)
@@ -185,6 +185,8 @@
<s:form method="POST" id="registerForm" namespace="/poll"
enctype="multipart/form-data">
+ <s:hidden key="poll.topiaId"/>
+
<sj:tabbedpanel id="formTabs" selectedTab="%{selectedTab}">
<sj:tab id="tabGeneral" target="tgeneral" key="pollen.tab.poll.general"/>
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:07 UTC (rev 3231)
+++ 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)
@@ -40,6 +40,7 @@
<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"/>
@@ -50,8 +51,9 @@
<s:url id='exportImg' value='/img/export.png'/>
<s:set id='exportTitle'><s:text name="pollen.action.pollExport"/></s:set>
-<s:url id="cloneUrl" action="clone/" namespace="/poll" method="input"/>
+<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"/>
@@ -80,15 +82,15 @@
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 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) {
@@ -108,7 +110,7 @@
result += formatLink("${resultUrl}" + id, "${resultImg}", "Result", "${resultTitle}")
}
if (cellvalue.indexOf('edit') > -1) {
- result += formatLink("${editUrl}" + adminId, "${editImg}", "Edit", "${editTitle}")
+ result += formatLink("${editUrl}" + adminId + "!${editMethod}", "${editImg}", "Edit", "${editTitle}")
}
if (cellvalue.indexOf('close') > -1) {
var script = 'return confirmClose("' + adminId + '");'
@@ -118,8 +120,9 @@
result += formatLink("${exportUrl}" + id, "${exportImg}", "Export", "${exportTitle}")
}
if (cellvalue.indexOf('clone') > -1) {
- var script = 'return confirmClone("' + adminId + '");'
- result += formatLinkByScript(script, "${cloneImg}", "Clone", "${cloneTitle}")
+// var script = 'return confirmClone("' + adminId + '");'
+// result += formatLinkByScript(script, "${cloneImg}", "Clone", "${cloneTitle}")
+ result += formatLink("${cloneUrl}" + id + "!${cloneMethod}", "${cloneImg}", "Clone", "${cloneTitle}")
}
if (cellvalue.indexOf('delete') > -1) {
var script = 'return confirmDelete("' + adminId + '");'
1
0
r3231 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources: . org/chorem/pollen/ui/actions/poll
by fdesbois@users.chorem.org 03 Apr '12
by fdesbois@users.chorem.org 03 Apr '12
03 Apr '12
Author: fdesbois
Date: 2012-04-03 20:16:07 +0200 (Tue, 03 Apr 2012)
New Revision: 3231
Url: http://chorem.org/repositories/revision/pollen/3231
Log:
Use global conversion configuration for PollUri
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/xwork-conversion.properties
Removed:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction-conversion.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/CreatePoll-conversion.properties
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction-conversion.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction-conversion.properties 2012-04-03 16:47:41 UTC (rev 3230)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction-conversion.properties 2012-04-03 18:16:07 UTC (rev 3231)
@@ -1,24 +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%
-###
-uriId=org.chorem.pollen.ui.actions.PollUriConverter
\ No newline at end of file
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/CreatePoll-conversion.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/CreatePoll-conversion.properties 2012-04-03 16:47:41 UTC (rev 3230)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/CreatePoll-conversion.properties 2012-04-03 18:16:07 UTC (rev 3231)
@@ -1,24 +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%
-###
-uriId=org.chorem.pollen.ui.actions.PollUriConverter
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/xwork-conversion.properties (from rev 3230, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction-conversion.properties)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/xwork-conversion.properties (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/xwork-conversion.properties 2012-04-03 18:16:07 UTC (rev 3231)
@@ -0,0 +1,24 @@
+###
+# #%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%
+###
+org.chorem.pollen.bean.PollUri=org.chorem.pollen.ui.actions.PollUriConverter
\ No newline at end of file
1
0
r3230 - branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration
by tchemit@users.chorem.org 03 Apr '12
by tchemit@users.chorem.org 03 Apr '12
03 Apr '12
Author: tchemit
Date: 2012-04-03 18:47:41 +0200 (Tue, 03 Apr 2012)
New Revision: 3230
Url: http://chorem.org/repositories/revision/pollen/3230
Log:
rename inner class copy from t3
Modified:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallback.java
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallback.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallback.java 2012-04-02 17:30:25 UTC (rev 3229)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallback.java 2012-04-03 16:47:41 UTC (rev 3230)
@@ -50,7 +50,7 @@
};
public PollenMigrationCallback() {
- super(new T3MigrationCallBackForVersionResolver());
+ super(new PollenMigrationCallBackForVersionResolver());
}
@Override
@@ -74,7 +74,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.0.1
*/
- public static class T3MigrationCallBackForVersionResolver implements MigrationCallBackForVersionResolver {
+ public static class PollenMigrationCallBackForVersionResolver implements MigrationCallBackForVersionResolver {
@Override
public Class<? extends MigrationCallBackForVersion> getCallBack(Version version) {
1
0
Author: tchemit
Date: 2012-04-02 19:30:25 +0200 (Mon, 02 Apr 2012)
New Revision: 3229
Url: http://chorem.org/repositories/revision/pollen/3229
Log:
- use same behaviour for actions in grids
- fix EditPoll action (need to add the correct PollUri convertor)
- add svn properties + headers
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/Confirm.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/DeleteUser.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Confirm.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeleteFavoriteList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeletePollAccount.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/CreatePoll-conversion.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/confirmDeleteUser.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/confirmDeleteFavoriteList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/confirmDeletePollAccount.jsp
Modified:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonToListDAOImpl.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/FileUploadAware.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java
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/resources/config/struts-admin.xml
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-user.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/struts.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteList.js
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteLists.js
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/usersList.js
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonToListDAOImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonToListDAOImpl.java 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonToListDAOImpl.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -1,3 +1,26 @@
+/*
+ * #%L
+ * Pollen :: Persistence
+ *
+ * $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.business.persistence;
import java.util.List;
Property changes on: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonToListDAOImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -1,3 +1,26 @@
+/*
+ * #%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.bean;
import com.google.common.base.Function;
Property changes on: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -26,14 +26,18 @@
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
+import java.io.Serializable;
+
/**
* TODO
*
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
-public class PollUri {
+public class PollUri implements Serializable {
+ private static final long serialVersionUID = 1L;
+
public static PollUri newPollUri(String uri) {
PollUri result = new PollUri();
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/FileUploadAware.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/FileUploadAware.java 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/FileUploadAware.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -1,3 +1,26 @@
+/*
+ * #%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;
import java.io.File;
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/FileUploadAware.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/Confirm.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/Confirm.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/Confirm.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -0,0 +1,97 @@
+/*
+ * #%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.admin;
+
+import org.apache.commons.lang.StringUtils;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.services.impl.PollService;
+import org.chorem.pollen.services.impl.UserService;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * Action for confirmation
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class Confirm extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String userId;
+
+ protected String pollId;
+
+ protected UserAccount user;
+
+ protected Poll poll;
+
+ protected String redirectUrl;
+
+ public void setRedirectUrl(String redirectUrl) {
+ this.redirectUrl = redirectUrl;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+ public void setPollId(String pollId) {
+ this.pollId = pollId;
+ }
+
+ public String getRedirectUrl() {
+ return redirectUrl;
+ }
+
+ public UserAccount getUser() {
+ return user;
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ if (StringUtils.isNotEmpty(userId)) {
+
+ // load user
+ UserService service = newService(UserService.class);
+
+ user = service.getEntityById(UserAccount.class, userId);
+ }
+
+ if (StringUtils.isNotEmpty(pollId)) {
+
+ // load poll
+ PollService servcie = newService(PollService.class);
+
+ poll = servcie.getPollByPollId(pollId);
+ }
+
+ return SUCCESS;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/Confirm.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/DeleteUser.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/DeleteUser.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/DeleteUser.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -0,0 +1,82 @@
+/*
+ * #%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.admin;
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.services.exceptions.UserNotFoundException;
+import org.chorem.pollen.services.impl.UserService;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * Delete a selected user.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class DeleteUser extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String userId;
+
+ protected String redirectUrl;
+
+ public void setRedirectUrl(String redirectUrl) {
+ this.redirectUrl = redirectUrl;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getRedirectUrl() {
+ return redirectUrl;
+ }
+
+ public String execute() throws Exception {
+
+ Preconditions.checkNotNull(userId);
+
+ UserService service = newService(UserService.class);
+
+ String result = INPUT;
+
+ try {
+ UserAccount user =
+ service.getEntityById(UserAccount.class, userId);
+
+ service.deleteUser(userId);
+ getTransaction().commitTransaction();
+ addActionMessage(
+ _("pollen.information.user.deleted", user.getDisplayName()));
+
+ result = SUCCESS;
+ } catch (UserNotFoundException e) {
+ addFieldError("deleteUser.login",
+ _("pollen.error.user.not.found"));
+ }
+ return result;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/DeleteUser.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/admin/ManageUsers.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -28,7 +28,6 @@
import org.chorem.pollen.services.exceptions.UserEmailAlreadyUsedException;
import org.chorem.pollen.services.exceptions.UserInvalidPasswordException;
import org.chorem.pollen.services.exceptions.UserLoginAlreadyUsedException;
-import org.chorem.pollen.services.exceptions.UserNotFoundException;
import org.chorem.pollen.services.impl.UserService;
import org.chorem.pollen.ui.actions.PollenActionSupport;
@@ -60,9 +59,9 @@
return getUser();
}
- public UserAccount getDeleteUser() {
- return getUser();
- }
+// public UserAccount getDeleteUser() {
+// return getUser();
+// }
public String getAction() {
return action;
@@ -129,28 +128,28 @@
return result;
}
- public String delete() throws Exception {
-
- Preconditions.checkNotNull(user);
-
- UserService service = newService(UserService.class);
-
- String result = INPUT;
-
- try {
- service.deleteUser(user.getTopiaId());
- getTransaction().commitTransaction();
- addActionMessage(
- _("pollen.information.user.deleted", user.getDisplayName()));
-
- // remove this user, otherwise it will be reused in the user lists
- user = null;
- action = null;
- result = SUCCESS;
- } catch (UserNotFoundException e) {
- addFieldError("deleteUser.login",
- _("pollen.error.user.not.found"));
- }
- return result;
- }
+// public String delete() throws Exception {
+//
+// Preconditions.checkNotNull(user);
+//
+// UserService service = newService(UserService.class);
+//
+// String result = INPUT;
+//
+// try {
+// service.deleteUser(user.getTopiaId());
+// getTransaction().commitTransaction();
+// addActionMessage(
+// _("pollen.information.user.deleted", user.getDisplayName()));
+//
+// // remove this user, otherwise it will be reused in the user lists
+// user = null;
+// action = null;
+// result = SUCCESS;
+// } catch (UserNotFoundException e) {
+// addFieldError("deleteUser.login",
+// _("pollen.error.user.not.found"));
+// }
+// return result;
+// }
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -23,6 +23,7 @@
*/
package org.chorem.pollen.ui.actions.json;
+import com.google.common.collect.Sets;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.entities.PollenBinderHelper;
import org.chorem.pollen.services.impl.UserService;
@@ -30,6 +31,7 @@
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Obtain paginated users.
@@ -74,6 +76,7 @@
List<UserAccount> allUsers = userService.getUsers(pager);
+ UserAccount userAccount = getPollenUserAccount();
users = new Map[allUsers.size()];
Binder<UserAccount, UserAccount> binder =
PollenBinderHelper.getSimpleTopiaBinder(UserAccount.class);
@@ -83,9 +86,24 @@
user
);
map.put("id", user.getTopiaId());
+ Set<String> functions = getUserFunctions(userAccount, user);
+ map.put("functions", functions);
+
users[index++] = map;
}
return SUCCESS;
}
+
+ protected Set<String> getUserFunctions(UserAccount connectedUser, UserAccount user) {
+ Set<String> result = Sets.newHashSet();
+ result.add("edit");
+ if (!user.equals(connectedUser)) {
+
+ // can not delete current connected user
+
+ result.add("delete");
+ }
+ return result;
+ }
}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.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/EditPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -55,6 +55,8 @@
private static final String PREFIX_PERSON_TO_LIST = "personToList_%d_%d";
+ private static final long serialVersionUID = 1L;
+
protected PollUri pollUri;
public final PollUri getUriId() {
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Confirm.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Confirm.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Confirm.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -0,0 +1,96 @@
+/*
+ * #%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.user;
+
+import org.apache.commons.lang.StringUtils;
+import org.chorem.pollen.business.persistence.PersonList;
+import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.services.impl.FavoriteService;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * Action for confirmation
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class Confirm extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String favoriteListId;
+
+ protected String pollAccountId;
+
+ protected PersonList favoriteList;
+
+ protected PollAccount pollAccount;
+
+ protected String redirectUrl;
+
+ public void setRedirectUrl(String redirectUrl) {
+ this.redirectUrl = redirectUrl;
+ }
+
+ public void setPollAccountId(String pollAccountId) {
+ this.pollAccountId = pollAccountId;
+ }
+
+ public void setFavoriteListId(String favoriteListId) {
+ this.favoriteListId = favoriteListId;
+ }
+
+ public String getRedirectUrl() {
+ return redirectUrl;
+ }
+
+ public PersonList getFavoriteList() {
+ return favoriteList;
+ }
+
+ public PollAccount getPollAccount() {
+ return pollAccount;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ FavoriteService service = newService(FavoriteService.class);
+
+ if (StringUtils.isNotEmpty(favoriteListId)) {
+
+ // load favorite list
+ favoriteList = service.getEntityById(PersonList.class,
+ favoriteListId);
+ }
+
+ if (StringUtils.isNotEmpty(pollAccountId)) {
+
+ // load poll account
+ pollAccount = service.getEntityById(PollAccount.class,
+ pollAccountId);
+ }
+ return SUCCESS;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Confirm.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeleteFavoriteList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeleteFavoriteList.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeleteFavoriteList.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -0,0 +1,85 @@
+/*
+ * #%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.user;
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.business.persistence.PersonList;
+import org.chorem.pollen.services.exceptions.UserNotFoundException;
+import org.chorem.pollen.services.impl.FavoriteService;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * Delete a selected favorite list for the connected user.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class DeleteFavoriteList extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String favoriteListId;
+
+ protected String redirectUrl;
+
+ public void setRedirectUrl(String redirectUrl) {
+ this.redirectUrl = redirectUrl;
+ }
+
+ public void setFavoriteListId(String favoriteListId) {
+ this.favoriteListId = favoriteListId;
+ }
+
+ public String getRedirectUrl() {
+ return redirectUrl;
+ }
+
+ public String execute() throws Exception {
+
+ Preconditions.checkNotNull(favoriteListId);
+
+ String result = INPUT;
+
+ try {
+ FavoriteService service = newService(FavoriteService.class);
+
+ PersonList favoriteList = service.getEntityById(
+ PersonList.class, favoriteListId);
+
+ PersonList deletedFavoritedList = service.deleteFavoriteList(
+ getPollenUserAccount(), favoriteList);
+
+ getTransaction().commitTransaction();
+
+ addActionMessage(_("pollen.information.favoriteList.deleted",
+ deletedFavoritedList.getName()));
+
+ result = SUCCESS;
+ } catch (UserNotFoundException e) {
+ addFieldError("deleteUser.login",
+ _("pollen.error.user.not.found"));
+ }
+ return result;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeleteFavoriteList.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeletePollAccount.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeletePollAccount.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeletePollAccount.java 2012-04-02 17:30:25 UTC (rev 3229)
@@ -0,0 +1,86 @@
+/*
+ * #%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.user;
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.business.persistence.PersonList;
+import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.services.impl.FavoriteService;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * Delete a selected favorite list for the connected user.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class DeletePollAccount extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String favoriteListId;
+
+ protected String pollAccountId;
+
+ protected String redirectUrl;
+
+ public void setRedirectUrl(String redirectUrl) {
+ this.redirectUrl = redirectUrl;
+ }
+
+ public void setFavoriteListId(String favoriteListId) {
+ this.favoriteListId = favoriteListId;
+ }
+
+ public void setPollAccountId(String pollAccountId) {
+ this.pollAccountId = pollAccountId;
+ }
+
+ public String getRedirectUrl() {
+ return redirectUrl;
+ }
+
+ public String execute() throws Exception {
+
+ Preconditions.checkNotNull(pollAccountId);
+
+ FavoriteService service = newService(FavoriteService.class);
+
+ PersonList favoriteList = service.getEntityById(PersonList.class,
+ favoriteListId);
+
+ PollAccount pollAccount = service.getEntityById(PollAccount.class,
+ pollAccountId);
+
+ service.removePollAccountToFavoriteList(favoriteList, pollAccount);
+
+ getTransaction().commitTransaction();
+
+ addActionMessage(
+ _("pollen.information.pollAccount.removedFromFavoriteList",
+ pollAccount.getVotingId()));
+
+ return SUCCESS;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/DeletePollAccount.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-admin.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-admin.xml 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-admin.xml 2012-04-02 17:30:25 UTC (rev 3229)
@@ -62,11 +62,18 @@
<result>/WEB-INF/jsp/admin/usersList.jsp</result>
</action>
+ <!-- confirm delete user -->
+ <action name="confirmDeleteUser"
+ class="org.chorem.pollen.ui.actions.admin.Confirm">
+ <result>/WEB-INF/jsp/admin/confirmDeleteUser.jsp</result>
+ </action>
+
<!-- delete user -->
- <action name="delete" method="delete"
- class="org.chorem.pollen.ui.actions.admin.ManageUsers">
- <result name="input">/WEB-INF/jsp/admin/usersList.jsp</result>
- <result>/WEB-INF/jsp/admin/usersList.jsp</result>
+ <action name="deleteUser"
+ class="org.chorem.pollen.ui.actions.admin.DeleteUser">
+ <!--<result name="input">/WEB-INF/jsp/admin/usersList.jsp</result>-->
+ <result type="redirect2"/>
+ <!--<result>/WEB-INF/jsp/admin/usersList.jsp</result>-->
</action>
</package>
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-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-04-02 17:30:25 UTC (rev 3229)
@@ -39,11 +39,6 @@
<param name="actionName">votefor/${uriId}</param>
</result-type>
- <result-type name="redirect2"
- class="org.apache.struts2.dispatcher.ServletRedirectResult">
- <param name="location">${redirectUrl}</param>
- <param name="prependServletContext">false</param>
- </result-type>
</result-types>
<!-- create poll -->
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-user.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-user.xml 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-user.xml 2012-04-02 17:30:25 UTC (rev 3229)
@@ -79,12 +79,19 @@
<result>/WEB-INF/jsp/user/favoriteLists.jsp</result>
</action>
+ <!-- confirm delete favorite list -->
+ <action name="confirmDeleteFavoriteList"
+ class="org.chorem.pollen.ui.actions.user.Confirm">
+ <result>/WEB-INF/jsp/user/confirmDeleteFavoriteList.jsp</result>
+ </action>
+
<!-- delete favorite list -->
- <action name="deleteFavoriteList" method="delete"
- class="org.chorem.pollen.ui.actions.user.ManageFavoriteLists">
+ <action name="deleteFavoriteList"
+ class="org.chorem.pollen.ui.actions.user.DeleteFavoriteList">
<interceptor-ref name="pollenParamsPrepareParamsStack"/>
- <result name="input">/WEB-INF/jsp/user/favoriteLists.jsp</result>
- <result>/WEB-INF/jsp/user/favoriteLists.jsp</result>
+ <!--<result name="input">/WEB-INF/jsp/user/favoriteLists.jsp</result>-->
+ <result type="redirect2"/>
+ <!--<result>/WEB-INF/jsp/user/favoriteLists.jsp</result>-->
</action>
<!-- edit favorite list -->
@@ -110,12 +117,19 @@
<result>/WEB-INF/jsp/user/favoriteList.jsp</result>
</action>
+ <!-- confirm delete poll account from a favorite list -->
+ <action name="confirmDeletePollAccount"
+ class="org.chorem.pollen.ui.actions.user.Confirm">
+ <result>/WEB-INF/jsp/user/confirmDeletePollAccount.jsp</result>
+ </action>
+
<!-- remove poll account from a favorite list -->
- <action name="removePollAccount" method="delete"
- class="org.chorem.pollen.ui.actions.user.ManageFavoriteList">
+ <action name="deletePollAccount"
+ class="org.chorem.pollen.ui.actions.user.DeletePollAccount">
<interceptor-ref name="pollenParamsPrepareParamsStack"/>
- <result name="input">/WEB-INF/jsp/user/favoriteList.jsp</result>
- <result>/WEB-INF/jsp/user/favoriteList.jsp</result>
+ <!--<result name="input">/WEB-INF/jsp/user/favoriteList.jsp</result>-->
+ <!--<result>/WEB-INF/jsp/user/favoriteList.jsp</result>-->
+ <result type="redirect2"/>
</action>
<!-- display createds polls -->
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-04-02 17:30:25 UTC (rev 3229)
@@ -183,7 +183,9 @@
pollen.information.confirmClonePoll=Confirm clone of poll\:
pollen.information.confirmClosePoll=Confirm close of poll\:
pollen.information.confirmDeleteChoice=Confirm delete of choice %s
+pollen.information.confirmDeleteFavoriteList=Confirm delete of favorite list\:
pollen.information.confirmDeletePoll=Confirm delete of poll\:
+pollen.information.confirmDeleteUser=Confirm delete of user %s
pollen.information.confirmDeleteVote=Confirm delete of vote for %s
pollen.information.favoriteList.created=Favorite list %s created.
pollen.information.favoriteList.deleted=Favorite list %s deleted.
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-04-02 17:30:25 UTC (rev 3229)
@@ -189,9 +189,12 @@
pollen.info.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 \:
pollen.information.confirmDeletePoll=Confirmer la suppression du sondage \:
+pollen.information.confirmDeletePollAccount=Confirmer la suppression du votant \:
pollen.information.confirmDeletePollChoice=Confirmer la suppression du choix %s
pollen.information.confirmDeletePollVote=Confirmer la suppression du vote de %s
+pollen.information.confirmDeleteUser=Confirmer la suppression de l'utilisateur \:
pollen.information.favoriteList.created=La liste %s a été créée.
pollen.information.favoriteList.deleted=La liste %s a été supprimée.
pollen.information.irreversible.operation=Attention, Cette opération est irréversible.
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/CreatePoll-conversion.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/CreatePoll-conversion.properties (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/CreatePoll-conversion.properties 2012-04-02 17:30:25 UTC (rev 3229)
@@ -0,0 +1,24 @@
+###
+# #%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%
+###
+uriId=org.chorem.pollen.ui.actions.PollUriConverter
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/CreatePoll-conversion.properties
___________________________________________________________________
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/struts.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-04-02 17:30:25 UTC (rev 3229)
@@ -57,6 +57,12 @@
<param name="namespace">/</param>
<param name="actionName">home</param>
</result-type>
+
+ <result-type name="redirect2"
+ class="org.apache.struts2.dispatcher.ServletRedirectResult">
+ <param name="location">${redirectUrl}</param>
+ <param name="prependServletContext">false</param>
+ </result-type>
</result-types>
<interceptors>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml 2012-04-02 17:30:25 UTC (rev 3229)
@@ -29,6 +29,8 @@
<pattern>/images/*</pattern>
<pattern>/config-browser/*</pattern>
<pattern>/json/*</pattern>
+ <pattern>/user/confirm*</pattern>
+ <pattern>/admin/confirm*</pattern>
<pattern>/poll/confirm*</pattern>
<pattern>/poll/display*</pattern>
<pattern>/poll/selectPersonListTo*</pattern>
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/confirmDeleteUser.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/confirmDeleteUser.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/confirmDeleteUser.jsp 2012-04-02 17:30:25 UTC (rev 3229)
@@ -0,0 +1,56 @@
+<%--
+ #%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 contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<script type="text/javascript">
+ function cancel() {
+ $('#confirmDialog').dialog('close');
+ return false;
+ }
+</script>
+<s:form method="POST" namespace="/admin">
+ <fieldset class="ui-widget-content ui-corner-all">
+
+ <s:hidden key="redirectUrl" label=''/>
+ <s:hidden key="userId" value='%{user.topiaId}' label=''/>
+
+ <s:text name="pollen.information.confirmDeleteUser"/>
+ <div align="center" style="padding-top: 1em;">
+ "<strong><s:property value="user.displayName"/></strong>"
+ </div>
+ <br/>
+
+ <div style="padding-top: 1em;">
+ <strong>
+ <s:text name="pollen.information.irreversible.operation"/>
+ </strong>
+ </div>
+ <hr/>
+ <div align="right">
+ <s:submit onclick="return cancel();" theme="simple"
+ key="pollen.action.cancel"/>
+ <s:submit key="pollen.action.delete" theme="simple" action="deleteUser"/>
+ </div>
+ </fieldset>
+</s:form>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/confirmDeleteUser.jsp
___________________________________________________________________
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/webapp/WEB-INF/jsp/admin/usersList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp 2012-04-02 17:30:25 UTC (rev 3229)
@@ -24,6 +24,7 @@
<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>
+<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<script type="text/javascript"
src="<s:url value='/js/gridHelper.js' />"></script>
@@ -39,11 +40,17 @@
<s:set var="user" value="%{#session.pollenSession.userAccount}"/>
<script type="text/javascript">
+
+ var redirectUrl = '<s:url namespace="/admin" action="usersList"/>';
+ var deleteTitle = '<s:text name="pollen.action.deleteUser"/>';
+ var deleteUrl = '<s:url action="confirmDeleteUser" namespace="/admin"/>';
+ var loadUserUrl = '<s:url action="getUser" namespace="/json"/>';
+ var editImg = '<s:url value='/img/edit.png'/>';
+ var editTitle = '<s:text name="pollen.action.editUser"/>';
+ var deleteImg = '<s:url value='/img/delete.png'/>';
+
jQuery(document).ready(function () {
- initUsersPage(
- '${action}',
- '<s:url action="getUser" namespace="/json"/>'
- );
+ initUsersPage('${action}', '${user.topiaId}');
});
</script>
@@ -57,69 +64,70 @@
navigatorAdd="false" viewrecords="true"
rowList="10,15,20,50,100" rowNum="10"
navigatorExtraButtons="{
- add: { title: '%{getText(\"pollen.action.createUser\")}', icon: 'ui-icon-plus', topic: 'users-addRow' },
- edit: { title: '%{getText(\"pollen.action.editUser\")}', icon: 'ui-icon-pencil', topic: 'users-editRow' },
- delete:{ title: '%{getText(\"pollen.action.deleteUser\")}', icon: 'ui-icon-trash', topic: 'users-deleteRow' }}">
+ add: { title: '%{getText(\"pollen.action.createUser\")}', icon: 'ui-icon-plus', topic: 'users-addRow' }}">
<sjg:gridColumn name="id" title="id" hidden="true"/>
<sjg:gridColumn name="login" title='%{getText("pollen.common.login")}'/>
- <sjg:gridColumn name="firstName" title='%{getText("pollen.common.firstName")}'/>
+ <sjg:gridColumn name="firstName"
+ title='%{getText("pollen.common.firstName")}'/>
<sjg:gridColumn name="lastName" title='%{getText("pollen.common.lastName")}'/>
<sjg:gridColumn name="email" title='%{getText("pollen.common.email")}'/>
- <sjg:gridColumn name="administrator" width="100" formatter="checkbox"
- title='%{getText("pollen.common.administrator")}' />
+ <sjg:gridColumn name="administrator" width="20" formatter="checkbox"
+ title='%{getText("pollen.common.administrator")}'/>
+ <sjg:gridColumn name="functions" title='%{getText("pollen.common.functions")}'
+ formatter="userFunctions" width="40" sortable="false"/>
</sjg:grid>
<br/>
-<s:form id='createForm' method="POST" namespace="/admin" cssClass="hidden userForm">
+<s:form id='createForm' method="POST" namespace="/admin"
+ cssClass="hidden userForm">
<s:hidden name="action" value="create"/>
<fieldset>
<legend><s:text name="pollen.fieldset.userInformation.toCreate"/></legend>
- <s:textfield key="createUser.login" label="%{getText('pollen.common.login')}" required="true" size="40"/>
- <s:textfield key="createUser.email" label="%{getText('pollen.common.email')}" required="true" size="40"/>
- <s:textfield key="createUser.firstName" label="%{getText('pollen.common.firstName')}" size="40"/>
- <s:textfield key="createUser.lastName" label="%{getText('pollen.common.lastName')}" size="40"/>
- <s:checkbox key="createUser.administrator" label="%{getText('pollen.common.administrator')}"/>
+ <s:textfield key="createUser.login"
+ label="%{getText('pollen.common.login')}" required="true"
+ size="40"/>
+ <s:textfield key="createUser.email"
+ label="%{getText('pollen.common.email')}" required="true"
+ size="40"/>
+ <s:textfield key="createUser.firstName"
+ label="%{getText('pollen.common.firstName')}" size="40"/>
+ <s:textfield key="createUser.lastName"
+ label="%{getText('pollen.common.lastName')}" size="40"/>
+ <s:checkbox key="createUser.administrator"
+ label="%{getText('pollen.common.administrator')}"/>
</fieldset>
<br/>
<s:submit action="create" key="pollen.action.create" align="center"/>
</s:form>
-<s:form id='editForm' method="POST" namespace="/admin" cssClass="hidden userForm">
+<s:form id='editForm' method="POST" namespace="/admin"
+ cssClass="hidden userForm">
<s:hidden name="action" value="edit"/>
<s:hidden key="editUser.topiaId" label=""/>
<fieldset>
<legend><s:text name="pollen.fieldset.userInformation.toUpdate"/></legend>
- <s:textfield key="editUser.login" label="%{getText('pollen.common.login')}" required="true" readonly="true" size="40"/>
- <s:textfield key="editUser.email" label="%{getText('pollen.common.email')}" required="true" size="40"/>
- <s:textfield key="editUser.firstName" label="%{getText('pollen.common.firstName')}" size="40"/>
- <s:textfield key="editUser.lastName" label="%{getText('pollen.common.lastName')}" size="40"/>
- <s:checkbox key="editUser.administrator" label="%{getText('pollen.common.administrator')}"/>
+ <s:textfield key="editUser.login" label="%{getText('pollen.common.login')}"
+ required="true" readonly="true" size="40"/>
+ <s:textfield key="editUser.email" label="%{getText('pollen.common.email')}"
+ required="true" size="40"/>
+ <s:textfield key="editUser.firstName"
+ label="%{getText('pollen.common.firstName')}" size="40"/>
+ <s:textfield key="editUser.lastName"
+ label="%{getText('pollen.common.lastName')}" size="40"/>
+ <s:checkbox key="editUser.administrator"
+ label="%{getText('pollen.common.administrator')}"/>
</fieldset>
<br/>
<s:submit action="edit" key="pollen.action.validate" align="center"/>
</s:form>
-<s:form id='deleteForm' method="POST" namespace="/admin" cssClass="hidden userForm">
+<sj:dialog id="confirmDialog" autoOpen="false" modal="true" width="500"/>
- <s:hidden name="action" value="delete"/>
- <s:hidden key="deleteUser.topiaId" label=""/>
- <fieldset>
- <legend><s:text name="pollen.fieldset.userInformation.toDelete"/></legend>
- <s:textfield key="deleteUser.login" label="%{getText('pollen.common.login')}" required="true" readonly="true" size="40"/>
- <s:textfield key="deleteUser.email" label="%{getText('pollen.common.email')}" required="true" readonly="true" size="40"/>
- <s:textfield key="deleteUser.firstName" label="%{getText('pollen.common.firstName')}" readonly="true" size="40"/>
- <s:textfield key="deleteUser.lastName" label="%{getText('pollen.common.lastName')}" readonly="true" size="40"/>
- <s:checkbox key="deleteUser.administrator" label="%{getText('pollen.common.administrator')}" disabled="true"/>
- </fieldset>
- <br/>
- <s:submit action="delete" key="pollen.action.delete" align="center"/>
-</s:form>
-
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/confirmDeleteFavoriteList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/confirmDeleteFavoriteList.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/confirmDeleteFavoriteList.jsp 2012-04-02 17:30:25 UTC (rev 3229)
@@ -0,0 +1,56 @@
+<%--
+ #%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 contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<script type="text/javascript">
+ function cancel() {
+ $('#confirmDialog').dialog('close');
+ return false;
+ }
+</script>
+<s:form method="POST" namespace="/user">
+ <fieldset class="ui-widget-content ui-corner-all">
+
+ <s:hidden key="redirectUrl" label=''/>
+ <s:hidden key="favoriteListId" value='%{favoriteList.topiaId}' label=''/>
+
+ <s:text name="pollen.information.confirmDeleteFavoriteList"/>
+ <div align="center" style="padding-top: 1em;">
+ "<strong><s:property value="favoriteList.name"/></strong>"
+ </div>
+ <br/>
+
+ <div style="padding-top: 1em;">
+ <strong><s:text
+ name="pollen.information.irreversible.operation"/></strong>
+ </div>
+ <hr/>
+ <div align="right">
+ <s:submit onclick="return cancel();" theme="simple"
+ key="pollen.action.cancel"/>
+ <s:submit key="pollen.action.delete" theme="simple"
+ action="deleteFavoriteList"/>
+ </div>
+ </fieldset>
+</s:form>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/confirmDeleteFavoriteList.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/confirmDeletePollAccount.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/confirmDeletePollAccount.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/confirmDeletePollAccount.jsp 2012-04-02 17:30:25 UTC (rev 3229)
@@ -0,0 +1,57 @@
+<%--
+ #%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 contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<script type="text/javascript">
+ function cancel() {
+ $('#confirmDialog').dialog('close');
+ return false;
+ }
+</script>
+<s:form method="POST" namespace="/user">
+ <fieldset class="ui-widget-content ui-corner-all">
+
+ <s:hidden key="redirectUrl" label=''/>
+ <s:hidden key="favoriteListId" value='%{favoriteList.topiaId}' label=''/>
+ <s:hidden key="pollAccountId" value='%{pollAccount.topiaId}' label=''/>
+
+ <s:text name="pollen.information.confirmDeletePollAccount"/>
+ <div align="center" style="padding-top: 1em;">
+ "<strong><s:property value="pollAccount.votingId"/></strong>"
+ </div>
+ <br/>
+
+ <div style="padding-top: 1em;">
+ <strong><s:text
+ name="pollen.information.irreversible.operation"/></strong>
+ </div>
+ <hr/>
+ <div align="right">
+ <s:submit onclick="return cancel();" theme="simple"
+ key="pollen.action.cancel"/>
+ <s:submit key="pollen.action.delete" theme="simple"
+ action="deletePollAccount"/>
+ </div>
+ </fieldset>
+</s:form>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/confirmDeletePollAccount.jsp
___________________________________________________________________
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/webapp/WEB-INF/jsp/user/favoriteList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteList.jsp 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteList.jsp 2012-04-02 17:30:25 UTC (rev 3229)
@@ -24,6 +24,7 @@
<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>
+<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<script type="text/javascript"
src="<s:url value='/js/gridHelper.js' />"></script>
@@ -35,14 +36,24 @@
<s:param name="favoriteListId" value="%{favoriteList.topiaId}"/>
</s:url>
+<s:url id="editPollAccounts" action="editPollAccount" namespace="/user">
+ <s:param name="favoriteListId" value="%{favoriteList.topiaId}"/>
+</s:url>
+
<script type="text/javascript">
+ var favoriteListId = '<s:property value="favoriteList.topiaId"/>';
+ var redirectUrl = '${editPollAccounts}';
+ var deleteTitle = '<s:text name="pollen.action.deletePollAccount"/>';
+ var deleteUrl = '<s:url action="confirmDeletePollAccount" namespace="/user" />';
+ var loadPollActionUrl = '<s:url action="getFavoriteListPollAccount" namespace="/json"/>';
+ var editImg = '<s:url value='/img/edit.png'/>';
+ var editTitle = '<s:text name="pollen.action.editPollAccount"/>';
+ var deleteImg = '<s:url value='/img/delete.png'/>';
+
jQuery(document).ready(function () {
- initFavoritePage(
- '${action}',
- '<s:url action="getFavoriteListPollAccount" namespace="/json"/>'
- );
+ initFavoritePage('${action}');
});
</script>
@@ -67,13 +78,14 @@
navigatorAdd="false" viewrecords="true"
rowList="10,15,20,50,100" rowNum="10"
navigatorExtraButtons="{
- add: { title: '%{getText(\"pollen.action.createPollAccount\")}', icon: 'ui-icon-plus', topic: 'pollAccounts-addRow' },
- edit: { title: '%{getText(\"pollen.action.editPollAccount\")}', icon: 'ui-icon-pencil', topic: 'pollAccounts-editRow' },
- delete:{ title: '%{getText(\"pollen.action.deletePollAccount\")}', icon: 'ui-icon-trash', topic: 'pollAccounts-deleteRow'}}">
+ add: { title: '%{getText(\"pollen.action.createPollAccount\")}', icon: 'ui-icon-plus', topic: 'pollAccounts-addRow' }}">
<sjg:gridColumn name="id" title="id" hidden="true"/>
<sjg:gridColumn name="votingId" title='%{getText("pollen.common.name")}'/>
<sjg:gridColumn name="email" title='%{getText("pollen.common.email")}'/>
+ <sjg:gridColumn name="functions" title='%{getText("pollen.common.functions")}'
+ formatter="favoriteListFunctions" width="40"
+ sortable="false"/>
</sjg:grid>
<br/>
@@ -119,31 +131,11 @@
align="center"/>
</s:form>
-<s:form id='deleteForm' method="POST" namespace="/user"
- cssClass="hidden pollAccountForm">
-
- <s:hidden name="action" value="delete"/>
- <s:hidden key="deletePollAccount.topiaId" label=""/>
- <s:hidden key="favoriteListId" label=""/>
-
- <fieldset>
- <legend>
- <s:text name="pollen.fieldset.pollAccount.toDeleteFromFavoriteList"/>
- </legend>
- <s:textfield key="deletePollAccount.votingId" required="true" size="40"
- label="%{getText('pollen.common.name')}" readonly="true"/>
- <s:textfield key="deletePollAccount.email" required="true" readonly="true"
- label="%{getText('pollen.common.email')}" size="40"/>
- </fieldset>
- <br/>
-
- <s:submit action="removePollAccount" key="pollen.action.delete"
- align="center"/>
-</s:form>
-
<br/>
<s:form method="POST" namespace="/user">
<s:submit action="favoriteLists"
key="pollen.action.backToFavoriteLists" align="center"/>
</s:form>
+
+<sj:dialog id="confirmDialog" autoOpen="false" modal="true" width="500"/>
\ No newline at end of file
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp 2012-04-02 17:30:25 UTC (rev 3229)
@@ -24,6 +24,7 @@
<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>
+<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<script type="text/javascript"
src="<s:url value='/js/gridHelper.js' />"></script>
@@ -38,12 +39,17 @@
<script type="text/javascript">
+ var redirectUrl = '<s:url namespace="/user" action="favoriteLists"/>';
+ var deleteTitle = '<s:text name="pollen.action.deleteFavoriteList"/>';
+ var deleteUrl = '<s:url action="confirmDeleteFavoriteList" namespace="/user"/>';
+ var loadUserUrl = '<s:url action="getFavoriteList" namespace="/json"/>';
+ var editImg = '<s:url value='/img/edit.png'/>';
+ var editTitle = '<s:text name="pollen.action.editFavoriteList"/>';
+ var deleteImg = '<s:url value='/img/delete.png'/>';
+
jQuery(document).ready(function () {
- initFavoritesPage(
- '${action}',
- '<s:url action="getFavoriteList" namespace="/json"/>'
- );
+ initFavoritesPage('${action}');
});
</script>
@@ -57,14 +63,15 @@
navigatorSearch="false" navigatorRefresh="false"
navigatorAdd="false" rowList="10,15,20,50,100" rowNum="10"
navigatorExtraButtons="{
- add: { title: '%{getText(\"pollen.action.createFavoriteList\")}', icon: 'ui-icon-plus', topic: 'favoriteLists-addRow' },
- edit: { title: '%{getText(\"pollen.action.editFavoriteList\")}', icon: 'ui-icon-pencil', topic: 'favoriteLists-editRow' },
- delete:{ title: '%{getText(\"pollen.action.deleteFavoriteList\")}', icon: 'ui-icon-trash', topic: 'favoriteLists-deleteRow'}}">
+ add: { title: '%{getText(\"pollen.action.createFavoriteList\")}', icon: 'ui-icon-plus', topic: 'favoriteLists-addRow' }}">
<sjg:gridColumn name="id" title="id" hidden="true"/>
<sjg:gridColumn name="name" title='%{getText("pollen.common.name")}'/>
<sjg:gridColumn name="nbAccounts"
title='%{getText("pollen.common.nbAccounts")}'/>
+ <sjg:gridColumn name="functions" title='%{getText("pollen.common.functions")}'
+ formatter="favoriteListsFunctions" width="40"
+ sortable="false"/>
</sjg:grid>
<br/>
@@ -87,32 +94,13 @@
align="center"/>
</s:form>
-<s:form id='deleteForm' method="POST" namespace="/user"
- cssClass="hidden favoriteForm">
+<s:form id='editForm' method="POST" namespace="/user" theme="simple"
+ action="editFavoriteList" cssClass="hidden">
- <s:hidden name="action" value="delete"/>
- <s:hidden key="deleteFavoriteList.topiaId" label=""/>
-
- <fieldset>
- <legend>
- <s:text name="pollen.fieldset.userFavoriteList.toDelete"/>
- </legend>
- <s:textfield key="deleteFavoriteList.name" required="true" readonly="true"
- size="40" label="%{getText('pollen.common.name')}"/>
- </fieldset>
- <br/>
- <s:submit action="deleteFavoriteList" key="pollen.action.delete"
- align="center"/>
-</s:form>
-
-<s:form id='editForm' method="POST" namespace="/user"
- action="editFavoriteList" theme="simple"
- cssClass="hidden">
-
<s:hidden key="favoriteListId" label=""/>
<s:submit action="editFavoriteList"/>
</s:form>
+<sj:dialog id="confirmDialog" autoOpen="false" modal="true" width="500"/>
-
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteList.js
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteList.js 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteList.js 2012-04-02 17:30:25 UTC (rev 3229)
@@ -26,12 +26,17 @@
$('#createForm').show();
} else if (action == 'edit') {
$('#editForm').show();
- } else if (action == 'delete') {
- $('#deleteForm').show();
}
// listen row selection
- $.addRowSelectTopic('pollAccounts');
+ $.addRowSelectTopic('pollAccounts', function () {
+ if (action != '') {
+ // come back from action
+ action = '';
+ return;
+ }
+ $(".pollAccountForm").hide();
+ });
$.addClearSelectTopic('pollAccounts', function () {
if (action != '') {
@@ -50,50 +55,50 @@
$('#editForm').hide();
$('#createForm').show();
});
+}
- // to edit the selected row
- $.listenRowTopic('pollAccounts-editRow', function (event) {
- var id = $.getSelectedId('pollAccounts');
- if (!id) {
+function favoriteListFunctions(cellvalue, options, rowObject) {
- // no row selected
- return;
- }
+ var id = rowObject.id;
- jQuery.getJSON(loadPollActionUrl, { "pollAccountId":id },
- function (result) {
+ var result = "";
- var pollAccount = result.pollAccount;
- $('#editForm [name="editPollAccount.topiaId"]').val(pollAccount.id);
- $('#editForm [name="editPollAccount.votingId"]').val(pollAccount.votingId);
- $('#editForm [name="editPollAccount.email"]').val(pollAccount.email);
- $('#deleteForm').hide();
- $('#createForm').hide();
- $('#editForm').show();
- }
- );
- });
+ var script = 'return editPollAccount("' + id + '");';
+ result += formatLinkByScript(script, editImg, "Edit", editTitle);
- // to delete the selected row
- $.listenRowTopic('pollAccounts-deleteRow', function (event) {
- var id = $.getSelectedId('pollAccounts');
- if (!id) {
+ script = 'return confirmDelete("' + id + '");';
+ result += formatLinkByScript(script, deleteImg, "Delete", deleteTitle);
+ return result;
+}
- // no row selected
- return;
- }
+function formatLinkByScript(script, image, imageAlt, imageTitle) {
+ return "<a href='#' onclick='" + script + "'><image alt='" + imageAlt + "' title='" + imageTitle + "' src='" + image + "'> </a>";
+}
- jQuery.getJSON(loadPollActionUrl, { "pollAccountId":id },
- function (result) {
+// to edit the selected row
+function editPollAccount(id) {
- var pollAccount = result.pollAccount;
- $('#deleteForm [name="deletePollAccount.topiaId"]').val(pollAccount.id);
- $('#deleteForm [name="deletePollAccount.votingId"]').val(pollAccount.votingId);
- $('#deleteForm [name="deletePollAccount.email"]').val(pollAccount.email);
- $('#editForm').hide();
- $('#createForm').hide();
- $('#deleteForm').show();
- }
- );
- });
+ jQuery.getJSON(
+ loadPollActionUrl, { "pollAccountId":id }, function (result) {
+
+ var pollAccount = result.pollAccount;
+ $('#editForm [name="editPollAccount.topiaId"]').val(pollAccount.id);
+ $('#editForm [name="editPollAccount.votingId"]').val(pollAccount.votingId);
+ $('#editForm [name="editPollAccount.email"]').val(pollAccount.email);
+ $('#deleteForm').hide();
+ $('#createForm').hide();
+ $('#editForm').show();
+ }
+ );
+}
+
+function confirmDelete(id) {
+ $('.ui-dialog-title').html(deleteTitle)
+ var dialog = $("#confirmDialog");
+ var url = deleteUrl + '?' + $.param({favoriteListId:favoriteListId,
+ pollAccountId:id,
+ redirectUrl:redirectUrl});
+ dialog.load(url);
+ dialog.dialog('open');
+ return false;
}
\ No newline at end of file
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteLists.js
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteLists.js 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteLists.js 2012-04-02 17:30:25 UTC (rev 3229)
@@ -21,16 +21,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
-function initFavoritesPage(action, loadFavoriteList) {
+function initFavoritesPage(action) {
if (action == 'create') {
$('#createForm').show();
- } else if (action == 'delete') {
- $('#deleteForm').show();
}
// listen row selection
- $.addRowSelectTopic('favoriteLists');
+ $.addRowSelectTopic('favoriteLists', function () {
+ if (action != '') {
+ // come back from action
+ action = '';
+ return;
+ }
+ $(".userForm").hide();
+ });
$.addClearSelectTopic('favoriteLists', function () {
if (action != '') {
@@ -51,34 +56,38 @@
$('#deleteForm').hide();
$('#createForm').show();
});
+}
- // to edit a selected row
- $.listenRowTopic('favoriteLists-editRow', function (event) {
- var id = $.getSelectedId('favoriteLists');
- if (!id) {
- // no row selected
- return;
- }
+function favoriteListsFunctions(cellvalue, options, rowObject) {
- $('#editForm [name="favoriteListId"]').val(id);
- $('#editForm').submit();
- });
+ var id = rowObject.id;
- // to delete the selected row
- $.listenRowTopic('favoriteLists-deleteRow', function (event) {
- var id = $.getSelectedId('favoriteLists');
- if (!id) {
- // no row selected
- return;
- }
- jQuery.getJSON(loadFavoriteList, { favoriteListId:id },
- function (result) {
- var user = result.favoriteList;
- $('#deleteForm [name="deleteFavoriteList.topiaId"]').val(user.id);
- $('#deleteForm [name="deleteFavoriteList.name"]').val(user.name);
- $('#createForm').hide();
- $('#deleteForm').show();
- }
- );
- });
+ var result = "";
+
+ var script = 'return editFavoriteList("' + id + '");';
+ result += formatLinkByScript(script, editImg, "Edit", editTitle);
+
+ script = 'return confirmDelete("' + id + '");';
+ result += formatLinkByScript(script, deleteImg, "Delete", deleteTitle);
+ return result;
+}
+
+function formatLinkByScript(script, image, imageAlt, imageTitle) {
+ return "<a href='#' onclick='" + script + "'><image alt='" + imageAlt + "' title='" + imageTitle + "' src='" + image + "'> </a>";
+}
+
+function editFavoriteList(id) {
+ $('#editForm [name="favoriteListId"]').val(id);
+ $('#editForm').submit();
+ return false;
+}
+
+function confirmDelete(id) {
+ $('.ui-dialog-title').html(deleteTitle)
+ var dialog = $("#confirmDialog");
+ var url = deleteUrl + '?' + $.param({favoriteListId:id,
+ redirectUrl:redirectUrl});
+ dialog.load(url);
+ dialog.dialog('open');
+ return false;
}
\ No newline at end of file
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/usersList.js
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/usersList.js 2012-04-02 16:42:38 UTC (rev 3228)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/usersList.js 2012-04-02 17:30:25 UTC (rev 3229)
@@ -21,7 +21,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
-function initUsersPage(action, loadUserUrl) {
+function initUsersPage(action, userId) {
if (action == 'create') {
$('#createForm').show();
@@ -29,12 +29,16 @@
if (action == 'edit') {
$('#editForm').show();
}
- if (action == 'delete') {
- $('#deleteForm').show();
- }
// listen row selection
- $.addRowSelectTopic('users');
+ $.addRowSelectTopic('users', function () {
+ if (action != '') {
+ // come back from action
+ action = '';
+ return;
+ }
+ $(".userForm").hide();
+ });
$.addClearSelectTopic('users', function () {
if (action != '') {
@@ -58,65 +62,54 @@
$('#deleteForm').hide();
$('#createForm').show();
});
+}
- // to edit a selected row
- $.listenRowTopic('users-editRow', function (event) {
- var id = $.getSelectedId('users');
- if (!id) {
+function userFunctions(cellvalue, options, rowObject) {
- // no user selected
- return;
- }
- $('#editForm .errorMessage').hide();
- jQuery.getJSON(loadUserUrl, { "userId":id }, function (result) {
+ var id = rowObject.id;
- var user = result.user;
- $('#editForm [name="editUser.topiaId"]').val(user.id);
- $('#editForm [name="editUser.login"]').val(user.login);
- $('#editForm [name="editUser.email"]').val(user.email);
- $('#editForm [name="editUser.firstName"]').val(user.firstName);
- $('#editForm [name="editUser.lastName"]').val(user.lastName);
- $('#editForm [name="editUser.administrator"]').prop('checked', false);
- $('#editForm [name="editUser.administrator"]').prop('checked', user.administrator);
- $('#editForm').show();
- $('#createForm').hide();
- $('#deleteForm').hide();
- }
- );
- });
+ var result = "";
- // to delete the selected row
- $.listenRowTopic('users-deleteRow', function (event) {
- var id = $.getSelectedId('users');
- if (!id) {
+ if (cellvalue.indexOf('edit') > -1) {
+ var script = 'return editUser("' + id + '");'
+ result += formatLinkByScript(script, editImg, "Edit", editTitle)
+ }
+ if (cellvalue.indexOf('delete') > -1) {
+ var script = 'return confirmDelete("' + id + '");'
+ result += formatLinkByScript(script, deleteImg, "Delete", deleteTitle)
+ }
+ return result;
+}
- // no user selected
- return;
- }
+function formatLinkByScript(script, image, imageAlt, imageTitle) {
+ return "<a href='#' onclick='" + script + "'><image alt='" + imageAlt + "' title='" + imageTitle + "' src='" + image + "'> </a>";
+}
- var userId = '${user.topiaId}';
+function editUser(id) {
+ $('#editForm .errorMessage').hide();
+ jQuery.getJSON(
+ loadUserUrl, { "userId":id }, function (result) {
- if (id == userId) {
+ var user = result.user;
+ $('#editForm [name="editUser.topiaId"]').val(user.id);
+ $('#editForm [name="editUser.login"]').val(user.login);
+ $('#editForm [name="editUser.email"]').val(user.email);
+ $('#editForm [name="editUser.firstName"]').val(user.firstName);
+ $('#editForm [name="editUser.lastName"]').val(user.lastName);
+ $('#editForm [name="editUser.administrator"]').prop('checked', false);
+ $('#editForm [name="editUser.administrator"]').prop('checked', user.administrator);
+ $('#editForm').show();
+ $('#createForm').hide();
+ }
+ );
+ return false;
+}
- // can not delete connected user
- return;
- }
- $('#deleteForm .errorMessage').hide();
-
- jQuery.getJSON(loadUserUrl, { "userId":id }, function (result) {
-
- var user = result.user;
- $('#deleteForm [name="deleteUser.topiaId"]').val(user.id);
- $('#deleteForm [name="deleteUser.login"]').val(user.login);
- $('#deleteForm [name="deleteUser.email"]').val(user.email);
- $('#deleteForm [name="deleteUser.firstName"]').val(user.firstName);
- $('#deleteForm [name="deleteUser.lastName"]').val(user.lastName);
- $('#deleteForm [name="deleteUser.administrator"]').prop('checked', false);
- $('#deleteForm [name="deleteUser.administrator"]').prop('checked', user.administrator);
- $('#editForm').hide();
- $('#createForm').hide();
- $('#deleteForm').show();
- }
- );
- });
-}
\ No newline at end of file
+function confirmDelete(id) {
+ $('.ui-dialog-title').html(deleteTitle)
+ var dialog = $("#confirmDialog");
+ var url = deleteUrl + '?' + $.param({userId:id, redirectUrl:redirectUrl});
+ dialog.load(url);
+ dialog.dialog('open');
+ return false;
+}
1
0
r3228 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll resources/config
by fdesbois@users.chorem.org 02 Apr '12
by fdesbois@users.chorem.org 02 Apr '12
02 Apr '12
Author: fdesbois
Date: 2012-04-02 18:42:38 +0200 (Mon, 02 Apr 2012)
New Revision: 3228
Url: http://chorem.org/repositories/revision/pollen/3228
Log:
Begin EditPoll action
Modified:
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
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
Modified: 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-02 16:42:32 UTC (rev 3227)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-04-02 16:42:38 UTC (rev 3228)
@@ -138,7 +138,7 @@
* All the parameters send by request used to build back choices of the
* poll.
*/
- private Map<String, String[]> parameters;
+ protected Map<String, String[]> parameters;
private boolean informationsError;
@@ -311,7 +311,16 @@
}
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 {
@@ -322,9 +331,8 @@
choiceTypes = decorateToName(ChoiceType.values());
voteCountingTypes = decorateToName(VoteCountingType.values());
- //TODO tchemit-2012-03-05 use a default value from configuration
- nbTextChoices = nbDateChoices = nbImageChoices = 5;
- nbVotingLists = 1;
+ nbTextChoices = nbDateChoices = nbImageChoices = getNbChoices();
+ nbVotingLists = getDefaultNbVotingLists();
String tokenSuffix = getServiceContext().createPollenUrlId();
@@ -358,15 +366,15 @@
switch (pollChoiceType) {
case TEXT:
- choices = buildTextChoices(5);
+ choices = buildTextChoices(nbTextChoices);
tokenId = textChoiceTokenId;
break;
case DATE:
- choices = buildDateChoices(5);
+ choices = buildDateChoices(nbDateChoices);
tokenId = dateChoiceTokenId;
break;
case IMAGE:
- choices = buildImageChoices(5);
+ choices = buildImageChoices(nbImageChoices);
tokenId = imageChoiceTokenId;
break;
}
@@ -376,7 +384,7 @@
votingListTokenId = DisplayVotingList.VOTING_LIST_TOKEN + "_" +
tokenSuffix;
- Map<Integer, VotingList> votingLists = buildVotingLists(1);
+ Map<Integer, VotingList> votingLists = buildVotingLists(nbVotingLists);
getPollenSession().putDynamicData(votingListTokenId, votingLists);
}
Modified: 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-02 16:42:32 UTC (rev 3227)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java 2012-04-02 16:42:38 UTC (rev 3228)
@@ -23,13 +23,220 @@
*/
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 org.chorem.pollen.ui.actions.PollUriConverter;
+
+import java.util.List;
+import java.util.Map;
+
/**
- * Display a poll.
+ * Edit a poll.
*
* @author tchemit <chemit(a)codelutin.com>
+ * @author fdesbois <desbois(a)codelutin.com>
* @since 1.2.6
*/
-public class EditPoll extends AbstractPollUriIdAction {
+public class EditPoll 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;
+ }
+
+ protected void preparePollUri(Map<String, String[]> parameters) {
+ if (pollUri == null) {
+ String[] values = parameters.get("uriId");
+ pollUri = PollUriConverter.convertFromString(values);
+ }
+ }
+
+ protected boolean needTopiaId() {
+ return true;
+ }
+
+ public boolean isVoteStarted() {
+ return getPoll().sizeVote() > 0;
+ }
+
+ @Override
+ public Poll getPoll() {
+ if (poll == null) {
+ poll = getPollService().getPollByPollId(pollUri.getPollId());
+ if (!needTopiaId()) {
+ poll.setTopiaId(null);
+ }
+ }
+ return poll;
+ }
+
+ @Override
+ public void prepare() throws Exception {
+
+ preparePollUri(parameters);
+
+ // -- Choice --
+ ChoiceType choiceType = getPoll().getChoiceType();
+ prepareParams(getPoll().getChoice(), withChoicePrefix(choiceType));
+
+ // -- VotingList --
+ if (getPoll().getPollType() != PollType.FREE) {
+ prepareParams(getPoll().getVotingList(), withVotingListPrefix());
+ }
+
+ super.prepare();
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+// getPollService().updatePoll(poll):
+
+ // remove all stuff from session
+ getPollenSession().clearDynamicData();
+
+ addActionMessage(_("pollen.info.poll.created"));
+ return SUCCESS;
+ }
+
+ 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 (needTopiaId()) {
+ 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 (needTopiaId()) {
+ 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 (needTopiaId()) {
+ 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);
+ }
}
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-02 16:42:32 UTC (rev 3227)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-04-02 16:42:38 UTC (rev 3228)
@@ -93,7 +93,7 @@
<action name="modification/*"
class="org.chorem.pollen.ui.actions.poll.EditPoll">
<param name="uriId">{1}</param>
- <result name="input">/WEB-INF/jsp/poll/edit.jsp</result>
+ <result name="input">/WEB-INF/jsp/poll/create.jsp</result>
<result>/WEB-INF/jsp/poll/resume.jsp</result>
</action>
1
0
r3227 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll resources/i18n webapp/WEB-INF/jsp/poll
by fdesbois@users.chorem.org 02 Apr '12
by fdesbois@users.chorem.org 02 Apr '12
02 Apr '12
Author: fdesbois
Date: 2012-04-02 18:42:32 +0200 (Mon, 02 Apr 2012)
New Revision: 3227
Url: http://chorem.org/repositories/revision/pollen/3227
Log:
Vote validation for maxChoiceNb and percentage
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-04-02 16:42:25 UTC (rev 3226)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-04-02 16:42:32 UTC (rev 3227)
@@ -32,6 +32,7 @@
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.Vote;
+import org.chorem.pollen.business.persistence.VoteToChoice;
/**
* Votes to a poll.
@@ -75,6 +76,29 @@
addFieldError("pollAccount.votingId", _("pollen.error.user.alreadyVoted"));
}
}
+
+
+ int nbVotes = 0;
+ int totalValues = 0;
+ for (VoteToChoice voteToChoice : vote.getChoiceVoteToChoice()) {
+
+ Integer value = voteToChoice.getVoteValue();
+ if (value != null && value != 0) {
+ nbVotes++;
+ totalValues += value;
+ }
+ }
+
+ // check that the number of choices is not greater than maxChoiceNb
+ int maxChoice = getPoll().getMaxChoiceNb();
+ if (maxChoice != 0 && nbVotes > maxChoice) {
+ addFieldError("vote.choices", _("pollen.error.vote.maxChoiceNb", maxChoice));
+ }
+
+ // check for percentage that the sum of all values equals 100
+ if (isPercentageVoteCounting() && totalValues != 100) {
+ addFieldError("vote.choices", _("pollen.error.vote.percentage"));
+ }
}
@Override
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-04-02 16:42:25 UTC (rev 3226)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-04-02 16:42:32 UTC (rev 3227)
@@ -161,6 +161,8 @@
pollen.error.user.not.found=User not found
pollen.error.user.restrictedListsForbidden=The poll is restricted and you are not allowed to vote. Check if you have correctly used the link sent to you by email.
pollen.error.userNotAllowed=You are not allowed to count the votes for this poll.
+pollen.error.vote.maxChoiceNb=The maximal number of choices is %d.
+pollen.error.vote.percentage=The sum of the values must be equals to 100.
pollen.fieldset.connexionInformation=Connexion informations
pollen.fieldset.login=Login
pollen.fieldset.poll.choices=Choices
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-04-02 16:42:25 UTC (rev 3226)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-04-02 16:42:32 UTC (rev 3227)
@@ -168,6 +168,8 @@
pollen.error.user.not.found=Utilisateur non trouvé
pollen.error.user.restrictedListsForbidden=Le sondage est restreint et vous n'êtes pas autorisé à voter. Vérifiez que vous avez bien utiliser le lien qui vous a été envoyé.
pollen.error.userNotAllowed=Vous n'êtes pas autorisé à dépouiller ce sondage.
+pollen.error.vote.maxChoiceNb=Le nombre de choix maximal est de %d.
+pollen.error.vote.percentage=La somme des valeurs doit être égale à 100.
pollen.fieldset.connexionInformation=Information de connexion
pollen.fieldset.login=Connexion
pollen.fieldset.poll.choices=Les choix
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-04-02 16:42:25 UTC (rev 3226)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-04-02 16:42:32 UTC (rev 3227)
@@ -413,7 +413,8 @@
</table>
<div id="voteError">
<s:fielderror fieldName="pollAccount.votingId"/>
- <%--<t:errors/>--%>
+ <s:fielderror fieldName="vote.choices"/>
+ <%--<t:errors/>--%>
</div>
<s:if test="voteAllowed">
1
0
r3226 - in branches/pollen-1.2.6-struts2: pollen-persistence/src/main/java/org/chorem/pollen/business/persistence pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions pollen-ui-struts2/src/main/webapp/WEB-INF/decorators pollen-ui-struts2/src/main/webapp/css
by fdesbois@users.chorem.org 02 Apr '12
by fdesbois@users.chorem.org 02 Apr '12
02 Apr '12
Author: fdesbois
Date: 2012-04-02 18:42:25 +0200 (Mon, 02 Apr 2012)
New Revision: 3226
Url: http://chorem.org/repositories/revision/pollen/3226
Log:
- missing has methods for messages
- do not use <s:actionmessage/> and <s:actionerror/> struts tags
- problem with some poll flags
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-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.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/css/common.css
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-02 09:44:30 UTC (rev 3225)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java 2012-04-02 16:42:25 UTC (rev 3226)
@@ -71,7 +71,7 @@
@Override
public boolean isFinished(Date currentDate) {
- return endDate != null && endDate.after(currentDate);
+ return endDate != null && currentDate.after(endDate);
}
@Override
@@ -81,7 +81,7 @@
@Override
public boolean isAddChoiceRunning(Date currentDate) {
- return isAddChoiceStarted(currentDate) && !isAddChoiceFinished(currentDate);
+ return !isClosed() && !isFinished(currentDate) && isAddChoiceStarted(currentDate) && !isAddChoiceFinished(currentDate);
}
@Override
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-04-02 09:44:30 UTC (rev 3225)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-04-02 16:42:25 UTC (rev 3226)
@@ -25,6 +25,7 @@
import com.google.common.collect.Lists;
import com.opensymphony.xwork2.ActionContext;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.struts2.StrutsStatics;
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.business.persistence.UserAccount;
@@ -78,7 +79,7 @@
return getPollenApplicationContext().getConfiguration();
}
- /** Pollen User session. */
+ /** Pollen User getPollenSession(). */
private transient PollenSession pollenSession;
/**
@@ -234,9 +235,9 @@
@Override
public void addActionMessage(String message) {
- List<String> messages = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_MESSAGES);
+ List<String> messages = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_MESSAGES);
if (messages == null) {
- messages = Lists.newArrayList(message);
+ messages = Lists.newArrayList(message);
getPollenSession().putDynamicData(PollenSession.SESSION_TOKEN_MESSAGES, messages);
} else {
messages.add(message);
@@ -255,24 +256,36 @@
}
@Override
- public Collection<String> getActionErrors() {
- List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_ERRORS);
- if (result != null) {
- getPollenSession().removeDynamicData(PollenSession.SESSION_TOKEN_ERRORS);
+ public Collection<String> getActionMessages() {
+ List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_MESSAGES);
+ if (result == null) {
+ result = Collections.emptyList();
} else {
- result = Collections.emptyList();
+ getPollenSession().removeDynamicData(PollenSession.SESSION_TOKEN_MESSAGES);
}
return result;
}
@Override
- public Collection<String> getActionMessages() {
- List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_MESSAGES);
- if (result != null) {
- getPollenSession().removeDynamicData(PollenSession.SESSION_TOKEN_MESSAGES);
- } else {
+ public Collection<String> getActionErrors() {
+ List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_ERRORS);
+ if (result == null) {
result = Collections.emptyList();
+ } else {
+ getPollenSession().removeDynamicData(PollenSession.SESSION_TOKEN_ERRORS);
}
return result;
}
+
+ @Override
+ public boolean hasActionMessages() {
+ List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_MESSAGES);
+ return CollectionUtils.isNotEmpty(result);
+ }
+
+ @Override
+ public boolean hasActionErrors() {
+ List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_ERRORS);
+ return CollectionUtils.isNotEmpty(result);
+ }
}
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-02 09:44:30 UTC (rev 3225)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp 2012-04-02 16:42:25 UTC (rev 3226)
@@ -245,14 +245,22 @@
<%--<div t:type="nuiton/feedback" t:id="borderFeedback" t:autoClear="false"/>--%>
<s:if test="hasActionMessages()">
- <div class="fb-info">
- <s:actionmessage/>
+ <div class="info_success">
+ <ul class="actionMessages">
+ <s:iterator value="actionMessages" var="message">
+ <li><span><s:property value="#message" escapeHtml="false"/></span></li>
+ </s:iterator>
+ </ul>
</div>
</s:if>
<s:if test="hasActionErrors()">
- <div class="fb-error">
- <s:actionerror/>
+ <div class="info_error">
+ <ul class="actionErrors">
+ <s:iterator value="actionErrors" var="message">
+ <li><span><s:property value="#message" escapeHtml="false"/></span></li>
+ </s:iterator>
+ </ul>
</div>
</s:if>
<d:body/>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/css/common.css
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/css/common.css 2012-04-02 09:44:30 UTC (rev 3225)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/css/common.css 2012-04-02 16:42:25 UTC (rev 3226)
@@ -111,7 +111,7 @@
.info_success {
background: no-repeat scroll 8px 5px #DFFFDF;
border: 2px solid #9FCF9F;
- width: 800px;
+ width: 970px;
margin-bottom: 5px;
}
.info_success ul{
@@ -130,7 +130,7 @@
.info_error {
background: no-repeat scroll 8px 5px #FFE3E3;
border: 2px solid #DD0000;
- width: 800px;
+ width: 970px;
margin-bottom: 5px;
}
.info_error ul{
1
0