Author: soh...@jb... Date: 2006-05-04 10:05:38 -0400 (Thu, 04 May 2006) New Revision: 4089 Added: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/DeletePost.java labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/delete_post.xhtml Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml Log: http://jira.jboss.com/jira/browse/JBFORUMS-70 - Delete a Post Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java 2006-05-04 13:12:55 UTC (rev 4088) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java 2006-05-04 14:05:38 UTC (rev 4089) @@ -35,6 +35,7 @@ public static final String START_REPLY = "startReply"; public static final String START_NEW_TOPIC = "startNewTopic"; public static final String START_EDIT_POST = "startEditPost"; + public static final String TOPIC_DELETED = "topicDeleted"; //---------parameter constants-------------------------------------------------------------------------------------------------- public static final String p_categoryId = "c"; public static final String p_forumId = "f"; Added: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/DeletePost.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/DeletePost.java 2006-05-04 13:12:55 UTC (rev 4088) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/DeletePost.java 2006-05-04 14:05:38 UTC (rev 4089) @@ -0,0 +1,118 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +package org.jboss.portlet.forums.ui.action; + +import org.jboss.portlet.forums.ui.BaseController; +import org.jboss.portlet.forums.ui.Constants; +import org.jboss.portlet.forums.ui.ForumUtil; +import org.jboss.portlet.forums.ui.JSFUtil; + +import org.jboss.portlet.forums.model.Forum; +import org.jboss.portlet.forums.model.Topic; +import org.jboss.portlet.forums.model.Post; + + +/* + * Created on May 3, 2006 + * + * @author <a href="mailto:soh...@jb...">Sohil Shah</a> + */ +public class DeletePost extends ActionController +{ + //---------------------------------------------------------------------------------------------------------------------------------- + /** + * + * + */ + public DeletePost() + { + + } + //actions--------------------------------------------------------------------------------------------------------------------------------- + /** + * + */ + public String confirmDelete() + { + String navState = null; + try + { + //get the post id + int postId = -1; + String p = ForumUtil.getParameter(Constants.p_postId); + if(p!=null && p.trim().length()>0) + { + postId = Integer.parseInt(p); + } + + //setup the business objects/data of interest + Post post = BaseController.getForumsModule().findPostById(new Integer(postId)); + Topic topic = post.getTopic(); + Forum forum = topic.getForum(); + boolean isFirstPost = false; + boolean isLastPost = false; + if(topic.getFirstPost().getId().intValue()==post.getId().intValue()) + { + isFirstPost = true; + } + if(topic.getLastPost().getId().intValue()==post.getId().intValue()) + { + isLastPost = true; + } + + //now perform the actual delete operation......................... + if (isLastPost && isFirstPost) + { + // cascade delete will take care of removing + // the post + // the watches + // the poll + // the links + this.getForumsModule().removeTopic(post.getTopic()); + forum.setPostCount(forum.getPostCount() - 1); + forum.setTopicCount(forum.getTopicCount() - 1); + + //set the proper navigation state + navState = Constants.TOPIC_DELETED; + } + else + { + this.getForumsModule().removePost(post); + topic.setReplies(topic.getReplies() - 1); + forum.setPostCount(forum.getPostCount() - 1); + if(isLastPost) + { + Post lastPost = this.getForumsModule().findLastPost(topic); + topic.setLastPostDate(lastPost.getCreateDate()); + } + + //set the proper navigation state + navState = Constants.SUCCESS; + } + } + catch(Exception e) + { + JSFUtil.handleException(e); + } + return navState; + } +} Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-05-04 13:12:55 UTC (rev 4088) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-05-04 14:05:38 UTC (rev 4089) @@ -9,8 +9,8 @@ <!-- general application configuration --> <application> <!-- jbossportal-facelets integration --> - <property-resolver>org.jboss.portal.faces.el.DelegatingPropertyResolver</property-resolver> - <view-handler>com.sun.facelets.FaceletPortletViewHandler</view-handler> + <!--property-resolver>org.jboss.portal.faces.el.DelegatingPropertyResolver</property-resolver> + <view-handler>com.sun.facelets.FaceletPortletViewHandler</view-handler--> <!-- standalone facelets integration --> <!--view-handler>com.sun.facelets.FaceletViewHandler</view-handler--> @@ -258,4 +258,23 @@ <managed-bean-class>org.jboss.portlet.forums.ui.action.ModeratorAction</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> + + <!-- managedBean for deletePost usecase --> + <managed-bean> + <managed-bean-name>deletePost</managed-bean-name> + <managed-bean-class>org.jboss.portlet.forums.ui.action.DeletePost</managed-bean-class> + <managed-bean-scope>request</managed-bean-scope> + </managed-bean> + <navigation-rule> + <from-view-id>/views/topics/delete_post.xhtml</from-view-id> + <!-- represents delete of the selected post was successfull --> + <navigation-case> + <from-outcome>success</from-outcome> + <to-view-id>/views/topics/viewtopic_body.xhtml</to-view-id> + </navigation-case> + <navigation-case> + <from-outcome>topicDeleted</from-outcome> + <to-view-id>/views/forums/viewforum_body.xhtml</to-view-id> + </navigation-case> + </navigation-rule> </faces-config> \ No newline at end of file Added: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/delete_post.xhtml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/delete_post.xhtml 2006-05-04 13:12:55 UTC (rev 4088) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/delete_post.xhtml 2006-05-04 14:05:38 UTC (rev 4089) @@ -0,0 +1,64 @@ +<!-- +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +--> + +<div xmlns="http://www.w3.org/1999/xhtml" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:c="http://java.sun.com/jstl/core" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:t="http://myfaces.apache.org/tomahawk" + xmlns:forums="http://www.jboss.com/products/jbossportal/forums" + class="bb" +> + +<ui:composition template="/views/common/common.xhtml"> +<ui:define name="mainContent"> + + <table class="forumline" width="100%" cellspacing="1" cellpadding="3" border="0"> + <tr> + <th class="thHead" height="25" valign="middle"><span class="tableTitle">Information</span></th> + </tr> + <tr> + <td class="row1" align="center"> + <h:form> + <span class="gen"><br/> + Are you sure you want to delete this post? + <br/><br/> + <input type="hidden" name="p" value="#{param['p']}"/> + <input type="hidden" name="t" value="#{param['t']}"/> + <input type="hidden" name="f" value="#{param['f']}"/> + <h:commandButton type="submit" value="Yes" styleClass="mainoption" action="#{deletePost.confirmDelete}"/> + &nbsp;&nbsp; + <h:commandButton type="button" value="No" styleClass="liteoption" onclick="javascript:history.back();"/> + </span> + </h:form> + </td> + </tr> + </table> + + +</ui:define> +</ui:composition> + +</div> \ No newline at end of file Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml 2006-05-04 13:12:55 UTC (rev 4088) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml 2006-05-04 14:05:38 UTC (rev 4089) @@ -228,6 +228,17 @@ alt="${resource.Reply_to_topic}" /> </f:verbatim> </h:commandLink> + <!-- add the delete post link --> + <h:outputLink value="#{forums:outputLink('/views/topics/delete_post.jsf',true)}" style="text-decoration: none;"> + <f:param name="p" value="#{postrow.id}"/> + <f:param name="t" value="#{topic.topic.id}"/> + <f:param name="f" value="#{topic.topic.forum.id}"/> + <f:verbatim> + <img border="0" + src="#{forums:themeURL('resourceReplyLockedURL')}" + alt="${resource.Topic_locked}" /> + </f:verbatim> + </h:outputLink> </td> </tr> <tr> |