Pollen-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- 3196 discussions
Author: tchemit
Date: 2012-06-18 18:19:22 +0200 (Mon, 18 Jun 2012)
New Revision: 3516
Url: http://chorem.org/repositories/revision/pollen/3516
Log:
- fixes #609: Review security access for administrator (should review it when using shiro permissions)
- continuous results have nothing to see with public results
- have same actions on results page than in vote-moderate page
- remove Dummy ChoiceHelper class (at last!)
- remove ResultLink action (at last!)
Removed:
trunk/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultLink.java
Modified:
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModeratePoll.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SummaryPoll.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorAccessRequired.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollVoteAccessRequired.java
trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
trunk/pollen-ui-struts2/src/main/webapp/js/createPoll.js
trunk/src/site/rst/security.rst
Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/bean/ChoiceHelper.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -1,106 +0,0 @@
-/*
- * #%L
- * Pollen :: Services
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.bean;
-
-import com.google.common.collect.Iterables;
-import org.chorem.pollen.business.persistence.Choice;
-import org.chorem.pollen.common.ChoiceType;
-import org.chorem.pollen.services.PollenServiceFunctions;
-
-/**
- * Used to manage all objects from {@link Choice} inheritance tree depends
- * on {@link ChoiceType}.
- * <p/>
- * Created: 30/03/12
- *
- * @author fdesbois <desbois(a)codelutin.com>
- * @since 1.3
- * @deprecated will be removed soon a class form this is not required :(
- */
-@Deprecated
-public final class ChoiceHelper {
-
- private ChoiceHelper() {
- }
-
-// public static Object toValue(Choice choice, ChoiceType choiceType) {
-// Object result;
-// switch (choiceType) {
-// case DATE:
-// if (choice instanceof PollDateChoice) {
-// result = ((PollDateChoice) choice).getDate();
-// } else {
-// result = new Date(Long.parseLong(choice.getName()));
-// }
-// break;
-// case IMAGE:
-// if (choice instanceof PollImageChoice) {
-// result = ((PollImageChoice) choice).getLocation();
-// } else {
-// result = choice.getName();
-// }
-// break;
-// case TEXT:
-// default:
-// result = choice.getName();
-// }
-// return result;
-// }
-
-// public static Function<Choice, Object> toValue(final ChoiceType type) {
-// return new Function<Choice, Object>() {
-//
-// @Override
-// public Object apply(Choice input) {
-// return toValue(input, type);
-// }
-// };
-// }
-
-// public static Iterable<Object> toValues(Iterable<Choice> choices,
-// ChoiceType choiceType) {
-// return Iterables.transform(choices, toValue(choiceType));
-// }
-
- public static Iterable<String> toNames(Iterable<Choice> choices) {
- return Iterables.transform(choices,
- PollenServiceFunctions.CHOICE_TO_NAME);
- }
-
-// public static String getValuePropertyName(ChoiceType choiceType) {
-// String result;
-// switch (choiceType) {
-// case DATE:
-// result = PollDateChoice.PROPERTY_DATE;
-// break;
-// case IMAGE:
-// result = PollImageChoice.PROPERTY_LOCATION;
-// break;
-// case TEXT:
-// default:
-// result = Choice.PROPERTY_NAME;
-// }
-// return result;
-// }
-
-}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -27,6 +27,7 @@
import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.PollenTechnicalException;
import org.chorem.pollen.bean.PollUri;
+import org.chorem.pollen.bean.PollUrl;
import org.chorem.pollen.business.persistence.Comment;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
@@ -50,12 +51,12 @@
*/
public class SecurityService extends PollenServiceSupport {
- public boolean isPollCreator(Poll poll, PollUri uriId,
+ public boolean isPollCreator(Poll poll, String accountId,
UserAccount pollenUserAccount) {
PollAccount creator = poll.getCreator();
- boolean result = creator.getAccountId().equals(uriId.getAccountId());
+ boolean result = creator.getAccountId().equals(accountId);
if (!result) {
if (pollenUserAccount != null) {
@@ -67,7 +68,28 @@
return result;
}
+ public boolean isCanClosePoll(Poll poll, AccountIdRole accountIdRole) {
+ boolean result = !poll.isClosed();
+
+ if (result) {
+
+ // poll can be closed, check user can do action
+ result = accountIdRole == AccountIdRole.CREATOR;
+ }
+
+ return result;
+ }
+
+ public void removeAccountIdWhenConnected(PollUrl url,
+ UserAccount userAccount) {
+ if (userAccount != null) {
+
+ // remove accountId from url
+ url.getPollUri().setAccountId(null);
+ }
+ }
+
/**
* To define meaning of a accountId.
*
@@ -99,83 +121,6 @@
AccountIdRole.CREATOR
);
-// public void checkPoll(PollUri uri) throws PollNotFoundException {
-//
-// getExistingPoll(uri);
-// }
-
-// public void checkPollResult(PollUri uri) throws PollNotFoundException, UnauthorizedPollAccessException {
-//
-// Poll poll = getExistingPoll(uri);
-//
-// if (!poll.isPublicResults()) {
-// throw new UnauthorizedPollAccessException();
-// }
-// }
-
-// public void checkPollAccount(PollUri uri) throws PollNotFoundException, UnauthorizedPollAccessException {
-//
-//
-// String accountId = uri.getAccountId();
-//
-// Poll poll = getExistingPoll(uri);
-//
-// PollAccountDAO dao = getDAO(PollAccount.class);
-//
-// String pollId = uri.getPollId();
-//
-// if (poll.getPollType() == PollType.FREE) {
-//
-// // free poll
-// if (accountId != null) {
-//
-// // account Id is given check there is a such vote for this account
-//
-// try {
-//
-// if (!dao.existsByPollVoteAccountId(pollId, accountId)) {
-// throw new UnauthorizedPollAccessException();
-// }
-// } catch (TopiaException e) {
-// throw new PollenTechnicalException(
-// "Could not check pollAccount existence from poll '" +
-// pollId + "' and account '" + accountId + "'", e);
-// }
-// }
-// } else {
-//
-// // check that uri contains a correct poll account for this
-//
-// // Use PersonToList association entity to find coherence between
-// // the poll and votingId
-//
-// try {
-// PollAccount result =
-// dao.getRestrictedPollAccount(pollId, accountId);
-//
-// if (result == null) {
-// throw new UnauthorizedPollAccessException();
-// }
-// } catch (TopiaException e) {
-// throw new PollenTechnicalException(
-// "Could not obtain restricted pollAccount", e);
-// }
-// }
-// }
-
-// public void checkPollCreator(PollUri uri) throws PollNotFoundException, UnauthorizedPollAccessException {
-//
-// String accountId = uri.getAccountId();
-//
-// Poll poll = getExistingPoll(uri);
-//
-// String creatorId = poll.getCreator().getAccountId();
-//
-// if (!creatorId.equals(accountId)) {
-// throw new UnauthorizedPollAccessException();
-// }
-// }
-
public AccountIdRole getAccountIdRole(Poll poll, String accountId) {
Preconditions.checkNotNull(poll);
@@ -248,7 +193,9 @@
return null;
}
- public String isCanAccessVote(Poll poll, String accountId, AccountIdRole accountIdRole) {
+ public String isCanAccessVote(Poll poll,
+ String accountId,
+ AccountIdRole accountIdRole) {
if (AccountIdRole.CREATOR == accountIdRole) {
@@ -275,7 +222,6 @@
String accountId,
AccountIdRole accountIdRole) {
-
Date now = serviceContext.getCurrentTime();
if (!poll.isRunning(now)) {
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -22,14 +22,10 @@
*/
package org.chorem.pollen.ui;
-import org.apache.struts2.ServletActionContext;
-import org.chorem.pollen.PollenTechnicalException;
+import org.chorem.pollen.services.impl.SecurityService;
import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.net.MalformedURLException;
-import java.net.URL;
+import javax.servlet.ServletRequest;
/**
* Useful ui methods.
@@ -42,6 +38,8 @@
/** Keep the servlet context */
private static ServletContext servletContext;
+ private static final String ACCOUNT_ID_ROLE = "accountIdRole";
+
public static ServletContext getServletContext() {
return servletContext;
}
@@ -50,39 +48,18 @@
PollenUIUtils.servletContext = servletContext;
}
- public static void redirect(String url) throws Exception {
-
- HttpServletResponse response = ServletActionContext.getResponse();
- HttpServletRequest request = ServletActionContext.getRequest();
-
- String path = request.getContextPath();
- if (!url.startsWith("/")) {
- path += "/";
- }
- response.sendRedirect(path + url);
+ public static void setAccountIdRole(ServletRequest request,
+ SecurityService.AccountIdRole accountIdRole) {
+ request.setAttribute(ACCOUNT_ID_ROLE, accountIdRole);
}
- public static URL getApplicationBase(HttpServletRequest request) {
-
- // get port
- String port;
- if ("http".equalsIgnoreCase(request.getScheme()) && request.getServerPort() != 80 ||
- "https".equalsIgnoreCase(request.getScheme()) && request.getServerPort() != 443) {
- port = ":" + request.getServerPort();
- } else {
- port = "";
- }
-
- String applicationBase = request.getScheme() + "://" + request.getServerName() +
- port + request.getContextPath();
- try {
- return new URL(applicationBase);
- } catch (MalformedURLException e) {
- throw new PollenTechnicalException(
- "Could not compute pollen url", e);
- }
+ public static SecurityService.AccountIdRole getAccountIdRole(ServletRequest request) {
+ SecurityService.AccountIdRole result = (SecurityService.AccountIdRole)
+ request.getAttribute(ACCOUNT_ID_ROLE);
+ return result;
}
protected PollenUIUtils() {
+ // helper can not be instanciated
}
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -459,12 +459,12 @@
poll.setMaxChoiceNb(0);
}
- if (!poll.isPublicResults()) {
+// if (!poll.isPublicResults()) {
+//
+// // force to not have continous results
+// poll.setContinuousResults(false);
+// }
- // force to not have continous results
- poll.setContinuousResults(false);
- }
-
if (poll.isAnonymous()) {
// force to not have choice to vote anonymously
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -30,6 +30,7 @@
import org.apache.struts2.interceptor.ServletRequestAware;
import org.chorem.pollen.bean.PollResult;
import org.chorem.pollen.bean.PollResultList;
+import org.chorem.pollen.bean.PollUrl;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.Comment;
import org.chorem.pollen.business.persistence.Poll;
@@ -43,8 +44,8 @@
import org.chorem.pollen.services.exceptions.PollAccountNotFound;
import org.chorem.pollen.services.exceptions.PollNotFoundException;
import org.chorem.pollen.services.impl.SecurityService;
+import org.chorem.pollen.ui.PollenUIUtils;
import org.chorem.pollen.ui.actions.PageSkin;
-import org.chorem.pollen.ui.security.PollVoteAccessRequired;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
@@ -65,6 +66,8 @@
/** Logger. */
private static final Log log = LogFactory.getLog(AbstractVoteAction.class);
+ public static final String PREPARE_VOTE_PAGE = "prepareVotePage";
+
/**
* Loaded poll.
*
@@ -73,7 +76,7 @@
private Poll poll;
/**
- * Is feed existfor this poll ?
+ * Is feed exists for this poll ?
*
* @since 1.3
*/
@@ -93,17 +96,21 @@
*/
private PollAccount pollAccount;
- //TODO-thcemit-2012-06-03 Do we use this ? nobody set it... so always false
- private boolean alreadyVoted;
-
/**
- * Is votr allowed for current user?
+ * Is vote allowed for current user?
*
* @since 1.3
*/
private boolean voteAllowed;
/**
+ * Is current user can go to results.
+ *
+ * @since 1.4
+ */
+ private boolean resultAllowed;
+
+ /**
* All votes for the poll.
*
* @since 1.3
@@ -159,6 +166,11 @@
*/
private transient HttpServletRequest request;
+ /**
+ * @return {@code true} if moderation is possible, {@code false} otherwise
+ * @since 1.4
+ */
+ public abstract boolean isModerate();
@Override
public PageSkin getSkin() {
@@ -179,10 +191,6 @@
return poll;
}
- public boolean isFeedFileExisting() {
- return feedFileExisting;
- }
-
public PollAccount getPollAccount() {
return pollAccount;
}
@@ -195,27 +203,57 @@
return vote;
}
- public boolean isPollChoiceOrVoteStarted() {
- Date now = serviceContext.getCurrentTime();
- return poll.isAddChoiceStarted(now) || poll.isStarted(now);
+ public List<PollResult> getResults() {
+ return results;
}
- public boolean isAlreadyVoted() {
- return alreadyVoted;
+ public List<Comment> getComments() {
+ return comments;
}
- public boolean isAnonymousVote() {
- return poll.isAnonymous();
+ public String getCreatorName() {
+ return poll.getCreator().getVotingId();
}
- public List<PollResult> getResults() {
- return results;
+ public String getVoteSizeMessage() {
+ return _("pollen.common.voteNbVotes", getPoll().sizeVote());
}
- public List<Comment> getComments() {
- return comments;
+ public String getCommentAuthor() {
+ if (commentAuthor == null) {
+
+ UserAccount user = getPollenUserAccount();
+ if (user == null) {
+
+ // Use current pollAccount name for comment
+ commentAuthor = getPollAccount().getVotingId();
+
+ } else {
+
+ // Connecter user name
+ commentAuthor = user.getDisplayName();
+ }
+ }
+ return commentAuthor;
}
+ public String getSummaryUrl() {
+ PollUrl url = getPollUrlService().getPollSummaryUrl(poll);
+ getSecurityService().removeAccountIdWhenConnected(url, getPollenUserAccount());
+ return url.getUrl();
+ }
+
+ public String getResultUrl() {
+ PollUrl url = getPollUrlService().getPollResultUrl(poll);
+ url.getPollUri().setAccountId(getAccountId());
+ getSecurityService().removeAccountIdWhenConnected(url, getPollenUserAccount());
+ return url.getUrl();
+ }
+
+ public boolean isFeedFileExisting() {
+ return feedFileExisting;
+ }
+
public boolean isCreatorUser() {
return creatorUser;
}
@@ -224,17 +262,28 @@
return !poll.isAnonymous() || isRestrictedPoll() || isGroupPoll();
}
+ public boolean isPollChoiceOrVoteStarted() {
+ Date now = serviceContext.getCurrentTime();
+ return poll.isAddChoiceStarted(now) || poll.isStarted(now);
+ }
+
+ public boolean isAnonymousVote() {
+ return poll.isAnonymous();
+ }
+
public boolean isPollChoiceRunning() {
Date now = serviceContext.getCurrentTime();
return poll.isAddChoiceRunning(now);
}
- public String getCreatorName() {
- return poll.getCreator().getVotingId();
+ public boolean isPollStarted() {
+ Date now = serviceContext.getCurrentTime();
+ return poll.getBeginDate() == null || poll.getBeginDate().before(now);
}
- public String getVoteSizeMessage() {
- return _("pollen.common.voteNbVotes", getPoll().sizeVote());
+ public boolean isPollFinished() {
+ Date now = serviceContext.getCurrentTime();
+ return poll.getEndDate() != null && poll.getEndDate().before(now);
}
public boolean isDescNull(Choice choice) {
@@ -281,80 +330,37 @@
return poll.getVoteCountingType() == VoteCountingType.NUMBER;
}
- public boolean isPollStarted() {
- Date now = serviceContext.getCurrentTime();
- return poll.getBeginDate() == null || poll.getBeginDate().before(now);
+ public boolean isVoteAllowed() {
+ return voteAllowed;
}
- public boolean isPollFinished() {
- Date now = serviceContext.getCurrentTime();
- return poll.getEndDate() != null && poll.getEndDate().before(now);
+ public boolean isResultAllowed() {
+ return resultAllowed;
}
- public String getCommentAuthor() {
- if (commentAuthor == null) {
-
- UserAccount user = getPollenUserAccount();
- if (user == null) {
-
- // Use current pollAccount name for comment
- commentAuthor = getPollAccount().getVotingId();
-
- } else {
-
- // Connecter user name
- commentAuthor = user.getDisplayName();
- }
- }
- return commentAuthor;
+ public boolean isModifyVoteAllowed(Vote vote) {
+ return getSecurityService().isCanModifyVote(
+ getPoll(),
+ vote.getTopiaId(),
+ getAccountId(),
+ getPollenUserAccount());
}
- public void setCommentAuthor(String commentAuthor) {
- this.commentAuthor = commentAuthor;
+ public boolean isDeleteCommentAllowed(Comment comment) {
+ return getSecurityService().isCanDeleteComment(
+ comment,
+ getUriId().getAccountId(),
+ accountIdRole,
+ getPollenUserAccount());
}
- protected String prepareVotePage(boolean moderate) throws Exception {
-
- loadPoll();
-
- // Current poll account
- loadPollAccount();
-
- // All votes
- // TODO no pagination for the moment, need to retrieve the correct page depends on current pollAccount
- votes = getVoteService().getAllVotes(poll);
-
- accountIdRole = (SecurityService.AccountIdRole)
- request.getAttribute(PollVoteAccessRequired.ACCOUNT_ID_ROLE);
-
- voteAllowed = !moderate &&
- getSecurityService().isCanVote(poll,
- getAccountId(),
- accountIdRole);
-
- // Current vote
- if (voteAllowed) {
- vote = getVoteService().getVoteEditable(poll, pollAccount);
- }
-
- loadPollResults();
- loadPollComments();
-
- feedFileExisting = getPollFeedService().isFeedExists(poll);
-
- creatorUser = getSecurityService().isPollCreator(poll,
- getUriId(),
- getPollenUserAccount());
-
- if (log.isInfoEnabled()) {
- Date now = serviceContext.getCurrentTime();
- log.info("pollChoiceOrVoteStarted = " + isPollChoiceOrVoteStarted());
- log.info("pollChoiceRunning = " + isPollChoiceRunning());
- log.info("pollRunning = " + poll.isRunning(now));
- log.info("accountFieldDisplayed = " + isAccountFieldDisplayed());
- log.info("creatorUser = " + creatorUser);
- }
- return INPUT;
+ public boolean isDeleteVoteAllowed(Vote vote) {
+ return getSecurityService().isCanDeleteVote(
+ getPoll(),
+ vote.getTopiaId(),
+ getUriId().getAccountId(),
+ accountIdRole,
+ getPollenUserAccount());
}
public String getResultValue(Choice choice) {
@@ -390,45 +396,93 @@
return result;
}
- public boolean isModifyVoteAllowed(Vote vote) {
- return getSecurityService().isCanModifyVote(
- getPoll(),
- vote.getTopiaId(),
- getAccountId(),
- getPollenUserAccount());
+ public Date getChoiceAsDate(Choice choice) {
+ return new Date(Long.valueOf(choice.getName()));
}
- public boolean isVoteAllowed() {
- return voteAllowed;
+ public void setCommentAuthor(String commentAuthor) {
+ this.commentAuthor = commentAuthor;
}
- public boolean isDeleteCommentAllowed(Comment comment) {
- return getSecurityService().isCanDeleteComment(
- comment,
- getUriId().getAccountId(),
- accountIdRole,
- getPollenUserAccount());
- }
+ public String prepareVotePage() throws Exception {
- public boolean isDeleteVoteAllowed(Vote vote) {
- return getSecurityService().isCanDeleteVote(
- getPoll(),
- vote.getTopiaId(),
- getUriId().getAccountId(),
- accountIdRole,
- getPollenUserAccount());
-// // can delete a vote if admin or poll creator
-// return isUserAdmin() || isCreatorUser();
+ boolean moderate = isModerate();
+
+ loadPoll();
+
+ // Current poll account
+ loadPollAccount();
+
+ // All votes
+ // TODO no pagination for the moment, need to retrieve the correct page depends on current pollAccount
+ votes = getVoteService().getAllVotes(poll);
+
+ accountIdRole = PollenUIUtils.getAccountIdRole(request);
+
+ // is vote allowed ?
+ if (moderate) {
+ voteAllowed = false;
+ } else {
+ String accountId = getAccountId();
+ if (accountIdRole == SecurityService.AccountIdRole.CREATOR) {
+
+ // remove accountId (can vote even if creator ?)
+ accountId = null;
+ }
+ voteAllowed = getSecurityService().isCanVote(poll,
+ null,
+ accountIdRole);
+ }
+
+ // is can display result link ?
+ resultAllowed =
+ getSecurityService().isCanAccessResult(poll, accountIdRole)
+ == null;
+
+ if (voteAllowed) {
+
+ // load modifiable vote
+ vote = getVoteService().getVoteEditable(poll, pollAccount);
+ }
+
+ // load poll results
+ PollResultList pollResultList =
+ getPollResultsService().getResults(poll);
+
+ results = pollResultList.getPollResults();
+
+ if (log.isDebugEnabled()) {
+ for (PollResult res : results) {
+ log.debug(res.getName() + ": " + res.getValue()
+ + ", (voteCounting=" + res.getVoteCountingType()
+ + ", byGroup=" + res.isByGroup() + ")");
+ }
+ }
+
+ // load comments
+ comments = getPollCommentService().getAllComments(poll.getPollId());
+
+ feedFileExisting = getPollFeedService().isFeedExists(poll);
+
+ creatorUser = getSecurityService().isPollCreator(poll,
+ getAccountId(),
+ getPollenUserAccount());
+
+ if (log.isInfoEnabled()) {
+ Date now = serviceContext.getCurrentTime();
+ log.info("pollChoiceOrVoteStarted = " + isPollChoiceOrVoteStarted());
+ log.info("pollChoiceRunning = " + isPollChoiceRunning());
+ log.info("pollRunning = " + poll.isRunning(now));
+ log.info("accountFieldDisplayed = " + isAccountFieldDisplayed());
+ log.info("creatorUser = " + creatorUser);
+ }
+ return INPUT;
}
public String escapeLineBreak(String text) {
return text;
}
- public Date getChoiceAsDate(Choice choice) {
- return new Date(Long.valueOf(choice.getName()));
- }
-
protected void loadPollAccount() throws PollAccountNotFound {
// Current poll account
@@ -453,24 +507,4 @@
}
}
- protected void loadPollComments() {
-
- comments = getPollCommentService().getAllComments(poll.getPollId());
- }
-
- protected void loadPollResults() throws PollNotFoundException {
-
- PollResultList pollResultList =
- getPollResultsService().getResults(poll);
-
- results = pollResultList.getPollResults();
-
- if (log.isDebugEnabled()) {
- for (PollResult res : results) {
- log.debug(res.getName() + ": " + res.getValue()
- + ", (voteCounting=" + res.getVoteCountingType()
- + ", byGroup=" + res.isByGroup() + ")");
- }
- }
- }
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddChoice.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -22,11 +22,9 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import com.google.common.collect.Iterables;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
import org.apache.commons.lang3.StringUtils;
-import org.chorem.pollen.bean.ChoiceHelper;
import org.chorem.pollen.bean.PollImageChoice;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.common.ChoiceType;
@@ -74,6 +72,11 @@
}
@Override
+ public boolean isModerate() {
+ return false;
+ }
+
+ @Override
public void prepare() throws PollNotFoundException {
loadPoll();
@@ -107,24 +110,23 @@
_("pollen.error.choice.empty", typeLabel));
} else {
- //TODO-tchemit-2012-06-16 Remove this code and perfomr a real validation (name not empty, name not duplicated)
- // Retrieve existing values to check if the new choice not already exists
- Iterable<String> pollChoiceValues = ChoiceHelper.toNames(
- getPoll().getChoice());
+ if (!getPoll().isChoiceEmpty()) {
- // -- Validate value notExists
- if (Iterables.contains(pollChoiceValues, choiceName)) {
- addFieldError("choice." + propName,
- _("pollen.error.poll.detected.duplicate.choice.name"));
+ // check that the choice is not already used
+
+ for (Choice pollChoice : getPoll().getChoice()) {
+ String pollChoiceName = pollChoice.getName();
+ if (pollChoiceName.equals(choiceName)) {
+ addFieldError("choice." + propName,
+ _("pollen.error.poll.choice.already.used.name"));
+ break;
+ }
+ }
}
}
}
- public String prepareVotePage() throws Exception {
- return prepareVotePage(false);
- }
-
- @InputConfig(methodName = "prepareVotePage")
+ @InputConfig(methodName = PREPARE_VOTE_PAGE)
@Override
public String execute() throws Exception {
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -53,6 +53,11 @@
}
@Override
+ public boolean isModerate() {
+ return false;
+ }
+
+ @Override
public void prepare() throws Exception {
loadPoll();
@@ -71,7 +76,7 @@
}
}
- @InputConfig(methodName = "prepareVotePage")
+ @InputConfig(methodName = PREPARE_VOTE_PAGE)
@Override
public String execute() throws Exception {
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -58,8 +58,13 @@
this.reason = reason;
}
- @InputConfig(methodName = "prepareVotePage")
@Override
+ public boolean isModerate() {
+ return false;
+ }
+
+ @InputConfig(methodName = PREPARE_VOTE_PAGE)
+ @Override
public String execute() throws Exception {
Preconditions.checkNotNull(getPollId());
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModeratePoll.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModeratePoll.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModeratePoll.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -35,9 +35,14 @@
@Override
public String input() throws Exception {
- prepareVotePage(true);
+ prepareVotePage();
addFlashWarning(_("pollen.information.moderate.page"));
return INPUT;
}
+
+ @Override
+ public boolean isModerate() {
+ return true;
+ }
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -36,6 +36,7 @@
import org.apache.struts2.views.util.UrlHelper;
import org.chorem.pollen.bean.PollResult;
import org.chorem.pollen.bean.PollResultList;
+import org.chorem.pollen.bean.PollUrl;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
@@ -82,13 +83,20 @@
private boolean userAllowed;
/**
- * Is user is poll(s creator ?
+ * Is user is poll's creator ?
*
* @since 1.4
*/
private boolean creatorUser;
/**
+ * Is feed exists for this poll ?
+ *
+ * @since 1.4
+ */
+ private boolean feedFileExisting;
+
+ /**
* Résultats du sondage.
* <p/>
* La map est indexée par les noms de choix.
@@ -150,6 +158,29 @@
return creatorUser;
}
+ public boolean isFeedFileExisting() {
+ return feedFileExisting;
+ }
+
+ public String getSummaryUrl() {
+ PollUrl url = getPollUrlService().getPollSummaryUrl(poll);
+ url.getPollUri().setAccountId(getAccountId());
+ getSecurityService().removeAccountIdWhenConnected(url, getPollenUserAccount());
+ return url.getUrl();
+ }
+
+ public String getVoteUrl() {
+ PollUrl url = getPollUrlService().getPollVoteUrl(poll);
+ url.getPollUri().setAccountId(getAccountId());
+ if (poll.getPollType() == PollType.FREE) {
+
+ // can removed accountId only for free poll
+ //FIXME Should found out in ohter case the accountId (if exists for the connected id) if no accountId is given
+ getSecurityService().removeAccountIdWhenConnected(url, getPollenUserAccount());
+ }
+ return url.getUrl();
+ }
+
public List<PollResult> getResults() {
return results;
}
@@ -206,6 +237,8 @@
poll = getPollService().getExistingPollByPollId(pollId);
+ feedFileExisting = getPollFeedService().isFeedExists(poll);
+
if (byGroup == null) {
// default byGroup value
Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultLink.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultLink.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultLink.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -1,68 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (struts2)
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-import com.google.common.base.Preconditions;
-import org.chorem.pollen.business.persistence.Poll;
-import org.chorem.pollen.ui.actions.PageSkin;
-
-/**
- * Display the result link page.
- *
- * @author fdesbois <desbois(a)codelutin.com>
- * @since 1.3
- */
-public class ResultLink extends AbstractPollUriIdAction {
-
- private static final long serialVersionUID = 1L;
-
- protected Poll poll;
-
- protected String pollResultUrl;
-
- @Override
- public PageSkin getSkin() {
- return PageSkin.EDITION;
- }
-
- public Poll getPoll() {
- return poll;
- }
-
- public String getPollResultUrl() {
- return pollResultUrl;
- }
-
- @Override
- public String execute() throws Exception {
-
- String pollUid = getPollId();
- Preconditions.checkNotNull(pollUid);
-
- poll = getPollService().getExistingPollByPollId(pollUid);
-
- pollResultUrl = getPollUrlService().getPollResultUrl(poll).getUrl();
-
- return SUCCESS;
- }
-}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SummaryPoll.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SummaryPoll.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SummaryPoll.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -23,18 +23,23 @@
package org.chorem.pollen.ui.actions.poll;
import com.google.common.base.Preconditions;
+import org.apache.struts2.interceptor.ServletRequestAware;
+import org.chorem.pollen.bean.PollUrl;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.services.impl.SecurityService;
+import org.chorem.pollen.ui.PollenUIUtils;
import org.chorem.pollen.ui.actions.PageSkin;
+import javax.servlet.http.HttpServletRequest;
+
/**
* Action to display summary of a poll for his creator (or an admin).
*
* @author tchemit <chemit(a)codelutin.com>
* @since 1.4
*/
-public class SummaryPoll extends AbstractPollUriIdAction {
+public class SummaryPoll extends AbstractPollUriIdAction implements ServletRequestAware {
private static final long serialVersionUID = 1L;
@@ -45,8 +50,23 @@
*/
private Poll poll;
- public Poll getPoll() {
- return poll;
+ /**
+ * The accountId role on this page.
+ *
+ * @since 1.4
+ */
+ private SecurityService.AccountIdRole accountIdRole;
+
+ /**
+ * The incoming request (some stuff are store in it from security filters).
+ *
+ * @since 1.4
+ */
+ private transient HttpServletRequest request;
+
+ @Override
+ public void setServletRequest(HttpServletRequest request) {
+ this.request = request;
}
@Override
@@ -54,55 +74,69 @@
return PageSkin.EDITION;
}
+ public Poll getPoll() {
+ return poll;
+ }
+
public String getVoteUrl() {
- return getPollUrlService().getPollVoteUrl(poll).getUrl();
+ PollUrl url = getPollUrlService().getPollVoteUrl(poll);
+ if (poll.getPollType() == PollType.FREE) {
+
+ // can removed accountId only for free poll
+ //FIXME Should found out in ohter case the accountId (if exists for the connected id) if no accountId is given
+ getSecurityService().removeAccountIdWhenConnected(url, getPollenUserAccount());
+ }
+ return url.getUrl();
}
public String getModerateUrl() {
- return getPollUrlService().getPollModerateUrl(poll).getUrl();
+ PollUrl url = getPollUrlService().getPollModerateUrl(poll);
+ getSecurityService().removeAccountIdWhenConnected(url, getPollenUserAccount());
+ return url.getUrl();
}
public String getEditUrl() {
- return getPollUrlService().getPollEditUrl(poll).getUrl();
+ PollUrl url = getPollUrlService().getPollEditUrl(poll);
+ getSecurityService().removeAccountIdWhenConnected(url, getPollenUserAccount());
+ return url.getUrl();
}
public String getCloneUrl() {
- return getPollUrlService().getPollCloneUrl(poll).getUrl();
+ PollUrl url = getPollUrlService().getPollCloneUrl(poll);
+ getSecurityService().removeAccountIdWhenConnected(url, getPollenUserAccount());
+ return url.getUrl();
}
public String getExportUrl() {
- return getPollUrlService().getPollExportUrl(poll).getUrl();
+ PollUrl url = getPollUrlService().getPollExportUrl(poll);
+ getSecurityService().removeAccountIdWhenConnected(url, getPollenUserAccount());
+ return url.getUrl();
}
public String getResultUrl() {
- return getPollUrlService().getPollResultUrl(poll).getUrl();
+ PollUrl url = getPollUrlService().getPollResultUrl(poll);
+ getSecurityService().removeAccountIdWhenConnected(url, getPollenUserAccount());
+ return url.getUrl();
}
public boolean isCanClose() {
- return !poll.isClosed();
+ return getSecurityService().isCanClosePoll(poll, accountIdRole);
}
public boolean isCanShowResult() {
String errorMessage = getSecurityService().isCanAccessResult(
- poll, SecurityService.AccountIdRole.CREATOR);
+ poll, accountIdRole);
return errorMessage == null;
}
public boolean isCanVote() {
- //FIXME-tchemit-2012-06-05 Should check that creator can vote instead
- PollType pollType = poll.getPollType();
- return pollType == PollType.FREE;
-
-// boolean result;
-// try {
-// getSecurityService().checkPollAccount(getUriId());
-// result = true;
-// } catch (PollNotFoundException e) {
-// result = false;
-// } catch (UnauthorizedPollAccessException e) {
-// result = false;
-// }
-// return result;
+ String accountId = getAccountId();
+ if (accountIdRole == SecurityService.AccountIdRole.CREATOR) {
+ accountId = null;
+ }
+ return getSecurityService().isCanVote(poll,
+ accountId,
+ accountIdRole);
}
@Override
@@ -114,6 +148,8 @@
poll = getPollService().getExistingPollByPollId(pollId);
+ accountIdRole = PollenUIUtils.getAccountIdRole(request);
+
return SUCCESS;
}
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -49,9 +49,14 @@
private static final long serialVersionUID = 1L;
@Override
+ public boolean isModerate() {
+ return false;
+ }
+
+ @Override
public void prepare() throws Exception {
- prepareVotePage(false);
+ prepareVotePage();
// Messages
if (getPoll().isClosed()) {
@@ -61,11 +66,11 @@
} else if (isPollFinished()) {
addFlashMessage(_("pollen.information.pollFinished"));
} else if (isCreatorUser()) {
- if (getUriId().isAccountIdNotBlank()) {
-
- // account Id setted in url, so should not be abel to vote
- addFlashWarning(_("pollen.information.vote.creatorUser"));
- }
+// if (getUriId().isAccountIdNotBlank()) {
+//
+// // account Id setted in url, so should not be abel to vote
+// addFlashWarning(_("pollen.information.vote.creatorUser"));
+// }
}
if (isPollChoiceRunning()) {
addFlashMessage(_("pollen.information.pollChoiceRunning"));
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorAccessRequired.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorAccessRequired.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorAccessRequired.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -27,6 +27,7 @@
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.impl.SecurityService;
+import org.chorem.pollen.ui.PollenUIUtils;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@@ -129,8 +130,7 @@
if (isAccessAllowed) {
// store accountIdRole in request
- request.setAttribute(PollVoteAccessRequired.ACCOUNT_ID_ROLE,
- accountIdRole);
+ PollenUIUtils.setAccountIdRole(request, accountIdRole);
}
return isAccessAllowed;
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -26,6 +26,7 @@
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.impl.SecurityService;
+import org.chorem.pollen.ui.PollenUIUtils;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@@ -121,8 +122,7 @@
if (isAccessAllowed) {
// store accountIdRole in request
- request.setAttribute(PollVoteAccessRequired.ACCOUNT_ID_ROLE,
- accountIdRole);
+ PollenUIUtils.setAccountIdRole(request, accountIdRole);
}
return isAccessAllowed;
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollVoteAccessRequired.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollVoteAccessRequired.java 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollVoteAccessRequired.java 2012-06-18 16:19:22 UTC (rev 3516)
@@ -26,6 +26,7 @@
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.impl.SecurityService;
+import org.chorem.pollen.ui.PollenUIUtils;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@@ -40,8 +41,6 @@
*/
public class PollVoteAccessRequired extends AbstractPollenAuthorization {
- public static final String ACCOUNT_ID_ROLE = "accountIdRole";
-
protected final AdminUserRequired adminFilter;
public PollVoteAccessRequired() {
@@ -121,7 +120,7 @@
if (isAccessAllowed) {
// store accountIdRole in request
- request.setAttribute(ACCOUNT_ID_ROLE, accountIdRole);
+ PollenUIUtils.setAccountIdRole(request, accountIdRole);
}
return isAccessAllowed;
Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-06-18 16:19:22 UTC (rev 3516)
@@ -32,6 +32,7 @@
pollen.action.importPersonListToExistingVotingList=Add selected voting list
pollen.action.importPersonListToNewVotingList=Create a new group from the selected voting list
pollen.action.login=Log me In
+pollen.action.moderatePoll=Moderate the poll
pollen.action.modify=Modify
pollen.action.pollChoiceDelete=Delete this choice
pollen.action.pollChoiceDown=Down this choice
Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
===================================================================
--- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-06-18 16:19:22 UTC (rev 3516)
@@ -32,6 +32,7 @@
pollen.action.importPersonListToExistingVotingList=Ajouter la liste sélectionnée de votants
pollen.action.importPersonListToNewVotingList=Créer un groupe à partir de la liste sélectionnée
pollen.action.login=M'identifier
+pollen.action.moderatePoll=Modérer le sondage
pollen.action.modify=Modifier
pollen.action.pollChoiceDelete=Supprimer ce choix
pollen.action.pollChoiceDown=Descendre ce choix
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-06-18 16:19:22 UTC (rev 3516)
@@ -80,17 +80,23 @@
<legend><s:text name="pollen.common.aboutPoll"/></legend>
<div style="float: right">
<s:if test="creatorUser or userAdmin">
- <s:a namespace="/poll" action="summary/%{uriId}">
+ <s:a href="%{summaryUrl}">
<img src="<s:url value='/img/editSmall.png'/>"
- title="<s:text name='pollen.action.editPoll'/>"
- alt="<s:text name='pollen.action.editPoll'/>"/>
+ title="<s:text name='pollen.action.summaryPoll'/>"
+ alt="<s:text name='pollen.action.summaryPoll'/>"/>
</s:a>
</s:if>
- <s:a namespace="/poll" action="votefor/%{uriId}">
+ <s:a href='%{voteUrl}'>
<img src="<s:url value='/img/vote.png'/>"
title="<s:text name="pollen.common.vote.return-help"/>"
alt="<s:text name="pollen.common.vote.return"/>"/>
</s:a>
+ <s:if test="feedFileExisting">
+ <s:a namespace="/poll" action="getFeed">
+ <s:param name="pollId" value="poll.pollId"/>
+ <img src="<s:url value='/img/feed.png'/>" title="Atom" alt="Atom"/>
+ </s:a>
+ </s:if>
</div>
<s:label value="%{poll.creator.votingId}"
key='pollen.common.pollCreator'/>
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-06-18 16:19:22 UTC (rev 3516)
@@ -124,14 +124,14 @@
<legend><s:text name="pollen.common.aboutPoll"/></legend>
<div style="float: right">
<s:if test="creatorUser or userAdmin">
- <s:a namespace="/poll" action="summary/%{uriId}">
+ <s:a href="%{summaryUrl}">
<img src="<s:url value='/img/editSmall.png'/>"
title="<s:text name='pollen.action.summaryPoll'/>"
alt="<s:text name='pollen.action.summaryPoll'/>"/>
</s:a>
</s:if>
- <s:if test="poll.publicResults">
- <s:a namespace="/poll" action="results/%{uriId}">
+ <s:if test="resultAllowed">
+ <s:a href="%{resultUrl}">
<img src="<s:url value='/img/count.png'/>"
title="<s:text name='pollen.common.vote.results-help'/>"
alt="<s:text name='pollen.common.vote.results'/>"/>
@@ -405,10 +405,10 @@
</tr>
</s:iterator>
</s:if>
-<s:if test="poll.continuousResults">
+<s:if test="resultAllowed">
<tr>
<td>
- <s:a namespace="/poll" action="results/%{poll.pollId}">
+ <s:a href='%{resultUrl}'>
<s:text name="pollen.common.vote.results"/>
</s:a>
</td>
Modified: trunk/pollen-ui-struts2/src/main/webapp/js/createPoll.js
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/js/createPoll.js 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/pollen-ui-struts2/src/main/webapp/js/createPoll.js 2012-06-18 16:19:22 UTC (rev 3516)
@@ -581,10 +581,6 @@
$('[name="reminderHourCountdown"]').attr('disabled', !val);
}
- function changePublicOption(val) {
- $('[name="poll.continuousResults"]').attr('disabled', !val);
- }
-
function changeAnonymousOption(val) {
$('[name="poll.anonymousVoteAllowed"]').attr('disabled', val);
}
@@ -630,9 +626,6 @@
changeChoiceAddAllowed($(this).prop('checked'));
});
- $('[name="poll.publicResults"]').change(function () {
- changePublicOption($(this).prop('checked'));
- });
$('[name="poll.anonymous"]').change(function () {
changeAnonymousOption($(this).prop('checked'));
});
@@ -667,7 +660,6 @@
changeChoiceAddAllowed(datas['choiceAddAllowed'] == 'true');
changeLimitChoice(datas['limitChoice'] == 'true');
changeReminder(datas['reminder'] == 'true');
- changePublicOption(datas['publicOption'] == 'true');
changeAnonymousOption(datas['anonymousOption'] == 'true');
changeChoiceType(datas['choiceType']);
Modified: trunk/src/site/rst/security.rst
===================================================================
--- trunk/src/site/rst/security.rst 2012-06-18 14:16:41 UTC (rev 3515)
+++ trunk/src/site/rst/security.rst 2012-06-18 16:19:22 UTC (rev 3516)
@@ -105,6 +105,7 @@
- poll:create
- poll:modify
+- poll:accesVote
- poll:vote
- poll:close
- poll:delete
1
0
r3515 - trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its
by ymartel@users.chorem.org 18 Jun '12
by ymartel@users.chorem.org 18 Jun '12
18 Jun '12
Author: ymartel
Date: 2012-06-18 16:16:41 +0200 (Mon, 18 Jun 2012)
New Revision: 3515
Url: http://chorem.org/repositories/revision/pollen/3515
Log:
refs #606 : add ITs for text poll with groups
Added:
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateTextPollForGroupSIT.java
Modified:
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java
Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java
===================================================================
--- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java 2012-06-18 12:44:50 UTC (rev 3514)
+++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java 2012-06-18 14:16:41 UTC (rev 3515)
@@ -52,8 +52,8 @@
}
/**
- * This test create a simple free text poll.
- * At the end, should be on summary page.
+ * This test create a text poll with restriction on participant but no participant.
+ * At the end, should stay on create poll page, cause at least one participant is needed.
*
* @throws Exception
*/
@@ -300,21 +300,4 @@
checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.email"), participantOneEmail);
}
- /**
- * Prepare the poll with general data : one title and two choices
- */
- void preparePoll() {
- // Go on home page
- gotoUrl(fixtures.createPollURL());
-
- // Set title
- sendKeysByName("poll.title", "My Poll");
-
- // Set first choice
- sendKeysByName("textChoice_0.name", "Choix numero un");
-
- // Set second choice
- sendKeysByName("textChoice_1.name", "Choix numero deux");
- }
-
}
Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateTextPollForGroupSIT.java
===================================================================
--- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateTextPollForGroupSIT.java (rev 0)
+++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateTextPollForGroupSIT.java 2012-06-18 14:16:41 UTC (rev 3515)
@@ -0,0 +1,487 @@
+/*
+ * #%L
+ * Pollen :: UI (struts2)
+ * $Id: CreateFreeTextPollSIT.java 3507 2012-06-18 09:45:47Z ymartel $
+ * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-ui-struts2/src/test/java/org/… $
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.its;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+
+import java.util.List;
+
+/**
+ * Test the well work of a text poll creation page with the use of groups.
+ * <p/>
+ * Tested cases :
+ * <ul>
+ * <li>Creation with a nonamed group (KO)</li>
+ * <li>Creation with two group with same name (KO)</li>
+ * <li>Creation with a participant without email (KO)</li>
+ * <li>Creation with a participant with only an email (no name) (KO)</li>
+ * <li>Creation with two participants with same name in same group (KO)</li>
+ * <li>Creation with two participants with same email (KO)</li>
+ * <li>Creation with two participants with same name in different group (KO)</li>
+ * <li>Creation with two participants with same email in different group (KO)</li>
+ * </ul>
+ *
+ * @author ymartel <martel(a)codelutin.com>
+ * @since 1.4
+ */
+public class CreateTextPollForGroupSIT extends PollenBaseWebDriverIT {
+
+ public CreateTextPollForGroupSIT(Class<? extends WebDriver> driverType) {
+ super(driverType);
+ }
+
+ /**
+ * This test create a text poll with group of participant but with no name on group.
+ * At the end, should stay on create page cause the group name is mandatory
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createTextPollWithNoNamedGroup() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel and display group form
+ goToGroupForm();
+
+ // Check that the group form is displayed
+ WebElement groupNameElement = findElement(By.id("votingListGROUP_0.name"));
+ Assert.assertEquals("input", groupNameElement.getTagName());
+ Assert.assertTrue(groupNameElement.isDisplayed());
+
+ // Set a participant in the group
+ // send name
+ String participantOneName = "toto";
+ sendKeysById("votingListGROUP_0PersonToList_0.votingId", participantOneName);
+ // send email
+ String participantOneEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListGROUP_0PersonToList_0.email", participantOneEmail);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table, and group form is still displayed
+ groupNameElement = findElement(By.id("votingListGROUP_0.name"));
+ Assert.assertEquals("input", groupNameElement.getTagName());
+ Assert.assertTrue(groupNameElement.isDisplayed());
+ // check the participant is still here
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.votingId"), participantOneName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.email"), participantOneEmail);
+ }
+
+ /**
+ * This test create a group text poll, with two groups with same name.
+ * At the end, should stay on create poll page, cause the group name should be unique.
+ * The group names and participants should not be lost.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createGroupTextPollWithGroupsWithSameName() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel and display group form
+ goToGroupForm();
+
+ // Set First group name
+ String groupOneName = "my group";
+ sendKeysById("votingListGROUP_0.name", groupOneName);
+ // Set first participant in Group 1
+ // send name
+ String participantOneName = "toto";
+ sendKeysById("votingListGROUP_0PersonToList_0.votingId", participantOneName);
+ // send email
+ String participantOneEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListGROUP_0PersonToList_0.email", participantOneEmail);
+
+ // Add a group
+ WebElement addGroupElement = findElement(By.name("pollen.action.addVotingList"));
+ Assert.assertEquals("input", addGroupElement.getTagName());
+ Assert.assertTrue(addGroupElement.isDisplayed());
+ addGroupElement.click();
+
+ // Set name of the second group: same as first one
+ sendKeysById("votingListGROUP_1.name", groupOneName);
+ // Set second participant in second group
+ // send name
+ String participantTwoName = "toto2";
+ sendKeysById("votingListGROUP_1PersonToList_0.votingId", participantTwoName);
+ // send email
+ String participantTwoEmail = "toto2(a)codelutin.com";
+ sendKeysById("votingListGROUP_1PersonToList_0.email", participantTwoEmail);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ checkWebElementValue(By.id("votingListGROUP_0.name"), groupOneName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.votingId"), participantOneName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.email"), participantOneEmail);
+ checkWebElementValue(By.id("votingListGROUP_1.name"), groupOneName);
+ checkWebElementValue(By.id("votingListGROUP_1PersonToList_0.votingId"), participantTwoName);
+ checkWebElementValue(By.id("votingListGROUP_1PersonToList_0.email"), participantTwoEmail);
+ }
+
+ /**
+ * This test create a group text poll, with one participant without email.
+ * At the end, should stay on create poll page, cause the mail is mandatory.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createGroupTextPollWithParticipantWithoutMail() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel and display group form
+ goToGroupForm();
+
+ // Set group name
+ String groupName = "my group";
+ sendKeysById("votingListGROUP_0.name", groupName);
+
+ // Set first participant
+ // send name
+ String participantName = "toto";
+ sendKeysById("votingListGROUP_0PersonToList_0.votingId", participantName);
+ // send an empty email
+ sendKeysById("votingListGROUP_0PersonToList_0.email", "");
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ checkWebElementValue(By.id("votingListGROUP_0.name"), groupName); // group name still here
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.votingId"), participantName); // participant name still here
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.email"), ""); // still no email
+ }
+
+ /**
+ * This test create a group text poll, with one participant without name.
+ * At the end, should stay on create poll page, cause the mail is mandatory.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createGroupTextPollWithParticipantWithoutName() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+ // Go to option panel and display group form
+ goToGroupForm();
+
+
+ // Set group name
+ String groupName = "my group";
+ sendKeysById("votingListGROUP_0.name", groupName);
+
+ // Set a participant
+ // send name
+ sendKeysById("votingListGROUP_0PersonToList_0.votingId", "");
+ // send an empty email
+ String participantEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListGROUP_0PersonToList_0.email", participantEmail);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ checkWebElementValue(By.id("votingListGROUP_0.name"), groupName); // group name still here
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.votingId"), ""); // participant name still empty
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.email"), participantEmail); // still the mail
+ }
+
+ /**
+ * This test create a group text poll, with two participants with same email in same group.
+ * At the end, should stay on create poll page, cause the email should be unique.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createTextPollWithSameGroupParticipantsWithSameEmail() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel and display group form
+ goToGroupForm();
+
+ // Set group name
+ String groupName = "my group";
+ sendKeysById("votingListGROUP_0.name", groupName);
+ // Set first participant in Group
+ // send name
+ String participantOneName = "toto";
+ sendKeysById("votingListGROUP_0PersonToList_0.votingId", participantOneName);
+ // send email
+ String participantEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListGROUP_0PersonToList_0.email", participantEmail);
+
+ // Set second participant in Group with same email
+ // send name
+ String participantTwoName = "toto2";
+ sendKeysById("votingListGROUP_0PersonToList_1.votingId", participantTwoName);
+ // send email
+ sendKeysById("votingListGROUP_0PersonToList_1.email", participantEmail);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ checkWebElementValue(By.id("votingListGROUP_0.name"), groupName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.votingId"), participantOneName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.email"), participantEmail);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_1.votingId"), participantTwoName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_1.email"), participantEmail);
+ }
+
+ /**
+ * This test create a group text poll, with two participants on different group with same email.
+ * At the end, should stay on create poll page, cause the participant names should be unique.
+ * The group names and participants should not be lost.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createGroupTextPollWithParticipantsWithSameEmail() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel and display group form
+ goToGroupForm();
+
+ // Set First group name
+ String groupOneName = "my group";
+ sendKeysById("votingListGROUP_0.name", groupOneName);
+ // Set first participant in Group 1
+ // send name
+ String participantOneName = "toto";
+ sendKeysById("votingListGROUP_0PersonToList_0.votingId", participantOneName);
+ // send email
+ String participantEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListGROUP_0PersonToList_0.email", participantEmail);
+
+ // Add a group
+ WebElement addGroupElement = findElement(By.name("pollen.action.addVotingList"));
+ Assert.assertEquals("input", addGroupElement.getTagName());
+ Assert.assertTrue(addGroupElement.isDisplayed());
+ addGroupElement.click();
+
+ // Set name of the second group
+ String groupTwoName = "my other group";
+ sendKeysById("votingListGROUP_1.name", groupTwoName);
+ // Set second participant in second group
+ // send name
+ String participantTwoName = "toto2";
+ sendKeysById("votingListGROUP_1PersonToList_0.votingId", participantTwoName);
+ // send email
+ sendKeysById("votingListGROUP_1PersonToList_0.email", participantEmail);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ checkWebElementValue(By.id("votingListGROUP_0.name"), groupOneName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.votingId"), participantOneName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.email"), participantEmail);
+ checkWebElementValue(By.id("votingListGROUP_1.name"), groupTwoName);
+ checkWebElementValue(By.id("votingListGROUP_1PersonToList_0.votingId"), participantTwoName);
+ checkWebElementValue(By.id("votingListGROUP_1PersonToList_0.email"), participantEmail);
+ }
+
+ /**
+ * This test create a group text poll, with two participant with same name in a group.
+ * At the end, should stay on create poll page, cause the email should be unique.
+ * The group name and participant info must be not lost
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createTextPollWithSameGroupParticipantsWithSameName() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel and display option panel
+ goToGroupForm();
+
+ // Set group name
+ String groupName = "my group";
+ sendKeysById("votingListGROUP_0.name", groupName);
+ // Set first participant in Group
+ // send name
+ String participantName = "toto";
+ sendKeysById("votingListGROUP_0PersonToList_0.votingId", participantName);
+ // send email
+ String participantOneEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListGROUP_0PersonToList_0.email", participantOneEmail);
+
+ // Set second participant in Group with same email
+ // send name
+ sendKeysById("votingListGROUP_0PersonToList_1.votingId", participantName);
+ // send email
+ String participantTwoEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListGROUP_0PersonToList_1.email", participantTwoEmail);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ checkWebElementValue(By.id("votingListGROUP_0.name"), groupName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.votingId"), participantName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.email"), participantOneEmail);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_1.votingId"), participantName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_1.email"), participantTwoEmail);
+ }
+
+ /**
+ * This test create a group text poll, with two participants of different group with same name.
+ * At the end, should stay on create poll page, cause the participant name should be unique.
+ * The group names and participants should not be lost.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createGroupTextPollWithParticipantsWithSameName() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel and group form
+ goToGroupForm();
+
+ // Set First group name
+ String groupOneName = "my group";
+ sendKeysById("votingListGROUP_0.name", groupOneName);
+ // Set first participant in Group 1
+ // send name
+ String participantName = "toto";
+ sendKeysById("votingListGROUP_0PersonToList_0.votingId", participantName);
+ // send email
+ String participantOneEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListGROUP_0PersonToList_0.email", participantOneEmail);
+
+ // Add a group
+ WebElement addGroupElement = findElement(By.name("pollen.action.addVotingList"));
+ Assert.assertEquals("input", addGroupElement.getTagName());
+ Assert.assertTrue(addGroupElement.isDisplayed());
+ addGroupElement.click();
+
+ // Set name of the second group
+ String groupTwoName = "my other group";
+ sendKeysById("votingListGROUP_1.name", groupTwoName);
+ // Set second participant in second group
+ // send name
+ sendKeysById("votingListGROUP_1PersonToList_0.votingId", participantName);
+ // send email
+ String participantTwoEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListGROUP_1PersonToList_0.email", participantTwoEmail);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ checkWebElementValue(By.id("votingListGROUP_0.name"), groupOneName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.votingId"), participantName);
+ checkWebElementValue(By.id("votingListGROUP_0PersonToList_0.email"), participantOneEmail);
+ checkWebElementValue(By.id("votingListGROUP_1.name"), groupTwoName);
+ checkWebElementValue(By.id("votingListGROUP_1PersonToList_0.votingId"), participantName);
+ checkWebElementValue(By.id("votingListGROUP_1PersonToList_0.email"), participantTwoEmail);
+ }
+
+ /**
+ * Click on option panel, and select Group type to restrict the poll participation
+ */
+ void goToGroupForm() {
+ // Go to option panel : click on it
+ WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]"));
+ optionsClick.click();
+
+ // Switch to group type
+ List<WebElement> pollTypesElement = findElements(By.name("poll.pollType"));
+ Assert.assertEquals(3, pollTypesElement.size());
+ WebElement restrictedTypeElement = pollTypesElement.get(2);
+ Assert.assertEquals("input", restrictedTypeElement.getTagName());
+ Assert.assertEquals("GROUP", restrictedTypeElement.getAttribute("value"));
+ Assert.assertTrue(restrictedTypeElement.isDisplayed());
+ restrictedTypeElement.click();
+ }
+
+}
Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java
===================================================================
--- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java 2012-06-18 12:44:50 UTC (rev 3514)
+++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java 2012-06-18 14:16:41 UTC (rev 3515)
@@ -161,6 +161,23 @@
}
/**
+ * Prepare the poll with general data : one title and two choices
+ */
+ void preparePoll() {
+ // Go on home page
+ gotoUrl(fixtures.createPollURL());
+
+ // Set title
+ sendKeysByName("poll.title", "My Poll");
+
+ // Set first choice
+ sendKeysByName("textChoice_0.name", "Choix numero un");
+
+ // Set second choice
+ sendKeysByName("textChoice_1.name", "Choix numero deux");
+ }
+
+ /**
* Set a value for a WebElement.
* This operations does 3 steps :
* <ul>
@@ -240,7 +257,7 @@
if (safeDrivers == null) {
List<Class<? extends WebDriver>> allDrivers = Lists.newArrayList();
-// allDrivers.add(HtmlUnitDriver.class);
+ allDrivers.add(HtmlUnitDriver.class);
allDrivers.add(FirefoxDriver.class);
// allDrivers.add(ChromeDriver.class);
// allDrivers.add(InternetExplorerDriver.class);
1
0
r3514 - in trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui: . its
by ymartel@users.chorem.org 18 Jun '12
by ymartel@users.chorem.org 18 Jun '12
18 Jun '12
Author: ymartel
Date: 2012-06-18 14:44:50 +0200 (Mon, 18 Jun 2012)
New Revision: 3514
Url: http://chorem.org/repositories/revision/pollen/3514
Log:
refs #606 : add ITs for text restricted poll
Added:
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java
Modified:
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java
Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java
===================================================================
--- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java 2012-06-18 11:38:22 UTC (rev 3513)
+++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java 2012-06-18 12:44:50 UTC (rev 3514)
@@ -162,4 +162,5 @@
public String date(int year, int month, int day) {
return date(year, month, day, 0, 0);
}
+
}
Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java
===================================================================
--- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java (rev 0)
+++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java 2012-06-18 12:44:50 UTC (rev 3514)
@@ -0,0 +1,320 @@
+/*
+ * #%L
+ * Pollen :: UI (struts2)
+ * $Id: CreateFreeTextPollSIT.java 3507 2012-06-18 09:45:47Z ymartel $
+ * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-ui-struts2/src/test/java/org/… $
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.its;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+
+import java.util.List;
+
+/**
+ * Test the well work of a text poll creation page with a restricted list of participant.
+ * <p/>
+ * Tested cases :
+ * <ul>
+ * <li>Creation without participant (KO)</li>
+ * <li>Creation with two participants with same name (KO)</li>
+ * <li>Creation with two participants with same email (KO)</li>
+ * <li>Creation with a participant without email (KO)</li>
+ * <li>Creation with a participant with only an email (no name) (KO)</li>
+ * </ul>
+ *
+ * @author ymartel <martel(a)codelutin.com>
+ * @since 1.4
+ */
+public class CreateRestrictedTextPollSIT extends PollenBaseWebDriverIT {
+
+ public CreateRestrictedTextPollSIT(Class<? extends WebDriver> driverType) {
+ super(driverType);
+ }
+
+ /**
+ * This test create a simple free text poll.
+ * At the end, should be on summary page.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createRestrictedTextPollWithoutParticipant() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel : click on it
+ WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]"));
+ optionsClick.click();
+
+ // Switch to restricted type
+ List<WebElement> pollTypesElement = findElements(By.name("poll.pollType"));
+ Assert.assertEquals(3, pollTypesElement.size());
+ WebElement restrictedTypeElement = pollTypesElement.get(1);
+ Assert.assertEquals("input", restrictedTypeElement.getTagName());
+ Assert.assertEquals("RESTRICTED", restrictedTypeElement.getAttribute("value"));
+ Assert.assertTrue(restrictedTypeElement.isDisplayed());
+ restrictedTypeElement.click();
+
+ // Check that the participant form is displayed
+ WebElement participantOneNameElement = findElement(By.id("votingListRESTRICTED_0PersonToList_0.votingId"));
+ Assert.assertEquals("input", participantOneNameElement.getTagName());
+ Assert.assertTrue(participantOneNameElement.isDisplayed());
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ participantOneNameElement = findElement(By.id("votingListRESTRICTED_0PersonToList_0.votingId"));
+ Assert.assertEquals("input", participantOneNameElement.getTagName());
+ Assert.assertTrue(participantOneNameElement.isDisplayed());
+ }
+
+ /**
+ * This test create a restricted text poll, with two participant with same name.
+ * At the end, should stay on create poll page, cause the name should be unique.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createRestrictedTextPollWithParticipantsWithSameName() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel : click on it
+ WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]"));
+ optionsClick.click();
+
+ // Switch to restricted type
+ List<WebElement> pollTypesElement = findElements(By.name("poll.pollType"));
+ Assert.assertEquals(3, pollTypesElement.size());
+ WebElement restrictedTypeElement = pollTypesElement.get(1);
+ Assert.assertEquals("input", restrictedTypeElement.getTagName());
+ Assert.assertEquals("RESTRICTED", restrictedTypeElement.getAttribute("value"));
+ Assert.assertTrue(restrictedTypeElement.isDisplayed());
+ restrictedTypeElement.click();
+
+ // Set first participant
+ // send name
+ String participantOneName = "toto";
+ sendKeysById("votingListRESTRICTED_0PersonToList_0.votingId", participantOneName);
+ // send email
+ String participantOneEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListRESTRICTED_0PersonToList_0.email", participantOneEmail);
+ // Set second participant
+ // send name
+ sendKeysById("votingListRESTRICTED_0PersonToList_1.votingId", participantOneName);
+ // send email
+ String participantTwoEmail = "toto2(a)codelutin.com";
+ sendKeysById("votingListRESTRICTED_0PersonToList_1.email", participantTwoEmail);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.votingId"), participantOneName);
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.email"), participantOneEmail);
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_1.votingId"), participantOneName);
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_1.email"), participantTwoEmail);
+ }
+
+ /**
+ * This test create a restricted text poll, with two participant with same email.
+ * At the end, should stay on create poll page, cause the email should be unique.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createRestrictedTextPollWithParticipantsWithSameEmail() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel : click on it
+ WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]"));
+ optionsClick.click();
+
+ // Switch to restricted type
+ List<WebElement> pollTypesElement = findElements(By.name("poll.pollType"));
+ Assert.assertEquals(3, pollTypesElement.size());
+ WebElement restrictedTypeElement = pollTypesElement.get(1);
+ Assert.assertEquals("input", restrictedTypeElement.getTagName());
+ Assert.assertEquals("RESTRICTED", restrictedTypeElement.getAttribute("value"));
+ Assert.assertTrue(restrictedTypeElement.isDisplayed());
+ restrictedTypeElement.click();
+
+ // Set first participant
+ // send name
+ String participantOneName = "toto";
+ sendKeysById("votingListRESTRICTED_0PersonToList_0.votingId", participantOneName);
+ // send email
+ String participantOneEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListRESTRICTED_0PersonToList_0.email", participantOneEmail);
+ // Set second participant
+ // send name
+ String participantTwoName = "toto2";
+ sendKeysById("votingListRESTRICTED_0PersonToList_1.votingId", participantTwoName);
+ // send email
+ sendKeysById("votingListRESTRICTED_0PersonToList_1.email", participantOneEmail);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.votingId"), participantOneName);
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.email"), participantOneEmail);
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_1.votingId"), participantTwoName);
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_1.email"), participantOneEmail);
+ }
+
+ /**
+ * This test create a restricted text poll, with one participant without email.
+ * At the end, should stay on create poll page, cause the mail is mandatory.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createRestrictedTextPollWithParticipantWithoutMail() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel : click on it
+ WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]"));
+ optionsClick.click();
+
+ // Switch to restricted type
+ List<WebElement> pollTypesElement = findElements(By.name("poll.pollType"));
+ Assert.assertEquals(3, pollTypesElement.size());
+ WebElement restrictedTypeElement = pollTypesElement.get(1);
+ Assert.assertEquals("input", restrictedTypeElement.getTagName());
+ Assert.assertEquals("RESTRICTED", restrictedTypeElement.getAttribute("value"));
+ Assert.assertTrue(restrictedTypeElement.isDisplayed());
+ restrictedTypeElement.click();
+
+ // Set first participant
+ // send name
+ String participantOneName = "toto";
+ sendKeysById("votingListRESTRICTED_0PersonToList_0.votingId", participantOneName);
+ // send email
+ String participantOneEmail = " ";
+ sendKeysById("votingListRESTRICTED_0PersonToList_0.email", participantOneEmail);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.votingId"), participantOneName);
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.email"), participantOneEmail);
+ }
+
+ /**
+ * This test create a restricted text poll, with one participant without email.
+ * At the end, should stay on create poll page, cause the mail is mandatory.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createRestrictedTextPollWithParticipantWithoutName() throws Exception {
+
+ // Prepare the poll
+ preparePoll();
+
+ // Go to option panel : click on it
+ WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]"));
+ optionsClick.click();
+
+ // Switch to restricted type
+ List<WebElement> pollTypesElement = findElements(By.name("poll.pollType"));
+ Assert.assertEquals(3, pollTypesElement.size());
+ WebElement restrictedTypeElement = pollTypesElement.get(1);
+ Assert.assertEquals("input", restrictedTypeElement.getTagName());
+ Assert.assertEquals("RESTRICTED", restrictedTypeElement.getAttribute("value"));
+ Assert.assertTrue(restrictedTypeElement.isDisplayed());
+ restrictedTypeElement.click();
+
+ // Set first participant
+ // send name
+ String participantOneName = "";
+ sendKeysById("votingListRESTRICTED_0PersonToList_0.votingId", participantOneName);
+ // send email
+ String participantOneEmail = "toto(a)codelutin.com";
+ sendKeysById("votingListRESTRICTED_0PersonToList_0.email", participantOneEmail);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ WebElement errorMessage = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(errorMessage);
+ // Check we are in good table
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.votingId"), participantOneName);
+ checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.email"), participantOneEmail);
+ }
+
+ /**
+ * Prepare the poll with general data : one title and two choices
+ */
+ void preparePoll() {
+ // Go on home page
+ gotoUrl(fixtures.createPollURL());
+
+ // Set title
+ sendKeysByName("poll.title", "My Poll");
+
+ // Set first choice
+ sendKeysByName("textChoice_0.name", "Choix numero un");
+
+ // Set second choice
+ sendKeysByName("textChoice_1.name", "Choix numero deux");
+ }
+
+}
Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java
===================================================================
--- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java 2012-06-18 11:38:22 UTC (rev 3513)
+++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java 2012-06-18 12:44:50 UTC (rev 3514)
@@ -161,6 +161,67 @@
}
/**
+ * Set a value for a WebElement.
+ * This operations does 3 steps :
+ * <ul>
+ * <li>Get the WebElement thanks to its id (given in parameter)</li>
+ * <li>check the element is an input</li>
+ * <li>check the element is displayed</li>
+ * <li>clear the element</li>
+ * <li>send the wanted keys</li>
+ * </ul>
+ */
+ protected void sendKeysById(String webElementId, String value) {
+ sendKeysBy(By.id(webElementId), value);
+ }
+
+ /**
+ * Set a value for a WebElement.
+ * This operations does 3 steps :
+ * <ul>
+ * <li>Get the WebElement thanks to its name (given in parameter)</li>
+ * <li>check the element is an input</li>
+ * <li>check the element is displayed</li>
+ * <li>clear the element</li>
+ * <li>send the wanted keys</li>
+ * </ul>
+ */
+ protected void sendKeysByName(String webElementName, String value) {
+ By byName = By.name(webElementName);
+ sendKeysBy(byName, value);
+ }
+
+ /**
+ * Set a value for a WebElement.
+ * This operations does 3 steps :
+ * <ul>
+ * <li>Get the WebElement thanks to a {@link By} locator</li>
+ * <li>check the element is an input</li>
+ * <li>check the element is displayed</li>
+ * <li>clear the element</li>
+ * <li>send the wanted keys</li>
+ * </ul>
+ */
+ protected void sendKeysBy(By by, String value) {
+ WebElement webElement = findElement(by);
+ Assert.assertEquals("input", webElement.getTagName());
+ Assert.assertTrue(webElement.isDisplayed());
+ webElement.sendKeys(value);
+ Assert.assertEquals(value, webElement.getAttribute("value"));
+ }
+
+ /**
+ * Get a WebElement with a {@link By} locator, and check it is an input and that is value is the one expected.
+ *
+ */
+ protected void checkWebElementValue(By by, String expectedValue) {
+ WebElement webElement = findElement(by);
+ Assert.assertEquals("input", webElement.getTagName());
+ Assert.assertTrue(webElement.isDisplayed());
+ Assert.assertEquals(expectedValue, webElement.getAttribute("value"));
+ }
+
+ /**
* Web driver resource.
*
* @author tchemit <chemit(a)codelutin.com>
@@ -179,7 +240,7 @@
if (safeDrivers == null) {
List<Class<? extends WebDriver>> allDrivers = Lists.newArrayList();
- allDrivers.add(HtmlUnitDriver.class);
+// allDrivers.add(HtmlUnitDriver.class);
allDrivers.add(FirefoxDriver.class);
// allDrivers.add(ChromeDriver.class);
// allDrivers.add(InternetExplorerDriver.class);
1
0
r3513 - in trunk: pollen-services/src/main/java/org/chorem/pollen/bean pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-ui-struts2/src/main/resources/i18n
by tchemit@users.chorem.org 18 Jun '12
by tchemit@users.chorem.org 18 Jun '12
18 Jun '12
Author: tchemit
Date: 2012-06-18 13:38:22 +0200 (Mon, 18 Jun 2012)
New Revision: 3513
Url: http://chorem.org/repositories/revision/pollen/3513
Log:
- remove the suffixUrl stuff
- can now change image choice
- i18n
Modified:
trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollUrl.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollUrlService.java
trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollUrl.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollUrl.java 2012-06-18 10:42:01 UTC (rev 3512)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollUrl.java 2012-06-18 11:38:22 UTC (rev 3513)
@@ -22,8 +22,6 @@
*/
package org.chorem.pollen.bean;
-import org.apache.commons.lang3.StringUtils;
-
/**
* Created: 12/04/12
*
@@ -33,8 +31,6 @@
private String baseUrl;
- private String suffixUrl;
-
private PollUri pollUri;
/**
@@ -65,7 +61,6 @@
result.baseUrl = pollUrl.getBaseUrl();
String pollId = pollUrl.getPollUri().getPollId();
result.pollUri = PollUri.newPollUri(pollId, accountId);
- result.suffixUrl = pollUrl.suffixUrl;
return result;
}
@@ -80,19 +75,8 @@
return pollUri;
}
- public String getSuffixUrl() {
- return suffixUrl;
- }
-
- public void setSuffixUrl(String suffixUrl) {
- this.suffixUrl = suffixUrl;
- }
-
public String getUrl() {
String result = getBaseUrl() + getPollUri().getUri();
- if (StringUtils.isNotBlank(suffixUrl)) {
- result += suffixUrl;
- }
return result;
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-06-18 10:42:01 UTC (rev 3512)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-06-18 11:38:22 UTC (rev 3513)
@@ -28,6 +28,7 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.logging.Log;
@@ -73,7 +74,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.UUID;
import static org.nuiton.i18n.I18n.l_;
@@ -793,7 +793,10 @@
ChoiceType choiceType = poll.getChoiceType();
ChoiceDAO dao = getDAO(Choice.class);
Choice choiceLoaded;
- if (choice.getTopiaId() == null) {
+
+ boolean newChoice = choice.getTopiaId() == null;
+
+ if (newChoice) {
choiceLoaded = create(dao);
poll.addChoice(choiceLoaded);
@@ -803,18 +806,20 @@
if (choiceType == ChoiceType.IMAGE) {
-
PollImageChoice imageChoice = (PollImageChoice) choice;
- imageChoice.toChoice(choiceLoaded);
- if (choice.getTopiaId() == null) {
+ if (newChoice ||
+ !ObjectUtils.equals(choice.getName(),
+ choiceLoaded.getName())) {
// copy image where it belong and generate the thumb
- // only if choice is to create
+ // only if choice is to create or name has change (so image too...)
try {
saveImages(poll, imageChoice);
} catch (IOException e) {
throw new PollenTechnicalException(
"Could not create image choice", e);
}
+ // bind other fields
+ imageChoice.toChoice(choiceLoaded);
}
} else if (choiceType == ChoiceType.DATE) {
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollUrlService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollUrlService.java 2012-06-18 10:42:01 UTC (rev 3512)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollUrlService.java 2012-06-18 11:38:22 UTC (rev 3513)
@@ -45,7 +45,6 @@
public PollUrl getPollCloneUrl(Poll poll) {
PollUrl result = newPollUrl(PollActions.CLONE, poll, true);
- result.setSuffixUrl("!input");
return result;
}
@@ -71,7 +70,6 @@
public PollUrl getPollEditUrl(Poll poll) {
PollUrl result = newPollUrl(PollActions.EDIT, poll, true);
- result.setSuffixUrl("!input");
return result;
}
Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-06-18 10:42:01 UTC (rev 3512)
+++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-06-18 11:38:22 UTC (rev 3513)
@@ -327,13 +327,13 @@
pollen.tab.poll.options=Options
pollen.title.clone.poll=Clone a poll
pollen.title.close.poll=Close a poll
-pollen.title.editPoll=Edit a poll
pollen.title.createPoll=New poll
pollen.title.delete.poll=Delete a poll
pollen.title.delete.pollChoice=Delete a poll choice
pollen.title.delete.pollComment=Delete a poll comment
pollen.title.delete.pollVote=Delete a poll vote
pollen.title.editFavoriteList=Edit a favorite list
+pollen.title.editPoll=Edit a poll
pollen.title.favoriteLists=Your favorite lists
pollen.title.myAccount=My account
pollen.title.pollsCreatedList=Polls created
Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
===================================================================
--- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-06-18 10:42:01 UTC (rev 3512)
+++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-06-18 11:38:22 UTC (rev 3513)
@@ -327,13 +327,13 @@
pollen.tab.poll.options=Options
pollen.title.clone.poll=Clonage d'un sondage
pollen.title.close.poll=Fermeture d'un sondage
-pollen.title.editPoll=Modifier un sondage
pollen.title.createPoll=Nouveau sondage
pollen.title.delete.poll=Suppression d'un sondage
pollen.title.delete.pollChoice=Suppression d'un choix
pollen.title.delete.pollComment=Suppression d'un commentaire
pollen.title.delete.pollVote=Suppression d'un vote
pollen.title.editFavoriteList=Edition de la liste des favoris
+pollen.title.editPoll=Modifier un sondage
pollen.title.favoriteLists=Vos listes de votants
pollen.title.myAccount=Mon compte
pollen.title.pollsCreatedList=Sondages créés
1
0
r3512 - in trunk/pollen-ui-struts2/src/main: resources/i18n webapp/WEB-INF/jsp/poll
by tchemit@users.chorem.org 18 Jun '12
by tchemit@users.chorem.org 18 Jun '12
18 Jun '12
Author: tchemit
Date: 2012-06-18 12:42:01 +0200 (Mon, 18 Jun 2012)
New Revision: 3512
Url: http://chorem.org/repositories/revision/pollen/3512
Log:
change page name when edit a poll + improve a javascript
Modified:
trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-06-18 10:35:27 UTC (rev 3511)
+++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-06-18 10:42:01 UTC (rev 3512)
@@ -327,6 +327,7 @@
pollen.tab.poll.options=Options
pollen.title.clone.poll=Clone a poll
pollen.title.close.poll=Close a poll
+pollen.title.editPoll=Edit a poll
pollen.title.createPoll=New poll
pollen.title.delete.poll=Delete a poll
pollen.title.delete.pollChoice=Delete a poll choice
Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
===================================================================
--- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-06-18 10:35:27 UTC (rev 3511)
+++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-06-18 10:42:01 UTC (rev 3512)
@@ -327,6 +327,7 @@
pollen.tab.poll.options=Options
pollen.title.clone.poll=Clonage d'un sondage
pollen.title.close.poll=Fermeture d'un sondage
+pollen.title.editPoll=Modifier un sondage
pollen.title.createPoll=Nouveau sondage
pollen.title.delete.poll=Suppression d'un sondage
pollen.title.delete.pollChoice=Suppression d'un choix
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-06-18 10:35:27 UTC (rev 3511)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-06-18 10:42:01 UTC (rev 3512)
@@ -58,10 +58,8 @@
choiceType:'<s:property value="%{poll.choiceType.name()}"/>',
pollType:'<s:property value="%{poll.pollType.name()}"/>',
confirmCloseTitle:"<s:text name='pollen.title.close.poll'/>",
- confirmCloseUrl:'<s:url action="confirmClosePoll/" namespace="/poll"/>'
- + '<s:property value="%{poll.adminId}"/>',
- confirmCloseRedirectUrl:'<s:url action="summary/" namespace="/poll"/>'
- + '<s:property value="%{poll.adminId}"/>'
+ confirmCloseUrl:'<s:url action="confirmClosePoll/%{poll.adminId}" namespace="/poll"/>',
+ confirmCloseRedirectUrl:'<s:url action="summary/%{poll.adminId}" namespace="/poll"/>'
}
);
</script>
@@ -73,7 +71,14 @@
<s:url id='errorImg' value='/img/exclamation.png'/>
-<title><s:text name="pollen.title.createPoll"/></title>
+<title>
+ <s:if test="edit">
+ <s:text name="pollen.title.editPoll"/>
+ </s:if>
+ <s:else>
+ <s:text name="pollen.title.createPoll"/>
+ </s:else>
+</title>
<h1 class="title${pageLogo}"><s:property value="%{pageTitle}"/></h1>
1
0
r3511 - trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security
by tchemit@users.chorem.org 18 Jun '12
by tchemit@users.chorem.org 18 Jun '12
18 Jun '12
Author: tchemit
Date: 2012-06-18 12:35:27 +0200 (Mon, 18 Jun 2012)
New Revision: 3511
Url: http://chorem.org/repositories/revision/pollen/3511
Log:
propagate the AccountIdRole obtained by security filters
Modified:
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorAccessRequired.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorAccessRequired.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorAccessRequired.java 2012-06-18 10:34:48 UTC (rev 3510)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorAccessRequired.java 2012-06-18 10:35:27 UTC (rev 3511)
@@ -126,6 +126,13 @@
}
}
+ if (isAccessAllowed) {
+
+ // store accountIdRole in request
+ request.setAttribute(PollVoteAccessRequired.ACCOUNT_ID_ROLE,
+ accountIdRole);
+ }
+
return isAccessAllowed;
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java 2012-06-18 10:34:48 UTC (rev 3510)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollResultAccessRequired.java 2012-06-18 10:35:27 UTC (rev 3511)
@@ -117,6 +117,13 @@
registerError(request, errorMessage);
}
}
+
+ if (isAccessAllowed) {
+
+ // store accountIdRole in request
+ request.setAttribute(PollVoteAccessRequired.ACCOUNT_ID_ROLE,
+ accountIdRole);
+ }
return isAccessAllowed;
}
1
0
r3510 - trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll
by tchemit@users.chorem.org 18 Jun '12
by tchemit@users.chorem.org 18 Jun '12
18 Jun '12
Author: tchemit
Date: 2012-06-18 12:34:48 +0200 (Mon, 18 Jun 2012)
New Revision: 3510
Url: http://chorem.org/repositories/revision/pollen/3510
Log:
remove double test
Modified:
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-06-18 10:01:58 UTC (rev 3509)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-06-18 10:34:48 UTC (rev 3510)
@@ -335,25 +335,23 @@
?
</s:else>
</s:if>
- <s:if test="!poll.anonymous">
- <s:if test="isModifyVoteAllowed(#vote)">
- <s:a action="editVote" namespace="/poll">
- <s:param name="pollId" value="%{pollId}"/>
- <s:param name="accountId" value="%{#vote.pollAccount.accountId}"/>
- <img src="<s:url value="/img/editSmall.png"/>"
- title="<s:text name="pollen.action.editVote"/>"
- alt="<s:text name="pollen.action.editVote"/>"/>
- </s:a>
- </s:if>
- <s:if test="isDeleteVoteAllowed(#vote)">
- <s:a action="deleteVote" namespace="/poll" href="#"
- onclick="return openDeleteVoteDialog('%{#vote.topiaId}');">
- <img src="<s:url value="/img/delete.png"/>"
- title="<s:text name="pollen.action.deleteVote"/>"
- alt="<s:text name="pollen.action.deleteVote"/>"/>
- </s:a>
- </s:if>
+ <s:if test="isModifyVoteAllowed(#vote)">
+ <s:a action="editVote" namespace="/poll">
+ <s:param name="pollId" value="%{pollId}"/>
+ <s:param name="accountId" value="%{#vote.pollAccount.accountId}"/>
+ <img src="<s:url value="/img/editSmall.png"/>"
+ title="<s:text name="pollen.action.editVote"/>"
+ alt="<s:text name="pollen.action.editVote"/>"/>
+ </s:a>
</s:if>
+ <s:if test="isDeleteVoteAllowed(#vote)">
+ <s:a action="deleteVote" namespace="/poll" href="#"
+ onclick="return openDeleteVoteDialog('%{#vote.topiaId}');">
+ <img src="<s:url value="/img/delete.png"/>"
+ title="<s:text name="pollen.action.deleteVote"/>"
+ alt="<s:text name="pollen.action.deleteVote"/>"/>
+ </s:a>
+ </s:if>
</td>
<s:iterator value="poll.choice" var="choice">
<s:if test="!isChoiceHidden(#choice)">
1
0
r3509 - in trunk: pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll
by tchemit@users.chorem.org 18 Jun '12
by tchemit@users.chorem.org 18 Jun '12
18 Jun '12
Author: tchemit
Date: 2012-06-18 12:01:58 +0200 (Mon, 18 Jun 2012)
New Revision: 3509
Url: http://chorem.org/repositories/revision/pollen/3509
Log:
fix security stuffs
Modified:
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java 2012-06-18 09:45:51 UTC (rev 3508)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java 2012-06-18 10:01:58 UTC (rev 3509)
@@ -24,7 +24,6 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
-import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.PollenTechnicalException;
import org.chorem.pollen.bean.PollUri;
@@ -59,9 +58,11 @@
boolean result = creator.getAccountId().equals(uriId.getAccountId());
if (!result) {
- // try to match userAccount
- result = ObjectUtils.equals(pollenUserAccount,
- creator.getUserAccount());
+ if (pollenUserAccount != null) {
+
+ // try to match userAccount
+ result = pollenUserAccount.equals(creator.getUserAccount());
+ }
}
return result;
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-06-18 09:45:51 UTC (rev 3508)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-06-18 10:01:58 UTC (rev 3509)
@@ -24,6 +24,7 @@
import com.google.common.base.Preconditions;
import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.common.PollType;
/**
* To delete a poll vote.
@@ -68,6 +69,14 @@
getVoteService().deleteVote(poll, voteId, reason);
addFlashMessage(_("pollen.information.vote.deleted"));
+
+ if (poll.getPollType() == PollType.FREE &&
+ getUriId().isAccountIdNotBlank() &&
+ !poll.getCreator().getAccountId().equals(getAccountId())) {
+
+ // remove accountId from url, voter does no longer exists.
+ getUriId().setAccountId(null);
+ }
return SUCCESS;
}
}
1
0
r3508 - in trunk/pollen-ui-struts2/src/main/webapp: WEB-INF/jsp/poll css img js
by tchemit@users.chorem.org 18 Jun '12
by tchemit@users.chorem.org 18 Jun '12
18 Jun '12
Author: tchemit
Date: 2012-06-18 11:45:51 +0200 (Mon, 18 Jun 2012)
New Revision: 3508
Url: http://chorem.org/repositories/revision/pollen/3508
Log:
fixes #614: We cannot see images in real size anymore
Added:
trunk/pollen-ui-struts2/src/main/webapp/css/jquery.lightbox-0.5.css
trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-blank.gif
trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-btn-close.gif
trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-btn-next.gif
trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-btn-prev.gif
trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-ico-loading.gif
trunk/pollen-ui-struts2/src/main/webapp/js/jquery.lightbox-0.5.js
trunk/pollen-ui-struts2/src/main/webapp/js/jquery.lightbox-0.5.min.js
Modified:
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-06-18 09:45:47 UTC (rev 3507)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-06-18 09:45:51 UTC (rev 3508)
@@ -25,7 +25,13 @@
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<link rel="stylesheet" type="text/css"
href="<s:url value='/css/results.css'/>"/>
+<link rel="stylesheet" type="text/css"
+ href="<s:url value='/css/jquery.lightbox-0.5.css'/>"/>
+
+<script type="text/javascript"
+ src="<s:url value='/js/jquery.lightbox-0.5.js' />"></script>
+
<script type="text/javascript">
function displayCharts(type) {
@@ -49,10 +55,18 @@
// register all chart url (without the type in it)
displayCharts(1);
- });
+ $('a[rel*="lightbox"]').lightBox(
+ {
+ imageLoading:'<s:url value="/img/lightbox-ico-loading.gif"/>',
+ imageBtnClose:'<s:url value="/img/lightbox-btn-close.gif"/>',
+ imageBtnPrev:'<s:url value="/img/lightbox-btn-prev.gif"/>',
+ imageBtnNext:'<s:url value="/img/lightbox-btn-next.gif"/>'
+ });
+ });
</script>
+
<s:if test="userAllowed">
<h1 class="titleVoteCounting"><s:property value="poll.title"/></h1>
@@ -106,11 +120,19 @@
escapeAmp="false">
<s:param name="choiceId" value="name"/>
<s:param name="pollId" value="poll.pollId"/>
+ <s:param name="thumb" value="false"/>
+ </s:url>
+ <s:url id="imageUrlThumb" namespace="/io" action="getPollChoiceImage"
+ escapeAmp="false">
+ <s:param name="choiceId" value="name"/>
+ <s:param name="pollId" value="poll.pollId"/>
<s:param name="thumb" value="true"/>
</s:url>
- <img alt="<s:property value='name'/>"
- title="<s:property value='name'/>"
- src="<s:property value='imageUrl'/>">
+ <a href="<s:property value='imageUrl'/>" rel="lightbox">
+ <img alt="<s:property value='name'/>"
+ title="<s:property value='name'/>"
+ src="<s:property value='imageUrlThumb'/>">
+ </a>
</s:elseif>
<br/>
@@ -162,8 +184,10 @@
<s:if test="choicesResults != null">
<div id="resultChart">
<div>
- <s:iterator value="choicesResultNames" var="choicesResultName" status="status">
- <img id='chart_<s:property value="#status.index"/>' alt="<s:property/>"
+ <s:iterator value="choicesResultNames" var="choicesResultName"
+ status="status">
+ <img id='chart_<s:property value="#status.index"/>'
+ alt="<s:property/>"
title="<s:property/>"
src="<s:property value='%{getChoicesResultCharUrl(400,300, #choicesResultName)}'/>">
</s:iterator>
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-06-18 09:45:47 UTC (rev 3507)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-06-18 09:45:51 UTC (rev 3508)
@@ -28,9 +28,13 @@
<link rel="stylesheet" type="text/css"
href="<s:url value='/css/vote.css'/>"/>
+<link rel="stylesheet" type="text/css"
+ href="<s:url value='/css/jquery.lightbox-0.5.css'/>"/>
<script type="text/javascript"
src="<s:url value='/js/gridHelper.js' />"></script>
+<script type="text/javascript"
+ src="<s:url value='/js/jquery.lightbox-0.5.js' />"></script>
<s:set id='deleteCommentTitle'>
<s:text name="pollen.title.delete.pollComment"/>
@@ -97,6 +101,13 @@
$votingIdField.attr('disabled', $(this).prop('checked'));
});
+ $('a[rel*="lightbox"]').lightBox(
+ {
+ imageLoading:'<s:url value="/img/lightbox-ico-loading.gif"/>',
+ imageBtnClose:'<s:url value="/img/lightbox-btn-close.gif"/>',
+ imageBtnPrev:'<s:url value="/img/lightbox-btn-prev.gif"/>',
+ imageBtnNext:'<s:url value="/img/lightbox-btn-next.gif"/>'
+ });
});
</script>
@@ -232,26 +243,36 @@
<s:if test="imageType">
<s:iterator value="poll.choice" var="choice">
<s:if test="!isChoiceHidden(#choice)">
+
<s:url id="imageUrl" namespace="/io" action="getPollChoiceImage"
escapeAmp="false">
<s:param name="choiceId" value="name"/>
<s:param name="pollId" value="poll.pollId"/>
+ <s:param name="thumb" value="false"/>
+ </s:url>
+ <s:url id="imageUrlThumb" namespace="/io" action="getPollChoiceImage"
+ escapeAmp="false">
+ <s:param name="choiceId" value="name"/>
+ <s:param name="pollId" value="poll.pollId"/>
<s:param name="thumb" value="true"/>
</s:url>
<s:if test="!isDescNull(#choice)">
<th class="desc">
-
- <img alt="<s:property value='name'/>"
- title='<s:property value="escapeLineBreak(#choice.description)"/>'
- src="<s:property value='imageUrl'/>">
+ <a href="<s:property value='imageUrl'/>" rel="lightbox">
+ <img alt="<s:property value='name'/>"
+ title='<s:property value="escapeLineBreak(#choice.description)"/>'
+ src="<s:property value='imageUrlThumb'/>">
+ </a>
</th>
</s:if>
<s:else>
<th>
- <img alt="<s:property value='name'/>"
- title='<s:property value="escapeLineBreak(#choice.description)"/>'
- src="<s:property value='imageUrl'/>">
+ <a href="<s:property value='imageUrl'/>" rel="lightbox">
+ <img alt="<s:property value='name'/>"
+ title='<s:property value="escapeLineBreak(#choice.description)"/>'
+ src="<s:property value='imageUrlThumb'/>">
+ </a>
</th>
</s:else>
</s:if>
Added: trunk/pollen-ui-struts2/src/main/webapp/css/jquery.lightbox-0.5.css
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/css/jquery.lightbox-0.5.css (rev 0)
+++ trunk/pollen-ui-struts2/src/main/webapp/css/jquery.lightbox-0.5.css 2012-06-18 09:45:51 UTC (rev 3508)
@@ -0,0 +1,102 @@
+/**
+ * %%Ignore-License
+ * jQuery lightBox plugin
+ * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
+ * and adapted to me for use like a plugin from jQuery.
+ * @name jquery-lightbox-0.5.css
+ * @author Leandro Vieira Pinho - http://leandrovieira.com
+ * @version 0.5
+ * @date April 11, 2008
+ * @category jQuery plugin
+ * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
+ * @license CCAttribution-ShareAlike 2.5 Brazil - http://creativecommons.org/licenses/by-sa/2.5/br/deed.en_US
+ * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
+ */
+#jquery-overlay {
+ position: absolute;
+ top: 0;
+ left: 0;
+ z-index: 90;
+ width: 100%;
+ height: 500px;
+}
+#jquery-lightbox {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ z-index: 100;
+ text-align: center;
+ line-height: 0;
+}
+#jquery-lightbox a img { border: none; }
+#lightbox-container-image-box {
+ position: relative;
+ background-color: #fff;
+ width: 250px;
+ height: 250px;
+ margin: 0 auto;
+}
+#lightbox-container-image { padding: 10px; }
+#lightbox-loading {
+ position: absolute;
+ top: 40%;
+ left: 0%;
+ height: 25%;
+ width: 100%;
+ text-align: center;
+ line-height: 0;
+}
+#lightbox-nav {
+ position: absolute;
+ top: 0;
+ left: 0;
+ height: 100%;
+ width: 100%;
+ z-index: 10;
+}
+#lightbox-container-image-box > #lightbox-nav { left: 0; }
+#lightbox-nav a { outline: none;}
+#lightbox-nav-btnPrev, #lightbox-nav-btnNext {
+ width: 49%;
+ height: 100%;
+ zoom: 1;
+ display: block;
+}
+#lightbox-nav-btnPrev {
+ left: 0;
+ float: left;
+}
+#lightbox-nav-btnNext {
+ right: 0;
+ float: right;
+}
+#lightbox-container-image-data-box {
+ font: 10px Verdana, Helvetica, sans-serif;
+ background-color: #fff;
+ margin: 0 auto;
+ line-height: 1.4em;
+ overflow: auto;
+ width: 100%;
+ padding: 0 10px 0;
+}
+#lightbox-container-image-data {
+ padding: 0 10px;
+ color: #666;
+}
+#lightbox-container-image-data #lightbox-image-details {
+ width: 70%;
+ float: left;
+ text-align: left;
+}
+#lightbox-image-details-caption { font-weight: bold; }
+#lightbox-image-details-currentNumber {
+ display: block;
+ clear: left;
+ padding-bottom: 1.0em;
+}
+#lightbox-secNav-btnClose {
+ width: 66px;
+ float: right;
+ padding-bottom: 0.7em;
+}
\ No newline at end of file
Property changes on: trunk/pollen-ui-struts2/src/main/webapp/css/jquery.lightbox-0.5.css
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-blank.gif
===================================================================
(Binary files differ)
Property changes on: trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-blank.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-btn-close.gif
===================================================================
(Binary files differ)
Property changes on: trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-btn-close.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-btn-next.gif
===================================================================
(Binary files differ)
Property changes on: trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-btn-next.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-btn-prev.gif
===================================================================
(Binary files differ)
Property changes on: trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-btn-prev.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-ico-loading.gif
===================================================================
(Binary files differ)
Property changes on: trunk/pollen-ui-struts2/src/main/webapp/img/lightbox-ico-loading.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/pollen-ui-struts2/src/main/webapp/js/jquery.lightbox-0.5.js
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/js/jquery.lightbox-0.5.js (rev 0)
+++ trunk/pollen-ui-struts2/src/main/webapp/js/jquery.lightbox-0.5.js 2012-06-18 09:45:51 UTC (rev 3508)
@@ -0,0 +1,474 @@
+/**
+ * %%Ignore-License
+ *
+ * jQuery lightBox plugin
+ * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
+ * and adapted to me for use like a plugin from jQuery.
+ * @name jquery-lightbox-0.5.js
+ * @author Leandro Vieira Pinho - http://leandrovieira.com
+ * @version 0.5
+ * @date April 11, 2008
+ * @category jQuery plugin
+ * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
+ * @license CCAttribution-ShareAlike 2.5 Brazil - http://creativecommons.org/licenses/by-sa/2.5/br/deed.en_US
+ * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
+ */
+
+// Offering a Custom Alias suport - More info: http://docs.jquery.com/Plugins/Authoring#Custom_Alias
+(function($) {
+ /**
+ * $ is an alias to jQuery object
+ *
+ */
+ $.fn.lightBox = function(settings) {
+ // Settings to configure the jQuery lightBox plugin how you like
+ settings = jQuery.extend({
+ // Configuration related to overlay
+ overlayBgColor: '#000', // (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.
+ overlayOpacity: 0.8, // (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9
+ // Configuration related to navigation
+ fixedNavigation: false, // (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.
+ // Configuration related to images
+ imageLoading: '../images/lightbox-ico-loading.gif', // (string) Path and the name of the loading icon
+ imageBtnPrev: '../images/lightbox-btn-prev.gif', // (string) Path and the name of the prev button image
+ imageBtnNext: '../images/lightbox-btn-next.gif', // (string) Path and the name of the next button image
+ imageBtnClose: '../images/lightbox-btn-close.gif', // (string) Path and the name of the close btn
+ imageBlank: '../images/lightbox-blank.gif', // (string) Path and the name of a blank image (one pixel)
+ // Configuration related to container image box
+ containerBorderSize: 10, // (integer) If you adjust the padding in the CSS for the container, #lightbox-container-image-box, you will need to update this value
+ containerResizeSpeed: 400, // (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default.
+ // Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.
+ txtImage: 'Image', // (string) Specify text "Image"
+ txtOf: 'of', // (string) Specify text "of"
+ // Configuration related to keyboard navigation
+ keyToClose: 'c', // (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
+ keyToPrev: 'p', // (string) (p = previous) Letter to show the previous image
+ keyToNext: 'n', // (string) (n = next) Letter to show the next image.
+ // Don�t alter these variables in any way
+ imageArray: [],
+ activeImage: 0
+ },settings);
+ // Caching the jQuery object with all elements matched
+ var jQueryMatchedObj = this; // This, in this context, refer to jQuery object
+ /**
+ * Initializing the plugin calling the start function
+ *
+ * @return boolean false
+ */
+ function _initialize() {
+ _start(this,jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked
+ return false; // Avoid the browser following the link
+ }
+ /**
+ * Start the jQuery lightBox plugin
+ *
+ * @param object objClicked The object (link) whick the user have clicked
+ * @param object jQueryMatchedObj The jQuery object with all elements matched
+ */
+ function _start(objClicked,jQueryMatchedObj) {
+ // Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
+ $('embed, object, select').css({ 'visibility' : 'hidden' });
+ // Call the function to create the markup structure; style some elements; assign events in some elements.
+ _set_interface();
+ // Unset total images in imageArray
+ settings.imageArray.length = 0;
+ // Unset image active information
+ settings.activeImage = 0;
+ // We have an image set? Or just an image? Let�s see it.
+ if ( jQueryMatchedObj.length == 1 ) {
+ settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')));
+ } else {
+ // Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references
+ for ( var i = 0; i < jQueryMatchedObj.length; i++ ) {
+ settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));
+ }
+ }
+ while ( settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href') ) {
+ settings.activeImage++;
+ }
+ // Call the function that prepares image exibition
+ _set_image_to_view();
+ }
+ /**
+ * Create the jQuery lightBox plugin interface
+ *
+ * The HTML markup will be like that:
+ <div id="jquery-overlay"></div>
+ <div id="jquery-lightbox">
+ <div id="lightbox-container-image-box">
+ <div id="lightbox-container-image">
+ <img src="../fotos/XX.jpg" id="lightbox-image">
+ <div id="lightbox-nav">
+ <a href="#" id="lightbox-nav-btnPrev"></a>
+ <a href="#" id="lightbox-nav-btnNext"></a>
+ </div>
+ <div id="lightbox-loading">
+ <a href="#" id="lightbox-loading-link">
+ <img src="../images/lightbox-ico-loading.gif">
+ </a>
+ </div>
+ </div>
+ </div>
+ <div id="lightbox-container-image-data-box">
+ <div id="lightbox-container-image-data">
+ <div id="lightbox-image-details">
+ <span id="lightbox-image-details-caption"></span>
+ <span id="lightbox-image-details-currentNumber"></span>
+ </div>
+ <div id="lightbox-secNav">
+ <a href="#" id="lightbox-secNav-btnClose">
+ <img src="../images/lightbox-btn-close.gif">
+ </a>
+ </div>
+ </div>
+ </div>
+ </div>
+ *
+ */
+ function _set_interface() {
+ // Apply the HTML markup into body tag
+ $('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="' + settings.imageBtnClose + '"></a></div></div></div></div>');
+ // Get page sizes
+ var arrPageSizes = ___getPageSize();
+ // Style overlay and show it
+ $('#jquery-overlay').css({
+ backgroundColor: settings.overlayBgColor,
+ opacity: settings.overlayOpacity,
+ width: arrPageSizes[0],
+ height: arrPageSizes[1]
+ }).fadeIn();
+ // Get page scroll
+ var arrPageScroll = ___getPageScroll();
+ // Calculate top and left offset for the jquery-lightbox div object and show it
+ $('#jquery-lightbox').css({
+ top: arrPageScroll[1] + (arrPageSizes[3] / 10),
+ left: arrPageScroll[0]
+ }).show();
+ // Assigning click events in elements to close overlay
+ $('#jquery-overlay,#jquery-lightbox').click(function() {
+ _finish();
+ });
+ // Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects
+ $('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() {
+ _finish();
+ return false;
+ });
+ // If window was resized, calculate the new overlay dimensions
+ $(window).resize(function() {
+ // Get page sizes
+ var arrPageSizes = ___getPageSize();
+ // Style overlay and show it
+ $('#jquery-overlay').css({
+ width: arrPageSizes[0],
+ height: arrPageSizes[1]
+ });
+ // Get page scroll
+ var arrPageScroll = ___getPageScroll();
+ // Calculate top and left offset for the jquery-lightbox div object and show it
+ $('#jquery-lightbox').css({
+ top: arrPageScroll[1] + (arrPageSizes[3] / 10),
+ left: arrPageScroll[0]
+ });
+ });
+ }
+ /**
+ * Prepares image exibition; doing a image�s preloader to calculate it�s size
+ *
+ */
+ function _set_image_to_view() { // show the loading
+ // Show the loading
+ $('#lightbox-loading').show();
+ if ( settings.fixedNavigation ) {
+ $('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
+ } else {
+ // Hide some elements
+ $('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
+ }
+ // Image preload process
+ var objImagePreloader = new Image();
+ objImagePreloader.onload = function() {
+ $('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);
+ // Perfomance an effect in the image container resizing it
+ _resize_container_image_box(objImagePreloader.width,objImagePreloader.height);
+ // clear onLoad, IE behaves irratically with animated gifs otherwise
+ objImagePreloader.onload=function(){};
+ };
+ objImagePreloader.src = settings.imageArray[settings.activeImage][0];
+ };
+ /**
+ * Perfomance an effect in the image container resizing it
+ *
+ * @param integer intImageWidth The image�s width that will be showed
+ * @param integer intImageHeight The image�s height that will be showed
+ */
+ function _resize_container_image_box(intImageWidth,intImageHeight) {
+ // Get current width and height
+ var intCurrentWidth = $('#lightbox-container-image-box').width();
+ var intCurrentHeight = $('#lightbox-container-image-box').height();
+ // Get the width and height of the selected image plus the padding
+ var intWidth = (intImageWidth + (settings.containerBorderSize * 2)); // Plus the image�s width and the left and right padding value
+ var intHeight = (intImageHeight + (settings.containerBorderSize * 2)); // Plus the image�s height and the left and right padding value
+ // Diferences
+ var intDiffW = intCurrentWidth - intWidth;
+ var intDiffH = intCurrentHeight - intHeight;
+ // Perfomance the effect
+ $('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight },settings.containerResizeSpeed,function() { _show_image(); });
+ if ( ( intDiffW == 0 ) && ( intDiffH == 0 ) ) {
+ if ( $.browser.msie ) {
+ ___pause(250);
+ } else {
+ ___pause(100);
+ }
+ }
+ $('#lightbox-container-image-data-box').css({ width: intImageWidth });
+ $('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) });
+ };
+ /**
+ * Show the prepared image
+ *
+ */
+ function _show_image() {
+ $('#lightbox-loading').hide();
+ $('#lightbox-image').fadeIn(function() {
+ _show_image_data();
+ _set_navigation();
+ });
+ _preload_neighbor_images();
+ };
+ /**
+ * Show the image information
+ *
+ */
+ function _show_image_data() {
+ $('#lightbox-container-image-data-box').slideDown('fast');
+ $('#lightbox-image-details-caption').hide();
+ if ( settings.imageArray[settings.activeImage][1] ) {
+ $('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show();
+ }
+ // If we have a image set, display 'Image X of X'
+ if ( settings.imageArray.length > 1 ) {
+ $('#lightbox-image-details-currentNumber').html(settings.txtImage + ' ' + ( settings.activeImage + 1 ) + ' ' + settings.txtOf + ' ' + settings.imageArray.length).show();
+ }
+ }
+ /**
+ * Display the button navigations
+ *
+ */
+ function _set_navigation() {
+ $('#lightbox-nav').show();
+
+ // Instead to define this configuration in CSS file, we define here. And it�s need to IE. Just.
+ $('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
+
+ // Show the prev button, if not the first image in set
+ if ( settings.activeImage != 0 ) {
+ if ( settings.fixedNavigation ) {
+ $('#lightbox-nav-btnPrev').css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' })
+ .unbind()
+ .bind('click',function() {
+ settings.activeImage = settings.activeImage - 1;
+ _set_image_to_view();
+ return false;
+ });
+ } else {
+ // Show the images button for Next buttons
+ $('#lightbox-nav-btnPrev').unbind().hover(function() {
+ $(this).css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' });
+ },function() {
+ $(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
+ }).show().bind('click',function() {
+ settings.activeImage = settings.activeImage - 1;
+ _set_image_to_view();
+ return false;
+ });
+ }
+ }
+
+ // Show the next button, if not the last image in set
+ if ( settings.activeImage != ( settings.imageArray.length -1 ) ) {
+ if ( settings.fixedNavigation ) {
+ $('#lightbox-nav-btnNext').css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' })
+ .unbind()
+ .bind('click',function() {
+ settings.activeImage = settings.activeImage + 1;
+ _set_image_to_view();
+ return false;
+ });
+ } else {
+ // Show the images button for Next buttons
+ $('#lightbox-nav-btnNext').unbind().hover(function() {
+ $(this).css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' });
+ },function() {
+ $(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
+ }).show().bind('click',function() {
+ settings.activeImage = settings.activeImage + 1;
+ _set_image_to_view();
+ return false;
+ });
+ }
+ }
+ // Enable keyboard navigation
+ _enable_keyboard_navigation();
+ }
+ /**
+ * Enable a support to keyboard navigation
+ *
+ */
+ function _enable_keyboard_navigation() {
+ $(document).keydown(function(objEvent) {
+ _keyboard_action(objEvent);
+ });
+ }
+ /**
+ * Disable the support to keyboard navigation
+ *
+ */
+ function _disable_keyboard_navigation() {
+ $(document).unbind();
+ }
+ /**
+ * Perform the keyboard actions
+ *
+ */
+ function _keyboard_action(objEvent) {
+ // To ie
+ if ( objEvent == null ) {
+ keycode = event.keyCode;
+ escapeKey = 27;
+ // To Mozilla
+ } else {
+ keycode = objEvent.keyCode;
+ escapeKey = objEvent.DOM_VK_ESCAPE;
+ }
+ // Get the key in lower case form
+ key = String.fromCharCode(keycode).toLowerCase();
+ // Verify the keys to close the ligthBox
+ if ( ( key == settings.keyToClose ) || ( key == 'x' ) || ( keycode == escapeKey ) ) {
+ _finish();
+ }
+ // Verify the key to show the previous image
+ if ( ( key == settings.keyToPrev ) || ( keycode == 37 ) ) {
+ // If we�re not showing the first image, call the previous
+ if ( settings.activeImage != 0 ) {
+ settings.activeImage = settings.activeImage - 1;
+ _set_image_to_view();
+ _disable_keyboard_navigation();
+ }
+ }
+ // Verify the key to show the next image
+ if ( ( key == settings.keyToNext ) || ( keycode == 39 ) ) {
+ // If we�re not showing the last image, call the next
+ if ( settings.activeImage != ( settings.imageArray.length - 1 ) ) {
+ settings.activeImage = settings.activeImage + 1;
+ _set_image_to_view();
+ _disable_keyboard_navigation();
+ }
+ }
+ }
+ /**
+ * Preload prev and next images being showed
+ *
+ */
+ function _preload_neighbor_images() {
+ if ( (settings.imageArray.length -1) > settings.activeImage ) {
+ objNext = new Image();
+ objNext.src = settings.imageArray[settings.activeImage + 1][0];
+ }
+ if ( settings.activeImage > 0 ) {
+ objPrev = new Image();
+ objPrev.src = settings.imageArray[settings.activeImage -1][0];
+ }
+ }
+ /**
+ * Remove jQuery lightBox plugin HTML markup
+ *
+ */
+ function _finish() {
+ $('#jquery-lightbox').remove();
+ $('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
+ // Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
+ $('embed, object, select').css({ 'visibility' : 'visible' });
+ }
+ /**
+ / THIRD FUNCTION
+ * getPageSize() by quirksmode.com
+ *
+ * @return Array Return an array with page width, height and window width, height
+ */
+ function ___getPageSize() {
+ var xScroll, yScroll;
+ if (window.innerHeight && window.scrollMaxY) {
+ xScroll = window.innerWidth + window.scrollMaxX;
+ yScroll = window.innerHeight + window.scrollMaxY;
+ } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
+ xScroll = document.body.scrollWidth;
+ yScroll = document.body.scrollHeight;
+ } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
+ xScroll = document.body.offsetWidth;
+ yScroll = document.body.offsetHeight;
+ }
+ var windowWidth, windowHeight;
+ if (self.innerHeight) { // all except Explorer
+ if(document.documentElement.clientWidth){
+ windowWidth = document.documentElement.clientWidth;
+ } else {
+ windowWidth = self.innerWidth;
+ }
+ windowHeight = self.innerHeight;
+ } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
+ windowWidth = document.documentElement.clientWidth;
+ windowHeight = document.documentElement.clientHeight;
+ } else if (document.body) { // other Explorers
+ windowWidth = document.body.clientWidth;
+ windowHeight = document.body.clientHeight;
+ }
+ // for small pages with total height less then height of the viewport
+ if(yScroll < windowHeight){
+ pageHeight = windowHeight;
+ } else {
+ pageHeight = yScroll;
+ }
+ // for small pages with total width less then width of the viewport
+ if(xScroll < windowWidth){
+ pageWidth = xScroll;
+ } else {
+ pageWidth = windowWidth;
+ }
+ arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
+ return arrayPageSize;
+ };
+ /**
+ / THIRD FUNCTION
+ * getPageScroll() by quirksmode.com
+ *
+ * @return Array Return an array with x,y page scroll values.
+ */
+ function ___getPageScroll() {
+ var xScroll, yScroll;
+ if (self.pageYOffset) {
+ yScroll = self.pageYOffset;
+ xScroll = self.pageXOffset;
+ } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
+ yScroll = document.documentElement.scrollTop;
+ xScroll = document.documentElement.scrollLeft;
+ } else if (document.body) {// all other Explorers
+ yScroll = document.body.scrollTop;
+ xScroll = document.body.scrollLeft;
+ }
+ arrayPageScroll = new Array(xScroll,yScroll);
+ return arrayPageScroll;
+ };
+ /**
+ * Stop the code execution from a escified time in milisecond
+ *
+ */
+ function ___pause(ms) {
+ var date = new Date();
+ curDate = null;
+ do { var curDate = new Date(); }
+ while ( curDate - date < ms);
+ };
+ // Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once
+ return this.unbind('click').click(_initialize);
+ };
+})(jQuery); // Call and execute the function immediately passing the jQuery object
\ No newline at end of file
Property changes on: trunk/pollen-ui-struts2/src/main/webapp/js/jquery.lightbox-0.5.js
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/pollen-ui-struts2/src/main/webapp/js/jquery.lightbox-0.5.min.js
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/js/jquery.lightbox-0.5.min.js (rev 0)
+++ trunk/pollen-ui-struts2/src/main/webapp/js/jquery.lightbox-0.5.min.js 2012-06-18 09:45:51 UTC (rev 3508)
@@ -0,0 +1,43 @@
+/**
+ * %%Ignore-License
+ * jQuery lightBox plugin
+ * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
+ * and adapted to me for use like a plugin from jQuery.
+ * @name jquery-lightbox-0.5.js
+ * @author Leandro Vieira Pinho - http://leandrovieira.com
+ * @version 0.5
+ * @date April 11, 2008
+ * @category jQuery plugin
+ * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
+ * @license CCAttribution-ShareAlike 2.5 Brazil - http://creativecommons.org/licenses/by-sa/2.5/br/deed.en_US
+ * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
+ */
+(function($){$.fn.lightBox=function(settings){settings=jQuery.extend({overlayBgColor:'#000',overlayOpacity:0.8,fixedNavigation:false,imageLoading:'images/lightbox-ico-loading.gif',imageBtnPrev:'images/lightbox-btn-prev.gif',imageBtnNext:'images/lightbox-btn-next.gif',imageBtnClose:'images/lightbox-btn-close.gif',imageBlank:'images/lightbox-blank.gif',containerBorderSize:10,containerResizeSpeed:400,txtImage:'Image',txtOf:'of',keyToClose:'c',keyToPrev:'p',keyToNext:'n',imageArray:[],activeImage:0},settings);var jQueryMatchedObj=this;function _initialize(){_start(this,jQueryMatchedObj);return false;}
+function _start(objClicked,jQueryMatchedObj){$('embed, object, select').css({'visibility':'hidden'});_set_interface();settings.imageArray.length=0;settings.activeImage=0;if(jQueryMatchedObj.length==1){settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')));}else{for(var i=0;i<jQueryMatchedObj.length;i++){settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));}}
+while(settings.imageArray[settings.activeImage][0]!=objClicked.getAttribute('href')){settings.activeImage++;}
+_set_image_to_view();}
+function _set_interface(){$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="'+settings.imageLoading+'"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="'+settings.imageBtnClose+'"></a></div></div></div></div>');var arrPageSizes=___getPageSize();$('#jquery-overlay').css({backgroundColor:settings.overlayBgColor,opacity:settings.overlayOpacity,width:arrPageSizes[0],height:arrPageSizes[1]}).fadeIn();var arrPageScroll=___getPageScroll();$('#jquery-lightbox').css({top:arrPageScroll[1]+(arrPageSizes[3]/10),left:arrPageScroll[0]}).show();$('#jquery-overlay,#jquery-lightbox').click(function(){_finish();});$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function(){_finish();return false;});$(window).resize(function(){var arrPageSizes=___getPageSize();$('#jquery-overlay').css({width:arrPageSizes[0],height:arrPageSizes[1]});var arrPageScroll=___getPageScroll();$('#jquery-lightbox').css({top:arrPageScroll[1]+(arrPageSizes[3]/10),left:arrPageScroll[0]});});}
+function _set_image_to_view(){$('#lightbox-loading').show();if(settings.fixedNavigation){$('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();}else{$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();}
+var objImagePreloader=new Image();objImagePreloader.onload=function(){$('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);objImagePreloader.onload=function(){};};objImagePreloader.src=settings.imageArray[settings.activeImage][0];};function _resize_container_image_box(intImageWidth,intImageHeight){var intCurrentWidth=$('#lightbox-container-image-box').width();var intCurrentHeight=$('#lightbox-container-image-box').height();var intWidth=(intImageWidth+(settings.containerBorderSize*2));var intHeight=(intImageHeight+(settings.containerBorderSize*2));var intDiffW=intCurrentWidth-intWidth;var intDiffH=intCurrentHeight-intHeight;$('#lightbox-container-image-box').animate({width:intWidth,height:intHeight},settings.containerResizeSpeed,function(){_show_image();});if((intDiffW==0)&&(intDiffH==0)){if($.browser.msie){___pause(250);}else{___pause(100);}}
+$('#lightbox-container-image-data-box').css({width:intImageWidth});$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({height:intImageHeight+(settings.containerBorderSize*2)});};function _show_image(){$('#lightbox-loading').hide();$('#lightbox-image').fadeIn(function(){_show_image_data();_set_navigation();});_preload_neighbor_images();};function _show_image_data(){$('#lightbox-container-image-data-box').slideDown('fast');$('#lightbox-image-details-caption').hide();if(settings.imageArray[settings.activeImage][1]){$('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show();}
+if(settings.imageArray.length>1){$('#lightbox-image-details-currentNumber').html(settings.txtImage+' '+(settings.activeImage+1)+' '+settings.txtOf+' '+settings.imageArray.length).show();}}
+function _set_navigation(){$('#lightbox-nav').show();$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({'background':'transparent url('+settings.imageBlank+') no-repeat'});if(settings.activeImage!=0){if(settings.fixedNavigation){$('#lightbox-nav-btnPrev').css({'background':'url('+settings.imageBtnPrev+') left 15% no-repeat'}).unbind().bind('click',function(){settings.activeImage=settings.activeImage-1;_set_image_to_view();return false;});}else{$('#lightbox-nav-btnPrev').unbind().hover(function(){$(this).css({'background':'url('+settings.imageBtnPrev+') left 15% no-repeat'});},function(){$(this).css({'background':'transparent url('+settings.imageBlank+') no-repeat'});}).show().bind('click',function(){settings.activeImage=settings.activeImage-1;_set_image_to_view();return false;});}}
+if(settings.activeImage!=(settings.imageArray.length-1)){if(settings.fixedNavigation){$('#lightbox-nav-btnNext').css({'background':'url('+settings.imageBtnNext+') right 15% no-repeat'}).unbind().bind('click',function(){settings.activeImage=settings.activeImage+1;_set_image_to_view();return false;});}else{$('#lightbox-nav-btnNext').unbind().hover(function(){$(this).css({'background':'url('+settings.imageBtnNext+') right 15% no-repeat'});},function(){$(this).css({'background':'transparent url('+settings.imageBlank+') no-repeat'});}).show().bind('click',function(){settings.activeImage=settings.activeImage+1;_set_image_to_view();return false;});}}
+_enable_keyboard_navigation();}
+function _enable_keyboard_navigation(){$(document).keydown(function(objEvent){_keyboard_action(objEvent);});}
+function _disable_keyboard_navigation(){$(document).unbind();}
+function _keyboard_action(objEvent){if(objEvent==null){keycode=event.keyCode;escapeKey=27;}else{keycode=objEvent.keyCode;escapeKey=objEvent.DOM_VK_ESCAPE;}
+key=String.fromCharCode(keycode).toLowerCase();if((key==settings.keyToClose)||(key=='x')||(keycode==escapeKey)){_finish();}
+if((key==settings.keyToPrev)||(keycode==37)){if(settings.activeImage!=0){settings.activeImage=settings.activeImage-1;_set_image_to_view();_disable_keyboard_navigation();}}
+if((key==settings.keyToNext)||(keycode==39)){if(settings.activeImage!=(settings.imageArray.length-1)){settings.activeImage=settings.activeImage+1;_set_image_to_view();_disable_keyboard_navigation();}}}
+function _preload_neighbor_images(){if((settings.imageArray.length-1)>settings.activeImage){objNext=new Image();objNext.src=settings.imageArray[settings.activeImage+1][0];}
+if(settings.activeImage>0){objPrev=new Image();objPrev.src=settings.imageArray[settings.activeImage-1][0];}}
+function _finish(){$('#jquery-lightbox').remove();$('#jquery-overlay').fadeOut(function(){$('#jquery-overlay').remove();});$('embed, object, select').css({'visibility':'visible'});}
+function ___getPageSize(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
+var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth=self.innerWidth;}
+windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
+if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
+if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
+arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize;};function ___getPageScroll(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset;}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft;}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft;}
+arrayPageScroll=new Array(xScroll,yScroll);return arrayPageScroll;};function ___pause(ms){var date=new Date();curDate=null;do{var curDate=new Date();}
+while(curDate-date<ms);};return this.unbind('click').click(_initialize);};})(jQuery);
\ No newline at end of file
Property changes on: trunk/pollen-ui-struts2/src/main/webapp/js/jquery.lightbox-0.5.min.js
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r3507 - in trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui: . its
by ymartel@users.chorem.org 18 Jun '12
by ymartel@users.chorem.org 18 Jun '12
18 Jun '12
Author: ymartel
Date: 2012-06-18 11:45:47 +0200 (Mon, 18 Jun 2012)
New Revision: 3507
Url: http://chorem.org/repositories/revision/pollen/3507
Log:
refs #606 : add ITs for free Date poll create
Added:
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java
Modified:
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeTextPollSIT.java
Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java
===================================================================
--- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java 2012-06-18 08:22:04 UTC (rev 3506)
+++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java 2012-06-18 09:45:47 UTC (rev 3507)
@@ -26,7 +26,11 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.bean.PollUri;
+import org.nuiton.util.DateUtil;
+import java.util.Calendar;
+import java.util.Date;
+
/**
* Some fixtures for tests.
*
@@ -79,6 +83,10 @@
return "b9b434acd58d42fca083d473ee021fce";
}
+ public String datePattern() {
+ return "dd/MM/yyyy HH:mm";
+ }
+
public String homeURL() {
return baseUrl() + "home";
}
@@ -139,11 +147,19 @@
return baseUrl() + "poll/create";
}
- public String editPollURL() {
- return baseUrl() + "poll/edit";
- }
-
public String summaryURL() {
return baseUrl() + "poll/summary";
}
+
+ public String date(int year, int month, int day, int hour, int minute) {
+ Calendar instance = Calendar.getInstance();
+ instance.set(year, month, day, hour, minute);
+ Date date = instance.getTime();
+ String dateString = DateUtil.formatDate(date, datePattern());
+ return dateString;
+ }
+
+ public String date(int year, int month, int day) {
+ return date(year, month, day, 0, 0);
+ }
}
Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java
===================================================================
--- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java (rev 0)
+++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java 2012-06-18 09:45:47 UTC (rev 3507)
@@ -0,0 +1,312 @@
+/*
+ * #%L
+ * Pollen :: UI (struts2)
+ * $Id: CreateFreeTextPollSIT.java 3481 2012-06-15 15:12:06Z ymartel $
+ * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-ui-struts2/src/test/java/org/… $
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.its;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+
+import java.util.List;
+
+/**
+ * Test the well work of a Free Date poll creation page.
+ *
+ * Tested cases :
+ * <ul>
+ * <li>Classic creation with filled mandatory fields (a title and at least 2 choices(OK)</li>
+ * <li>Classic creation with no title (KO)</li>
+ * <li>Classic creation with no choice (KO)</li>
+ * <li>Classic creation with two same choices (KO)</li>
+ * <li>Classic creation with invalid date format for one of the choices (KO)</li>
+ * </ul>
+ *
+ * @author ymartel <martel(a)codelutin.com>
+ *
+ * @since 1.4
+ */
+public class CreateFreeDatePollSIT extends PollenBaseWebDriverIT {
+
+ public CreateFreeDatePollSIT(Class<? extends WebDriver> driverType) {
+ super(driverType);
+ }
+
+ /**
+ * This test create a simple free text poll.
+ * At the end, should be on summary page.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createSimpleFreeDatePoll() throws Exception {
+
+ // Go on home page
+ gotoUrl(fixtures.createPollURL());
+
+ // Set title
+ WebElement titleElement = findElement(By.name("poll.title"));
+ Assert.assertEquals("input", titleElement.getTagName());
+ Assert.assertTrue(titleElement.isDisplayed());
+ titleElement.sendKeys("My Date Poll");
+
+ // Switch to Date choices
+ List<WebElement> choiceTypesElement = findElements(By.name("poll.choiceType"));
+ Assert.assertEquals(3, choiceTypesElement.size());
+ WebElement dateChoiceTypeElement = choiceTypesElement.get(1);
+ Assert.assertEquals("input", dateChoiceTypeElement.getTagName());
+ Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value"));
+ Assert.assertTrue(dateChoiceTypeElement.isDisplayed());
+ dateChoiceTypeElement.click();
+
+ // Set first choice
+ WebElement choiceOneElement = findElement(By.name("dateChoice_0.name"));
+ Assert.assertEquals("input", choiceOneElement.getTagName());
+ Assert.assertTrue(choiceOneElement.isDisplayed());
+ choiceOneElement.sendKeys(fixtures.date(1431, 05, 30));
+
+ // Set second choice
+ WebElement choiceTwoElement = findElement(By.name("dateChoice_1.name"));
+ Assert.assertEquals("input", choiceTwoElement.getTagName());
+ Assert.assertTrue(choiceTwoElement.isDisplayed());
+ choiceTwoElement.sendKeys(fixtures.date(1789, 8, 26));
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // All good, should be on summary page !
+ checkCurrentUrl(fixtures.summaryURL(), false);
+ }
+
+ /**
+ * This test create a free date poll with two choices but no title.
+ * At the end, should be still on create page, with an error message.
+ */
+ @Test
+ public void createSimpleFreeDatePollWithoutTitle() throws Exception {
+
+ // Go on home page
+ gotoUrl(fixtures.createPollURL());
+
+ // Switch to Date choices
+ List<WebElement> choiceTypesElement = findElements(By.name("poll.choiceType"));
+ Assert.assertEquals(3, choiceTypesElement.size());
+ WebElement dateChoiceTypeElement = choiceTypesElement.get(1);
+ Assert.assertEquals("input", dateChoiceTypeElement.getTagName());
+ Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value"));
+ Assert.assertTrue(dateChoiceTypeElement.isDisplayed());
+ dateChoiceTypeElement.click();
+
+ // Set first choice
+ WebElement choiceOneElement = findElement(By.name("dateChoice_0.name"));
+ Assert.assertEquals("input", choiceOneElement.getTagName());
+ Assert.assertTrue(choiceOneElement.isDisplayed());
+ String choiceOneValue = fixtures.date(1431, 05, 30);
+ choiceOneElement.sendKeys(choiceOneValue);
+
+ // Set second choice
+ WebElement choiceTwoElement = findElement(By.name("dateChoice_1.name"));
+ Assert.assertEquals("input", choiceTwoElement.getTagName());
+ Assert.assertTrue(choiceTwoElement.isDisplayed());
+ String choiceTwoValue = fixtures.date(1789, 8, 26);
+ choiceTwoElement.sendKeys(choiceTwoValue);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // Title is missing, should stay on create poll page
+ checkCurrentUrl(fixtures.createPollURL(), false);
+
+ // Check an error message has been displayed
+ WebElement titleError = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(titleError);
+
+ // Check that choice fields are not lost
+ choiceOneElement = findElement(By.name("dateChoice_0.name"));
+ Assert.assertEquals("input", choiceOneElement.getTagName());
+ Assert.assertTrue(choiceOneElement.isDisplayed());
+ Assert.assertEquals(choiceOneValue, choiceOneElement.getAttribute("value"));
+ choiceTwoElement = findElement(By.name("dateChoice_1.name"));
+ Assert.assertEquals("input", choiceTwoElement.getTagName());
+ Assert.assertTrue(choiceTwoElement.isDisplayed());
+ Assert.assertEquals(choiceTwoValue, choiceTwoElement.getAttribute("value"));
+
+ }
+
+ /**
+ * This test create a free date poll without choices.
+ * At the end, should be still on create page, with an error message.
+ */
+ @Test
+ public void createSimpleFreeDatePollWithoutChoice() throws Exception {
+
+ // Go on home page
+ gotoUrl(fixtures.createPollURL());
+
+ // Set title
+ WebElement titleElement = findElement(By.name("poll.title"));
+ Assert.assertEquals("input", titleElement.getTagName());
+ Assert.assertTrue(titleElement.isDisplayed());
+ String pollTitle = "My Date Poll";
+ titleElement.sendKeys(pollTitle);
+
+ // Switch to Date choices
+ List<WebElement> choiceTypesElement = findElements(By.name("poll.choiceType"));
+ Assert.assertEquals(3, choiceTypesElement.size());
+ WebElement dateChoiceTypeElement = choiceTypesElement.get(1);
+ Assert.assertEquals("input", dateChoiceTypeElement.getTagName());
+ Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value"));
+ Assert.assertTrue(dateChoiceTypeElement.isDisplayed());
+ dateChoiceTypeElement.click();
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // No choices, should stay on create poll page
+ checkCurrentUrl(fixtures.createPollURL(), false);
+
+ // Check that title field is not lost
+ titleElement = findElement(By.name("poll.title"));
+ Assert.assertEquals("input", titleElement.getTagName());
+ Assert.assertTrue(titleElement.isDisplayed());
+ Assert.assertEquals(pollTitle, titleElement.getAttribute("value"));
+
+ // Check an error message has been displayed for choices
+ WebElement choicesError = findElement(By.id("poll_choices_error"));
+ Assert.assertNotNull(choicesError);
+
+ // Check that we are still on Date choices
+ choiceTypesElement = findElements(By.name("poll.choiceType"));
+ Assert.assertEquals(3, choiceTypesElement.size());
+ dateChoiceTypeElement = choiceTypesElement.get(1);
+ Assert.assertEquals("input", dateChoiceTypeElement.getTagName());
+ Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value"));
+ Assert.assertEquals("true", dateChoiceTypeElement.getAttribute("checked"));
+
+ }
+
+ /**
+ * This test create a free date poll with a same value for two choices.
+ * At the end, should be still on create page, with an error message.
+ *
+ */
+ @Test
+ public void createSimpleFreeDatePollWithTwoSameDate() throws Exception {
+
+ // Go on home page
+ gotoUrl(fixtures.createPollURL());
+
+ // Set title
+ WebElement titleElement = findElement(By.name("poll.title"));
+ Assert.assertEquals("input", titleElement.getTagName());
+ Assert.assertTrue(titleElement.isDisplayed());
+ titleElement.sendKeys("My Date Poll");
+
+ // Switch to Date choices
+ List<WebElement> choiceTypesElement = findElements(By.name("poll.choiceType"));
+ Assert.assertEquals(3, choiceTypesElement.size());
+ WebElement dateChoiceTypeElement = choiceTypesElement.get(1);
+ Assert.assertEquals("input", dateChoiceTypeElement.getTagName());
+ Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value"));
+ Assert.assertTrue(dateChoiceTypeElement.isDisplayed());
+ dateChoiceTypeElement.click();
+
+ // Set first choice
+ WebElement choiceOneElement = findElement(By.name("dateChoice_0.name"));
+ Assert.assertEquals("input", choiceOneElement.getTagName());
+ Assert.assertTrue(choiceOneElement.isDisplayed());
+ String date = fixtures.date(1431, 05, 30);
+ choiceOneElement.sendKeys(date);
+
+ // Set second choice
+ WebElement choiceTwoElement = findElement(By.name("dateChoice_1.name"));
+ Assert.assertEquals("input", choiceTwoElement.getTagName());
+ Assert.assertTrue(choiceTwoElement.isDisplayed());
+ choiceTwoElement.sendKeys(date);
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // An error, should stay on create page
+ checkCurrentUrl(fixtures.createPollURL(), false);
+
+ // Check an error message has been displayed for choices
+ WebElement choicesError = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(choicesError);
+ }
+
+ /**
+ * This test create a free date poll with a bas format for one of the choices.
+ * At the end, should be still on create page, with an error message.
+ *
+ */
+ @Test
+ public void createSimpleFreeDatePollWithBadFormatDate() throws Exception {
+
+ // Go on home page
+ gotoUrl(fixtures.createPollURL());
+
+ // Set title
+ WebElement titleElement = findElement(By.name("poll.title"));
+ Assert.assertEquals("input", titleElement.getTagName());
+ Assert.assertTrue(titleElement.isDisplayed());
+ titleElement.sendKeys("My Date Poll");
+
+ // Switch to Date choices
+ List<WebElement> choiceTypesElement = findElements(By.name("poll.choiceType"));
+ Assert.assertEquals(3, choiceTypesElement.size());
+ WebElement dateChoiceTypeElement = choiceTypesElement.get(1);
+ Assert.assertEquals("input", dateChoiceTypeElement.getTagName());
+ Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value"));
+ Assert.assertTrue(dateChoiceTypeElement.isDisplayed());
+ dateChoiceTypeElement.click();
+
+ // Set first choice
+ WebElement choiceOneElement = findElement(By.name("dateChoice_0.name"));
+ Assert.assertEquals("input", choiceOneElement.getTagName());
+ Assert.assertTrue(choiceOneElement.isDisplayed());
+ choiceOneElement.sendKeys(fixtures.date(1431, 05, 30));
+
+ // Set second choice
+ WebElement choiceTwoElement = findElement(By.name("dateChoice_1.name"));
+ Assert.assertEquals("input", choiceTwoElement.getTagName());
+ Assert.assertTrue(choiceTwoElement.isDisplayed());
+ choiceTwoElement.sendKeys("28 08 1789");
+
+ // Submit form
+ WebElement submit = findElement(By.name("action:create"));
+ submit.click();
+
+ // An error, should stay on create page
+ checkCurrentUrl(fixtures.createPollURL(), false);
+
+ // Check an error message has been displayed for choices
+ WebElement choicesError = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(choicesError);
+ }
+
+}
Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeTextPollSIT.java
===================================================================
--- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeTextPollSIT.java 2012-06-18 08:22:04 UTC (rev 3506)
+++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeTextPollSIT.java 2012-06-18 09:45:47 UTC (rev 3507)
@@ -286,7 +286,7 @@
WebElement startDateElement = findElement(By.name("poll.endDate"));
Assert.assertEquals("input", startDateElement.getTagName());
Assert.assertTrue(startDateElement.isDisplayed());
- //FIXME ymartel 2012/06/14 : review way to get DAte ?
+ //FIXME ymartel 2012/06/14 : review way to get Date ?
Date twoMonthsAgo = DateUtils.addMonths(new Date(), -2);
String formatTwoMonthsAgo = DateUtil.formatDate(twoMonthsAgo, "dd/MM/yyyy HH:mm");
startDateElement.sendKeys(formatTwoMonthsAgo);
@@ -438,8 +438,8 @@
checkCurrentUrl(fixtures.createPollURL(), false);
// Check an error message has been displayed
- WebElement dateError = findElement(By.className("errorMessage"));
- Assert.assertNotNull(dateError);
+ WebElement maxChoicesError = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(maxChoicesError);
// Go on general tab and check that Title and and choice fields values are not lost
WebElement generalClick = findElement(By.xpath("//a[@href=\"#tgeneral\"]"));
@@ -472,6 +472,9 @@
// No choices, should stay on create poll page
checkCurrentUrl(fixtures.createPollURL(), false);
+ // Check an error message has been displayed
+ maxChoicesError = findElement(By.className("errorMessage"));
+ Assert.assertNotNull(maxChoicesError);
}
1
0