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
May 2010
- 2 participants
- 39 discussions
25 May '10
Author: fdesbois
Date: 2010-05-25 11:29:17 +0200 (Tue, 25 May 2010)
New Revision: 3011
Url: http://chorem.org/repositories/revision/pollen/3011
Log:
- Start refactor Vote page
- Add pollenUtils for entities
- Move votes methods in a new ServiceVote
Added:
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/VoteModel.java
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java
trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties
trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties
trunk/pollen-business/src/main/xmi/pollen.zargo
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -121,6 +121,7 @@
// Set context in PollenProperty enum to use easily method
// getValue() on PollenProperty
PollenProperty.setContext(this);
+ PollenUtils.setContext(this);
createSuperAdmin(serviceUser);
//
Added: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java (rev 0)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -0,0 +1,22 @@
+package org.chorem.pollen;
+
+import java.util.Date;
+
+/**
+ * Created: 21 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class PollenUtils {
+
+ private static PollenContext context;
+
+ public static void setContext(PollenContext context) {
+ PollenUtils.context = context;
+ }
+
+ public static Date getCurrentDate() {
+ return context.getCurrentDate();
+ }
+}
Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenUtils.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollImpl.java 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollImpl.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -1,10 +1,14 @@
package org.chorem.pollen.entity;
+import org.chorem.pollen.PollenBusinessException;
+import org.chorem.pollen.PollenUtils;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
+import java.util.Date;
+
/**
* PollImpl
*
@@ -21,26 +25,6 @@
private static final long serialVersionUID = 1L;
@Override
- public boolean canVote(PollAccount person) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public boolean canAdminPoll(PollAccount person) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public boolean canCreateChoice(PollAccount person) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public boolean canAccessPoll(PollAccount person) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
public ChoiceType getChoiceType() {
return ChoiceType.valueOf(getTypeChoice());
}
@@ -71,6 +55,7 @@
}
@Override
+ @Deprecated
public Choice addNewChoice(String name, String description) {
// check exist
Choice choice = new ChoiceImpl();
@@ -80,4 +65,21 @@
addChoice(choice);
return choice;
}
+
+ @Override
+ public boolean isStarted() {
+ Date now = PollenUtils.getCurrentDate();
+ return getBeginDate() == null || getBeginDate().before(now);
+ }
+
+ @Override
+ public boolean isFinished() {
+ Date now = PollenUtils.getCurrentDate();
+ return getEndDate() != null && getEndDate().before(now);
+ }
+
+ @Override
+ public boolean isRunning() {
+ return isStarted() && !isFinished() && !getClosed();
+ }
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -269,24 +269,6 @@
}
@Override
- protected void executeCreateUpdateVote(TopiaContext transaction,
- PollAccount person) throws TopiaException {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- protected void executeDeleteVote(TopiaContext transaction, Poll poll,
- PollAccount person) throws TopiaException {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- protected Poll executeGetPollForUpdate(TopiaContext transaction,
- String pollUId) throws PollenBusinessException, TopiaException {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
protected List<Poll> executeGetAllPolls(TopiaContext transaction)
throws TopiaException {
throw new UnsupportedOperationException("Not supported yet.");
@@ -312,25 +294,6 @@
}
@Override
- protected List<PollAccount> executeGetVotes(TopiaContext transaction,
- Poll poll, int startIndex, int endIndex)
- throws TopiaException {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- protected Poll executeGetPollForResults(TopiaContext transaction,
- String pollUId) throws PollenBusinessException, TopiaException {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- protected Poll executeGetPollForVote(TopiaContext transaction,
- String pollUId) throws PollenBusinessException, TopiaException {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
protected ParticipantList executeGetNewPollList() {
PollAccount list = new PollAccountImpl();
list.setList(true);
@@ -380,7 +343,7 @@
@Override
protected Poll executeGetPoll(TopiaContext transaction,
String pollUid, String... properties)
- throws TopiaException {
+ throws TopiaException, PollenBusinessException {
PollDAO dao = PollenDAOHelper.getPollDAO(transaction);
@@ -389,6 +352,10 @@
addLoad(properties);
Poll result = dao.findByQuery(query);
+ if (result == null) {
+ throw new PollenBusinessException(
+ PollenBusinessException.PollenExceptionType.POLL_NOT_EXIST);
+ }
return result;
}
Added: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java (rev 0)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -0,0 +1,68 @@
+package org.chorem.pollen.service;
+
+import org.chorem.pollen.PollenContext;
+import org.chorem.pollen.PollenException;
+import org.chorem.pollen.entity.Poll;
+import org.chorem.pollen.entity.PollAccount;
+import org.chorem.pollen.entity.PollAccountImpl;
+import org.chorem.pollen.entity.UserAccount;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+
+import java.util.List;
+
+/**
+ * Created: 21 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class ServiceVoteImpl extends ServiceVoteAbstract {
+
+ private PollenContext context;
+
+ public void setContext(PollenContext context) {
+ this.context = context;
+ }
+
+ @Override
+ protected TopiaContext beginTransaction() throws TopiaException {
+ return context.beginTransaction();
+ }
+
+ @Override
+ protected void treateError(TopiaContext transaction, Exception eee,
+ String message, Object... args) throws PollenException {
+ context.treateError(transaction, eee, message, args);
+ }
+
+ @Override
+ protected void closeTransaction(TopiaContext transaction) {
+ context.closeTransaction(transaction);
+ }
+
+ @Override
+ protected boolean executeCanVote(TopiaContext transaction, Poll poll, PollAccount participant) throws Exception {
+ return false;
+ }
+
+ @Override
+ protected PollAccount executeGetNewPollAccount() throws Exception {
+ PollAccount account = new PollAccountImpl();
+ return account;
+ }
+
+ @Override
+ protected PollAccount executeGetPollAccount(TopiaContext transaction, String accountUid) throws Exception {
+ return null;
+ }
+
+ @Override
+ protected List<PollAccount> executeGetVotes(TopiaContext transaction, Poll poll, int startIndex, int endIndex) throws Exception {
+ return null;
+ }
+
+ @Override
+ protected void executeDeleteVote(TopiaContext transaction, Poll poll, PollAccount participant) throws Exception {
+ }
+}
Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceVoteImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties
===================================================================
--- trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-05-25 09:29:17 UTC (rev 3011)
@@ -75,7 +75,12 @@
pollen.error.serviceUser.getUsers=
pollen.error.serviceUser.updateFavoriteParticipant=
pollen.error.serviceUser.updateUser=
+pollen.error.serviceVote.canVote=
+pollen.error.serviceVote.deleteVote=
+pollen.error.serviceVote.getNewPollAccount=
+pollen.error.serviceVote.getPollAccount=
pollen.error.serviceVote.getVote=
+pollen.error.serviceVote.getVotes=
pollen.error.serviceVote.getVotesByPoll=Unable to load votes from poll with uid \= %1$s
pollen.error.serviceVote.hasAlreadyVoted=Unable test vote existing for account with votingId \= %1$s and poll with uid \= %2$s
pollen.exception.favorite_list_name_exist=
Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties
===================================================================
--- trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-05-25 09:29:17 UTC (rev 3011)
@@ -74,7 +74,12 @@
pollen.error.serviceUser.getUsers=
pollen.error.serviceUser.updateFavoriteParticipant=
pollen.error.serviceUser.updateUser=
+pollen.error.serviceVote.canVote=
+pollen.error.serviceVote.deleteVote=
+pollen.error.serviceVote.getNewPollAccount=
+pollen.error.serviceVote.getPollAccount=
pollen.error.serviceVote.getVote=
+pollen.error.serviceVote.getVotes=
pollen.error.serviceVote.getVotesByPoll=
pollen.error.serviceVote.hasAlreadyVoted=
pollen.exception.favorite_list_name_exist=La liste %1$s existe d\u00E9j\u00E0 pour l'utilisateur %2$s
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -4,6 +4,7 @@
import org.apache.tapestry5.ValueEncoder;
import org.apache.tapestry5.ioc.Messages;
import org.chorem.pollen.PollenBusinessException;
+import org.chorem.pollen.PollenException;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.entity.Choice;
import org.chorem.pollen.entity.ParticipantList;
@@ -99,7 +100,8 @@
* @param user Connected user as creator of a new poll (can be null
* if no user is connected).
*/
- public void initPoll(ServicePoll servicePoll, String uid, UserAccount user) {
+ public void initPoll(ServicePoll servicePoll, String uid, UserAccount user)
+ throws PollenBusinessException {
if (StringUtils.isNotEmpty(uid)) {
if (logger.isDebugEnabled()) {
logger.debug("Get existing poll with pollUID = " + uid);
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/VoteModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/VoteModel.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/VoteModel.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -0,0 +1,61 @@
+package org.chorem.pollen.ui.models;
+
+import org.chorem.pollen.PollenBusinessException;
+import org.chorem.pollen.entity.Poll;
+import org.chorem.pollen.entity.PollAccount;
+import org.chorem.pollen.entity.UserAccount;
+import org.chorem.pollen.service.ServicePoll;
+import org.chorem.pollen.service.ServiceVote;
+import org.chorem.pollen.ui.data.PollUri;
+
+/**
+ * Created: 21 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class VoteModel {
+
+ protected Poll poll;
+
+ protected PollAccount account;
+
+ protected ServicePoll servicePoll;
+
+ protected ServiceVote serviceVote;
+
+ public VoteModel(ServicePoll servicePoll, ServiceVote serviceVote) {
+ this.servicePoll = servicePoll;
+ }
+
+ public void init(PollUri uri)
+ throws PollenBusinessException {
+ poll = servicePoll.getPoll(uri.getPollUid());
+ account = serviceVote.getPollAccount(uri.getAccountUid());
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public boolean isCreatorUser(UserAccount user) {
+ return user.equals(poll.getCreator().getUserAccount());
+ }
+
+ public PollAccount getPollAccount() {
+ if (account == null) {
+ account = serviceVote.getNewPollAccount();
+ }
+ return account;
+ }
+
+ public boolean isAllowedToVote() {
+ if (poll.isFinished()) {
+ return false;
+ }
+ if (poll.getPollType().isRestrictedOrGroup() || poll.getAnonymous()) {
+ return serviceVote.canVote(poll, account);
+ }
+ return true;
+ }
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/VoteModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -173,7 +173,12 @@
logger.debug("-------- NEW POLL FORM MODEL --------");
}
model = new PollFormModel();
- model.initPoll(servicePoll, pollUID, getUserConnected());
+ try {
+ model.initPoll(servicePoll, pollUID, getUserConnected());
+ } catch (PollenBusinessException eee) {
+ String message = manager.getErrorMessage(logger, messages, eee);
+ addFatal(message);
+ }
}
return model;
}
@@ -394,7 +399,7 @@
/** Flag if submit comes from lists edition */
private boolean editLists;
- protected static final String EVENT_UPDATE_POLL_TYPE = "updateFromPollType";
+ protected static final String EVENT_UPDATE_POLL_TYPE = "updatePollType";
/** DATA ** */
@@ -437,7 +442,7 @@
}
@Log
- Object onUpdateFromPollType(String value) {
+ Object onUpdatePollType(String value) {
getModel().setPollType(servicePoll, manager, PollType.valueOf(value));
return refreshListZone();
}
@@ -658,11 +663,18 @@
pollLinks.setPollUri(uri);
// Send an email to the creator
if (creator.getEmail() != null) {
- if (!sendCreatorEmail(creator, uri)) {
- return mainZone;
+ try {
+ sendCreatorEmail(creator, uri);
+ pollLinks.addInfo(messages.get(
+ "pollen.ui.poll.links.creatorEmail.success"));
+ } catch (PollenBusinessException eee) {
+ String message =
+ manager.getErrorMessage(logger, messages, eee);
+ pollLinks.addError(message);
}
} else {
- pollLinks.addInfo("pollen.ui.poll.links.creatorEmail.notDefined");
+ pollLinks.addInfo(messages.get(
+ "pollen.ui.poll.links.creatorEmail.notDefined"));
}
if (getPoll().getPollType().isRestrictedOrGroup()) {
pollLinks.addInfo("Les votants ont reçu un mail !");
@@ -672,7 +684,8 @@
return mainZone;
}
- protected boolean sendCreatorEmail(PollAccount creator, PollUri uri) {
+ protected void sendCreatorEmail(PollAccount creator, PollUri uri)
+ throws PollenBusinessException {
PollenEmail email = new PollenEmailImpl();
email.setTo(creator.getEmail());
email.setSubject(messages.format(
@@ -684,15 +697,8 @@
servicePollUri.getVoteUrl(uri),
servicePollUri.getModerateVoteUrl(uri),
servicePollUri.getPollUpdateUrl(uri)));
- try {
- serviceEmail.sendEmail(email);
- pollLinks.addInfo("pollen.ui.poll.links.creatorEmail.success");
- } catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(logger, messages, eee);
- addError(message);
- return false;
- }
- return true;
+
+ serviceEmail.sendEmail(email);
}
@Log
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -4,6 +4,7 @@
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.PageRenderLinkSource;
+import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.entity.Poll;
import org.chorem.pollen.service.ServicePoll;
import org.chorem.pollen.ui.base.AbstractPollenPage;
@@ -69,7 +70,7 @@
}
}
- public boolean isPollNull() {
+ public boolean isPollNull() throws PollenBusinessException {
return getPoll() == null;
}
@@ -77,7 +78,7 @@
this.pollUri = pollUri;
}
- public Poll getPoll() {
+ public Poll getPoll() throws PollenBusinessException {
if (pollUri != null) {
poll = servicePoll.getPoll(pollUri.getPollUid());
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -478,7 +478,7 @@
if (id != null && !"".equals(id)) {
pollId = id.split(":", 2)[0];
- poll = servicePoll.getPollForResults(pollId);
+ //poll = servicePoll.getPollForResults(pollId);
if (poll != null) {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -50,12 +50,14 @@
import org.chorem.pollen.entity.Vote;
import org.chorem.pollen.service.ServicePoll;
import org.chorem.pollen.service.ServiceUser;
+import org.chorem.pollen.service.ServiceVote;
import org.chorem.pollen.ui.base.AbstractUploadPage;
import org.chorem.pollen.ui.components.Border;
import org.chorem.pollen.ui.components.Pager;
import org.chorem.pollen.ui.data.AddressBar;
import org.chorem.pollen.ui.data.ChoiceField;
import org.chorem.pollen.ui.data.PollUri;
+import org.chorem.pollen.ui.models.VoteModel;
import org.chorem.pollen.ui.services.PollenManager;
import org.chorem.pollen.ui.services.ServiceImage;
import org.nuiton.web.tapestry5.components.FeedBack;
@@ -79,860 +81,9 @@
public Border getBorder() {
return border;
}
-//
-// @Parameter(defaultPrefix = BindingConstants.MESSAGE, value = "title")
-// @Property
-// private String title;
-//
-// /** Paramètres de la page */
-// private String param;
-//
-// /** Affichage des messages pour l'utilisateur */
-// @Component(id = "feedback")
-// private FeedBack feedback;
-//
-//
-// /**
-// * Objet de session représentant l'url du site.
-// */
-// @SessionState
-// @Property
-// private String siteURL;
-//
-// @Component
-// private Form voteForm;
-//
-//// @Component(id = "pollAccountName")
-//// private TextField nameField;
-//
-//// /** Composant DateTimeField pour les choix du sondage */
-//// @SuppressWarnings("unused")
-//// @Component(parameters = { "timePicker=true", "timePickerAdjacent=true" })
-//// private DateTimeField dateDTF;
-//
-// /** Locale courante */
-// @Inject
-// private Locale currentLocale;
-//
-// @Inject
-// private Logger logger;
-//
-// @Inject
-// private Messages messages;
-//
-// /**
-// * Vote courant de l'utilisateur
-// */
-// @Property
-// private Vote vote;
-//
-// /** Choix courant du sondage */
-// @Property
-// private Choice choiceOfPoll;
-// /** Choix courant du nouveau vote */
-// @Property
-// private Choice choiceOfVote;
-//
-// /** Résultats du sondage */
-// @Persist
-// private List<Result> results;
-//
-// /**
-// * Modèle pour l'affichage de la liste des sondages
-// */
-// @SuppressWarnings( { "unchecked", "unused" })
-// @Property
-// @Retain
-// private BeanModel voteModel;
-//
-// /*@InjectPage
-// private ImageDisplay imageDisplay;*/
-//
-//// @InjectComponent
-//// private Zone pollZone;
-//
-// /**
-// * Objet servant à changer la couleur à chaque ligne de la liste des
-// * sondages
-// */
-// @SuppressWarnings("unused")
-// @Property
-// private EvenOdd evenOdd = new EvenOdd();
-//
-// /** Choix courant (type texte) */
-// private boolean addChoice;
-//
-// /** Le votant a déjà voté ? */
-// private boolean alreadyVoted;
-//
-// /** Le vote est anonyme */
-// @Property
-// private boolean anonymousVote = false;
-//
-// /** Liste des choix */
-//// private List<ChoiceDTO> voteChoices = new ArrayList<ChoiceDTO>();
-//
-// /** Identifiant du compte correspondant à l'adresse forgée */
-//// private String pollAccountId;
-//
-// /** Compte du votant */
-//// @Property
-//// private PollAccountDTO pollAccount;
-//
-//// /** Nouveau choix de type texte */
-//// @Property
-//// @Persist
-//// private ChoiceDTO newChoice;
-//
-// /** Nouveau choix de type date */
-// @Property
-// @Persist
-// private DateChoiceUIO newDateChoice;
-//
-// /** Nouveau choix de type image */
-// @Property
-// @Persist
-// private ImageChoiceUIO newImageChoice;
-//
-// /** Injection des services */
-// @Inject
-// private ServicePoll servicePoll;
-// @Inject
-// private ServiceVote serviceVote;
-//
-// @Inject
-// private ServicePollAccount servicePollAccount;
-// @Inject
-// private ServiceResults serviceResults;
-//
-// /**
-// * Composant pour la gestion des flux RSS
-// */
-// @InjectComponent
-// private ContextLink feedContext;
-//
-// /**
-// * Context to get feed of the current poll
-// * @return a FeedContext defined in .tml file
-// */
-// public ContextLink getFeedContext() {
-// return feedContext;
-// }
-//
-//// /**
-//// * Composant pour la gestion des upload d'images
-//// */
-//// @InjectComponent
-//// private ImageContextLink imgContext;
-////
-//// /**
-//// * Context to get images for choices.
-//// * @return an ImageContextLink defined in .tml file
-//// */
-//// public ImageContextLink getImgContext() {
-//// return imgContext;
-//// }
-//
-// @InjectComponent
-// private FeedBack voteFeedback;
-//
-// public String getVoteSizeMessage() throws PollenBusinessException {
-// if (log.isDebugEnabled()) {
-// log.debug("poll voteDTOs list size : " + getVotes().size());
-// log.debug("poll nbVotes : " + getPoll().getNbVotes());
-// }
-// return messages.format("vote-size", getPoll().getNbVotes());
-// }
-//
-// /** Méthode appelée après la soumission du vote. */
-//// @Log
-//// Object onSuccessFromVoteForm() throws PollenBusinessException {
-//// if (initPollAccount()) {
-//// List<ChoiceDTO> choiceDTOs = new ArrayList<ChoiceDTO>();
-//// if (getPoll().getVoteCounting() == VoteCountingType.NORMAL) {
-//// int nbChoices = 0;
-//// for (ChoiceDTO choice : getPoll().getChoices()) {
-//// if (choice.getValue() == 1) {
-//// nbChoices++;
-//// }
-//// choiceDTOs.add(choice);
-//// }
-//// if (nbChoices > getPoll().getMaxChoiceNb()) {
-//// voteForm.recordError(messages.format(("tooManyChoices"),
-//// getPoll().getMaxChoiceNb()));
-//// return pollZone.getBody();
-//// }
-////
-//// } else if (getPoll().getVoteCounting() == VoteCountingType.PERCENTAGE) {
-//// int total = 0;
-//// for (ChoiceDTO choice : getPoll().getChoices()) {
-//// total = total + choice.getValue();
-//// choiceDTOs.add(choice);
-//// }
-//// if (total != 100) {
-//// voteForm.recordError(messages.get("not100percent"));
-//// return pollZone.getBody();
-//// }
-////
-//// } else if (getPoll().getVoteCounting() == VoteCountingType.CONDORCET) {
-//// for (ChoiceDTO choice : getPoll().getChoices()) {
-//// if (choice.getValue() == 0) {
-//// choice.setValue(100);
-//// }
-//// choiceDTOs.add(choice);
-//// }
-////
-//// } else if (getPoll().getVoteCounting() == VoteCountingType.NUMBER) {
-//// String votingId = pollAccount.getVotingId();
-//// if (anonymousVote) {
-//// votingId = "anonymous" + UUID.randomUUID().toString().replaceAll("-", "");
-//// }
-////
-//// for (ChoiceDTO choice : getPoll().getChoices()) {
-//// if (!choice.isHidden()) {
-//// choiceDTOs.add(choice);
-////
-//// // creates a new hidden choice
-////// ChoiceDTO hiddenChoice = new ChoiceDTO();
-////// hiddenChoice.setName(NumberMethod.HIDDEN_PREFIX +
-////// choice.getName() + "#" + votingId);
-////// hiddenChoice.setHidden(true);
-////// hiddenChoice.setValue(choice.getValue());
-////// hiddenChoice.setPollId(choice.getPollId());
-////// hiddenChoice.setVoteId(choice.getVoteId());
-////// hiddenChoice.setValidate(false);
-//// ChoiceDTO hiddenChoice =
-//// servicePoll.getNewHiddenChoice(choice, votingId);
-////
-//// String choiceId =
-//// serviceChoice.createChoice(hiddenChoice);
-//// hiddenChoice.setId(choiceId);
-//// choiceDTOs.add(hiddenChoice);
-//// }
-//// }
-//// }
-////
-//// VoteDTO vote = new VoteDTO(null, getPoll().getId(), null);
-//// vote.setChoiceDTOs(choiceDTOs);
-//// vote.setWeight(pollAccount.getWeight());
-//// vote.setAnonymous(anonymousVote);
-////
-//// // mise à jour du vote ou création d'un nouveau vote
-//// if (alreadyVoted) {
-//// for (VoteDTO v : getVotes()) {
-//// PollAccountDTO voteAccount = servicePollAccount
-//// .findPollAccountById(v.getPollAccountId());
-////
-//// if (voteAccount.getVotingId().equals(getPollAccount().getVotingId())) {
-//// vote.setId(v.getId());
-//// deleteVote(vote.getId());
-//// serviceVote.createVote(vote, getPollAccount());
-//// }
-//// }
-//// } else {
-//// serviceVote.createVote(vote, getPollAccount());
-//// }
-////
-//// // Mise à jour du sondage et des résultats
-//// //poll = servicePoll.findPollByPollId(getPoll().getPollId());
-//// poll = null;
-//// countPoll();
-////
-//// addFeedEntry(PollAction.ADDVOTE, getPollAccount().getVotingId(),
-//// getResultsAsString());
-//// sendMailNotification();
-//// voteFeedback.addInfo(messages.get("vote-success"));
-//// page = pager.getLastPage();
-//// // Reset votes to reload them depends on page change.
-//// votes = null;
-//// return this;
-//// }
-////// voteChoices.clear();
-//// return pollZone.getBody();
-//// }
-//
-//// private void deleteVote(String voteId) throws PollenBusinessException {
-//// for (VoteDTO vote : getVotes()) {
-//// if (vote.getId().equals(voteId)) {
-////
-//// List<ChoiceDTO> choiceDTOs = vote.getChoiceDTOs();
-//// for (ChoiceDTO choiceDTO : choiceDTOs) {
-////
-//// if (choiceDTO.isHidden()) {
-//// serviceChoice.deleteChoice(choiceDTO.getId());
-//// }
-//// }
-////
-//// break;
-//// }
-//// }
-////
-//// serviceVote.deleteVote(voteId);
-//// }
-////
-//// /** Méthode appelée lors de la suppression d'un vote. */
-//// Object onActionFromDeleteVote(String voteId) throws PollenBusinessException {
-//// deleteVote(voteId);
-////
-//// // Mise à jour du sondage et des résultats
-////// poll = servicePoll.findPollByPollId(poll.getPollId());
-//// poll = null;
-//// countPoll();
-////
-//// return pollZone.getBody();
-//// }
-//
-// /** Initialisation du pollAccount et contrôle du nom. */
-//// private boolean initPollAccount() throws PollenBusinessException {
-////
-//// //// Contrôle et définition du votingId
-//// alreadyVoted = false;
-//// boolean modifAllowed = false;
-//// boolean restrictedListsForbidden = false;
-////
-//// // Suppression des espaces pouvant provoquer un double vote
-//// String votingId = getPollAccount().getVotingId().trim();
-//// getPollAccount().setVotingId(votingId);
-////
-//// // Contrôle de la présence du votant dans les listes de votants
-//// // du sondage (si le sondage n'est pas libre)
-////// if (!isFreePoll()) {
-////// restrictedListsForbidden = true;
-////// for (VotingListDTO list : poll.getVotingListDTOs()) {
-////// for (PollAccountDTO account : list.getPollAccountDTOs()) {
-////// if (pollAccount.getVotingId().equals(account.getVotingId())) {
-////// restrictedListsForbidden = false;
-////// pollAccount = servicePollAccount
-////// .findPollAccountById(account.getId());
-////// pollAccount.setVotingListId(list.getId());
-////// pollAccount.setWeight(account.getWeight());
-////// logger.debug("Compte \"" + account.getVotingId()
-////// + "\" présent dans la liste \""
-////// + list.getName() + "\" (poids="
-////// + account.getWeight() + ")");
-////// }
-////// }
-////// }
-////// }
-////
-//// // The calcul of alreadyVoted will be needed for no double votingId
-//// // Carefull, not correct for an anonymous vote
-//// alreadyVoted = serviceVote.hasAlreadyVoted(votingId, getPoll());
-////
-//// // Check for restricted poll
-//// if (!alreadyVoted && !isFreePoll()) {
-//// if (uri.getAccountUid() != null) {
-//// // The accountUid must be valid for the poll
-//// PollAccountDTO restrictedAccount =
-//// servicePoll.getRestrictedAccount(uri.getAccountUid(), getPoll());
-////
-//// if (restrictedAccount != null) {
-//// // PollAccount is replaced by the good account from db
-//// pollAccount = restrictedAccount;
-//// // Refresh alreadyVoted value depends on getPollAccount()
-//// alreadyVoted = getPollAccount().isHasVoted();
-//// // Existing account is null is forbidden for a restricted poll
-//// } else {
-//// restrictedListsForbidden = true;
-//// }
-//// // Not allowed to vote without an accountUid
-//// } else {
-//// restrictedListsForbidden = true;
-//// }
-////
-//// if (restrictedListsForbidden) {
-////// voteForm.recordError(nameField,
-////// messages.get("restrictedListsForbidden"));
-//// }
-//// }
-////
-//// // Génération d'un identifiant de vote (si le sondage est libre et anonyme)
-//// if (getPoll().isAnonymous()) {
-//// anonymousVote = true;
-//// if (isFreePoll()) {
-//// getPollAccount().setVotingId("anonymous"
-//// + UUID.randomUUID().toString().replaceAll("-", ""));
-//// }
-//// }
-////
-//// //// Définition de l'userId
-//// if (userExists) {
-//// getPollAccount().setUserId(user.getId());
-//// } else {
-//// getPollAccount().setUserId("");
-//// }
-////
-//// modifAllowed = isModifAllowed(getPollAccount().getVotingId());
-//// if (alreadyVoted && !modifAllowed) {
-////// voteForm.recordError(nameField, messages.format("alreadyVoted",
-////// getPollAccount().getVotingId()));
-//// }
-////
-//// logger.debug("votingId: " + getPollAccount().getVotingId());
-//// logger.debug("alreadyVoted: " + alreadyVoted);
-//// logger.debug("modifAllowed: " + modifAllowed);
-//// logger.debug("restrictedListsForbidden: " + restrictedListsForbidden);
-//// return ((!alreadyVoted || modifAllowed) && !restrictedListsForbidden);
-//// }
-//
-// /**
-// * Retourne vrai si la modification du vote est autorisée. C'est à dire si
-// * l'utilisateur connecté est l'auteur du vote ou si le votant défini par
-// * l'url est l'auteur du vote.
-// *
-// * @param votingId le votant a rechercher
-// * @return vrai si la modification du vote est autorisée
-// */
-//// public boolean isModifAllowed(String votingId) throws PollenBusinessException {
-//// boolean modifAllowed = false;
-//// int i = 0;
-////
-//// // parcours des votes pour trouver celui correspondant au votingId
-//// // et contrôle du droit de modification
-//// while (i < getVotes().size() && !modifAllowed) {
-////
-//// // account : compte associé au vote courant
-//// //String id = getVotes().get(i).getPollAccountId();
-//// //PollAccountDTO account = servicePollAccount.findPollAccountById(id);
-//// VoteDTO curr = getVotes().get(i);
-////
-//// // si le votant du vote correspond au votingId
-//// if (curr.getName().equals(votingId)) {
-//// if (logger.isDebugEnabled()) {
-//// logger.debug("vote name: " + curr.getName());
-//// logger.debug("vote account: " + curr.getPollAccountId());
-////// logger.debug("voting account: " + pollAccountId);
-//// }
-////
-//// // si le votant du vote correspond au votant actuel (pollAccountId)
-////// if (pollAccountId != null
-////// && pollAccountId.equals(curr.getPollAccountId())) {
-////// modifAllowed = true;
-////// }
-////
-//// // si l'utilisateur du vote correspond à l'utilisateur actuel (user)
-//// if (userExists && user.getId().length() > 0) {
-//// modifAllowed = user.getId().equals(curr.getUserId());
-//// }
-//// }
-////
-//// i++;
-//// }
-////
-//// return modifAllowed;
-//// }
-//
-// /** Ajout d'une entrée dans le flux de syndication */
-// private void addFeedEntry(PollAction pollAction, String titleStr,
-// String contentStr) throws PollenBusinessException {
-// String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollUid();
-// File feedFile = getFeedContext().getFile(getPoll().getPollUid());
-// String title = null;
-// String content = null;
-//
-// switch (pollAction) {
-// case ADDVOTE:
-// if (isVoteAnonymous()) {
-// titleStr = messages.get("anonymous");
-// }
-// title = messages.format("pollFeed_voteTitle", titleStr);
-// content = messages.format("pollFeed_voteContent", contentStr);
-// break;
-// case ADDCHOICE:
-// title = messages.format("pollFeed_choiceTitle", titleStr);
-// content = messages.format("pollFeed_choiceContent", contentStr);
-// break;
-// case ADDCOMMENT:
-// title = messages.format("pollFeed_commentTitle", titleStr);
-// content = messages.format("pollFeed_commentContent", contentStr);
-// break;
-// }
-//
-// if (!feedFile.exists()) {
-// FeedUtil.createFeed(feedFile, "atom_1.0", messages.format(
-// "pollFeed_title", getPoll().getTitle()), siteURL, messages
-// .format("pollFeed_desc", getPoll().getDescription()));
-// }
-// FeedUtil.feedFeed(feedFile, title, voteURL, content);
-// }
-//
-// /** Envoi du mail de notification */
-// private void sendMailNotification() throws PollenBusinessException {
-// String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollUid();
-// String modifURL = siteURL + "poll/Modification/" + getPoll().getPollUid()
-// + ":" + MD5.encode(getPoll().getCreatorId());
-// Map<String, String> data = new HashMap<String, String>();
-// data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST));
-// data.put("port", pollen.getProperty(PollenProperty.EMAIL_PORT));
-// data.put("from", pollen.getProperty(PollenProperty.EMAIL_FROM));
-//
-// // Mail au créateur
-// data.put("to", getPoll().getCreatorEmail());
-// data.put("title", messages.format("voteEmail_subject", getPoll().getTitle()));
-// data.put("msg", messages.format("voteEmail_msg", getPoll().getTitle(), getPoll()
-// .getNbVotes(), voteURL, modifURL));
-//
-// for (PreventRuleDTO rule : getPoll().getPreventRuleDTOs()) {
-// PreventRuleManager manager = new PreventRuleManager(rule);
-// manager.execute("vote", getVotes().size(), data);
-// }
-// }
-//
-// public boolean isAddChoice() {
-// return addChoice;
-// }
-//
-// public void setAddChoice(boolean addChoice) {
-// choiceOfVote.setValue((addChoice) ? 1 : 0);
-// }
-//
-// public void setAddNumberVote(Integer value) {
-// if (value != null) {
-// choiceOfVote.setValue(value);
-//
-// } else {
-// choiceOfVote.setValue(-1);
-// }
-// }
-//
-// public Integer getAddNumberVote() {
-// return null;
-// }
-//
-//
-// /**
-// * Retourne si le choix fait partie du vote (s'il a été renseigné par le
-// * votant).
-// *
-// * @param choice le choix concerné
-// * @return true si le choix est dans le vote
-// */
-// public Boolean isChoiceInVote(ChoiceDTO choice) throws PollenBusinessException {
-// if (choice != null) {
-// switch (getPoll().getVoteCounting()) {
-// case NORMAL:
-// return choice.getValue() > 0;
-// case PERCENTAGE:
-// return true;
-// case CONDORCET:
-// return choice.getValue() < 100;
-// case NUMBER:
-// return choice.getValue() >= 0;
-// }
-// }
-// return null;
-// }
-//
-// public boolean isChoiceHidden() {
-// return choiceOfPoll.isHidden();
-// }
-//
-// /**
-// * Retourne le choix de vote correspondant au choix de sondage courant.
-// *
-// * @return un choix de vote
-// */
-// @Property(write = false)
-// private ChoiceDTO currentVoteChoice;
-//
-// public char setCurrentVoteChoice() {
-//// currentVoteChoice = null;
-//// for (ChoiceDTO choice : vote.getChoiceDTOs()) {
-//// if (choice.getId().equals(choiceOfPoll.getId())) {
-//// currentVoteChoice = choice;
-//// break;
-//// }
-//// }
-//
-// return 0;
-// }
-//
-// /**
-// * Retourne le résultat correspondant au choix de sondage courant.
-// *
-// * @return le résultat du choix
-// */
-// public String getCurrentChoiceResult() {
-// String val = "";
-// for (ResultDTO result : results) {
-// if (result.getName().equals(choiceOfPoll.getName())) {
-// val = removeTrailing0(result.getValue());
-// }
-// }
-// return val;
-// }
-//
-// /**
-// * Vérifie que le fichier de flux de syndication existe.
-// *
-// * @return vrai si le fichier existe
-// */
-// @Log
-// public boolean isFeedFileExisting() throws PollenBusinessException {
-// File feedFile = getFeedContext().getFile(getPoll().getPollUid());
-// if (log.isDebugEnabled()) {
-// log.debug("feed context path : " + getFeedContext().getContextPath());
-// log.debug("feed absolute path : " + feedFile.getAbsolutePath());
-// }
-// return feedFile.exists() ? true : false;
-// }
-//
-// /**
-// * Supprime le 0 final d'un nombre à virgule. Le résultat peut-être un
-// * double : 1,0 -> 1 et 1,2 -> 1,2.
-// *
-// * @param val le nombre
-// * @return le nombre sans 0 final
-// */
-// private String removeTrailing0(String val) {
-// if (val.endsWith(".0")) {
-// val = val.substring(0, val.indexOf('.'));
-// }
-// return val;
-// }
-//
-// /**
-// * Retourne une chaîne contenant les résultats du sondage.
-// *
-// * @return les résultats
-// */
-// public String getResultsAsString() throws PollenBusinessException {
-// StringBuffer res = new StringBuffer("");
-// Iterator<ResultDTO> it = results.iterator();
-// while (it.hasNext()) {
-// ResultDTO result = it.next();
-// if (isDateType()) {
-// Date date = new Date(Long.parseLong(result.getName()));
-// res.append(dateFormat.format(date));
-// } else {
-// res.append(result.getName());
-// }
-// res.append("=" + removeTrailing0(result.getValue()));
-// if (it.hasNext()) {
-// res.append(", ");
-// }
-// }
-// return res.toString();
-// }
-//
-// /**
-// * Retourne true si le sondage est anonyme ou si le vote soumis est anonyme.
-// * Utilisé lors de la soumission d'un vote.
-// *
-// * @return true si le vote est anonyme
-// */
-// public boolean isVoteAnonymous() throws PollenBusinessException {
-// return getPoll().isAnonymous() || anonymousVote;
-// }
-//
-// /**
-// * Retourne true si le sondage est anonyme ou si le vote courant est
-// * anonyme. Utilisé dans la boucle de parcours des votes.
-// *
-// * @return true si le vote est anonyme
-// */
-// public boolean isCurrentVoteAnonymous() throws PollenBusinessException {
-// return getPoll().isAnonymous() || vote.isAnonymous();
-// }
-//
-// /** Retourne vrai si la checkbox anonymousVote doit être affichée. */
-// public boolean isAnonymousVoteDisplayed() throws PollenBusinessException {
-// return getPoll().isAnonymousVoteAllowed() && !getPoll().isAnonymous();
-// }
-//
-// /** Retourne l'identifiant du votant du vote courant */
-// public String getCurrentVotingId() {
-// return vote.getName();
-// }
-//
-// /** Validation du champs de saisie du choix (texte). */
-// void onValidateFromTextName(String value) throws ValidationException, PollenBusinessException {
-// validateNewChoice(value);
-// }
-//
-// /** Validation du champs de saisie du choix (date). */
-// void onValidateFromDateDTF(Date value) throws ValidationException, PollenBusinessException {
-// validateNewChoice(String.valueOf(value.getTime()));
-// }
-//
-// /** Validation du champs de saisie du choix (image). */
-// void onValidateFromImgFile(UploadedFile value) throws ValidationException, PollenBusinessException {
-// validateNewChoice(value.getFileName().replace(' ', '_'));
-// }
-//
-// /** Validation du champs de saisie du choix. */
-// private void validateNewChoice(String value) throws ValidationException, PollenBusinessException {
-// for (ChoiceDTO choice : getPoll().getChoices()) {
-// if (value.equals(choice.getName())) {
-// throw new ValidationException(messages.format("choiceExists",
-// value));
-// }
-// }
-// }
-//
-// /** Méthode appelée lors de l'ajout d'un choix. */
-// Object onSuccessFromChoiceForm() throws PollenBusinessException {
-// String choiceName = null;
-// String choiceDesc = null;
-// if (isTextType()) {
-// if (newChoice.getName() != null) {
-// newChoice.setValidate(true);
-// newChoice.setPollUid(getPoll().getPollUid());
-// getPoll().getChoices().add(newChoice);
-// choiceName = newChoice.getName();
-// choiceDesc = newChoice.getDescription();
-// }
-// } else if (isDateType()) {
-// if (newDateChoice.getDate() != null) {
-// newDateChoice.setValidate(true);
-// newDateChoice.setPollUid(getPoll().getPollUid());
-// newDateChoice.setName(String.valueOf(newDateChoice.getDate()
-// .getTime()));
-// getPoll().getChoices().add(newDateChoice);
-// Date date = new Date(Long.parseLong(newDateChoice.getName()));
-// choiceName = dateFormat.format(date);
-// choiceDesc = newDateChoice.getDescription();
-// }
-// } else if (isImageType()) {
-// if (newImageChoice.getImg() != null) {
-// newImageChoice.setValidate(true);
-// newImageChoice.setPollUid(getPoll().getPollUid());
-// newImageChoice.setName(newImageChoice.getImg().getFileName()
-// .replace(' ', '_'));
-// getPoll().getChoices().add(newImageChoice);
-// //File imgFile = getImgContext().getImageDir(); // dir set in getImgContext()
-//// File imgFile = getImgContext().getImageDir(); // dir set in getImgContext()
-//// ImageUtil.saveImage(newImageChoice, imgFile);
-// choiceName = newImageChoice.getName();
-// choiceDesc = newImageChoice.getDescription();
-// }
-// }
-//
-// servicePoll.updatePoll(getPoll());
-// poll = null;
-// //poll = servicePoll.findPollByPollId(getPoll().getPollId());
-// addFeedEntry(PollAction.ADDCHOICE, choiceName, choiceDesc);
-//// newChoice = new ChoiceDTO();
-//// newDateChoice = new DateChoiceUIO();
-//// newImageChoice = new ImageChoiceUIO();
-// return this;
-// }
-//
-//// public boolean isPollNull() {
-//// return poll == null;
-//// }
-//
-//
-// public boolean isPollChoiceOrVoteStarted() throws PollenBusinessException {
-// return isPollChoiceStarted() || isPollStarted();
-// }
-//
-//// public boolean isDescNull() {
-//// return choiceOfPoll.getDescription() == null
-//// || "".equals(choiceOfPoll.getDescription());
-//// }
-//
-//
-// public boolean isFreePoll() throws PollenBusinessException {
-// return getPoll().getPollType() == PollType.FREE;
-// }
-//
-// public boolean isRestrictedPoll() throws PollenBusinessException {
-// return getPoll().getPollType() == PollType.RESTRICTED;
-// }
-//
-// public boolean isGroupPoll() throws PollenBusinessException {
-// return getPoll().getPollType() == PollType.GROUP;
-// }
-//
-// public boolean isTextType() throws PollenBusinessException {
-// return getPoll().getChoiceType() == ChoiceType.TEXT;
-// }
-//
-// public boolean isDateType() throws PollenBusinessException {
-// return getPoll().getChoiceType() == ChoiceType.DATE;
-// }
-//
-// public boolean isImageType() throws PollenBusinessException {
-// return getPoll().getChoiceType() == ChoiceType.IMAGE;
-// }
-//
-// public boolean isNormalVoteCounting() throws PollenBusinessException {
-// return getPoll().getVoteCounting() == VoteCountingType.NORMAL;
-// }
-//
-// public boolean isPercentageVoteCounting() throws PollenBusinessException {
-// return getPoll().getVoteCounting() == VoteCountingType.PERCENTAGE;
-// }
-//
-// public boolean isCondorcetVoteCounting() throws PollenBusinessException {
-// return getPoll().getVoteCounting() == VoteCountingType.CONDORCET;
-// }
-//
-// public boolean isNumberVoteCounting() throws PollenBusinessException {
-// return getPoll().getVoteCounting() == VoteCountingType.NUMBER;
-// }
-//
-// /** Retourne le message d'aide correspondant au type de sondage. */
-// public String getHelpMessage() throws PollenBusinessException {
-// switch (getPoll().getVoteCounting()) {
-// case NORMAL:
-// return messages.get("normalVote-help");
-// case PERCENTAGE:
-// return messages.get("percentageVote-help");
-// case CONDORCET:
-// return messages.get("condorcetVote-help");
-// case NUMBER:
-// return messages.get("numberVote-help");
-// default:
-// return "";
-// }
-// }
-//
-// /**
-// * Retourne la date correspondant au choix courant
-// *
-// * @return date
-// */
-// public Date getChoiceNameAsDate() {
-// return new Date(Long.valueOf(choiceOfPoll.getName()));
-// }
-//
-// /** Dépouillement du sondage. Mise à jour des résultats. */
-// private void countPoll() throws PollenBusinessException {
-// ResultListDTO resultListDTO = null;
-// if (getPoll().getContinuousResults()) {
-//
-// if (isGroupPoll()) {
-// resultListDTO = serviceResults.getGroupResults(getPoll().getPollUid());
-// } else {
-// resultListDTO = serviceResults.getNormalResults(getPoll().getPollUid());
-// }
-//
-// results = resultListDTO.getResultDTOs();
-//
-// if (logger.isDebugEnabled()) {
-// for (ResultDTO res : results) {
-// logger.debug(res.getName() + ": " + res.getValue()
-// + ", (voteCounting=" + res.getVoteCounting()
-// + ", byGroup=" + res.isByGroup() + ")");
-// }
-// }
-// }
-// }
-
-
-
-
-
-
-
-
- ////////////////// NEW IMPLEMENTATION
-
@Inject
- private Logger log;
+ private Logger logger;
@Inject
private Messages messages;
@@ -944,8 +95,8 @@
private PollUri uri;
/** TEMP : Affichage des messages pour l'utilisateur */
- @Component(id = "feedback")
- private FeedBack feedback;
+// @Component(id = "feedback")
+// private FeedBack feedback;
@Parameter(defaultPrefix = BindingConstants.MESSAGE, value = "title")
@Property
@@ -960,15 +111,9 @@
@Inject
private ServiceUser serviceUser;
-
- /**
- * Sondage pour lequel l'utilisateur vote
- */
- @Persist
- private Poll poll;
- @Property
- private boolean pollNull;
+ @Inject
+ private ServiceVote serviceVote;
/** Compte du votant */
private PollAccount pollAccount;
@@ -976,11 +121,18 @@
/** Format des dates */
private DateFormat dateFormat;
+ @Persist
+ private VoteModel model;
+
/**
- * Méthode appelée au moment de l'activation de la page
+ * Address bar of the page. Display in Border layout component.
*
- * @param id l'identifiant du sondage et du votant
+ * @return the address bar of the page.
*/
+ public AddressBar getAddressBar() {
+ return AddressBar.newBar().appendCurrent(title);
+ }
+
void onActivate(EventContext ec) throws PollenBusinessException {
uri = ec.get(PollUri.class, 0);
if (ec.getCount() > 1) {
@@ -988,49 +140,54 @@
}
}
- /**
- * Méthode appelée au moment de la désactivation de la page
- *
- * @return l'identifiant du sondage et du votant
- */
Object[] onPassivate() {
return new Object[]{uri, page};
}
- /**
- * Initialisation de l'affichage
- */
+
@Log
void setupRender() {
- try {
- poll = null;
- getPoll();
-
- if (getPoll().getClosed()) {
- feedback.addInfo(messages.get("pollClosed"));
- } else if (!isPollStarted()) {
- feedback.addInfo(messages.get("pollNotStarted"));
- } else if (isPollFinished()) {
- feedback.addInfo(messages.get("pollFinished"));
+ if (uri == null) {
+ addFatal("Url null");
+ } else {
+ model = null;
+ try {
+ getModel().init(uri);
+ } catch (PollenBusinessException eee) {
+ // Poll not found
+ String message = manager.getErrorMessage(logger, messages, eee);
+ addFatal(message);
}
- if (isPollChoiceRunning()) {
- feedback.addInfo(messages.get("pollChoiceRunning"));
- }
-
- //countPoll();
- } catch (PollenBusinessException eee) {
- feedback.addError(messages.get(eee.getMessage()));
- pollNull = true;
}
+
+
+// try {
+// poll = null;
+// getPoll();
+//
+// if (getPoll().getClosed()) {
+// addInfo(messages.get("pollClosed"));
+// } else if (!isPollStarted()) {
+// addInfo(messages.get("pollNotStarted"));
+// } else if (isPollFinished()) {
+// addInfo(messages.get("pollFinished"));
+// }
+// if (isPollChoiceRunning()) {
+// addInfo(messages.get("pollChoiceRunning"));
+// }
+//
+// //countPoll();
+// } catch (PollenBusinessException eee) {
+// addError(messages.get(eee.getMessage()));
+// pollNull = true;
+// }
}
- /**
- * Address bar of the page. Display in Border layout component.
- *
- * @return the address bar of the page.
- */
- public AddressBar getAddress() {
- return AddressBar.newBar().appendCurrent(title);
+ public VoteModel getModel() {
+ if (model != null) {
+ model = new VoteModel(servicePoll, serviceVote);
+ }
+ return model;
}
/**
@@ -1046,40 +203,10 @@
return dateFormat;
}
- public Poll getPoll() throws PollenBusinessException {
- if (poll == null) {
- poll = servicePoll.getPollForVote(uri.getPollUid());
-
- if (poll != null) {
-
- // Initialisations pour les formulaires
-// newChoice = new ChoiceDTO();
-// newDateChoice = new DateChoiceUIO();
-// newImageChoice = new ImageChoiceUIO();
- } else {
- throw new PollenBusinessException(
- PollenExceptionType.POLL_NOT_EXIST);
- }
- }
- return poll;
+ public Poll getPoll() {
+ return getModel().getPoll();
}
- public boolean isPollStarted() throws PollenBusinessException {
- Date now = new Date();
- return getPoll().getBeginDate() == null ||
- getPoll().getBeginDate().before(now);
- }
-
- public boolean isPollFinished() throws PollenBusinessException {
- Date now = new Date();
- return getPoll().getEndDate() != null &&
- getPoll().getEndDate().before(now);
- }
-
- public boolean isPollRunning() throws PollenBusinessException {
- return isPollStarted() && !isPollFinished() && !getPoll().getClosed();
- }
-
/**
* Use a PollAccount to represent the current session user.
* The existing account is used if accountUid is present in the uri.
@@ -1089,34 +216,7 @@
* @return
*/
public PollAccount getPollAccount() throws PollenBusinessException {
- if (pollAccount == null) {
- // Identification du votant
- if (uri.getAccountUid() != null) {
- // pollAccount = serviceUser.getPerson(uri.getAccountUid());
-
-
-// pollAccountId = pollAccount.getId();
- }
-
- if (pollAccount == null) {
- // pollAccount = serviceUser.getNewPerson(getUserConnected());//new PollAccountDTO();
-
-
-// if (userExists) {
-// if (user.getFirstName() != null && user.getLastName() != null) {
-// pollAccount.setVotingId(
-// user.getFirstName() + " " + user.getLastName());
-//
-// } else if (user.getFirstName() != null) {
-// pollAccount.setVotingId(user.getFirstName());
-//
-// } else if (user.getLastName() != null) {
-// pollAccount.setVotingId(user.getLastName());
-// }
-// }
- }
- }
- return pollAccount;
+ return getModel().getPollAccount();
}
/**
@@ -1126,8 +226,7 @@
* @throws PollenBusinessException
*/
public boolean isCreatorUser() throws PollenBusinessException {
- return isUserConnected() && getUserConnected().equals(
- getPoll().getCreator().getUserAccount());
+ return isUserConnected() && getModel().isCreatorUser(getUserConnected());
}
/************** PAGER *****************************************************/
@@ -1227,8 +326,8 @@
*/
public List<ChoiceField> getChoices() throws PollenBusinessException {
if (choices == null) {
- if (log.isInfoEnabled()) {
- log.info("Prepare choices for render");
+ if (logger.isInfoEnabled()) {
+ logger.info("Prepare choices for render");
}
choices = new ArrayList<ChoiceField>();
for (Choice curr : getPoll().getChoice()) {
@@ -1236,8 +335,8 @@
choices.add(field);
}
}
- if (log.isDebugEnabled()) {
- log.debug("nb choices loaded : " + choices.size());
+ if (logger.isDebugEnabled()) {
+ logger.debug("nb choices loaded : " + choices.size());
}
return choices;
}
@@ -1457,8 +556,8 @@
// return getCurrentVote().getChoiceValue(choice.getId());
// }
- public boolean getCanVote() throws PollenBusinessException {
- return isPollRunning();
+ public boolean getCanVote() {
+ return getModel().isAllowedToVote();
}
public boolean canEditVote() throws PollenBusinessException {
@@ -1486,68 +585,70 @@
/************** COMMENTS **************************************************/
- @InjectComponent
- private Zone commentZone;
+ // TODO-fdesbois-2010-05-21 : create a component for comments
- private List<Comment> comments;
-
- /** Commentaire courant pour l'affichage des commentaires */
- @SuppressWarnings("unused")
- @Property
- @Persist
- private Comment comment;
-
- /** Nouveau commentaire posté */
- private Comment newComment;
-
- public List<Comment> getComments() throws PollenBusinessException {
- if (comments == null) {
- comments = servicePoll.getComments(poll, -1, -1);
- }
- return comments;
- }
-
- /**
- * Accessor for newComment property. Instantiate a new comment if needed.
- *
- * @return the current newComment.
- */
- public Comment getNewComment() {
- if (newComment == null) {
- newComment = new CommentImpl();
- }
- return newComment;
- }
-
- /**
- * ACTION EVENT :: delete a comment.
- *
- * @param commentId id of the comment to delete
- * @return the commentZone
- * @throws PollenBusinessException
- */
- Object onActionFromDeleteComment(String commentId) throws PollenBusinessException {
-// servicePoll.deleteComment(getPoll(), commentId);
- return commentZone.getBody();
- }
-
- /**
- * SUCCESS EVENT :: submit form for adding a new comment.
- *
- * @return the commentZone
- * @throws PollenBusinessException
- */
- @Log
- Object onSuccessFromCommentForm() throws PollenBusinessException {
- if (log.isDebugEnabled()) {
- log.debug("newComment author : " + getNewComment().getAuthor());
- log.debug("newComment text : " + getNewComment().getText());
- }
-// getNewComment().setPostDate(new Date());
-// servicePoll.createComment(getPoll(), getNewComment());
-// addFeedEntry(PollAction.ADDCOMMENT,
-// getNewComment().getAuthor(),
-// getNewComment().getText());
- return commentZone.getBody();
- }
+// @InjectComponent
+// private Zone commentZone;
+//
+// private List<Comment> comments;
+//
+// /** Commentaire courant pour l'affichage des commentaires */
+// @SuppressWarnings("unused")
+// @Property
+// @Persist
+// private Comment comment;
+//
+// /** Nouveau commentaire posté */
+// private Comment newComment;
+//
+// public List<Comment> getComments() throws PollenBusinessException {
+// if (comments == null) {
+// comments = servicePoll.getComments(poll, -1, -1);
+// }
+// return comments;
+// }
+//
+// /**
+// * Accessor for newComment property. Instantiate a new comment if needed.
+// *
+// * @return the current newComment.
+// */
+// public Comment getNewComment() {
+// if (newComment == null) {
+// newComment = new CommentImpl();
+// }
+// return newComment;
+// }
+//
+// /**
+// * ACTION EVENT :: delete a comment.
+// *
+// * @param commentId id of the comment to delete
+// * @return the commentZone
+// * @throws PollenBusinessException
+// */
+// Object onActionFromDeleteComment(String commentId) throws PollenBusinessException {
+//// servicePoll.deleteComment(getPoll(), commentId);
+// return commentZone.getBody();
+// }
+//
+// /**
+// * SUCCESS EVENT :: submit form for adding a new comment.
+// *
+// * @return the commentZone
+// * @throws PollenBusinessException
+// */
+// @Log
+// Object onSuccessFromCommentForm() throws PollenBusinessException {
+// if (logger.isDebugEnabled()) {
+// logger.debug("newComment author : " + getNewComment().getAuthor());
+// logger.debug("newComment text : " + getNewComment().getText());
+// }
+//// getNewComment().setPostDate(new Date());
+//// servicePoll.createComment(getPoll(), getNewComment());
+//// addFeedEntry(PollAction.ADDCOMMENT,
+//// getNewComment().getAuthor(),
+//// getNewComment().getText());
+// return commentZone.getBody();
+// }
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-05-25 09:29:17 UTC (rev 3011)
@@ -41,6 +41,8 @@
import org.chorem.pollen.service.ServicePollImpl;
import org.chorem.pollen.service.ServiceUser;
import org.chorem.pollen.service.ServiceUserImpl;
+import org.chorem.pollen.service.ServiceVote;
+import org.chorem.pollen.service.ServiceVoteImpl;
import org.chorem.pollen.ui.data.PollUri;
import org.nuiton.web.tapestry5.services.ServiceAuthentication;
import org.slf4j.Logger;
@@ -88,6 +90,12 @@
return service;
}
+ public static ServiceVote buildServiceVote(PollenManager manager) {
+ ServiceVoteImpl service = new ServiceVoteImpl();
+ service.setContext(manager.getContext());
+ return service;
+ }
+
public static ServiceEmail buildServiceEmail(PollenManager manager) {
ServiceEmailImpl service = new ServiceEmailImpl();
service.setContext(manager.getContext());
Modified: trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-05-21 11:59:50 UTC (rev 3010)
+++ trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-05-25 09:29:17 UTC (rev 3011)
@@ -1,12 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html t:type="border" t:addressBar="addressBar" t:pageLogo="literal:Vote" t:feedFilename="prop:uri.pollUid"
+ xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
-<t:border t:address="address.items" t:pageLogo="literal:Vote" t:feedFilename="prop:uri.pollUid"
- xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
-
- <t:feedback t:id="feedback"/>
- <t:unless test="pollNull">
+ <t:if test="poll">
<h1 class="titleVote">${poll.title}</h1>
-
<!-- Informations sur le sondage -->
<div id="pollTop">
${poll.description}
@@ -14,9 +13,9 @@
<legend>${message:about}</legend>
<div style="float: right">
<t:if test="poll.publicResults">
- <t:PageLink t:page="poll/Results" t:context="poll.pollUid">
+ <a t:type="pagelink" t:page="poll/Results" t:context="poll.pollUid">
<img src="${asset:context:img/count.png}" title="${message:results-help}" alt="${message:results}"/>
- </t:PageLink>
+ </a>
</t:if>
<t:FeedContextLink t:id="feedContext" />
<t:if test="feedFileExisting">
@@ -40,277 +39,277 @@
</fieldset>
</div>
- <t:if test="pollChoiceOrVoteStarted">
+ <!--<t:if test="pollChoiceOrVoteStarted">-->
- <!-- Sondage -->
+ <!--<!– Sondage –>-->
- <!--<t:zone t:id="pollZone" t:show="show" t:update="show">-->
- <t:if t:test="poll.anonymous">
- <p>${voteSizeMessage}</p>
- <t:feedback t:id="voteFeedback"/>
- <p:else>
- <t:pager t:nbRowsPerPage="nbVotesPerPage" t:nbTotalRows="poll.nbVotes"
- t:currentPage="page" t:noPagerText="prop:noPagerText" t:range="pagerRange"/>
- </p:else>
- </t:if>
- <t:form t:id="voteForm" t:zone="pollZone">
- <table id="poll">
- <thead>
- <tr>
- <t:if test="${AccountFieldDisplayed}">
- <th style="width:200px;">${message:voterName}</th>
- <p:else>
- <th></th>
- </p:else>
- </t:if>
- <th t:type="loop" t:source="choices" t:value="choice" t:volatile="true">
- <t:unless test="choice.hidden">
- <!-- Blocks for each choice type -->
- <t:block t:id="choiceText">
- <span class="desc">${choice.text}</span>
- </t:block>
- <t:block t:id="choiceImage">
- <a rel="lightbox[pollChoiceImages]" href="${imageLink}">
- <img src="${imageThumb}" alt="${choice.description}"/>
- </a>
- </t:block>
- <t:block t:id="choiceDate">
- <t:output value="choice.date" format="dateFormat"/>
- </t:block>
- <!-- Display choice with or whithout description -->
- <t:if t:test="choice.description">
- <span t:type="ck/Tooltip" t:value="choice.description" t:effect="blind">
- <t:delegate to="choiceBlock" />
- </span>
- <p:else>
- <t:delegate to="choiceBlock" />
- </p:else>
- </t:if>
- <t:if test="canDeleteChoice">
- <!-- Action to delete the choice -->
- <t:actionlink t:id="deleteChoice" context="choice.id"
- t:mixins="confirm" t:message="message:pollen.ui.choice.delete.confirm">
- <img src="${asset:context:img/delete.png}" title="message:pollen.ui.choice.delete.title"
- alt="message:pollen.ui.choice.delete.title"/>
- </t:actionlink>
- </t:if>
- </t:unless>
- </th>
- </tr>
- </thead>
- <t:if test="canVote">
- <tfoot>
- <tr>
- <t:if test="accountFieldDisplayed">
- <th id="voterName">
- <input t:type="textfield" t:id="pollAccountName" value="pollAccount.votingId" t:validate="required"/>
- </th>
- <p:else>
- <th></th>
- </p:else>
- </t:if>
- <t:loop t:source="choices" t:value="choice" volatile="true">
- <t:if test="!choice.hidden">
- <th>
- <t:if test="poll.voteCounting.normal">
- <input t:type="checkbox" value="addChoice" />
- </t:if>
- <t:if test="poll.voteCounting.percentage">
- <t:textField t:value="currentVote.getChoiceValues(choice.id)" size="3" t:validate="required, min=0, max=100"/>%
- </t:if>
- <t:if test="poll.voteCounting.condorcet">
- <t:textField t:id="condorcetInput" t:value="choiceOfVote.value" size="3" t:nulls="zero" t:validate="min=0, max=99"/>
- </t:if>
- <t:if test="poll.voteCounting.number">
- <t:textField t:value="addNumberVote" size="3" />
- </t:if>
- </th>
- </t:if>
- </t:loop>
- </tr>
- </tfoot>
- </t:if>
- <tbody>
- <t:unless t:test="poll.anonymous">
- <t:loop t:source="votes" t:value="vote" t:rowIndex="voteIndex" volatile="true">
- <tr>
- <td class="${evenodd.next}">
- <t:if test="${AccountFieldDisplayed}">
- <t:unless test="${currentVoteAnonymous}">
- ${vote.name}
- <p:else>
- ?
- </p:else>
- </t:unless>
- </t:if>
- <t:unless test="${poll.anonymous}">
- <t:if test="canEditVote()">
- <t:actionlink t:id="editVote" context="voteIndex" t:zone="pollZone">
- <img src="${asset:context:img/editSmall.png}" title="${message:edit}" alt="${message:edit}"/>
- </t:actionlink>
- </t:if>
- <t:if test="creatorUser">
- <t:actionlink t:id="deleteVote" context="vote.id" t:zone="pollZone">
- <img src="${asset:context:img/delete.png}" title="${message:delete}" alt="${message:delete}"/>
- </t:actionlink>
- </t:if>
- </t:unless>
- </td>
- <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
- <t:unless t:test="choiceHidden">
- ${setCurrentVoteChoice()}
- <t:if t:test="poll.anonymous">
- <td class="anonymous">?</td>
- <p:else>
- <t:if test="isNormalVoteCounting()">
- <t:if test="isChoiceInVote(currentVoteChoice)">
- <td class="voted">OK</td>
- <p:else>
- <td class="notVoted"></td>
- </p:else>
- </t:if>
- </t:if>
- <t:if test="isPercentageVoteCounting()">
- <t:if test="isChoiceInVote(currentVoteChoice)">
- <td class="voted">${currentVoteChoice.value} %</td>
- <p:else>
- <td class="notVoted"></td>
- </p:else>
- </t:if>
- </t:if>
- <t:if test="isCondorcetVoteCounting()">
- <t:if test="isChoiceInVote(currentVoteChoice)">
- <td class="voted">${currentVoteChoice.value}</td>
- <p:else>
- <td class="notVoted"></td>
- </p:else>
- </t:if>
- </t:if>
- <t:if test="isNumberVoteCounting()">
- <t:if test="isChoiceInVote(currentVoteChoice)">
- <td class="voted">${currentVoteChoice.value}</td>
- <p:else>
- <td class="notVoted"></td>
- </p:else>
- </t:if>
- </t:if>
- </p:else>
- </t:if>
- </t:unless>
- </t:loop>
- </tr>
- </t:loop>
- </t:unless>
- <t:if test="poll.continuousResults">
- <tr>
- <td>
- <t:PageLink t:page="poll/results" t:context="${poll.pollUid}">${message:results}</t:PageLink>
- </td>
- <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
- <t:if test="!isChoiceHidden()">
- <td class="result">${currentChoiceResult}</td>
- </t:if>
- </t:loop>
- </tr>
- </t:if>
- </tbody>
- </table>
- <div id="voteError">
- <t:errors/>
- </div>
- <t:if test="pollRunning">
- <div id="buttons">
- <t:if test="anonymousVoteDisplayed">
- <t:checkbox t:id="anonymousVote" t:value="anonymousVote" />
- <t:label for="anonymousVote" />
- <br/>
- </t:if>
- <input t:id="submitVote" t:type="Submit" t:value="${message:submitVote}" />
- </div>
- </t:if>
- </t:form>
- <!--</t:zone>-->
+ <!--<!–<t:zone t:id="pollZone" t:show="show" t:update="show">–>-->
+ <!--<t:if t:test="poll.anonymous">-->
+ <!--<p>${voteSizeMessage}</p>-->
+ <!--<t:feedback t:id="voteFeedback"/>-->
+ <!--<p:else>-->
+ <!--<t:pager t:nbRowsPerPage="nbVotesPerPage" t:nbTotalRows="poll.nbVotes"-->
+ <!--t:currentPage="page" t:noPagerText="prop:noPagerText" t:range="pagerRange"/>-->
+ <!--</p:else>-->
+ <!--</t:if>-->
+ <!--<t:form t:id="voteForm" t:zone="pollZone">-->
+ <!--<table id="poll">-->
+ <!--<thead>-->
+ <!--<tr>-->
+ <!--<t:if test="${AccountFieldDisplayed}">-->
+ <!--<th style="width:200px;">${message:voterName}</th>-->
+ <!--<p:else>-->
+ <!--<th></th>-->
+ <!--</p:else>-->
+ <!--</t:if>-->
+ <!--<th t:type="loop" t:source="choices" t:value="choice" t:volatile="true">-->
+ <!--<t:unless test="choice.hidden">-->
+ <!--<!– Blocks for each choice type –>-->
+ <!--<t:block t:id="choiceText">-->
+ <!--<span class="desc">${choice.text}</span>-->
+ <!--</t:block>-->
+ <!--<t:block t:id="choiceImage">-->
+ <!--<a rel="lightbox[pollChoiceImages]" href="${imageLink}">-->
+ <!--<img src="${imageThumb}" alt="${choice.description}"/>-->
+ <!--</a>-->
+ <!--</t:block>-->
+ <!--<t:block t:id="choiceDate">-->
+ <!--<t:output value="choice.date" format="dateFormat"/>-->
+ <!--</t:block>-->
+ <!--<!– Display choice with or whithout description –>-->
+ <!--<t:if t:test="choice.description">-->
+ <!--<span t:type="ck/Tooltip" t:value="choice.description" t:effect="blind">-->
+ <!--<t:delegate to="choiceBlock" />-->
+ <!--</span>-->
+ <!--<p:else>-->
+ <!--<t:delegate to="choiceBlock" />-->
+ <!--</p:else>-->
+ <!--</t:if>-->
+ <!--<t:if test="canDeleteChoice">-->
+ <!--<!– Action to delete the choice –>-->
+ <!--<t:actionlink t:id="deleteChoice" context="choice.id"-->
+ <!--t:mixins="confirm" t:message="message:pollen.ui.choice.delete.confirm">-->
+ <!--<img src="${asset:context:img/delete.png}" title="message:pollen.ui.choice.delete.title"-->
+ <!--alt="message:pollen.ui.choice.delete.title"/>-->
+ <!--</t:actionlink>-->
+ <!--</t:if>-->
+ <!--</t:unless>-->
+ <!--</th>-->
+ <!--</tr>-->
+ <!--</thead>-->
+ <!--<t:if test="canVote">-->
+ <!--<tfoot>-->
+ <!--<tr>-->
+ <!--<t:if test="accountFieldDisplayed">-->
+ <!--<th id="voterName">-->
+ <!--<input t:type="textfield" t:id="pollAccountName" value="pollAccount.votingId" t:validate="required"/>-->
+ <!--</th>-->
+ <!--<p:else>-->
+ <!--<th></th>-->
+ <!--</p:else>-->
+ <!--</t:if>-->
+ <!--<t:loop t:source="choices" t:value="choice" volatile="true">-->
+ <!--<t:if test="!choice.hidden">-->
+ <!--<th>-->
+ <!--<t:if test="poll.voteCounting.normal">-->
+ <!--<input t:type="checkbox" value="addChoice" />-->
+ <!--</t:if>-->
+ <!--<t:if test="poll.voteCounting.percentage">-->
+ <!--<t:textField t:value="currentVote.getChoiceValues(choice.id)" size="3" t:validate="required, min=0, max=100"/>%-->
+ <!--</t:if>-->
+ <!--<t:if test="poll.voteCounting.condorcet">-->
+ <!--<t:textField t:id="condorcetInput" t:value="choiceOfVote.value" size="3" t:nulls="zero" t:validate="min=0, max=99"/>-->
+ <!--</t:if>-->
+ <!--<t:if test="poll.voteCounting.number">-->
+ <!--<t:textField t:value="addNumberVote" size="3" />-->
+ <!--</t:if>-->
+ <!--</th>-->
+ <!--</t:if>-->
+ <!--</t:loop>-->
+ <!--</tr>-->
+ <!--</tfoot>-->
+ <!--</t:if>-->
+ <!--<tbody>-->
+ <!--<t:unless t:test="poll.anonymous">-->
+ <!--<t:loop t:source="votes" t:value="vote" t:rowIndex="voteIndex" volatile="true">-->
+ <!--<tr>-->
+ <!--<td class="${evenodd.next}">-->
+ <!--<t:if test="${AccountFieldDisplayed}">-->
+ <!--<t:unless test="${currentVoteAnonymous}">-->
+ <!--${vote.name}-->
+ <!--<p:else>-->
+ <!--?-->
+ <!--</p:else>-->
+ <!--</t:unless>-->
+ <!--</t:if>-->
+ <!--<t:unless test="${poll.anonymous}">-->
+ <!--<t:if test="canEditVote()">-->
+ <!--<t:actionlink t:id="editVote" context="voteIndex" t:zone="pollZone">-->
+ <!--<img src="${asset:context:img/editSmall.png}" title="${message:edit}" alt="${message:edit}"/>-->
+ <!--</t:actionlink>-->
+ <!--</t:if>-->
+ <!--<t:if test="creatorUser">-->
+ <!--<t:actionlink t:id="deleteVote" context="vote.id" t:zone="pollZone">-->
+ <!--<img src="${asset:context:img/delete.png}" title="${message:delete}" alt="${message:delete}"/>-->
+ <!--</t:actionlink>-->
+ <!--</t:if>-->
+ <!--</t:unless>-->
+ <!--</td>-->
+ <!--<t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">-->
+ <!--<t:unless t:test="choiceHidden">-->
+ <!--${setCurrentVoteChoice()}-->
+ <!--<t:if t:test="poll.anonymous">-->
+ <!--<td class="anonymous">?</td>-->
+ <!--<p:else>-->
+ <!--<t:if test="isNormalVoteCounting()">-->
+ <!--<t:if test="isChoiceInVote(currentVoteChoice)">-->
+ <!--<td class="voted">OK</td>-->
+ <!--<p:else>-->
+ <!--<td class="notVoted"></td>-->
+ <!--</p:else>-->
+ <!--</t:if>-->
+ <!--</t:if>-->
+ <!--<t:if test="isPercentageVoteCounting()">-->
+ <!--<t:if test="isChoiceInVote(currentVoteChoice)">-->
+ <!--<td class="voted">${currentVoteChoice.value} %</td>-->
+ <!--<p:else>-->
+ <!--<td class="notVoted"></td>-->
+ <!--</p:else>-->
+ <!--</t:if>-->
+ <!--</t:if>-->
+ <!--<t:if test="isCondorcetVoteCounting()">-->
+ <!--<t:if test="isChoiceInVote(currentVoteChoice)">-->
+ <!--<td class="voted">${currentVoteChoice.value}</td>-->
+ <!--<p:else>-->
+ <!--<td class="notVoted"></td>-->
+ <!--</p:else>-->
+ <!--</t:if>-->
+ <!--</t:if>-->
+ <!--<t:if test="isNumberVoteCounting()">-->
+ <!--<t:if test="isChoiceInVote(currentVoteChoice)">-->
+ <!--<td class="voted">${currentVoteChoice.value}</td>-->
+ <!--<p:else>-->
+ <!--<td class="notVoted"></td>-->
+ <!--</p:else>-->
+ <!--</t:if>-->
+ <!--</t:if>-->
+ <!--</p:else>-->
+ <!--</t:if>-->
+ <!--</t:unless>-->
+ <!--</t:loop>-->
+ <!--</tr>-->
+ <!--</t:loop>-->
+ <!--</t:unless>-->
+ <!--<t:if test="poll.continuousResults">-->
+ <!--<tr>-->
+ <!--<td>-->
+ <!--<t:PageLink t:page="poll/results" t:context="${poll.pollUid}">${message:results}</t:PageLink>-->
+ <!--</td>-->
+ <!--<t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">-->
+ <!--<t:if test="!isChoiceHidden()">-->
+ <!--<td class="result">${currentChoiceResult}</td>-->
+ <!--</t:if>-->
+ <!--</t:loop>-->
+ <!--</tr>-->
+ <!--</t:if>-->
+ <!--</tbody>-->
+ <!--</table>-->
+ <!--<div id="voteError">-->
+ <!--<t:errors/>-->
+ <!--</div>-->
+ <!--<t:if test="poll.running">-->
+ <!--<div id="buttons">-->
+ <!--<t:if test="anonymousVoteDisplayed">-->
+ <!--<t:checkbox t:id="anonymousVote" t:value="anonymousVote" />-->
+ <!--<t:label for="anonymousVote" />-->
+ <!--<br/>-->
+ <!--</t:if>-->
+ <!--<input t:id="submitVote" t:type="Submit" t:value="${message:submitVote}" />-->
+ <!--</div>-->
+ <!--</t:if>-->
+ <!--</t:form>-->
+ <!--<!–</t:zone>–>-->
- <!-- Ajout de choix -->
- <!--<t:ImageContextLink t:id="imgContext" t:thumb="true" t:dir="poll.pollUid"/>-->
- <t:if test="canAddChoice">
- <h4>${message:pollen.ui.choice.add.title}</h4>
- <div id="choiceFormDiv">
- <t:form t:id="addChoice">
- <t:if t:test="newChoice.type.date">
- <label t:type="label" for="choiceDate" />*<br />
- <input t:type="ck/dateTimeField" t:id="choiceDate" value="newChoice.date"
- t:timePicker="true" t:timePickerAdjacent="true" t:validate="required, regexp"
- t:datePattern="message:pollen.ui.choice.datePattern"/>
- </t:if>
- <t:if t:test="newChoice.type.image">
- <label t:type="label" for="choiceImage" />*<br />
- <input t:type="upload" t:id="choiceImage" t:value="newChoice.image" t:validate="required, regexp" />
- </t:if>
- <t:if t:test="newChoice.type.text">
- <label t:type="label" for="choiceText" />*<br />
- <input t:type="textfield" t:id="choiceText" value="newChoice.text" t:validate="required"/>
- </t:if>
-<!-- <t:delegate t:to="newChoiceBlock" /><br />
- <t:block t:id="newChoiceDate">
- <label t:type="label" for="choiceDate" />*<br />
- <input t:type="ck/dateTimeField" t:id="choiceDate" value="newChoice.date"
- t:timePicker="true" t:timePickerAdjacent="true" t:validate="required, regexp"
- t:datePattern="message:pollen.ui.choice.datePattern"/>
- </t:block>
- <t:block t:id="newChoiceImage">
- <label t:type="label" for="choiceImage" />*<br />
- <input t:type="upload" t:id="choiceImage" t:value="newChoice.image" t:validate="required, regexp" />
- </t:block>
- <t:block t:id="newChoiceText">
- <label t:type="label" for="choiceText" />*<br />
- <input t:type="textfield" t:id="choiceText" value="newChoice.text" t:validate="required"/>
- </t:block>-->
- <label t:type="label" for="choiceDescription" /><br />
- <input t:type="textfield" t:id="choiceDescription" value="newChoice.description" />
- <input t:type="submit" value="message:pollen.ui.choice.add.submit" />
- </t:form>
- </div>
- </t:if>
+ <!--<!– Ajout de choix –>-->
+ <!--<!–<t:ImageContextLink t:id="imgContext" t:thumb="true" t:dir="poll.pollUid"/>–>-->
+ <!--<t:if test="canAddChoice">-->
+ <!--<h4>${message:pollen.ui.choice.add.title}</h4>-->
+ <!--<div id="choiceFormDiv">-->
+ <!--<t:form t:id="addChoice">-->
+ <!--<t:if t:test="newChoice.type.date">-->
+ <!--<label t:type="label" for="choiceDate" />*<br />-->
+ <!--<input t:type="ck/dateTimeField" t:id="choiceDate" value="newChoice.date"-->
+ <!--t:timePicker="true" t:timePickerAdjacent="true" t:validate="required, regexp"-->
+ <!--t:datePattern="message:pollen.ui.choice.datePattern"/>-->
+ <!--</t:if>-->
+ <!--<t:if t:test="newChoice.type.image">-->
+ <!--<label t:type="label" for="choiceImage" />*<br />-->
+ <!--<input t:type="upload" t:id="choiceImage" t:value="newChoice.image" t:validate="required, regexp" />-->
+ <!--</t:if>-->
+ <!--<t:if t:test="newChoice.type.text">-->
+ <!--<label t:type="label" for="choiceText" />*<br />-->
+ <!--<input t:type="textfield" t:id="choiceText" value="newChoice.text" t:validate="required"/>-->
+ <!--</t:if>-->
+<!--<!– <t:delegate t:to="newChoiceBlock" /><br />-->
+ <!--<t:block t:id="newChoiceDate">-->
+ <!--<label t:type="label" for="choiceDate" />*<br />-->
+ <!--<input t:type="ck/dateTimeField" t:id="choiceDate" value="newChoice.date"-->
+ <!--t:timePicker="true" t:timePickerAdjacent="true" t:validate="required, regexp"-->
+ <!--t:datePattern="message:pollen.ui.choice.datePattern"/>-->
+ <!--</t:block>-->
+ <!--<t:block t:id="newChoiceImage">-->
+ <!--<label t:type="label" for="choiceImage" />*<br />-->
+ <!--<input t:type="upload" t:id="choiceImage" t:value="newChoice.image" t:validate="required, regexp" />-->
+ <!--</t:block>-->
+ <!--<t:block t:id="newChoiceText">-->
+ <!--<label t:type="label" for="choiceText" />*<br />-->
+ <!--<input t:type="textfield" t:id="choiceText" value="newChoice.text" t:validate="required"/>-->
+ <!--</t:block>–>-->
+ <!--<label t:type="label" for="choiceDescription" /><br />-->
+ <!--<input t:type="textfield" t:id="choiceDescription" value="newChoice.description" />-->
+ <!--<input t:type="submit" value="message:pollen.ui.choice.add.submit" />-->
+ <!--</t:form>-->
+ <!--</div>-->
+ <!--</t:if>-->
<!-- Ajout de commentaires -->
- <h3>${message:comments}</h3>
- <t:zone t:id="commentZone" show="show" update="show">
- <div id="commentsDiv">
- <div t:type="loop" t:source="comments" t:value="comment" class="${evenodd.next}">
- <t:if test="creatorUser">
- <span class="cmd">
- <t:actionlink t:id="deleteComment" context="comment.id" t:zone="commentZone">
- <img src="${asset:context:img/delete.png}" title="${message:delete}" alt="${message:delete}"/>
- </t:actionlink>
- </span>
- </t:if>
- <span class="name">${comment.author}</span> :
- <span class="date">
- <t:output value="comment.postDate" format="dateFormat"/>
- </span>
- <t:textOutput value="${comment.text}" />
- </div>
- </div>
- <div id="commentFormDiv">
- <t:form t:id="commentForm" t:zone="commentZone" t:volatile="true">
- <t:label for="commenterName" />
- <br/>
- <t:textField t:value="newComment.author" t:id="commenterName"
- t:validate="required" />
- <br/>
- <t:label for="commentArea" />
- <br/>
- <t:textArea t:value="newComment.text" t:id="commentArea"
- t:validate="required" />
- <br/>
- <t:Submit t:id="submitComment" t:value="${message:submitComment}" />
- </t:form>
- </div>
- </t:zone>
+ <!--<h3>${message:comments}</h3>-->
+ <!--<t:zone t:id="commentZone" show="show" update="show">-->
+ <!--<div id="commentsDiv">-->
+ <!--<div t:type="loop" t:source="comments" t:value="comment" class="${evenodd.next}">-->
+ <!--<t:if test="creatorUser">-->
+ <!--<span class="cmd">-->
+ <!--<t:actionlink t:id="deleteComment" context="comment.id" t:zone="commentZone">-->
+ <!--<img src="${asset:context:img/delete.png}" title="${message:delete}" alt="${message:delete}"/>-->
+ <!--</t:actionlink>-->
+ <!--</span>-->
+ <!--</t:if>-->
+ <!--<span class="name">${comment.author}</span> :-->
+ <!--<span class="date">-->
+ <!--<t:output value="comment.postDate" format="dateFormat"/>-->
+ <!--</span>-->
+ <!--<t:textOutput value="${comment.text}" />-->
+ <!--</div>-->
+ <!--</div>-->
+ <!--<div id="commentFormDiv">-->
+ <!--<t:form t:id="commentForm" t:zone="commentZone" t:volatile="true">-->
+ <!--<t:label for="commenterName" />-->
+ <!--<br/>-->
+ <!--<t:textField t:value="newComment.author" t:id="commenterName"-->
+ <!--t:validate="required" />-->
+ <!--<br/>-->
+ <!--<t:label for="commentArea" />-->
+ <!--<br/>-->
+ <!--<t:textArea t:value="newComment.text" t:id="commentArea"-->
+ <!--t:validate="required" />-->
+ <!--<br/>-->
+ <!--<t:Submit t:id="submitComment" t:value="${message:submitComment}" />-->
+ <!--</t:form>-->
+ <!--</div>-->
+ <!--</t:zone>-->
- </t:if>
- </t:unless>
-</t:border>
\ No newline at end of file
+ <!--</t:if>-->
+ </t:if>
+</html>
\ No newline at end of file
1
0
r3010 - in trunk/pollen-ui/src/main/java/org/chorem/pollen/ui: components pages/admin pages/poll pages/user
by fdesbois@users.chorem.org 21 May '10
by fdesbois@users.chorem.org 21 May '10
21 May '10
Author: fdesbois
Date: 2010-05-21 13:59:50 +0200 (Fri, 21 May 2010)
New Revision: 3010
Url: http://chorem.org/repositories/revision/pollen/3010
Log:
Replace 'Handler' by 'Callback' in javadoc for onSomething methods
Modified:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsCreate.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsCreate.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsCreate.java 2010-05-21 11:56:38 UTC (rev 3009)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsCreate.java 2010-05-21 11:59:50 UTC (rev 3010)
@@ -57,7 +57,7 @@
private Form createList;
/**
- * SETUP_RENDER :: Handler method called when the component is rendered.
+ * SETUP_RENDER :: Callback method called when the component is rendered.
* Will clean errors from {@code createList} form.
*/
void setupRender() {
@@ -65,7 +65,7 @@
}
/**
- * ON_PREPARE :: Handler method for both prepareRender and prepareSubmit
+ * ON_PREPARE :: Callback method for both prepareRender and prepareSubmit
* events of {@code createList} form. Will instantiate a new instance
* of FavoriteList using {@code serviceFavorite} and user connected.
*
@@ -82,7 +82,7 @@
}
/**
- * ON_VALIDATE_FORM :: Handler method for validateForm event of the
+ * ON_VALIDATE_FORM :: Callback method for validateForm event of the
* {@code createList} form. The {@code newFavoriteList} will be created
* using {@code serviceFavorite}. Errors from service will be recorded
* into the {@code createList} form.
@@ -108,7 +108,7 @@
}
/**
- * ON_SUCCESS :: Handler method for success event of the {@code createList}
+ * ON_SUCCESS :: Callback method for success event of the {@code createList}
* form. Will display a success message and refresh the {@code page}
* container.
*/
@@ -119,7 +119,7 @@
}
/**
- * ON_FAILURE :: Handler method for failure event of the {@code createList}
+ * ON_FAILURE :: Callback method for failure event of the {@code createList}
* form. Will refresh the form (included in a zone} to display errors.
*/
Object onFailureFromCreateList() {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java 2010-05-21 11:56:38 UTC (rev 3009)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java 2010-05-21 11:59:50 UTC (rev 3010)
@@ -132,7 +132,7 @@
}
/**
- * ON_ACTION :: Handler method for action on editParticipant actionLink. The
+ * ON_ACTION :: Callback method for action on editParticipant actionLink. The
* participantEdited will be set to the participant selected in the Grid
* with {@code id}.
*
@@ -148,7 +148,7 @@
}
/**
- * ON_ACTION :: Handler method for action on cancelEdition actionLink.
+ * ON_ACTION :: Callback method for action on cancelEdition actionLink.
* Simply refresh the zone will change edition mode.
*
* @return the updateZone content to refresh
@@ -158,7 +158,7 @@
}
/**
- * ON_ACTION :: Handler method for action on removeParticipant actionLink.
+ * ON_ACTION :: Callback method for action on removeParticipant actionLink.
* The selected id from the Grid will be used to delete the participant.
*
* @param id used to delete the participant
@@ -195,7 +195,7 @@
}
/**
- * ON_VALIDATE_FORM :: Handler method for validateForm event of the
+ * ON_VALIDATE_FORM :: Callback method for validateForm event of the
* participantsForm. The participantEdited will be updated using
* serviceFavorite. Errors from service will be recorded into the
* participantsForm.
@@ -217,7 +217,7 @@
}
/**
- * ON_SUCCESS :: Handler method for success event of the participantsForm.
+ * ON_SUCCESS :: Callback method for success event of the participantsForm.
* Clean form data (participantEdited) and display a success message. {@link
* #onSubmitFromParticipantsForm()} will be called after it to refresh the
* updateZone.
@@ -239,7 +239,7 @@
}
/**
- * ON_SUBMIT :: Handler method for submit event called after succes or
+ * ON_SUBMIT :: Callback method for submit event called after succes or
* failure of the participantsForm. Will refresh the updateZone to display
* errors or Grid updated.
*
@@ -258,7 +258,7 @@
private Form addParticipant;
/**
- * ON_PREPARE :: Handler method for both prepareSubmit and prepareRender
+ * ON_PREPARE :: Callback method for both prepareSubmit and prepareRender
* events of the participantsForm. Will instantiate a new
* FavoriteParticipant to render or saved with form data.
*
@@ -272,7 +272,7 @@
}
/**
- * ON_VALIDATE_FORM :: Handler method for validateForm event of the
+ * ON_VALIDATE_FORM :: Callback method for validateForm event of the
* addParticipant form. The newParticipant will be created using
* serviceFavorite. Errors from service will be recorded into the
* addParticipant form.
@@ -293,7 +293,7 @@
}
/**
- * ON_SUCCESS :: Handler method for success event of the addParticipant
+ * ON_SUCCESS :: Callback method for success event of the addParticipant
* form. Will display a success message. {@link #onSubmitFromAddParticipant()}
* will be called after it to refresh the updateZone.
*/
@@ -304,7 +304,7 @@
}
/**
- * ON_SUBMIT :: Handler method for submit event called after succes or
+ * ON_SUBMIT :: Callback method for submit event called after succes or
* failure of the addParticipant form. Will refresh the updateZone to
* display errors or Grid updated.
*
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java 2010-05-21 11:56:38 UTC (rev 3009)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java 2010-05-21 11:59:50 UTC (rev 3010)
@@ -147,7 +147,7 @@
}
/**
- * ON_ACTION :: Handler method for action on editAccount actionLink. The
+ * ON_ACTION :: Callback method for action on editAccount actionLink. The
* accountEdited will be set to the user selected in the Grid with {@code
* login}.
*
@@ -163,7 +163,7 @@
}
/**
- * ON_ACTION :: Handler method for action on deletedAccount actionLink. The
+ * ON_ACTION :: Callback method for action on deletedAccount actionLink. The
* selected login from the Grid will be used to delete the user.
*
* @param login used to delete the user
@@ -174,7 +174,7 @@
}
/**
- * ON_PREPARE_FOR_SUBMIT :: Handler method for prepareSubmit event of the
+ * ON_PREPARE_FOR_SUBMIT :: Callback method for prepareSubmit event of the
* usersForm. The accountEdited will be initialized to properly be saved in
* {@link #onValidateFormFromUsersForm()}
*/
@@ -185,7 +185,7 @@
}
/**
- * ON_VALIDATE_FORM :: Handler method for validateForm event of the
+ * ON_VALIDATE_FORM :: Callback method for validateForm event of the
* usersForm. The accountEdited will be updated using serviceUser. Errors
* from service will be recorded into the usersForm.
*
@@ -202,7 +202,7 @@
}
/**
- * ON_SUCCESS :: Handler method for success event of the usersForm. No error
+ * ON_SUCCESS :: Callback method for success event of the usersForm. No error
* occurs from validation, a message will be displayed to client.
*
* @return the current page to refresh
@@ -213,7 +213,7 @@
}
/**
- * ON_FAILURE :: Handler method for failure event of the usersForm. Errors
+ * ON_FAILURE :: Callback method for failure event of the usersForm. Errors
* were recorded into the usersForm. The usersForm will be refresh to
* display error messages.
*
@@ -243,7 +243,7 @@
private String newPassword;
/**
- * ON_PREPARE :: Handler method for prepare events of the newUserForm. The
+ * ON_PREPARE :: Callback method for prepare events of the newUserForm. The
* newUser will be initialized if needed before render and before submit.
*/
public void onPrepareFromNewUserForm() {
@@ -253,7 +253,7 @@
}
/**
- * ON_VALIDATE_FORM :: Handler method for validateForm event of the
+ * ON_VALIDATE_FORM :: Callback method for validateForm event of the
* newUserForm. The newUser will be created using serviceUser. Errors from
* service will be recorded into the newUserForm. The password will be
* generated if an email is set into the form. Otherwise the password will
@@ -292,7 +292,7 @@
}
/**
- * ON_SUCCESS :: Handler method for success event of the newUserForm. No
+ * ON_SUCCESS :: Callback method for success event of the newUserForm. No
* error occurs from validation, success message is displayed to client and
* an email is sent to the newUser created if it's defined. The persist
* fields of the page will be discarded to refresh the grid with no order or
@@ -335,7 +335,7 @@
}
/**
- * ON_FAILURE :: Handler method for failure event of the newUserForm. Errors
+ * ON_FAILURE :: Callback method for failure event of the newUserForm. Errors
* were recorded into the newUserForm. The newUserForm will be refresh to
* display error messages.
*
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-21 11:56:38 UTC (rev 3009)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-21 11:59:50 UTC (rev 3010)
@@ -590,7 +590,7 @@
private ServicePollUri servicePollUri;
/**
- * ON_SELECTED:: Handler method for all submit actions. Will reset refreshing
+ * ON_SELECTED:: Callback method for all submit actions. Will reset refreshing
* zones flags used for subForm components.
*/
@Log
@@ -600,7 +600,7 @@
}
/**
- * ON_SELECTED:: Handler method for action on choiceStep submit button. Will
+ * ON_SELECTED:: Callback method for action on choiceStep submit button. Will
* change the view and display the choice formFragment of the pollForm.
* Note : maybe validations will be needed in this case (use edited flag).
*/
@@ -611,7 +611,7 @@
}
/**
- * ON_SELECTED:: Handler method for action on mainStep submit button. Will
+ * ON_SELECTED:: Callback method for action on mainStep submit button. Will
* change the view and display the main formFragment of the pollForm.
* This is a previous action after being on choices.
*/
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java 2010-05-21 11:56:38 UTC (rev 3009)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java 2010-05-21 11:59:50 UTC (rev 3010)
@@ -149,7 +149,7 @@
}
/**
- * ON_ACTION :: Handler method for action on {@code deleteList} actionLink.
+ * ON_ACTION :: Callback method for action on {@code deleteList} actionLink.
* Check is done using {@link #canDeleteList()}, then the {@code
* serviceFavorite} is called to execute the delete on {@code
* favoriteListSelected}.
1
0
Author: fdesbois
Date: 2010-05-21 13:56:38 +0200 (Fri, 21 May 2010)
New Revision: 3009
Url: http://chorem.org/repositories/revision/pollen/3009
Log:
- Add javadoc
- Change signature of getErrorMessage from PollenManager
- Refactor exceptions managment by ErrorReport in PollFormModel validations
- Extract sendEmail method for creator from onSuccess callback
Modified:
trunk/pollen-business/src/main/xmi/pollen.zargo
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsCreate.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/Connection.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserProfile.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserRegister.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java
trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -282,7 +282,7 @@
feedback.addInfo(messages.get("loginOk"));
} catch (PollenBusinessException eee) {
feedback.addError(
- manager.getErrorMessage(eee, messages, logger));
+ manager.getErrorMessage(logger, messages, eee));
}
}
return this;
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsCreate.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsCreate.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsCreate.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -11,6 +11,8 @@
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenBusinessException.PollenExceptionType;
import org.chorem.pollen.entity.FavoriteList;
+import org.chorem.pollen.entity.FavoriteParticipant;
+import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.service.ServiceFavorite;
import org.chorem.pollen.ui.base.PollenPage;
import org.chorem.pollen.ui.services.PollenManager;
@@ -91,7 +93,7 @@
try {
serviceFavorite.createFavoriteList(newFavoriteList);
} catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
+ String message = manager.getErrorMessage(logger, messages, eee);
if (logger.isDebugEnabled()) {
logger.debug(message);
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -210,8 +210,9 @@
try {
serviceFavorite.updateFavoriteParticipant(participantEdited);
} catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
- participantsForm.recordError(message);
+// String message = manager.getErrorMessage(eee, messages, logger);
+// participantsForm.recordError(message);
+ manager.recordFormError(logger, messages, eee, participantsForm);
}
}
@@ -285,8 +286,9 @@
try {
serviceFavorite.createFavoriteParticipant(newParticipant);
} catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
- addParticipant.recordError(message);
+// String message = manager.getErrorMessage(eee, messages, logger);
+// addParticipant.recordError(message);
+ manager.recordFormError(logger, messages, eee, participantsForm);
}
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -11,7 +11,7 @@
import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.service.ServicePoll;
import org.chorem.pollen.ui.data.ChoiceField;
-import org.chorem.pollen.ui.data.FieldValidationException;
+import org.chorem.pollen.ui.data.ErrorReport;
import org.chorem.pollen.ui.pages.poll.PollForm;
import org.chorem.pollen.ui.services.PollenManager;
import org.chorem.pollen.ui.services.ServiceImage;
@@ -90,11 +90,14 @@
/**
* Initialize the poll using an {@code uid} for an existing poll or the
* current {@code user} connected if he exists as the creator of a new
- * poll.
+ * poll with {@code createMode} flag set.
*
- * @param uid Unique id of an existing poll (can be null for a new poll)
- * @param user Connected user as creator of a new poll (can be null if no
- * user is connected).
+ * @param servicePoll Service used to retrieve an existing poll based on
+ * {@code uid} or instantiate a new one.
+ * @param uid Unique id of an existing poll (can be null for a new
+ * poll)
+ * @param user Connected user as creator of a new poll (can be null
+ * if no user is connected).
*/
public void initPoll(ServicePoll servicePoll, String uid, UserAccount user) {
if (StringUtils.isNotEmpty(uid)) {
@@ -322,7 +325,8 @@
poll = servicePoll.createPoll(poll, getLists());
}
- public void validate(Messages messages) throws FieldValidationException {
+ public ErrorReport validate(Messages messages) {
+ ErrorReport report = new ErrorReport();
// Initialize beginDate if needed
Date beginDate = poll.getBeginDate();
@@ -334,9 +338,11 @@
// Check endDate
Date endDate = poll.getEndDate();
if (endDate != null && endDate.before(beginDate)) {
- throw new FieldValidationException(
- PollForm.FORM_FIELD_END_DATE,
+ report.recordFieldError(PollForm.FORM_FIELD_END_DATE,
"error endDate before beginDate");
+// throw new FieldValidationException(
+// PollForm.FORM_FIELD_END_DATE,
+// "error endDate before beginDate");
}
// Add choices is allowed after creation
@@ -351,23 +357,28 @@
// Check beginChoiceDate
if (endDate != null && beginChoiceDate.after(endDate)) {
- throw new FieldValidationException(
- PollForm.FORM_FIELD_BEGIN_CHOICE_DATE,
+ report.recordFieldError(PollForm.FORM_FIELD_BEGIN_CHOICE_DATE,
"error beginChoiceDate after endDate");
+// throw new FieldValidationException(
+// PollForm.FORM_FIELD_BEGIN_CHOICE_DATE,
+// "error beginChoiceDate after endDate");
}
// Check endChoiceDate
Date endChoiceDate = poll.getEndChoiceDate();
if (endChoiceDate != null && endChoiceDate.before(beginChoiceDate)) {
- throw new FieldValidationException(
- PollForm.FORM_FIELD_END_CHOICE_DATE,
+ report.recordFieldError(PollForm.FORM_FIELD_END_CHOICE_DATE,
"error endChoiceDate before beginChoiceDate");
+// throw new FieldValidationException(
+// PollForm.FORM_FIELD_END_CHOICE_DATE,
+// "error endChoiceDate before beginChoiceDate");
}
}
- // TODO-fdesbois-2010-05-20 : change exceptions by ErrorReport
// validation rules :
// - not allowed to save poll without choice if addChoiceAllowed is false
+
+ return report;
}
/**
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/Connection.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/Connection.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/Connection.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -100,9 +100,9 @@
}
} catch (PollenBusinessException eee) {
// TODO two different errors, on password or on login
- //addError(messages.get("loginFailed"));
- String message = manager.getErrorMessage(eee, messages, logger);
- loginForm.recordError(message);
+// String message = manager.getErrorMessage(eee, messages, logger);
+// loginForm.recordError(message);
+ manager.recordFormError(logger, messages, eee, loginForm);
}
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -195,8 +195,9 @@
try {
serviceUser.updateUser(accountEdited, true);
} catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
- usersForm.recordError(message);
+// String message = manager.getErrorMessage(eee, messages, logger);
+// usersForm.recordError(message);
+ manager.recordFormError(logger, messages, eee, usersForm);
}
}
@@ -279,7 +280,7 @@
serviceUser.createUser(newUser);
addInfo(passwordInfo);
} catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
+ String message = manager.getErrorMessage(logger, messages, eee);
switch (eee.getType()) {
case USER_EMAIL_EXIST:
newUserForm.recordError(newEmail, message);
@@ -320,7 +321,7 @@
newUser.getLogin(), newUser.getEmail()));
} catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
+ String message = manager.getErrorMessage(logger, messages, eee);
addError(message);
addInfo(messages.format(
"pollen.ui.user.create.emailFailedShowPassword",
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -14,6 +14,7 @@
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
+import org.apache.tapestry5.corelib.components.Select;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
@@ -39,6 +40,7 @@
import org.chorem.pollen.ui.components.Border;
import org.chorem.pollen.ui.data.AddressBar;
import org.chorem.pollen.ui.data.ChoiceField;
+import org.chorem.pollen.ui.data.ErrorReport;
import org.chorem.pollen.ui.data.FieldValidationException;
import org.chorem.pollen.ui.data.PollUri;
import org.chorem.pollen.ui.models.ParticipantListModel;
@@ -117,6 +119,19 @@
@InjectComponent
private Form mainForm;
+ private enum PollStep {
+ MAIN, CHOICES;
+ }
+
+ /** Current step of the Form */
+ private PollStep step;
+
+ /**
+ * Flag to detect an internal edition in the form. Use when submit
+ * actions are triggered from all buttons except the save one.
+ */
+ private boolean edited;
+
void onActivate(String id) {
pollUID = id;
}
@@ -379,7 +394,7 @@
/** Flag if submit comes from lists edition */
private boolean editLists;
- protected static final String EVENT_UPDATE_POLL_TYPE = "updatePollType";
+ protected static final String EVENT_UPDATE_POLL_TYPE = "updateFromPollType";
/** DATA ** */
@@ -422,7 +437,7 @@
}
@Log
- Object onUpdatePollType(String value) {
+ Object onUpdateFromPollType(String value) {
getModel().setPollType(servicePoll, manager, PollType.valueOf(value));
return refreshListZone();
}
@@ -469,7 +484,7 @@
try {
getModel().setCurrentList(manager, listName);
} catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
+ String message = manager.getErrorMessage(logger, messages, eee);
listsFeedback.addError(message);
}
}
@@ -495,12 +510,13 @@
return listsZone.getBody();
}
- /** ********************** CHOIX **************************************** */
+ /** ********************** CHOICES ************************************** */
- @Property
- private ChoiceField choice;
+ @Inject
+ private ServiceImage serviceImage;
- private List<ChoiceField> choices;
+ @InjectComponent
+ private Zone choicesZone;
@Inject
private Block choiceText;
@@ -511,30 +527,19 @@
@Inject
private Block choiceImage;
- private boolean refresh;
+ @Property
+ private ChoiceField choice;
+ @Property
+ private boolean refreshChoicesZone;
+
/**
* Get choices from poll if it exists or initialized 4 choices with the
- * default type : TEXT. TODO-fdesbois-2010-05-19 : put this treatment in
- * PollFormModel
+ * default type : TEXT.
*
* @return a list of ChoiceDTO
*/
public List<ChoiceField> getChoices() throws PollenBusinessException {
-// if (choices == null) {
-// choices = new ArrayList<ChoiceField>();
-// if (isCreateMode()) {
-// // Initialized to choice TEXT type
-// for (int i = 0; i < 4; i++) {
-// choices.add(ChoiceField.getChoiceText());
-// }
-// } else {
-// for (Choice current : getPoll().getChoice()) {
-// choices.add(new ChoiceField(getPoll(), current));
-// }
-// }
-// }
-// return choices;
return getModel().getChoices();
}
@@ -549,44 +554,67 @@
}
}
- private enum PollStep {
-
- MAIN, CHOICES;
+ @Log
+ Object onChangeFromChoiceType(String value) {
+ ChoiceType type = ChoiceType.valueOf(value);
+ getPoll().setChoiceType(type);
+ refreshChoicesZone = true;
+ return choicesZone.getBody();
}
- private PollStep step;
+ /** ********************** NAVIGATION/SUBMISSION ************************ */
- private boolean edited;
+ /** Service used to retrieve Field components from their ids */
+ @Inject
+ private ComponentSource componentSource;
- @Property
- private boolean refreshChoicesZone;
+ /** Form fields used for validation */
+ public static final String FORM_FIELD_BEGIN_DATE = "beginDate";
- @InjectComponent
- private Zone choicesZone;
+ public static final String FORM_FIELD_END_DATE = "endDate";
+ public static final String FORM_FIELD_BEGIN_CHOICE_DATE = "beginChoiceDate";
+
+ public static final String FORM_FIELD_END_CHOICE_DATE = "endChoiceDate";
+
+ /** Resulting page after success submission */
+ @InjectPage
+ private PollLinks pollLinks;
+
+ /** Service to send email after success */
@Inject
- private ServiceImage serviceImage;
+ private ServiceEmail serviceEmail;
- @Log
- Object onChangeFromChoiceType(String value) {
- ChoiceType type = ChoiceType.valueOf(value);
- getPoll().setChoiceType(type);
- refreshChoicesZone = true;
- return choicesZone.getBody();
- }
+ /** Service to manage uris used in emails sent */
+ @Inject
+ private ServicePollUri servicePollUri;
+ /**
+ * ON_SELECTED:: Handler method for all submit actions. Will reset refreshing
+ * zones flags used for subForm components.
+ */
@Log
void onSelected() {
refreshListsZone = false;
refreshChoicesZone = false;
}
+ /**
+ * ON_SELECTED:: Handler method for action on choiceStep submit button. Will
+ * change the view and display the choice formFragment of the pollForm.
+ * Note : maybe validations will be needed in this case (use edited flag).
+ */
@Log
void onSelectedFromChoiceStep() {
step = PollStep.CHOICES;
edited = true;
}
+ /**
+ * ON_SELECTED:: Handler method for action on mainStep submit button. Will
+ * change the view and display the main formFragment of the pollForm.
+ * This is a previous action after being on choices.
+ */
@Log
void onSelectedFromMainStep() {
step = PollStep.MAIN;
@@ -601,86 +629,40 @@
return step.equals(PollStep.MAIN);
}
- @Inject
- private ComponentSource componentSource;
-
- public static final String FORM_FIELD_BEGIN_DATE = "beginDate";
-
- public static final String FORM_FIELD_END_DATE = "endDate";
-
- public static final String FORM_FIELD_BEGIN_CHOICE_DATE = "beginChoiceDate";
-
- public static final String FORM_FIELD_END_CHOICE_DATE = "endChoiceDate";
-
@Log
void onValidateForm() {
if (!edited) {
- // Need validations on dates
- try {
- getModel().validate(messages);
- getModel().create(servicePoll, serviceImage);
- } catch (FieldValidationException eee) {
- manager.recordFormError(eee, mainForm, componentSource);
- } catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
- mainForm.recordError(message);
+ // Validate data
+ ErrorReport report = getModel().validate(messages);
+ // Record errors if report is not empty
+ if (report.hasErrors()) {
+ manager.recordFormErrors(componentSource, report, mainForm);
+ } else {
+ // Execute create for business save in database
+ try {
+ getModel().create(servicePoll, serviceImage);
+ } catch (PollenBusinessException eee) {
+ manager.recordFormError(logger, messages, eee, mainForm);
+ }
}
}
}
- @Inject
- private PageRenderLinkSource linkSource;
-
- private Link successLink;
-
- @InjectPage
- private PollLinks pollLinks;
-
- @Inject
- private ServiceEmail serviceEmail;
-
- @Inject
- private ServicePollUri servicePollUri;
-
-// public void prepareSuccessLinks(Poll newPoll) {
-// String creatorUid = newPoll.getCreator().getUid();
-// String pollUid = newPoll.getUid();
-// PollUri uri = servicePollUri.getNewPollUri(creatorUid, pollUid);
-//// successLink = linkSource.createPageRenderLinkWithContext(
-//// PollLinks.class, uri);
-// pollLinks.setPollUri(uri);
-// }
-
@Log
Object onSuccess() {
if (!edited) {
+ pollLinks.addInfo("Sauvegarde OK !");
PollAccount creator = getPoll().getCreator();
PollUri uri = servicePollUri.getNewPollUri(creator.getUid(),
getPoll().getUid());
pollLinks.setPollUri(uri);
- pollLinks.addInfo("Sauvegarde OK !");
+ // Send an email to the creator
if (creator.getEmail() != null) {
- pollLinks.addInfo("Vous avez recu un mail !");
- PollenEmail email = new PollenEmailImpl();
- email.setTo(creator.getEmail());
- email.setSubject(messages.format(
- "pollen.email.createPoll.subject",
- getPoll().getTitle()));
- email.setContent(messages.format(
- "pollen.email.createPoll.content",
- getPoll().getTitle(),
- servicePollUri.getVoteUrl(uri),
- servicePollUri.getModerateVoteUrl(uri),
- servicePollUri.getPollUpdateUrl(uri)));
- try {
- serviceEmail.sendEmail(email);
- } catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
- addError(message);
+ if (!sendCreatorEmail(creator, uri)) {
return mainZone;
}
- } else {
- // TODO-fdesbois-2010-05-20 : display a pretty message for this case : the links page need to be keeped by user
+ } else {
+ pollLinks.addInfo("pollen.ui.poll.links.creatorEmail.notDefined");
}
if (getPoll().getPollType().isRestrictedOrGroup()) {
pollLinks.addInfo("Les votants ont reçu un mail !");
@@ -690,6 +672,29 @@
return mainZone;
}
+ protected boolean sendCreatorEmail(PollAccount creator, PollUri uri) {
+ PollenEmail email = new PollenEmailImpl();
+ email.setTo(creator.getEmail());
+ email.setSubject(messages.format(
+ "pollen.email.createPoll.subject",
+ getPoll().getTitle()));
+ email.setContent(messages.format(
+ "pollen.email.createPoll.content",
+ getPoll().getTitle(),
+ servicePollUri.getVoteUrl(uri),
+ servicePollUri.getModerateVoteUrl(uri),
+ servicePollUri.getPollUpdateUrl(uri)));
+ try {
+ serviceEmail.sendEmail(email);
+ pollLinks.addInfo("pollen.ui.poll.links.creatorEmail.success");
+ } catch (PollenBusinessException eee) {
+ String message = manager.getErrorMessage(logger, messages, eee);
+ addError(message);
+ return false;
+ }
+ return true;
+ }
+
@Log
Object onFailure() {
return mainZone;
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -25,6 +25,7 @@
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.services.PropertyAccess;
import org.chorem.pollen.entity.FavoriteList;
+import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.service.ServiceFavorite;
import org.chorem.pollen.ui.base.AbstractPollenPage;
import org.chorem.pollen.ui.components.Border;
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserProfile.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserProfile.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserProfile.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -133,10 +133,10 @@
/**
* ON_VALIDATE_FORM :: <br \>
* UI validation : check if the two passwords are equals. <br \>
- * BUSINESS validation : execute {@link ServiceUser#updateUser(UserAccount) }
+ * BUSINESS validation : execute {@link ServiceUser#updateUser(UserAccount,boolean) }
* which throws errors
- * {@link PollenBusinessException.PollenExceptionType.USER_WRONG_PASSWORD}
- * and {@link PollenBusinessException.PollenExceptionType.USER_EMAIL_EXIST}.
+ * {@link PollenBusinessException.PollenExceptionType#USER_WRONG_PASSWORD}
+ * and {@link PollenBusinessException.PollenExceptionType#USER_EMAIL_EXIST}.
*/
@Log
void onValidateFormFromAccountForm() {
@@ -159,7 +159,7 @@
}
serviceUser.updateUser(user, false);
} catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
+ String message = manager.getErrorMessage(logger, messages, eee);
switch (eee.getType()) {
case USER_WRONG_PASSWORD:
accountForm.recordError(passwordField, message); break;
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserRegister.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserRegister.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserRegister.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -132,8 +132,8 @@
* UI validation : check if the two passwords are equals. <br \>
* BUSINESS validation : execute {@link ServiceUser#createUser(UserAccount)}
* which throws errors
- * {@link PollenBusinessException.PollenExceptionType.USER_LOGIN_EXIST}
- * and {@link PollenBusinessException.PollenExceptionType.USER_EMAIL_EXIST}.
+ * {@link PollenBusinessException.PollenExceptionType#USER_LOGIN_EXIST}
+ * and {@link PollenBusinessException.PollenExceptionType#USER_EMAIL_EXIST}.
*/
void onValidateFormFromRegister() {
// Check newPassword that must be equals to passwordVerify
@@ -153,7 +153,7 @@
// Saving new user
serviceUser.createUser(newUser);
} catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
+ String message = manager.getErrorMessage(logger, messages, eee);
switch (eee.getType()) {
case USER_EMAIL_EXIST:
register.recordError(emailField, message); break;
@@ -199,7 +199,7 @@
newUser.getEmail()));
} catch (PollenBusinessException eee) {
- String message = manager.getErrorMessage(eee, messages, logger);
+ String message = manager.getErrorMessage(logger, messages, eee);
index.addError(message);
}
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -24,6 +24,8 @@
import org.apache.tapestry5.Field;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.OrderedConfiguration;
+import org.apache.tapestry5.ioc.services.RegistryShutdownHub;
import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
import org.apache.tapestry5.ioc.services.SymbolProvider;
import org.apache.tapestry5.ioc.util.CaseInsensitiveMap;
@@ -34,7 +36,6 @@
import org.chorem.pollen.PollenProperty;
import org.chorem.pollen.service.ServiceUser;
import org.chorem.pollen.ui.data.ErrorReport;
-import org.chorem.pollen.ui.data.FieldValidationException;
import org.nuiton.util.ApplicationConfig;
import org.slf4j.Logger;
@@ -44,23 +45,31 @@
import java.util.Properties;
/**
- * WaoManager
+ * This service contains the main {@link PollenContext} for business. This is
+ * the service that start and stop the business part of the application. For
+ * this, PollenManager was registered in Tapestry as a {@link
+ * RegistryShutdownListener} to stop the context and contribute to registry
+ * startup from {@link AppModule#contributeRegistryStartup(OrderedConfiguration,
+ * ServiceUser, PollenManager, RegistryShutdownHub)}. The application {@code
+ * context} was not visible for pages, this service use delegation for needed
+ * methods from {@code context}.
* <p/>
+ * This service is also used to manage errors from {@link
+ * PollenBusinessException} that contains i18n keys for messages. Traductions are
+ * made via Tapestry global catalog messages ({@code app.properties}). But you
+ * need to write messages in {@code resources/i18n/pollen-ui.properties}. A
+ * maven goal is used to merge i18n messages from business (and libs) and ui
+ * into the main Tapestry catalog {@code app.properties}
+ * <p/>
* Created: 24 nov. 2009
*
* @author fdesbois
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$
- * par : $Author$
+ * @version $Id$
*/
public class PollenManager implements Runnable,
RegistryShutdownListener,
SymbolProvider {
-// private static final Logger logger =
-// LoggerFactory.getLogger(PollenManager.class);
-
private final Map<String, String> propertiesMap =
new CaseInsensitiveMap<String>();
@@ -69,7 +78,8 @@
private ServiceUser serviceUser;
/**
- * Constructor of WaoManager. It needs the WaoContext to start and stop.
+ * Constructor of PollenManager. It needs the PollenContext to start and
+ * stop.
*
* @param context used to manage application lifecycle
*/
@@ -129,8 +139,17 @@
return context.createPollenUrlId();
}
- public String getErrorMessage(PollenBusinessException error,
- Messages messages, Logger logger) {
+ /**
+ * Retrieve an error message from business {@code error} exception. Will
+ * used {@code messages} and {@code logger} services.
+ *
+ * @param logger Service to log error message from business
+ * @param messages Service to retrieve messages from i18n catalog
+ * @param error Exception to treate
+ * @return the error message to display
+ */
+ public String getErrorMessage(Logger logger, Messages messages,
+ PollenBusinessException error) {
if (logger.isDebugEnabled()) {
logger.debug("ERROR from business : " + error.getMessage() +
" _ args = " + Arrays.toString(error.getArgs()));
@@ -144,23 +163,44 @@
return message;
}
- public void recordFormError(FieldValidationException error,
- Form form, ComponentSource componentSource)
- throws ClassCastException {
- if (error.getField() == null) {
- form.recordError(error.getMessage());
- } else {
- Field field = getFieldByName(error.getField(), componentSource);
- form.recordError(field, error.getMessage());
- }
+ /**
+ * Record a business {@code error} exception into a {@code form}. Will used
+ * {@code messages} and {@code logger} services.
+ *
+ * @param logger Service to log error message from business
+ * @param messages Service to retrieve messages from i18n catalog
+ * @param error Exception to treate
+ * @param form Form where error need to be recorded
+ * @see #getErrorMessage(Logger, Messages, PollenBusinessException)
+ */
+ public void recordFormError(Logger logger, Messages messages,
+ PollenBusinessException error,
+ Form form) {
+ String message = getErrorMessage(logger, messages, error);
+ form.recordError(message);
}
- public void recordFormErrors(ErrorReport report,
- Form form, ComponentSource componentSource)
- throws ClassCastException {
+ /**
+ * Record ui errors (from validation) defined in {@code report} into a
+ * {@code form}. Will used {@code componentSource} service.
+ *
+ * @param componentSource Service to retrieve Field components from their
+ * ids
+ * @param report ErrorReport that contains errors
+ * @param form Form where errors need to be recorded
+ * @throws ClassCastException when {@code componentSource} doesn't
+ * find the right component based on field
+ * ids in {@code report}.
+ * @throws IllegalArgumentException when no field component was found based
+ * on field ids in {@code report}.
+ */
+ public void recordFormErrors(ComponentSource componentSource,
+ ErrorReport report,
+ Form form)
+ throws ClassCastException, IllegalArgumentException {
for (Map.Entry<String, String> entry : report.getFieldErrors().entrySet()) {
- Field field = getFieldByName(entry.getKey(), componentSource);
+ Field field = getFieldByName(componentSource, entry.getKey());
form.recordError(field, entry.getValue());
}
for (String message : report.getErrors()) {
@@ -168,9 +208,24 @@
}
}
- protected Field getFieldByName(String field, ComponentSource componentSource)
- throws ClassCastException {
+// public void recordFormError(FieldValidationException error,
+// Form form, ComponentSource componentSource)
+// throws ClassCastException {
+// if (error.getField() == null) {
+// form.recordError(error.getMessage());
+// } else {
+// Field field = getFieldByName(error.getField(), componentSource);
+// form.recordError(field, error.getMessage());
+// }
+// }
+
+ protected Field getFieldByName(ComponentSource componentSource, String field)
+ throws ClassCastException, IllegalArgumentException {
Component component = componentSource.getComponent(field);
+ if (component == null) {
+ throw new IllegalArgumentException("no field component was found" +
+ " with id " + field);
+ }
if (!(component instanceof Field)) {
throw new ClassCastException("invalid cast to Field from : " +
component.getClass().getName());
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -2,34 +2,98 @@
import org.apache.tapestry5.Link;
import org.apache.tapestry5.services.PageRenderLinkSource;
+import org.chorem.pollen.ui.components.Border;
import org.chorem.pollen.ui.data.PollUri;
-import org.chorem.pollen.ui.pages.poll.PollForm;
-import org.chorem.pollen.ui.pages.poll.VoteForPoll;
/**
+ * Service used to manage PollUri in application. The contextPath is needed to
+ * retrieve proper urls from uri, but to retrieve Tapestry links, only {@link
+ * PageRenderLinkSource} service is used. The links will be used in Tapestry
+ * templates, and full urls will be used for emails.
+ * <p/>
* Created: 20 mai 2010
*
* @author fdesbois <fdesbois(a)codelutin.com>
* @version $Id$
+ * @see PollUri
+ * @see ServicePollUriImpl
*/
public interface ServicePollUri {
+ /**
+ * Retrieve link for poll update page.
+ *
+ * @param uri PollUri that contains pollUid and creatorUid
+ * @return the Link to used for poll update page
+ */
Link getPollUpdateLink(PollUri uri);
+ /**
+ * Retrieve link for vote page.
+ *
+ * @param uri PollUri that contains pollUid (accountUid is not necessary)
+ * @return the Link to used for vote page
+ */
Link getVoteLink(PollUri uri);
+ /**
+ * Retrieve link for moderation on vote page.
+ *
+ * @param uri PollUri that contains pollUid and creatorUid (moderator)
+ * @return the Link to used for moderation on vote page
+ */
Link getModerateVoteLink(PollUri uri);
+ /**
+ * Retrieve url for poll update page.
+ *
+ * @param uri PollUri that contains pollUid and creatorUid
+ * @return the full url to used for poll update page
+ */
String getPollUpdateUrl(PollUri uri);
+ /**
+ * Retrieve url for vote page.
+ *
+ * @param uri PollUri that contains pollUid (accountUid is not necessary)
+ * @return the full url to used for vote page
+ */
String getVoteUrl(PollUri uri);
+ /**
+ * Retrieve url for moderation on vote page.
+ *
+ * @param uri PollUri that contains pollUid and creatorUid (moderator)
+ * @return the full url to used for moderation on vote page
+ */
String getModerateVoteUrl(PollUri uri);
+ /**
+ * Retrieve a new instance of PollUri with {@code accountUid} and {@code
+ * pollUid} initialized.
+ *
+ * @param accountUid Unique id of the account for the uri
+ * @param pollUid Unique id of the poll for the uri
+ * @return a new PollUri
+ */
PollUri getNewPollUri(String accountUid, String pollUid);
+ /**
+ * Retrieve a new instance of PollUri based on string {@code uri} that
+ * contains both account and poll uid necessary.
+ *
+ * @param uri Full uri as a String
+ * @return a new PollUri
+ */
PollUri getNewPollUri(String uri);
+ /**
+ * Injector for contextPath used for urls. This method need to be called
+ * before retrieving urls. The {@link Border} layout will do this job on
+ * page render.
+ *
+ * @param contextPath Context path of the current server
+ */
void setContextPath(String contextPath);
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java 2010-05-21 11:56:38 UTC (rev 3009)
@@ -14,10 +14,17 @@
*/
public class ServicePollUriImpl implements ServicePollUri {
+ /** Service used to create links */
private PageRenderLinkSource linkSource;
+ /** Context path of the current server used to create urls */
private String contextPath;
+ /**
+ * Constructor of ServicePollUriImpl.
+ *
+ * @param linkSource Service used to create links.
+ */
public ServicePollUriImpl(PageRenderLinkSource linkSource) {
this.linkSource = linkSource;
}
Modified: trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-05-20 17:54:37 UTC (rev 3008)
+++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-05-21 11:56:38 UTC (rev 3009)
@@ -76,6 +76,8 @@
pollen.ui.poll.links.editPage=Lien d'acc\u00e8s \u00e0 la modification du sondage :
pollen.ui.poll.links.register=Si vous \u00eates un utilisateur identifi\u00e9, vous pouvez retrouver ces liens dans la page
pollen.ui.poll.links.myPolls=Mes sondages
+pollen.ui.poll.links.creatorEmail.success=Un email vous a \u00e9t\u00e9 envoy\u00e9 avec les liens ci-dessous.
+pollen.ui.poll.links.creatorEmail.notDefined=Aucun email n'a \u00e9t\u00e9 d\u00e9fini \u00e0 la cr\u00e9ation du sondage, vous devriez enregistrer cette page dans vos favoris pour ne pas perdre les liens.
# OLD LOGIN_COMPONENT
1
0
r3008 - in trunk/pollen-ui/src/main: java/org/chorem/pollen/ui/components java/org/chorem/pollen/ui/models java/org/chorem/pollen/ui/pages/poll resources/org/chorem/pollen/ui/components
by fdesbois@users.chorem.org 20 May '10
by fdesbois@users.chorem.org 20 May '10
20 May '10
Author: fdesbois
Date: 2010-05-20 19:54:37 +0200 (Thu, 20 May 2010)
New Revision: 3008
Url: http://chorem.org/repositories/revision/pollen/3008
Log:
- Add some notes
- Change restriction for email on UserLists -> email is required. It's pretty tricky to check if user has email on poll creation (what can we do about accountUid on each participant ?)
Modified:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/UserListsUpdate.tml
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-05-20 17:36:51 UTC (rev 3007)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-05-20 17:54:37 UTC (rev 3008)
@@ -182,7 +182,7 @@
} else {
logo = "pollen" + pageLogo + "_en.png";
}
-
+ // Initialize contextPath for servicePollUri
servicePollUri.setContextPath(getServerPath());
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-20 17:36:51 UTC (rev 3007)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-20 17:54:37 UTC (rev 3008)
@@ -364,6 +364,10 @@
"error endChoiceDate before beginChoiceDate");
}
}
+
+ // TODO-fdesbois-2010-05-20 : change exceptions by ErrorReport
+ // validation rules :
+ // - not allowed to save poll without choice if addChoiceAllowed is false
}
/**
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-20 17:36:51 UTC (rev 3007)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-20 17:54:37 UTC (rev 3008)
@@ -679,6 +679,8 @@
addError(message);
return mainZone;
}
+ } else {
+ // TODO-fdesbois-2010-05-20 : display a pretty message for this case : the links page need to be keeped by user
}
if (getPoll().getPollType().isRestrictedOrGroup()) {
pollLinks.addInfo("Les votants ont reçu un mail !");
Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/UserListsUpdate.tml
===================================================================
--- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/UserListsUpdate.tml 2010-05-20 17:36:51 UTC (rev 3007)
+++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/UserListsUpdate.tml 2010-05-20 17:54:37 UTC (rev 3008)
@@ -26,7 +26,7 @@
</p:nameCell>
<p:emailCell>
<t:if t:test="editionMode">
- <input t:type="textfield" t:id="editEmail" value="participantEdited.email" t:validate="regexp" size="15" />
+ <input t:type="textfield" t:id="editEmail" value="participantEdited.email" t:validate="required,regexp" size="15" />
<p:else>${participant.email}</p:else>
</t:if>
</p:emailCell>
1
0
r3007 - in trunk/pollen-ui/src/main: java/org/chorem/pollen/ui/base java/org/chorem/pollen/ui/components java/org/chorem/pollen/ui/data java/org/chorem/pollen/ui/pages/poll java/org/chorem/pollen/ui/services resources/i18n
by fdesbois@users.chorem.org 20 May '10
by fdesbois@users.chorem.org 20 May '10
20 May '10
Author: fdesbois
Date: 2010-05-20 19:36:51 +0200 (Thu, 20 May 2010)
New Revision: 3007
Url: http://chorem.org/repositories/revision/pollen/3007
Log:
Create service to manage PollUri
Added:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java
Modified:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/AbstractPollenPage.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/AbstractPollenPage.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/AbstractPollenPage.java 2010-05-20 16:50:54 UTC (rev 3006)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/AbstractPollenPage.java 2010-05-20 17:36:51 UTC (rev 3007)
@@ -4,6 +4,7 @@
import org.apache.tapestry5.ioc.annotations.Inject;
import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.ui.components.Border;
+import org.chorem.pollen.ui.services.ServicePollUri;
import org.nuiton.web.tapestry5.services.ServiceAuthentication;
/**
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-05-20 16:50:54 UTC (rev 3006)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-05-20 17:36:51 UTC (rev 3007)
@@ -41,6 +41,7 @@
import org.chorem.pollen.ui.data.AddressBar;
import org.chorem.pollen.ui.pages.Index;
import org.chorem.pollen.ui.services.PollenManager;
+import org.chorem.pollen.ui.services.ServicePollUri;
import org.nuiton.web.tapestry5.components.FeedBack;
import org.nuiton.web.tapestry5.services.ServiceAuthentication;
import org.slf4j.Logger;
@@ -58,6 +59,9 @@
@Inject
private Logger logger;
+ @Inject
+ private ServicePollUri servicePollUri;
+
/**
* Chaine définissant le style de la page
*/
@@ -178,6 +182,8 @@
} else {
logo = "pollen" + pageLogo + "_en.png";
}
+
+ servicePollUri.setContextPath(getServerPath());
}
boolean afterRender() {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java 2010-05-20 16:50:54 UTC (rev 3006)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java 2010-05-20 17:36:51 UTC (rev 3007)
@@ -20,7 +20,7 @@
protected String accountUid;
- protected PollUri() {
+ public PollUri() {
}
@@ -32,23 +32,14 @@
// }
// }
- public static PollUri newUri(String stringUri) {
- PollUri uri = new PollUri();
+ public void setUri(String stringUri) {
String[] tab = stringUri.split(SEPARATOR);
- uri.setPollUid(tab[0]);
+ setPollUid(tab[0]);
if (tab.length == 2) {
- uri.setAccountUid(tab[1]);
+ setAccountUid(tab[1]);
}
- return uri;
}
- public static PollUri newUri(String accountUid, String pollUid) {
- PollUri uri = new PollUri();
- uri.setAccountUid(accountUid);
- uri.setPollUid(pollUid);
- return uri;
- }
-
public String getAccountUid() {
return accountUid;
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-20 16:50:54 UTC (rev 3006)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-20 17:36:51 UTC (rev 3007)
@@ -21,6 +21,8 @@
import org.apache.tapestry5.services.ComponentSource;
import org.apache.tapestry5.services.PageRenderLinkSource;
import org.chorem.pollen.PollenBusinessException;
+import org.chorem.pollen.bean.PollenEmail;
+import org.chorem.pollen.bean.PollenEmailImpl;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
@@ -31,6 +33,7 @@
import org.chorem.pollen.entity.PreventRule;
import org.chorem.pollen.entity.PreventRuleImpl;
import org.chorem.pollen.mail.PreventRuleManager;
+import org.chorem.pollen.service.ServiceEmail;
import org.chorem.pollen.service.ServicePoll;
import org.chorem.pollen.ui.base.AbstractPollenPage;
import org.chorem.pollen.ui.components.Border;
@@ -42,6 +45,7 @@
import org.chorem.pollen.ui.models.PollFormModel;
import org.chorem.pollen.ui.services.PollenManager;
import org.chorem.pollen.ui.services.ServiceImage;
+import org.chorem.pollen.ui.services.ServicePollUri;
import org.nuiton.web.tapestry5.components.FeedBack;
import org.slf4j.Logger;
@@ -632,23 +636,49 @@
@InjectPage
private PollLinks pollLinks;
- public void prepareSuccessLinks(Poll newPoll) {
- String creatorUid = newPoll.getCreator().getUid();
- String pollUid = newPoll.getUid();
- PollUri uri = PollUri.newUri(creatorUid, pollUid);
-// successLink = linkSource.createPageRenderLinkWithContext(
-// PollLinks.class, uri);
- pollLinks.setPollUri(uri);
- }
+ @Inject
+ private ServiceEmail serviceEmail;
+ @Inject
+ private ServicePollUri servicePollUri;
+
+// public void prepareSuccessLinks(Poll newPoll) {
+// String creatorUid = newPoll.getCreator().getUid();
+// String pollUid = newPoll.getUid();
+// PollUri uri = servicePollUri.getNewPollUri(creatorUid, pollUid);
+//// successLink = linkSource.createPageRenderLinkWithContext(
+//// PollLinks.class, uri);
+// pollLinks.setPollUri(uri);
+// }
+
@Log
Object onSuccess() {
if (!edited) {
PollAccount creator = getPoll().getCreator();
- PollUri uri = PollUri.newUri(creator.getUid(), getPoll().getUid());
+ PollUri uri = servicePollUri.getNewPollUri(creator.getUid(),
+ getPoll().getUid());
+ pollLinks.setPollUri(uri);
pollLinks.addInfo("Sauvegarde OK !");
if (creator.getEmail() != null) {
- pollLinks.addInfo("Vous avez recu un mail !");
+ pollLinks.addInfo("Vous avez recu un mail !");
+ PollenEmail email = new PollenEmailImpl();
+ email.setTo(creator.getEmail());
+ email.setSubject(messages.format(
+ "pollen.email.createPoll.subject",
+ getPoll().getTitle()));
+ email.setContent(messages.format(
+ "pollen.email.createPoll.content",
+ getPoll().getTitle(),
+ servicePollUri.getVoteUrl(uri),
+ servicePollUri.getModerateVoteUrl(uri),
+ servicePollUri.getPollUpdateUrl(uri)));
+ try {
+ serviceEmail.sendEmail(email);
+ } catch (PollenBusinessException eee) {
+ String message = manager.getErrorMessage(eee, messages, logger);
+ addError(message);
+ return mainZone;
+ }
}
if (getPoll().getPollType().isRestrictedOrGroup()) {
pollLinks.addInfo("Les votants ont reçu un mail !");
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java 2010-05-20 16:50:54 UTC (rev 3006)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java 2010-05-20 17:36:51 UTC (rev 3007)
@@ -10,6 +10,7 @@
import org.chorem.pollen.ui.components.Border;
import org.chorem.pollen.ui.data.AddressBar;
import org.chorem.pollen.ui.data.PollUri;
+import org.chorem.pollen.ui.services.ServicePollUri;
import org.slf4j.Logger;
/**
@@ -45,7 +46,7 @@
}
@Inject
- private PageRenderLinkSource linkSource;
+ private ServicePollUri servicePollUri;
private Poll poll;
@@ -83,23 +84,16 @@
return poll;
}
- public Link getPollLink() {
- Link link = linkSource.createPageRenderLinkWithContext(
- PollForm.class, pollUri);
- return link;
- }
-
public Link getVoteLink() {
- PollUri voteUri = PollUri.newUri(null, pollUri.getPollUid());
- Link link = linkSource.createPageRenderLinkWithContext(
- VoteForPoll.class, voteUri);
- return link;
+ return servicePollUri.getVoteLink(pollUri);
}
public Link getModerateVoteLink() {
- Link link = linkSource.createPageRenderLinkWithContext(
- VoteForPoll.class, pollUri);
- return link;
+ return servicePollUri.getModerateVoteLink(pollUri);
}
+ public Link getPollLink() {
+ return servicePollUri.getPollUpdateLink(pollUri);
+ }
+
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-05-20 16:50:54 UTC (rev 3006)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-05-20 17:36:51 UTC (rev 3007)
@@ -29,6 +29,7 @@
import org.apache.tapestry5.services.ApplicationStateCreator;
import org.apache.tapestry5.services.ApplicationStateManager;
import org.apache.tapestry5.services.ComponentRequestFilter;
+import org.apache.tapestry5.services.PageRenderLinkSource;
import org.apache.tapestry5.upload.services.UploadSymbols;
import org.chorem.pollen.PollenContextImpl;
import org.chorem.pollen.entity.UserAccount;
@@ -97,6 +98,11 @@
return new ServiceImageImpl(manager.getContext());
}
+ public static ServicePollUri buildServicePollUri(
+ PageRenderLinkSource linkSource) {
+ return new ServicePollUriImpl(linkSource);
+ }
+
public ServiceAuthentication<UserAccount> buildServiceAuthentication(
ApplicationStateManager stateManager) {
ServiceAuthentication<UserAccount> instance =
@@ -187,7 +193,9 @@
@Override
public PollUri coerce(String input) {
- return PollUri.newUri(input);
+ PollUri uri = new PollUri();
+ uri.setUri(input);
+ return uri;
}
};
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java 2010-05-20 17:36:51 UTC (rev 3007)
@@ -0,0 +1,35 @@
+package org.chorem.pollen.ui.services;
+
+import org.apache.tapestry5.Link;
+import org.apache.tapestry5.services.PageRenderLinkSource;
+import org.chorem.pollen.ui.data.PollUri;
+import org.chorem.pollen.ui.pages.poll.PollForm;
+import org.chorem.pollen.ui.pages.poll.VoteForPoll;
+
+/**
+ * Created: 20 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public interface ServicePollUri {
+
+ Link getPollUpdateLink(PollUri uri);
+
+ Link getVoteLink(PollUri uri);
+
+ Link getModerateVoteLink(PollUri uri);
+
+ String getPollUpdateUrl(PollUri uri);
+
+ String getVoteUrl(PollUri uri);
+
+ String getModerateVoteUrl(PollUri uri);
+
+ PollUri getNewPollUri(String accountUid, String pollUid);
+
+ PollUri getNewPollUri(String uri);
+
+ void setContextPath(String contextPath);
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUri.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java 2010-05-20 17:36:51 UTC (rev 3007)
@@ -0,0 +1,82 @@
+package org.chorem.pollen.ui.services;
+
+import org.apache.tapestry5.Link;
+import org.apache.tapestry5.services.PageRenderLinkSource;
+import org.chorem.pollen.ui.data.PollUri;
+import org.chorem.pollen.ui.pages.poll.PollForm;
+import org.chorem.pollen.ui.pages.poll.VoteForPoll;
+
+/**
+ * Created: 20 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class ServicePollUriImpl implements ServicePollUri {
+
+ private PageRenderLinkSource linkSource;
+
+ private String contextPath;
+
+ public ServicePollUriImpl(PageRenderLinkSource linkSource) {
+ this.linkSource = linkSource;
+ }
+
+ @Override
+ public Link getPollUpdateLink(PollUri uri) {
+ Link link = linkSource.createPageRenderLinkWithContext(
+ PollForm.class, uri);
+ return link;
+ }
+
+ @Override
+ public Link getVoteLink(PollUri uri) {
+ PollUri voteUri = getNewPollUri(null, uri.getPollUid());
+ Link link = linkSource.createPageRenderLinkWithContext(
+ VoteForPoll.class, voteUri);
+ return link;
+ }
+
+ @Override
+ public Link getModerateVoteLink(PollUri uri) {
+ Link link = linkSource.createPageRenderLinkWithContext(
+ VoteForPoll.class, uri);
+ return link;
+ }
+
+ @Override
+ public String getPollUpdateUrl(PollUri uri) {
+ return contextPath + getPollUpdateLink(uri);
+ }
+
+ @Override
+ public String getVoteUrl(PollUri uri) {
+ return contextPath + getVoteLink(uri);
+ }
+
+ @Override
+ public String getModerateVoteUrl(PollUri uri) {
+ return contextPath + getModerateVoteLink(uri);
+ }
+
+ @Override
+ public PollUri getNewPollUri(String accountUid, String pollUid) {
+ PollUri pollUri = new PollUri();
+ pollUri.setAccountUid(accountUid);
+ pollUri.setPollUid(pollUid);
+ return pollUri;
+ }
+
+ @Override
+ public PollUri getNewPollUri(String uri) {
+ PollUri pollUri = new PollUri();
+ pollUri.setUri(uri);
+ return pollUri;
+ }
+
+ @Override
+ public void setContextPath(String contextPath) {
+ this.contextPath = contextPath;
+ }
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServicePollUriImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-05-20 16:50:54 UTC (rev 3006)
+++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-05-20 17:36:51 UTC (rev 3007)
@@ -6,6 +6,8 @@
############################ EMAIL #############################################
pollen.email.userRegister.subject=[Pollen] Confirmation de cr\u00e9ation du compte %s
pollen.email.userRegister.content=Bienvenue %1$s. Vous venez de cr\u00e9er un compte sur l'application de sondage en ligne Pollen.\n\nIdentifiant : %2$s\nMot de passe : %3$s\n\nVous pouvez d\u00e8s maintenant g\u00e9rer vos sondages en vous identifiant sur le site : \n%4$s
+pollen.email.createPoll.subject=[Pollen] Cr\u00e9ation d'un sondage (%1$s)
+pollen.email.createPoll.content=Vous venez de cr\u00e9er le sondage "%1$s".\nVous pouvez y acc\u00e9der en suivant les liens ci-dessous.\n\nPage de vote : \n%2$s\nMod\u00e9ration des votes : \n%3$s\nPage de modification : \n%4$s
############################ GLOBAL ############################################
pollen.ui.tooltip.help=Aide
@@ -33,7 +35,8 @@
pollen.ui.user.update.cancel=Annuler les changements
pollen.ui.user.delete=Supprimer cet utilisateur
pollen.ui.user.delete.confirmMessage=Etes-vous s\u00fbr de vouloir d\u00e9finitivement supprimer cet utilisateur ?
-############################ USER ##############################################
+
+############################ LIST ##############################################
pollen.ui.list.create.title=Cr\u00e9er une nouvelle liste
pollen.ui.list.create.success=La liste %1$s a \u00e9t\u00e9 cr\u00e9\u00e9e avec succ\u00e8s.
pollen.ui.list.create.weightHelp=Ce chiffre correspond au poids du vote de la personne, c'est \u00e0 dire le nombre de voix que poss\u00e8de la personne dans le sondage.
@@ -58,7 +61,10 @@
pollen.ui.participant.weight-label=Poids
pollen.ui.participant.add=Nouveau participant
+############################ POLL ##############################################
pollen.ui.poll.form.confirmlistChange=Des changements ont \u00e9t\u00e9 effectu\u00e9s sur la/les liste(s), un changement de restriction supprimera les modifications. Voulez-vous continuer ?
+
+
pollen.ui.poll.links.pollName=%1$s par %2$s
pollen.ui.poll.links.uriNotDefined=Page inaccessible sans identifiant du sondage dans l'url !
pollen.ui.poll.links.notAllowed=L'url est incorrect, vous n'\u00eates pas autoris\u00e9 \u00e0 acc\u00e9der aux liens du sondage.
1
0
Author: fdesbois
Date: 2010-05-20 18:50:54 +0200 (Thu, 20 May 2010)
New Revision: 3006
Url: http://chorem.org/repositories/revision/pollen/3006
Log:
- Add PageLinks
- Evo #196 : add link for moderation without user account
- Improve QueryBuilder
Added:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java
trunk/pollen-ui/src/main/webapp/poll/PollLinks.tml
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContext.java
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java
trunk/pollen-business/src/main/java/org/chorem/pollen/TopiaQueryBuilder.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceUserImpl.java
trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties
trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties
trunk/pollen-business/src/main/xmi/pollen.zargo
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/AbstractPollsPage.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenAuthentication.java
trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml
trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml
trunk/pollen-ui/src/main/webapp/poll/PollForm.tml
trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
trunk/pollen-ui/src/main/webapp/user/UserPollsCreated.tml
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContext.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContext.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContext.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -4,6 +4,8 @@
import org.chorem.pollen.service.ServiceUser;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.util.ApplicationConfig;
@@ -121,5 +123,7 @@
*/
void closeTransaction(TopiaContext transaction);
+ PollenQueryBuilder newQueryBuilder(TopiaQuery query);
+
} //PollenContext
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenContextImpl.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -13,6 +13,8 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.util.ApplicationConfig;
import org.nuiton.util.ArgumentsParserException;
import static org.nuiton.i18n.I18n._;
@@ -388,4 +390,13 @@
return null;
}
+ @Override
+ public PollenQueryBuilder newQueryBuilder(TopiaQuery query) {
+ PollenQueryBuilder builder = new PollenQueryBuilder();
+ if (query != null) {
+ builder.setQuery(query);
+ }
+ return builder;
+ }
+
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/PollenQueryBuilder.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -4,6 +4,7 @@
import org.chorem.pollen.bean.Filter;
import org.chorem.pollen.entity.FavoriteList;
import org.chorem.pollen.entity.FavoriteParticipant;
+import org.chorem.pollen.entity.PollAccount;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.persistence.TopiaDAO;
@@ -20,14 +21,10 @@
*/
public class PollenQueryBuilder extends TopiaQueryBuilder {
- public PollenQueryBuilder() {
+ protected PollenQueryBuilder() {
super();
}
- public PollenQueryBuilder(TopiaDAO<?> dao) {
- super(dao);
- }
-
public EntityQueryProperty getFavoriteListProperty(String alias) {
return getEntityProperty(FavoriteList.class, alias);
}
@@ -37,6 +34,11 @@
return getEntityProperty(FavoriteParticipant.class, alias);
}
+ public EntityQueryProperty getPollCreatorProperty(
+ String alias) {
+ return getEntityProperty(PollAccount.class, alias);
+ }
+
public TopiaQuery createQueryFindFavoriteParticipantsByFavoriteList(
Filter filter) {
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/TopiaQueryBuilder.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/TopiaQueryBuilder.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/TopiaQueryBuilder.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -20,9 +20,7 @@
* </ul>
* <br />
* To use directly {@code prepare} methods, you have to set the query using
- * {@link #setQuery(TopiaQuery)} or instantiate the builder with the entity
- * dao using {@link #TopiaQueryBuilder(TopiaDAO)}, this will create a new query
- * from dao.
+ * {@link #setQuery(TopiaQuery)}.
*
* Created: 28 avr. 2010
*
@@ -34,33 +32,13 @@
protected TopiaQuery query;
- public TopiaQueryBuilder() {
+ protected TopiaQueryBuilder() {
}
- /**
- * This will create a new TopiaQuery from the {@code dao} in argument.
- *
- * @param dao used to create a new TopiaQuery in the builder
- */
- public TopiaQueryBuilder(TopiaDAO<?> dao) {
- setQuery(dao.createQuery());
- }
-
public static TopiaQueryBuilder newInstance() {
return new TopiaQueryBuilder();
}
- /**
- * This will create a new TopiaQueryBuilder with a new TopiaQuery from
- * the {@code dao} in argument.
- *
- * @param dao used to create a new TopiaQuery in the builder
- * @return a new instance of TopiaQueryBuilder
- */
- public static TopiaQueryBuilder newInstance(TopiaDAO<?> dao) {
- return new TopiaQueryBuilder(dao);
- }
-
public void setQuery(TopiaQuery query) {
this.query = query;
}
@@ -90,7 +68,7 @@
* @param element
* @param collection
* @return the TopiaQuery created
- * @see Filter#prepareQuery(TopiaQuery, boolean, PropertyUid)
+ * @see #prepareQuery(Filter, EntityQueryProperty)
*/
public TopiaQuery createQueryFindElementsByCollection(
EntityQueryProperty element,
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -244,7 +244,7 @@
protected Map<String, FavoriteParticipant> executeGetFavoriteParticipants(
TopiaContext transaction, Filter filter) throws TopiaException {
- PollenQueryBuilder builder = new PollenQueryBuilder();
+ PollenQueryBuilder builder = context.newQueryBuilder(null);
TopiaQuery query =
builder.createQueryFindFavoriteParticipantsByFavoriteList(filter);
@@ -268,7 +268,7 @@
protected int executeGetNbFavoriteParticipants(TopiaContext transaction,
Filter filter) throws TopiaException {
- PollenQueryBuilder builder = new PollenQueryBuilder();
+ PollenQueryBuilder builder = context.newQueryBuilder(null);
TopiaQuery query =
builder.createQueryFindFavoriteParticipantsByFavoriteList(filter);
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -1,11 +1,14 @@
package org.chorem.pollen.service;
import org.apache.commons.collections.CollectionUtils;
+import org.chorem.pollen.EntityQueryProperty;
import org.chorem.pollen.PollenBinderHelper;
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenContext;
import org.chorem.pollen.PollenDAOHelper;
import org.chorem.pollen.PollenException;
+import org.chorem.pollen.PollenQueryBuilder;
+import org.chorem.pollen.TopiaQueryBuilder;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.entity.Choice;
import org.chorem.pollen.entity.ChoiceDAO;
@@ -21,6 +24,7 @@
import org.chorem.pollen.entity.UserAccount;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
import java.util.ArrayList;
import java.util.Collection;
@@ -86,7 +90,7 @@
}
@Override
- protected void executeCreatePoll(TopiaContext transaction,
+ protected Poll executeCreatePoll(TopiaContext transaction,
List<Object> errorArgs, Poll poll, Collection<ParticipantList> lists)
throws TopiaException,
IllegalArgumentException,
@@ -122,6 +126,8 @@
dao.update(newPoll);
transaction.commitTransaction();
+
+ return newPoll;
}
protected Poll createBasicPoll(TopiaContext transaction, Poll source)
@@ -339,4 +345,51 @@
return participant;
}
+ @Override
+ protected boolean executeCanAdminPoll(TopiaContext transaction,
+ String accountUid, String pollUid)
+ throws TopiaException {
+
+ PollDAO dao = PollenDAOHelper.getPollDAO(transaction);
+
+ // No need alias managment so, no need of queryBuilder
+// PollenQueryBuilder builder = context.newQueryBuilder(dao);
+//
+// EntityQueryProperty creatorProperty =
+// builder.getPollCreatorProperty(Poll.CREATOR);
+//
+// int count = builder.getQuery().
+// add(Poll.UID, pollUid).
+// add(creatorProperty.nameProperty(PollAccount.UID), accountUid).
+// executeCount();
+
+ String creatorUidProperty =
+ TopiaQuery.getProperty(Poll.CREATOR, PollAccount.UID);
+
+ int count = dao.createQuery().
+ add(Poll.UID, pollUid).
+ add(creatorUidProperty, accountUid).
+ executeCount();
+
+ // Note a boolean admin exist in PollAccount, maybe
+ // find the account in lists
+
+ return count > 0;
+ }
+
+ @Override
+ protected Poll executeGetPoll(TopiaContext transaction,
+ String pollUid, String... properties)
+ throws TopiaException {
+
+ PollDAO dao = PollenDAOHelper.getPollDAO(transaction);
+
+ TopiaQuery query = dao.createQuery().
+ add(Poll.UID, pollUid).
+ addLoad(properties);
+
+ Poll result = dao.findByQuery(query);
+ return result;
+ }
+
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceUserImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceUserImpl.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceUserImpl.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -268,11 +268,11 @@
UserAccountDAO dao = PollenDAOHelper.getUserAccountDAO(transaction);
- TopiaQueryBuilder builder = new TopiaQueryBuilder(dao);
- builder.prepareQuery(filter);
+ TopiaQuery query = dao.createQuery();
+ context.newQueryBuilder(query).prepareQuery(filter);
Map<String, UserAccount> results = dao.findAllMappedByQuery(
- builder.getQuery(), UserAccount.LOGIN, String.class);
+ query, UserAccount.LOGIN, String.class);
return results;
}
@@ -282,10 +282,10 @@
UserAccountDAO dao = PollenDAOHelper.getUserAccountDAO(transaction);
- TopiaQueryBuilder builder = new TopiaQueryBuilder(dao);
- builder.prepareQuery(filter);
+ TopiaQuery query = dao.createQuery();
+ context.newQueryBuilder(query).prepareQuery(filter);
- int result = builder.getQuery().executeCount();
+ int result = query.executeCount();
return result;
}
Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties
===================================================================
--- trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-05-20 16:50:54 UTC (rev 3006)
@@ -22,6 +22,7 @@
pollen.error.serviceList.deleteAccountFromPersonList=
pollen.error.serviceMail.sendEmail=
pollen.error.servicePoll.addComment=
+pollen.error.servicePoll.canAdminPoll=
pollen.error.servicePoll.createChoice=
pollen.error.servicePoll.createPoll=
pollen.error.servicePoll.createUpdateVote=
@@ -40,7 +41,7 @@
pollen.error.servicePoll.getPollForUpdate=
pollen.error.servicePoll.getPollForVote=
pollen.error.servicePoll.getPollsByUser=
-pollen.error.servicePoll.getRestrictedAccount=Unable to retrieve restricted account with accountUId \= %1$s and poll with uid \= %2$s
+pollen.error.servicePoll.getRestrictedAccount=Unable to retrieve restricted account with accountUid \= %1$s and poll with uid \= %2$s
pollen.error.servicePoll.getRunningPolls=
pollen.error.servicePoll.getVotes=
pollen.error.servicePoll.savePoll=
Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties
===================================================================
--- trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-05-20 16:50:54 UTC (rev 3006)
@@ -22,6 +22,7 @@
pollen.error.serviceList.deleteAccountFromPersonList=
pollen.error.serviceMail.sendEmail=Erreur lors de l'envoi de l'email sur le serveur %1$s\:%2$d pour %3$s de la part de %4$s
pollen.error.servicePoll.addComment=Impossible d'ajouter un nouveau commentaire cr\u00E9\u00E9 par %1$s pour le sondage %2$s (%3$s)
+pollen.error.servicePoll.canAdminPoll=
pollen.error.servicePoll.createChoice=
pollen.error.servicePoll.createPoll=Impossible d'enregistrer le sondage %1$s cr\u00E9\u00E9 par %2$s
pollen.error.servicePoll.createUpdateVote=
@@ -39,7 +40,7 @@
pollen.error.servicePoll.getPollForUpdate=
pollen.error.servicePoll.getPollForVote=
pollen.error.servicePoll.getPollsByUser=
-pollen.error.servicePoll.getRestrictedAccount=Unable to retrieve restricted account with accountUId \= %1$s and poll with uid \= %2$s
+pollen.error.servicePoll.getRestrictedAccount=Unable to retrieve restricted account with accountUid \= %1$s and poll with uid \= %2$s
pollen.error.servicePoll.getRunningPolls=
pollen.error.servicePoll.getVotes=
pollen.error.servicePoll.savePoll=
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/AbstractPollsPage.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/AbstractPollsPage.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/AbstractPollsPage.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -113,7 +113,7 @@
// public String getAdminId() {
// PollAccount creator = servicePollAccount.findPollAccountById(poll
// .getCreatorId());
-// return poll.getPollUId() + ":" + creator.getAccountUId();
+// return poll.getPollUid() + ":" + creator.getAccountUid();
// }
/**
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -1,8 +1,6 @@
package org.chorem.pollen.ui.data;
-import org.apache.tapestry5.ValueEncoder;
-
/**
* PollUri
*
@@ -18,30 +16,59 @@
private static final String SEPARATOR = ":";
- protected String pollUId;
+ protected String pollUid;
- protected String accountUId;
+ protected String accountUid;
- public PollUri(String uri) {
- String[] tab = uri.split(SEPARATOR);
- pollUId = tab[0];
+ protected PollUri() {
+
+ }
+
+// public PollUri(String uri) {
+// String[] tab = uri.split(SEPARATOR);
+// pollUid = tab[0];
+// if (tab.length == 2) {
+// accountUid = tab[1];
+// }
+// }
+
+ public static PollUri newUri(String stringUri) {
+ PollUri uri = new PollUri();
+ String[] tab = stringUri.split(SEPARATOR);
+ uri.setPollUid(tab[0]);
if (tab.length == 2) {
- accountUId = tab[1];
+ uri.setAccountUid(tab[1]);
}
+ return uri;
}
- public String getAccountUId() {
- return accountUId;
+ public static PollUri newUri(String accountUid, String pollUid) {
+ PollUri uri = new PollUri();
+ uri.setAccountUid(accountUid);
+ uri.setPollUid(pollUid);
+ return uri;
}
- public String getPollUId() {
- return pollUId;
+ public String getAccountUid() {
+ return accountUid;
}
+ public void setAccountUid(String accountUid) {
+ this.accountUid = accountUid;
+ }
+
+ public String getPollUid() {
+ return pollUid;
+ }
+
+ public void setPollUid(String pollUid) {
+ this.pollUid = pollUid;
+ }
+
public String getUri() {
- String uri = getPollUId();
- if (getAccountUId() != null) {
- uri += SEPARATOR + getAccountUId();
+ String uri = getPollUid();
+ if (getAccountUid() != null) {
+ uri += SEPARATOR + getAccountUid();
}
return uri;
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -101,7 +101,7 @@
if (logger.isDebugEnabled()) {
logger.debug("Get existing poll with pollUID = " + uid);
}
- poll = servicePoll.getPollForUpdate(uid);
+ poll = servicePoll.getPoll(uid, Poll.CHOICE, Poll.POLL_ACCOUNT);
// TODO : init advancedOptions
// TODO-fdesbois-2010-05-19 : exception need to be throw if uid not correspond to an existing poll
} else {
@@ -319,7 +319,7 @@
choiceField.saveName(serviceImage);
poll.addChoice(choiceField.getChoice());
}
- servicePoll.createPoll(poll, getLists());
+ poll = servicePoll.createPoll(poll, getLists());
}
public void validate(Messages messages) throws FieldValidationException {
@@ -366,13 +366,6 @@
}
}
- public Date getBeginDate() {
- if (poll.getBeginDate() == null) {
- poll.setBeginDate(new Date());
- }
- return poll.getBeginDate();
- }
-
/**
* ValueEncoder toClient is used to convert {@code value} to the list name.
*
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -9,6 +9,7 @@
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.InjectComponent;
+import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
@@ -18,6 +19,7 @@
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.ComponentSource;
+import org.apache.tapestry5.services.PageRenderLinkSource;
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
@@ -25,6 +27,7 @@
import org.chorem.pollen.entity.Participant;
import org.chorem.pollen.entity.ParticipantList;
import org.chorem.pollen.entity.Poll;
+import org.chorem.pollen.entity.PollAccount;
import org.chorem.pollen.entity.PreventRule;
import org.chorem.pollen.entity.PreventRuleImpl;
import org.chorem.pollen.mail.PreventRuleManager;
@@ -34,6 +37,7 @@
import org.chorem.pollen.ui.data.AddressBar;
import org.chorem.pollen.ui.data.ChoiceField;
import org.chorem.pollen.ui.data.FieldValidationException;
+import org.chorem.pollen.ui.data.PollUri;
import org.chorem.pollen.ui.models.ParticipantListModel;
import org.chorem.pollen.ui.models.PollFormModel;
import org.chorem.pollen.ui.services.PollenManager;
@@ -80,9 +84,6 @@
@InjectComponent
private Zone mainZone;
- @Inject
- private Logger logger;
-
@Override
public Border getBorder() {
return border;
@@ -90,7 +91,7 @@
/** Services injected */
@Inject
- private Logger log;
+ private Logger logger;
@Inject
private Messages messages;
@@ -125,6 +126,7 @@
initOptions();
listsFeedback.clearErrors();
step = PollStep.MAIN;
+ mainForm.clearErrors();
}
/**
@@ -148,8 +150,8 @@
*/
public PollFormModel getModel() {
if (model == null) {
- if (log.isDebugEnabled()) {
- log.debug("-------- NEW POLL FORM MODEL --------");
+ if (logger.isDebugEnabled()) {
+ logger.debug("-------- NEW POLL FORM MODEL --------");
}
model = new PollFormModel();
model.initPoll(servicePoll, pollUID, getUserConnected());
@@ -211,8 +213,8 @@
@Log
void onPrepareForRender() {
String formId = mainForm.getClientId();
- if (log.isDebugEnabled()) {
- log.debug("form id : " + formId);
+ if (logger.isDebugEnabled()) {
+ logger.debug("form id : " + formId);
}
if (formId != null) {
// Script for form interactions : see "webapp/js/pollForm.js"
@@ -387,8 +389,8 @@
public ParticipantList getListSelected() {
ParticipantList result = getModel().getCurrentList();
- if (log.isDebugEnabled() && result != null) {
- log.debug("List selected : " + result.getName());
+ if (logger.isDebugEnabled() && result != null) {
+ logger.debug("List selected : " + result.getName());
}
return result;
}
@@ -410,7 +412,7 @@
// A dialog box will appeared for user confirmation on changing poll
// type with data unsaved.
json.put("confirm",
- messages.get("pollen.ui.poll.listChanged.confirmMessage"));
+ messages.get("pollen.ui.poll.form.confirmlistChange"));
}
return json;
}
@@ -622,10 +624,44 @@
}
}
+ @Inject
+ private PageRenderLinkSource linkSource;
+
+ private Link successLink;
+
+ @InjectPage
+ private PollLinks pollLinks;
+
+ public void prepareSuccessLinks(Poll newPoll) {
+ String creatorUid = newPoll.getCreator().getUid();
+ String pollUid = newPoll.getUid();
+ PollUri uri = PollUri.newUri(creatorUid, pollUid);
+// successLink = linkSource.createPageRenderLinkWithContext(
+// PollLinks.class, uri);
+ pollLinks.setPollUri(uri);
+ }
+
@Log
Object onSuccess() {
+ if (!edited) {
+ PollAccount creator = getPoll().getCreator();
+ PollUri uri = PollUri.newUri(creator.getUid(), getPoll().getUid());
+ pollLinks.addInfo("Sauvegarde OK !");
+ if (creator.getEmail() != null) {
+ pollLinks.addInfo("Vous avez recu un mail !");
+ }
+ if (getPoll().getPollType().isRestrictedOrGroup()) {
+ pollLinks.addInfo("Les votants ont reçu un mail !");
+ }
+ return pollLinks;
+ }
return mainZone;
}
+ @Log
+ Object onFailure() {
+ return mainZone;
+ }
+
}
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -0,0 +1,105 @@
+package org.chorem.pollen.ui.pages.poll;
+
+import org.apache.tapestry5.Link;
+import org.apache.tapestry5.annotations.InjectComponent;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.PageRenderLinkSource;
+import org.chorem.pollen.entity.Poll;
+import org.chorem.pollen.service.ServicePoll;
+import org.chorem.pollen.ui.base.AbstractPollenPage;
+import org.chorem.pollen.ui.components.Border;
+import org.chorem.pollen.ui.data.AddressBar;
+import org.chorem.pollen.ui.data.PollUri;
+import org.slf4j.Logger;
+
+/**
+ * Created: 20 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class PollLinks extends AbstractPollenPage {
+
+ public static final String URI_SEPARATOR = "/";
+
+ @InjectComponent
+ private Border border;
+
+ @Inject
+ private Logger logger;
+
+ @Inject
+ private ServicePoll servicePoll;
+
+ @Override
+ public Border getBorder() {
+ return border;
+ }
+
+ public String getTitle() {
+ return "Liens d'accès au sondage";
+ }
+
+ public AddressBar getAddressBar() {
+ return AddressBar.newBar().appendCurrent(getTitle());
+ }
+
+ @Inject
+ private PageRenderLinkSource linkSource;
+
+ private Poll poll;
+
+ private PollUri pollUri;
+
+ void onActivate(PollUri pollUri) {
+ this.pollUri = pollUri;
+ }
+
+ PollUri onPassivate() {
+ return pollUri;
+ }
+
+ void setupRender() {
+ if (pollUri == null) {
+ addFatal("pollen.ui.poll.links.uriNotDefined");
+ } else if (!servicePoll.canAdminPoll(
+ pollUri.getAccountUid(), pollUri.getPollUid())) {
+ addFatal("pollen.ui.poll.links.notAllowed");
+ }
+ }
+
+ public boolean isPollNull() {
+ return getPoll() == null;
+ }
+
+ public void setPollUri(PollUri pollUri) {
+ this.pollUri = pollUri;
+ }
+
+ public Poll getPoll() {
+ if (pollUri != null) {
+ poll = servicePoll.getPoll(pollUri.getPollUid());
+ }
+ return poll;
+ }
+
+ public Link getPollLink() {
+ Link link = linkSource.createPageRenderLinkWithContext(
+ PollForm.class, pollUri);
+ return link;
+ }
+
+ public Link getVoteLink() {
+ PollUri voteUri = PollUri.newUri(null, pollUri.getPollUid());
+ Link link = linkSource.createPageRenderLinkWithContext(
+ VoteForPoll.class, voteUri);
+ return link;
+ }
+
+ public Link getModerateVoteLink() {
+ Link link = linkSource.createPageRenderLinkWithContext(
+ VoteForPoll.class, pollUri);
+ return link;
+ }
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollLinks.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -372,9 +372,9 @@
// ResultListDTO resultListDTO = null;
//
// if (byGroup) {
-// resultListDTO = serviceResults.getGroupResults(poll.getPollUId());
+// resultListDTO = serviceResults.getGroupResults(poll.getPollUid());
// } else {
-// resultListDTO = serviceResults.getNormalResults(poll.getPollUId());
+// resultListDTO = serviceResults.getNormalResults(poll.getPollUid());
// }
//
// results = resultListDTO.getResultDTOs();
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -421,10 +421,10 @@
////
//// // Check for restricted poll
//// if (!alreadyVoted && !isFreePoll()) {
-//// if (uri.getAccountUId() != null) {
-//// // The accountUId must be valid for the poll
+//// if (uri.getAccountUid() != null) {
+//// // The accountUid must be valid for the poll
//// PollAccountDTO restrictedAccount =
-//// servicePoll.getRestrictedAccount(uri.getAccountUId(), getPoll());
+//// servicePoll.getRestrictedAccount(uri.getAccountUid(), getPoll());
////
//// if (restrictedAccount != null) {
//// // PollAccount is replaced by the good account from db
@@ -435,7 +435,7 @@
//// } else {
//// restrictedListsForbidden = true;
//// }
-//// // Not allowed to vote without an accountUId
+//// // Not allowed to vote without an accountUid
//// } else {
//// restrictedListsForbidden = true;
//// }
@@ -525,8 +525,8 @@
// /** Ajout d'une entrée dans le flux de syndication */
// private void addFeedEntry(PollAction pollAction, String titleStr,
// String contentStr) throws PollenBusinessException {
-// String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollUId();
-// File feedFile = getFeedContext().getFile(getPoll().getPollUId());
+// String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollUid();
+// File feedFile = getFeedContext().getFile(getPoll().getPollUid());
// String title = null;
// String content = null;
//
@@ -558,8 +558,8 @@
//
// /** Envoi du mail de notification */
// private void sendMailNotification() throws PollenBusinessException {
-// String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollUId();
-// String modifURL = siteURL + "poll/Modification/" + getPoll().getPollUId()
+// String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollUid();
+// String modifURL = siteURL + "poll/Modification/" + getPoll().getPollUid()
// + ":" + MD5.encode(getPoll().getCreatorId());
// Map<String, String> data = new HashMap<String, String>();
// data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST));
@@ -669,7 +669,7 @@
// */
// @Log
// public boolean isFeedFileExisting() throws PollenBusinessException {
-// File feedFile = getFeedContext().getFile(getPoll().getPollUId());
+// File feedFile = getFeedContext().getFile(getPoll().getPollUid());
// if (log.isDebugEnabled()) {
// log.debug("feed context path : " + getFeedContext().getContextPath());
// log.debug("feed absolute path : " + feedFile.getAbsolutePath());
@@ -777,7 +777,7 @@
// if (isTextType()) {
// if (newChoice.getName() != null) {
// newChoice.setValidate(true);
-// newChoice.setPollUId(getPoll().getPollUId());
+// newChoice.setPollUid(getPoll().getPollUid());
// getPoll().getChoices().add(newChoice);
// choiceName = newChoice.getName();
// choiceDesc = newChoice.getDescription();
@@ -785,7 +785,7 @@
// } else if (isDateType()) {
// if (newDateChoice.getDate() != null) {
// newDateChoice.setValidate(true);
-// newDateChoice.setPollUId(getPoll().getPollUId());
+// newDateChoice.setPollUid(getPoll().getPollUid());
// newDateChoice.setName(String.valueOf(newDateChoice.getDate()
// .getTime()));
// getPoll().getChoices().add(newDateChoice);
@@ -796,7 +796,7 @@
// } else if (isImageType()) {
// if (newImageChoice.getImg() != null) {
// newImageChoice.setValidate(true);
-// newImageChoice.setPollUId(getPoll().getPollUId());
+// newImageChoice.setPollUid(getPoll().getPollUid());
// newImageChoice.setName(newImageChoice.getImg().getFileName()
// .replace(' ', '_'));
// getPoll().getChoices().add(newImageChoice);
@@ -904,9 +904,9 @@
// if (getPoll().getContinuousResults()) {
//
// if (isGroupPoll()) {
-// resultListDTO = serviceResults.getGroupResults(getPoll().getPollUId());
+// resultListDTO = serviceResults.getGroupResults(getPoll().getPollUid());
// } else {
-// resultListDTO = serviceResults.getNormalResults(getPoll().getPollUId());
+// resultListDTO = serviceResults.getNormalResults(getPoll().getPollUid());
// }
//
// results = resultListDTO.getResultDTOs();
@@ -1048,7 +1048,7 @@
public Poll getPoll() throws PollenBusinessException {
if (poll == null) {
- poll = servicePoll.getPollForVote(uri.getPollUId());
+ poll = servicePoll.getPollForVote(uri.getPollUid());
if (poll != null) {
@@ -1082,7 +1082,7 @@
/**
* Use a PollAccount to represent the current session user.
- * The existing account is used if accountUId is present in the uri.
+ * The existing account is used if accountUid is present in the uri.
* Otherwise a new account is instanciate with user properties
* (for vote name).
*
@@ -1091,8 +1091,8 @@
public PollAccount getPollAccount() throws PollenBusinessException {
if (pollAccount == null) {
// Identification du votant
- if (uri.getAccountUId() != null) {
- // pollAccount = serviceUser.getPerson(uri.getAccountUId());
+ if (uri.getAccountUid() != null) {
+ // pollAccount = serviceUser.getPerson(uri.getAccountUid());
// pollAccountId = pollAccount.getId();
@@ -1314,7 +1314,7 @@
// break;
// case IMAGE:
// newChoice = ChoiceField.getChoiceImage(
-// getPoll().getPollUId());
+// getPoll().getPollUid());
// break;
// case TEXT:
// default:
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -73,7 +73,7 @@
// for (VotingListDTO list : poll.getVotingListDTOs()) {
// for (PollAccountDTO account : list.getPollAccountDTOs()) {
// if (account.getEmail().equals(user.getEmail())) {
-// return poll.getPollUId() + ":" + account.getAccountUId();
+// return poll.getPollUid() + ":" + account.getAccountUid();
// }
// }
// }
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -107,7 +107,7 @@
/**
* Execute PollenManager when registry startup.
* The manager will be instantiated using
- * {@link #buildPollenManager(org.apache.tapestry5.ioc.services.RegistryShutdownHub) }.
+ * {@link #buildPollenManager() }.
* The serviceUser is needed to start the application.
*
* @param configuration to add the manager to registry startup
@@ -187,7 +187,7 @@
@Override
public PollUri coerce(String input) {
- return new PollUri(input);
+ return PollUri.newUri(input);
}
};
@@ -249,12 +249,12 @@
/**
* Contribution to ComponentRequestHandler service. The
- * {@link AuthenticationFilter} is added to the configuration of
+ * {@link PollenAuthenticationFilter} is added to the configuration of
* the service to provide authentication managment on user connected.
*
* @param configuration of ComponentRequestHandler
* @see ServiceAuthentication
- * @see AuthenticationFilter
+ * @see PollenAuthenticationFilter
* @see ComponentRequestFilter
*/
public static void contributeComponentRequestHandler(
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenAuthentication.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenAuthentication.java 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenAuthentication.java 2010-05-20 16:50:54 UTC (rev 3006)
@@ -2,11 +2,13 @@
package org.chorem.pollen.ui.services;
import org.apache.tapestry5.annotations.SessionState;
+import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.services.ApplicationStateManager;
import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.entity.UserAccountImpl;
import org.chorem.pollen.ui.data.PollenRequiresAuthentication;
import org.chorem.pollen.ui.pages.admin.AdminUsers;
+import org.nuiton.web.tapestry5.services.ServiceAuthentication;
import org.nuiton.web.tapestry5.services.ServiceAuthenticationImpl;
/**
@@ -27,6 +29,8 @@
public class PollenAuthentication extends
ServiceAuthenticationImpl<UserAccount, PollenRequiresAuthentication> {
+ protected Class<?> pageClass;
+
public PollenAuthentication(ApplicationStateManager stateManager) {
super(stateManager, UserAccount.class,
PollenRequiresAuthentication.class);
@@ -53,7 +57,7 @@
* in AppModule.
*
* @return a new instance of UserAccount.
- * @see AppModule#contributeApplicationStateManager(MappedConfiguration, ServiceAuthentication)
+ * @see AppModule#contributeApplicationStateManager(MappedConfiguration , ServiceAuthentication)
*/
@Override
public UserAccount getNewUserInstance() {
Modified: trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-05-20 16:50:54 UTC (rev 3006)
@@ -1,6 +1,7 @@
############################ PAGES #############################################
pollen.page.AdminUsers.title=Gestion des utilisateurs
pollen.page.UserLists.title=Vos listes de votants
+pollen.page.PollLinks.title=Liens d'acc\u00e8s au sondage
############################ EMAIL #############################################
pollen.email.userRegister.subject=[Pollen] Confirmation de cr\u00e9ation du compte %s
@@ -57,8 +58,20 @@
pollen.ui.participant.weight-label=Poids
pollen.ui.participant.add=Nouveau participant
-pollen.ui.poll.listChanged.confirmMessage=Des changements ont été effectués sur la/les liste(s), un changement de restriction supprimera les modifications. Voulez-vous continuer ?
+pollen.ui.poll.form.confirmlistChange=Des changements ont \u00e9t\u00e9 effectu\u00e9s sur la/les liste(s), un changement de restriction supprimera les modifications. Voulez-vous continuer ?
+pollen.ui.poll.links.pollName=%1$s par %2$s
+pollen.ui.poll.links.uriNotDefined=Page inaccessible sans identifiant du sondage dans l'url !
+pollen.ui.poll.links.notAllowed=L'url est incorrect, vous n'\u00eates pas autoris\u00e9 \u00e0 acc\u00e9der aux liens du sondage.
+#pollen.ui.poll.links.votePage=Le lien ci-dessous m\u00e8ne \u00e0 la page de votes. Enregistrez-le et envoyez-le \u00e0 ceux que vous voulez voir voter :
+#pollen.ui.poll.links.adminVotePage=Le lien ci-dessous m\u00e8ne \u00e0 la page de votes avec un acc\u00e8s mod\u00e9rateur. Enregistrez-le pour pouvoir mod\u00e9rer les votes si besoin :
+#pollen.ui.poll.links.editPage=Le lien ci-dessous m\u00e8ne \u00e0 la page de modification du sondage. Enregistrez-le pour pouvoir modifier votre sondage au besoin ou le clore :
+pollen.ui.poll.links.votePage=Lien d'acc\u00e8s publique \u00e0 la page des votes :
+pollen.ui.poll.links.adminVotePage=Lien d'acc\u00e8s mod\u00e9rateur \u00e0 la page des votes :
+pollen.ui.poll.links.editPage=Lien d'acc\u00e8s \u00e0 la modification du sondage :
+pollen.ui.poll.links.register=Si vous \u00eates un utilisateur identifi\u00e9, vous pouvez retrouver ces liens dans la page
+pollen.ui.poll.links.myPolls=Mes sondages
+
# OLD LOGIN_COMPONENT
connectionLegend=Connexion
loginSubmit=Me connecter
@@ -70,6 +83,8 @@
# FORM:: poll
groupName-label=Nom du groupe
+participantEmail-regexp=^([a-zA-Z0-9_.+-])+(a)(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$
+participantEmail-regexp-message=Adresse email invalide.
# FORM:: user
firstName-label=Pr\u00e9nom
Modified: trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml 2010-05-20 16:50:54 UTC (rev 3006)
@@ -8,8 +8,8 @@
<img src="${asset:context:img/vote.png}" alt="${message:vote}" style="margin-right: 18px;"/>
${message:votePage}
<br />
- <t:PageLink t:context="poll.pollUId" t:page="poll/VoteForPoll" style="margin-left:50px;">
- ${siteURL}poll/VoteFor/${poll.pollUId}
+ <t:PageLink t:context="poll.pollUid" t:page="poll/VoteForPoll" style="margin-left:50px;">
+ ${siteURL}poll/VoteFor/${poll.pollUid}
</t:PageLink>
</div>
<div style="margin-top: 10px;">
Modified: trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-05-20 16:50:54 UTC (rev 3006)
@@ -275,7 +275,7 @@
</div>
</t:formfragment>
<t:formfragment t:id="imgChoiceFragment" visible="isImgChoices()">
- <t:ImageContextLink t:id="imgContext" t:dir="poll.pollUId" />
+ <t:ImageContextLink t:id="imgContext" t:dir="poll.pollUid" />
<div t:type="loop" t:source="imgTypeChoices" t:value="imgTypeChoice" t:volatile="true">
<div class="fleft choiceName">
<t:label for="imgFile" />
Modified: trunk/pollen-ui/src/main/webapp/poll/PollForm.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/PollForm.tml 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/webapp/poll/PollForm.tml 2010-05-20 16:50:54 UTC (rev 3006)
@@ -337,7 +337,8 @@
<td>
<t:textfield t:id="participantEmail"
value="participant.email"
- size="25" />
+ size="25"
+ t:validate="required,regexp" />
</td>
<td>
<t:textfield t:id="participantWeight"
Added: trunk/pollen-ui/src/main/webapp/poll/PollLinks.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/PollLinks.tml (rev 0)
+++ trunk/pollen-ui/src/main/webapp/poll/PollLinks.tml 2010-05-20 16:50:54 UTC (rev 3006)
@@ -0,0 +1,44 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html t:type="border" t:addressBar="addressBar" t:pageLogo="literal:Creation" t:pageTitle="prop:title"
+ xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
+ <!--<t:feedback t:id="feedback"/>-->
+ <t:unless t:test="pollNull">
+ <h1 class="titleCreation">${title}</h1>
+
+ <h3>${format:pollen.ui.poll.links.pollName=poll.title,poll.creator.name}</h3>
+ <t:unless t:test="poll.pollType.restrictedOrGroup">
+ <div style="margin-top: 10px;">
+ <img src="${asset:context:img/vote.png}" alt="${message:vote}" style="margin-right: 20px;"/>
+ ${message:pollen.ui.poll.links.votePage}
+ <br />
+ <a href="${voteLink}" style="margin-left:50px;">
+ ${url}${voteLink.toAbsoluteUri()}
+ </a>
+ </div>
+ <!--<p:else>-->
+ <!--${message:pollen.ui.poll.links.noVoteLinkForRestriction}-->
+ <!--</p:else>-->
+ </t:unless>
+ <div style="margin-top: 10px;">
+ <img src="${asset:context:img/edit.png}" alt="${message:edit}" />
+ <img src="${asset:context:img/vote.png}" alt="${message:vote}" style="margin-right: 1px;" />
+ ${message:pollen.ui.poll.links.adminVotePage}
+ <br />
+ <a href="${moderateVoteLink}" style="margin-left:50px;">
+ ${url}${moderateVoteLink.toAbsoluteUri()}
+ </a>
+ </div>
+ <div style="margin-top: 10px;">
+ <img src="${asset:context:img/edit.png}" alt="${message:edit}" style="margin-right: 26px;" />
+ ${message:pollen.ui.poll.links.editPage}
+ <br />
+ <a href="${pollLink}" style="margin-left:50px;">
+ ${url}${pollLink.toAbsoluteUri()}
+ </a>
+ </div>
+ <div style="margin-top: 30px;">
+ ${message:pollen.ui.poll.links.register}
+ <t:PageLink t:page="user/PollsCreated">${message:pollen.ui.poll.links.myPolls}</t:PageLink>.
+ </div>
+ </t:unless>
+</html>
\ No newline at end of file
Property changes on: trunk/pollen-ui/src/main/webapp/poll/PollLinks.tml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-05-20 16:50:54 UTC (rev 3006)
@@ -1,5 +1,5 @@
-<t:border t:address="address.items" t:pageLogo="literal:Vote" t:feedFilename="prop:uri.pollUId"
+<t:border t:address="address.items" t:pageLogo="literal:Vote" t:feedFilename="prop:uri.pollUid"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
<t:feedback t:id="feedback"/>
@@ -14,13 +14,13 @@
<legend>${message:about}</legend>
<div style="float: right">
<t:if test="poll.publicResults">
- <t:PageLink t:page="poll/Results" t:context="poll.pollUId">
+ <t:PageLink t:page="poll/Results" t:context="poll.pollUid">
<img src="${asset:context:img/count.png}" title="${message:results-help}" alt="${message:results}"/>
</t:PageLink>
</t:if>
<t:FeedContextLink t:id="feedContext" />
<t:if test="feedFileExisting">
- <t:FileLink filename="${poll.pollUId}" type="literal:application/atom+xml" t:context="feedContext">
+ <t:FileLink filename="${poll.pollUid}" type="literal:application/atom+xml" t:context="feedContext">
<img src="${asset:context:img/feed.png}" title="Atom" alt="Atom"/>
</t:FileLink>
</t:if>
@@ -204,7 +204,7 @@
<t:if test="poll.continuousResults">
<tr>
<td>
- <t:PageLink t:page="poll/results" t:context="${poll.pollUId}">${message:results}</t:PageLink>
+ <t:PageLink t:page="poll/results" t:context="${poll.pollUid}">${message:results}</t:PageLink>
</td>
<t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
<t:if test="!isChoiceHidden()">
@@ -233,7 +233,7 @@
<!-- Ajout de choix -->
- <!--<t:ImageContextLink t:id="imgContext" t:thumb="true" t:dir="poll.pollUId"/>-->
+ <!--<t:ImageContextLink t:id="imgContext" t:thumb="true" t:dir="poll.pollUid"/>-->
<t:if test="canAddChoice">
<h4>${message:pollen.ui.choice.add.title}</h4>
<div id="choiceFormDiv">
Modified: trunk/pollen-ui/src/main/webapp/user/UserPollsCreated.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/user/UserPollsCreated.tml 2010-05-20 10:55:16 UTC (rev 3005)
+++ trunk/pollen-ui/src/main/webapp/user/UserPollsCreated.tml 2010-05-20 16:50:54 UTC (rev 3006)
@@ -10,7 +10,7 @@
<t:grid t:id="pollsGrid" t:source="polls" t:row="poll" model="pollsModel" t:inPlace="true"
t:rowsPerPage="10" t:pagerPosition="bottom" t:rowClass="prop:evenodd.next">
<p:functionsCell>
- <t:PageLink t:page="poll/VoteForPoll" t:context="poll.pollUId">
+ <t:PageLink t:page="poll/VoteForPoll" t:context="poll.pollUid">
<img src="${asset:context:img/vote.png}" title="${message:vote-help}" alt="${message:vote}" />
</t:PageLink>
<t:PageLink t:page="poll/results" t:context="adminId">
@@ -21,18 +21,18 @@
<t:PageLink t:page="poll/modification" t:context="adminId">
<img src="${asset:context:img/edit.png}" title="${message:edit-help}" alt="${message:edit}" />
</t:PageLink>
- <t:ActionLink t:id="close" t:context="poll.pollUId">
+ <t:ActionLink t:id="close" t:context="poll.pollUid">
<img src="${asset:context:img/close.png}" title="${message:close-help}" alt="${message:close}" />
</t:ActionLink>
</t:unless>
- <t:ActionLink t:id="export" t:context="poll.pollUId">
+ <t:ActionLink t:id="export" t:context="poll.pollUid">
<img src="${asset:context:img/export.png}" title="${message:export-help}" alt="${message:export}" />
</t:ActionLink>
- <t:PageLink t:page="poll/creation" t:context="poll.pollUId">
+ <t:PageLink t:page="poll/creation" t:context="poll.pollUid">
<img src="${asset:context:img/copy.png}" title="${message:copy-help}" alt="${message:copy}" />
</t:PageLink>
- <t:ActionLink t:id="deletePoll" t:context="poll.pollUId">
+ <t:ActionLink t:id="deletePoll" t:context="poll.pollUid">
<img src="${asset:context:img/delete.png}" title="${message:delete-help}" alt="${message:delete}" />
</t:ActionLink>
</p:functionsCell>
1
0
r3005 - in trunk/pollen-business/src/test/java/org/chorem/pollen: . service test
by fdesbois@users.chorem.org 20 May '10
by fdesbois@users.chorem.org 20 May '10
20 May '10
Author: fdesbois
Date: 2010-05-20 12:55:16 +0200 (Thu, 20 May 2010)
New Revision: 3005
Url: http://chorem.org/repositories/revision/pollen/3005
Log:
missing refactor for tests
Modified:
trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java 2010-05-20 10:42:31 UTC (rev 3004)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/TopiaQueryBuilderTest.java 2010-05-20 10:55:16 UTC (rev 3005)
@@ -53,7 +53,7 @@
Assert.assertEquals(builder.getQuery().fullQuery(),
"FROM " + UserAccount.class.getName() +
- " ORDER BY " + TopiaEntity.CREATE_DATE + " DESC");
+ " ORDER BY " + TopiaEntity.TOPIA_CREATE_DATE + " DESC");
}
@@ -98,7 +98,7 @@
"SELECT P FROM " + FavoriteParticipant.class.getName() + " P, "
+ FavoriteList.class.getName() + " L" +
" WHERE P IN elements (L." + FavoriteList.FAVORITE_PARTICIPANT +
- ") ORDER BY P." + TopiaEntity.CREATE_DATE + " DESC");
+ ") ORDER BY P." + TopiaEntity.TOPIA_CREATE_DATE + " DESC");
log.info("test3 : orderBy name and email desc");
String orderBy = FavoriteParticipant.NAME + ", " + FavoriteParticipant.EMAIL + " desc";
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java 2010-05-20 10:42:31 UTC (rev 3004)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java 2010-05-20 10:55:16 UTC (rev 3005)
@@ -108,7 +108,7 @@
try {
newPoll = servicePoll.createBasicPoll(transaction, poll);
Assert.assertNotNull(newPoll);
- Assert.assertNotNull(newPoll.getId());
+ Assert.assertNotNull(newPoll.getTopiaId());
Assert.assertNotNull(newPoll.getUid());
Assert.assertEquals("Poll", newPoll.getTitle());
@@ -130,7 +130,7 @@
try {
PollDAO dao = PollenDAOHelper.getPollDAO(transaction);
- Poll pollFound = dao.findByTopiaId(newPoll.getId());
+ Poll pollFound = dao.findByTopiaId(newPoll.getTopiaId());
Assert.assertNotNull(pollFound);
Assert.assertNotNull(pollFound.getCreator());
Assert.assertEquals(user, pollFound.getCreator().getUserAccount());
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-05-20 10:42:31 UTC (rev 3004)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/test/AbstractServiceTest.java 2010-05-20 10:55:16 UTC (rev 3005)
@@ -232,7 +232,7 @@
PollenDAOHelper.getFavoriteListDAO(transaction);
TopiaQuery query = dao.createQuery().
- add(TopiaEntity.ID, id).
+ add(TopiaEntity.TOPIA_ID, id).
addLoad(propertiesLoad);
FavoriteList result = dao.findByQuery(query);
1
0
Author: fdesbois
Date: 2010-05-20 12:42:31 +0200 (Thu, 20 May 2010)
New Revision: 3004
Url: http://chorem.org/repositories/revision/pollen/3004
Log:
- Refactor from Topia ID in TOPIA_ID
- Add error managment for form validation (not tested yet)
Added:
trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantImpl.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ErrorReport.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FieldValidationException.java
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java
trunk/pollen-business/src/main/java/org/chorem/pollen/bean/Filter.java
trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteListImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java
trunk/pollen-business/src/main/xmi/pollen.zargo
trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java
trunk/pollen-ui/src/main/webapp/poll/PollForm.tml
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/EntityQueryProperty.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -1,66 +1,65 @@
-
package org.chorem.pollen;
-import org.nuiton.topia.framework.*;
+import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.persistence.TopiaEntity;
/**
* EntityQueryProperty is used to simplify property concatenation in TopiaQuery.
- * The usage is simple, the EntityQueryProperty need a mainAlias which represents
- * the entity in a TopiaQuery. Then the {@link #nameProperty(String)}
- * is called to retrieve the correct property name used for the query.
- * Exemple :
+ * The usage is simple, the EntityQueryProperty need a mainAlias which
+ * represents the entity in a TopiaQuery. Then the {@link #nameProperty(String)}
+ * is called to retrieve the correct property name used for the query. Exemple
+ * :
* <pre>
* BoatDAO dao = AppDAOHelper.getBoatDAO(topiaContext);
- *
+ * <p/>
* // Property used in the query
* EntityQueryProperty boatProperty = new EntityQueryProperty("B");
- *
+ * <p/>
* // It's better to create the query with the property name
* TopiaQuery query = dao.createQuery(boatProperty.name());
- *
+ * <p/>
* // The property NAME of the boat need to be find equals to "ULUBERLU"
* query.add(boatProperty.nameProperty(Boat.NAME), "ULUBERLU");
- *
+ * <p/>
* // It's avoid doing this :
* query.add("B." + Boat.NAME, "ULUBERLU");
* </pre>
* This last exemple is a simple case but for a more complex query with more
* than one entity, it's obvious that concatenation using + is not a good
- * practice.<br />
- * You can also use this class as a superclass for each entity, ex :
+ * practice.<br /> You can also use this class as a superclass for each entity,
+ * ex :
* <pre>
* public class BoatProperty extends EntityQueryProperty {
- *
+ * <p/>
* public BoatProperty(String mainAlias) {
* super(mainAlias);
* }
- *
+ * <p/>
* public String namePropertyName() {
* return nameProperty(Boat.NAME);
* }
- * }
+ * }
* </pre>
- *
+ * <p/>
* Created: 14 avr. 2010
*
* @author fdesbois <fdesbois(a)codelutin.com>
*/
public class EntityQueryProperty {
- /** alias of the entity **/
+ /** alias of the entity * */
protected String mainAlias;
- /** name of the property used for join in query **/
+ /** name of the property used for join in query * */
protected String propertyJoin;
- /** class of the entity **/
+ /** class of the entity * */
protected Class<? extends TopiaEntity> entityClass;
/**
* Default constructor. mainAlias, propertyJoin and entityClass are null.
- * You can use setters to initalize these three properties.
- * You can use {@link #nameProperty(String)} method with a mainAlias null.
+ * You can use setters to initalize these three properties. You can use
+ * {@link #nameProperty(String)} method with a mainAlias null.
*/
public EntityQueryProperty() {
}
@@ -77,13 +76,13 @@
/**
* Constructor with mainAlias and entityClass.
*
- * @param mainAlias alias of the entity corresponding to this
- * EntityQueryProperty
+ * @param mainAlias alias of the entity corresponding to this
+ * EntityQueryProperty
* @param entityClass class of the entity corresponding to this
- * EntityQueryProperty
+ * EntityQueryProperty
*/
public EntityQueryProperty(String mainAlias,
- Class<? extends TopiaEntity> entityClass) {
+ Class<? extends TopiaEntity> entityClass) {
this(mainAlias);
setEntityClass(entityClass);
}
@@ -111,15 +110,15 @@
* Setter for entityClass.
*
* @param entityClass class of the entity corresponding to this
- * EntityQueryProperty
+ * EntityQueryProperty
*/
public void setEntityClass(Class<? extends TopiaEntity> entityClass) {
this.entityClass = entityClass;
}
/**
- * Name the entity as a property for a TopiaQuery. Careful, this name can
- * be null if no mainAlias is properly set.
+ * Name the entity as a property for a TopiaQuery. Careful, this name can be
+ * null if no mainAlias is properly set.
*
* @return the entity name to use in a TopiaQuery
*/
@@ -144,7 +143,7 @@
* @return the property name to use in a TopiaQuery
*/
public String namePropertyId() {
- return nameProperty(TopiaEntity.ID);
+ return nameProperty(TopiaEntity.TOPIA_ID);
}
/**
@@ -153,7 +152,7 @@
* @return the property name to use in a TopiaQuery
*/
public String namePropertyCreateDate() {
- return nameProperty(TopiaEntity.CREATE_DATE);
+ return nameProperty(TopiaEntity.TOPIA_CREATE_DATE);
}
/**
@@ -170,11 +169,10 @@
}
/**
- * Get the entityClass associated with this EntityQueryProperty.
- * Can be useful in some case, to create other query for exemple or to
- * use it in {@link TopiaQuery#addFrom(Class)} method.
- * The entityClass need to be set before calling this method to avoid
- * NullPointerException.
+ * Get the entityClass associated with this EntityQueryProperty. Can be
+ * useful in some case, to create other query for exemple or to use it in
+ * {@link TopiaQuery#addFrom(Class)} method. The entityClass need to be set
+ * before calling this method to avoid NullPointerException.
*
* @return the entity class corresponding to this EntityQueryProperty.
*/
@@ -191,7 +189,7 @@
* instantiate.
*
* @return a new TopiaQuery with the main entity as the EntityQueryProperty
- * provides it.
+ * provides it.
*/
public TopiaQuery newQuery() {
return new TopiaQuery(getEntityClass(), name());
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/bean/Filter.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/bean/Filter.java 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/bean/Filter.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -1,13 +1,13 @@
-
package org.chorem.pollen.bean;
+import org.nuiton.topia.persistence.TopiaEntity;
+
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
-import org.nuiton.topia.persistence.TopiaEntity;
/**
* Filter
- *
+ * <p/>
* Created: 23 avr. 2010
*
* @author fdesbois
@@ -109,11 +109,11 @@
/**
* Set the value of referenceId
*
- * @param entity
+ * @param entity
*/
public void setReference(TopiaEntity entity) {
String oldReferenceId = this.referenceId;
- this.referenceId = entity.getId();
+ this.referenceId = entity.getTopiaId();
propertyChangeSupport.firePropertyChange(PROP_REFERENCE_ID,
oldReferenceId, referenceId);
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteListImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteListImpl.java 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteListImpl.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -48,4 +48,9 @@
addFavoriteParticipant(favorite);
return null;
}
+
+ @Override
+ public String getId() {
+ return getTopiaId();
+ }
}
Added: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantImpl.java (rev 0)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantImpl.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -0,0 +1,15 @@
+package org.chorem.pollen.entity;
+
+/**
+ * Created: 20 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class FavoriteParticipantImpl extends FavoriteParticipantAbstract {
+
+ @Override
+ public String getId() {
+ return getTopiaId();
+ }
+}
Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountImpl.java 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountImpl.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -61,4 +61,9 @@
addChild(account);
return null;
}
+
+ @Override
+ public String getId() {
+ return getTopiaId();
+ }
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServiceFavoriteImpl.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -1,7 +1,5 @@
package org.chorem.pollen.service;
-import java.util.List;
-import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -25,18 +23,23 @@
import org.nuiton.topia.framework.TopiaQuery.Op;
import org.nuiton.topia.persistence.TopiaEntity;
+import java.util.List;
+import java.util.Map;
+
/**
* ServiceFavorite
- *
+ * <p/>
* Created: 5 mai 2010
*
- * @author fdesbois
- * $Id$
+ * @author fdesbois $Id: ServiceFavoriteImpl.java 2996 2010-05-14 12:06:15Z
+ * fdesbois $
*/
public class ServiceFavoriteImpl extends ServiceFavoriteAbstract {
private Log log = LogFactory.getLog(ServiceUserImpl.class);
+
private static final String BINDER_CONTEXT_FAVORITE_LIST = "favoriteList";
+
private PollenContext context;
public void setContext(PollenContext context) {
@@ -50,7 +53,7 @@
@Override
protected void treateError(TopiaContext transaction, Exception eee,
- String message, Object... args) throws PollenException {
+ String message, Object... args) throws PollenException {
context.treateError(transaction, eee, message, args);
}
@@ -68,7 +71,7 @@
@Override
protected void executeCreateFavoriteList(TopiaContext transaction,
- FavoriteList list) throws TopiaException, PollenBusinessException {
+ FavoriteList list) throws TopiaException, PollenBusinessException {
FavoriteListDAO dao = PollenDAOHelper.getFavoriteListDAO(transaction);
@@ -92,10 +95,10 @@
@Override
protected void executeDeleteFavoriteList(TopiaContext transaction,
- FavoriteList list) throws TopiaException {
+ FavoriteList list) throws TopiaException {
FavoriteListDAO dao = PollenDAOHelper.getFavoriteListDAO(transaction);
- FavoriteList listLoaded = dao.findById(list.getId());
+ FavoriteList listLoaded = dao.findByTopiaId(list.getId());
dao.delete(listLoaded);
transaction.commitTransaction();
@@ -113,28 +116,28 @@
}
/**
- * Check if the {@code participant} doesn't already exists with same
- * email, name and favoriteList.
+ * Check if the {@code participant} doesn't already exists with same email,
+ * name and favoriteList.
*
- * @param dao used to verify the existing participant
+ * @param dao used to verify the existing participant
* @param participant FavoriteParticipant to check
* @throws PollenBusinessException if FavoriteParticipant already exists
- * @throws TopiaException for technical errors from ToPIA
+ * @throws TopiaException for technical errors from ToPIA
*/
protected void checkFavoriteParticipant(FavoriteParticipantDAO dao,
- FavoriteParticipant participant)
+ FavoriteParticipant participant)
throws PollenBusinessException, TopiaException {
FavoriteList list = participant.getFavoriteList();
TopiaQuery query = dao.createQuery().
- add(FavoriteParticipant.FAVORITE_LIST, list).
- add(FavoriteParticipant.NAME, participant.getName()).
- add(FavoriteParticipant.EMAIL, participant.getEmail());
+ add(FavoriteParticipant.FAVORITE_LIST, list).
+ add(FavoriteParticipant.NAME, participant.getName()).
+ add(FavoriteParticipant.EMAIL, participant.getEmail());
// Check only on entities different from the one in argument
if (StringUtils.isNotEmpty(participant.getId())) {
- query.add(TopiaEntity.ID, Op.NEQ, participant.getId());
+ query.add(TopiaEntity.TOPIA_ID, Op.NEQ, participant.getId());
}
// existing participant found
@@ -166,7 +169,7 @@
@Override
protected void executeCreateFavoriteParticipant(TopiaContext transaction,
- FavoriteParticipant participant)
+ FavoriteParticipant participant)
throws PollenBusinessException, TopiaException {
FavoriteParticipantDAO dao =
@@ -177,8 +180,8 @@
// Create newParticipant with naturalId
FavoriteParticipant newParticipant =
dao.create(participant.getName(),
- participant.getEmail(),
- participant.getFavoriteList());
+ participant.getEmail(),
+ participant.getFavoriteList());
// Set other field
newParticipant.setWeight(participant.getWeight());
@@ -188,12 +191,12 @@
@Override
protected void executeDeleteFavoriteParticipant(TopiaContext transaction,
- String id) throws TopiaException {
+ String id) throws TopiaException {
FavoriteParticipantDAO dao =
PollenDAOHelper.getFavoriteParticipantDAO(transaction);
- FavoriteParticipant participantLoaded = dao.findById(id);
+ FavoriteParticipant participantLoaded = dao.findByTopiaId(id);
dao.delete(participantLoaded);
@@ -202,7 +205,7 @@
@Override
protected void executeUpdateFavoriteParticipant(TopiaContext transaction,
- FavoriteParticipant participant)
+ FavoriteParticipant participant)
throws TopiaException, PollenBusinessException {
FavoriteParticipantDAO dao =
@@ -211,7 +214,7 @@
checkFavoriteParticipant(dao, participant);
FavoriteParticipant participantLoaded =
- dao.findById(participant.getId());
+ dao.findByTopiaId(participant.getId());
// Set all fields except favoriteList that can't be changed
participantLoaded.setName(participant.getName());
@@ -230,7 +233,7 @@
FavoriteParticipantDAO dao =
PollenDAOHelper.getFavoriteParticipantDAO(transaction);
- FavoriteParticipant result = dao.findById(id);
+ FavoriteParticipant result = dao.findByTopiaId(id);
// Load parent list
result.getFavoriteList();
@@ -263,7 +266,7 @@
@Override
protected int executeGetNbFavoriteParticipants(TopiaContext transaction,
- Filter filter) throws TopiaException {
+ Filter filter) throws TopiaException {
PollenQueryBuilder builder = new PollenQueryBuilder();
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/service/ServicePollImplTest.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -3,7 +3,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PollenDAOHelper;
-import org.chorem.pollen.test.AbstractServiceTest;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.entity.FavoriteList;
@@ -15,8 +14,8 @@
import org.chorem.pollen.entity.PollDAO;
import org.chorem.pollen.entity.PollImpl;
import org.chorem.pollen.entity.UserAccount;
+import org.chorem.pollen.test.AbstractServiceTest;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
@@ -45,6 +44,7 @@
private Poll poll;
//@Before
+
public void init() throws Exception {
// Initialize service and default user
getServicePoll();
@@ -130,7 +130,7 @@
try {
PollDAO dao = PollenDAOHelper.getPollDAO(transaction);
- Poll pollFound = dao.findById(newPoll.getId());
+ Poll pollFound = dao.findByTopiaId(newPoll.getId());
Assert.assertNotNull(pollFound);
Assert.assertNotNull(pollFound.getCreator());
Assert.assertEquals(user, pollFound.getCreator().getUserAccount());
@@ -140,7 +140,7 @@
}
log.info("test 2 : create poll with new creator");
- poll.getCreator().setUserAccount(null);
+ poll.getCreator().setUserAccount(null);
transaction = beginTransaction();
newPoll = null;
@@ -193,7 +193,7 @@
log.info("test 2 : createPollAccounts from two lists : GROUP." +
" One of the list is an existing favorite one");
-
+
transaction = beginTransaction();
try {
// Create only list accounts
@@ -211,7 +211,7 @@
// Check on list1
if (account.getName().equals(list1.getName())) {
Assert.assertEquals(2, account.getChild().size());
- // Check on list2
+ // Check on list2
} else if (account.getName().equals(list2.getName())) {
Assert.assertEquals(3, account.getChild().size());
// Child are person accounts
@@ -252,7 +252,7 @@
PollDAO dao = PollenDAOHelper.getPollDAO(transaction);
Assert.assertTrue(dao.existByNaturalId(poll.getUid()));
Poll pollFound = dao.findByNaturalId(poll.getUid());
-
+
// Check pollType and accounts
Assert.assertEquals(PollType.FREE, pollFound.getPollType());
Assert.assertEquals(0, pollFound.getPollAccount().size());
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -1,7 +1,5 @@
-
package org.chorem.pollen.ui.data;
-import java.util.Date;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.lang.StringUtils;
import org.apache.tapestry5.upload.services.UploadedFile;
@@ -13,28 +11,30 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Date;
+
/**
- * This class extends ChoiceDTO to have the same properties. It had the
- * behavior to be an image or a date depends on the choice type.
- * You have to set the type when needed (changing) or using static methods :
+ * This class extends ChoiceDTO to have the same properties. It had the behavior
+ * to be an image or a date depends on the choice type. You have to set the type
+ * when needed (changing) or using static methods :
* <pre>
* - {@link #getChoiceDate(java.lang.String)} : need the date pattern to format
* - {@link #getChoiceImage(java.lang.String)} : need the pollId to save the
* image
* - {@link #getChoiceText()}
* </pre>
- *
+ * <p/>
* Before saving choices using servicePoll, you have to save the name using
* {@link #saveName()} method : the name to save depends on the choice type.
- *
+ * <p/>
* Created: 6 mars 2010
*
* @author fdesbois
* @version $Revision$
* @since 1.3
- *
- * Mise a jour: $Date$
- * par : $Author$
+ * <p/>
+ * Mise a jour: $Date$ par
+ * : $Author$
*/
public class ChoiceField {
@@ -74,8 +74,8 @@
this.choice = choice;
if (log.isDebugEnabled()) {
log.debug("Instanciate ChoiceField : " +
- "type = " + getChoiceType() +
- " _ name = " + getName());
+ "type = " + getChoiceType() +
+ " _ name = " + getName());
}
switch (getChoiceType()) {
case DATE:
@@ -105,7 +105,7 @@
* Instantiate a new choiceField for an Image ChoiceType.
*
* @param pollUId used to save the image (corresponding to the folder where
- * the image will be saved).
+ * the image will be saved).
* @return the ChoiceField which is image typed
* @see #setImageType(java.lang.String)
*/
@@ -119,7 +119,7 @@
* Instantiate a new choiceField for a Text ChoiceType.
*
* @return the ChoiceField which is text typed
- * @see #setTextType()
+ * @see #setTextType()
*/
public static ChoiceField getChoiceText() {
ChoiceField result = new ChoiceField();
@@ -128,8 +128,8 @@
}
/**
- * Change type of the choice to date type. The date type need a
- * {@code pattern} to format the date when saving the choice.
+ * Change type of the choice to date type. The date type need a {@code
+ * pattern} to format the date when saving the choice.
*
* @see #saveName()
*/
@@ -151,9 +151,7 @@
date = null;
}
- /**
- * Change type of the choice to text type.
- */
+ /** Change type of the choice to text type. */
public void setTextType() {
setChoiceType(ChoiceType.TEXT);
date = null;
@@ -173,7 +171,7 @@
this.image = image;
String contentType = StringUtils.lowerCase(image.getContentType());
if (!contentType.contains("image")) {
- throw new FileUploadException("wrong type " +
+ throw new FileUploadException("wrong type " +
image.getContentType() + " for image upload " +
image.getFileName());
}
@@ -215,9 +213,10 @@
* correspond to the image file name ;
* - TEXT : the text becomes the choice name.
* </pre>
+ *
* @param serviceImage used to save the image
*/
- public void saveName(ServiceImage serviceImage) {
+ public void saveName(ServiceImage serviceImage) {
String name = "";
switch (getChoiceType()) {
case DATE:
@@ -232,7 +231,7 @@
setName(name);
}
- protected Choice getChoice() {
+ public Choice getChoice() {
if (choice == null) {
choice = new ChoiceImpl();
}
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ErrorReport.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ErrorReport.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ErrorReport.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -0,0 +1,57 @@
+package org.chorem.pollen.ui.data;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created: 20 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class ErrorReport {
+
+ protected Map<String, String> fieldErrors;
+
+ protected Collection<String> errors;
+
+ public void recordFieldError(String field, String message) {
+ getFieldErrors().put(field, message);
+ }
+
+ public void recordError(String message) {
+ getErrors().add(message);
+ }
+
+ public Map<String, String> getFieldErrors() {
+ if (fieldErrors == null) {
+ fieldErrors = new HashMap<String, String>();
+ }
+ return fieldErrors;
+ }
+
+ public Collection<String> getErrors() {
+ if (errors == null) {
+ errors = new ArrayList<String>();
+ }
+ return errors;
+ }
+
+ public Collection<String> getAllErrors() {
+ Collection<String> allErrors = new ArrayList<String>(getErrors());
+ allErrors.addAll(getFieldErrors().values());
+ return allErrors;
+ }
+
+ public void clear() {
+ errors = null;
+ fieldErrors = null;
+ }
+
+ public boolean hasErrors() {
+ return !getAllErrors().isEmpty();
+ }
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ErrorReport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FieldValidationException.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FieldValidationException.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FieldValidationException.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -0,0 +1,27 @@
+package org.chorem.pollen.ui.data;
+
+import org.apache.tapestry5.ValidationException;
+
+/**
+ * Created: 20 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class FieldValidationException extends ValidationException {
+
+ protected String field;
+
+ public FieldValidationException(String message) {
+ super(message);
+ }
+
+ public FieldValidationException(String field, String message) {
+ super(message);
+ this.field = field;
+ }
+
+ public String getField() {
+ return field;
+ }
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FieldValidationException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -31,10 +31,10 @@
public static final String PROPERTY_PARTICIPANTS = "participants";
- protected ServicePoll service;
+// protected ServicePoll service;
+//
+// protected PollenManager manager;
- protected PollenManager manager;
-
protected ParticipantList list;
protected ParticipantMap participants;
@@ -49,14 +49,23 @@
}
};
- public ParticipantListModel(ServicePoll service, PollenManager manager) {
- this.service = service;
- this.manager = manager;
+ public ParticipantListModel() {
+// this.service = service;
+// this.manager = manager;
participants = new ParticipantMap();
}
- public Participant addNewParticipant() {
- Participant newParticipant = service.getNewPollParticipant();
+ /**
+ * Instantiate a new participant and add it to the current participants
+ * list.
+ *
+ * @param servicePoll Service used to instantiate a new participant
+ * @param manager Service to manage temporary id if needed
+ * @return a new Participant
+ */
+ public Participant addNewParticipant(ServicePoll servicePoll,
+ PollenManager manager) {
+ Participant newParticipant = servicePoll.getNewPollParticipant();
String id = manager.createPollenId();
participants.put(id, newParticipant);
((TopiaEntity) newParticipant).addPropertyListener(participantsListener);
@@ -77,7 +86,14 @@
return participants.values();
}
- public void setList(ParticipantList participantList) {
+ /**
+ * Set a {@code participantList} for current usage. Will initialize
+ * participants from the list.
+ *
+ * @param manager Service used to manage temporary id if needed
+ * @param participantList ParticipantList to set as current one
+ */
+ public void setList(PollenManager manager, ParticipantList participantList) {
if (logger.isDebugEnabled()) {
logger.debug("Set current list : " + participantList.getName());
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -2,21 +2,29 @@
import org.apache.commons.lang.StringUtils;
import org.apache.tapestry5.ValueEncoder;
+import org.apache.tapestry5.ioc.Messages;
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.common.PollType;
+import org.chorem.pollen.entity.Choice;
import org.chorem.pollen.entity.ParticipantList;
import org.chorem.pollen.entity.Poll;
import org.chorem.pollen.entity.UserAccount;
import org.chorem.pollen.service.ServicePoll;
+import org.chorem.pollen.ui.data.ChoiceField;
+import org.chorem.pollen.ui.data.FieldValidationException;
import org.chorem.pollen.ui.pages.poll.PollForm;
import org.chorem.pollen.ui.services.PollenManager;
+import org.chorem.pollen.ui.services.ServiceImage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Date;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
/**
@@ -43,7 +51,7 @@
public static final String PROPERTY_LISTS = "lists";
/** Service to manage poll */
- protected ServicePoll service;
+// protected ServicePoll service;
/** Current poll in edition */
protected Poll poll;
@@ -51,6 +59,8 @@
/** Current lists in edition */
protected Map<String, ParticipantList> lists;
+ protected List<ChoiceField> choices;
+
/** Current listModel that contains current edited list and its participants */
protected ParticipantListModel listModel;
@@ -67,18 +77,13 @@
};
/**
- * Constructor of PollFormModel. Need services {@code servicePoll} and
- * {@code manager} to manage the current edited poll. Use {@link
- * #initPoll(String, UserAccount)} to initialize the poll.
- *
- * @param servicePoll ServicePoll to manage poll
- * @param manager PollenManager to manage ids
+ * Constructor of PollFormModel. Use {@link #initPoll(ServicePoll, String,
+ * UserAccount)} to initialize the poll.
*/
- public PollFormModel(ServicePoll servicePoll,
- PollenManager manager) {
- this.service = servicePoll;
+ public PollFormModel() {
+// this.service = servicePoll;
lists = new LinkedHashMap<String, ParticipantList>();
- listModel = new ParticipantListModel(service, manager);
+ listModel = new ParticipantListModel();
listModel.addPropertyChangeListener(listsListener);
}
@@ -91,26 +96,26 @@
* @param user Connected user as creator of a new poll (can be null if no
* user is connected).
*/
- public void initPoll(String uid, UserAccount user) {
+ public void initPoll(ServicePoll servicePoll, String uid, UserAccount user) {
if (StringUtils.isNotEmpty(uid)) {
if (logger.isDebugEnabled()) {
logger.debug("Get existing poll with pollUID = " + uid);
}
- poll = service.getPollForUpdate(uid);
+ poll = servicePoll.getPollForUpdate(uid);
// TODO : init advancedOptions
// TODO-fdesbois-2010-05-19 : exception need to be throw if uid not correspond to an existing poll
} else {
if (logger.isDebugEnabled()) {
logger.debug("Init new poll");
}
- poll = service.getNewPoll(user);
+ poll = servicePoll.getNewPoll(user);
createMode = true;
}
}
/**
* Get the current poll. Will be null if initializion with {@link
- * #initPoll(String, UserAccount)} has not been called.
+ * #initPoll(ServicePoll, String, UserAccount)} has not been called.
*
* @return the current poll.
*/
@@ -127,20 +132,43 @@
return createMode;
}
+ public List<ChoiceField> getChoices() {
+ if (choices == null) {
+ choices = new ArrayList<ChoiceField>();
+ if (createMode) {
+ // Initialized to choice TEXT type
+ for (int i = 0; i < 4; i++) {
+ choices.add(ChoiceField.getChoiceText());
+ }
+ } else {
+ for (Choice current : poll.getChoice()) {
+ choices.add(new ChoiceField(poll, current));
+ }
+ }
+ }
+ return choices;
+ }
+
/**
* Change the poll type to {@code type}. The lists managment will depends on
* poll type. For a {@link PollType#RESTRICTED} poll, a new list will be
* automatically added and set for current usage. For a {@link
* PollType#GROUP} poll, the listModel is simply reset.
*
- * @param type PollType to change
+ * @param servicePoll Service used to add a new list for restricted poll
+ * @param manager Service to manage temporary id on participants of the
+ * unique restricted list
+ * @param type PollType to change
+ * @see #addNewList(ServicePoll, String)
+ * @see ParticipantListModel#setList(PollenManager, ParticipantList)
*/
- public void setPollType(PollType type) {
+ public void setPollType(ServicePoll servicePoll, PollenManager manager,
+ PollType type) {
lists.clear();
if (type.isRestricted()) {
- addNewList(DEFAULT_LIST_NAME);
+ addNewList(servicePoll, DEFAULT_LIST_NAME);
// Set automatically the current list to the unique one
- listModel.setList(lists.get(DEFAULT_LIST_NAME));
+ listModel.setList(manager, lists.get(DEFAULT_LIST_NAME));
} else if (type.isGroup()) {
listModel.reset();
}
@@ -166,14 +194,15 @@
* be added if the {@code listName} is empty or if a list with this {@code
* listName} already exists.
*
- * @param listName for the new list to add
+ * @param servicePoll Service used to instantiate a new ParticipantList
+ * @param listName for the new list to add
* @return true if the list has been added, false otherwise
* @see #addList(ParticipantList)
*/
- public boolean addNewList(String listName) {
+ public boolean addNewList(ServicePoll servicePoll, String listName) {
boolean result = false;
if (StringUtils.isNotEmpty(listName)) {
- ParticipantList newList = service.getNewPollList();
+ ParticipantList newList = servicePoll.getNewPollList();
newList.setName(listName);
return addList(newList);
}
@@ -220,11 +249,14 @@
* list will be automatically saved. If error occurs during save, the
* previous list will be refresh (no list change will be done).
*
+ * @param manager Service used to manage temporary id on participants from
+ * the list to set
* @param listName name of the list to set (empty name will be ignored)
* @throws PollenBusinessException for saving error (doubloons)
* @see #saveCurrentList()
*/
- public void setCurrentList(String listName) throws PollenBusinessException {
+ public void setCurrentList(PollenManager manager, String listName)
+ throws PollenBusinessException {
if (StringUtils.isNotEmpty(listName)) {
ParticipantList list = getCurrentList();
try {
@@ -237,7 +269,7 @@
} finally {
// Previous list will be keeped if error occurs during save.
// Apply change in listModel
- listModel.setList(list);
+ listModel.setList(manager, list);
}
}
}
@@ -272,10 +304,75 @@
listModel.persistParticipants();
}
- public void create() throws PollenBusinessException {
- service.createPoll(poll, getLists());
+ /**
+ * Create the poll in business. This will generate choice name to be persist
+ * and used the current lists for restriction.
+ *
+ * @param servicePoll Service used to create the poll.
+ * @param serviceImage Service used to manage image choices save.
+ * @throws PollenBusinessException
+ */
+ public void create(ServicePoll servicePoll, ServiceImage serviceImage)
+ throws PollenBusinessException {
+ poll.clearChoice();
+ for (ChoiceField choiceField : getChoices()) {
+ choiceField.saveName(serviceImage);
+ poll.addChoice(choiceField.getChoice());
+ }
+ servicePoll.createPoll(poll, getLists());
}
+ public void validate(Messages messages) throws FieldValidationException {
+
+ // Initialize beginDate if needed
+ Date beginDate = poll.getBeginDate();
+ if (beginDate == null) {
+ beginDate = new Date();
+ poll.setBeginDate(beginDate);
+ }
+
+ // Check endDate
+ Date endDate = poll.getEndDate();
+ if (endDate != null && endDate.before(beginDate)) {
+ throw new FieldValidationException(
+ PollForm.FORM_FIELD_END_DATE,
+ "error endDate before beginDate");
+ }
+
+ // Add choices is allowed after creation
+ if (poll.getChoiceAddAllowed()) {
+
+ // Initialize beginChoiceDate if needed
+ Date beginChoiceDate = poll.getBeginChoiceDate();
+ if (beginChoiceDate == null) {
+ beginChoiceDate = new Date();
+ poll.setBeginChoiceDate(beginChoiceDate);
+ }
+
+ // Check beginChoiceDate
+ if (endDate != null && beginChoiceDate.after(endDate)) {
+ throw new FieldValidationException(
+ PollForm.FORM_FIELD_BEGIN_CHOICE_DATE,
+ "error beginChoiceDate after endDate");
+ }
+
+ // Check endChoiceDate
+ Date endChoiceDate = poll.getEndChoiceDate();
+ if (endChoiceDate != null && endChoiceDate.before(beginChoiceDate)) {
+ throw new FieldValidationException(
+ PollForm.FORM_FIELD_END_CHOICE_DATE,
+ "error endChoiceDate before beginChoiceDate");
+ }
+ }
+ }
+
+ public Date getBeginDate() {
+ if (poll.getBeginDate() == null) {
+ poll.setBeginDate(new Date());
+ }
+ return poll.getBeginDate();
+ }
+
/**
* ValueEncoder toClient is used to convert {@code value} to the list name.
*
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -17,11 +17,11 @@
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONObject;
+import org.apache.tapestry5.services.ComponentSource;
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
-import org.chorem.pollen.entity.Choice;
import org.chorem.pollen.entity.Participant;
import org.chorem.pollen.entity.ParticipantList;
import org.chorem.pollen.entity.Poll;
@@ -33,15 +33,16 @@
import org.chorem.pollen.ui.components.Border;
import org.chorem.pollen.ui.data.AddressBar;
import org.chorem.pollen.ui.data.ChoiceField;
+import org.chorem.pollen.ui.data.FieldValidationException;
import org.chorem.pollen.ui.models.ParticipantListModel;
import org.chorem.pollen.ui.models.PollFormModel;
import org.chorem.pollen.ui.services.PollenManager;
+import org.chorem.pollen.ui.services.ServiceImage;
import org.nuiton.web.tapestry5.components.FeedBack;
import org.slf4j.Logger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -150,8 +151,8 @@
if (log.isDebugEnabled()) {
log.debug("-------- NEW POLL FORM MODEL --------");
}
- model = new PollFormModel(servicePoll, manager);
- model.initPoll(pollUID, getUserConnected());
+ model = new PollFormModel();
+ model.initPoll(servicePoll, pollUID, getUserConnected());
}
return model;
}
@@ -342,7 +343,7 @@
return getPoll().getPollType().isFree();
}
- /** ******************* LISTS **************************************** */
+ /** ****************** LISTS **************************************** */
@Inject
private ComponentResources resources;
@@ -416,7 +417,7 @@
@Log
Object onUpdatePollType(String value) {
- getModel().setPollType(PollType.valueOf(value));
+ getModel().setPollType(servicePoll, manager, PollType.valueOf(value));
return refreshListZone();
}
@@ -439,9 +440,9 @@
@Log
void onSelectedFromAddList() {
// Set flag for editing lists
- setEditListsFlag();
+ edited = true;
// Add new list in model
- getModel().addNewList(listName);
+ getModel().addNewList(servicePoll, listName);
// Set the new list as selected one
setSelectedList(listName);
// Reset form field before refresh form
@@ -451,7 +452,7 @@
@Log
void onSelectedFromEditList(String listName) {
// Set flag for editing lists
- setEditListsFlag();
+ edited = true;
// Set the selected list
setSelectedList(listName);
}
@@ -460,7 +461,7 @@
// Change current list, will save the previous current one
// Errors can appear during saving previous participants.
try {
- getModel().setCurrentList(listName);
+ getModel().setCurrentList(manager, listName);
} catch (PollenBusinessException eee) {
String message = manager.getErrorMessage(eee, messages, logger);
listsFeedback.addError(message);
@@ -476,7 +477,7 @@
/** PARTICIPANTS FOR LIST ** */
Object onAddRowFromParticipants() {
- return getListModel().addNewParticipant();
+ return getListModel().addNewParticipant(servicePoll, manager);
}
void onRemoveRowFromParticipants(Participant participant) {
@@ -488,12 +489,8 @@
return listsZone.getBody();
}
- protected void setEditListsFlag() {
- editLists = true;
- }
+ /** ********************** CHOIX **************************************** */
- /** *********************** CHOIX **************************************** */
-
@Property
private ChoiceField choice;
@@ -518,20 +515,21 @@
* @return a list of ChoiceDTO
*/
public List<ChoiceField> getChoices() throws PollenBusinessException {
- if (choices == null) {
- choices = new ArrayList<ChoiceField>();
- if (isCreateMode()) {
- // Initialized to choice TEXT type
- for (int i = 0; i < 4; i++) {
- choices.add(ChoiceField.getChoiceText());
- }
- } else {
- for (Choice current : getPoll().getChoice()) {
- choices.add(new ChoiceField(getPoll(), current));
- }
- }
- }
- return choices;
+// if (choices == null) {
+// choices = new ArrayList<ChoiceField>();
+// if (isCreateMode()) {
+// // Initialized to choice TEXT type
+// for (int i = 0; i < 4; i++) {
+// choices.add(ChoiceField.getChoiceText());
+// }
+// } else {
+// for (Choice current : getPoll().getChoice()) {
+// choices.add(new ChoiceField(getPoll(), current));
+// }
+// }
+// }
+// return choices;
+ return getModel().getChoices();
}
public Block getChoiceTypeBlock() {
@@ -552,12 +550,17 @@
private PollStep step;
+ private boolean edited;
+
@Property
private boolean refreshChoicesZone;
@InjectComponent
private Zone choicesZone;
+ @Inject
+ private ServiceImage serviceImage;
+
@Log
Object onChangeFromChoiceType(String value) {
ChoiceType type = ChoiceType.valueOf(value);
@@ -575,11 +578,13 @@
@Log
void onSelectedFromChoiceStep() {
step = PollStep.CHOICES;
+ edited = true;
}
@Log
void onSelectedFromMainStep() {
step = PollStep.MAIN;
+ edited = true;
}
public boolean isChoiceStep() {
@@ -590,11 +595,35 @@
return step.equals(PollStep.MAIN);
}
+ @Inject
+ private ComponentSource componentSource;
+
+ public static final String FORM_FIELD_BEGIN_DATE = "beginDate";
+
+ public static final String FORM_FIELD_END_DATE = "endDate";
+
+ public static final String FORM_FIELD_BEGIN_CHOICE_DATE = "beginChoiceDate";
+
+ public static final String FORM_FIELD_END_CHOICE_DATE = "endChoiceDate";
+
@Log
+ void onValidateForm() {
+ if (!edited) {
+ // Need validations on dates
+ try {
+ getModel().validate(messages);
+ getModel().create(servicePoll, serviceImage);
+ } catch (FieldValidationException eee) {
+ manager.recordFormError(eee, mainForm, componentSource);
+ } catch (PollenBusinessException eee) {
+ String message = manager.getErrorMessage(eee, messages, logger);
+ mainForm.recordError(message);
+ }
+ }
+ }
+
+ @Log
Object onSuccess() {
-// if (!editLists) {
-// saveCurrentList();
-// }
return mainZone;
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java 2010-05-20 10:42:31 UTC (rev 3004)
@@ -21,14 +21,20 @@
package org.chorem.pollen.ui.services;
+import org.apache.tapestry5.Field;
+import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
import org.apache.tapestry5.ioc.services.SymbolProvider;
import org.apache.tapestry5.ioc.util.CaseInsensitiveMap;
+import org.apache.tapestry5.runtime.Component;
+import org.apache.tapestry5.services.ComponentSource;
import org.chorem.pollen.PollenBusinessException;
import org.chorem.pollen.PollenContext;
import org.chorem.pollen.PollenProperty;
import org.chorem.pollen.service.ServiceUser;
+import org.chorem.pollen.ui.data.ErrorReport;
+import org.chorem.pollen.ui.data.FieldValidationException;
import org.nuiton.util.ApplicationConfig;
import org.slf4j.Logger;
@@ -123,19 +129,53 @@
return context.createPollenUrlId();
}
- public String getErrorMessage(PollenBusinessException eee,
+ public String getErrorMessage(PollenBusinessException error,
Messages messages, Logger logger) {
if (logger.isDebugEnabled()) {
- logger.debug("ERROR from business : " + eee.getMessage() +
- " _ args = " + Arrays.toString(eee.getArgs()));
+ logger.debug("ERROR from business : " + error.getMessage() +
+ " _ args = " + Arrays.toString(error.getArgs()));
}
String message = null;
- if (eee.getArgs() != null) {
- message = messages.format(eee.getMessage(), eee.getArgs());
+ if (error.getArgs() != null) {
+ message = messages.format(error.getMessage(), error.getArgs());
} else {
- message = messages.get(eee.getMessage());
+ message = messages.get(error.getMessage());
}
return message;
}
+ public void recordFormError(FieldValidationException error,
+ Form form, ComponentSource componentSource)
+ throws ClassCastException {
+ if (error.getField() == null) {
+ form.recordError(error.getMessage());
+ } else {
+ Field field = getFieldByName(error.getField(), componentSource);
+ form.recordError(field, error.getMessage());
+ }
+ }
+
+ public void recordFormErrors(ErrorReport report,
+ Form form, ComponentSource componentSource)
+ throws ClassCastException {
+
+ for (Map.Entry<String, String> entry : report.getFieldErrors().entrySet()) {
+ Field field = getFieldByName(entry.getKey(), componentSource);
+ form.recordError(field, entry.getValue());
+ }
+ for (String message : report.getErrors()) {
+ form.recordError(message);
+ }
+ }
+
+ protected Field getFieldByName(String field, ComponentSource componentSource)
+ throws ClassCastException {
+ Component component = componentSource.getComponent(field);
+ if (!(component instanceof Field)) {
+ throw new ClassCastException("invalid cast to Field from : " +
+ component.getClass().getName());
+ }
+ return (Field) component;
+ }
+
}
Modified: trunk/pollen-ui/src/main/webapp/poll/PollForm.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/PollForm.tml 2010-05-19 18:25:58 UTC (rev 3003)
+++ trunk/pollen-ui/src/main/webapp/poll/PollForm.tml 2010-05-20 10:42:31 UTC (rev 3004)
@@ -5,50 +5,57 @@
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:p="tapestry:parameter">
-<h1 class="titlePoll">
+ <h1 class="titlePoll">
<t:if t:test="createMode">
- ${message:mainTitle-create}
- <p:else>${poll.title}</p:else>
+ ${message:mainTitle-create}
+ <p:else>${poll.title}</p:else>
</t:if>
-</h1>
+ </h1>
-<t:zone t:id="mainZone" t:update="show">
-<form t:type="form" t:id="mainForm" t:zone="mainZone" action="post">
-<t:errors />
-<t:formFragment t:id="mainFormFragment" t:visible="mainStep">
+ <t:zone t:id="mainZone" t:update="show">
+ <form t:type="form" t:id="mainForm" t:zone="mainZone" action="post">
+ <t:errors />
+ <t:formFragment t:id="mainFormFragment" t:visible="mainStep">
-<!-- MAIN INFOS -->
-<div id="p-pollForm-mainInfos">
- <fieldset>
- <legend>
- <img class="form-toggle" src="${asset:context:img/1uparrow.png}" /> ${message:legend-mainInfos}
- </legend>
- <div class="form-block">
- <p>
- <span><label t:type="label" t:for="title" />:</span>
+ <!-- MAIN INFOS -->
+ <div id="p-pollForm-mainInfos">
+ <fieldset>
+ <legend>
+ <img class="form-toggle"
+ src="${asset:context:img/1uparrow.png}" alt="toggle" /> ${message:legend-mainInfos}
+ </legend>
+ <div class="form-block">
+ <p>
+ <span><label t:type="label" t:for="title" />:
+ </span>
<input type="text" t:type="textfield" class="title" t:id="title"
value="poll.title" t:validate="required" />
- </p>
+ </p>
- <p>
- <span><label t:type="label" t:for="creatorName" />:</span>
+ <p>
+ <span><label t:type="label" t:for="creatorName" />:
+ </span>
<input type="text" t:type="textfield" t:id="creatorName"
value="poll.creator.name"
t:validate="required,minlength=2" />
<label t:type="label" t:for="email" />:
<input type="text" t:type="textfield" class="email" t:id="email"
value="poll.creator.email" t:validate="regexp" />
- </p>
+ </p>
- <p>
- <span><label t:type="label" t:for="description" />: </span>
+ <p>
+ <span><label t:type="label" t:for="description" />:
+ </span>
<textarea t:type="textarea" cols="80" rows="2"
- t:id="description" t:value="poll.description">${poll.description}</textarea>
- </p>
+ t:id="description" t:value="poll.description">
+ ${poll.description}
+ </textarea>
+ </p>
- <p>
+ <p>
<!-- FIXME : validate by regexp doesn't work : seems to be caused by dateTimeField component -->
- <span><label t:type="label" t:for="beginDate" />: </span>
+ <span><label t:type="label" t:for="beginDate" />:
+ </span>
<input t:type="ck/dateTimeField" t:id="beginDate"
value="poll.beginDate" t:validate="regexp"
t:datePattern="message:date-pattern" t:timePicker="true"
@@ -62,370 +69,371 @@
<label t:type="label" t:for="voteCountingType" />:
<select t:type="select" t:id="voteCountingType"
t:value="poll.voteCountingType" t:validate="required">
- <option></option>
+ <option></option>
</select>
- <span t:type="ck/Tooltip" title="${message:help}"
- t:value="${message:voteCounting-help}"
- t:effect="appear">
- <img src="${asset:context:img/help.png}"
- alt="${message:help}" />
- </span>
- </p>
+ <span t:type="ck/Tooltip" title="${message:help}"
+ t:value="${message:voteCounting-help}"
+ t:effect="appear">
+ <img src="${asset:context:img/help.png}"
+ alt="${message:help}" />
+ </span>
+ </p>
+ </div>
+ </fieldset>
</div>
- </fieldset>
-</div>
-<!-- OPTIONS -->
-<div id="p-pollForm-options">
- <fieldset>
- <legend>
- <!--<input t:type="checkbox" t:id="advancedOptions" t:mixins="triggerfragment" t:fragment="optionsFragment"/>-->
- <!--<label t:type="label" t:for="advancedOptions"/>-->
- <img class="form-toggle"
- src="${asset:context:img/1downarrow.png}" /> ${message:legend-options}
- </legend>
- <div class="form-block clearfix" style="display:none;">
- <!--<t:formFragment t:id="optionsFragment" visible="advancedOptions">-->
- <!-- LEFT COLUMN -->
- <div class="left-column fleft">
+ <!-- OPTIONS -->
+ <div id="p-pollForm-options">
+ <fieldset>
+ <legend>
+ <!--<input t:type="checkbox" t:id="advancedOptions" t:mixins="triggerfragment" t:fragment="optionsFragment"/>-->
+ <!--<label t:type="label" t:for="advancedOptions"/>-->
+ <img class="form-toggle"
+ src="${asset:context:img/1downarrow.png}" /> ${message:legend-options}
+ </legend>
+ <div class="form-block clearfix" style="display:none;">
+ <!--<t:formFragment t:id="optionsFragment" visible="advancedOptions">-->
+ <!-- LEFT COLUMN -->
+ <div class="left-column fleft">
<p>
- <input t:type="checkbox" t:id="anonymous"
- value="poll.anonymous" />
- <label t:type="label" t:for="anonymous" />
- <span t:type="ck/Tooltip" title="message:help"
- t:value="message:anonymous-help"
- t:effect="appear">
- <img src="${asset:context:img/help.png}"
- alt="message:help" />
- </span>
+ <input t:type="checkbox" t:id="anonymous"
+ value="poll.anonymous" />
+ <label t:type="label" t:for="anonymous" />
+ <span t:type="ck/Tooltip" title="message:help"
+ t:value="message:anonymous-help"
+ t:effect="appear">
+ <img src="${asset:context:img/help.png}"
+ alt="message:help" />
+ </span>
</p>
<p>
- <input t:type="checkbox" t:id="continuousResults"
- value="poll.continuousResults" />
- <label t:type="label" t:for="continuousResults" />
- <span t:type="ck/Tooltip" title="message:help"
- t:value="message:continuousResults-help"
- t:effect="appear">
- <img src="${asset:context:img/help.png}"
- alt="message:help" />
- </span>
+ <input t:type="checkbox" t:id="continuousResults"
+ value="poll.continuousResults" />
+ <label t:type="label" t:for="continuousResults" />
+ <span t:type="ck/Tooltip" title="message:help"
+ t:value="message:continuousResults-help"
+ t:effect="appear">
+ <img src="${asset:context:img/help.png}"
+ alt="message:help" />
+ </span>
</p>
<p>
- <input t:type="checkbox" t:id="choiceAddAllowed"
- value="poll.choiceAddAllowed"
- t:mixins="triggerfragment"
- t:fragment="choiceDateFragment" />
- <label t:type="label" t:for="choiceAddAllowed" />
- <span t:type="ck/Tooltip" title="message:help"
- t:value="message:choiceAddAllowed-help}"
- t:effect="appear">
- <img src="${asset:context:img/help.png}"
- alt="message:help" />
- </span>
+ <input t:type="checkbox" t:id="choiceAddAllowed"
+ value="poll.choiceAddAllowed"
+ t:mixins="triggerfragment"
+ t:fragment="choiceDateFragment" />
+ <label t:type="label" t:for="choiceAddAllowed" />
+ <span t:type="ck/Tooltip" title="message:help"
+ t:value="message:choiceAddAllowed-help}"
+ t:effect="appear">
+ <img src="${asset:context:img/help.png}"
+ alt="message:help" />
+ </span>
</p>
<p>
- <t:formFragment t:id="choiceDateFragment"
- t:visible="poll.choiceAddAllowed">
- <label t:type="label" t:for="beginChoiceDate" />
- <input t:type="ck/dateTimeField" t:id="beginChoiceDate"
- value="poll.beginChoiceDate" t:validate="regexp"
- t:datePattern="message:date-pattern"
- t:timePicker="true"
- t:timePickerAdjacent="true" />
- <br />
- <label t:type="label" t:for="endChoiceDate" />
- <input t:type="ck/dateTimeField" t:id="endChoiceDate"
- value="poll.endChoiceDate" t:validate="regexp"
- t:datePattern="message:date-pattern"
- t:timePicker="true"
- t:timePickerAdjacent="true" />
- </t:formFragment>
+ <t:formFragment t:id="choiceDateFragment"
+ t:visible="poll.choiceAddAllowed">
+ <label t:type="label" t:for="beginChoiceDate" />
+ <input t:type="ck/dateTimeField" t:id="beginChoiceDate"
+ value="poll.beginChoiceDate" t:validate="regexp"
+ t:datePattern="message:date-pattern"
+ t:timePicker="true"
+ t:timePickerAdjacent="true" />
+ <br />
+ <label t:type="label" t:for="endChoiceDate" />
+ <input t:type="ck/dateTimeField" t:id="endChoiceDate"
+ value="poll.endChoiceDate" t:validate="regexp"
+ t:datePattern="message:date-pattern"
+ t:timePicker="true"
+ t:timePickerAdjacent="true" />
+ </t:formFragment>
</p>
<p>
- <input t:type="checkbox" t:id="sendNotification"
- value="hasNotification"
- disabled="notificationDisabled"
- t:mixins="triggerfragment"
- t:fragment="notificationFragment" />
- <label t:type="label" t:for="sendNotification" />
- <span t:type="ck/Tooltip" title="message:help"
- t:value="message:sendNotification-help"
- t:effect="appear">
- <img src="${asset:context:img/help.png}"
- alt="message:help" />
- </span>
+ <input t:type="checkbox" t:id="sendNotification"
+ value="hasNotification"
+ disabled="notificationDisabled"
+ t:mixins="triggerfragment"
+ t:fragment="notificationFragment" />
+ <label t:type="label" t:for="sendNotification" />
+ <span t:type="ck/Tooltip" title="message:help"
+ t:value="message:sendNotification-help"
+ t:effect="appear">
+ <img src="${asset:context:img/help.png}"
+ alt="message:help" />
+ </span>
</p>
<p>
- <t:formFragment id="notificationHidden"
- t:id="notificationFragment"
- t:visible="hasNotification">
- <label t:type="label" t:for="notification" />
- <input t:type="textfield" t:id="notification"
- value="notification.sensibility" t:size="3"
- t:validate="min=0" />
- ${message:notification-label2}
- </t:formFragment>
+ <t:formFragment id="notificationHidden"
+ t:id="notificationFragment"
+ t:visible="hasNotification">
+ <label t:type="label" t:for="notification" />
+ <input t:type="textfield" t:id="notification"
+ value="notification.sensibility" t:size="3"
+ t:validate="min=0" />
+ ${message:notification-label2}
+ </t:formFragment>
</p>
- </div>
- <!-- RIGHT COLUMN -->
- <div class="fleft">
+ </div>
+ <!-- RIGHT COLUMN -->
+ <div class="fleft">
<p>
- <input t:type="checkbox" t:id="anonymousVoteAllowed"
- value="poll.anonymousVoteAllowed"
- disabled="anonymousVoteAllowedDisabled" />
- <label t:type="label" t:for="anonymousVoteAllowed" />
- <span t:type="ck/Tooltip" title="message:help"
- t:value="message:anonymousVoteAllowed-help"
- t:effect="appear">
- <img src="${asset:context:img/help.png}"
- alt="message:help" />
- </span>
+ <input t:type="checkbox" t:id="anonymousVoteAllowed"
+ value="poll.anonymousVoteAllowed"
+ disabled="anonymousVoteAllowedDisabled" />
+ <label t:type="label" t:for="anonymousVoteAllowed" />
+ <span t:type="ck/Tooltip" title="message:help"
+ t:value="message:anonymousVoteAllowed-help"
+ t:effect="appear">
+ <img src="${asset:context:img/help.png}"
+ alt="message:help" />
+ </span>
</p>
<p>
- <input t:type="checkbox" t:id="publicResults"
- value="poll.publicResults"
- disabled="publicResultsDisabled" />
- <label t:type="label" t:for="publicResults" />
- <span t:type="ck/Tooltip" title="message:help"
- t:value="message:publicResults-help"
- t:effect="appear">
- <img src="${asset:context:img/help.png}"
- alt="message:help" />
- </span>
+ <input t:type="checkbox" t:id="publicResults"
+ value="poll.publicResults"
+ disabled="publicResultsDisabled" />
+ <label t:type="label" t:for="publicResults" />
+ <span t:type="ck/Tooltip" title="message:help"
+ t:value="message:publicResults-help"
+ t:effect="appear">
+ <img src="${asset:context:img/help.png}"
+ alt="message:help" />
+ </span>
</p>
<p>
- <input t:type="checkbox" t:id="choiceNb" value="hasChoiceNb"
- disabled="choiceNbDisabled"
- t:mixins="triggerFragment"
- t:fragment="choiceNbFragment" />
- <label t:type="label" t:for="choiceNb" />
- <span t:type="ck/Tooltip" title="message:help"
- t:value="message:choiceNb-help"
- t:effect="appear">
- <img src="${asset:context:img/help.png}"
- alt="message:help" />
- </span>
+ <input t:type="checkbox" t:id="choiceNb" value="hasChoiceNb"
+ disabled="choiceNbDisabled"
+ t:mixins="triggerFragment"
+ t:fragment="choiceNbFragment" />
+ <label t:type="label" t:for="choiceNb" />
+ <span t:type="ck/Tooltip" title="message:help"
+ t:value="message:choiceNb-help"
+ t:effect="appear">
+ <img src="${asset:context:img/help.png}"
+ alt="message:help" />
+ </span>
</p>
<p>
- <t:formFragment id="choiceNbHidden" t:id="choiceNbFragment"
- t:visible="hasChoiceNb">
- <label t:type="label" t:for="maxChoiceNb" />
- <input t:type="textfield" t:id="maxChoiceNb"
- t:value="poll.maxChoiceNb" t:size="1"
- t:validate="min=0" />
- </t:formFragment>
+ <t:formFragment id="choiceNbHidden" t:id="choiceNbFragment"
+ t:visible="hasChoiceNb">
+ <label t:type="label" t:for="maxChoiceNb" />
+ <input t:type="textfield" t:id="maxChoiceNb"
+ t:value="poll.maxChoiceNb" t:size="1"
+ t:validate="min=0" />
+ </t:formFragment>
</p>
<p>
- <input t:type="checkbox" t:id="sendReminder"
- t:value="hasReminder" disabled="reminderDisabled"
- t:mixins="triggerfragment"
- t:fragment="reminderFragment" />
- <label t:type="label" t:for="sendReminder" />
- <span t:type="ck/Tooltip" title="message:help"
- t:value="message:sendReminder-help"
- t:effect="appear">
- <img src="${asset:context:img/help.png}"
- alt="message:help" />
- </span>
+ <input t:type="checkbox" t:id="sendReminder"
+ t:value="hasReminder" disabled="reminderDisabled"
+ t:mixins="triggerfragment"
+ t:fragment="reminderFragment" />
+ <label t:type="label" t:for="sendReminder" />
+ <span t:type="ck/Tooltip" title="message:help"
+ t:value="message:sendReminder-help"
+ t:effect="appear">
+ <img src="${asset:context:img/help.png}"
+ alt="message:help" />
+ </span>
</p>
<p>
- <t:formFragment id="reminderHidden" t:id="reminderFragment"
- t:visible="hasReminder">
- <input t:type="textfield" t:id="reminder"
- t:value="reminder.sensibility" t:size="1"
- t:validate="min=0" />
- <label t:type="label" t:for="reminder" />
- </t:formFragment>
+ <t:formFragment id="reminderHidden" t:id="reminderFragment"
+ t:visible="hasReminder">
+ <input t:type="textfield" t:id="reminder"
+ t:value="reminder.sensibility" t:size="1"
+ t:validate="min=0" />
+ <label t:type="label" t:for="reminder" />
+ </t:formFragment>
</p>
+ </div>
+ <!--</t:formFragment>-->
</div>
- <!--</t:formFragment>-->
+ </fieldset>
</div>
- </fieldset>
-</div>
-<!-- LISTS -->
-<div id="p-pollForm-lists">
- <fieldset>
- <legend>
- <label t:type="label" t:for="pollType" />:
- <!--<select t:type="select" t:id="pollType" class="list-select" t:value="poll.pollType" t:validate="required"-->
- <!--t:mixins="nuiton/zoneUpdater" t:event="change" t:zone="p-pollForm-lists-zone" />-->
- <select t:type="select" t:id="pollType" t:value="poll.pollType"
- t:validate="required"
- t:mixins="ck/onEvent" t:event="change"
- t:onCompleteCallback="onConfirmRefreshZone" />
- <span t:type="ck/Tooltip" title="message:help"
- t:value="message:pollType-help" t:effect="appear">
+ <!-- LISTS -->
+ <div id="p-pollForm-lists">
+ <fieldset>
+ <legend>
+ <label t:type="label" t:for="pollType" />:
+ <!--<select t:type="select" t:id="pollType" class="list-select" t:value="poll.pollType" t:validate="required"-->
+ <!--t:mixins="nuiton/zoneUpdater" t:event="change" t:zone="p-pollForm-lists-zone" />-->
+ <select t:type="select" t:id="pollType" t:value="poll.pollType"
+ t:validate="required"
+ t:mixins="ck/onEvent" t:event="change"
+ t:onCompleteCallback="onConfirmRefreshZone" />
+ <span t:type="ck/Tooltip" title="message:help"
+ t:value="message:pollType-help" t:effect="appear">
<img src="${asset:context:img/help.png}" alt="message:help" />
- </span>
- </legend>
- <div t:type="zone" t:id="listsZone" id="p-pollForm-lists-zone"
- class="form-block" t:update="show">
- <t:if t:test="canDisplayLists()">
+ </span>
+ </legend>
+ <div t:type="zone" t:id="listsZone" id="p-pollForm-lists-zone"
+ class="form-block" t:update="show">
+ <t:if t:test="canDisplayLists()">
<t:nuiton.feedback t:id="listsFeedback" />
<br />
<t:subForm t:visible="refreshListsZone">
- <t:if t:test="poll.pollType.group">
- <p>
- <label t:type="label" t:for="groupName" />:
- <input t:type="textfield" t:id="groupName"
- value="listName" />
- <input t:type="submit" t:id="addList"
- value="${message:pollen.ui.button.add}" />
- </p>
+ <t:if t:test="poll.pollType.group">
+ <p>
+ <label t:type="label" t:for="groupName" />:
+ <input t:type="textfield" t:id="groupName"
+ value="listName" />
+ <input t:type="submit" t:id="addList"
+ value="${message:pollen.ui.button.add}" />
+ </p>
- <p class="center">
- <t:loop t:source="lists" t:value="list"
- t:encoder="model">
- <input class="list-edition${styleSelected}"
- t:type="nuiton/submitContext"
- t:context="list.name" t:id="editList"
- value="${list.name}" />
- <t:if t:test="currentListSelected">
- <a t:type="actionlink" t:id="removeList"
- t:zone="p-pollForm-lists-zone">
- <span t:type="any"
- t:mixins="nuiton/confirm">
- <img src="${asset:context:img/delete.png}"
- alt="${message:delete}" />
- </span>
- </a>
- </t:if>
- </t:loop>
- </p>
- </t:if>
- <t:if t:test="listSelected">
- <div class="t-data-grid">
- <table class="t-data-grid">
- <thead>
- <tr>
- <th>
- ${message:pollen.ui.participant.name-label}
- </th>
- <th>
- ${message:pollen.ui.participant.email-label}
- </th>
- <th>
- ${message:pollen.ui.participant.weight-label}
- </th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- <tr t:type="ajaxformloop" t:id="participants"
- source="listModel.participants"
- value="participant" t:encoder="listModel">
- <td>
- <t:textfield t:id="participantName"
- value="participant.name"
- size="20"
- t:validate="required" />
- </td>
- <td>
- <t:textfield t:id="participantEmail"
- value="participant.email"
- size="25" />
- </td>
- <td>
- <t:textfield t:id="participantWeight"
- value="participant.weight"
- size="1" />
- </td>
- <td>
- <t:removerowlink>
- <img src="${asset:context:img/delete.png}"
- alt="${message:delete}" />
- </t:removerowlink>
- </td>
- <p:addRow>
- <td colspan="4" class="center">
- <t:addrowlink>
- ${message:pollen.ui.participant.add}
- </t:addrowlink>
- </td>
- </p:addRow>
- </tr>
- </tbody>
- </table>
- </div>
- </t:if>
+ <p class="center">
+ <t:loop t:source="lists" t:value="list"
+ t:encoder="model">
+ <input class="list-edition${styleSelected}"
+ t:type="nuiton/submitContext"
+ t:context="list.name" t:id="editList"
+ value="${list.name}" />
+ <t:if t:test="currentListSelected">
+ <a t:type="actionlink" t:id="removeList"
+ t:zone="p-pollForm-lists-zone">
+ <span t:type="any"
+ t:mixins="nuiton/confirm">
+ <img src="${asset:context:img/delete.png}"
+ alt="${message:delete}" />
+ </span>
+ </a>
+ </t:if>
+ </t:loop>
+ </p>
+ </t:if>
+ <t:if t:test="listSelected">
+ <div class="t-data-grid">
+ <table class="t-data-grid">
+ <thead>
+ <tr>
+ <th>
+ ${message:pollen.ui.participant.name-label}
+ </th>
+ <th>
+ ${message:pollen.ui.participant.email-label}
+ </th>
+ <th>
+ ${message:pollen.ui.participant.weight-label}
+ </th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr t:type="ajaxformloop" t:id="participants"
+ source="listModel.participants"
+ value="participant" t:encoder="listModel">
+ <td>
+ <t:textfield t:id="participantName"
+ value="participant.name"
+ size="20"
+ t:validate="required" />
+ </td>
+ <td>
+ <t:textfield t:id="participantEmail"
+ value="participant.email"
+ size="25" />
+ </td>
+ <td>
+ <t:textfield t:id="participantWeight"
+ value="participant.weight"
+ size="1" />
+ </td>
+ <td>
+ <t:removerowlink>
+ <img src="${asset:context:img/delete.png}"
+ alt="${message:delete}" />
+ </t:removerowlink>
+ </td>
+ <p:addRow>
+ <td colspan="4" class="center">
+ <t:addrowlink>
+ ${message:pollen.ui.participant.add}
+ </t:addrowlink>
+ </td>
+ </p:addRow>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </t:if>
</t:subForm>
- </t:if>
+ </t:if>
+ </div>
+ </fieldset>
+ <p class="center">
+ <input t:type="submit" t:id="choiceStep" value="CHOICE" />
+ </p>
</div>
- </fieldset>
- <p class="center"><input t:type="submit" t:id="choiceStep" value="CHOICE" />
- </p>
-</div>
-</t:formFragment>
-<t:formFragment t:id="choiceFormFragment" t:visible="choiceStep">
+ </t:formFragment>
+ <t:formFragment t:id="choiceFormFragment" t:visible="choiceStep">
- <!-- CHOICES -->
- <div id="p-pollForm-choices">
- <fieldset>
+ <!-- CHOICES -->
+ <div id="p-pollForm-choices">
+ <fieldset>
<legend>
- <label t:type="label" t:for="choiceType" />:
- <select t:type="select" t:id="choiceType"
- t:value="poll.choiceType" t:validate="required"
- t:mixins="nuiton/zoneUpdater" t:event="change"
- t:zone="p-pollForm-choices-zone" />
+ <label t:type="label" t:for="choiceType" />:
+ <select t:type="select" t:id="choiceType"
+ t:value="poll.choiceType" t:validate="required"
+ t:mixins="nuiton/zoneUpdater" t:event="change"
+ t:zone="p-pollForm-choices-zone" />
</legend>
<t:zone t:id="choicesZone" id="p-pollForm-choices-zone">
- <t:subForm t:visible="refreshChoicesZone">
- <div t:type="loop" t:source="choices" t:value="choice"
- t:volatile="true" class="clearfix">
- <div class="fleft choiceName">
- <t:delegate t:to="choiceTypeBlock" />
- <t:block t:id="choiceText">
- <label t:type="label" t:for="choiceTextField" />:
- <input type="text" class="nameField"
- t:type="textfield" t:id="choiceTextField"
- value="choice.text" />
- </t:block>
- <t:block t:id="choiceDate">
- <label t:type="label" t:for="choiceDateField" />:
- <input t:type="ck/dateTimeField"
- t:id="choiceDateField"
- value="choice.date" t:validate="regexp"
- t:datePattern="message:date-pattern"
- t:timePicker="true"
- t:timePickerAdjacent="true" />
- </t:block>
- <t:block t:id="choiceImage">
- <label t:type="label"
- t:for="choiceImageField" />:
- <input type="file" class="nameField"
- t:type="upload" t:id="choiceImageField"
- value="choice.image"
- t:validate="regexp" />
- </t:block>
- <t:block t:id="choiceDisplay">
- ${choice.name}
- </t:block>
-
- <t:label t:for="choiceDescription" />
- :
- </div>
- <div class="fleft">
- <t:textarea cols="34" rows="1"
- t:id="choiceDescription"
- t:value="choice.description" />
- </div>
- </div>
- </t:subForm>
+ <t:subForm t:visible="refreshChoicesZone">
+ <div t:type="loop" t:source="choices" t:value="choice"
+ t:volatile="true" class="clearfix">
+ <div class="fleft choiceName">
+ <t:delegate t:to="choiceTypeBlock" />
+ <t:block t:id="choiceText">
+ <label t:type="label" t:for="choiceTextField" />:
+ <input type="text" class="nameField"
+ t:type="textfield" t:id="choiceTextField"
+ value="choice.text" />
+ </t:block>
+ <t:block t:id="choiceDate">
+ <label t:type="label" t:for="choiceDateField" />:
+ <input t:type="ck/dateTimeField"
+ t:id="choiceDateField"
+ value="choice.date" t:validate="regexp"
+ t:datePattern="message:date-pattern"
+ t:timePicker="true"
+ t:timePickerAdjacent="true" />
+ </t:block>
+ <t:block t:id="choiceImage">
+ <label t:type="label"
+ t:for="choiceImageField" />:
+ <input type="file" class="nameField"
+ t:type="upload" t:id="choiceImageField"
+ value="choice.image"
+ t:validate="regexp" />
+ </t:block>
+ <t:block t:id="choiceDisplay">
+ ${choice.name}
+ </t:block>
+
+ <t:label t:for="choiceDescription" />
+ :
+ </div>
+ <div class="fleft">
+ <t:textarea cols="34" rows="1"
+ t:id="choiceDescription"
+ t:value="choice.description" />
+ </div>
+ </div>
+ </t:subForm>
</t:zone>
- </fieldset>
- </div>
- <p class="center">
- <input t:type="submit" t:id="mainStep" value="PREVIOUS" />
- <input t:type="submit" t:id="save" value="SAVE" />
- </p>
-</t:formFragment>
-</form>
-</t:zone>
+ </fieldset>
+ </div>
+ <p class="center">
+ <input t:type="submit" t:id="mainStep" value="PREVIOUS" />
+ <input t:type="submit" t:id="save" value="SAVE" />
+ </p>
+ </t:formFragment>
+ </form>
+ </t:zone>
</html>
1
0
r3003 - in trunk: pollen-business/src/main/xmi pollen-ui/src/main/java/org/chorem/pollen/ui/components pollen-ui/src/main/java/org/chorem/pollen/ui/data pollen-ui/src/main/java/org/chorem/pollen/ui/models pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll pollen-ui/src/main/resources/i18n pollen-ui/src/main/webapp/js pollen-ui/src/main/webapp/poll
by fdesbois@users.chorem.org 19 May '10
by fdesbois@users.chorem.org 19 May '10
19 May '10
Author: fdesbois
Date: 2010-05-19 20:25:58 +0200 (Wed, 19 May 2010)
New Revision: 3003
Url: http://chorem.org/repositories/revision/pollen/3003
Log:
- Use listeners to check changes on lists
- Uncomment choices managment -> other formFragment
- Inversion of subForm boolean
Removed:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollStep.java
Modified:
trunk/pollen-business/src/main/xmi/pollen.zargo
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/SubForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
trunk/pollen-ui/src/main/webapp/js/pollen.js
trunk/pollen-ui/src/main/webapp/poll/PollForm.tml
Modified: trunk/pollen-business/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/SubForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/SubForm.java 2010-05-19 13:25:45 UTC (rev 3002)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/SubForm.java 2010-05-19 18:25:58 UTC (rev 3003)
@@ -30,8 +30,8 @@
logger.debug("form already visible : " + visible);
}
if (visible) {
- return noFormBlock;
+ return formBlock;
}
- return formBlock;
+ return noFormBlock;
}
}
Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollStep.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollStep.java 2010-05-19 13:25:45 UTC (rev 3002)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollStep.java 2010-05-19 18:25:58 UTC (rev 3003)
@@ -1,32 +0,0 @@
-/* *##% Pollen
- * Copyright (C) 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>. ##%*/
-
-package org.chorem.pollen.ui.data;
-
-/** Énumération représentant les étapes du formulaire de création de sondage. */
-public enum PollStep {
- POLL(1), OPTIONS(2), LISTS(3), CHOICES(4);
-
- protected Integer index;
-
- private PollStep(Integer index) {
- this.index = index;
- }
-
- public Integer getIndex() {
- return index;
- }
-}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java 2010-05-19 13:25:45 UTC (rev 3002)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java 2010-05-19 18:25:58 UTC (rev 3003)
@@ -6,9 +6,13 @@
import org.chorem.pollen.entity.ParticipantList;
import org.chorem.pollen.service.ServicePoll;
import org.chorem.pollen.ui.services.PollenManager;
+import org.nuiton.topia.persistence.TopiaEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -25,6 +29,8 @@
private static final Logger logger =
LoggerFactory.getLogger(ParticipantListModel.class);
+ public static final String PROPERTY_PARTICIPANTS = "participants";
+
protected ServicePoll service;
protected PollenManager manager;
@@ -33,6 +39,16 @@
protected ParticipantMap participants;
+ protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
+
+ protected final PropertyChangeListener participantsListener =
+ new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ firePropertyChange(PROPERTY_PARTICIPANTS, participants);
+ }
+ };
+
public ParticipantListModel(ServicePoll service, PollenManager manager) {
this.service = service;
this.manager = manager;
@@ -43,6 +59,8 @@
Participant newParticipant = service.getNewPollParticipant();
String id = manager.createPollenId();
participants.put(id, newParticipant);
+ ((TopiaEntity) newParticipant).addPropertyListener(participantsListener);
+ firePropertyChange(PROPERTY_PARTICIPANTS, participants);
return newParticipant;
}
@@ -51,6 +69,8 @@
logger.debug("Remove participant : " + participant);
}
participants.remove(participant);
+ ((TopiaEntity) participant).removePropertyListener(participantsListener);
+ firePropertyChange(PROPERTY_PARTICIPANTS, participants);
}
public Collection<Participant> getParticipants() {
@@ -115,6 +135,34 @@
}
/**
+ * addPropertyChangeListener :
+ *
+ * @param listener
+ */
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ /**
+ * removePropertyChangeListener :
+ *
+ * @param listener
+ */
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * firePropertyChange :
+ *
+ * @param propertyName
+ * @param newValue
+ */
+ protected void firePropertyChange(String propertyName, Object newValue) {
+ pcs.firePropertyChange(propertyName, null, newValue);
+ }
+
+ /**
* Participant map is a BidiMap ordered on values inserted using a {@link
* LinkedHashMap}.
*/
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-19 13:25:45 UTC (rev 3002)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-19 18:25:58 UTC (rev 3003)
@@ -13,6 +13,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -38,6 +40,8 @@
/** Default listName for Restricted Poll */
private static final String DEFAULT_LIST_NAME = "LIST";
+ public static final String PROPERTY_LISTS = "lists";
+
/** Service to manage poll */
protected ServicePoll service;
@@ -52,6 +56,16 @@
protected boolean createMode;
+ protected boolean listsChanged;
+
+ protected final PropertyChangeListener listsListener =
+ new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ listsChanged = true;
+ }
+ };
+
/**
* Constructor of PollFormModel. Need services {@code servicePoll} and
* {@code manager} to manage the current edited poll. Use {@link
@@ -64,7 +78,8 @@
PollenManager manager) {
this.service = servicePoll;
lists = new LinkedHashMap<String, ParticipantList>();
- this.listModel = new ParticipantListModel(service, manager);
+ listModel = new ParticipantListModel(service, manager);
+ listModel.addPropertyChangeListener(listsListener);
}
/**
@@ -130,8 +145,13 @@
listModel.reset();
}
poll.setPollType(type);
+ listsChanged = false;
}
+ public boolean isListsChanged() {
+ return listsChanged;
+ }
+
/**
* Retrieve a collection of {@link ParticipantList} of current lists.
*
@@ -176,6 +196,7 @@
logger.debug("Add list : " + listName);
}
lists.put(listName, list);
+ listsChanged = true;
result = true;
} else if (logger.isDebugEnabled()) {
logger.debug("Refuse adding list : " + listName);
@@ -238,6 +259,7 @@
getLists().remove(listModel.getList());
listModel.reset();
+ listsChanged = true;
}
/**
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-19 13:25:45 UTC (rev 3002)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-19 18:25:58 UTC (rev 3003)
@@ -1,7 +1,9 @@
package org.chorem.pollen.ui.pages.poll;
import org.apache.commons.lang.StringUtils;
+import org.apache.tapestry5.Block;
import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.Link;
import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
@@ -14,9 +16,12 @@
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.json.JSONObject;
import org.chorem.pollen.PollenBusinessException;
+import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
+import org.chorem.pollen.entity.Choice;
import org.chorem.pollen.entity.Participant;
import org.chorem.pollen.entity.ParticipantList;
import org.chorem.pollen.entity.Poll;
@@ -27,6 +32,7 @@
import org.chorem.pollen.ui.base.AbstractPollenPage;
import org.chorem.pollen.ui.components.Border;
import org.chorem.pollen.ui.data.AddressBar;
+import org.chorem.pollen.ui.data.ChoiceField;
import org.chorem.pollen.ui.models.ParticipantListModel;
import org.chorem.pollen.ui.models.PollFormModel;
import org.chorem.pollen.ui.services.PollenManager;
@@ -35,8 +41,10 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.List;
/**
* PollForm : Creation and Modification.
@@ -115,6 +123,7 @@
model = null;
initOptions();
listsFeedback.clearErrors();
+ step = PollStep.MAIN;
}
/**
@@ -206,7 +215,8 @@
}
if (formId != null) {
// Script for form interactions : see "webapp/js/pollForm.js"
- renderSupport.addScript("new PollForm('%s', '%s', '%s', '%s');",
+ renderSupport.addScript("var pollForm = " +
+ "new PollForm('%s', '%s', '%s', '%s');",
formId,
VoteCountingType.NORMAL,
PollType.FREE,
@@ -225,71 +235,6 @@
// advancedOptions = false;
// }
- /************************** CHOIX *****************************************/
-
-// @Property
-// private ChoiceField choice;
-//
-// private List<ChoiceField> choices;
-//
-// @Inject
-// private Block choiceText;
-//
-// @Inject
-// private Block choiceDate;
-//
-// @Inject
-// private Block choiceImage;
-//
-// private boolean refresh;
-//
-// /**
-// * Get choices from poll if it exists or initialized 4 choices with the
-// * default type : TEXT.
-// *
-// * @return a list of ChoiceDTO
-// */
-// public List<ChoiceField> getChoices() throws PollenBusinessException {
-// if (choices == null) {
-// choices = new ArrayList<ChoiceField>();
-// if (isCreateMode()) {
-// // Initialized to choice TEXT type
-// for (int i = 0; i < 4; i++) {
-// choices.add(ChoiceField.getChoiceText());
-// }
-// } else {
-// for (Choice current : getPoll().getChoice()) {
-// choices.add(new ChoiceField(getPoll(), current));
-// }
-// }
-// }
-// return choices;
-// }
-//
-// public Block getChoiceTypeBlock() {
-// switch(poll.getChoiceType()) {
-// case DATE:
-// return choiceDate;
-// case IMAGE:
-// return choiceImage;
-// default:
-// return choiceText;
-// }
-// }
-//
-// void onSelectedFromRefreshOptions() {
-// refresh = true;
-// }
-//
-// // TEMP
-// @Log
-// Object onSuccessFromMainForm() {
-// if (!refresh) {
-//
-// }
-// return mainForm;
-// }
-
/************************** OPTIONS ***************************************/
/** Synchronization with anonymous and anonymousVoteAllowed options * */
@@ -397,7 +342,7 @@
return getPoll().getPollType().isFree();
}
- /** ******************** LISTS **************************************** */
+ /** ******************* LISTS **************************************** */
@Inject
private ComponentResources resources;
@@ -422,11 +367,13 @@
/** Flag for subForm used for lists managment */
@Property
- private boolean formActivate;
+ private boolean refreshListsZone;
/** Flag if submit comes from lists edition */
private boolean editLists;
+ protected static final String EVENT_UPDATE_POLL_TYPE = "updatePollType";
+
/** DATA ** */
public ParticipantListModel getListModel() {
@@ -448,14 +395,28 @@
/** PollType change ** */
@Log
- Object onChangeFromPollType(String value) {
- PollType type = PollType.valueOf(value);
- getModel().setPollType(type);
- if (type.isRestrictedOrGroup()) {
- listsFeedback.addInfo("Edition en cours d'une liste restreinte. " +
- "Attention un changement de type de restriction provoquera" +
- " une remise à zéro de la/les liste(s) en cours d'édition.");
+ JSONObject onChangeFromPollType(String value) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Lists changed : " + getModel().isListsChanged());
}
+ // Prepare Json response for javascript callback method
+ JSONObject json = new JSONObject();
+ Link link = resources.createEventLink(EVENT_UPDATE_POLL_TYPE, value);
+ json.put("link", link.toAbsoluteURI());
+ json.put("zoneId", "p-pollForm-lists-zone");
+ // Add confirm message only if changed appears
+ if (getModel().isListsChanged()) {
+ // A dialog box will appeared for user confirmation on changing poll
+ // type with data unsaved.
+ json.put("confirm",
+ messages.get("pollen.ui.poll.listChanged.confirmMessage"));
+ }
+ return json;
+ }
+
+ @Log
+ Object onUpdatePollType(String value) {
+ getModel().setPollType(PollType.valueOf(value));
return refreshListZone();
}
@@ -522,17 +483,114 @@
getListModel().removeParticipant(participant);
}
- protected Object refreshListZone() {
- formActivate = false;
+ Object refreshListZone() {
+ refreshListsZone = true;
return listsZone.getBody();
}
protected void setEditListsFlag() {
- formActivate = true;
editLists = true;
}
+ /** *********************** CHOIX **************************************** */
+
+ @Property
+ private ChoiceField choice;
+
+ private List<ChoiceField> choices;
+
+ @Inject
+ private Block choiceText;
+
+ @Inject
+ private Block choiceDate;
+
+ @Inject
+ private Block choiceImage;
+
+ private boolean refresh;
+
+ /**
+ * Get choices from poll if it exists or initialized 4 choices with the
+ * default type : TEXT. TODO-fdesbois-2010-05-19 : put this treatment in
+ * PollFormModel
+ *
+ * @return a list of ChoiceDTO
+ */
+ public List<ChoiceField> getChoices() throws PollenBusinessException {
+ if (choices == null) {
+ choices = new ArrayList<ChoiceField>();
+ if (isCreateMode()) {
+ // Initialized to choice TEXT type
+ for (int i = 0; i < 4; i++) {
+ choices.add(ChoiceField.getChoiceText());
+ }
+ } else {
+ for (Choice current : getPoll().getChoice()) {
+ choices.add(new ChoiceField(getPoll(), current));
+ }
+ }
+ }
+ return choices;
+ }
+
+ public Block getChoiceTypeBlock() {
+ switch (getPoll().getChoiceType()) {
+ case DATE:
+ return choiceDate;
+ case IMAGE:
+ return choiceImage;
+ default:
+ return choiceText;
+ }
+ }
+
+ private enum PollStep {
+
+ MAIN, CHOICES;
+ }
+
+ private PollStep step;
+
+ @Property
+ private boolean refreshChoicesZone;
+
+ @InjectComponent
+ private Zone choicesZone;
+
@Log
+ Object onChangeFromChoiceType(String value) {
+ ChoiceType type = ChoiceType.valueOf(value);
+ getPoll().setChoiceType(type);
+ refreshChoicesZone = true;
+ return choicesZone.getBody();
+ }
+
+ @Log
+ void onSelected() {
+ refreshListsZone = false;
+ refreshChoicesZone = false;
+ }
+
+ @Log
+ void onSelectedFromChoiceStep() {
+ step = PollStep.CHOICES;
+ }
+
+ @Log
+ void onSelectedFromMainStep() {
+ step = PollStep.MAIN;
+ }
+
+ public boolean isChoiceStep() {
+ return step.equals(PollStep.CHOICES);
+ }
+
+ public boolean isMainStep() {
+ return step.equals(PollStep.MAIN);
+ }
+
+ @Log
Object onSuccess() {
// if (!editLists) {
// saveCurrentList();
Modified: trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-05-19 13:25:45 UTC (rev 3002)
+++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-05-19 18:25:58 UTC (rev 3003)
@@ -51,11 +51,14 @@
pollen.ui.list.update.removeParticipant=Supprimer ce votant
pollen.ui.list.update.removeParticipant.confirmMessage=Etes-vous s\u00fbr de vouloir supprimer %1$s de la liste ?
pollen.ui.list.update.removeParticipant.success=Le votant a \u00e9t\u00e9 supprim\u00e9 avec succ\u00e8s.
+
pollen.ui.participant.name-label=Nom
pollen.ui.participant.email-label=Email
pollen.ui.participant.weight-label=Poids
pollen.ui.participant.add=Nouveau participant
+pollen.ui.poll.listChanged.confirmMessage=Des changements ont été effectués sur la/les liste(s), un changement de restriction supprimera les modifications. Voulez-vous continuer ?
+
# OLD LOGIN_COMPONENT
connectionLegend=Connexion
loginSubmit=Me connecter
@@ -65,6 +68,9 @@
passwordComp-required-message=Vous devez entrer votre mot de passe.
loginFailed=Mauvais identifiant ou mot de passe.
+# FORM:: poll
+groupName-label=Nom du groupe
+
# FORM:: user
firstName-label=Pr\u00e9nom
lastName-label=Nom
Modified: trunk/pollen-ui/src/main/webapp/js/pollen.js
===================================================================
--- trunk/pollen-ui/src/main/webapp/js/pollen.js 2010-05-19 13:25:45 UTC (rev 3002)
+++ trunk/pollen-ui/src/main/webapp/js/pollen.js 2010-05-19 18:25:58 UTC (rev 3003)
@@ -38,6 +38,19 @@
zoneManager.updateFromURL(response.link);
}
+function onConfirmRefreshZone(response) {
+ var zoneManager = Tapestry.findZoneManagerForZone(response.zoneId);
+
+ if (response.confirm) {
+ // Show confirm dialog for refresh
+ if (confirm(response.confirm)) {
+ zoneManager.updateFromURL(response.link);
+ }
+ } else {
+ zoneManager.updateFromURL(response.link);
+ }
+}
+
function triggerFragment(checkbox, fragment) {
fragment.toggle();
}
Modified: trunk/pollen-ui/src/main/webapp/poll/PollForm.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/PollForm.tml 2010-05-19 13:25:45 UTC (rev 3002)
+++ trunk/pollen-ui/src/main/webapp/poll/PollForm.tml 2010-05-19 18:25:58 UTC (rev 3003)
@@ -15,6 +15,8 @@
<t:zone t:id="mainZone" t:update="show">
<form t:type="form" t:id="mainForm" t:zone="mainZone" action="post">
<t:errors />
+<t:formFragment t:id="mainFormFragment" t:visible="mainStep">
+
<!-- MAIN INFOS -->
<div id="p-pollForm-mainInfos">
<fieldset>
@@ -247,74 +249,35 @@
</div>
</fieldset>
</div>
-<!-- CHOICES -->
-<!--<div id="p-pollForm-choices">-->
-<!--<fieldset>-->
-<!--<legend>-->
-<!--<label t:type="label" t:for="choiceType" />: -->
-<!--<select t:type="select" t:id="choiceType" t:value="poll.choiceType" t:validate="required">-->
-<!--<option></option>-->
-<!--</select> -->
-<!--<input type="image" t:type="submit" class="ico refresh" t:id="refreshChoices" value="Refresh choices" title="${message:refreshChoices-button}"/>-->
-<!--</legend>-->
-<!--<div t:type="loop" t:source="choices" t:value="choice" t:volatile="true" class="clearfix">-->
-<!--<div class="fleft choiceName">-->
-<!--<t:delegate t:to="choiceTypeBlock" />-->
-<!--<t:block t:id="choiceText">-->
-<!--<label t:type="label" t:for="choiceTextField" />: -->
-<!--<input type="text" class="nameField" t:type="textfield" t:id="choiceTextField" value="choice.text" />-->
-<!--</t:block>-->
-<!--<t:block t:id="choiceDate">-->
-<!--<label t:type="label" t:for="choiceDateField" />: -->
-<!--<input t:type="ck/dateTimeField" t:id="choiceDateField" value="choice.date" t:validate="regexp"-->
-<!--t:datePattern="message:date-pattern" t:timePicker="true" t:timePickerAdjacent="true"/>-->
-<!--</t:block>-->
-<!--<t:block t:id="choiceImage">-->
-<!--<label t:type="label" t:for="choiceImageField" />: -->
-<!--<input type="file" class="nameField" t:type="upload" t:id="choiceImageField" value="choice.image" t:validate="regexp" />-->
-<!--</t:block>-->
-<!--<t:block t:id="choiceDisplay">-->
-<!--${choice.name}-->
-<!--</t:block>-->
-<!-- -->
-<!--<t:label t:for="choiceDescription" />: -->
-<!--</div>-->
-<!--<div class="fleft">-->
-<!--<t:textarea cols="34" rows="1" t:id="choiceDescription" t:value="choice.description" />-->
-<!--</div>-->
-<!--</div>-->
-<!--</fieldset>-->
-<!--</div>-->
<!-- LISTS -->
<div id="p-pollForm-lists">
<fieldset>
<legend>
<label t:type="label" t:for="pollType" />:
- <select t:type="select" class="list-select" t:id="pollType"
- t:value="poll.pollType" t:validate="required"
- t:mixins="nuiton/zoneUpdater" t:event="change"
- t:zone="p-pollForm-lists-zone" />
- <span t:type="ck/Tooltip" title="message:help"
- t:value="message:pollType-help" t:effect="appear">
- <img src="${asset:context:img/help.png}"
- alt="message:help" />
- </span>
+ <!--<select t:type="select" t:id="pollType" class="list-select" t:value="poll.pollType" t:validate="required"-->
+ <!--t:mixins="nuiton/zoneUpdater" t:event="change" t:zone="p-pollForm-lists-zone" />-->
+ <select t:type="select" t:id="pollType" t:value="poll.pollType"
+ t:validate="required"
+ t:mixins="ck/onEvent" t:event="change"
+ t:onCompleteCallback="onConfirmRefreshZone" />
+ <span t:type="ck/Tooltip" title="message:help"
+ t:value="message:pollType-help" t:effect="appear">
+ <img src="${asset:context:img/help.png}" alt="message:help" />
+ </span>
</legend>
- <div t:type="zone" id="p-pollForm-lists-zone" t:id="listsZone"
+ <div t:type="zone" t:id="listsZone" id="p-pollForm-lists-zone"
class="form-block" t:update="show">
<t:if t:test="canDisplayLists()">
<t:nuiton.feedback t:id="listsFeedback" />
<br />
- <t:subForm t:visible="formActivate">
+ <t:subForm t:visible="refreshListsZone">
<t:if t:test="poll.pollType.group">
<p>
- <label t:type="label" t:for="listName" />:
- <input t:type="textfield" t:id="listName"
+ <label t:type="label" t:for="groupName" />:
+ <input t:type="textfield" t:id="groupName"
value="listName" />
- <input t:type="submit" t:id="addList" value="ADD" />
- <!--<a t:type="actionlink" t:id="addList" t:zone="p-pollForm-lists-zone">-->
- <!--ADD-->
- <!--</a>-->
+ <input t:type="submit" t:id="addList"
+ value="${message:pollen.ui.button.add}" />
</p>
<p class="center">
@@ -324,18 +287,14 @@
t:type="nuiton/submitContext"
t:context="list.name" t:id="editList"
value="${list.name}" />
- <!--<span t:type="any" t:mixins="nuiton/confirm">-->
- <!--<input t:type="nuiton/submitContext" t:id="removeList" t:image="context:img/delete.png" t:context="list.name" value="${message:delete}" />-->
- <!--</span>-->
<t:if t:test="currentListSelected">
- <!--<input t:type="submit" t:id="saveList" t:image="context:img/save.png" />-->
<a t:type="actionlink" t:id="removeList"
t:zone="p-pollForm-lists-zone">
- <span t:type="any"
- t:mixins="nuiton/confirm">
- <img src="${asset:context:img/delete.png}"
- alt="${message:delete}" />
- </span>
+ <span t:type="any"
+ t:mixins="nuiton/confirm">
+ <img src="${asset:context:img/delete.png}"
+ alt="${message:delete}" />
+ </span>
</a>
</t:if>
</t:loop>
@@ -398,32 +357,75 @@
</t:if>
</t:subForm>
</t:if>
- <!--<t:delegate t:to="listsBlock" />-->
- <!--<t:block t:id="listsForm">-->
- <!--<form t:type="form" action="tapestry">-->
- <!--<t:delegate t:to="listsFields" />-->
- <!--</form>-->
- <!--</t:block>-->
- <!--<t:block t:id="listsFields">-->
- <!--<t:if t:test="poll.pollType.group">-->
- <!--<p>-->
- <!--<label t:type="label" t:for="listName" />: -->
- <!--<input t:type="textfield" t:id="listName" value="listName"/> -->
- <!--<input t:type="submit" t:id="addList" value="ADD"/>-->
- <!--</p>-->
- <!--<p>-->
- <!--<t:loop t:source="lists.values()" t:value="list" t:volatile="true">-->
- <!--${list.name} -->
- <!--</t:loop>-->
- <!--</p>-->
- <!--<p:else>-->
- <!--COOL-->
- <!--</p:else>-->
- <!--</t:if>-->
- <!--</t:block> -->
</div>
</fieldset>
+ <p class="center"><input t:type="submit" t:id="choiceStep" value="CHOICE" />
+ </p>
</div>
+</t:formFragment>
+<t:formFragment t:id="choiceFormFragment" t:visible="choiceStep">
+
+ <!-- CHOICES -->
+ <div id="p-pollForm-choices">
+ <fieldset>
+ <legend>
+ <label t:type="label" t:for="choiceType" />:
+ <select t:type="select" t:id="choiceType"
+ t:value="poll.choiceType" t:validate="required"
+ t:mixins="nuiton/zoneUpdater" t:event="change"
+ t:zone="p-pollForm-choices-zone" />
+ </legend>
+ <t:zone t:id="choicesZone" id="p-pollForm-choices-zone">
+ <t:subForm t:visible="refreshChoicesZone">
+ <div t:type="loop" t:source="choices" t:value="choice"
+ t:volatile="true" class="clearfix">
+ <div class="fleft choiceName">
+ <t:delegate t:to="choiceTypeBlock" />
+ <t:block t:id="choiceText">
+ <label t:type="label" t:for="choiceTextField" />:
+ <input type="text" class="nameField"
+ t:type="textfield" t:id="choiceTextField"
+ value="choice.text" />
+ </t:block>
+ <t:block t:id="choiceDate">
+ <label t:type="label" t:for="choiceDateField" />:
+ <input t:type="ck/dateTimeField"
+ t:id="choiceDateField"
+ value="choice.date" t:validate="regexp"
+ t:datePattern="message:date-pattern"
+ t:timePicker="true"
+ t:timePickerAdjacent="true" />
+ </t:block>
+ <t:block t:id="choiceImage">
+ <label t:type="label"
+ t:for="choiceImageField" />:
+ <input type="file" class="nameField"
+ t:type="upload" t:id="choiceImageField"
+ value="choice.image"
+ t:validate="regexp" />
+ </t:block>
+ <t:block t:id="choiceDisplay">
+ ${choice.name}
+ </t:block>
+
+ <t:label t:for="choiceDescription" />
+ :
+ </div>
+ <div class="fleft">
+ <t:textarea cols="34" rows="1"
+ t:id="choiceDescription"
+ t:value="choice.description" />
+ </div>
+ </div>
+ </t:subForm>
+ </t:zone>
+ </fieldset>
+ </div>
+ <p class="center">
+ <input t:type="submit" t:id="mainStep" value="PREVIOUS" />
+ <input t:type="submit" t:id="save" value="SAVE" />
+ </p>
+</t:formFragment>
</form>
</t:zone>
</html>
1
0
r3002 - in trunk/pollen-ui/src/main/java/org/chorem/pollen/ui: . components data models pages/admin pages/poll pages/user
by fdesbois@users.chorem.org 19 May '10
by fdesbois@users.chorem.org 19 May '10
19 May '10
Author: fdesbois
Date: 2010-05-19 15:25:45 +0200 (Wed, 19 May 2010)
New Revision: 3002
Url: http://chorem.org/repositories/revision/pollen/3002
Log:
- Move models in a new package 'models'.
- Add poll instantiation in PollFormModel
- Add javadoc
Added:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/FavoriteParticipantDataSource.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/GenericSelectModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java
Removed:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FavoriteParticipantDataSource.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/GenericSelectModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ParticipantListModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollFormModel.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/UserAccountDataSource.java
Modified:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java 2010-05-19 12:59:57 UTC (rev 3001)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -1,4 +1,3 @@
-
package org.chorem.pollen.ui.components;
import org.apache.tapestry5.annotations.InjectComponent;
@@ -15,7 +14,7 @@
import org.chorem.pollen.entity.FavoriteParticipant;
import org.chorem.pollen.service.ServiceFavorite;
import org.chorem.pollen.ui.data.EvenOdd;
-import org.chorem.pollen.ui.data.FavoriteParticipantDataSource;
+import org.chorem.pollen.ui.models.FavoriteParticipantDataSource;
import org.chorem.pollen.ui.services.PollenManager;
import org.nuiton.web.tapestry5.components.FeedBack;
import org.slf4j.Logger;
@@ -27,7 +26,7 @@
* participant in the Grid and one to edit a participant directly in the grid.
* Each action will return the {@code updateZone} to refresh data loaded by
* {@link #getParticipants()} method.
- *
+ * <p/>
* Created: 27 avr. 2010
*
* @author fdesbois <fdesbois(a)codelutin.com>
@@ -35,11 +34,11 @@
*/
public class UserListsUpdate {
- /** Parameters of the component **/
+ /** Parameters of the component * */
@Parameter(required = true)
private FavoriteList source;
- /** Services injected **/
+ /** Services injected * */
@Inject
private Logger logger;
@@ -52,7 +51,7 @@
@Inject
private Messages messages;
- /** Main properties for Grid **/
+ /** Main properties for Grid * */
private EvenOdd evenOdd;
private FavoriteParticipantDataSource participants;
@@ -75,11 +74,11 @@
}
/**
- * Load participants data from serviceFavorite in a
- * {@link FavoriteParticipantDataSource} to manage pagination and order.
- * The filter added contains data for serviceFavorite (startIndex, endIndex,
- * orderBy and referenceId). The reference is set to the source FavoriteList
- * of the component, i.e. all FavoriteParticipants need to be part of the
+ * Load participants data from serviceFavorite in a {@link
+ * FavoriteParticipantDataSource} to manage pagination and order. The filter
+ * added contains data for serviceFavorite (startIndex, endIndex, orderBy
+ * and referenceId). The reference is set to the source FavoriteList of the
+ * component, i.e. all FavoriteParticipants need to be part of the
* FavoriteList source.
*
* @return the DataSource that contains participants.
@@ -100,20 +99,13 @@
/***************************** EDIT PARTICIPANT FORM **********************/
/**
- * FORM EVENTS ORDER -> RENDER :
- * load size of participants dataSource
- * call prepareForRender
- * load participants data
- *
- * FORM EVENTS ORDER -> SUBMIT :
- * call prepareForSubmit
- * load size of participants dataSource
- * load participants data
- * load participantEdited to push form data (hidden fields in first)
- * call selected on submit button
- * call validateForm
- * call success or failure
- * call submit
+ * FORM EVENTS ORDER -> RENDER : load size of participants dataSource call
+ * prepareForRender load participants data
+ * <p/>
+ * FORM EVENTS ORDER -> SUBMIT : call prepareForSubmit load size of
+ * participants dataSource load participants data load participantEdited to
+ * push form data (hidden fields in first) call selected on submit button
+ * call validateForm call success or failure call submit
*/
@InjectComponent
@@ -131,7 +123,7 @@
* Test if the edited participant is the current one in the Grid.
*
* @return true if the participantEdited is defined and correspond to the
- * current participant in the Grid
+ * current participant in the Grid
*/
public boolean isEditionMode() {
// The current participant in the loop is equals to the edited one
@@ -140,8 +132,8 @@
}
/**
- * ON_ACTION :: Handler method for action on editParticipant actionLink.
- * The participantEdited will be set to the participant selected in the Grid
+ * ON_ACTION :: Handler method for action on editParticipant actionLink. The
+ * participantEdited will be set to the participant selected in the Grid
* with {@code id}.
*
* @param id key of the participant from the Grid
@@ -181,15 +173,13 @@
}
/**
- * Getter to retrieve participantEdited.
- * <br \>
- * The participantEditedId is needed and was provided for render by the
- * {@link #onActionFromEditParticipant(String)} method and for submit by
- * the hidden field in the form that keep the id after rendering the form.
- * The participantEdited is loaded from the participants dataSource that
- * contains all FavoriteParticipant displayed in the Grid. The submit will
- * reload the participants dataSource before saving modification on the
- * FavoriteParticipant edited.
+ * Getter to retrieve participantEdited. <br \> The participantEditedId is
+ * needed and was provided for render by the {@link #onActionFromEditParticipant(String)}
+ * method and for submit by the hidden field in the form that keep the id
+ * after rendering the form. The participantEdited is loaded from the
+ * participants dataSource that contains all FavoriteParticipant displayed
+ * in the Grid. The submit will reload the participants dataSource before
+ * saving modification on the FavoriteParticipant edited.
*
* @return the FavoriteParticipant in edition
*/
@@ -202,7 +192,7 @@
participantEdited = participants.get(participantEditedId);
}
return participantEdited;
- }
+ }
/**
* ON_VALIDATE_FORM :: Handler method for validateForm event of the
@@ -227,9 +217,9 @@
/**
* ON_SUCCESS :: Handler method for success event of the participantsForm.
- * Clean form data (participantEdited) and display a success message.
- * {@link #onSubmitFromParticipantsForm()} will be called after it to
- * refresh the updateZone.
+ * Clean form data (participantEdited) and display a success message. {@link
+ * #onSubmitFromParticipantsForm()} will be called after it to refresh the
+ * updateZone.
*/
void onSuccessFromParticipantsForm() {
participantsFeedback.addInfo(
@@ -239,8 +229,8 @@
}
/**
- * Clean the form content, i.e. the favorite participant in edition and
- * its id.
+ * Clean the form content, i.e. the favorite participant in edition and its
+ * id.
*/
protected void cleanFormData() {
participantEditedId = null;
@@ -258,7 +248,7 @@
return updateZone;
}
- /***************************** NEW PARTICIPANT FORM ***********************/
+ /** ************************** NEW PARTICIPANT FORM ********************** */
@Property
private FavoriteParticipant newParticipant;
@@ -276,7 +266,7 @@
void onPrepareFromAddParticipant() {
if (newParticipant == null) {
newParticipant =
- serviceFavorite.getNewFavoriteParticipant(source);
+ serviceFavorite.getNewFavoriteParticipant(source);
}
}
@@ -301,14 +291,14 @@
}
/**
- * ON_SUCCESS :: Handler method for success event of the addParticipant form.
- * Will display a success message. {@link #onSubmitFromAddParticipant()}
+ * ON_SUCCESS :: Handler method for success event of the addParticipant
+ * form. Will display a success message. {@link #onSubmitFromAddParticipant()}
* will be called after it to refresh the updateZone.
*/
void onSuccessFromAddParticipant() {
participantsFeedback.addInfo(
messages.format("pollen.ui.list.update.addParticipant.success",
- newParticipant.getName()));
+ newParticipant.getName()));
}
/**
Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FavoriteParticipantDataSource.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FavoriteParticipantDataSource.java 2010-05-19 12:59:57 UTC (rev 3001)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FavoriteParticipantDataSource.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -1,68 +0,0 @@
-
-package org.chorem.pollen.ui.data;
-
-import java.util.Map;
-import org.apache.tapestry5.grid.SortConstraint;
-import org.chorem.pollen.PollenException;
-import org.chorem.pollen.bean.Filter;
-import org.chorem.pollen.entity.FavoriteParticipant;
-import org.chorem.pollen.service.ServiceFavorite;
-import org.nuiton.web.tapestry5.data.AbstractMappedGridDataSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * UserAccountDataSource
- *
- * Created: 23 avr. 2010
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class FavoriteParticipantDataSource extends
- AbstractMappedGridDataSource<String, FavoriteParticipant> {
-
- private static final Logger logger =
- LoggerFactory.getLogger(FavoriteParticipantDataSource.class);
-
- private ServiceFavorite service;
-
- private Filter filter;
-
- public FavoriteParticipantDataSource(ServiceFavorite service,
- Filter filter) {
- this.service = service;
- this.filter = filter;
- }
-
- @Override
- protected Map<String, FavoriteParticipant> execute(
- int startIndex, int endIndex, SortConstraint orderBy)
- throws PollenException {
- filter.setStartIndex(startIndex);
- filter.setEndIndex(endIndex);
- filter.setOrderBy(resolveOrderBy(orderBy));
- if (logger.isDebugEnabled()) {
- logger.debug("LOAD DATA");
- }
- return service.getFavoriteParticipants(filter);
- }
-
- @Override
- protected int count() throws PollenException {
- int count = service.getNbFavoriteParticipants(filter);
- if (logger.isDebugEnabled()) {
- logger.debug("Nb elements : " + count);
- }
- return count;
- }
-
- @Override
- public Class<?> getRowType() {
- return FavoriteParticipant.class;
- }
-
-}
Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/GenericSelectModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/GenericSelectModel.java 2010-05-19 12:59:57 UTC (rev 3001)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/GenericSelectModel.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -1,129 +0,0 @@
-/* *##% Pollen
- * Copyright (C) 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>. ##%*/
-
-package org.chorem.pollen.ui.data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.tapestry5.OptionGroupModel;
-import org.apache.tapestry5.OptionModel;
-import org.apache.tapestry5.ValueEncoder;
-import org.apache.tapestry5.corelib.components.Select;
-import org.apache.tapestry5.internal.OptionModelImpl;
-import org.apache.tapestry5.ioc.services.PropertyAccess;
-import org.apache.tapestry5.ioc.services.PropertyAdapter;
-import org.apache.tapestry5.util.AbstractSelectModel;
-
-/**
- * Generic selection model for a list of Objects. Adadpted from
- * http://wiki.apache.org/tapestry/Tapestry5HowtoSelectWithObjects
- *
- * use:
- *
- * <pre>
- * @Inject
- * private PropertyAccess _access;
- * </pre>
- *
- * in your page to ge the {@link PropertyAccess} service.<br>
- * !Notice: you must set the created instance both as model and encoder
- * parameter for the {@link Select} component.
- * @param <T>
- */
-public class GenericSelectModel<T> extends AbstractSelectModel implements
- ValueEncoder<T> {
-
- private PropertyAdapter labelFieldAdapter;
- private PropertyAdapter idFieldAdapter;
- private List<T> list;
-
- public GenericSelectModel(List<T> list, Class<T> clazz, String labelField,
- String idField, PropertyAccess access) {
- this.list = list;
- if (idField != null) {
- this.idFieldAdapter =
- access.getAdapter(clazz).getPropertyAdapter(idField);
- }
- if (labelField != null) {
- this.labelFieldAdapter =
- access.getAdapter(clazz).getPropertyAdapter(labelField);
- }
- }
-
- @Override
- public List<OptionGroupModel> getOptionGroups() {
- return null;
- }
-
- @Override
- public List<OptionModel> getOptions() {
- List<OptionModel> optionModelList = new ArrayList<OptionModel>();
- if (labelFieldAdapter == null) {
- for (T obj : list) {
- optionModelList.add(new OptionModelImpl(nvl(obj), obj));
- }
- } else {
- for (T obj : list) {
- optionModelList.add(new OptionModelImpl(nvl(labelFieldAdapter
- .get(obj)), obj));
- }
- }
- return optionModelList;
- }
-
- public List<T> getList() {
- return list;
- }
-
- // ValueEncoder methods
-
- @Override
- public String toClient(T obj) {
- if (idFieldAdapter == null) {
- return obj + "";
- } else {
- return idFieldAdapter.get(obj) + "";
- }
- }
-
- @Override
- public T toValue(String string) {
- if (idFieldAdapter == null) {
- for (T obj : list) {
- if (nvl(obj).equals(string)) {
- return obj;
- }
- }
- } else {
- for (T obj : list) {
- if (nvl(idFieldAdapter.get(obj)).equals(string)) {
- return obj;
- }
- }
- }
- return null;
- }
-
- private String nvl(Object o) {
- if (o == null) {
- return "";
- }
- else {
- return o.toString();
- }
- }
-}
Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ParticipantListModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ParticipantListModel.java 2010-05-19 12:59:57 UTC (rev 3001)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ParticipantListModel.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -1,160 +0,0 @@
-package org.chorem.pollen.ui.data;
-
-import org.apache.tapestry5.ValueEncoder;
-import org.chorem.pollen.PollenBusinessException;
-import org.chorem.pollen.entity.Participant;
-import org.chorem.pollen.entity.ParticipantList;
-import org.chorem.pollen.service.ServicePoll;
-import org.chorem.pollen.ui.services.PollenManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * Created: 18 mai 2010
- *
- * @author fdesbois <fdesbois(a)codelutin.com>
- * @version $Id$
- */
-public class ParticipantListModel implements ValueEncoder<Participant> {
-
- private static final Logger logger =
- LoggerFactory.getLogger(ParticipantListModel.class);
-
- protected ServicePoll service;
-
- protected PollenManager manager;
-
- protected ParticipantList list;
-
- protected ParticipantMap participants;
-
- public ParticipantListModel(ServicePoll service, PollenManager manager) {
- this.service = service;
- this.manager = manager;
- participants = new ParticipantMap();
- }
-
- public Participant addNewParticipant() {
- Participant newParticipant = service.getNewPollParticipant();
- String id = manager.createPollenId();
- participants.put(id, newParticipant);
- return newParticipant;
- }
-
- public void removeParticipant(Participant participant) {
- if (logger.isDebugEnabled()) {
- logger.debug("Remove participant : " + participant);
- }
- participants.remove(participant);
- }
-
- public Collection<Participant> getParticipants() {
- return participants.values();
- }
-
- public void setList(ParticipantList participantList) {
- if (logger.isDebugEnabled()) {
- logger.debug("Set current list : " + participantList.getName());
- }
- list = participantList;
- participants.clear();
- for (Participant participant : participantList.getParticipants()) {
- String id = participant.getId() != null ? participant.getId() :
- manager.createPollenId();
- if (logger.isTraceEnabled()) {
- logger.trace("Push participant : " +
- participant.getName() +
- " (" + participant.getEmail() + ")" +
- " ID = " + id);
- }
- participants.put(id, participant);
- }
- }
-
- public ParticipantList getList() {
- return list;
- }
-
- public void reset() {
- if (logger.isDebugEnabled()) {
- logger.debug("Reset current list");
- }
- list = null;
- participants.clear();
- }
-
- public void persistParticipants() throws PollenBusinessException {
- if (logger.isDebugEnabled()) {
- logger.debug("Save current list : " + list.getName());
- }
- list.setParticipants(getParticipants());
- }
-
- @Override
- public String toClient(Participant value) {
- String key = participants.getKey(value);
- if (logger.isTraceEnabled()) {
- logger.trace("toClient key = " + key);
- }
- return key;
- }
-
- @Override
- public Participant toValue(String key) {
- Participant value = participants.getValue(key);
- if (logger.isTraceEnabled()) {
- logger.trace("toValue from : " + key + " = " + value.getName() +
- " (" + value.getEmail() + ")");
- }
- return value;
- }
-
- /**
- * Participant map is a BidiMap ordered on values inserted using a {@link
- * LinkedHashMap}.
- */
- protected class ParticipantMap {
-
- protected Map<String, Participant> participants;
-
- protected Map<Participant, String> keys;
-
- public ParticipantMap() {
- participants = new LinkedHashMap<String, Participant>();
- keys = new HashMap<Participant, String>();
- }
-
- public void put(String id, Participant participant) {
- participants.put(id, participant);
- keys.put(participant, id);
- }
-
- public String getKey(Participant participant) {
- return keys.get(participant);
- }
-
- public Participant getValue(String id) {
- return participants.get(id);
- }
-
- public void clear() {
- keys.clear();
- participants.clear();
- }
-
- public void remove(Participant participant) {
- String id = keys.remove(participant);
- participants.remove(id);
- }
-
- public Collection<Participant> values() {
- return participants.values();
- }
-
- }
-}
Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollFormModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollFormModel.java 2010-05-19 12:59:57 UTC (rev 3001)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollFormModel.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -1,241 +0,0 @@
-package org.chorem.pollen.ui.data;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.tapestry5.ValueEncoder;
-import org.chorem.pollen.PollenBusinessException;
-import org.chorem.pollen.common.PollType;
-import org.chorem.pollen.entity.ParticipantList;
-import org.chorem.pollen.entity.Poll;
-import org.chorem.pollen.service.ServicePoll;
-import org.chorem.pollen.ui.pages.poll.PollForm;
-import org.chorem.pollen.ui.services.PollenManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * Model for PollForm page. Contains the current {@code poll} and its
- * participant {@code lists}. Use {@link ParticipantListModel} to manage current
- * edited list for restricted or group Poll. Implement a {@link ValueEncoder} to
- * manage ParticipantList client conversion in PollForm page.
- * <p/>
- * Created: 18 mai 2010
- *
- * @author fdesbois <fdesbois(a)codelutin.com>
- * @version $Id$
- * @see PollForm
- * @see ValueEncoder
- */
-public class PollFormModel implements ValueEncoder<ParticipantList> {
-
- private static final Logger logger =
- LoggerFactory.getLogger(PollFormModel.class);
-
- /** Default listName for Restricted Poll */
- private static final String DEFAULT_LIST_NAME = "LIST";
-
- /** Service to manage poll */
- protected ServicePoll service;
-
- /** Current poll in edition */
- protected Poll poll;
-
- /** Current lists in edition */
- protected Map<String, ParticipantList> lists;
-
- /** Current listModel that contains current edited list and its participants */
- protected ParticipantListModel listModel;
-
- /**
- * Constructor of PollFormModel. Initialize with edited {@code poll}. Need
- * services {@code servicePoll} and {@code manager} to manage the {@code
- * poll}.
- *
- * @param poll Current poll in edition
- * @param servicePoll ServicePoll to manage poll
- * @param manager PollenManager to manage ids
- */
- public PollFormModel(Poll poll,
- ServicePoll servicePoll,
- PollenManager manager) {
- this.poll = poll;
- this.service = servicePoll;
- lists = new LinkedHashMap<String, ParticipantList>();
- this.listModel = new ParticipantListModel(service, manager);
- }
-
- /**
- * Change the poll type to {@code type}. The lists managment will depends on
- * poll type. For a {@link PollType#RESTRICTED} poll, a new list will be
- * automatically added and set for current usage. For a {@link
- * PollType#GROUP} poll, the listModel is simply reset.
- *
- * @param type PollType to change
- */
- public void setPollType(PollType type) {
- lists.clear();
- if (type.isRestricted()) {
- addNewList(DEFAULT_LIST_NAME);
- // Set automatically the current list to the unique one
- listModel.setList(lists.get(DEFAULT_LIST_NAME));
- } else if (type.isGroup()) {
- listModel.reset();
- }
- poll.setPollType(type);
- }
-
- /**
- * Retrieve a collection of {@link ParticipantList} of current lists.
- *
- * @return a Collection<ParticipantList>
- */
- public Collection<ParticipantList> getLists() {
- return lists.values();
- }
-
- /**
- * Add a new list to the poll using the {@code listName}. The list will not
- * be added if the {@code listName} is empty or if a list with this {@code
- * listName} already exists.
- *
- * @param listName for the new list to add
- * @return true if the list has been added, false otherwise
- * @see #addList(ParticipantList)
- */
- public boolean addNewList(String listName) {
- boolean result = false;
- if (StringUtils.isNotEmpty(listName)) {
- ParticipantList newList = service.getNewPollList();
- newList.setName(listName);
- return addList(newList);
- }
- return result;
- }
-
- /**
- * Add a {@code list} to the poll. The {@code list} will not be added if its
- * name already reference an exising list.
- *
- * @param list ParticipantList to add
- * @return true if the list has been added, false otherwise
- */
- public boolean addList(ParticipantList list) {
- boolean result = false;
- if (list != null) {
- String listName = list.getName();
- if (!lists.containsKey(listName)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Add list : " + listName);
- }
- lists.put(listName, list);
- result = true;
- } else if (logger.isDebugEnabled()) {
- logger.debug("Refuse adding list : " + listName);
- }
- }
- return result;
- }
-
- /**
- * Give the current {@link ParticipantListModel} that references the list
- * currently edited.
- *
- * @return the current listModel
- */
- public ParticipantListModel getListModel() {
- return listModel;
- }
-
- /**
- * Set the current list using its {@code listName}. The previous current
- * list will be automatically saved. If error occurs during save, the
- * previous list will be refresh (no list change will be done).
- *
- * @param listName name of the list to set (empty name will be ignored)
- * @throws PollenBusinessException for saving error (doubloons)
- * @see #saveCurrentList()
- */
- public void setCurrentList(String listName) throws PollenBusinessException {
- if (StringUtils.isNotEmpty(listName)) {
- ParticipantList list = getCurrentList();
- try {
- // Save previous list if not null
- if (list != null) {
- saveCurrentList();
- }
- // Change list
- list = lists.get(listName);
- } finally {
- // Previous list will be keeped if error occurs during save.
- // Apply change in listModel
- listModel.setList(list);
- }
- }
- }
-
- /**
- * Get the current list.
- *
- * @return the current list in edition.
- */
- public ParticipantList getCurrentList() {
- return listModel.getList();
- }
-
- /** Remove the current list. */
- public void removeCurrentList() {
- if (logger.isDebugEnabled()) {
- logger.debug("Remove list : " + listModel.getList().getName());
- }
-
- getLists().remove(listModel.getList());
- listModel.reset();
- }
-
- /**
- * Save the current participants from current list.
- *
- * @throws PollenBusinessException for saving errors (doubloons)
- * @see ParticipantListModel#persistParticipants()
- */
- public void saveCurrentList() throws PollenBusinessException {
- listModel.persistParticipants();
- }
-
- public void create() throws PollenBusinessException {
- service.createPoll(poll, getLists());
- }
-
- /**
- * ValueEncoder toClient is used to convert {@code value} to the list name.
- *
- * @param value ParticipantList to convert toClient
- * @return the list name as a unique key for the list
- * @see ValueEncoder#toClient(Object)
- */
- @Override
- public String toClient(ParticipantList value) {
- return value.getName();
- }
-
- /**
- * ValueEncoder toClient is used to convert {@code clientValue} key to the
- * list object.
- *
- * @param clientValue List name of the ParticipantList to retrieve.
- * @return the ParticipantList corresponding to its name in argument
- * @see ValueEncoder#toValue(String)
- */
- @Override
- public ParticipantList toValue(String clientValue) {
- for (ParticipantList curr : lists.values()) {
- if (clientValue.equals(curr.getName())) {
- return curr;
- }
- }
- return null;
- }
-}
Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/UserAccountDataSource.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/UserAccountDataSource.java 2010-05-19 12:59:57 UTC (rev 3001)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/UserAccountDataSource.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -1,53 +0,0 @@
-
-package org.chorem.pollen.ui.data;
-
-import java.util.Map;
-import org.apache.tapestry5.grid.SortConstraint;
-import org.chorem.pollen.PollenException;
-import org.chorem.pollen.bean.Filter;
-import org.chorem.pollen.entity.UserAccount;
-import org.chorem.pollen.service.ServiceUser;
-import org.nuiton.web.tapestry5.data.AbstractMappedGridDataSource;
-
-/**
- * UserAccountDataSource
- *
- * Created: 23 avr. 2010
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class UserAccountDataSource extends AbstractMappedGridDataSource<String, UserAccount> {
-
- private ServiceUser service;
-
- private Filter filter;
-
- public UserAccountDataSource(ServiceUser service, Filter filter) {
- this.service = service;
- this.filter = filter;
- }
-
- @Override
- protected Map<String, UserAccount> execute(int startIndex, int endIndex,
- SortConstraint orderBy) throws PollenException {
- filter.setStartIndex(startIndex);
- filter.setEndIndex(endIndex);
- filter.setOrderBy(resolveOrderBy(orderBy));
- return service.getUsers(filter);
- }
-
- @Override
- protected int count() throws PollenException {
- return service.getNbUsers(filter);
- }
-
- @Override
- public Class<?> getRowType() {
- return UserAccount.class;
- }
-
-}
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/FavoriteParticipantDataSource.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/FavoriteParticipantDataSource.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/FavoriteParticipantDataSource.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -0,0 +1,68 @@
+package org.chorem.pollen.ui.models;
+
+import org.apache.tapestry5.grid.SortConstraint;
+import org.chorem.pollen.PollenException;
+import org.chorem.pollen.bean.Filter;
+import org.chorem.pollen.entity.FavoriteParticipant;
+import org.chorem.pollen.service.ServiceFavorite;
+import org.nuiton.web.tapestry5.data.AbstractMappedGridDataSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+
+/**
+ * UserAccountDataSource
+ * <p/>
+ * Created: 23 avr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ * <p/>
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class FavoriteParticipantDataSource extends
+ AbstractMappedGridDataSource<String, FavoriteParticipant> {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(FavoriteParticipantDataSource.class);
+
+ private ServiceFavorite service;
+
+ private Filter filter;
+
+ public FavoriteParticipantDataSource(ServiceFavorite service,
+ Filter filter) {
+ this.service = service;
+ this.filter = filter;
+ }
+
+ @Override
+ protected Map<String, FavoriteParticipant> execute(
+ int startIndex, int endIndex, SortConstraint orderBy)
+ throws PollenException {
+ filter.setStartIndex(startIndex);
+ filter.setEndIndex(endIndex);
+ filter.setOrderBy(resolveOrderBy(orderBy));
+ if (logger.isDebugEnabled()) {
+ logger.debug("LOAD DATA");
+ }
+ return service.getFavoriteParticipants(filter);
+ }
+
+ @Override
+ protected int count() throws PollenException {
+ int count = service.getNbFavoriteParticipants(filter);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Nb elements : " + count);
+ }
+ return count;
+ }
+
+ @Override
+ public Class<?> getRowType() {
+ return FavoriteParticipant.class;
+ }
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/FavoriteParticipantDataSource.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/GenericSelectModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/GenericSelectModel.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/GenericSelectModel.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -0,0 +1,131 @@
+/* *##% Pollen
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. ##%*/
+
+package org.chorem.pollen.ui.models;
+
+import org.apache.tapestry5.OptionGroupModel;
+import org.apache.tapestry5.OptionModel;
+import org.apache.tapestry5.ValueEncoder;
+import org.apache.tapestry5.corelib.components.Select;
+import org.apache.tapestry5.internal.OptionModelImpl;
+import org.apache.tapestry5.ioc.services.PropertyAccess;
+import org.apache.tapestry5.ioc.services.PropertyAdapter;
+import org.apache.tapestry5.util.AbstractSelectModel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Generic selection model for a list of Objects. Adadpted from
+ * http://wiki.apache.org/tapestry/Tapestry5HowtoSelectWithObjects
+ * <p/>
+ * use:
+ * <p/>
+ * <pre>
+ * @Inject
+ * private PropertyAccess _access;
+ * </pre>
+ * <p/>
+ * in your page to ge the {@link PropertyAccess} service.<br> !Notice: you must
+ * set the created instance both as model and encoder parameter for the {@link
+ * Select} component.
+ *
+ * @param <T>
+ */
+public class GenericSelectModel<T> extends AbstractSelectModel implements
+ ValueEncoder<T> {
+
+ private PropertyAdapter labelFieldAdapter;
+
+ private PropertyAdapter idFieldAdapter;
+
+ private List<T> list;
+
+ public GenericSelectModel(List<T> list, Class<T> clazz, String labelField,
+ String idField, PropertyAccess access) {
+ this.list = list;
+ if (idField != null) {
+ this.idFieldAdapter =
+ access.getAdapter(clazz).getPropertyAdapter(idField);
+ }
+ if (labelField != null) {
+ this.labelFieldAdapter =
+ access.getAdapter(clazz).getPropertyAdapter(labelField);
+ }
+ }
+
+ @Override
+ public List<OptionGroupModel> getOptionGroups() {
+ return null;
+ }
+
+ @Override
+ public List<OptionModel> getOptions() {
+ List<OptionModel> optionModelList = new ArrayList<OptionModel>();
+ if (labelFieldAdapter == null) {
+ for (T obj : list) {
+ optionModelList.add(new OptionModelImpl(nvl(obj), obj));
+ }
+ } else {
+ for (T obj : list) {
+ optionModelList.add(new OptionModelImpl(nvl(labelFieldAdapter
+ .get(obj)), obj));
+ }
+ }
+ return optionModelList;
+ }
+
+ public List<T> getList() {
+ return list;
+ }
+
+ // ValueEncoder methods
+
+ @Override
+ public String toClient(T obj) {
+ if (idFieldAdapter == null) {
+ return obj + "";
+ } else {
+ return idFieldAdapter.get(obj) + "";
+ }
+ }
+
+ @Override
+ public T toValue(String string) {
+ if (idFieldAdapter == null) {
+ for (T obj : list) {
+ if (nvl(obj).equals(string)) {
+ return obj;
+ }
+ }
+ } else {
+ for (T obj : list) {
+ if (nvl(idFieldAdapter.get(obj)).equals(string)) {
+ return obj;
+ }
+ }
+ }
+ return null;
+ }
+
+ private String nvl(Object o) {
+ if (o == null) {
+ return "";
+ } else {
+ return o.toString();
+ }
+ }
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/GenericSelectModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -0,0 +1,160 @@
+package org.chorem.pollen.ui.models;
+
+import org.apache.tapestry5.ValueEncoder;
+import org.chorem.pollen.PollenBusinessException;
+import org.chorem.pollen.entity.Participant;
+import org.chorem.pollen.entity.ParticipantList;
+import org.chorem.pollen.service.ServicePoll;
+import org.chorem.pollen.ui.services.PollenManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Created: 18 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class ParticipantListModel implements ValueEncoder<Participant> {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(ParticipantListModel.class);
+
+ protected ServicePoll service;
+
+ protected PollenManager manager;
+
+ protected ParticipantList list;
+
+ protected ParticipantMap participants;
+
+ public ParticipantListModel(ServicePoll service, PollenManager manager) {
+ this.service = service;
+ this.manager = manager;
+ participants = new ParticipantMap();
+ }
+
+ public Participant addNewParticipant() {
+ Participant newParticipant = service.getNewPollParticipant();
+ String id = manager.createPollenId();
+ participants.put(id, newParticipant);
+ return newParticipant;
+ }
+
+ public void removeParticipant(Participant participant) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Remove participant : " + participant);
+ }
+ participants.remove(participant);
+ }
+
+ public Collection<Participant> getParticipants() {
+ return participants.values();
+ }
+
+ public void setList(ParticipantList participantList) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Set current list : " + participantList.getName());
+ }
+ list = participantList;
+ participants.clear();
+ for (Participant participant : participantList.getParticipants()) {
+ String id = participant.getId() != null ? participant.getId() :
+ manager.createPollenId();
+ if (logger.isTraceEnabled()) {
+ logger.trace("Push participant : " +
+ participant.getName() +
+ " (" + participant.getEmail() + ")" +
+ " ID = " + id);
+ }
+ participants.put(id, participant);
+ }
+ }
+
+ public ParticipantList getList() {
+ return list;
+ }
+
+ public void reset() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Reset current list");
+ }
+ list = null;
+ participants.clear();
+ }
+
+ public void persistParticipants() throws PollenBusinessException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Save current list : " + list.getName());
+ }
+ list.setParticipants(getParticipants());
+ }
+
+ @Override
+ public String toClient(Participant value) {
+ String key = participants.getKey(value);
+ if (logger.isTraceEnabled()) {
+ logger.trace("toClient key = " + key);
+ }
+ return key;
+ }
+
+ @Override
+ public Participant toValue(String key) {
+ Participant value = participants.getValue(key);
+ if (logger.isTraceEnabled()) {
+ logger.trace("toValue from : " + key + " = " + value.getName() +
+ " (" + value.getEmail() + ")");
+ }
+ return value;
+ }
+
+ /**
+ * Participant map is a BidiMap ordered on values inserted using a {@link
+ * LinkedHashMap}.
+ */
+ protected class ParticipantMap {
+
+ protected Map<String, Participant> participants;
+
+ protected Map<Participant, String> keys;
+
+ public ParticipantMap() {
+ participants = new LinkedHashMap<String, Participant>();
+ keys = new HashMap<Participant, String>();
+ }
+
+ public void put(String id, Participant participant) {
+ participants.put(id, participant);
+ keys.put(participant, id);
+ }
+
+ public String getKey(Participant participant) {
+ return keys.get(participant);
+ }
+
+ public Participant getValue(String id) {
+ return participants.get(id);
+ }
+
+ public void clear() {
+ keys.clear();
+ participants.clear();
+ }
+
+ public void remove(Participant participant) {
+ String id = keys.remove(participant);
+ participants.remove(id);
+ }
+
+ public Collection<Participant> values() {
+ return participants.values();
+ }
+
+ }
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -0,0 +1,286 @@
+package org.chorem.pollen.ui.models;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.tapestry5.ValueEncoder;
+import org.chorem.pollen.PollenBusinessException;
+import org.chorem.pollen.common.PollType;
+import org.chorem.pollen.entity.ParticipantList;
+import org.chorem.pollen.entity.Poll;
+import org.chorem.pollen.entity.UserAccount;
+import org.chorem.pollen.service.ServicePoll;
+import org.chorem.pollen.ui.pages.poll.PollForm;
+import org.chorem.pollen.ui.services.PollenManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Model for PollForm page. Contains the current {@code poll} and its
+ * participant {@code lists}. Use {@link ParticipantListModel} to manage current
+ * edited list for restricted or group Poll. Implement a {@link ValueEncoder} to
+ * manage ParticipantList client conversion in PollForm page.
+ * <p/>
+ * Created: 18 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ * @see PollForm
+ * @see ValueEncoder
+ */
+public class PollFormModel implements ValueEncoder<ParticipantList> {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(PollFormModel.class);
+
+ /** Default listName for Restricted Poll */
+ private static final String DEFAULT_LIST_NAME = "LIST";
+
+ /** Service to manage poll */
+ protected ServicePoll service;
+
+ /** Current poll in edition */
+ protected Poll poll;
+
+ /** Current lists in edition */
+ protected Map<String, ParticipantList> lists;
+
+ /** Current listModel that contains current edited list and its participants */
+ protected ParticipantListModel listModel;
+
+ protected boolean createMode;
+
+ /**
+ * Constructor of PollFormModel. Need services {@code servicePoll} and
+ * {@code manager} to manage the current edited poll. Use {@link
+ * #initPoll(String, UserAccount)} to initialize the poll.
+ *
+ * @param servicePoll ServicePoll to manage poll
+ * @param manager PollenManager to manage ids
+ */
+ public PollFormModel(ServicePoll servicePoll,
+ PollenManager manager) {
+ this.service = servicePoll;
+ lists = new LinkedHashMap<String, ParticipantList>();
+ this.listModel = new ParticipantListModel(service, manager);
+ }
+
+ /**
+ * Initialize the poll using an {@code uid} for an existing poll or the
+ * current {@code user} connected if he exists as the creator of a new
+ * poll.
+ *
+ * @param uid Unique id of an existing poll (can be null for a new poll)
+ * @param user Connected user as creator of a new poll (can be null if no
+ * user is connected).
+ */
+ public void initPoll(String uid, UserAccount user) {
+ if (StringUtils.isNotEmpty(uid)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Get existing poll with pollUID = " + uid);
+ }
+ poll = service.getPollForUpdate(uid);
+ // TODO : init advancedOptions
+ // TODO-fdesbois-2010-05-19 : exception need to be throw if uid not correspond to an existing poll
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Init new poll");
+ }
+ poll = service.getNewPoll(user);
+ createMode = true;
+ }
+ }
+
+ /**
+ * Get the current poll. Will be null if initializion with {@link
+ * #initPoll(String, UserAccount)} has not been called.
+ *
+ * @return the current poll.
+ */
+ public Poll getPoll() {
+ return poll;
+ }
+
+ /**
+ * Check if the current poll is in creation mode.
+ *
+ * @return true for create mode or false.
+ */
+ public boolean isCreateMode() {
+ return createMode;
+ }
+
+ /**
+ * Change the poll type to {@code type}. The lists managment will depends on
+ * poll type. For a {@link PollType#RESTRICTED} poll, a new list will be
+ * automatically added and set for current usage. For a {@link
+ * PollType#GROUP} poll, the listModel is simply reset.
+ *
+ * @param type PollType to change
+ */
+ public void setPollType(PollType type) {
+ lists.clear();
+ if (type.isRestricted()) {
+ addNewList(DEFAULT_LIST_NAME);
+ // Set automatically the current list to the unique one
+ listModel.setList(lists.get(DEFAULT_LIST_NAME));
+ } else if (type.isGroup()) {
+ listModel.reset();
+ }
+ poll.setPollType(type);
+ }
+
+ /**
+ * Retrieve a collection of {@link ParticipantList} of current lists.
+ *
+ * @return a Collection<ParticipantList>
+ */
+ public Collection<ParticipantList> getLists() {
+ return lists.values();
+ }
+
+ /**
+ * Add a new list to the poll using the {@code listName}. The list will not
+ * be added if the {@code listName} is empty or if a list with this {@code
+ * listName} already exists.
+ *
+ * @param listName for the new list to add
+ * @return true if the list has been added, false otherwise
+ * @see #addList(ParticipantList)
+ */
+ public boolean addNewList(String listName) {
+ boolean result = false;
+ if (StringUtils.isNotEmpty(listName)) {
+ ParticipantList newList = service.getNewPollList();
+ newList.setName(listName);
+ return addList(newList);
+ }
+ return result;
+ }
+
+ /**
+ * Add a {@code list} to the poll. The {@code list} will not be added if its
+ * name already reference an exising list.
+ *
+ * @param list ParticipantList to add
+ * @return true if the list has been added, false otherwise
+ */
+ public boolean addList(ParticipantList list) {
+ boolean result = false;
+ if (list != null) {
+ String listName = list.getName();
+ if (!lists.containsKey(listName)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Add list : " + listName);
+ }
+ lists.put(listName, list);
+ result = true;
+ } else if (logger.isDebugEnabled()) {
+ logger.debug("Refuse adding list : " + listName);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Give the current {@link ParticipantListModel} that references the list
+ * currently edited.
+ *
+ * @return the current listModel
+ */
+ public ParticipantListModel getListModel() {
+ return listModel;
+ }
+
+ /**
+ * Set the current list using its {@code listName}. The previous current
+ * list will be automatically saved. If error occurs during save, the
+ * previous list will be refresh (no list change will be done).
+ *
+ * @param listName name of the list to set (empty name will be ignored)
+ * @throws PollenBusinessException for saving error (doubloons)
+ * @see #saveCurrentList()
+ */
+ public void setCurrentList(String listName) throws PollenBusinessException {
+ if (StringUtils.isNotEmpty(listName)) {
+ ParticipantList list = getCurrentList();
+ try {
+ // Save previous list if not null
+ if (list != null) {
+ saveCurrentList();
+ }
+ // Change list
+ list = lists.get(listName);
+ } finally {
+ // Previous list will be keeped if error occurs during save.
+ // Apply change in listModel
+ listModel.setList(list);
+ }
+ }
+ }
+
+ /**
+ * Get the current list.
+ *
+ * @return the current list in edition.
+ */
+ public ParticipantList getCurrentList() {
+ return listModel.getList();
+ }
+
+ /** Remove the current list. */
+ public void removeCurrentList() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Remove list : " + listModel.getList().getName());
+ }
+
+ getLists().remove(listModel.getList());
+ listModel.reset();
+ }
+
+ /**
+ * Save the current participants from current list.
+ *
+ * @throws PollenBusinessException for saving errors (doubloons)
+ * @see ParticipantListModel#persistParticipants()
+ */
+ public void saveCurrentList() throws PollenBusinessException {
+ listModel.persistParticipants();
+ }
+
+ public void create() throws PollenBusinessException {
+ service.createPoll(poll, getLists());
+ }
+
+ /**
+ * ValueEncoder toClient is used to convert {@code value} to the list name.
+ *
+ * @param value ParticipantList to convert toClient
+ * @return the list name as a unique key for the list
+ * @see ValueEncoder#toClient(Object)
+ */
+ @Override
+ public String toClient(ParticipantList value) {
+ return value.getName();
+ }
+
+ /**
+ * ValueEncoder toClient is used to convert {@code clientValue} key to the
+ * list object.
+ *
+ * @param clientValue List name of the ParticipantList to retrieve.
+ * @return the ParticipantList corresponding to its name in argument
+ * @see ValueEncoder#toValue(String)
+ */
+ @Override
+ public ParticipantList toValue(String clientValue) {
+ for (ParticipantList curr : lists.values()) {
+ if (clientValue.equals(curr.getName())) {
+ return curr;
+ }
+ }
+ return null;
+ }
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -0,0 +1,53 @@
+package org.chorem.pollen.ui.models;
+
+import org.apache.tapestry5.grid.SortConstraint;
+import org.chorem.pollen.PollenException;
+import org.chorem.pollen.bean.Filter;
+import org.chorem.pollen.entity.UserAccount;
+import org.chorem.pollen.service.ServiceUser;
+import org.nuiton.web.tapestry5.data.AbstractMappedGridDataSource;
+
+import java.util.Map;
+
+/**
+ * UserAccountDataSource
+ * <p/>
+ * Created: 23 avr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ * <p/>
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class UserAccountDataSource extends AbstractMappedGridDataSource<String, UserAccount> {
+
+ private ServiceUser service;
+
+ private Filter filter;
+
+ public UserAccountDataSource(ServiceUser service, Filter filter) {
+ this.service = service;
+ this.filter = filter;
+ }
+
+ @Override
+ protected Map<String, UserAccount> execute(int startIndex, int endIndex,
+ SortConstraint orderBy) throws PollenException {
+ filter.setStartIndex(startIndex);
+ filter.setEndIndex(endIndex);
+ filter.setOrderBy(resolveOrderBy(orderBy));
+ return service.getUsers(filter);
+ }
+
+ @Override
+ protected int count() throws PollenException {
+ return service.getNbUsers(filter);
+ }
+
+ @Override
+ public Class<?> getRowType() {
+ return UserAccount.class;
+ }
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java 2010-05-19 12:59:57 UTC (rev 3001)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -40,12 +40,12 @@
import org.chorem.pollen.ui.components.Border;
import org.chorem.pollen.ui.data.AddressBar;
import org.chorem.pollen.ui.data.PollenRequiresAuthentication;
-import org.chorem.pollen.ui.data.UserAccountDataSource;
+import org.chorem.pollen.ui.models.UserAccountDataSource;
import org.chorem.pollen.ui.services.PollenManager;
import org.slf4j.Logger;
/**
- * Management of users by an admin.
+ * Management of users by an admin.
*
* @author fdesbois <fdesbois(a)codelutin.com>
* @version $Id$
@@ -57,9 +57,9 @@
@InjectComponent
private Border border;
- /** Page title from Messages **/
- @Parameter(defaultPrefix = BindingConstants.MESSAGE,
- value = "pollen.page.AdminUsers.title")
+ /** Page title from Messages * */
+ @Parameter(defaultPrefix = BindingConstants.MESSAGE,
+ value = "pollen.page.AdminUsers.title")
@Property
private String title;
@@ -72,13 +72,13 @@
return AddressBar.newBar().appendCurrent(title);
}
- /** Services used by the page **/
+ /** Services used by the page * */
@Inject
private Logger logger;
@Inject
private ComponentResources resources;
-
+
@Inject
private Messages messages;
@@ -93,25 +93,25 @@
/***************************** USERS GRID/FORM ****************************/
- /** Components of the page **/
+ /** Components of the page * */
@InjectComponent
private Form usersForm;
- /**
+ /**
* Users list : the {@link Persist} is used to keep current page and order
* from dataSource.
*/
@Persist
private UserAccountDataSource accounts;
- /** Current user from iteration on accounts **/
+ /** Current user from iteration on accounts * */
@Property
private UserAccount account;
- /** Edited user **/
+ /** Edited user * */
@Property
private UserAccount accountEdited;
-
+
/**
* Use the {@link UserAccountDataSource} to retrieve existing user accounts.
* This will manage pagination and order of the grid.
@@ -129,7 +129,7 @@
* Test if the edited account is the current one in the Grid.
*
* @return true if the accountEdited is defined and correspond to the
- * current account in the Grid
+ * current account in the Grid
*/
public boolean isEditionMode() {
// The current account in the loop is equals to the edited one
@@ -147,9 +147,9 @@
}
/**
- * ON_ACTION :: Handler method for action on editAccount actionLink.
- * The accountEdited will be set to the user selected in the Grid with
- * {@code login}.
+ * ON_ACTION :: Handler method for action on editAccount actionLink. The
+ * accountEdited will be set to the user selected in the Grid with {@code
+ * login}.
*
* @param login key of the user from the Grid
* @return the usersForm to display form with accountEdited
@@ -163,8 +163,8 @@
}
/**
- * ON_ACTION :: Handler method for action on deletedAccount actionLink.
- * The selected login from the Grid will be used to delete the user.
+ * ON_ACTION :: Handler method for action on deletedAccount actionLink. The
+ * selected login from the Grid will be used to delete the user.
*
* @param login used to delete the user
* @see ServiceUser#deleteUser(String)
@@ -188,7 +188,7 @@
* ON_VALIDATE_FORM :: Handler method for validateForm event of the
* usersForm. The accountEdited will be updated using serviceUser. Errors
* from service will be recorded into the usersForm.
- *
+ *
* @see ServiceUser#updateUser(UserAccount, boolean)
*/
public void onValidateFormFromUsersForm() {
@@ -201,20 +201,20 @@
}
/**
- * ON_SUCCESS :: Handler method for success event of the usersForm.
- * No error occurs from validation, a message will be displayed to client.
+ * ON_SUCCESS :: Handler method for success event of the usersForm. No error
+ * occurs from validation, a message will be displayed to client.
*
* @return the current page to refresh
*/
- public Object onSuccessFromUsersForm() {
+ public Object onSuccessFromUsersForm() {
addInfo(messages.get("pollen.ui.user.update.success"));
return this;
}
/**
- * ON_FAILURE :: Handler method for failure event of the usersForm.
- * Errors were recorded into the usersForm. The usersForm will be refresh
- * to display error messages.
+ * ON_FAILURE :: Handler method for failure event of the usersForm. Errors
+ * were recorded into the usersForm. The usersForm will be refresh to
+ * display error messages.
*
* @return the usersForm to refresh (in the usersZone)
*/
@@ -224,11 +224,11 @@
/***************************** NEW USER FORM ******************************/
- /** newUser to create from newUserForm **/
+ /** newUser to create from newUserForm * */
@Property
private UserAccount newUser;
- /** Components used for refresh or validations **/
+ /** Components used for refresh or validations * */
@InjectComponent
private Form newUserForm;
@@ -238,13 +238,12 @@
@InjectComponent
private Field newEmail;
- /** newPassword created for the newUser **/
+ /** newPassword created for the newUser * */
private String newPassword;
/**
- * ON_PREPARE :: Handler method for prepare events of the newUserForm.
- * The newUser will be initialized if needed before render and before
- * submit.
+ * ON_PREPARE :: Handler method for prepare events of the newUserForm. The
+ * newUser will be initialized if needed before render and before submit.
*/
public void onPrepareFromNewUserForm() {
if (newUser == null) {
@@ -254,10 +253,10 @@
/**
* ON_VALIDATE_FORM :: Handler method for validateForm event of the
- * newUserForm. The newUser will be created using serviceUser. Errors
- * from service will be recorded into the newUserForm. The password will
- * be generated if an email is set into the form. Otherwise the password
- * will be the same as the newUser login.
+ * newUserForm. The newUser will be created using serviceUser. Errors from
+ * service will be recorded into the newUserForm. The password will be
+ * generated if an email is set into the form. Otherwise the password will
+ * be the same as the newUser login.
*
* @see ServiceUser#createUser(UserAccount)
*/
@@ -268,12 +267,12 @@
// Generate new password
newPassword = RandomStringUtils.randomAlphanumeric(8);
passwordInfo =
- messages.get("pollen.ui.user.create.passwordGenerated");
+ messages.get("pollen.ui.user.create.passwordGenerated");
} else {
// Password will be the same as the login
newPassword = newUser.getLogin();
passwordInfo =
- messages.get("pollen.ui.user.create.passwordSameAsLogin");
+ messages.get("pollen.ui.user.create.passwordSameAsLogin");
}
newUser.setNewPassword(newPassword);
@@ -283,7 +282,8 @@
String message = manager.getErrorMessage(eee, messages, logger);
switch (eee.getType()) {
case USER_EMAIL_EXIST:
- newUserForm.recordError(newEmail, message); break;
+ newUserForm.recordError(newEmail, message);
+ break;
case USER_LOGIN_EXIST:
newUserForm.recordError(newLogin, message);
}
@@ -291,11 +291,11 @@
}
/**
- * ON_SUCCESS :: Handler method for success event of the newUserForm.
- * No error occurs from validation, success message is displayed to client
- * and an email is sent to the newUser created if it's defined.
- * The persist fields of the page will be discarded to refresh the grid with
- * no order or page filter.
+ * ON_SUCCESS :: Handler method for success event of the newUserForm. No
+ * error occurs from validation, success message is displayed to client and
+ * an email is sent to the newUser created if it's defined. The persist
+ * fields of the page will be discarded to refresh the grid with no order or
+ * page filter.
*
* @return the current page to refresh
* @see ServiceEmail#sendEmail(PollenEmail)
@@ -309,12 +309,12 @@
PollenEmail email = serviceEmail.getNewEmail(newUser);
email.setSubject(
messages.format("pollen.email.userRegister.subject",
- newUser.getLogin()));
+ newUser.getLogin()));
email.setContent(
messages.format("pollen.email.userRegister.content",
- newUser.getDisplayName(), newUser.getLogin(),
- newPassword, getUrl()));
-
+ newUser.getDisplayName(), newUser.getLogin(),
+ newPassword, getUrl()));
+
serviceEmail.sendEmail(email);
addInfo(messages.format("pollen.ui.user.create.sendEmail",
newUser.getLogin(), newUser.getEmail()));
@@ -334,9 +334,9 @@
}
/**
- * ON_FAILURE :: Handler method for failure event of the newUserForm.
- * Errors were recorded into the newUserForm. The newUserForm will be
- * refresh to display error messages.
+ * ON_FAILURE :: Handler method for failure event of the newUserForm. Errors
+ * were recorded into the newUserForm. The newUserForm will be refresh to
+ * display error messages.
*
* @return the newUserForm to refresh (in the newUserZone)
*/
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-19 12:59:57 UTC (rev 3001)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -27,8 +27,8 @@
import org.chorem.pollen.ui.base.AbstractPollenPage;
import org.chorem.pollen.ui.components.Border;
import org.chorem.pollen.ui.data.AddressBar;
-import org.chorem.pollen.ui.data.ParticipantListModel;
-import org.chorem.pollen.ui.data.PollFormModel;
+import org.chorem.pollen.ui.models.ParticipantListModel;
+import org.chorem.pollen.ui.models.PollFormModel;
import org.chorem.pollen.ui.services.PollenManager;
import org.nuiton.web.tapestry5.components.FeedBack;
import org.slf4j.Logger;
@@ -79,6 +79,7 @@
return border;
}
+ /** Services injected */
@Inject
private Logger log;
@@ -91,11 +92,17 @@
@Inject
private PollenManager manager;
+ /** Main page context */
private String pollUID;
+ /** Main page model */
@Persist
- private Poll poll;
+ private PollFormModel model;
+ /** Main page form component */
+ @InjectComponent
+ private Form mainForm;
+
void onActivate(String id) {
pollUID = id;
}
@@ -105,10 +112,8 @@
}
void setupRender() {
- poll = null;
- initMainInfos();
- initOptions();
model = null;
+ initOptions();
listsFeedback.clearErrors();
}
@@ -116,25 +121,30 @@
* Get the main poll used in the form. The existing poll is loaded if the
* pollUID exist.
*
- * @return poll existing or a new one
- * @throws PollenBusinessException
+ * @return the current poll in edition
+ * @see #getModel()
*/
public Poll getPoll() {
- if (poll == null) {
- if (StringUtils.isNotEmpty(pollUID)) {
- if (log.isDebugEnabled()) {
- log.debug("Get existing poll with pollUID = " + pollUID);
- }
- poll = servicePoll.getPollForUpdate(pollUID);
- // TODO : init advancedOptions
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Init new poll");
- }
- poll = servicePoll.getNewPoll(getUserConnected());
+ return getModel().getPoll();
+ }
+
+ /**
+ * Retrieve the current model for the PollForm or create a new one. The poll
+ * will be initialized depends on {@code pollUID} context : the existing
+ * poll corresponding will be retrieve or a new one will be instantiate with
+ * connected user as the creator.
+ *
+ * @return the model of this page
+ */
+ public PollFormModel getModel() {
+ if (model == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("-------- NEW POLL FORM MODEL --------");
}
+ model = new PollFormModel(servicePoll, manager);
+ model.initPoll(pollUID, getUserConnected());
}
- return poll;
+ return model;
}
/**
@@ -144,7 +154,7 @@
* @throws PollenBusinessException
*/
public boolean isCreateMode() {
- return StringUtils.isEmpty(getPoll().getId());
+ return getModel().isCreateMode();
}
/**
@@ -173,10 +183,6 @@
return AddressBar.newBar().appendCurrent(getPageTitle());
}
- public void setPollCopyFromPoll(Poll poll) {
- this.poll = servicePoll.getNewPoll(poll);
- }
-
public Date getCurrentDate() {
return new Date();
}
@@ -188,19 +194,15 @@
@Environmental
private RenderSupport renderSupport;
-// @InjectComponent
-// private FormFragment optionsFragment;
-
/**
* Action when rendering form. A script is added to manage form
- * interactions
+ * interactions.
*/
@Log
void onPrepareForRender() {
String formId = mainForm.getClientId();
if (log.isDebugEnabled()) {
log.debug("form id : " + formId);
-// log.debug("options fragment id : " + optionsFragment.getClientId());
}
if (formId != null) {
// Script for form interactions : see "webapp/js/pollForm.js"
@@ -214,17 +216,15 @@
/** *********************** MAIN INFOS ********************************* */
- @InjectComponent
- private Form mainForm;
- @Persist
- @Property
- private boolean advancedOptions;
+// @Persist
+// @Property
+// private boolean advancedOptions;
+//
+// protected void initMainInfos() {
+// advancedOptions = false;
+// }
- protected void initMainInfos() {
- advancedOptions = false;
- }
-
/************************** CHOIX *****************************************/
// @Property
@@ -397,57 +397,38 @@
return getPoll().getPollType().isFree();
}
- /** ********************* LISTS **************************************** */
+ /** ******************** LISTS **************************************** */
- @Persist
- private PollFormModel model;
+ @Inject
+ private ComponentResources resources;
-// @Persist
-// private Map<String, ParticipantList> lists;
+ @InjectComponent
+ private Zone listsZone;
+ @InjectComponent
+ private FeedBack listsFeedback;
+
+ /** Current list for loop (GROUP type) */
@Property
private ParticipantList list;
-// @Persist
-// private String listSelectedName;
-
-// @Persist
-// private ParticipantList listSelected;
-//
-// private Map<String, Participant> selectedParticipants;
-
+ /** Current participant for ajaxFormLoop (GROUP or RESTRICTED) types */
@Property
private Participant participant;
- @InjectComponent
- private Zone listsZone;
-
+ /** Field to add a new list */
@Property
private String listName;
- @Inject
- private ComponentResources resources;
-
+ /** Flag for subForm used for lists managment */
@Property
private boolean formActivate;
- @InjectComponent
- private FeedBack listsFeedback;
-
+ /** Flag if submit comes from lists edition */
private boolean editLists;
/** DATA ** */
- public PollFormModel getModel() {
- if (model == null) {
- if (log.isDebugEnabled()) {
- log.debug("-------- NEW MODEL --------");
- }
- model = new PollFormModel(getPoll(), servicePoll, manager);
- }
- return model;
- }
-
public ParticipantListModel getListModel() {
return getModel().getListModel();
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java 2010-05-19 12:59:57 UTC (rev 3001)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java 2010-05-19 13:25:45 UTC (rev 3002)
@@ -15,8 +15,6 @@
package org.chorem.pollen.ui.pages.user;
-import java.util.List;
-
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.InjectComponent;
@@ -33,18 +31,20 @@
import org.chorem.pollen.ui.components.UserListsCreate;
import org.chorem.pollen.ui.components.UserListsUpdate;
import org.chorem.pollen.ui.data.AddressBar;
-import org.chorem.pollen.ui.data.GenericSelectModel;
import org.chorem.pollen.ui.data.PollenRequiresAuthentication;
+import org.chorem.pollen.ui.models.GenericSelectModel;
+import java.util.List;
+
/**
* Page to manage favorite lists of the connected user only (managed thanks to
* {@link PollenRequiresAuthentication} annotation). This page use two main
* components, {@link UserListsCreate} to create a FavoriteList (from import
- * csv, ldap or an empty one) and {@link UserListsUpdate} to manage content
- * of the FavoriteList. This page will provide {@code favoriteListSelected}
- * from a form with only a SelectModel loaded by {@link #getFavoriteLists()}
- * with {@link #getFavoriteListModel()} as model. The delete action is also
- * manage by the page using {@code serviceFavorite}.
+ * csv, ldap or an empty one) and {@link UserListsUpdate} to manage content of
+ * the FavoriteList. This page will provide {@code favoriteListSelected} from a
+ * form with only a SelectModel loaded by {@link #getFavoriteLists()} with
+ * {@link #getFavoriteListModel()} as model. The delete action is also manage by
+ * the page using {@code serviceFavorite}.
*
* @author rannou
* @author fdesbois <fdesbois(a)codelutin.com>
@@ -56,7 +56,7 @@
/************************** PAGE CONFIGURATION ****************************/
- /** Border layout **/
+ /** Border layout * */
@InjectComponent
private Border border;
@@ -65,13 +65,13 @@
return border;
}
- /** Page title from Messages **/
+ /** Page title from Messages * */
@Parameter(defaultPrefix = BindingConstants.MESSAGE,
- value = "pollen.page.UserLists.title")
+ value = "pollen.page.UserLists.title")
@Property
private String title;
- /**
+ /**
* AddressBar for {@code border} component.
*
* @return a new AddressBar for the page.
@@ -80,7 +80,7 @@
return AddressBar.newBar().appendCurrent(title);
}
- /** Services injected **/
+ /** Services injected * */
@Inject
private ServiceFavorite serviceFavorite;
@@ -90,15 +90,16 @@
@Inject
private Messages messages;
- /************************** SELECT FAVORITE LIST **************************/
+ /** *********************** SELECT FAVORITE LIST ************************* */
private List<FavoriteList> favoriteLists;
+
private GenericSelectModel<FavoriteList> favoriteListModel;
/**
- * Main property favoriteListSelected is keeped in Session and was
- * used as parameter for UserListsUpdate component.
- **/
+ * Main property favoriteListSelected is keeped in Session and was used as
+ * parameter for UserListsUpdate component.
+ */
@Persist
@Property
private FavoriteList favoriteListSelected;
@@ -113,10 +114,10 @@
if (favoriteListModel == null) {
favoriteListModel =
new GenericSelectModel<FavoriteList>(getFavoriteLists(),
- FavoriteList.class,
- FavoriteList.NAME,
- FavoriteList.NAME,
- propertyAccess);
+ FavoriteList.class,
+ FavoriteList.NAME,
+ FavoriteList.NAME,
+ propertyAccess);
}
return favoriteListModel;
}
@@ -137,28 +138,28 @@
/************************** SELECT FAVORITE LIST **************************/
/**
- * Used to verify if the {@code favoriteListSelected} is set and ready
- * to be deleted using {@code deleteList} actionLink.
+ * Used to verify if the {@code favoriteListSelected} is set and ready to be
+ * deleted using {@code deleteList} actionLink.
*
* @return true if the {@code favoriteListSelected} is not null.
*/
public boolean canDeleteList() {
- return favoriteListSelected != null;
+ return favoriteListSelected != null;
}
/**
* ON_ACTION :: Handler method for action on {@code deleteList} actionLink.
- * Check is done using {@link #canDeleteList()}, then the
- * {@code serviceFavorite} is called to execute the delete on
- * {@code favoriteListSelected}.
- *
+ * Check is done using {@link #canDeleteList()}, then the {@code
+ * serviceFavorite} is called to execute the delete on {@code
+ * favoriteListSelected}.
+ *
* @see ServiceFavorite#deleteFavoriteList(FavoriteList)
*/
void onActionFromDeleteList() {
if (canDeleteList()) {
serviceFavorite.deleteFavoriteList(favoriteListSelected);
addInfo(
- messages.get("pollen.ui.list.delete.success"));
+ messages.get("pollen.ui.list.delete.success"));
}
}
}
\ No newline at end of file
1
0