Author: jonathan
Date: Thu Jan 24 11:07:00 2008
New Revision: 12844

Log:

MASHUP-562: Comments can now be deleted from the mashup page (after 
confirmation) by the comment author, the mashup author, or by an admin user.

Modified:
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
   trunk/mashup/java/modules/www/ajax_comment.jsp
   trunk/mashup/java/modules/www/index.jsp
   trunk/mashup/java/modules/www/mashup.jsp
   trunk/mashup/java/modules/www/search.jsp

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
  (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
  Thu Jan 24 11:07:00 2008
@@ -416,10 +416,6 @@
                     if (mashupName.contains("?")) {
                         mashupName = mashupName.substring(0, 
mashupName.indexOf("?"));
                     }
-                    if (mashupName.contains(";")) {
-                        mashupName = mashupName.substring(0, 
mashupName.indexOf(";"));
-                    }
-
 
                     QueryResult queryResult = new QueryResult();
                     queryResult.setName(mashupName);

Modified: trunk/mashup/java/modules/www/ajax_comment.jsp
==============================================================================
--- trunk/mashup/java/modules/www/ajax_comment.jsp      (original)
+++ trunk/mashup/java/modules/www/ajax_comment.jsp      Thu Jan 24 11:07:00 2008
@@ -42,12 +42,13 @@
             // Prototype.js simulates a DELETE with a POST with an additional 
method.  YUK?!
             String method = request.getParameter("_method");
             if (method != null && method.equals("delete")) {
-                commentText = request.getParameter("comment");
-                String commentTime = request.getParameter("time");
-
-                // delete the comment here.
-                success = false;
-                reason = "Unable to delete tags at this time";
+                String commentPath = request.getParameter("commentPath");
+                try {
+                    registry.delete(commentPath);
+                } catch (RegistryException e) {
+                    success = false;
+                    reason = e.getMessage();
+                }
             } else {
                 commentText = RegistryUtils.getRequestBody(request);
 
@@ -83,6 +84,7 @@
                 for (int i = 0; i < comments.length; i++) {
                     Comment c = comments[i];
                     String commenter = c.getUser();
+                    String text = c.getText();
             %>
 
             <tr>
@@ -91,15 +93,19 @@
                         .getFullName(request, commenter) %></a> 
(<%=commenter%>)
                 </td>
                 <td>
-                    <%= c.getText() %>
+                    <%= text %>
                     <%
-                        if (author.equals(currentUser) || 
commenter.equals(currentUser)) {
-                            %>&nbsp;<span class="edit-link"><img 
src="images/smalldelete.gif" alt="remove this comment" 
onClick="removeComment('<%=c.getTime()%>')"/></span><%
+                        if (author.equals(currentUser) || 
commenter.equals(currentUser) || RegistryUtils.isAdminRole(registry)) {
+                            String shortCommentText;
+                            if (text.length() > 40) {
+                                shortCommentText = text.substring(0,40) + 
"...";
+                            } else {
+                                shortCommentText = text;
+                            }
+                            %>&nbsp;<span class="edit-link"><img 
src="images/smalldelete.gif" alt="remove this comment" 
onClick="removeComment('<%=c.getCommentPath()%>', 
'<%=shortCommentText%>')"/></span><%
                         }
                     %>
                 </td>
-
-                <!-- todo: fix commented timezone -->
             </tr>
 
             <% } %>

Modified: trunk/mashup/java/modules/www/index.jsp
==============================================================================
--- trunk/mashup/java/modules/www/index.jsp     (original)
+++ trunk/mashup/java/modules/www/index.jsp     Thu Jan 24 11:07:00 2008
@@ -320,6 +320,10 @@
 
 <%
 } else if (results.getResultsType().equals("comment")) {
+    String mashupName = result.getName();
+    if (mashupName.contains(";")) {
+        mashupName = mashupName.substring(0, mashupName.indexOf(";"));
+    }
 %>
 
 <tr class="results">
@@ -333,7 +337,7 @@
                                                                                
      result.getAuthor())%></a> (<%=result.getAuthor()%>)
     </td>
     <td nowrap>
-        <a 
href="mashup.jsp?path=<%=result.getPath()%>"><%=result.getName().split(";")[0]%></a>
+        <a href="mashup.jsp?path=<%=result.getPath()%>"><%=mashupName%></a>
     </td>
     <td class="desc" colspan="2">
         <%=result.getContentString() %>

Modified: trunk/mashup/java/modules/www/mashup.jsp
==============================================================================
--- trunk/mashup/java/modules/www/mashup.jsp    (original)
+++ trunk/mashup/java/modules/www/mashup.jsp    Thu Jan 24 11:07:00 2008
@@ -255,26 +255,31 @@
         $("Comment_commentText").value = "";
     }
 
-    function removeComment(time) {
+    function removeComment(commentPath, commentText) {
         var path = $('Comment_path').value;
         var commenter = $('Comment_commenter').value;
-        $('comments_area').style.cursor = "progress";
 
-        new Ajax.Request("ajax_comment.jsp", {
-            method: "delete",
-            parameters: {
-                "path" : path,
-                "commenter" : commenter,
-                "time" : time
-            },
-            onSuccess: function (transport) {
-                $('comments').replace(transport.responseText);
-                $('comments_area').style.cursor = "default";
-            },
-            onFailure: function (transport) {
-                alert("Trouble contacting WSO2 Mashup Server ajax service.  
Please try again later.");
-            }
-        });
+        var confirmation = confirm("You are about to permanently delete the 
comment '" + commentText + "'. Are you sure?");
+
+        if (confirmation) {
+            $('comments_area').style.cursor = "progress";
+
+            new Ajax.Request("ajax_comment.jsp", {
+                method: "delete",
+                parameters: {
+                    "path" : path,
+                    "commenter" : commenter,
+                    "commentPath" : commentPath
+                },
+                onSuccess: function (transport) {
+                    $('comments').replace(transport.responseText);
+                    $('comments_area').style.cursor = "default";
+                },
+                onFailure: function (transport) {
+                    alert("Trouble contacting WSO2 Mashup Server ajax service. 
 Please try again later.");
+                }
+            });
+        }
     }
 
     function checkCommentEnter(e) {
@@ -506,6 +511,7 @@
                 for (int i = 0; i < comments.length; i++) {
                     Comment c = comments[i];
                     String commenter = c.getUser();
+                    String text = c.getText();
             %>
 
             <tr>
@@ -514,22 +520,26 @@
                         .getFullName(request, commenter) %></a> 
(<%=commenter%>)
                 </td>
                 <td>
-                    <%= c.getText() %>
+                    <%= text %>
                     <%
-                        if (author.equals(currentUser) || 
commenter.equals(currentUser)) {
-                            %>&nbsp;<span class="edit-link"><img 
src="images/smalldelete.gif" alt="remove this comment" 
onClick="removeComment('<%=c.getTime()%>')"/></span><%
+                        if (author.equals(currentUser) || 
commenter.equals(currentUser) || RegistryUtils.isAdminRole(registry)) {
+                            String shortCommentText;
+                            if (text.length() > 40) {
+                                shortCommentText = text.substring(0,40) + 
"...";
+                            } else {
+                                shortCommentText = text;
+                            }
+                            %>&nbsp;<span class="edit-link"><img 
src="images/smalldelete.gif" alt="remove this comment" 
onClick="removeComment('<%=c.getCommentPath()%>', 
'<%=shortCommentText%>')"/></span><%
                         }
                     %>
                 </td>
-
-                <!-- todo: fix commented timezone -->
             </tr>
 
             <% } %>
 
         </tbody>
     </table>
-</div>
+</div>                                 
 <br/>
 
 

Modified: trunk/mashup/java/modules/www/search.jsp
==============================================================================
--- trunk/mashup/java/modules/www/search.jsp    (original)
+++ trunk/mashup/java/modules/www/search.jsp    Thu Jan 24 11:07:00 2008
@@ -788,7 +788,13 @@
         </nobr>
     </td>
     <td valign="top">
-        <img src="images/ra.gif"/>
+        <% if (action.equals("deleted")) { %>
+            <img src="images/delete.gif"/>
+        <% } else if (action.equals("commented")) { %>
+            <img src="images/write.gif"/>
+        <% } else { %>
+            <img src="images/edit.gif"/>
+        <% } %>
     </td>
     <td valign="top" width="100%" colspan="2">
         <% if 
(result.getAuthor().equals(RegistryUtils.getCurrentUser(registry))) { %>
@@ -799,8 +805,12 @@
         <% } %>
         <%= action %>
         <% if (action.equals("commented")) { %>on<% } %>
-        <a href="mashup.jsp?path=<%=path%>"><%=result.getName()%></a>
-        <% if (action.equals("rated")) { %>
+        <% if (action.equals("deleted")) { %>
+            <%=result.getName()%>
+        <% } else { %>
+            <a href="mashup.jsp?path=<%=path%>"><%=result.getName()%></a>
+        <% }
+           if (action.equals("rated")) { %>
         <%=result.getContentString() %> stars
         <% } else if (action.equals("tagged")) { %>
         with <a
@@ -814,6 +824,11 @@
 
 <%
 } else if (results.getResultsType().equals("comment")) {
+    String mashupName = result.getName();
+    if (mashupName.contains(";")) {
+        mashupName = mashupName.substring(0, mashupName.indexOf(";"));
+    }
+    
 %>
 <tr class="results">
     <td width="12%" valign="top">
@@ -826,7 +841,7 @@
                                                                                
      result.getAuthor())%></a> (<%=result.getAuthor()%>)
     </td>
     <td nowrap>
-        <a 
href="mashup.jsp?path=<%=result.getPath()%>"><%=result.getName()%></a>
+        <a href="mashup.jsp?path=<%=result.getPath()%>"><%=mashupName%></a>
     </td>
     <td class="desc" colspan="2">
         <%=result.getContentString() %>

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to