roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gma...@apache.org
Subject svn commit: r1616937 - in /roller/trunk/app/src/main: java/org/apache/roller/weblogger/pojos/ java/org/apache/roller/weblogger/ui/struts2/editor/ resources/ webapp/WEB-INF/ webapp/WEB-INF/jsps/editor/
Date Sat, 09 Aug 2014 12:08:01 GMT
Author: gmazza
Date: Sat Aug  9 12:08:01 2014
New Revision: 1616937

URL: http://svn.apache.org/r1616937
Log:
Consolidation of CategoryAdd and CategoryEdit, various other GUI cleanup.

Removed:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryAdd.java
    roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/CategoryAdd.jsp
Modified:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogCategory.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryBean.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryEdit.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryRemove.java
    roller/trunk/app/src/main/resources/ApplicationResources.properties
    roller/trunk/app/src/main/resources/struts.xml
    roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/BookmarkEdit.jsp
    roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/CategoryEdit.jsp
    roller/trunk/app/src/main/webapp/WEB-INF/tiles.xml

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogCategory.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogCategory.java?rev=1616937&r1=1616936&r2=1616937&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogCategory.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogCategory.java Sat
Aug  9 12:08:01 2014
@@ -61,6 +61,10 @@ public class WeblogCategory implements S
         
         this.weblog = weblog;
         weblog.getWeblogCategories().add(this);
+        calculatePosition();
+    }
+
+    public void calculatePosition() {
         int size = weblog.getWeblogCategories().size();
         if (size == 1) {
             this.position = 0;
@@ -68,17 +72,11 @@ public class WeblogCategory implements S
             this.position = weblog.getWeblogCategories().get(size - 2).getPosition() + 1;
         }
     }
-    
-    
+
     //------------------------------------------------------- Good citizenship
 
     public String toString() {
-        StringBuilder buf = new StringBuilder();
-        buf.append("{");
-        buf.append(getId());
-        buf.append(", ").append(getName());
-        buf.append("}");
-        return buf.toString();
+        return "{" + getId() + ", " + getName() + "}";
     }
     
     @Override
@@ -210,11 +208,4 @@ public class WeblogCategory implements S
         }
     }
 
