r3179 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions java/org/chorem/pollen/ui/actions/poll resources/config resources/i18n webapp/WEB-INF webapp/WEB-INF/jsp webapp/WEB-INF/jsp/poll
Author: tchemit Date: 2012-03-14 10:42:22 +0100 (Wed, 14 Mar 2012) New Revision: 3179 Url: http://chorem.org/repositories/revision/pollen/3179 Log: ajout des import de liste de favoris dans sondages restreints Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personListToVotingList.jsp branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/home.jsp branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-13 14:06:19 UTC (rev 3178) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-14 09:42:22 UTC (rev 3179) @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.struts2.StrutsStatics; import org.chorem.pollen.PollenConfiguration; +import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.services.DefaultPollenServiceContext; import org.chorem.pollen.services.PollenService; import org.chorem.pollen.services.PollenServiceContext; @@ -247,4 +248,9 @@ String result = getDateTimeFormat().format(date); return result; } + + public boolean isUserLoggued() { + UserAccount userAccount = getPollenSession().getUserAccount(); + return userAccount != null; + } } Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-03-13 14:06:19 UTC (rev 3178) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-03-14 09:42:22 UTC (rev 3179) @@ -309,6 +309,9 @@ @Override public void prepare() throws Exception { + // remove all stuff from session + getPollenSession().clearDynamicData(); + pollTypes = decorateToName(PollType.values()); choiceTypes = decorateToName(ChoiceType.values()); voteCountingTypes = decorateToName(VoteCountingType.values()); @@ -366,12 +369,13 @@ Preconditions.checkNotNull(poll); + informationsError = false; + // poll must have a title if (StringUtils.isEmpty(poll.getTitle())) { addFieldError("poll.title", _("pollen.error.poll.required.title")); } - informationsError = false; // validate choices Map<Integer, Choice> orderedChoices = getOrderedChoices(); @@ -381,7 +385,6 @@ // poll must have at least one choice addFieldError("poll.choices", _("pollen.error.poll.required.one.choice")); - informationsError = true; } else { //TODO tchemit improve this (from different cases text-date-image) @@ -398,10 +401,10 @@ if (duplicateNameDetected) { addFieldError("poll.choices", _("pollen.error.poll.detected.duplicate.choice.name")); - informationsError = true; } } + optionsError = false; // validate security stuff @@ -425,6 +428,14 @@ emails); } } + + informationsError = hasFieldErrors(); + + if (!informationsError && optionsError) { + + // trick to force to go back to form + addFieldError("", ""); + } } @Override @@ -563,7 +574,7 @@ // keep errors to display them in correct action String errorToken = DisplayVotingList.getVotingListErrorTokenId( - votingListTokenId, 0); + votingListTokenId, votingListNumber); if (log.isInfoEnabled()) { log.info("Add " + errors.size() + " errors to " + errorToken); } Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java 2012-03-14 09:42:22 UTC (rev 3179) @@ -0,0 +1,116 @@ +/* + * #%L + * Pollen :: UI (strust2) + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package org.chorem.pollen.ui.actions.poll; + +import com.google.common.collect.Maps; +import org.chorem.pollen.business.persistence.PersonList; +import org.chorem.pollen.business.persistence.PersonToList; +import org.chorem.pollen.business.persistence.PersonToListImpl; +import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.services.impl.FavoriteService; +import org.chorem.pollen.ui.PollenSession; +import org.chorem.pollen.ui.actions.PollenActionSupport; + +import java.util.Map; + +/** + * Load in session a personToList to import into a votingList. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2.6 + */ +public class ImportPersonListToVotingList extends PollenActionSupport { + + private static final long serialVersionUID = 1L; + + public static final String TOKEN = "ImportPersonListToVotingList"; + + protected int votingListNumber; + + protected int personToListNumber; + + protected String personListId; + + protected String tokenId; + + /** Count of personToList for this votingList. */ + protected int nbPersonToLists; + + public int getVotingListNumber() { + return votingListNumber; + } + + public void setVotingListNumber(int votingListNumber) { + this.votingListNumber = votingListNumber; + } + + public int getPersonToListNumber() { + return personToListNumber; + } + + public void setPersonToListNumber(int personToListNumber) { + this.personToListNumber = personToListNumber; + } + + public String getPersonListId() { + return personListId; + } + + public void setPersonListId(String personListId) { + this.personListId = personListId; + } + + public String getTokenId() { + return tokenId; + } + + public int getNbPersonToLists() { + return nbPersonToLists; + } + + @Override + public String execute() throws Exception { + + tokenId = getServiceContext().createPollenUrlId() + TOKEN; + Map<Integer, PersonToList> data = Maps.newTreeMap(); + FavoriteService service = newService(FavoriteService.class); + PollenSession session = getPollenSession(); + PersonList favoriteList = + service.getFavoriteList(session.getUserAccount(), personListId); + nbPersonToLists = favoriteList.sizePollAccount(); + if (nbPersonToLists > 0) { + int index = personToListNumber; + for (PollAccount pollAccount : favoriteList.getPollAccount()) { + PersonToList p = new PersonToListImpl(); + p.setPollAccount(pollAccount); + p.setWeight(1); + data.put(index++, p); + } + } + session.putDynamicData(tokenId, data); + + + return SUCCESS; + } +} Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ImportPersonListToVotingList.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java 2012-03-14 09:42:22 UTC (rev 3179) @@ -0,0 +1,73 @@ +/* + * #%L + * Pollen :: UI (strust2) + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package org.chorem.pollen.ui.actions.poll; + +import com.google.common.collect.Maps; +import org.chorem.pollen.PollenFunctions; +import org.chorem.pollen.business.persistence.PersonList; +import org.chorem.pollen.business.persistence.UserAccount; +import org.chorem.pollen.services.impl.FavoriteService; +import org.chorem.pollen.ui.actions.PollenActionSupport; + +import java.util.List; +import java.util.Map; + +/** + * Select a person list to add into an existing voting list. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2.6 + */ +public class SelectPersonListToVotingList extends PollenActionSupport { + + private static final long serialVersionUID = 1L; + + protected int votingListNumber; + + protected Map<String, PersonList> personList; + + public Map<String, PersonList> getPersonList() { + return personList; + } + + public int getVotingListNumber() { + return votingListNumber; + } + + public void setVotingListNumber(int votingListNumber) { + this.votingListNumber = votingListNumber; + } + + @Override + public String execute() throws Exception { + + FavoriteService service = newService(FavoriteService.class); + UserAccount userAccount = getPollenSession().getUserAccount(); + List<PersonList> personLists = service.getFavoriteLists(userAccount); + + personList = Maps.uniqueIndex(personLists, PollenFunctions.ENTITY_BY_ID); + + return SUCCESS; + } +} Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SelectPersonListToVotingList.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-13 14:06:19 UTC (rev 3178) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-14 09:42:22 UTC (rev 3179) @@ -115,7 +115,8 @@ <result type="stream"> <param name="contentCharSet">UTF-8</param> <param name="contentType">application/xml</param> - <param name="contentDisposition">attachment;filename="${filename}"</param> + <param name="contentDisposition">attachment;filename="${filename}" + </param> <param name="encode">true</param> <param name="bufferSize">4096</param> </result> @@ -180,7 +181,8 @@ </action> <!-- get the feed of a given poll --> - <action name="getFeed" class="org.chorem.pollen.ui.actions.poll.GetPollFeed"> + <action name="getFeed" + class="org.chorem.pollen.ui.actions.poll.GetPollFeed"> <result type="stream"> <param name="contentCharSet">UTF-8</param> <param name="contentType">application/atom+xml</param> @@ -219,6 +221,25 @@ <result type="redirectToVote"/> </action> + <!-- Select a favorite list to add to a voting list --> + <action name="selectPersonListToAddToVotingList" + class="org.chorem.pollen.ui.actions.poll.SelectPersonListToVotingList"> + <result>/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp</result> + </action> + + <!-- Select a favorite list to import into a new voting list --> + <action name="selectPersonListToCreateNewVotingList" + class="org.chorem.pollen.ui.actions.poll.SelectPersonListToVotingList"> + <result>/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp + </result> + </action> + + <!-- Load in session a personList to be imported into a voting list --> + <action name="displayPersonListToVotingList" + class="org.chorem.pollen.ui.actions.poll.ImportPersonListToVotingList"> + <result type="json"/> + </action> + </package> Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-13 14:06:19 UTC (rev 3178) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-14 09:42:22 UTC (rev 3179) @@ -3,6 +3,7 @@ pollen.action.addPersonToList=Add a voter pollen.action.addVotingList=Add a group pollen.action.backToFavoriteLists=Back to favorite lists +pollen.action.cancel=Cancel pollen.action.create=Create pollen.action.createFavoriteList=Create a new list pollen.action.createPoll=Create the poll @@ -192,6 +193,8 @@ pollen.label.pollRegisterPage=If you are a logged user, you can find these links on the page pollen.label.pollVotePage=The link below leads to the page to vote for your poll. Save it and send it to the people that you want to vote \: pollen.legend.login=Login +pollen.legend.select.favoriteList.to.add=Sélectionner la liste de favoris à ajouter +pollen.legend.select.personList.to.create.votingList=Sélectionner la liste des votant à importer dans le nouveau groupe pollen.menu.admin=Administration pollen.menu.createPoll=Create a poll pollen.menu.home=Home @@ -219,4 +222,6 @@ pollen.title.pollsParticipatedList=Polls participated pollen.title.pollsParticipatedList.legend=Polls in which you are involved pollen.title.register=Register +pollen.title.selectPersonListToAddVotingList=Sélectionner une liste de votant à ajouter +pollen.title.selectPersonListToCreateVotingList=Sélectionner une liste de votant pour créer un nouveau groupe pollen.title.usersList=Users administration Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-13 14:06:19 UTC (rev 3178) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-14 09:42:22 UTC (rev 3179) @@ -1,8 +1,12 @@ pollen.action.addChoice=Ajouter un choix pollen.action.addComment=Ajouter un commentaire +pollen.action.addPersonListFromVotingList=Ajouter des votants à partir d'une liste de votants +pollen.action.addPersonListToVotingList=Ajouter la liste des votants pollen.action.addPersonToList=Ajouter un votant pollen.action.addVotingList=Ajouter un groupe +pollen.action.addVotingListFromPersonList=Ajouter un groupe à partir d'une liste de votants pollen.action.backToFavoriteLists=Retour à la liste des favoris +pollen.action.cancel=Annuler pollen.action.create=Créer pollen.action.createFavoriteList=Créer une ouvelle liste pollen.action.createPoll=Créer le sondage @@ -18,6 +22,8 @@ pollen.action.editPollAccount=Editer le membre sélectionné pollen.action.editUser=Editer un utilisateur sélectionné pollen.action.editVote=Modifier le vote +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.modify=Modifier pollen.action.pollChoiceDelete=Supprimer ce choix @@ -75,6 +81,7 @@ pollen.common.or=ou pollen.common.password=Mot de passe pollen.common.password2=Répétez votre mot de passe +pollen.common.personList=Liste de votants pollen.common.personToList=Votant pollen.common.pollCreator=Créateur pollen.common.pollOption.anonymous=Sondage anonyme @@ -193,6 +200,8 @@ pollen.label.pollRegisterPage=Si vous êtes un utilisateur identifié, vous pouvez retrouver ces liens dans la page pollen.label.pollVotePage=Le lien ci-dessous mène à la page de vote. Enregistrez-le et envoyez-le à ceux que vous voulez voir voter \: pollen.legend.login=Login +pollen.legend.select.favoriteList.to.add=Sélectionner la liste de favoris à ajouter +pollen.legend.select.personList.to.create.votingList=Sélectionner la liste des votant à importer dans le nouveau groupe pollen.menu.admin=Administration pollen.menu.createPoll=Créer un sondage pollen.menu.home=Accueil @@ -222,5 +231,7 @@ pollen.title.pollsParticipatedList=Sondages participés pollen.title.pollsParticipatedList.legend=Liste des sondages pour lesquels vous avez voté pollen.title.register=S'enregistrer +pollen.title.selectPersonListToAddVotingList=Sélectionner une liste de votants à ajouter +pollen.title.selectPersonListToCreateVotingList=Sélectionner une liste de votants pour créer un nouveau groupe pollen.title.usersList=Gestion des utilisateurs title=Création d'un sondage Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml 2012-03-13 14:06:19 UTC (rev 3178) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators.xml 2012-03-14 09:42:22 UTC (rev 3179) @@ -31,6 +31,7 @@ <pattern>/json/*</pattern> <pattern>/poll/confirmDelete*</pattern> <pattern>/poll/display*</pattern> + <pattern>/poll/selectPersonListTo*</pattern> <pattern>/io/*</pattern> </excludes> Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/home.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/home.jsp 2012-03-13 14:06:19 UTC (rev 3178) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/home.jsp 2012-03-14 09:42:22 UTC (rev 3179) @@ -32,7 +32,7 @@ </div> <div class="center"> - <s:a action="createPoll" namespace="/poll"> + <s:a action="create" namespace="/poll" method="input"> <img src="<s:url value='/img/smallCreation_%{safeLanguage}.png' />" alt="poll creation"/> </s:a> <s:a action="createForm" namespace="/poll"> Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-03-13 14:06:19 UTC (rev 3178) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-03-14 09:42:22 UTC (rev 3179) @@ -34,6 +34,31 @@ <script type="text/javascript"> + function addPersonListToVotingList(personListId) { + console.info("person list to add into votingList : " + personListId); + return closeDialog(); + } + + function selectPersonListToAddToVotingList(votingListNumber) { + console.info("Add to votingList "+votingListNumber); + $('.ui-dialog-title').html('<s:text name="pollen.title.selectPersonListToAddVotingList"/>') + var dialog = $("#selectPersonListDialog"); + var url = "<s:url action='selectPersonListToAddToVotingList' namespace='/poll'/>"; + url += '?'+ $.param({votingListNumber:votingListNumber}); + dialog.load(url); + dialog.dialog('open'); + return false; + } + + function selectPersonListToCreateNewVotingList() { + $('.ui-dialog-title').html('<s:text name="pollen.title.selectPersonListToCreateVotingList"/>') + var dialog = $("#selectPersonListDialog"); + var url = "<s:url action='selectPersonListToCreateNewVotingList' namespace='/poll'/>"; + dialog.load(url); + dialog.dialog('open'); + return false; + } + jQuery(document).ready(function () { $('[name="poll.choiceAddAllowed"]').change(function (event) { var val = $(this).prop('checked'); @@ -285,9 +310,14 @@ <div id="votingLists"> <%--Where to load voting lists --%> </div> - <div class="groupPoll"> - <s:submit key="pollen.action.addVotingList" align="center" + <div class="groupPoll" align="center"> + <s:submit key="pollen.action.addVotingList" theme="simple" onclick="return addNewVotingList();"/> + <s:if test="userLoggued"> + <s:submit key="pollen.action.addVotingListFromPersonList" + theme="simple" + onclick="return selectPersonListToCreateNewVotingList();"/> + </s:if> </div> </div> </fieldset> @@ -307,18 +337,18 @@ element.append( '<image src="${errorImg}">' ); - element.attr('title', - '<s:text name="pollen.error.pollTabErrorFound"/>'); + element.attr('title', '<s:text name="pollen.error.pollTabErrorFound"/>'); } if (<s:property value="%{informationsError}"/>) { - var tab = $('#tabGeneral a'); - addErrorImage(tab); + addErrorImage($('#tabGeneral a')); } if (<s:property value="%{optionsError}"/>) { - tab = $('#tabOptions a'); - addErrorImage(tab); + addErrorImage($('#tabOptions a')); } }); -</script> \ No newline at end of file +</script> + +<sj:dialog id="selectPersonListDialog" resizable="true" autoOpen="false" + modal="true" width="500"/> Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personListToVotingList.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personListToVotingList.jsp (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personListToVotingList.jsp 2012-03-14 09:42:22 UTC (rev 3179) @@ -0,0 +1,40 @@ +<%-- + #%L + Pollen :: UI (strust2) + + $Id$ + $HeadURL$ + %% + Copyright (C) 2009 - 2012 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + #L% + --%> +<%@ page language="java" contentType="text/html" pageEncoding="utf-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + +<s:set name="prefix">votingList_<s:property value="votingListNumber"/></s:set> + +<script type="text/javascript"> + jQuery(document).ready(function () { + // personToList loading + <s:iterator begin="1" end="nbPersonToLists" status="status"> + addPersonToList(<s:property value="votingListNumber"/>, <s:property value='personToListNumber + %{#status.index}'/>, <s:property value="nbPersonToLists - 1"/>, '<s:property value="tokenId" />'); + </s:iterator> + }); +</script> + +<s:div id='personToList_%{votingListNumber}'> + <%--Where to load personToList--%> +</s:div> Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personListToVotingList.jsp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp 2012-03-13 14:06:19 UTC (rev 3178) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/personToList.jsp 2012-03-14 09:42:22 UTC (rev 3179) @@ -42,7 +42,7 @@ - <s:label for="%{#prefix}.email" key="pollen.common.email" theme="simple"/> <s:textfield cols="30" id="%{#prefix}.email" key="%{#prefix}.email" - label='' theme="simple" + label='' theme="simple" size="30" value="%{personToList.pollAccount.email}"/> - <s:label for="%{#prefix}.weight" key="pollen.common.weight" theme="simple"/> Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp 2012-03-14 09:42:22 UTC (rev 3179) @@ -0,0 +1,81 @@ +<%-- + #%L + Pollen :: UI (strust2) + + $Id$ + $HeadURL$ + %% + Copyright (C) 2009 - 2012 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + #L% + --%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + +<script type="text/javascript"> + + var votingListNumber = parseInt('<s:property value='%{votingListNumber}'/>'); + + function cancel() { + $('#selectPersonListDialog').dialog('close'); + return false; + } + + function addPersonListToVotingList(personListId) { + + // get first personToList number available + var containerId = "personToList_" + votingListNumber; + // get first personToList available position + var firstNumber = getFirstEmptyPersonToList(containerId); + if (firstNumber == -1) { + // no personToList available + // let's take a new one (max +1) + firstNumber = 1 + getLastPersonToList(containerId); + } else { + // remove all empty personToList + var numbers = getAllPersonToListNumbers(containerId); + for (n in numbers) { + if (n >= firstNumber) { + deletePersonToList(containerId + "_" + n); + } + } + } + loadPersonListToVotingList(votingListNumber, firstNumber, personListId); + return cancel(); + } + + jQuery(document).ready(function () { + $('#personList').change(function (event) { + var val = $(this).val(); + $('#add').attr('disabled', val == ''); + }); + }); + +</script> +<fieldset class="ui-widget-content ui-corner-all"> + <s:select id="personList" listValue="value.name" list="personList" + key='pollen.common.personList' headerKey="" headerValue=""/> + <hr/> + <div align="right"> + <s:submit onclick="return cancel();" theme="simple" + key="pollen.action.cancel"/> + <s:submit + onclick="return addPersonListToVotingList($('#personList').val());" + theme="simple" disabled='true' id='add' + key="pollen.action.importPersonListToExistingVotingList"/> + </div> +</fieldset> + Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToAddToVotingList.jsp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp 2012-03-14 09:42:22 UTC (rev 3179) @@ -0,0 +1,69 @@ +<%-- + #%L + Pollen :: UI (strust2) + + $Id$ + $HeadURL$ + %% + Copyright (C) 2009 - 2012 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + #L% + --%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + +<script type="text/javascript"> + + function cancel() { + $('#selectPersonListDialog').dialog('close'); + return false; + } + + function importPersonListToNewVotingList(personListId) { + // add a new votingList + addNewVotingList(); + // get his number + var votingListNumber = getLastVotingList("votingLists"); + + var containerId = "personToList_" + votingListNumber; + // remove all personToList of this votingList + var numbers = getAllPersonToListNumbers(containerId); + for (n in numbers) { + deletePersonToList(containerId + "_" + n); + } + // add personList to this votingList at position 0 + loadPersonListToVotingList(votingListNumber, 0, personListId); + return cancel(); + } + jQuery(document).ready(function () { + $('#personList').change(function (event) { + var val = $(this).val(); + $('#import').attr('disabled', val == ''); + }); + }); + +</script> +<fieldset class="ui-widget-content ui-corner-all"> + <s:select id="personList" listValue="value.name" list="personList" + key='pollen.common.personList' headerKey="" headerValue=""/> + <hr/> + <div align="right"> + <s:submit onclick="return cancel();" theme="simple" + key="pollen.action.cancel"/> + <s:submit id='import' disabled="true" theme="simple" + onclick="return importPersonListToNewVotingList($('#personList').val());" + key="pollen.action.importPersonListToNewVotingList"/> + </div> +</fieldset> \ No newline at end of file Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/selectPersonListToCreateNewVotingList.jsp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp 2012-03-13 14:06:19 UTC (rev 3178) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/votingList.jsp 2012-03-14 09:42:22 UTC (rev 3179) @@ -28,9 +28,6 @@ <s:set id='deleteTitle'> <s:text name="pollen.action.pollVotingListDelete"/> </s:set> -<s:set id='editTitle'> - <s:text name="pollen.action.pollVotingListEdit"/> -</s:set> <script type="text/javascript"> jQuery(document).ready(function () { @@ -53,15 +50,11 @@ - <s:label for="%{#prefix}.weight" key="pollen.common.weight" theme="simple"/> - <s:textfield id="%{#prefix}.weight" key="%{#prefix}.weight" value="%{votingList.weight}" + <s:textfield id="%{#prefix}.weight" key="%{#prefix}.weight" + value="%{votingList.weight}" size="1" label='' theme="simple"/> </div> <div id='<s:property value="%{#prefix}"/>_actions' class="fright"> - <s:a href='#' onclick="return editVotingList('%{prefix}')"> - <image alt='<s:property value="editTitle"/>' - title='<s:property value="editTitle"/>' - src="<s:url value='/img/edit.png'/>"></image> - </s:a> <s:a href='#' onclick="return deleteVotingList('votingLists_%{votingListNumber}')"> <image alt='<s:property value="deleteTitle"/>' @@ -78,10 +71,20 @@ <%--Where to load personToList--%> </s:div> <hr/> - <div class="cleanBoth"></div> - <s:submit id='%{#prefix}_addPersonToList' name='%{#prefix}_addPersonToList' - key="pollen.action.addPersonToList" align="center" - onclick='return addNewPersonToList("%{votingListNumber}");'/> + <div class="cleanBoth" align="center"> + <s:submit id='%{#prefix}_addPersonToList' + name='%{#prefix}_addPersonToList' + key="pollen.action.addPersonToList" theme="simple" + onclick='return addNewPersonToList("%{votingListNumber}");'/> + <s:if test="userLoggued"> + <s:submit id='%{#prefix}_addPersonToList' theme="simple" + name='%{#prefix}_addPersonToList' + key="pollen.action.addPersonListFromVotingList" + onclick='return selectPersonListToAddToVotingList("%{votingListNumber}");'/> + </s:if> + + </div> + </fieldset> <br/> </s:div> Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp 2012-03-13 14:06:19 UTC (rev 3178) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/votingListHelper.jsp 2012-03-14 09:42:22 UTC (rev 3179) @@ -27,166 +27,230 @@ <script type="text/javascript"> - var votingListText = '<s:text name="pollen.common.votingList"/>'; - var personToListText = '<s:text name="pollen.common.personToList"/>'; +var votingListText = '<s:text name="pollen.common.votingList"/>'; +var personToListText = '<s:text name="pollen.common.personToList"/>'; - function getFirstVotingList(containerId) { - var result = 65535; - getAllVotingLists(containerId).each(function () { - var current = $(this).data('votingListNumber'); - if (current < result) { - result = current; - } - }); - return result; +function getFirstVotingList(containerId) { + var result = 65535; + getAllVotingLists(containerId).each(function () { + var current = $(this).data('votingListNumber'); + if (current < result) { + result = current; + } + }); + return result; +} + +function getLastVotingList(containerId) { + var result = 0; + getAllVotingLists(containerId).each(function () { + var current = $(this).data('votingListNumber'); + if (current > result) { + result = current; + } + }); + return result; +} + +function getAllVotingLists(containerId) { + return $("div[id^='" + containerId + "_']"); +} + +function updateUpdownVotingListActions(containerId) { + getAllVotingLists(containerId).each(function (index) { + var currentVotingListNumber = $(this).data('votingListNumber'); + var labelWidget = $('#' + containerId + "_" + currentVotingListNumber + "_label"); + labelWidget.html(votingListText + ' ' + (index + 1)); + }); +} + +function loadVotingList(containerId, votingListNumber, nbVotingLists, tokenId) { + if (votingListNumber == -1) { + // to add a new votingList, get the new available votingListNumber + votingListNumber = 1 + getLastVotingList(containerId); } - - function getLastVotingList(containerId) { - var result = 0; - getAllVotingLists(containerId).each(function () { - var current = $(this).data('votingListNumber'); - if (current > result) { - result = current; + $.ajax( + { + url:'<s:url namespace="/poll" action="displayVotingList"/>', + data:{ tokenId:tokenId, votingListNumber:votingListNumber }, + async:false, + dataType:"html", + success:function (data, textStatus) { + var container = $("#" + containerId); + container.append(data); + // store votingListNumber + var votingList = $("#" + containerId + "_" + votingListNumber); + votingList.data('votingListNumber', votingListNumber); + votingList.data('votingListContainerId', containerId); + if (votingListNumber == nbVotingLists || !tokenId) { + updateUpdownVotingListActions(containerId); + } } }); - return result; - } +} - function getAllVotingLists(containerId) { - return $("div[id^='" + containerId + "_']"); - } +function addVotingList(votingListNumber, nbVotingLists, tokenId) { + loadVotingList('votingLists', votingListNumber, nbVotingLists, tokenId); +} - function updateUpdownVotingListActions(containerId) { - getAllVotingLists(containerId).each(function (index) { - var currentVotingListNumber = $(this).data('votingListNumber'); - var labelWidget = $('#' + containerId + "_" + currentVotingListNumber + "_label"); - labelWidget.html(votingListText + ' ' + (index + 1)); - }); - } +function addNewVotingList() { + addVotingList(-1, -1); + return false; +} - function loadVotingList(containerId, votingListNumber, nbVotingLists, tokenId) { - if (votingListNumber == -1) { - // to add a new votingList, get the new available votingListNumber - votingListNumber = 1 + getLastVotingList(containerId); +function deleteVotingList(votingListId) { + var votingList = $('#' + votingListId); + var containerId = votingList.data('votingListContainerId'); + votingList.remove(); + updateUpdownVotingListActions(containerId); + return false; +} + +function getFirstPersonToList(containerId) { + var result = 65535; + getAllPersonToLists(containerId).each(function () { + var current = $(this).data('personToListNumber'); + if (current < result) { + result = current; } - $.ajax( - { - url:'<s:url namespace="/poll" action="displayVotingList"/>', - data:{ tokenId:tokenId, votingListNumber:votingListNumber }, - async:false, - dataType:"html", - success:function (data, textStatus) { - var container = $("#" + containerId); - container.append(data); - // store votingListNumber - var votingList = $("#" + containerId + "_" + votingListNumber); - votingList.data('votingListNumber', votingListNumber); - votingList.data('votingListContainerId', containerId); - if (votingListNumber == nbVotingLists || !tokenId) { - updateUpdownVotingListActions(containerId); - } - } - }); - } + }); + return result; +} - function addVotingList(votingListNumber, nbVotingLists, tokenId) { - loadVotingList('votingLists', votingListNumber, nbVotingLists, tokenId); - } +function getLastPersonToList(containerId) { + var result = 0; + getAllPersonToLists(containerId).each(function () { + var current = $(this).data('personToListNumber'); + if (current > result) { + result = current; + } + }); + return result; +} - function addNewVotingList() { - addVotingList(-1, -1); - return false; - } +function getAllPersonToLists(containerId) { + return $("div[id^='" + containerId + "_']"); +} - function deleteVotingList(votingListId) { - var votingList = $('#' + votingListId); - var containerId = votingList.data('votingListContainerId'); - votingList.remove(); - updateUpdownVotingListActions(containerId); - return false; +function getAllPersonToListNumbers(containerId) { + var result = []; + getAllPersonToLists(containerId).each(function () { + var current = $(this).data('personToListNumber'); + result.push(current); + }); + return result; +} + +function getFirstEmptyPersonToList(containerId) { + var result = -1; + var numbers = getAllPersonToListNumbers(containerId); + for (var n in numbers) { + var nameInput = $('[name="' + containerId + '_' + n + '.votingId"]'); + var emailInput = $('[name="' + containerId + '_' + n + '.email"]'); + + var name = nameInput.val(); + var email = emailInput.val(); + if (name == '' && email == '') { + result = n; + break; + } } + return result; +} - function getFirstPersonToList(containerId) { - var result = 65535; - getAllPersonToLists(containerId).each(function () { - var current = $(this).data('personToListNumber'); - if (current < result) { - result = current; - } - }); - return result; +function updateUpdownPersonToListActions(containerId) { + getAllPersonToLists(containerId).each(function (index) { + var currentPersonToListNumber = $(this).data('personToListNumber'); + var labelWidget = $('#' + containerId + "_" + currentPersonToListNumber + "_label"); + labelWidget.html(personToListText + ' ' + (index + 1)); + }); +} + +function loadPersonToList(containerId, votingListNumber, personToListNumber, nbPersonToLists, tokenId) { + if (personToListNumber == -1) { + // to add a new personToList, get the new available personToListNumber + personToListNumber = 1 + getLastPersonToList(containerId); } - - function getLastPersonToList(containerId) { - var result = 0; - getAllPersonToLists(containerId).each(function () { - var current = $(this).data('personToListNumber'); - if (current > result) { - result = current; + $.ajax( + { + url:'<s:url namespace="/poll" action="displayPersonToList"/>', + data:{ + tokenId:tokenId, + votingListNumber:votingListNumber, + personToListNumber:personToListNumber + }, + async:false, + dataType:"html", + success:function (data, textStatus) { + var container = $("#" + containerId); + container.append(data); + // store personToListNumber + var personToList = $("#" + containerId + "_" + personToListNumber); + personToList.data('votingListNumber', votingListNumber); + personToList.data('personToListNumber', personToListNumber); + personToList.data('personToListContainerId', containerId); + if (personToListNumber == nbPersonToLists || !tokenId) { + updateUpdownPersonToListActions(containerId); + } } }); - return result; - } +} - function getAllPersonToLists(containerId) { - return $("div[id^='" + containerId + "_']"); - } +function addPersonToList(votingListNumber, personToListNumber, nbPersonToLists, tokenId) { + loadPersonToList( + 'personToList_' + votingListNumber, + votingListNumber, personToListNumber, nbPersonToLists, tokenId + ); +} - function updateUpdownPersonToListActions(containerId) { - getAllPersonToLists(containerId).each(function (index) { - var currentPersonToListNumber = $(this).data('personToListNumber'); - var labelWidget = $('#' + containerId + "_" + currentPersonToListNumber + "_label"); - labelWidget.html(personToListText + ' ' + (index + 1)); - }); - } +function addNewPersonToList(votingListNumber) { + addPersonToList(votingListNumber, -1, -1); + return false; +} - function loadPerson(containerId, votingListNumber, personToListNumber, nbPersonToLists, tokenId) { - if (personToListNumber == -1) { - // to add a new personToList, get the new available personToListNumber - personToListNumber = 1 + getLastPersonToList(containerId); - } - $.ajax( - { - url:'<s:url namespace="/poll" action="displayPersonToList"/>', - data:{ - tokenId:tokenId, - votingListNumber:votingListNumber, - personToListNumber:personToListNumber - }, - async:false, - dataType:"html", - success:function (data, textStatus) { - var container = $("#" + containerId); - container.append(data); - // store personToListNumber - var personToList = $("#" + containerId + "_" + personToListNumber); - personToList.data('votingListNumber', votingListNumber); - personToList.data('personToListNumber', personToListNumber); - personToList.data('personToListContainerId', containerId); - if (personToListNumber == nbPersonToLists || !tokenId) { - updateUpdownPersonToListActions(containerId); - } - } - }); - } +function deletePersonToList(personToListId) { + var personToList = $('#' + personToListId); + var containerId = personToList.data('personToListContainerId'); + personToList.remove(); + updateUpdownPersonToListActions(containerId); + return false; +} - function addPersonToList(votingListNumber, personToListNumber, nbPersonToLists, tokenId) { - loadPerson( - 'personToList_' + votingListNumber, - votingListNumber, personToListNumber, nbPersonToLists, tokenId - ); - } - function addNewPersonToList(votingListNumber) { - addPersonToList(votingListNumber, -1, -1); - return false; - } +function loadPersonListToVotingList(votingListNumber, personToListNumber, personListId) { - function deletePersonToList(personToListId) { - var personToList = $('#' + personToListId); - var containerId = personToList.data('personToListContainerId'); - personToList.remove(); - updateUpdownPersonToListActions(containerId); - return false; - } + $.ajax( + { + url:'<s:url namespace="/poll" action="displayPersonListToVotingList"/>', + data:{ + votingListNumber:votingListNumber, + personToListNumber:personToListNumber, + personListId:personListId }, + async:false, + dataType:"json", + success:function (data, textStatus) { + var token = data.tokenId; + var nbPersonToLists = parseInt(data.nbPersonToLists); + var personToListNumber = parseInt(data.personToListNumber); + var maxPersonToListNumber = parseInt(personToListNumber) + nbPersonToLists - 1; + console.info(">> token = " + token); + console.info(">> personListId = " + personListId); + console.info(">> incoming votingListNumber = " + votingListNumber); + console.info(">> nb personToList to import = " + nbPersonToLists); + console.info(">> first personToListNumber = " + personToListNumber); + console.info(">> last PersonToListNumber = " + maxPersonToListNumber); + + var index = personToListNumber; + while (index <= maxPersonToListNumber) { + console.info("Will load personToList = " + index + " / " + maxPersonToListNumber); + addPersonToList(votingListNumber, + index, + maxPersonToListNumber, + token + ); + index += 1; + } + } + }); +} </script> \ No newline at end of file
participants (1)
-
tchemit@users.chorem.org