Author: chathura
Date: Thu Dec 6 05:32:27 2007
New Revision: 10648
Log:
Implemented the in-place editing using AJAX!
It is possible to have html formatted content for descriptions.
Added:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/GetDescriptionAction.java
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/SetDescriptionAction.java
trunk/registry/modules/webapps/src/main/webapp/admin/ajax_desc.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
Thu Dec 6 05:32:27 2007
@@ -217,6 +217,25 @@
response.sendRedirect("/wso2registry/web" + path);
//forwardToResources(request, response, path);
+ } else if (command.equals("/setDescription")) {
+
+ String resourcePath = path;
+ String description = request.getParameter("description");
+
+ SetDescriptionAction setDescriptionAction = new
SetDescriptionAction();
+ setDescriptionAction.setResourcePath(resourcePath);
+ setDescriptionAction.setDescription(description);
+
+ try {
+ setDescriptionAction.execute(request);
+ } catch (RegistryException e) {
+ setErrorMessage(request, e.getMessage());
+ e.printStackTrace();
+ }
+
+
request.getSession().setAttribute(UIConstants.AJAX_DESCRIPTION_STRING,
setDescriptionAction.getDescription());
+
request.getRequestDispatcher(UIConstants.AJAX_DESCRIPTION_JSP).forward(request,
response);
+
} else if (command.equals("/addComment")) {
CommentAction commentAction = new CommentAction();
@@ -492,6 +511,21 @@
request.getSession().setAttribute(UIConstants.AJAX_RATING_BEAN,
ajaxRatingAction);
request.getRequestDispatcher(UIConstants.AJAX_RATING_JSP).forward(request,
response);
+
+ } else if (command.equals("/getDescription")) {
+
+ GetDescriptionAction getDescriptionAction = new
GetDescriptionAction();
+
getDescriptionAction.setResourcePath(request.getParameter("resourcePath"));
+
+ try {
+ getDescriptionAction.execute(request);
+ } catch (RegistryException e) {
+ setErrorMessage(request, e.getMessage());
+ e.printStackTrace();
+ }
+
+
request.getSession().setAttribute(UIConstants.AJAX_DESCRIPTION_STRING,
getDescriptionAction.getDescription());
+
request.getRequestDispatcher(UIConstants.AJAX_DESCRIPTION_JSP).forward(request,
response);
}
}
}
@@ -560,7 +594,7 @@
try {
request.getRequestDispatcher(UIConstants.RESOURCES_JSP)
- .forward(request, response);
+ .forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
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
Thu Dec 6 05:32:27 2007
@@ -28,6 +28,7 @@
public static final String SEARCH_BEAN = "search";
public static final String USER_BEAN = "userBean";
public static final String AJAX_RATING_BEAN = "ajaxRating";
+ public static final String AJAX_DESCRIPTION_STRING = "ajaxDesc";
public static final String WEB_PATH = "web";
public static final String SYSTEM_PATH = "system";
@@ -42,5 +43,6 @@
public static final String SEARCH_JSP = "/admin/search.jsp";
public static final String USER_JSP = "/admin/user.jsp";
public static final String AJAX_RATING_JSP = "/admin/ajax_rating.jsp";
+ public static final String AJAX_DESCRIPTION_JSP = "/admin/ajax_desc.jsp";
public static final String RESOURCE_DETAILS_JSP =
"/admin/resources_details.jsp";
}
Added:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/GetDescriptionAction.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/GetDescriptionAction.java
Thu Dec 6 05:32:27 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.actions;
+
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Registry;
+import org.wso2.registry.Resource;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class GetDescriptionAction extends AbstractRegistryAction {
+
+ private String resourcePath;
+ private String description;
+
+ public void execute(HttpServletRequest request) throws RegistryException {
+
+ setRequest(request);
+
+ Registry registry = getRegistry();
+ Resource resource = registry.get(resourcePath);
+ description = resource.getDescription();
+ }
+
+ public String getResourcePath() {
+ return resourcePath;
+ }
+
+ public void setResourcePath(String resourcePath) {
+ this.resourcePath = resourcePath;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
Added:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/SetDescriptionAction.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/SetDescriptionAction.java
Thu Dec 6 05:32:27 2007
@@ -0,0 +1,56 @@
+/*
+ * 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.actions;
+
+import org.wso2.registry.Registry;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class SetDescriptionAction extends AbstractRegistryAction {
+
+ private String resourcePath;
+ private String description;
+
+ public void execute(HttpServletRequest request) throws RegistryException {
+
+ setRequest(request);
+
+ Registry registry = getRegistry();
+
+ Resource resource = registry.get(resourcePath);
+ resource.setDescription(description);
+ registry.put(resourcePath, resource);
+ }
+
+ public String getResourcePath() {
+ return resourcePath;
+ }
+
+ public void setResourcePath(String resourcePath) {
+ this.resourcePath = resourcePath;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
Added: trunk/registry/modules/webapps/src/main/webapp/admin/ajax_desc.jsp
==============================================================================
--- (empty file)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/ajax_desc.jsp Thu Dec
6 05:32:27 2007
@@ -0,0 +1,16 @@
+<%@ page import="org.wso2.registry.web.actions.SetDescriptionAction" %>
+<%@ page import="org.wso2.registry.web.UIConstants" %>
+<%--
+ Created by IntelliJ IDEA.
+ User: chathura
+ Date: Dec 5, 2007
+ Time: 7:19:41 PM
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+<%
+ String description = (String)
request.getSession().getAttribute(UIConstants.AJAX_DESCRIPTION_STRING);
+%>
+
+<p><%=description%></p>
\ 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 Thu Dec
6 05:32:27 2007
@@ -81,8 +81,8 @@
}
function showHideEdit(){
- var normal_div=document.getElementById('resource-content');
- var edit_div=document.getElementById('resource-content-edit');
+ var normal_div=document.getElementById('descView');
+ var edit_div=document.getElementById('descEdit');
var edit_button = document.getElementById('editButton');
if(normal_div.style.display=='block'){
@@ -146,23 +146,48 @@
pForm.submit();
}
function showHideCommon(divxName){
- divx=document.getElementById(divxName);
-
- /* show the intialy hidden object */
- if(divx.style.display=='none'){
- if(divx.nodeName == 'DIV')
- divx.style.display='block';
- if(divx.nodeName == 'IMG')
- divx.style.display='inline';
- //link.innerHTML=textHidden;
- }
- /* hide the initaly shown object */
- else
- {
- divx.style.display='none';
-
- //link.innerHTML=textShown;
- }
-
-
+ divx=document.getElementById(divxName);
+
+ /* show the intialy hidden object */
+ if(divx.style.display=='none'){
+ if(divx.nodeName == 'DIV')
+ divx.style.display='block';
+ if(divx.nodeName == 'IMG')
+ divx.style.display='inline';
+ //link.innerHTML=textHidden;
+ }
+ /* hide the initaly shown object */
+ else
+ {
+ divx.style.display='none';
+
+ //link.innerHTML=textShown;
+ }
+
+
+}
+
+function processDescription() {
+
+ var normal_div=document.getElementById('descView');
+ var edit_div=document.getElementById('descEdit');
+ var edit_button = document.getElementById('editButton');
+
+ if (edit_button.value=='Save Description') {
+
+ var desc = edit_div.value;
+ new Ajax.Updater('descView', '/wso2registry/system/setDescription', {
method: 'post', parameters: {description: desc} });
+ edit_div.value = normal_div.innerHTML;
+ }
+
+ if(normal_div.style.display=='block'){
+ normal_div.style.display='none';
+ edit_div.style.display='block';
+ edit_button.value= 'Save Description';
+ }
+ else {
+ normal_div.style.display='block';
+ edit_div.style.display='none'
+ edit_button.value= 'Edit Description';
+ }
}
\ No newline at end of file
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
Thu Dec 6 05:32:27 2007
@@ -70,18 +70,20 @@
new Ajax.Updater('ratingDiv', '/wso2registry/system/getInitialRating', {
method: 'get', parameters: {resourcePath: '<%=details.getPath()%>'} });
</script>
-<div class="resource-content" id="resource-content" style="display:block;">
- <strong>Welcome to wso2 Registry!</strong> <br />
- The WSO2 Registry allows you to store any resources in a structured
repository.
- The Registry has built-in support for common XML and Web metadata formats.
-</div>
-<textarea class="resource-content" id="resource-content-edit"
style="display:none; width:98%;height:200px;">
- <strong>Welcome to wso2 Registry!</strong> <br />
- The WSO2 Registry allows you to store any resources in a structured
repository.
- The Registry has built-in support for common XML and Web metadata formats.
+<div class="resource-content" id="descView" style="display:block;">
+ description...
+</div>
+<textarea class="resource-content" id="descEdit" style="display:none;
width:98%;height:200px;">
+ description...
</textarea>
+
+<script type="text/javascript" xml:space="preserve">
+ new Ajax.Updater('descView', '/wso2registry/system/getDescription', {
method: 'get', parameters: {resourcePath: '<%=details.getPath()%>'} });
+ document.getElementById("descEdit").textContent =
document.getElementById("descView").innerHTML;
+</script>
+
<div class="resource-footer">
- <input id="editButton" type="button" class="button" value="Edit
Description" onclick="showHideEdit()" />
+ <input id="editButton" type="button" class="button" value="Edit
Description" onclick="processDescription()" />
</div>
<% if (details.isCollection()) { %>
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev