Author: unibrew Date: 2006-05-27 21:58:08 -0400 (Sat, 27 May 2006) New Revision: 4456 Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.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/moderator/delete_topic.xhtml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml Log: [JBFORUMS-43] Deleting, Locking and Unlocking topic in moderator's panel work. Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java 2006-05-27 20:13:08 UTC (rev 4455) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java 2006-05-28 01:58:08 UTC (rev 4456) @@ -142,49 +142,40 @@ //ui actions supported by this bean---------------------------------------------------------------------------------------------------- - //TODO: STILL NOT FINISHED public String deleteTopic () { Iterator it = checkboxes.keySet().iterator(); - - // This flag checks if there was at least one topic selected - boolean isAnySet=false; - - String message=""; - + String message=""; try { while (it.hasNext()) { Integer topicId = (Integer)it.next(); - boolean value = ((Boolean)checkboxes.get(topicId)).booleanValue(); - if ( value ) isAnySet=true; + boolean value = ((Boolean)checkboxes.get(topicId)).booleanValue(); - try { - Topic topic = getForumsModule().findTopicById(topicId); - //this.getForumsModule().removeTopic(topic); + try { + if (value) + { + Topic topic = getForumsModule().findTopicById(topicId); + this.getForumsModule().removeTopic(topic); + } } catch(Exception e) { message = bundle.getString("ERR_CANNOT_REMOVE_TOPIC"); FacesContext.getCurrentInstance().addMessage("message", new FacesMessage(FacesMessage.SEVERITY_ERROR,message,"moderate")); - return ""; + return "success"; } } - if (!isAnySet) - { - //message = bundle.getString(""); - FacesContext.getCurrentInstance().addMessage("message", - new FacesMessage(FacesMessage.SEVERITY_WARN,"Hey","ehhh")); - return ""; - } message = bundle.getString("SUCC_TOPIC_REMOVED"); FacesContext.getCurrentInstance().addMessage("message", new FacesMessage(FacesMessage.SEVERITY_INFO,message, "moderate")); + this.forum = BaseController.getForumsModule().findForumById(forum.getId()); + checkboxes=new HashMap(); } catch (Exception e) { JSFUtil.handleException(e); } - return ""; + return "success"; } public String moveTopic () @@ -192,41 +183,122 @@ return ""; } - //TODO: STILL NOT FINISHED public String lockTopic () { - Iterator it = checkboxes.keySet().iterator(); + if (isAnyCheckboxSelected()) + { + Iterator it = checkboxes.keySet().iterator(); + String message=""; + try { + while (it.hasNext()) + { + Integer topicId = (Integer)it.next(); + boolean value = ((Boolean)checkboxes.get(topicId)).booleanValue(); + + try { + if (value) + { + Topic topic = getForumsModule().findTopicById(topicId); + topic.setStatus(Constants.TOPIC_LOCKED); + } + } catch(Exception e) + { + message = bundle.getString("ERR_INTERNAL"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_ERROR,message,"moderate")); + return ""; + } + } + message = bundle.getString("SUCC_TOPIC_LOCKED"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_INFO,message, "moderate")); + this.forum = BaseController.getForumsModule().findForumById(forum.getId()); + checkboxes=new HashMap(); + } catch (Exception e) + { + JSFUtil.handleException(e); + } + return ""; + } else + { + String message = bundle.getString("None_selected"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_ERROR,message,"moderate")); + return ""; + } - // This flag checks if there was at least one topic selected - boolean isAnySet=false; - while (it.hasNext()) + } + + public String unlockTopic () + { + if (isAnyCheckboxSelected()) { - Integer topicId = (Integer)it.next(); - boolean value = ((Boolean)checkboxes.get(topicId)).booleanValue(); - if ( value ) isAnySet=true; - + Iterator it = checkboxes.keySet().iterator(); + String message=""; try { - Topic topic = getForumsModule().findTopicById(topicId); - //this.getForumsModule().removeTopic(topic); - } catch(Exception e) + while (it.hasNext()) + { + Integer topicId = (Integer)it.next(); + boolean value = ((Boolean)checkboxes.get(topicId)).booleanValue(); + + try { + if (value) + { + Topic topic = getForumsModule().findTopicById(topicId); + topic.setStatus(Constants.TOPIC_UNLOCKED); + } + } catch(Exception e) + { + message = bundle.getString("ERR_INTERNAL"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_ERROR,message,"moderate")); + return ""; + } + } + message = bundle.getString("SUCC_TOPIC_UNLOCKED"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_INFO,message, "moderate")); + this.forum = BaseController.getForumsModule().findForumById(forum.getId()); + checkboxes=new HashMap(); + } catch (Exception e) { - FacesContext.getCurrentInstance().addMessage("message", - new FacesMessage(FacesMessage.SEVERITY_ERROR,"moderate","ERR_CANNOT_REMOVE_TOPIC")); - return ""; - } + JSFUtil.handleException(e); + } + return ""; + } else + { + String message = bundle.getString("None_selected"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_ERROR,message,"moderate")); + return ""; } - if (!isAnySet) + } + + public String deleteConfirm() + { + if (isAnyCheckboxSelected()) { + return "confirmDelete"; + } else + { + String message = bundle.getString("None_selected"); FacesContext.getCurrentInstance().addMessage("message", - new FacesMessage(FacesMessage.SEVERITY_WARN,"","ehhh")); + new FacesMessage(FacesMessage.SEVERITY_ERROR,message,"moderate")); return ""; } - return ""; } - public String unlockTopic () + private boolean isAnyCheckboxSelected() { - return ""; + Iterator it = checkboxes.keySet().iterator(); + while (it.hasNext()) + { + if (((Boolean)checkboxes.get(it.next())).booleanValue()) + { + return true; + } + } + return false; } private void execute() throws Exception @@ -243,17 +315,13 @@ if(f!=null && f.trim().length()>0) { forumId = Integer.parseInt(f); - } + } + System.out.println("FORUMID: "+forumId); if(forumId!=-1) { // start with a stub implementation this.forum = BaseController.getForumsModule().findForumById(new Integer(forumId)); checkboxes=new HashMap(); - Iterator it = forum.getTopics().iterator(); - while (it.hasNext()) - { - Topic topic = (Topic)it.next(); - } } } 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-27 20:13:08 UTC (rev 4455) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-05-28 01:58:08 UTC (rev 4456) @@ -284,11 +284,11 @@ <navigation-rule> <from-view-id>/views/moderator/modcp_body.xhtml</from-view-id> <navigation-case> - <from-outcome>delete</from-outcome> + <from-outcome>confirmDelete</from-outcome> <to-view-id>/views/moderator/delete_topic.xhtml</to-view-id> </navigation-case> <navigation-case> - <from-outcome>move</from-outcome> + <from-outcome>confirmMove</from-outcome> <to-view-id>/views/moderator/move_topic.xhtml</to-view-id> </navigation-case> </navigation-rule> @@ -297,7 +297,7 @@ <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/views/moderator/modcp_body.xhtml</to-view-id> - </navigation-case> + </navigation-case> </navigation-rule> <!-- managedBean for deletePost usecase --> Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/delete_topic.xhtml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/delete_topic.xhtml 2006-05-27 20:13:08 UTC (rev 4455) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/delete_topic.xhtml 2006-05-28 01:58:08 UTC (rev 4456) @@ -44,12 +44,14 @@ <h:form> <span class="gen"><br/> ${resource.Topic_delete_confirm} - <br/><br/> - <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="#{deleteTopic.confirmDelete}"/> + <br/><br/> + <h:commandButton type="submit" value="Yes" styleClass="mainoption" action="#{moderator.deleteTopic}"> + <f:param name="f" value="#{moderator.forum.id}"/> + </h:commandButton> &nbsp;&nbsp; - <h:commandButton type="button" value="No" styleClass="liteoption" onclick="javascript:history.back();"/> + <h:commandButton type="button" value="No" styleClass="liteoption" onclick="javascript:history.back();"> + <f:param name="f" value="#{moderator.forum.id}"/> + </h:commandButton> </span> </h:form> </td> Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml 2006-05-27 20:13:08 UTC (rev 4455) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml 2006-05-28 01:58:08 UTC (rev 4456) @@ -74,11 +74,11 @@ <tr align="right"> <td class="catBottom" colspan="5" height="29"> - <h:commandButton action="delete" class="liteoption" value="${resource.Delete}"> + <h:commandButton action="#{moderator.deleteConfirm}" class="liteoption" value="${resource.Delete}"> <f:param name="f" value="#{forum.forum.id}"/> </h:commandButton> &nbsp; - <h:commandButton action="move" class="liteoption" value="${resource.Move}"> + <h:commandButton action="#{moveConfirm}" class="liteoption" value="${resource.Move}"> <f:param name="f" value="#{forum.forum.id}"/> </h:commandButton> &nbsp; |