r3235 - in branches/pollen-1.2.6-struts2: pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll pollen-ui-struts2/src/main/webapp/WEB-INF/decorators pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll
Author: fdesbois Date: 2012-04-05 09:50:52 +0200 (Thu, 05 Apr 2012) New Revision: 3235 Url: http://chorem.org/repositories/revision/pollen/3235 Log: - start implement updatePoll (not working yet) - add disabled when vote is started (missing disabled for votingList and choice) Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-05 07:50:42 UTC (rev 3234) +++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-05 07:50:52 UTC (rev 3235) @@ -214,43 +214,9 @@ if (!poll.isChoiceEmpty()) { // create choices - -// ChoiceType choiceType = result.getChoiceType(); -// -// ChoiceDAO choiceDAO = getDAO(Choice.class); -// for (Choice choice : poll.getChoice()) { addChoice(result, choice); -// -// Choice choiceCreated = create(choiceDAO); -// result.addChoice(choiceCreated); -// -// if (choiceType == ChoiceType.IMAGE) { -// -// // copy image where it belong and generate the thumb -// -// PollImageChoice imageChoice = (PollImageChoice) choice; -// imageChoice.toChoice(choiceCreated); -// try { -// saveImages(result, imageChoice); -// } catch (IOException e) { -// throw new PollenTechnicalException( -// "Could not create image choice", e); -// } -// } else if (choiceType == ChoiceType.DATE) { -// -// // date choice -// -// PollDateChoice dateChoice = (PollDateChoice) choice; -// dateChoice.toChoice(choiceCreated); -// } else { -// -// // text choice -// choiceCreated.setDescription(choice.getDescription()); -// choiceCreated.setValidate(choice.isValidate()); -// choiceCreated.setName(choice.getName()); -// } } } @@ -269,7 +235,72 @@ return result; } + + public void updatePoll(Poll poll) throws PollNotFoundException { + +// Poll result; +// try { +// +// PollDAO dao = getDAO(Poll.class); +// +// if (!dao.existByTopiaId(poll.getTopiaId())) { +// throw new PollNotFoundException(); +// } +// +// result = dao.update(poll); +// +// } catch (TopiaException e) { +// throw new PollenTechnicalException("Can't update poll [" + poll.getTopiaId() + "]", e); +// } +// return result; + + Poll pollToUpdate = getEntityById(Poll.class, poll.getTopiaId()); + if (pollToUpdate == null) { + throw new PollNotFoundException(); + } + + PollenBinderHelper.copy("", poll, pollToUpdate, false); + + // -- Creator -- // + PollAccount creator = poll.getCreator(); + PollAccount creatorToUpdate = pollToUpdate.getCreator(); + creatorToUpdate.setUserAccount(creator.getUserAccount()); + creatorToUpdate.setVotingId(creator.getVotingId()); + creatorToUpdate.setEmail(creator.getEmail()); + pollToUpdate.setCreator(creatorToUpdate); + + // -- Choices -- // + pollToUpdate.clearChoice(); + for (Choice choice : poll.getChoice()) { + addChoice(pollToUpdate, choice); + } + + // -- PreventRules -- // + + // We assume that all previous preventRules will be deleted + pollToUpdate.clearPreventRule(); + + // Create the new preventRules + PreventRuleDAO preventRuleDAO = getDAO(PreventRule.class); + for (PreventRule preventRule : poll.getPreventRule()) { + PreventRule preventRuleCreated = create(preventRuleDAO); + preventRuleCreated.setActive(preventRule.isActive()); + preventRuleCreated.setMethod(preventRule.getMethod()); + preventRuleCreated.setOneTime(preventRule.isOneTime()); + preventRuleCreated.setRepeated(preventRule.isRepeated()); + preventRuleCreated.setScope(preventRule.getScope()); + preventRuleCreated.setSensibility(preventRule.getSensibility()); + pollToUpdate.addPreventRule(preventRuleCreated); + } + + // -- VotingLists -- // + pollToUpdate.clearVotingList(); + for (VotingList votingList : poll.getVotingList()) { + addVotingList(pollToUpdate, votingList); + } + } + public String getPollVoteUrl(Poll poll) { URL applicationUrl = serviceContext.getApplicationURL(); StringBuilder url = new StringBuilder(applicationUrl.toString()); @@ -603,15 +634,20 @@ ChoiceType choiceType = poll.getChoiceType(); ChoiceDAO dao = getDAO(Choice.class); - Choice choiceCreated = create(dao); - poll.addChoice(choiceCreated); + Choice choiceLoaded; + if (choice.getTopiaId() == null) { + choiceLoaded = create(dao); + } else { + choiceLoaded = getEntityById(Choice.class, choice.getTopiaId()); + } + poll.addChoice(choiceLoaded); if (choiceType == ChoiceType.IMAGE) { // copy image where it belong and generate the thumb PollImageChoice imageChoice = (PollImageChoice) choice; - imageChoice.toChoice(choiceCreated); + imageChoice.toChoice(choiceLoaded); try { saveImages(poll, imageChoice); } catch (IOException e) { @@ -624,14 +660,14 @@ // date choice PollDateChoice dateChoice = (PollDateChoice) choice; - dateChoice.toChoice(choiceCreated); + dateChoice.toChoice(choiceLoaded); } else { // text choice - choiceCreated.setDescription(choice.getDescription()); - choiceCreated.setValidate(choice.isValidate()); - choiceCreated.setName(choice.getName()); + choiceLoaded.setDescription(choice.getDescription()); + choiceLoaded.setValidate(choice.isValidate()); + choiceLoaded.setName(choice.getName()); } } @@ -830,7 +866,58 @@ // ContextUtil.doFinally(transaction); // } } + + protected void addVotingList(Poll poll, VotingList votingList) { + + VotingListDAO votingListDAO = getDAO(VotingList.class); + PersonToListDAO personToListDAO = getDAO(PersonToList.class); + PollAccountDAO pollAccountDAO = getDAO(PollAccount.class); + // Prepare the VotingList and add it to the poll + VotingList votingListLoaded; + if (votingList.getTopiaId() == null) { + votingListLoaded = create(votingListDAO); + } else { + votingListLoaded = getEntityById(VotingList.class, votingList.getTopiaId()); + } + poll.addVotingList(votingListLoaded); + + votingListLoaded.setName(votingList.getName()); + votingListLoaded.setWeight(votingList.getWeight()); + + // Merge PersonToList + for (PersonToList personToList : votingList.getPollAccountPersonToList()) { + + PersonToList personToListLoaded; + if (personToList.getTopiaId() == null) { + personToListLoaded = create(personToListDAO); + } else { + personToListLoaded = getEntityById(PersonToList.class, personToList.getTopiaId()); + } + +// personToListLoaded.setHasVoted(personToList.isHasVoted()); + personToListLoaded.setWeight(personToList.getWeight()); + + PollAccount pollAccount = personToList.getPollAccount(); + PollAccount pollAccountLoaded = personToListLoaded.getPollAccount(); + + // Create the pollAccount if not exists + if (pollAccountLoaded == null) { + pollAccountLoaded = create(pollAccountDAO); + pollAccountLoaded.setAccountId(pollAccount.getAccountId()); + personToListLoaded.setPollAccount(pollAccountLoaded); + } + + pollAccountLoaded.setEmail(pollAccount.getEmail()); +// pollAccountLoaded.setUserAccount(pollAccount.getUserAccount()); + pollAccountLoaded.setVotingId(pollAccount.getVotingId()); + + // The model doesn't have any composition for this relation, the link must be set in both objects + personToListLoaded.setVotingList(votingListLoaded); + votingListLoaded.addPollAccountPersonToList(personToListLoaded); + } + } + /** * Création d'une miniature. * Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-05 07:50:42 UTC (rev 3234) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-05 07:50:52 UTC (rev 3235) @@ -776,7 +776,7 @@ return result2; } - private String getNonEmptyParameterValue(String paramName) { + protected String getNonEmptyParameterValue(String paramName) { String[] paramValues = parameters.get(paramName); String result = null; if (paramValues != null && paramValues.length == 1) { Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-05 07:50:42 UTC (rev 3234) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/LoadPoll.java 2012-04-05 07:50:52 UTC (rev 3235) @@ -143,11 +143,15 @@ PollAccount pollAccount = input.getPollAccount(); String prefix = String.format(PREFIX_PERSON_TO_LIST, votingListIndex, index); + String accountId; if (!clone) { putParameter(prefix, PersonToList.TOPIA_ID, input.getTopiaId()); + accountId = pollAccount.getAccountId(); + } else { + accountId = serviceContext.createPollenUrlId(); } putParameter(prefix, PersonToList.PROPERTY_WEIGHT, String.valueOf(input.getWeight())); - putParameter(prefix, PollAccount.PROPERTY_ACCOUNT_ID, pollAccount.getAccountId()); + putParameter(prefix, PollAccount.PROPERTY_ACCOUNT_ID, accountId); putParameter(prefix, PollAccount.PROPERTY_VOTING_ID, pollAccount.getVotingId()); putParameter(prefix, PollAccount.PROPERTY_EMAIL, pollAccount.getEmail()); Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-05 07:50:42 UTC (rev 3234) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-05 07:50:52 UTC (rev 3235) @@ -61,6 +61,8 @@ private static final Log log = LogFactory.getLog(SavePoll.class); private String userId; + + private String pollId; public void setUserId(String userId) { this.userId = userId; @@ -68,14 +70,22 @@ @Override protected Poll initPoll() { - UserAccount userAccount = getPollenUserAccount(); - Poll result = getPollService().getNewPoll(userAccount); + Poll result; + if (pollId != null) { + result = getPollService().getEntityById(Poll.class, pollId); + + } else { + UserAccount userAccount = getPollenUserAccount(); + result = getPollService().getNewPoll(userAccount); + } return result; } @Override public void prepare() throws Exception { + pollId = getNonEmptyParameterValue("poll.topiaId"); + prepareFormPage(); } @@ -150,6 +160,11 @@ public String execute() throws Exception { Poll poll = getPoll(); + + // Clear previous collections to save those from the form + poll.clearChoice(); + poll.clearPreventRule(); + poll.clearVotingList(); // Load userAccount from the form if (!isCreatorUserAccountDefined() && StringUtils.isNotBlank(userId)) { @@ -200,7 +215,7 @@ } if (isEdit()) { -// service.createPoll(poll); + service.updatePoll(poll); } else { service.createPoll(poll); Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp 2012-04-05 07:50:42 UTC (rev 3234) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp 2012-04-05 07:50:52 UTC (rev 3235) @@ -166,7 +166,7 @@ <div class="top_left${pageLogo}"></div> <ul class="top_middle${pageLogo}"> <li> - <s:a action="create" method="input" namespace="/poll"> + <s:a action="create" namespace="/poll"> <s:text name="pollen.menu.createPoll"/> </s:a> </li> Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-05 07:50:42 UTC (rev 3234) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-05 07:50:52 UTC (rev 3235) @@ -209,14 +209,14 @@ <fieldset> <legend><s:text name="pollen.common.voteCountingType"/></legend> <s:radio key='poll.voteCountingType' list="voteCountingTypes" - label='' theme="simple"/> + label='' theme="simple" disabled="%{voteStarted}"/> </fieldset> <br/> <fieldset> <legend><s:text name="pollen.fieldset.poll.choices"/></legend> <s:radio key='poll.choiceType' list="choiceTypes" label='' - theme="simple"/> + theme="simple" disabled="%{voteStarted}"/> <hr/> <s:fielderror fieldName="poll.choices"/> @@ -231,7 +231,7 @@ </div> <hr/> <s:submit key="pollen.action.addChoice" align="center" - onclick="return addNewChoice();"/> + onclick="return addNewChoice();" disabled="%{voteStarted}"/> </fieldset> </div> @@ -257,15 +257,15 @@ <legend><s:text name="pollen.fieldset.poll.options"/></legend> <s:checkbox key="poll.anonymous" - label="%{getText('pollen.common.pollOption.anonymous')}"/> + label="%{getText('pollen.common.pollOption.anonymous')}" disabled="%{voteStarted}"/> <s:checkbox key="poll.anonymousVoteAllowed" - label="%{getText('pollen.common.pollOption.anonymousVoteAllowed')}"/> + label="%{getText('pollen.common.pollOption.anonymousVoteAllowed')}" disabled="%{voteStarted}"/> <s:checkbox key="poll.continuousResults" label="%{getText('pollen.common.pollOption.continuousResults')}"/> <s:checkbox key="poll.publicResults" label="%{getText('pollen.common.pollOption.publicResults')}"/> <s:checkbox key="poll.choiceAddAllowed" - label="%{getText('pollen.common.pollOption.choiceAddAllowed')}"/> + label="%{getText('pollen.common.pollOption.choiceAddAllowed')}" disabled="%{voteStarted}"/> <div id='addChoiceAddAllowedPanel' class="hidden"> <sj:datepicker key="poll.beginChoiceDate" label="%{getText('pollen.common.beginChoiceDate')}" @@ -275,7 +275,7 @@ displayFormat="dd/mm/yy"/> </div> <s:checkbox key="limitChoice" - label="%{getText('pollen.common.pollOption.limitChoice')}"/> + label="%{getText('pollen.common.pollOption.limitChoice')}" disabled="%{voteStarted}"/> <div id='maxChoiceNbPanel' class="hidden"> <s:textfield key="poll.maxChoiceNb" label="%{getText('pollen.common.pollOption.maxChoiceNb')}"/> @@ -295,7 +295,7 @@ <legend><s:text name="pollen.fieldset.poll.general"/></legend> <sj:datepicker key="poll.beginDate" displayFormat="dd/mm/yy" - label="%{getText('pollen.common.beginDate')}"/> + label="%{getText('pollen.common.beginDate')}" disabled="%{voteStarted}"/> <sj:datepicker key="poll.endDate" displayFormat="dd/mm/yy" label="%{getText('pollen.common.endDate')}"/> </fieldset> @@ -304,7 +304,7 @@ <fieldset> <legend><s:text name="pollen.common.pollType"/></legend> <s:radio key='poll.pollType' list="pollTypes" - label='%{getText("pollen.common.pollType")}'/> + label='%{getText("pollen.common.pollType")}' disabled="%{voteStarted}"/> <hr/> <div class="restrictedPoll"> <div id="votingLists"> @@ -312,11 +312,11 @@ </div> <div class="groupPoll" align="center"> <s:submit key="pollen.action.addVotingList" theme="simple" - onclick="return addNewVotingList();"/> + onclick="return addNewVotingList();" disabled="%{voteStarted}"/> <s:if test="userLoggued"> <s:submit key="pollen.action.addVotingListFromPersonList" theme="simple" - onclick="return selectPersonListToCreateNewVotingList();"/> + onclick="return selectPersonListToCreateNewVotingList();" disabled="%{voteStarted}"/> </s:if> </div> </div> @@ -327,12 +327,6 @@ <br/> <s:submit action="save" key="pollen.action.savePoll" value="%{actionLabel}" align="center"/> - - <!--<div id="wwctrl_registerForm_pollen_action_<s:property value='%{actionLabel}'/>Poll" align="center"> - <input type="submit" id="registerForm_pollen_action_<s:property value='%{actionLabel}'/>Poll" - name="action:<s:property value='%{actionName}'/>" - value="<s:text name='pollen.action.%{actionLabel}Poll'/>"/> - </div>--> </s:form> <script type="text/javascript">
participants (1)
-
fdesbois@users.chorem.org