-    /**
-     * Convenience method for updating the category name
-     */
-    public void updateName(String newName) throws WebloggerException {
-        setName(newName);
-        WebloggerFactory.getWeblogger().getWeblogEntryManager().saveWeblogCategory(this);
-    }
 }

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryBean.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryBean.java?rev=1616937&r1=1616936&r2=1616937&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryBean.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryBean.java
Sat Aug  9 12:08:01 2014
@@ -67,11 +67,7 @@ public class CategoryBean {
     
     
     public void copyTo(WeblogCategory dataHolder) throws WebloggerException {
-        
-        if(!dataHolder.getName().equals(this.name)) {
-            dataHolder.updateName(this.name);
-        }
-        
+        dataHolder.setName(name);
         dataHolder.setDescription(this.description);
         dataHolder.setImage(this.image);
     }

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryEdit.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryEdit.java?rev=1616937&r1=1616936&r2=1616937&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryEdit.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryEdit.java
Sat Aug  9 12:08:01 2014
@@ -34,26 +34,22 @@ import org.apache.struts2.interceptor.va
 
 
 /**
- * Edit an existing Category.
+ * Edit a new or existing weblog category.
  */
 public class CategoryEdit extends UIAction {
     
     private static Log log = LogFactory.getLog(CategoryEdit.class);
     
-    // the category we are editing
+    // the (new or already existing) category we are editing
     private WeblogCategory category = null;
     
     // bean for managing form data
     private CategoryBean bean = new CategoryBean();
-    
-    
+
     public CategoryEdit() {
-        this.actionName = "categoryEdit";
         this.desiredMenu = "editor";
-        this.pageTitle = "categoryForm.edit.title";
     }
 
-
     @Override
     public List<String> requiredWeblogPermissionActions() {
         return Collections.singletonList(WeblogPermission.POST);
@@ -61,13 +57,17 @@ public class CategoryEdit extends UIActi
     
     
     public void myPrepare() {
-        try {
-            WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
-            if(!StringUtils.isEmpty(getBean().getId())) {
-                setCategory(wmgr.getWeblogCategory(getBean().getId()));
+        if (StringUtils.isEmpty(bean.getId())) {
+            // Create and initialize new, not-yet-saved category
+            category = new WeblogCategory();
+            category.setWeblog(getActionWeblog());
+        } else {
+            try {
+                WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
+                category = wmgr.getWeblogCategory(getBean().getId());
+            } catch (WebloggerException ex) {
+                log.error("Error looking up category", ex);
             }
-        } catch (WebloggerException ex) {
-            log.error("Error looking up category", ex);
         }
     }
     
@@ -77,78 +77,59 @@ public class CategoryEdit extends UIActi
      */
     @SkipValidation
     public String execute() {
-        
-        if (getCategory() == null) {
-            addError("Cannot edit null category");
-            return ERROR;
+        if (!isAdd()) {
+            // make sure bean is properly loaded from pojo data
+            getBean().copyFrom(category);
         }
-        
-        // make sure bean is properly loaded from pojo data
-        getBean().copyFrom(getCategory());
-        
         return INPUT;
     }
 
-    
+    private boolean isAdd() {
+        return actionName.equals("categoryAdd");
+    }
+
     /**
      * Save new category.
      */
     public String save() {
-        
-        if(getCategory() == null) {
-            addError("Cannot edit null category");
-            return ERROR;
-        }
-        
-        // validation
         myValidate();
         
         if(!hasActionErrors()) {
             try {
+
                 // copy updated attributes
-                getBean().copyTo(getCategory());
+                getBean().copyTo(category);
 
                 // save changes
                 WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
-                wmgr.saveWeblogCategory(getCategory());
+                wmgr.saveWeblogCategory(category);
                 WebloggerFactory.getWeblogger().flush();
 
                 // notify caches
-                CacheManager.invalidate(getCategory());
+                CacheManager.invalidate(category);
 
-                addMessage("categoryForm.changesSaved");
+                addMessage(isAdd()? "categoryForm.created"
+                        : "categoryForm.changesSaved",
+                        category.getName());
 
+                return SUCCESS;
             } catch(Exception ex) {
                 log.error("Error saving category", ex);
-                addError("categoryForm.error.saving");
+                addError("generic.error.check.logs");
             }
         }
         
         return INPUT;
     }
 
-    /**
-     * Cancel.
-     * 
-     * @return the string
-     */
-    public String cancel() {
-        return CANCEL;
-    }
-    
-    // TODO: validation
     public void myValidate() {
-        
-        // name is required, has max length, no html
-        
         // make sure new name is not a duplicate of an existing category
-        if (!getCategory().getName().equals(bean.getName()) &&
-            getCategory().getWeblog().hasCategory(bean.getName())) {
+        if ((isAdd() || !category.getName().equals(bean.getName())) &&
+            category.getWeblog().hasCategory(bean.getName())) {
             addError("categoryForm.error.duplicateName", bean.getName());
         }
     }
-
-
+/*
     public WeblogCategory getCategory() {
         return category;
     }
@@ -156,7 +137,7 @@ public class CategoryEdit extends UIActi
     public void setCategory(WeblogCategory category) {
         this.category = category;
     }
-
+*/
     public CategoryBean getBean() {
         return bean;
     }

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryRemove.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryRemove.java?rev=1616937&r1=1616936&r2=1616937&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryRemove.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryRemove.java
Sat Aug  9 12:08:01 2014
@@ -93,7 +93,7 @@ public class CategoryRemove extends UIAc
             }
         } catch (WebloggerException ex) {
             log.error("Error building categories list", ex);
-            addError("Error building categories list");
+            addError("generic.error.check.logs");
         }
         return INPUT;
     }
@@ -107,7 +107,7 @@ public class CategoryRemove extends UIAc
             try {
                 WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
 
-                if(getTargetCategoryId() != null) {
+                if (getTargetCategoryId() != null) {
                     WeblogCategory target = wmgr.getWeblogCategory(getTargetCategoryId());
                     wmgr.moveWeblogCategoryContents(getCategory(), target);
                     WebloggerFactory.getWeblogger().flush();
@@ -119,15 +119,11 @@ public class CategoryRemove extends UIAc
 
                 wmgr.removeWeblogCategory(getCategory());
                 WebloggerFactory.getWeblogger().flush();
-
-                // set category id to parent for next page
-                setRemoveId(id);
-
+                addMessage("categoryForm.removed", category.getName());
                 return SUCCESS;
-
             } catch(Exception ex) {
-                log.error("Error removing category - "+getRemoveId(), ex);
-                addError("Error removing category");
+                log.error("Error removing category - " + getRemoveId(), ex);
+                addError("generic.error.check.logs");
             }
         }
         

Modified: roller/trunk/app/src/main/resources/ApplicationResources.properties
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/resources/ApplicationResources.properties?rev=1616937&r1=1616936&r2=1616937&view=diff
==============================================================================
--- roller/trunk/app/src/main/resources/ApplicationResources.properties (original)
+++ roller/trunk/app/src/main/resources/ApplicationResources.properties Sat Aug  9 12:08:01
2014
@@ -48,7 +48,7 @@ bookmarkForm.url=Bookmark URL
 bookmarkForm.created=Bookmark "{0}" created
 bookmarkForm.updated=Bookmark "{0}" updated
 
-bookmarkForm.rootPrompt=Just the {0} and {1} fields are required.
+bookmarkForm.requiredFields=The {0} and {1} fields are required.
 
 # errors from validation
 Bookmark.error.nameNull=Name is a required field
@@ -133,11 +133,11 @@ categoryForm.edit.subtitle=Editing categ
 categoryForm.add.title=Add Category
 categoryForm.add.subtitle=Adding category
 categoryForm.image=Image URL
-categoryForm.created=Category created
-categoryForm.changesSaved=Changes saved
-
-categoryForm.error.duplicateName=The category name ''{0}'' is already in use, you will need
to choose another
-categoryForm.error.saving=Error saving new category
+categoryForm.created=Category "{0}" created
+categoryForm.changesSaved=Category "{0}" updated
+categoryForm.error.duplicateName=Category name "{0}" already in use, please choose another
+categoryForm.removed=Category "{0}" removed
+categoryForm.requiredFields={0} is required.
 
 # errors from validation
 Category.error.nameNull=Name is a required field

Modified: roller/trunk/app/src/main/resources/struts.xml
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/resources/struts.xml?rev=1616937&r1=1616936&r2=1616937&view=diff
==============================================================================
--- roller/trunk/app/src/main/resources/struts.xml (original)
+++ roller/trunk/app/src/main/resources/struts.xml Sat Aug  9 12:08:01 2014
@@ -329,25 +329,26 @@
         </action>
         
         <action name="categoryAdd!*" method="{1}"
-                class="org.apache.roller.weblogger.ui.struts2.editor.CategoryAdd">
-            <result name="input" type="tiles">.CategoryAdd</result>
+                class="org.apache.roller.weblogger.ui.struts2.editor.CategoryEdit">
+            <param name="actionName">categoryAdd</param>
+            <param name="pageTitle">categoryForm.add.title</param>
+            <result name="input" type="tiles">.CategoryEdit</result>
             <result name="success" type="chain">categories</result>
-            <result name="cancel" type="redirectAction">
-                <param name="actionName">categories</param>
-                <param name="weblog">${weblog}</param>
-            </result>
             <result name="error" type="chain">categories</result>
         </action>
         
         <action name="categoryEdit!*" method="{1}"
                 class="org.apache.roller.weblogger.ui.struts2.editor.CategoryEdit">
+            <param name="actionName">categoryEdit</param>
+            <param name="pageTitle">categoryForm.edit.title</param>
             <result name="input" type="tiles">.CategoryEdit</result>
+            <result name="success" type="chain">categories</result>
             <result name="cancel" type="redirectAction">
                 <param name="actionName">categories</param>
                 <param name="weblog">${weblog}</param>
             </result>
         </action>
-        
+
         <action name="categoryRemove!*" method="{1}"
                 class="org.apache.roller.weblogger.ui.struts2.editor.CategoryRemove">
             <result name="input" type="tiles">.CategoryRemove</result>

Modified: roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/BookmarkEdit.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/BookmarkEdit.jsp?rev=1616937&r1=1616936&r2=1616937&view=diff
==============================================================================
--- roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/BookmarkEdit.jsp (original)
+++ roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/BookmarkEdit.jsp Sat Aug  9 12:08:01
2014
@@ -34,7 +34,7 @@
 </p>
 
 <p class="pagetip">
-    <s:text name="bookmarkForm.rootPrompt">
+    <s:text name="bookmarkForm.requiredFields">
         <s:param><s:text name="generic.name"/></s:param>
         <s:param><s:text name="bookmarkForm.url"/></s:param>
     </s:text>
@@ -58,27 +58,27 @@
         
         <tr>
             <td><s:text name="generic.name" /></td>
-            <td><s:textfield name="bean.name" maxlength="255" size="70" /></td>
+            <td><s:textfield name="bean.name" maxlength="255" size="70" style="width:50%"/></td>
         </tr>
         
         <tr>
             <td><s:text name="bookmarkForm.url" /></td>
-            <td><s:textfield name="bean.url" maxlength="255" size="70" /></td>
+            <td><s:textfield name="bean.url" maxlength="255" size="70" style="width:50%"/></td>
         </tr>
         
         <tr>
             <td><s:text name="bookmarkForm.rssUrl" /></td>
-            <td><s:textfield name="bean.feedUrl" maxlength="255" size="70" /></td>
+            <td><s:textfield name="bean.feedUrl" maxlength="255" size="70" style="width:50%"/></td>
         </tr>
         
         <tr>
             <td><s:text name="generic.description" /></td>
-            <td><s:textarea name="bean.description" rows="5" cols="50" /></td>
+            <td><s:textfield name="bean.description" maxlength="255" size="70" style="width:50%"/></td>
         </tr>
 
         <tr>
             <td><s:text name="bookmarkForm.image" /></td>
-            <td><s:textfield name="bean.image" maxlength="255" size="70" /></td>
+            <td><s:textfield name="bean.image" maxlength="255" size="70" style="width:50%"/></td>
         </tr>
         
     </table>

Modified: roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/CategoryEdit.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/CategoryEdit.jsp?rev=1616937&r1=1616936&r2=1616937&view=diff
==============================================================================
--- roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/CategoryEdit.jsp (original)
+++ roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/CategoryEdit.jsp Sat Aug  9 12:08:01
2014
@@ -17,14 +17,33 @@
 --%>
 <%@ include file="/WEB-INF/jsps/taglibs-struts2.jsp" %>
 
+<%-- Titling, processing actions different between add and edit --%>
+<s:if test="actionName == 'categoryEdit'">
+    <s:set var="subtitleKey">categoryForm.edit.subtitle</s:set>
+    <s:set var="mainAction">categoryEdit</s:set>
+</s:if>
+<s:else>
+    <s:set var="subtitleKey">categoryForm.add.subtitle</s:set>
+    <s:set var="mainAction">categoryAdd</s:set>
+</s:else>
+
 <p class="subtitle">
-    <s:text name="categoryForm.edit.subtitle" />
+    <s:text name="%{#subtitleKey}" />
+</p>
+
+<p class="pagetip">
+    <s:text name="categoryForm.requiredFields">
+        <s:param><s:text name="generic.name"/></s:param>
+    </s:text>
 </p>
 
 <s:form action="categoryEdit!save">
     <s:hidden name="salt" />
     <s:hidden name="weblog" />
-    <s:hidden name="bean.id" />
+    <s:if test="actionName == 'categoryEdit'">
+        <%-- bean for add does not have a bean id yet --%>
+        <s:hidden name="bean.id" />
+    </s:if>
 
     <table>
         
@@ -35,18 +54,18 @@
         
         <tr>
             <td><s:text name="categoryForm.image" /></td>
-            <td><s:textfield name="bean.image" size="120" style="width:80%"/></td>
+            <td><s:textfield name="bean.image" size="120" style="width:50%"/></td>
         </tr>
 
         <tr>
             <td><s:text name="generic.description" /></td>
-            <td><s:textarea name="bean.description" rows="5" cols="50" style="width:50%"/></td>
+            <td><s:textfield name="bean.description" size="120" style="width:50%"/></td>
         </tr>
 
     </table>
     
     <p>
-        <s:submit value="%{getText('generic.save')}" />
+        <s:submit value="%{getText('generic.save')}" action="%{#mainAction}!save"/>
         <s:submit value="%{getText('generic.cancel')}" action="categoryEdit!cancel" />
     </p>
     

Modified: roller/trunk/app/src/main/webapp/WEB-INF/tiles.xml
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/webapp/WEB-INF/tiles.xml?rev=1616937&r1=1616936&r2=1616937&view=diff
==============================================================================
--- roller/trunk/app/src/main/webapp/WEB-INF/tiles.xml (original)
+++ roller/trunk/app/src/main/webapp/WEB-INF/tiles.xml Sat Aug  9 12:08:01 2014
@@ -317,11 +317,6 @@
         <put-attribute name="styles" value="/WEB-INF/jsps/tiles/css-sidebar.jsp" />
     </definition>
     
-    <definition name=".CategoryAdd" extends=".tiles-tabbedpage" >
-        <put-attribute name="content" value="/WEB-INF/jsps/editor/CategoryAdd.jsp" />
-        <put-attribute name="styles" value="/WEB-INF/jsps/tiles/css-nosidebar.jsp" />
-    </definition>
-    
     <definition name=".CategoryEdit" extends=".tiles-tabbedpage" >
         <put-attribute name="content" value="/WEB-INF/jsps/editor/CategoryEdit.jsp" />
         <put-attribute name="styles" value="/WEB-INF/jsps/tiles/css-nosidebar.jsp" />



Mime
View raw message