Author: julien(a)jboss.com
Date: 2007-03-30 12:07:35 -0400 (Fri, 30 Mar 2007)
New Revision: 6882
Modified:
trunk/theme/src/main/org/jboss/portal/theme/impl/render/dynamic/DynaPortletRenderer.java
trunk/theme/src/main/org/jboss/portal/theme/impl/render/dynamic/DynaRegionRenderer.java
Log:
improved DnD implementation, less javascript
Modified:
trunk/theme/src/main/org/jboss/portal/theme/impl/render/dynamic/DynaPortletRenderer.java
===================================================================
---
trunk/theme/src/main/org/jboss/portal/theme/impl/render/dynamic/DynaPortletRenderer.java 2007-03-30
14:18:57 UTC (rev 6881)
+++
trunk/theme/src/main/org/jboss/portal/theme/impl/render/dynamic/DynaPortletRenderer.java 2007-03-30
16:07:35 UTC (rev 6882)
@@ -52,6 +52,11 @@
/** @see PortletRenderer#render */
public void render(RenderContext renderContext, PortletRenderContext prc) throws
RenderException
{
+ doDND(renderContext, prc);
+ }
+
+ private void doDND(RenderContext renderContext, PortletRenderContext prc) throws
RenderException
+ {
if (DynaRegionRenderer.isEnabled())
{
// Provide handle on content if needed
@@ -61,18 +66,27 @@
DynaWindowRenderer.handleProvided.set(Boolean.TRUE);
//
- renderContext.getMarkupFragment().append("<span
class=\"handle\">");
+ StringBuffer out = renderContext.getMarkupFragment();
+ out.append("<span class=\"handle\">");
delegate.render(renderContext, prc);
- renderContext.getMarkupFragment().append("</span>");
+ out.append("</span>");
}
else
{
- delegate.render(renderContext, prc);
+ doCatchClicks(renderContext, prc);
}
}
else
{
- delegate.render(renderContext, prc);
+ doCatchClicks(renderContext, prc);
}
}
+
+ private void doCatchClicks(RenderContext renderContext, PortletRenderContext prc)
throws RenderException
+ {
+// StringBuffer out = renderContext.getMarkupFragment();
+// out.append("<div class=\"portlet-bilto\">");
+ delegate.render(renderContext, prc);
+// out.append("</div>");
+ }
}
Modified:
trunk/theme/src/main/org/jboss/portal/theme/impl/render/dynamic/DynaRegionRenderer.java
===================================================================
---
trunk/theme/src/main/org/jboss/portal/theme/impl/render/dynamic/DynaRegionRenderer.java 2007-03-30
14:18:57 UTC (rev 6881)
+++
trunk/theme/src/main/org/jboss/portal/theme/impl/render/dynamic/DynaRegionRenderer.java 2007-03-30
16:07:35 UTC (rev 6882)
@@ -39,10 +39,14 @@
public class DynaRegionRenderer implements RegionRenderer
{
- /** . */
+ /**
+ * .
+ */
private static final ThreadLocal enabledLocal = new ThreadLocal();
- /** . */
+ /**
+ * .
+ */
private RegionRenderer delegate;
public static boolean isEnabled()
@@ -83,77 +87,79 @@
markup.append("<script type='text/javascript'>\n");
markup.append("remote_server_url=\"").append(remoteURL).append(";\"\n");
- markup.append("regions_on_page = new Object();\n");
-
- String sendData =
- "function sendData(action, windowId, fromPos, fromRegionId, toPos,
toRegionId)\n" +
- "{\n" +
- " var options = {\n" +
- " method: 'post',\n" +
- " postBody: 'action=' + action +
'&windowId=' + windowId + '&fromPos=' + fromPos +
'&fromRegion=' + fromRegionId + '&toPos=' + toPos +
'&toRegion=' + toRegionId,\n" +
- " onSuccess: function(t)\n" +
- " {\n" +
- " },\n" +
- " onSuccess: function(t)\n" +
- " {\n" +
- " },\n" +
- " on404: function(t)\n" +
- " {\n" +
- " alert('Error 404: location \"' +
t.statusText + '\" was not found.');\n" +
- " },\n" +
- " onFailure: function(t)\n" +
- " {\n" +
- " alert('Error ' + t.status + ' -- ' +
t.statusText);\n" +
- " },\n" +
- " onLoading: function(t)\n" +
- " {\n" +
- " }\n" +
- " }\n" +
- " new Ajax.Request(remote_server_url, options);\n" +
- "}";
+ String sendData = "" +
+ "function sendData(action, windowId, fromPos, fromRegionId, toPos,
toRegionId) {\n" +
+ " var options = {\n" +
+ " method: 'post',\n" +
+ " postBody: 'action=' + action +
'&windowId=' + windowId + '&fromPos=' + fromPos +
'&fromRegion=' + fromRegionId + '&toPos=' + toPos +
'&toRegion=' + toRegionId,\n" +
+ " onSuccess: function(t)\n" +
+ " {\n" +
+ " },\n" +
+ " onSuccess: function(t)\n" +
+ " {\n" +
+ " },\n" +
+ " on404: function(t)\n" +
+ " {\n" +
+ " alert('Error 404: location \"' + t.statusText
+ '\" was not found.');\n" +
+ " },\n" +
+ " onFailure: function(t)\n" +
+ " {\n" +
+ " alert('Error ' + t.status + ' -- ' +
t.statusText);\n" +
+ " },\n" +
+ " onLoading: function(t)\n" +
+ " {\n" +
+ " }\n" +
+ " }\n" +
+ " new Ajax.Request(remote_server_url, options);\n" +
+ "}";
markup.append(sendData);
//
- String t =
+ String t = "" +
"function snapshot() {\n" +
- "for(region in regions_on_page) {\n" +
- "var regionId = regions_on_page[region];\n" +
- "var regionDiv = $(region);\n" +
- "for (var i = 0;i < regionDiv.childNodes.length;i++) {\n"
+
- "var child = regionDiv.childNodes[i];\n" +
- "child['regionId'] = regionId;\n" +
- "child['pos'] = i;\n" +
- "}\n" +
- "}\n" +
- "\n}";
+ // Find draggable regions
+ " var regions_on_page =
document.getElementsByClassName(\"draggable-region\");\n" +
+
+ // Save current state in the DOM itself
+ " for(var i = 0;i < regions_on_page.length;i++) {\n" +
+ " var regionDiv = regions_on_page[i]\n" +
+ " for (var j = 0;j < regionDiv.childNodes.length;j++)
{\n" +
+ " var child = regionDiv.childNodes[j];\n" +
+ " child['regionId'] = regionDiv.id;\n" +
+ " child['pos'] = j;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+
markup.append(t);
- String s =
- " var WindowMoveObserver = Class.create();\n" +
- " WindowMoveObserver.prototype =\n" +
- " {\n" +
- " initialize: function(element)\n" +
- " {\n" +
- " this.element = $(element);\n" +
- " },\n" +
- " onStart: function()\n" +
- " {\n" +
- " },\n" +
- " onEnd: function()\n" +
- " {\n" +
- " var elt = Draggables.activeDraggable.element;\n" +
- " var fromRegionId = elt['regionId'];\n" +
- " var fromPos = elt['pos'];\n" +
- " snapshot();\n" +
- " var toRegionId = elt['regionId'];\n" +
- " var toPos = elt['pos'];\n" +
- " sendData('windowmove', elt.id, fromPos,
fromRegionId, toPos, toRegionId);\n" +
- " }\n" +
- " };\n";
+ String s = "" +
+ "var WindowMoveObserver = Class.create();\n" +
+ "WindowMoveObserver.prototype =\n" +
+ "{\n" +
+ " initialize: function(element)\n" +
+ " {\n" +
+ " this.element = $(element);\n" +
+ " },\n" +
+ " onStart: function()\n" +
+ " {\n" +
+ " },\n" +
+ " onEnd: function()\n" +
+ " {\n" +
+ " var elt = Draggables.activeDraggable.element;\n" +
+ " var fromRegionId = elt['regionId'];\n" +
+ " var fromPos = elt['pos'];\n" +
+ " snapshot();\n" +
+ " var toRegionId = elt['regionId'];\n" +
+ " var toPos = elt['pos'];\n" +
+ " sendData('windowmove', elt.id, fromPos, fromRegionId,
toPos, toRegionId);\n" +
+ " }\n" +
+ "};\n";
markup.append(s);
- String u = "function removeWindow(elementId)\n" +
+ String u = "" +
+ "function removeWindow(elementId)\n" +
"{\n" +
" var effectElement = document.getElementById(elementId)\n" +
" new Effect.BlindUp(effectElement);\n" +
@@ -169,24 +175,24 @@
}
else if ("AJAXFooter".equals(rrc.getId()))
{
- markup.append("<script>\n");
- markup.append(
- "\n" +
- "var toto = new Array();\n" +
- "for(region in regions_on_page) {\n" +
- " toto.push(region);\n" +
- "}\n" +
- "for(region in regions_on_page) {\n" +
- "Sortable.create(region,
{dropOnEmpty:true,handle:'handle',tag:'div',containment:toto,constraint:false,
ghosting: false,\n" +
- " onChange: function(el)\n" +
- " {\n" +
- " },\n" +
- " onUpdate: function (el)\n" +
- " {\n" +
- " }\n" +
- "});\n" +
- "}\n");
+ markup.append("<script>\n" +
+ // Find the draggable regions
+ "var regions_on_page =
document.getElementsByClassName(\"draggable-region\");\n" +
+
+ //
+ "for(var i = 0;i < regions_on_page.length;i++) {\n" +
+ " var region = regions_on_page[i];" +
+ " Sortable.create(region,
{dropOnEmpty:true,handle:'handle',tag:'div',containment:regions_on_page,constraint:false,
ghosting: false,\n" +
+ " onChange: function(el)\n" +
+ " {\n" +
+ " },\n" +
+ " onUpdate: function (el)\n" +
+ " {\n" +
+ " }\n" +
+ " });\n" +
+ "}\n");
+
//
markup.append("Draggables.addObserver(new
WindowMoveObserver());\n");
@@ -209,16 +215,11 @@
//
if (regionEnabled)
{
- // Keep a map of logical regions to div containers
- markup.append("<script>").
-
append("regions_on_page[\"bilto-").append(rrc.getId()).append("\"]=\"").append(rrc.getId()).append("\";").
- append("</script>");
-
//
delegate.preRender(renderContext, rrc);
//
- markup.append("<div
id=\"bilto-").append(rrc.getId()).append("\">");
+ markup.append("<div class=\"draggable-region\"
id=\"").append(rrc.getId()).append("\">");
}
else
{
@@ -237,7 +238,7 @@
markup.append("<div> </div>");
markup.append("</div>");
}
-
+
//
delegate.postRender(renderContext, rrc);
@@ -245,7 +246,9 @@
enabledLocal.set(null);
}
- /** @see RegionRenderer#render */
+ /**
+ * @see RegionRenderer#render
+ */
public void render(RenderContext renderContext, final RegionRenderContext rrc) throws
RenderException
{
delegate.render(renderContext, rrc);