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
r3225 - branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen
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 11:44:30 +0200 (Mon, 02 Apr 2012)
New Revision: 3225
Url: http://chorem.org/repositories/revision/pollen/3225
Log:
Use author for commentDTO xml export
Modified:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java 2012-04-02 09:44:26 UTC (rev 3224)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java 2012-04-02 09:44:30 UTC (rev 3225)
@@ -116,7 +116,7 @@
@Override
public CommentDTO apply(Comment input) {
CommentDTO result = new CommentDTO(
- input.getPollAccount().getVotingId(), input.getText());
+ input.getAuthor(), input.getText());
return result;
}
};
1
0
r3224 - branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl
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 11:44:26 +0200 (Mon, 02 Apr 2012)
New Revision: 3224
Url: http://chorem.org/repositories/revision/pollen/3224
Log:
Use comment author for feed
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-04-02 09:29:44 UTC (rev 3223)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-04-02 09:44:26 UTC (rev 3224)
@@ -117,9 +117,8 @@
public void onAddComment(Comment comment, String pollVoteUrl) {
- //TODO Validate this is ok
String title = _("pollen.feed.addCommentTitle",
- comment.getPollAccount().getVotingId());
+ comment.getAuthor());
String content = _("pollen.feed.addCommentContent",
comment.getText());
1
0
Author: fdesbois
Date: 2012-04-02 11:29:44 +0200 (Mon, 02 Apr 2012)
New Revision: 3223
Url: http://chorem.org/repositories/revision/pollen/3223
Log:
- add comment author new column
- improve pollAccount link with comment
- add comment validation in action instead of xml
Removed:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml
Modified:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.zargo
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.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/confirmDeletePollComment.jsp
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-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java 2012-04-02 09:29:31 UTC (rev 3222)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java 2012-04-02 09:29:44 UTC (rev 3223)
@@ -82,8 +82,20 @@
// add foreign key indexes
addForeignKeyIndexes(queries);
+
+ // add author column for Comment
+ addCommentAuthorColumn(queries);
}
+
+ private void addCommentAuthorColumn(List<String> queries) {
+ queries.add("ALTER TABLE comment ADD COLUMN author VARCHAR(255);");
+
+ queries.add("UPDATE comment c SET c.author = (SELECT p.votingId FROM pollAccount p WHERE c.pollAccount = p.topiaId);");
+
+ queries.add("ALTER TABLE comment ALTER COLUMN author VARCHAR(255) NOT NULL;");
+ }
+
private void addForeignKeyIndexes(List<String> queries) {
queries.add("CREATE INDEX idx_PollAccount_pollsCreated ON poll(creator);");
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-04-02 09:29:31 UTC (rev 3222)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-04-02 09:29:44 UTC (rev 3223)
@@ -29,7 +29,6 @@
import org.chorem.pollen.business.persistence.CommentDAO;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
-import org.chorem.pollen.business.persistence.PollAccountDAO;
import org.chorem.pollen.business.persistence.PollDAO;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.services.PollenServiceSupport;
@@ -52,31 +51,42 @@
Preconditions.checkNotNull(poll);
PollDAO pollDAO = getDAO(Poll.class);
- PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
CommentDAO dao = getDAO(Comment.class);
try {
- // creates poll account
- PollAccount pollAccountCreated =
- pollAccountDAO.create(comment.getPollAccount());
-
// get last version of the poll
Poll pollToUpdate = pollDAO.findByTopiaId(poll.getTopiaId());
// creates the poll comment
Comment commentCreated = dao.create(
- Comment.PROPERTY_POLL_ACCOUNT, pollAccountCreated,
Comment.PROPERTY_POLL, pollToUpdate,
Comment.PROPERTY_POST_DATE, comment.getPostDate(),
+ Comment.PROPERTY_AUTHOR, comment.getAuthor(),
Comment.PROPERTY_TEXT, comment.getText()
);
// add it to poll
pollToUpdate.addComment(commentCreated);
- commitTransaction("Could not create comment " + comment.getText());
+ // attach poll account if exists
+ PollAccount pollAccount = comment.getPollAccount();
+ if (pollAccount.getTopiaId() != null) {
+ PollAccount pollAccountLoaded = getEntityById(PollAccount.class, pollAccount.getTopiaId());
+
+ // attach the userAccount
+ if (pollAccountLoaded.getUserAccount() == null && pollAccount.getUserAccount() != null) {
+ String userId = pollAccount.getUserAccount().getTopiaId();
+ UserAccount userAccountLoaded = getEntityById(UserAccount.class, userId);
+ pollAccountLoaded.setUserAccount(userAccountLoaded);
+ }
+
+ commentCreated.setPollAccount(pollAccountLoaded);
+ }
+
+ commitTransaction("Could not create comment (" + comment.getAuthor() + ") " + comment.getText());
+
// feed notification
PollService pollService = newService(PollService.class);
@@ -105,7 +115,6 @@
throw new PollCommentNotFound();
}
- //FIXME Should we also delete the associated pollAccount ?
dao.delete(comment);
commitTransaction("Could not delete comment " + comment.getText());
@@ -115,7 +124,7 @@
}
}
- public Comment getNewComment(PollAccount account, String text) {
+ public Comment getNewComment(PollAccount account, String author, String text) {
CommentDAO dao = getDAO(Comment.class);
Comment result = newInstance(dao);
@@ -123,49 +132,35 @@
if (account != null) {
result.setPollAccount(account);
}
+ result.setAuthor(author);
result.setText(text);
result.setPostDate(serviceContext.getCurrentTime());
return result;
}
- public PollAccount getNewPollAccount(UserAccount user, String votingId) {
- PollAccountDAO dao = getDAO(PollAccount.class);
- PollAccount result = newInstance(dao);
- if (user != null) {
- result.setVotingId(user.getDisplayName());
- result.setAccountId(serviceContext.createPollenUrlId());
- result.setEmail(user.getEmail());
- result.setUserAccount(user);
- }
- if (votingId != null) {
- result.setVotingId(votingId);
- }
- return result;
- }
-
public boolean isCanDeleteComment(Comment comment,
+ PollAccount pollAccount,
UserAccount userAccount) {
- boolean result = false;
+ boolean result;
+ PollAccount commentAccount = comment.getPollAccount();
+
+ // loggued
if (userAccount != null) {
- // loggued
+ boolean isAdmin = userAccount.isAdministrator();
+ boolean isCommentAccount = userAccount.equals(commentAccount.getUserAccount());
- if (userAccount.isAdministrator()) {
+ result = isAdmin || isCommentAccount;
- // administrator can always delete everything
- result = true;
+ } else if (pollAccount != null) {
- } else {
+ result = pollAccount.equals(commentAccount);
- PollAccount pollAccount = comment.getPollAccount();
- if (userAccount.equals(pollAccount.getUserAccount())) {
- result = true;
- }
- }
+ } else {
+ result = false;
}
-
return result;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-04-02 09:29:31 UTC (rev 3222)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-04-02 09:29:44 UTC (rev 3223)
@@ -117,6 +117,7 @@
UserAccount userAccount) {
Set<String> result = Sets.newHashSet();
boolean canDelete = pollService.isCanDeleteComment(comment,
+ null,
userAccount);
if (canDelete) {
result.add("delete");
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-04-02 09:29:31 UTC (rev 3222)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-04-02 09:29:44 UTC (rev 3223)
@@ -39,6 +39,7 @@
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
+import org.chorem.pollen.services.exceptions.PollAccountNotFound;
import org.chorem.pollen.services.exceptions.PollNotFoundException;
import org.chorem.pollen.services.impl.PollCommentService;
import org.chorem.pollen.services.impl.PollFeedService;
@@ -70,6 +71,8 @@
private transient PollService pollService;
private transient VoteService voteService;
+
+ private transient PollCommentService pollCommentService;
private Poll poll;
@@ -87,7 +90,7 @@
private Vote vote;
- private String commentName;
+ private String commentAuthor;
private String voteSizeMessage;
@@ -123,6 +126,13 @@
return voteService;
}
+ protected PollCommentService getPollCommentService() {
+ if (pollCommentService == null) {
+ pollCommentService = newService(PollCommentService.class);
+ }
+ return pollCommentService;
+ }
+
@Override
public void setParameters(Map<String, String[]> parameters) {
this.parameters = parameters;
@@ -248,19 +258,19 @@
return poll.getEndDate() != null && poll.getEndDate().before(now);
}
- public String getCommentName() {
- return commentName;
+ public String getCommentAuthor() {
+ if (commentAuthor == null) {
+ // Use current pollAccount name for comment
+ commentAuthor = getPollAccount().getVotingId();
+ }
+ return commentAuthor;
}
- public void setCommentName(String commentName) {
- this.commentName = commentName;
+ public void setCommentAuthor(String commentAuthor) {
+ this.commentAuthor = commentAuthor;
}
-
- public void resetCommentName() {
- setCommentName(getPollAccount().getVotingId());
- }
- public void prepareVotePage() throws Exception {
+ public String prepareVotePage() throws Exception {
loadPoll();
@@ -269,7 +279,7 @@
DateFormat.SHORT, getLocale()));
// Current poll account
- pollAccount = getPollService().getPollAccountEditable(getAccountId(), getPollenUserAccount(), poll);
+ loadPollAccount();
// All votes
// TODO no pagination for the moment, need to retrieve the correct page depends on current pollAccount
@@ -309,8 +319,6 @@
creatorUser = getPollenUserAccount() != null &&
getPollenUserAccount().equals(poll.getCreator().getUserAccount());
- resetCommentName();
-
if (log.isInfoEnabled()) {
Date now = serviceContext.getCurrentTime();
log.info("pollChoiceOrVoteStarted = " + isPollChoiceOrVoteStarted());
@@ -319,6 +327,7 @@
log.info("accountFieldDisplayed = " + isAccountFieldDisplayed());
log.info("creatorUser = " + creatorUser);
}
+ return INPUT;
}
public String getResultValue(Choice choice) {
@@ -362,6 +371,10 @@
return getVoteService().isVoteAllowed(getPoll(), getPollAccount());
}
+ public boolean isDeleteCommentAllowed(Comment comment) {
+ return isCreatorUser() || getPollCommentService().isCanDeleteComment(comment, getPollAccount(), getPollenUserAccount());
+ }
+
public String escapeLineBreak(String text) {
return text;
}
@@ -370,6 +383,12 @@
return formatDate(new Date(Long.valueOf(choice.getName())));
}
+ protected void loadPollAccount() throws PollAccountNotFound {
+
+ // Current poll account
+ pollAccount = getPollService().getPollAccountEditable(getAccountId(), getPollenUserAccount(), poll);
+ }
+
protected void loadPoll() throws PollNotFoundException {
// Ensure uri for poll and pollAccount loading
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-04-02 09:29:31 UTC (rev 3222)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-04-02 09:29:44 UTC (rev 3223)
@@ -23,11 +23,10 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import com.google.common.base.Preconditions;
+import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
+import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.business.persistence.Comment;
-import org.chorem.pollen.business.persistence.PollAccount;
-import org.chorem.pollen.services.impl.PollCommentService;
/**
* To add a poll comment.
@@ -35,43 +34,50 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
-public class AddComment extends AbstractVoteAction {
+public class AddComment extends AbstractVoteAction implements Preparable {
private static final long serialVersionUID = 1L;
+
+ private String commentText;
- /** Text of the comment. */
- protected String commentText;
+ public void setCommentText(String commentText) {
+ this.commentText = commentText;
+ }
public String getCommentText() {
return commentText;
}
- public void setCommentText(String commentText) {
- this.commentText = commentText;
+ @Override
+ public void prepare() throws Exception {
+
+ loadPoll();
+ loadPollAccount();
}
- @InputConfig(methodName = "prepareVotePage")
@Override
- public String execute() throws Exception {
+ public void validate() {
- loadPoll();
+ if (StringUtils.isBlank(getCommentAuthor())) {
+ addFieldError("commentAuthor", _("pollen.error.comment.name.empty"));
+ }
- Preconditions.checkNotNull(getCommentName());
- Preconditions.checkNotNull(getCommentText());
+ if (StringUtils.isBlank(getCommentText())) {
+ addFieldError("commentText", _("pollen.error.comment.text.empty"));
+ }
+ }
- PollCommentService service = newService(PollCommentService.class);
+ @InputConfig(methodName = "prepareVotePage")
+ @Override
+ public String execute() throws Exception {
- // prepare a new poll account for the comment
- PollAccount pollAccount = service.getNewPollAccount(
- getPollenUserAccount(), getCommentName());
-
// prepare a new comment
- Comment comment = service.getNewComment(pollAccount, getCommentText());
+ Comment comment = getPollCommentService().getNewComment(
+ getPollAccount(), getCommentAuthor(), getCommentText());
// create the comment
- service.createComment(getPoll(), comment);
+ getPollCommentService().createComment(getPoll(), comment);
return SUCCESS;
}
-
}
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 09:29:31 UTC (rev 3222)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-04-02 09:29:44 UTC (rev 3223)
@@ -53,7 +53,7 @@
pollen.common.choice.date=Date
pollen.common.choice.image=Image
pollen.common.choice.text=Label
-pollen.common.commentName=Name
+pollen.common.commentAuthor=Name
pollen.common.commentText=Comment
pollen.common.comments=Comments about this poll
pollen.common.csvImport=CSV import
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 09:29:31 UTC (rev 3222)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-04-02 09:29:44 UTC (rev 3223)
@@ -58,7 +58,7 @@
pollen.common.choice.date=Date
pollen.common.choice.image=Image
pollen.common.choice.text=Libellé
-pollen.common.commentName=Nom
+pollen.common.commentAuthor=Nom
pollen.common.commentText=Commentaire
pollen.common.comments=Commentaire à propos du sondage
pollen.common.csvImport=Import CSV
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml 2012-04-02 09:29:31 UTC (rev 3222)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/org/chorem/pollen/ui/actions/poll/AddComment-addComment-validation.xml 2012-04-02 09:29:44 UTC (rev 3223)
@@ -1,46 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- #%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%
- -->
-
-
-<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN"
- "http://www.opensymphony.com/xwork/xwork-validator-1.0.3.dtd">
-
-<validators>
-
- <field name="commentName">
-
- <field-validator type="requiredstring">
- <message key="pollen.error.comment.name.empty"/>
- </field-validator>
- </field>
-
- <field name="commentText">
-
- <field-validator type="requiredstring">
- <message key="pollen.error.comment.text.empty"/>
- </field-validator>
- </field>
-
-</validators>
\ No newline at end of file
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollComment.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollComment.jsp 2012-04-02 09:29:31 UTC (rev 3222)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollComment.jsp 2012-04-02 09:29:44 UTC (rev 3223)
@@ -33,8 +33,8 @@
<s:textfield key='comment.postDate' readonly="true" size="50"
label="%{getText('pollen.common.postDate')}"/>
- <s:textfield key='comment.pollAccount.votingId' readonly="true" size="50"
- label="%{getText('pollen.common.commentName')}"/>
+ <s:textfield key='comment.author' readonly="true" size="50"
+ label="%{getText('pollen.common.commentAuthor')}"/>
<s:textarea key='comment.text' readonly="true" rows="3"
label="%{getText('pollen.common.commentText')}"/>
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 09:29:31 UTC (rev 3222)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-04-02 09:29:44 UTC (rev 3223)
@@ -472,7 +472,7 @@
<s:if test="#status.even">class="even"</s:if>
<s:else>class="odd"</s:else>
>
- <s:if test="creatorUser">
+ <s:if test="isDeleteCommentAllowed(#comment)">
<span class="cmd">
<s:a href="#"
onclick="return openDeleteCommentDialog('%{#comment.topiaId}');">
@@ -482,7 +482,7 @@
</s:a>
</span>
</s:if>
- <span class="name"><s:property value='pollAccount.votingId'/></span> :
+ <span class="name"><s:property value='#comment.author'/></span> :
<span class="date">
<s:property value='%{formatDateTime(postDate)}'/>
</span>
@@ -530,8 +530,8 @@
<div id="commentFormDiv">
<s:form id='addCommentForm' method="POST" namespace="/poll" validate="true">
- <s:textfield key="commentName" required="true" size="78"
- label="%{getText('pollen.common.commentName')}"/>
+ <s:textfield key="commentAuthor" required="true" size="78"
+ label="%{getText('pollen.common.commentAuthor')}"/>
<s:textarea key="commentText" required="true" value=''
label="%{getText('pollen.common.commentText')}"/>
1
0
r3222 - in branches/pollen-1.2.6-struts2: pollen-services/src/main/java/org/chorem/pollen/bean pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors pollen-ui-struts2/src/main/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 11:29:31 +0200 (Mon, 02 Apr 2012)
New Revision: 3222
Url: http://chorem.org/repositories/revision/pollen/3222
Log:
- resolve issue with ChoiceType in createPoll prepare
- resolve issue with image upload (no params before prepare). Use new FileUploadAware interface.
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/FileUploadAware.java
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/PollDateChoice.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollImageChoice.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/CreatePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenFileUploadInterceptor.java
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-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-03-30 10:32:15 UTC (rev 3221)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java 2012-04-02 09:29:31 UTC (rev 3222)
@@ -8,6 +8,9 @@
import java.util.Date;
/**
+ * Used to manage all objects from {@link Choice} inheritance tree depends
+ * on {@link ChoiceType}.
+ * <p/>
* Created: 30/03/12
*
* @author fdesbois <desbois(a)codelutin.com>
@@ -55,5 +58,21 @@
ChoiceType choiceType) {
return Iterables.transform(choices, toValue(choiceType));
}
+
+ public static String getValuePropertyName(ChoiceType choiceType) {
+ String result;
+ switch (choiceType) {
+ case DATE:
+ result = PollDateChoice.PROPERTY_DATE;
+ break;
+ case IMAGE:
+ result = PollImageChoice.PROPERTY_LOCATION;
+ break;
+ case TEXT:
+ default:
+ result = Choice.PROPERTY_NAME;
+ }
+ return result;
+ }
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollDateChoice.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollDateChoice.java 2012-03-30 10:32:15 UTC (rev 3221)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollDateChoice.java 2012-04-02 09:29:31 UTC (rev 3222)
@@ -39,6 +39,8 @@
private static final long serialVersionUID = 1L;
+ public static final String PROPERTY_DATE = "date";
+
protected Date date;
public Date getDate() {
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollImageChoice.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollImageChoice.java 2012-03-30 10:32:15 UTC (rev 3221)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollImageChoice.java 2012-04-02 09:29:31 UTC (rev 3222)
@@ -36,6 +36,8 @@
public class PollImageChoice extends ChoiceImpl {
private static final long serialVersionUID = 1L;
+
+ public static final String PROPERTY_LOCATION = "location";
protected String location;
Added: 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 (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/FileUploadAware.java 2012-04-02 09:29:31 UTC (rev 3222)
@@ -0,0 +1,18 @@
+package org.chorem.pollen.ui.actions;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Created: 30/03/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ */
+public interface FileUploadAware {
+
+ void setFiles(String paramName, List<File> files);
+
+ void setFileContentTypes(String paramName, List<String> contentTypes);
+
+ void setFileNames(String paramName, List<String> fileNames);
+}
Modified: 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/AddChoice.java 2012-03-30 10:32:15 UTC (rev 3221)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java 2012-04-02 09:29:31 UTC (rev 3222)
@@ -24,37 +24,94 @@
package org.chorem.pollen.ui.actions.poll;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.bean.ChoiceHelper;
+import org.chorem.pollen.bean.PollImageChoice;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.services.exceptions.PollNotFoundException;
+import org.chorem.pollen.ui.actions.FileUploadAware;
+import java.io.File;
+import java.util.List;
+
/**
* To add a poll comment.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
-public class AddChoice extends AbstractVoteAction implements Preparable {
+public class AddChoice extends AbstractVoteAction implements Preparable, FileUploadAware {
private static final long serialVersionUID = 1L;
protected Choice choice;
+ private List<File> imageChoices;
+
+ private List<String> imageChoiceContentTypes;
+
+ private List<String> imageChoiceFileNames;
+
public Choice getChoice() {
return choice;
}
@Override
+ public void setFiles(String paramName, List<File> files) {
+ this.imageChoices = Lists.newArrayList(files);
+ }
+
+ @Override
+ public void setFileContentTypes(String paramName, List<String> contentTypes) {
+ this.imageChoiceContentTypes = Lists.newArrayList(contentTypes);
+ }
+
+ @Override
+ public void setFileNames(String paramName, List<String> fileNames) {
+ this.imageChoiceFileNames = Lists.newArrayList(fileNames);
+ }
+
+ public List<File> getImageChoices() {
+ if (imageChoices == null) {
+ imageChoices = Lists.newArrayList();
+ }
+ return imageChoices;
+ }
+
+ public List<String> getImageChoiceContentTypes() {
+ if (imageChoiceContentTypes == null) {
+ imageChoiceContentTypes = Lists.newArrayList();
+ }
+ return imageChoiceContentTypes;
+ }
+
+ public List<String> getImageChoiceFileNames() {
+ if (imageChoiceFileNames == null) {
+ imageChoiceFileNames = Lists.newArrayList();
+ }
+ return imageChoiceFileNames;
+ }
+
+ @Override
public void prepare() throws PollNotFoundException {
loadPoll();
ChoiceType choiceType = getPoll().getChoiceType();
choice = getPollService().getNewChoice(choiceType);
+
+ // Push image choice data from uploaded file
+ if (ChoiceType.IMAGE == choiceType && getImageChoices().size() == 1) {
+
+ String fileName = getImageChoiceFileNames().get(0);
+ String location = getImageChoices().get(0).getAbsolutePath();
+ choice.setName(fileName);
+ ((PollImageChoice)choice).setLocation(location);
+ }
}
@Override
@@ -62,14 +119,14 @@
ChoiceType choiceType = getPoll().getChoiceType();
- String typeKey = choiceType.name().toLowerCase();
+ String propName = ChoiceHelper.getValuePropertyName(choiceType);
Object value = ChoiceHelper.toValue(choice, choiceType);
// -- Validate value notEmpty
if (value == null || (value instanceof String && StringUtils.isBlank((String) value))) {
String typeLabel = getText(choiceType.getI18nKey());
- addFieldError("choice." + typeKey,
+ addFieldError("choice." + propName,
_("pollen.error.choice.empty", typeLabel));
} else {
@@ -78,7 +135,7 @@
// -- Validate value notExists
if (Iterables.contains(pollChoiceValues, value)) {
- addFieldError("choice." + typeKey,
+ addFieldError("choice." + propName,
_("pollen.error.poll.detected.duplicate.choice.name"));
}
}
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-03-30 10:32:15 UTC (rev 3221)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-04-02 09:29:31 UTC (rev 3222)
@@ -54,6 +54,7 @@
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;
@@ -73,7 +74,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
-public class CreatePoll extends PollenActionSupport implements Preparable, ParameterAware {
+public class CreatePoll extends PollenActionSupport implements Preparable, ParameterAware, FileUploadAware {
private static final long serialVersionUID = 1L;
@@ -235,6 +236,21 @@
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();
@@ -242,10 +258,6 @@
return imageChoice;
}
- public void setImageChoice(int index, File imageChoice) {
- addtoList(getImageChoice(), index, imageChoice);
- }
-
public List<String> getImageChoiceContentType() {
if (imageChoiceContentType == null) {
imageChoiceContentType = Lists.newArrayList();
@@ -260,14 +272,6 @@
return imageChoiceFileName;
}
- public void setImageChoiceContentType(int index, String imageChoiceContentType) {
- addtoList(getImageChoiceContentType(), index, imageChoiceContentType);
- }
-
- public void setImageChoiceFileName(int index, String imageChoiceFileName) {
- addtoList(getImageChoiceFileName(), index, imageChoiceFileName);
- }
-
public boolean isInformationsError() {
return informationsError;
}
@@ -333,10 +337,15 @@
imageChoiceTokenId = DisplayImageChoice.CHOICE_TOKEN + "_" +
tokenSuffix;
- ChoiceType pollChoiceType = getPoll().getChoiceType();
- if (pollChoiceType == null) {
- // Retrieve choiceType from parameters, the poll object will be updated after prepare
- String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType");
+ 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);
}
@@ -811,7 +820,7 @@
Matcher matcher = IMAGE_CHOICE_NAME_PATTERN.matcher(paramName);
if (matcher.matches()) {
- // found a text choice name
+ // found an image choice name
String paramValue = getNonEmptyParameterValue(paramName);
if (paramValue != null) {
@@ -1114,7 +1123,7 @@
private String getNonEmptyParameterValue(String paramName) {
String[] paramValues = parameters.get(paramName);
String result = null;
- if (paramValues.length == 1) {
+ if (paramValues != null && paramValues.length == 1) {
String paramValue = paramValues[0];
if (StringUtils.isNotEmpty(paramValue)) {
result = paramValue;
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenFileUploadInterceptor.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenFileUploadInterceptor.java 2012-03-30 10:32:15 UTC (rev 3221)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenFileUploadInterceptor.java 2012-04-02 09:29:31 UTC (rev 3222)
@@ -31,6 +31,7 @@
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
import org.apache.struts2.interceptor.FileUploadInterceptor;
+import org.chorem.pollen.ui.actions.FileUploadAware;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
@@ -142,11 +143,21 @@
}
if (!acceptedFiles.isEmpty()) {
- Map<String, Object> params = ac.getParameters();
- params.put(inputName, acceptedFiles.toArray(new File[acceptedFiles.size()]));
- params.put(contentTypeName, acceptedContentTypes.toArray(new String[acceptedContentTypes.size()]));
- params.put(fileNameName, acceptedFileNames.toArray(new String[acceptedFileNames.size()]));
+ if (action instanceof FileUploadAware) {
+ FileUploadAware fileUpload = (FileUploadAware) action;
+
+ fileUpload.setFiles(inputName, acceptedFiles);
+ fileUpload.setFileContentTypes(contentTypeName, acceptedContentTypes);
+ fileUpload.setFileNames(fileNameName, acceptedFileNames);
+
+ } else {
+ Map<String, Object> params = ac.getParameters();
+
+ params.put(inputName, acceptedFiles.toArray(new File[acceptedFiles.size()]));
+ params.put(contentTypeName, acceptedContentTypes.toArray(new String[acceptedContentTypes.size()]));
+ params.put(fileNameName, acceptedFileNames.toArray(new String[acceptedFileNames.size()]));
+ }
}
}
} else {
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-03-30 10:32:15 UTC (rev 3221)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-04-02 09:29:31 UTC (rev 3222)
@@ -433,31 +433,26 @@
<!-- Ajout de choix -->
<s:if test="pollChoiceRunning">
<div id="choiceFormDiv">
- <s:form id="choiceForm" method="POST" namespace="/poll">
+ <s:form id="choiceForm" method="POST" namespace="/poll" enctype="multipart/form-data">
<h4><s:text name="pollen.action.addChoice"/></h4>
<s:if test="textType">
<s:textfield key="choice.name"
- label="%{getText('pollen.common.choice')}"
- required="true"/>
+ label="%{getText('pollen.common.choice')}"
+ required="true"/>
</s:if>
- <s:if test="dateType">
- <s:label id="choice.date-label" for="choice.date" key="pollen.common.choice" theme="simple"/>
- <br/>
- <s:fielderror fieldName="choice.date"/>
- <br/>
- <sj:datepicker id="choice.date" name="choice.date" changeMonth="true"
- changeYear="true" labelSeparator="" theme="simple" label=""
- timepicker="true" displayFormat="dd/mm/yy" required="true"/>
- <br/>
- </s:if>
- <s:if test="imageType">
- <s:label id="choice.location-label" for="choice.location" key="pollen.common.choice" theme="simple"/>
- <br/>
- <s:fielderror fieldName="choice.location"/>
- <br/>
- <s:file id="choice.location" name="" label="choice.location" theme="simple" cssClass="nameField" required="true"/>
- <br/>
- </s:if>
+ <s:elseif test="dateType">
+ <sj:datepicker key="choice.date"
+ label="%{getText('pollen.common.choice')}"
+ changeMonth="true" changeYear="true"
+ timepicker="true" displayFormat="dd/mm/yy"
+ required="true"/>
+ </s:elseif>
+ <s:elseif test="imageType">
+ <s:file key="choice.location"
+ label="%{getText('pollen.common.choice')}"
+ cssClass="nameField"
+ required="true"/>
+ </s:elseif>
<br/>
<s:textarea cols="30" key="choice.description"
label="%{getText('pollen.common.description')}"/>
1
0
r3221 - in branches/pollen-1.2.6-struts2: pollen-services/src/main/java/org/chorem/pollen/bean pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll
by fdesbois@users.chorem.org 30 Mar '12
by fdesbois@users.chorem.org 30 Mar '12
30 Mar '12
Author: fdesbois
Date: 2012-03-30 12:32:15 +0200 (Fri, 30 Mar 2012)
New Revision: 3221
Url: http://chorem.org/repositories/revision/pollen/3221
Log:
- resolve issue on create poll with choiceType date and image
- create ChoiceHelper
- improve AddChoice validation
Added:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java
Modified:
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/CreatePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
Added: 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 (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java 2012-03-30 10:32:15 UTC (rev 3221)
@@ -0,0 +1,59 @@
+package org.chorem.pollen.bean;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.common.ChoiceType;
+
+import java.util.Date;
+
+/**
+ * Created: 30/03/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ */
+public final class ChoiceHelper {
+
+ private ChoiceHelper() {
+ }
+
+ public static Object toValue(Choice choice, ChoiceType choiceType) {
+ Object result;
+ switch (choiceType) {
+ case DATE:
+ if (choice instanceof PollDateChoice) {
+ result = ((PollDateChoice)choice).getDate();
+ } else {
+ result = new Date(Long.parseLong(choice.getName()));
+ }
+ break;
+ case IMAGE:
+ if (choice instanceof PollImageChoice) {
+ result = ((PollImageChoice)choice).getLocation();
+ } else {
+ result = choice.getName();
+ }
+ break;
+ case TEXT:
+ default:
+ result = choice.getName();
+ }
+ return result;
+ }
+
+ public static Function<Choice, Object> toValue(final ChoiceType type) {
+ return new Function<Choice, Object>() {
+
+ @Override
+ public Object apply(Choice input) {
+ return toValue(input, type);
+ }
+ };
+ }
+
+ public static Iterable<Object> toValues(Iterable<Choice> choices,
+ ChoiceType choiceType) {
+ return Iterables.transform(choices, toValue(choiceType));
+ }
+
+}
Modified: 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/AddChoice.java 2012-03-29 15:13:38 UTC (rev 3220)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java 2012-03-30 10:32:15 UTC (rev 3221)
@@ -23,17 +23,15 @@
*/
package org.chorem.pollen.ui.actions.poll;
+import com.google.common.collect.Iterables;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
import org.apache.commons.lang3.StringUtils;
-import org.chorem.pollen.bean.PollDateChoice;
-import org.chorem.pollen.bean.PollImageChoice;
+import org.chorem.pollen.bean.ChoiceHelper;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.services.exceptions.PollNotFoundException;
-import java.util.Date;
-
/**
* To add a poll comment.
*
@@ -63,19 +61,26 @@
public void validate() {
ChoiceType choiceType = getPoll().getChoiceType();
- switch (choiceType) {
- case DATE:
- validateChoiceDate();
- break;
+ String typeKey = choiceType.name().toLowerCase();
+
+ Object value = ChoiceHelper.toValue(choice, choiceType);
- case IMAGE:
- validateChoiceImage();
- break;
+ // -- Validate value notEmpty
+ if (value == null || (value instanceof String && StringUtils.isBlank((String) value))) {
+ String typeLabel = getText(choiceType.getI18nKey());
+ addFieldError("choice." + typeKey,
+ _("pollen.error.choice.empty", typeLabel));
+ } else {
- case TEXT:
- default:
- validateChoice();
+ // Retrieve existing values to check if the new choice not already exists
+ Iterable<Object> pollChoiceValues = ChoiceHelper.toValues(getPoll().getChoice(), choiceType);
+
+ // -- Validate value notExists
+ if (Iterables.contains(pollChoiceValues, value)) {
+ addFieldError("choice." + typeKey,
+ _("pollen.error.poll.detected.duplicate.choice.name"));
+ }
}
}
@@ -88,25 +93,4 @@
return SUCCESS;
}
- protected void validateChoiceDate() {
- Date date = ((PollDateChoice) choice).getDate();
- if (date == null) {
- addFieldError("choice.date", _("pollen.error.choice.empty", _("pollen.common.choice.date")));
- }
- }
-
- protected void validateChoiceImage() {
- String location = ((PollImageChoice) choice).getLocation();
- if (StringUtils.isBlank(location)) {
- addFieldError("choice.image", _("pollen.error.choice.empty", _("pollen.common.choice.image")));
- }
- }
-
- protected void validateChoice() {
- String name = choice.getName();
- if (StringUtils.isBlank(name)) {
- addFieldError("choice.text", _("pollen.error.choice.empty", _("pollen.common.choice.text")));
- }
- }
-
}
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-03-29 15:13:38 UTC (rev 3220)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-03-30 10:32:15 UTC (rev 3221)
@@ -34,6 +34,7 @@
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;
@@ -333,6 +334,11 @@
tokenSuffix;
ChoiceType pollChoiceType = getPoll().getChoiceType();
+ if (pollChoiceType == null) {
+ // Retrieve choiceType from parameters, the poll object will be updated after prepare
+ String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType");
+ pollChoiceType = ChoiceType.valueOf(choiceTypeParam);
+ }
if (log.isInfoEnabled()) {
log.info("choice type " + pollChoiceType);
@@ -387,19 +393,29 @@
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"));
+// }
- //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) {
+ 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"));
}
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-03-29 15:13:38 UTC (rev 3220)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-30 10:32:15 UTC (rev 3221)
@@ -47,10 +47,9 @@
private static final long serialVersionUID = 1L;
@Override
- public String input() throws Exception {
+ public void prepare() throws Exception {
- //TODO DO me!
- return INPUT;
+ prepareVotePage();
}
@Override
@@ -117,10 +116,4 @@
}
return SUCCESS;
}
-
- @Override
- public void prepare() throws Exception {
-
- prepareVotePage();
- }
}
1
0
r3220 - 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/jsp/poll
by fdesbois@users.chorem.org 29 Mar '12
by fdesbois@users.chorem.org 29 Mar '12
29 Mar '12
Author: fdesbois
Date: 2012-03-29 17:13:38 +0200 (Thu, 29 Mar 2012)
New Revision: 3220
Url: http://chorem.org/repositories/revision/pollen/3220
Log:
- resolve issues with deleteChoice
- resolve issues with deleteComment
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/DeleteComment.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollChoice.jsp
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-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-03-29 15:13:30 UTC (rev 3219)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-29 15:13:38 UTC (rev 3220)
@@ -647,6 +647,8 @@
}
ChoiceDAO dao = getDAO(Choice.class);
+
+ poll.removeChoice(choice);
delete(dao, choice);
commitTransaction("Could not delete choice " + choice.getName());
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-03-29 15:13:30 UTC (rev 3219)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-03-29 15:13:38 UTC (rev 3220)
@@ -64,7 +64,6 @@
service.deleteComment(commentId);
- resetCommentName();
return SUCCESS;
}
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollChoice.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollChoice.jsp 2012-03-29 15:13:30 UTC (rev 3219)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollChoice.jsp 2012-03-29 15:13:38 UTC (rev 3220)
@@ -28,7 +28,7 @@
<s:form method="POST" namespace="/poll" action="deleteChoice">
<s:hidden key="uriId" label=''/>
- <s:hidden key="choiceId" label=''/>
+ <s:hidden key="choiceId" value="%{choice.topiaId}" label=''/>
<s:text name="pollen.information.confirmDeletePollChoice">
<s:param>
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-03-29 15:13:30 UTC (rev 3219)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-29 15:13:38 UTC (rev 3220)
@@ -199,7 +199,7 @@
</s:else>
<s:if test="pollChoiceRunning">
<s:if test="creatorUser">
- <s:a action="deleteChoice" namespace="/poll">
+ <s:a action="deleteChoice" namespace="/poll" onclick="return openDeleteChoiceDialog('%{#choice.topiaId}');">
<s:param name="choiceId"><s:property value="id"/></s:param>
<img src="<s:url value="/img/delete.png"/>"
title="<s:text name="pollen.action.deleteChoice"/>"
@@ -433,7 +433,7 @@
<!-- Ajout de choix -->
<s:if test="pollChoiceRunning">
<div id="choiceFormDiv">
- <s:form id="choiceForm" method="POST" namespace="/poll" validate="true">
+ <s:form id="choiceForm" method="POST" namespace="/poll">
<h4><s:text name="pollen.action.addChoice"/></h4>
<s:if test="textType">
<s:textfield key="choice.name"
1
0
r3219 - 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/resources/i18n pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll
by fdesbois@users.chorem.org 29 Mar '12
by fdesbois@users.chorem.org 29 Mar '12
29 Mar '12
Author: fdesbois
Date: 2012-03-29 17:13:30 +0200 (Thu, 29 Mar 2012)
New Revision: 3219
Url: http://chorem.org/repositories/revision/pollen/3219
Log:
- add AddChoice action (validation redirection failed)
- missing addChoiceAllowed flag save in createPoll
- resolve issue on AddComment (validation doesn't work)
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java
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/AbstractVoteAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.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/vote.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-03-28 16:40:09 UTC (rev 3218)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-29 15:13:30 UTC (rev 3219)
@@ -124,6 +124,7 @@
result.setAnonymous(poll.isAnonymous());
result.setAnonymousVoteAllowed(poll.isAnonymousVoteAllowed());
+ result.setChoiceAddAllowed(poll.isChoiceAddAllowed());
result.setBeginChoiceDate(poll.getBeginChoiceDate());
result.setBeginDate(poll.getBeginDate());
result.setChoiceType(poll.getChoiceType());
@@ -211,40 +212,42 @@
// create choices
- ChoiceType choiceType = result.getChoiceType();
-
- ChoiceDAO choiceDAO = getDAO(Choice.class);
-
+// ChoiceType choiceType = result.getChoiceType();
+//
+// ChoiceDAO choiceDAO = getDAO(Choice.class);
+//
for (Choice choice : poll.getChoice()) {
- 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());
- }
+ 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());
+// }
}
}
@@ -556,7 +559,79 @@
commitTransaction("Could not close poll " + poll.getTitle());
}
+
+ public Choice getNewChoice(ChoiceType choiceType) {
+ Choice result;
+ switch (choiceType) {
+
+ case DATE:
+ result = new PollDateChoice();
+ break;
+
+ case IMAGE:
+ result = new PollImageChoice();
+ break;
+
+ case TEXT:
+ default:
+ ChoiceDAO dao = getDAO(Choice.class);
+ result = newInstance(dao);
+ }
+ return result;
+ }
+
+ public void createChoice(String pollId, Choice choice) throws PollNotFoundException {
+
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(choice);
+
+ Poll poll = getPollByPollId(pollId);
+
+ if (poll == null) {
+ throw new PollNotFoundException();
+ }
+
+ addChoice(poll, choice);
+
+ commitTransaction("Can't create new choice [" + poll.getChoiceType() + "] for poll '" + pollId + "'");
+ }
+
+ protected void addChoice(Poll poll, Choice choice) {
+
+ ChoiceType choiceType = poll.getChoiceType();
+ ChoiceDAO dao = getDAO(Choice.class);
+ Choice choiceCreated = create(dao);
+ poll.addChoice(choiceCreated);
+ if (choiceType == ChoiceType.IMAGE) {
+
+ // copy image where it belong and generate the thumb
+
+ PollImageChoice imageChoice = (PollImageChoice) choice;
+ imageChoice.toChoice(choiceCreated);
+ try {
+ saveImages(poll, 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());
+ }
+ }
+
public void deleteChoice(String pollId, String choiceId)
throws PollNotFoundException, PollChoiceNotFoundException {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-28 16:40:09 UTC (rev 3218)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-29 15:13:30 UTC (rev 3219)
@@ -262,9 +262,6 @@
public void prepareVotePage() throws Exception {
- // Ensure uri for poll and pollAccount loading
- preparePollUri(parameters);
-
loadPoll();
setDateFormat(DateFormat.getDateTimeInstance(
@@ -374,6 +371,9 @@
}
protected void loadPoll() throws PollNotFoundException {
+
+ // Ensure uri for poll and pollAccount loading
+ preparePollUri(parameters);
String pollId = getPollId();
if (StringUtils.isNotEmpty(pollId)) {
Added: 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/AddChoice.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java 2012-03-29 15:13:30 UTC (rev 3219)
@@ -0,0 +1,112 @@
+/*
+ * #%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 com.opensymphony.xwork2.interceptor.annotations.InputConfig;
+import org.apache.commons.lang3.StringUtils;
+import org.chorem.pollen.bean.PollDateChoice;
+import org.chorem.pollen.bean.PollImageChoice;
+import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.common.ChoiceType;
+import org.chorem.pollen.services.exceptions.PollNotFoundException;
+
+import java.util.Date;
+
+/**
+ * To add a poll comment.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class AddChoice extends AbstractVoteAction implements Preparable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected Choice choice;
+
+ public Choice getChoice() {
+ return choice;
+ }
+
+ @Override
+ public void prepare() throws PollNotFoundException {
+
+ loadPoll();
+
+ ChoiceType choiceType = getPoll().getChoiceType();
+ choice = getPollService().getNewChoice(choiceType);
+ }
+
+ @Override
+ public void validate() {
+
+ ChoiceType choiceType = getPoll().getChoiceType();
+ switch (choiceType) {
+
+ case DATE:
+ validateChoiceDate();
+ break;
+
+ case IMAGE:
+ validateChoiceImage();
+ break;
+
+ case TEXT:
+ default:
+ validateChoice();
+ }
+ }
+
+ @InputConfig(methodName = "prepareVotePage")
+ @Override
+ public String execute() throws Exception {
+
+ getPollService().createChoice(getPollId(), choice);
+
+ return SUCCESS;
+ }
+
+ protected void validateChoiceDate() {
+ Date date = ((PollDateChoice) choice).getDate();
+ if (date == null) {
+ addFieldError("choice.date", _("pollen.error.choice.empty", _("pollen.common.choice.date")));
+ }
+ }
+
+ protected void validateChoiceImage() {
+ String location = ((PollImageChoice) choice).getLocation();
+ if (StringUtils.isBlank(location)) {
+ addFieldError("choice.image", _("pollen.error.choice.empty", _("pollen.common.choice.image")));
+ }
+ }
+
+ protected void validateChoice() {
+ String name = choice.getName();
+ if (StringUtils.isBlank(name)) {
+ addFieldError("choice.text", _("pollen.error.choice.empty", _("pollen.common.choice.text")));
+ }
+ }
+
+}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-03-28 16:40:09 UTC (rev 3218)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-03-29 15:13:30 UTC (rev 3219)
@@ -71,7 +71,6 @@
// create the comment
service.createComment(getPoll(), comment);
- resetCommentName();
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-03-28 16:40:09 UTC (rev 3218)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-29 15:13:30 UTC (rev 3219)
@@ -97,21 +97,6 @@
<result>/WEB-INF/jsp/poll/resume.jsp</result>
</action>
- <!-- vote poll -->
- <action name="vote/*" method="execute"
- class="org.chorem.pollen.ui.actions.poll.VoteForPoll">
- <param name="uriId">{1}</param>
- <result name="input">/WEB-INF/jsp/poll/vote.jsp</result>
- <result type="redirectToVote"/>
- </action>
-
- <!-- vote poll (input) -->
- <action name="votefor/*" method="input"
- class="org.chorem.pollen.ui.actions.poll.VoteForPoll">
- <param name="uriId">{1}</param>
- <result name="input">/WEB-INF/jsp/poll/vote.jsp</result>
- </action>
-
<!-- confirm clone poll -->
<action name="confirmClonePoll/*"
class="org.chorem.pollen.ui.actions.poll.ConfirmPollAction">
@@ -182,9 +167,33 @@
<result>/WEB-INF/jsp/poll/confirmDeletePollComment.jsp</result>
</action>
+ <!-- vote poll -->
+ <action name="vote/*" method="execute"
+ class="org.chorem.pollen.ui.actions.poll.VoteForPoll">
+ <param name="uriId">{1}</param>
+ <result name="input">/WEB-INF/jsp/poll/vote.jsp</result>
+ <result type="redirectToVote"/>
+ </action>
+
+ <!-- vote poll (input) -->
+ <action name="votefor/*" method="input"
+ class="org.chorem.pollen.ui.actions.poll.VoteForPoll">
+ <param name="uriId">{1}</param>
+ <result name="input">/WEB-INF/jsp/poll/vote.jsp</result>
+ </action>
+
+ <!-- add a choice -->
+ <action name="addChoice/*"
+ class="org.chorem.pollen.ui.actions.poll.AddChoice">
+ <param name="uriId">{1}</param>
+ <result name="input">/WEB-INF/jsp/poll/vote.jsp</result>
+ <result type="redirectToVote"/>
+ </action>
+
<!-- add a poll comment -->
- <action name="addComment"
+ <action name="addComment/*"
class="org.chorem.pollen.ui.actions.poll.AddComment">
+ <param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/vote.jsp</result>
<result type="redirectToVote"/>
</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-03-28 16:40:09 UTC (rev 3218)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-29 15:13:30 UTC (rev 3219)
@@ -50,6 +50,9 @@
pollen.common.chartType-pie3d=Pie 3D
pollen.common.chartType-ring=Ring
pollen.common.choice=Choice
+pollen.common.choice.date=Date
+pollen.common.choice.image=Image
+pollen.common.choice.text=Label
pollen.common.commentName=Name
pollen.common.commentText=Comment
pollen.common.comments=Comments about this poll
@@ -116,6 +119,7 @@
pollen.common.votingList=Group
pollen.common.weight=Weight
pollen.error.accountNotFound=
+pollen.error.choice.empty=%s mandatory
pollen.error.comment.name.empty=Comment name mandatory
pollen.error.comment.text.empty=Comment text mandatory
pollen.error.email.required=You must provide an email
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-03-28 16:40:09 UTC (rev 3218)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-29 15:13:30 UTC (rev 3219)
@@ -55,6 +55,9 @@
pollen.common.chartType-pie3d=Camembert 3D
pollen.common.chartType-ring=Anneau
pollen.common.choice=Choix
+pollen.common.choice.date=Date
+pollen.common.choice.image=Image
+pollen.common.choice.text=Libellé
pollen.common.commentName=Nom
pollen.common.commentText=Commentaire
pollen.common.comments=Commentaire à propos du sondage
@@ -123,6 +126,7 @@
pollen.common.weight=Poids
pollen.common.x=Dépouillement
pollen.error.accountNotFound=
+pollen.error.choice.empty=%s obligatoire
pollen.error.comment.name.empty=Nom du commentaire obligatoire
pollen.error.comment.text.empty=Texte du commentaire obligatoire
pollen.error.email.required=Courriel obligatoire
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-03-28 16:40:09 UTC (rev 3218)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-29 15:13:30 UTC (rev 3219)
@@ -423,14 +423,51 @@
<%--<t:label for="anonymousVote"/>--%>
<br/>
</s:if>
- <s:submit action="vote/%{uriId}" key="pollen.action.pollVote"/>
+ <s:submit action="vote/%{uriId}" key="pollen.action.pollVote" align="center"/>
<%--<input id="submitVote" t:type="Submit" t:value="${message:submitVote}"/>--%>
</div>
</s:if>
</s:form>
</div>
+
+<!-- Ajout de choix -->
+<s:if test="pollChoiceRunning">
+ <div id="choiceFormDiv">
+ <s:form id="choiceForm" method="POST" namespace="/poll" validate="true">
+ <h4><s:text name="pollen.action.addChoice"/></h4>
+ <s:if test="textType">
+ <s:textfield key="choice.name"
+ label="%{getText('pollen.common.choice')}"
+ required="true"/>
+ </s:if>
+ <s:if test="dateType">
+ <s:label id="choice.date-label" for="choice.date" key="pollen.common.choice" theme="simple"/>
+ <br/>
+ <s:fielderror fieldName="choice.date"/>
+ <br/>
+ <sj:datepicker id="choice.date" name="choice.date" changeMonth="true"
+ changeYear="true" labelSeparator="" theme="simple" label=""
+ timepicker="true" displayFormat="dd/mm/yy" required="true"/>
+ <br/>
+ </s:if>
+ <s:if test="imageType">
+ <s:label id="choice.location-label" for="choice.location" key="pollen.common.choice" theme="simple"/>
+ <br/>
+ <s:fielderror fieldName="choice.location"/>
+ <br/>
+ <s:file id="choice.location" name="" label="choice.location" theme="simple" cssClass="nameField" required="true"/>
+ <br/>
+ </s:if>
+ <br/>
+ <s:textarea cols="30" key="choice.description"
+ label="%{getText('pollen.common.description')}"/>
+ <br/>
+ <s:submit action="addChoice/%{uriId}" key="pollen.action.addChoice" align="center"/>
+ </s:form>
+ </div>
+</s:if>
+
<!-- Ajout de commentaires -->
-
<h3><s:text name="pollen.common.comments"/></h3>
<div id="commentZone">
@@ -497,16 +534,15 @@
<div id="commentFormDiv">
- <s:form id='addCommentForm' method="POST" namespace="/poll">
- <s:hidden key="uriId" label=''/>
+ <s:form id='addCommentForm' method="POST" namespace="/poll" validate="true">
<s:textfield key="commentName" required="true" size="78"
label="%{getText('pollen.common.commentName')}"/>
<s:textarea key="commentText" required="true" value=''
label="%{getText('pollen.common.commentText')}"/>
<div class="cleanBoth">
- <s:submit action="addComment" key="pollen.action.addComment"
- align="left"/>
+ <s:submit action="addComment/%{uriId}" key="pollen.action.addComment"
+ align="center"/>
</div>
</s:form>
1
0
r3218 - 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/jsp/poll
by fdesbois@users.chorem.org 28 Mar '12
by fdesbois@users.chorem.org 28 Mar '12
28 Mar '12
Author: fdesbois
Date: 2012-03-28 18:40:09 +0200 (Wed, 28 Mar 2012)
New Revision: 3218
Url: http://chorem.org/repositories/revision/pollen/3218
Log:
add voteAllowed check for restricted poll
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
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-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-28 16:40:01 UTC (rev 3217)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-28 16:40:09 UTC (rev 3218)
@@ -169,16 +169,12 @@
// -- PollAccount -- //
PollAccount pollAccount = vote.getPollAccount();
String pollAccountId = pollAccount.getTopiaId();
- PollAccount pollAccountLoaded = null;
+ PollAccount pollAccountLoaded;
// Load existing account (restricted poll)
if (pollAccountId != null) {
pollAccountLoaded = getEntityById(PollAccount.class, pollAccountId);
- if (pollAccountLoaded == null) {
- throw new PollAccountNotFound();
- }
-
// Create new account
} else {
PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
@@ -354,6 +350,36 @@
throw new PollenTechnicalException("Could not obtain votes", e);
}
}
+
+ /**
+ * Vote is allowed if {@code poll} is running and {@code pollAccount} is
+ * defined in the {@code poll} restricted list if it's not a {@link PollType#FREE}
+ * poll. The account must be defined previously using
+ * {@link PollService#getPollAccountEditable(String, UserAccount, Poll)} to
+ * have a proper link between userAccount and pollAccount even if not already
+ * created in dabase.
+ *
+ * @param poll Poll
+ * @param accountEditable Account to check
+ * @return true if vote is allowed, false otherwise
+ */
+ public boolean isVoteAllowed(Poll poll, PollAccount accountEditable) {
+
+ Preconditions.checkNotNull(poll);
+ Preconditions.checkNotNull(accountEditable);
+
+ Date now = serviceContext.getCurrentTime();
+
+ boolean result = poll.isRunning(now);
+ if (poll.getPollType() != PollType.FREE) {
+
+ PersonToListDAO personToListDAO = getDAO(PersonToList.class);
+ PersonToList personToList = personToListDAO.findByPollAndAccount(poll, accountEditable);
+
+ result &= personToList != null;
+ }
+ return result;
+ }
public boolean isUpdateAllowed(Poll poll, String voteId, String accountId, UserAccount userConnected) {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-28 16:40:01 UTC (rev 3217)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-28 16:40:09 UTC (rev 3218)
@@ -186,11 +186,6 @@
return poll.isAddChoiceRunning(now);
}
- public boolean isPollRunning() {
- Date now = serviceContext.getCurrentTime();
- return poll.isRunning(now);
- }
-
public String getCreatorName() {
return poll.getCreator().getVotingId();
}
@@ -320,9 +315,10 @@
resetCommentName();
if (log.isInfoEnabled()) {
+ Date now = serviceContext.getCurrentTime();
log.info("pollChoiceOrVoteStarted = " + isPollChoiceOrVoteStarted());
log.info("pollChoiceRunning = " + isPollChoiceRunning());
- log.info("pollRunning = " + isPollRunning());
+ log.info("pollRunning = " + poll.isRunning(now));
log.info("accountFieldDisplayed = " + isAccountFieldDisplayed());
log.info("creatorUser = " + creatorUser);
}
@@ -365,6 +361,10 @@
return getVoteService().isUpdateAllowed(getPoll(), voteId, getAccountId(), getPollenUserAccount());
}
+ public boolean isVoteAllowed() {
+ return getVoteService().isVoteAllowed(getPoll(), getPollAccount());
+ }
+
public String escapeLineBreak(String text) {
return text;
}
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-03-28 16:40:01 UTC (rev 3217)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-28 16:40:09 UTC (rev 3218)
@@ -264,7 +264,7 @@
</s:if>
</tr>
</thead>
-<s:if test="pollRunning">
+<s:if test="voteAllowed">
<tfoot>
<tr>
<s:if test="accountFieldDisplayed">
@@ -416,7 +416,7 @@
<%--<t:errors/>--%>
</div>
-<s:if test="pollRunning">
+<s:if test="voteAllowed">
<div id="buttons">
<s:if test="poll.anonymousVoteAllowed">
<s:checkbox key="vote.anonymous"/>
1
0
r3217 - in branches/pollen-1.2.6-struts2: pollen-persistence/src/main/java/org/chorem/pollen/business/persistence pollen-services/src/main/java/org/chorem/pollen/services/impl
by fdesbois@users.chorem.org 28 Mar '12
by fdesbois@users.chorem.org 28 Mar '12
28 Mar '12
Author: fdesbois
Date: 2012-03-28 18:40:01 +0200 (Wed, 28 Mar 2012)
New Revision: 3217
Url: http://chorem.org/repositories/revision/pollen/3217
Log:
- resolve issue on personToList creation (missing votingList reference)
- manage weight on restricted poll
Added:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonToListDAOImpl.java
Modified:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
Added: 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 (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonToListDAOImpl.java 2012-03-28 16:40:01 UTC (rev 3217)
@@ -0,0 +1,34 @@
+package org.chorem.pollen.business.persistence;
+
+import java.util.List;
+
+/**
+ * Created: 28/03/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ * $Id$
+ */
+public class PersonToListDAOImpl<E extends PersonToList> extends PersonToListDAOAbstract<E> {
+
+ public PersonToList findByPollAndAccount(Poll poll, PollAccount account) {
+
+// TopiaQuery query = createQuery("e")
+// .addFrom(Poll.class, "p")
+// .addFrom(VotingList.class, "v")
+// .addEquals("p", poll)
+// .addInElements("v", "p." + Poll.PROPERTY_VOTING_LIST)
+// .addWhere("e." + PersonToList.PROPERTY_VOTING_LIST + " = v." + VotingList.PROPERTY_POLL_ACCOUNT_PERSON_TO_LIST)
+// .addEquals("e." + PersonToList.PROPERTY_POLL_ACCOUNT, account);
+
+ PersonToList result;
+ List<VotingList> votingLists = poll.getVotingList();
+ for (VotingList votingList : votingLists) {
+ result = votingList.getPollAccountPersonToList(account);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+
+}
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-03-28 16:39:54 UTC (rev 3216)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-03-28 16:40:01 UTC (rev 3217)
@@ -107,6 +107,7 @@
TopiaQuery query = createQuery("e")
.addFrom(Poll.class, "p")
.addFrom(Vote.class, "v")
+ .addEquals("p", poll)
.addInElements("v", "p." + Poll.PROPERTY_VOTE)
.addWhere("e = v." + Vote.PROPERTY_POLL_ACCOUNT)
.addEquals("e." + PollAccount.PROPERTY_USER_ACCOUNT, user);
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-03-28 16:39:54 UTC (rev 3216)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-28 16:40:01 UTC (rev 3217)
@@ -188,7 +188,6 @@
PersonToList personToListCreated = create(personToListDAO);
personToListCreated.setHasVoted(personToList.isHasVoted());
personToListCreated.setWeight(personToList.getWeight());
- votingListCreated.addPollAccountPersonToList(personToListCreated);
PollAccount pollAccount = personToList.getPollAccount();
PollAccount pollAccountCreated = create(pollAccountDAO);
@@ -198,6 +197,10 @@
pollAccountCreated.setVotingId(pollAccount.getVotingId());
personToListCreated.setPollAccount(pollAccountCreated);
+
+ // The model doesn't have any composition for this relation, the link must be set in both objects
+ personToListCreated.setVotingList(votingListCreated);
+ votingListCreated.addPollAccountPersonToList(personToListCreated);
}
}
result.addVotingList(votingListCreated);
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-28 16:39:54 UTC (rev 3216)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-28 16:40:01 UTC (rev 3217)
@@ -31,6 +31,8 @@
import org.chorem.pollen.PollenTechnicalException;
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.PersonToListDAO;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.PollAccountDAO;
@@ -43,6 +45,7 @@
import org.chorem.pollen.entities.PollenBinderHelper;
import org.chorem.pollen.entities.PollenDAOHelper;
import org.chorem.pollen.services.PollenServiceSupport;
+import org.chorem.pollen.services.exceptions.PollAccountNotFound;
import org.chorem.pollen.services.exceptions.VoteNotFoundException;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
@@ -67,7 +70,6 @@
Vote result = newInstance(voteDAO);
result.setPollAccount(account);
- // TODO weight ?
result.setWeight(1.);
// Prepare the List of VoteToChoice with Poll's choices
@@ -126,6 +128,12 @@
} else {
result = getNewVote(poll, accountEditable);
}
+
+ if (poll.getPollType() != PollType.FREE && accountEditable.getTopiaId() != null) {
+ PersonToListDAO personToListDAO = getDAO(PersonToList.class);
+ PersonToList personToList = personToListDAO.findByPollAndAccount(poll, accountEditable);
+ result.setWeight(personToList.getWeight());
+ }
return result;
}
@@ -150,7 +158,7 @@
return result;
}
- public Vote createVote(Vote vote) {
+ public Vote createVote(Vote vote) throws PollAccountNotFound {
VoteDAO voteDAO = getDAO(Vote.class);
@@ -163,14 +171,16 @@
String pollAccountId = pollAccount.getTopiaId();
PollAccount pollAccountLoaded = null;
- // Load existing account only if not anonymous, otherwise a new pollAccount must be created
- if (pollAccountId != null && !vote.isAnonymous()) {
+ // Load existing account (restricted poll)
+ if (pollAccountId != null) {
pollAccountLoaded = getEntityById(PollAccount.class, pollAccountId);
- }
+
+ if (pollAccountLoaded == null) {
+ throw new PollAccountNotFound();
+ }
- // Create the new PollAccount
- if (pollAccountLoaded == null) {
-
+ // Create new account
+ } else {
PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
pollAccountLoaded = create(pollAccountDAO);
pollAccountLoaded.setAccountId(pollAccount.getAccountId());
@@ -188,6 +198,7 @@
pollAccountLoaded.setUserAccount(userAccountLoaded);
}
}
+ // TODO Manage anonymous for existing account ??? problem with restricted and email
result.setPollAccount(pollAccountLoaded);
// -- List of VoteToChoice -- //
1
0
r3216 - 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 28 Mar '12
by fdesbois@users.chorem.org 28 Mar '12
28 Mar '12
Author: fdesbois
Date: 2012-03-28 18:39:54 +0200 (Wed, 28 Mar 2012)
New Revision: 3216
Url: http://chorem.org/repositories/revision/pollen/3216
Log:
- Add anonymous checkbox
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-03-28 16:39:46 UTC (rev 3215)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-28 16:39:54 UTC (rev 3216)
@@ -64,15 +64,18 @@
Poll poll = getPoll();
- String name = pollAccount.getVotingId();
- if (StringUtils.isBlank(name)) {
- addFieldError("pollAccount.votingId", _("pollen.error.pollAccount.votingId.required"));
- }
+ if (!vote.isAnonymous()) {
- // check if the new pollAccount (topiaId = null) has already voted
- if (pollAccount.getTopiaId() == null && getVoteService().hasAlreadyVoted(name, poll)) {
- addFieldError("pollAccount.votingId", _("pollen.error.user.alreadyVoted"));
- }
+ String name = pollAccount.getVotingId();
+ if (StringUtils.isBlank(name)) {
+ addFieldError("pollAccount.votingId", _("pollen.error.pollAccount.votingId.required"));
+ }
+
+ // check if the new pollAccount (topiaId = null) has already voted
+ if (pollAccount.getTopiaId() == null && getVoteService().hasAlreadyVoted(name, poll)) {
+ addFieldError("pollAccount.votingId", _("pollen.error.user.alreadyVoted"));
+ }
+ }
}
@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-03-28 16:39:46 UTC (rev 3215)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-28 16:39:54 UTC (rev 3216)
@@ -236,3 +236,4 @@
pollen.title.selectPersonListToAddVotingList=Select a voter list to import in voting list
pollen.title.selectPersonListToCreateVotingList=Select a favorite list to import in a new voting list
pollen.title.usersList=Users administration
+vote.anonymous=Anonymous vote
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-03-28 16:39:46 UTC (rev 3215)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-28 16:39:54 UTC (rev 3216)
@@ -246,3 +246,4 @@
pollen.title.selectPersonListToCreateVotingList=Sélectionner une liste de votants pour créer un nouveau groupe
pollen.title.usersList=Gestion des utilisateurs
title=Création d'un sondage
+vote.anonymous=Vote anonyme
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-03-28 16:39:46 UTC (rev 3215)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-28 16:39:54 UTC (rev 3216)
@@ -86,7 +86,18 @@
}
jQuery(document).ready(function () {
+
$('#poll tr:even').addClass('even');
+
+ var $anonymousField = $('#voteForm [name="vote.anonymous"]');
+ var $votingIdField = $('#voteForm [name="pollAccount.votingId"]');
+
+ $votingIdField.attr('disabled', $anonymousField.prop('checked'));
+
+ $anonymousField.change(function() {
+ $votingIdField.attr('disabled', $(this).prop('checked'));
+ });
+
});
@@ -407,8 +418,8 @@
<s:if test="pollRunning">
<div id="buttons">
- <s:if test="anonymousVoteDisplayed">
- <s:checkbox id="anonymousVote" value="anonymousVote"/>
+ <s:if test="poll.anonymousVoteAllowed">
+ <s:checkbox key="vote.anonymous"/>
<%--<t:label for="anonymousVote"/>--%>
<br/>
</s:if>
1
0