Author: chathura
Date: Tue Jan 15 08:57:37 2008
New Revision: 12283
Log:
Implemented AJAX based commenting UI.
Added:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/CommentsUtil.java
trunk/registry/modules/webapps/src/main/webapp/admin/ajax/comment-list.jsp
Modified:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
Modified:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
==============================================================================
---
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
(original)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
Tue Jan 15 08:57:37 2008
@@ -254,18 +254,26 @@
} else if (command.equals("/addComment")) {
- CommentAction commentAction = new CommentAction();
- commentAction.setPath(path);
- commentAction.setCommentText(request.getParameter("comment"));
-
try {
- commentAction.execute(request);
+ CommentsUtil.addComment(request, response);
} catch (Exception e) {
+ // todo: implement a general AJAX error segment
setErrorMessage(request, e.getMessage());
- e.printStackTrace();
+ forwardToResources(request, response, path);
}
- response.sendRedirect("/wso2registry/web" + path);
+ //CommentAction commentAction = new CommentAction();
+ //commentAction.setPath(path);
+
//commentAction.setCommentText(request.getParameter("comment"));
+ //
+ //try {
+ // commentAction.execute(request);
+ //} catch (Exception e) {
+ // setErrorMessage(request, e.getMessage());
+ // e.printStackTrace();
+ //}
+ //
+ //response.sendRedirect("/wso2registry/web" + path);
//forwardToResources(request, response, path);
} else if (command.equals("/setProperty")) {
Modified:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
==============================================================================
---
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
(original)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
Tue Jan 15 08:57:37 2008
@@ -29,6 +29,7 @@
public static final String VERSIONS_BEAN = "versions.bean";
public static final String AJAX_RATING_BEAN = "ajaxRating";
public static final String AJAX_DESCRIPTION_STRING = "ajaxDesc";
+ public static final String AJAX_COMMENTS_LIST = "ajaxComments";
public static final String RESOURCES_PATH = "resources";
public static final String VERSIONS_PATH = "versions";
@@ -55,6 +56,7 @@
public static final String AJAX_PERMISSIONS_JSP = "/admin/permisions.jsp";
public static final String AJAX_DESCRIPTION_JSP = "/admin/ajax_desc.jsp";
public static final String AJAX_PROPERTIES_JSP =
"/admin/ajax/resource-properties.jsp";
+ public static final String AJAX_COMMENTS_JSP =
"/admin/ajax/comment-list.jsp";
public static final String RESOURCE_DETAILS_JSP =
"/admin/resources_details.jsp";
public static final String ERROR_JSP = "/admin/error.jsp";
}
Added:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/CommentsUtil.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/CommentsUtil.java
Tue Jan 15 08:57:37 2008
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry.web.utils;
+
+import org.wso2.registry.Registry;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Comment;
+import org.wso2.registry.web.UIConstants;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.util.List;
+import java.util.ArrayList;
+import java.io.IOException;
+
+public class CommentsUtil {
+
+ public static void addComment(HttpServletRequest request,
HttpServletResponse response)
+ throws ServletException, IOException {
+
+ try {
+
+ String resourcePath = request.getParameter("resourcePath");
+ String commentText = request.getParameter("comment");
+ Registry registry = CommonUtil.getUserRegistry(request);
+ registry.addComment(resourcePath, new Comment(commentText));
+
+ Comment[] comments = registry.getComments(resourcePath);
+ List commentList = new ArrayList();
+ for (Comment comment : comments) {
+ commentList.add(comment);
+ }
+
+ request.getSession().setAttribute(UIConstants.AJAX_COMMENTS_LIST,
commentList);
+
+ } catch (RegistryException e) {
+ request.getSession().setAttribute(UIConstants.ERROR_MESSAGE,
e.getMessage());
+ }
+
+
request.getRequestDispatcher(UIConstants.AJAX_COMMENTS_JSP).forward(request,
response);
+ }
+}
Added:
trunk/registry/modules/webapps/src/main/webapp/admin/ajax/comment-list.jsp
==============================================================================
--- (empty file)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/ajax/comment-list.jsp
Tue Jan 15 08:57:37 2008
@@ -0,0 +1,19 @@
+<%@ page import="org.wso2.registry.Comment" %>
+<%@ page import="java.util.Iterator" %>
+<%@ page import="org.wso2.registry.web.UIConstants" %>
+<%@ page import="java.util.List" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%
+ List comments = (List)
request.getSession().getAttribute(UIConstants.AJAX_COMMENTS_LIST);
+ Iterator iComments = comments.iterator();
+ while (iComments.hasNext()) {
+ Comment comment = (Comment) iComments.next();
+%>
+<div class="comments-header">
+ <strong>Commented on </strong><%=comment.getTime().toString()%><strong>
by</strong> <a href="#"><%=comment.getUser()%></a>
+ <div class="comments-bottom">
+ <%=comment.getText()%>
+ </div>
+</div>
+
+<% } %>
\ No newline at end of file
Modified: trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js Tue Jan
15 08:57:37 2008
@@ -169,6 +169,13 @@
new Ajax.Updater('perExpanded', '/wso2registry/system/authorizeRoles', {
method: 'post', parameters: {permissionInput: msgBody, resourcePath:
resourcePath} });
}
+
+function addComment(resourcePath) {
+
+ var comment = document.getElementById('comment').value;
+ new Ajax.Updater('commentList', '/wso2registry/system/addComment', {
method: 'post', parameters: {comment: comment, resourcePath: resourcePath} });
+}
+
function showHideCommon(divxName){
divx=document.getElementById(divxName);
Modified:
trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
Tue Jan 15 08:57:37 2008
@@ -86,7 +86,7 @@
}
} %>
</h1>
- <!-- a href="#" style="float:right;
display:inline;margin-top:10px;margin-right:5px;"><img
src="/wso2registry/admin/images/icon-folder-up.jpg" border="0" / --></a>
+ <!-- a href="#" style="float:right;
display:inline;margin-top:10px;margin-right:5px;"><img
src="/wso2registry/admin/images/icon-folder-up.jpg" border="0" /></a-->
<span style="clear:both;" />
</div>
<table cellspacing="0" cellpadding="0" border="0" style="width:100%">
@@ -521,7 +521,7 @@
</tr>
</table>
</div>
-<!-- Hear comes the comments box -->
+<!-- Here comes the comments box -->
<div class="box2-head">
<table cellspacing="0" cellpadding="0" border="0" style="width:100%">
<tr>
@@ -553,14 +553,15 @@
<div id="add-comment-div" style="display:none;padding-bottom:10px;">
<h3>Add Comment</h3>
- <form action="/wso2registry/system/addComment" method="post">
- <textarea name="comment" class="comment-textbox"
style="width:99%"></textarea>
- <div style="margin-top:10px;"><input type="submit" class="button"
value="Add" onclick="showHideCommon('add-comment-div');" /> <input
type="button" class="button" value="Cancel"
onclick="showHideCommon('add-comment-div');" /></div>
+ <form>
+ <textarea id="comment" name="comment" class="comment-textbox"
style="width:99%"></textarea>
+ <div style="margin-top:10px;"><input type="button" class="button"
value="Add" onclick="addComment('<%=details.getPath()%>');" /> <input
type="button" class="button" value="Cancel"
onclick="showHideCommon('add-comment-div');" /></div>
</form>
</div>
<!-- END add comment box -->
<!-- START comments listing box -->
+ <div id="commentList">
<%
Iterator iComments = details.getComments().iterator();
while (iComments.hasNext()) {
@@ -574,14 +575,10 @@
</div>
<% } %>
-
+ </div>
<!-- END comment listing box -->
-
-
-
-
</div>
<div class="box2-bot">
<table cellspacing="0" cellpadding="0" border="0" style="width:100%" >
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev