[jboss-svn-commits] JBoss Portal SVN: r5244 - in trunk/theme/src: bin/portal-ajax-war bin/portal-ajax-war/images bin/portal-ajax-war/js/portal main/org/jboss/portal/theme main/org/jboss/portal/theme/servlet resources/portal-ajax-war/WEB-INF

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Sep 22 13:37:03 EDT 2006


Author: roy.russo at jboss.com
Date: 2006-09-22 13:37:01 -0400 (Fri, 22 Sep 2006)
New Revision: 5244

Added:
   trunk/theme/src/bin/portal-ajax-war/images/
   trunk/theme/src/bin/portal-ajax-war/images/roller.gif
   trunk/theme/src/main/org/jboss/portal/theme/servlet/
   trunk/theme/src/main/org/jboss/portal/theme/servlet/DynaAjaxServlet.java
Modified:
   trunk/theme/src/bin/portal-ajax-war/js/portal/event.js
   trunk/theme/src/resources/portal-ajax-war/WEB-INF/web.xml
Log:
- added XMLHTTPRequest logic in event.js
- added progress indicator on save
- added AJAX process servlet

Added: trunk/theme/src/bin/portal-ajax-war/images/roller.gif
===================================================================
(Binary files differ)


Property changes on: trunk/theme/src/bin/portal-ajax-war/images/roller.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/theme/src/bin/portal-ajax-war/js/portal/event.js
===================================================================
--- trunk/theme/src/bin/portal-ajax-war/js/portal/event.js	2006-09-22 15:30:57 UTC (rev 5243)
+++ trunk/theme/src/bin/portal-ajax-war/js/portal/event.js	2006-09-22 17:37:01 UTC (rev 5244)
@@ -22,32 +22,216 @@
 * @author <a href="mailto:roy at jboss.org">Roy Russo</a>
 */
 
-init();
+var o_el_regionA = new Array();
+var o_el_regionB = new Array();
 
-// initialize sortable and event updater
-function init()
+/**
+AJAX Send function. Assembles post data, and handles process
+**/
+function sendData(windowID, fromPos, fromRegion, toPos, toRegion)
 {
-   try
+   var options = {
+      method: 'post',
+      postBody: 'windowID=' + windowID + '&fromPos=' + fromPos + '&fromRegion=' + fromRegion + '&toPos=' + toPos + '&toRegion=' + toRegion,
+      onSuccess: function(t)
+      {
+         a = document.getElementById("ReqProgressIndicator");
+         document.body.removeChild(a);
+      },
+      onSuccess: function(t)
+      {
+         a = document.getElementById("ReqProgressIndicator");
+         document.body.removeChild(a);
+      },
+      on404: function(t)
+      {
+         a = document.getElementById("ReqProgressIndicator");
+         document.body.removeChild(a);
+         alert('Error 404: location "' + t.statusText + '" was not found.');
+      },
+      onFailure: function(t)
+      {
+         a = document.getElementById("ReqProgressIndicator");
+         document.body.removeChild(a);
+         alert('Error ' + t.status + ' -- ' + t.statusText);
+      },
+      onLoading: function(t)
+      {
+      }
+   }
+
+   var url = "http://localhost:8080/portal-ajax/ajax";
+   new Ajax.Request(url, options);
+
+   a = document.createElement("div");
+   a.id = "ReqProgressIndicator";
+   a.style.position = "absolute";
+   a.style.left = "2px";
+   a.style.top = document.documentElement.scrollTop + 2 + "px";
+   a.style.width = "50px";
+   a.style.height = "30px"
+   a.style.padding = "2px";
+   a.style.verticalAlign = "bottom";
+   a.style.backgroundColor = "#FFFFFF";
+   a.style.filter = "alpha(opacity=80)";
+   a.style.opacity = ".80";
+
+   a.innerHTML = "<img style='VERTICAL-ALIGN:bottom' src='/portal-ajax/images/roller.gif'><br/>Saving...";
+   document.body.appendChild(a);
+}
+
+/**
+Class that tracks window movement and updates DOM on move end.
+**/
+try
+{
+   var WindowMoveObserver = Class.create();
+   WindowMoveObserver.prototype =
    {
-      Sortable.create("regionA", {dropOnEmpty:true,handle:'handle',hoverclass:'dragover',tag:'div',containment:["regionA","regionB"],constraint:false, ghosting: false,
-         onChange: function(el)
+      initialize: function(element)
+      {
+         this.element = $(element);
+      },
+      onStart: function()
+      {
+      },
+      onEnd: function()
+      {
+         var children = this.element.childNodes;
+         for(var i = 0; i < children.length; i = i + 1)
          {
-            //	setMoved(el);
-         },
-         onUpdate: function (el)
-         {
-            //	moved_element = getMoved();
-            //	moved_Parent = moved_element.parentNode;
-            //	alert(moved_element.id + ' ' + moved_Parent.id);
+            if(Draggables.activeDraggable.element == children[i])
+            {
+               fromPos = findWindowPos(children[i]);
+               fromRegion = findWindowRegion(children[i]);
+
+               //alert("Moved: " + thischild.id + " from: " + fromRegion  + " pos: " + fromPos);
+               //alert("Moved: " + thischild.id + " to: " + this.element.id + " pos: " + i);
+
+               // window moved, update DOM
+               updateDOM();
+
+               // send Data
+               sendData(children[i].id, fromPos, fromRegion, i, this.element.id);
+               break;
+               // or FF continues looping.
+            }
          }
-      });
-      Sortable.create("regionB", {dropOnEmpty:true,handle:'handle',hoverclass:'dragover',tag:'div',containment:["regionA","regionB"],constraint:false, ghosting: false});
+      }
    }
+}
+catch(e)
+{
+   alert(e);
+}
+
+/**
+Creates sortables (drag/drop windows), attach observers and initialize the DOM
+**/
+try
+{
+   Sortable.create("regionA", {dropOnEmpty:true,handle:'handle',hoverclass:'dragover',tag:'div',containment:["regionA","regionB"],constraint:false, ghosting: false,
+      onChange: function(el)
+      {
+      },
+      onUpdate: function (el)
+      {
+      }
+   });
+
+   Sortable.create("regionB", {dropOnEmpty:true,handle:'handle',hoverclass:'dragover',tag:'div',containment:["regionA","regionB"],constraint:false, ghosting: false,
+      onChange: function(el)
+      {
+      },
+      onUpdate: function (el)
+      {
+      }
+   });
+
+   // attach observers to regions
+   Draggables.addObserver(new WindowMoveObserver($('regionA')));
+   Draggables.addObserver(new WindowMoveObserver($('regionB')));
+
+   // initialize DOM
+   updateDOM();
+}
+catch(e)
+{
+   alert(e);
+}
+
+/**
+Update th DOM order in our global array. Later used to compare move from/to
+**/
+function updateDOM()
+{
+   try
+   {
+      // reset to 0
+      o_el_regionA = new Array();
+      o_el_regionB = new Array();
+
+      var regionA = this.document.getElementById("regionA");
+      for(var i = 0; i < regionA.childNodes.length; i = i + 1)
+      {
+         o_el_regionA[i] = regionA.childNodes[i];
+      }
+      var regionB = this.document.getElementById("regionB");
+      for(var i = 0; i < regionB.childNodes.length; i = i + 1)
+      {
+         o_el_regionB[i] = regionB.childNodes[i];
+      }
+      //alert("New A: " + o_el_regionA.length + " New B: " + o_el_regionB.length);
+   }
    catch(e)
    {
-      alert(e);
+      alert("Error updateDOM: " + e);
    }
 }
 
-// protects against mem-leaks in IE/Gecko.
-//Event.observe(window, "load", init, false);
+/**
+Returns theoriginal Window position for a given window element
+**/
+function findWindowPos(element)
+{
+   for(var i = 0; i < o_el_regionA.length; i = i + 1)
+   {
+      currelement = o_el_regionA[i];
+      if(element == currelement)
+      {
+         return i;
+      }
+   }
+   for(var i = 0; i < o_el_regionB.length; i = i + 1)
+   {
+      currelement = o_el_regionB[i];
+      if(element = currelement)
+      {
+         return i;
+      }
+   }
+}
+
+/**
+Returns the original region where a window resided.
+**/
+function findWindowRegion(element)
+{
+   for(var i = 0; i < o_el_regionA.length; i = i + 1)
+   {
+      currelement = o_el_regionA[i];
+      if(element == currelement)
+      {
+         return "regionA";
+      }
+   }
+   for(var i = 0; i < o_el_regionB.length; i = i + 1)
+   {
+      currelement = o_el_regionB[i];
+      if(element = currelement)
+      {
+         return "regionB";
+      }
+   }
+}
+

Added: trunk/theme/src/main/org/jboss/portal/theme/servlet/DynaAjaxServlet.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/servlet/DynaAjaxServlet.java	2006-09-22 15:30:57 UTC (rev 5243)
+++ trunk/theme/src/main/org/jboss/portal/theme/servlet/DynaAjaxServlet.java	2006-09-22 17:37:01 UTC (rev 5244)
@@ -0,0 +1,140 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.portal.theme.servlet;
+
+import org.jboss.logging.Logger;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Enumeration;
+
+/**
+ * @author <a href="mailto:tomasz.szymanski at jboss.com">Tomasz Szymanski</a>
+ * @author <a href="mailto:roy at jboss.org">Roy Russo</a>
+ */
+
+public class DynaAjaxServlet extends HttpServlet
+{
+   private static final long serialVersionUID = 1L;
+
+   private static final String PERSIST = "PERSIST";
+
+   private static final String TEST_MODE = "TEST_MODE";
+
+   private final static Logger log = Logger.getLogger(DynaAjaxServlet.class);
+
+   private boolean testMode = false;
+
+   public void doGet(HttpServletRequest req, HttpServletResponse resp)
+         throws ServletException, IOException
+   {
+      doPost(req, resp);
+   }
+
+   public void doPost(HttpServletRequest req, HttpServletResponse resp)
+         throws ServletException, IOException
+   {
+      Enumeration paramNames = req.getParameterNames();
+      while(paramNames.hasMoreElements())
+      {
+         String name = (String) paramNames.nextElement();
+         //log.info("Parameter: " + name + " = " + req.getParameter(name));
+         System.out.println("Parameter: " + name + " = " + req.getParameter(name));
+      }
+
+      sendResp(resp, ((testMode) ? "Test mode ON" : "Test mode OFF"));
+
+/*
+      if(req.getParameter("action") != null)
+      {
+         if(req.getParameter("action").equals(PERSIST))
+         {
+            if(req.getParameter("positionNo") == null
+               || req.getParameter("windowId") == null
+               || req.getParameter("oldRegionId") == null
+               || req.getParameter("newRegionId") == null)
+            {
+               resp.sendError(400, "Not enought parameters");
+               return;
+            }
+
+            if(!testMode)
+            {
+               persistance.persistPosition(req.getParameter("positionNo"),
+                                           req.getParameter("windowId"), req
+                     .getParameter("oldRegionId"), req
+                     .getParameter("newRegionId"));
+            }
+
+            sendResp(resp, "Position persisted");
+         }
+         else if(req.getParameter("action").equals(TEST_MODE))
+         {
+            if(req.getParameter("mode") != null)
+            {
+               try
+               {
+                  testMode = Boolean.valueOf(req.getParameter("mode"))
+                        .booleanValue();
+               }
+               catch(RuntimeException e)
+               {
+                  resp.sendError(400, "Bad arguments");
+                  return;
+               }
+
+               sendResp(resp, ((testMode) ? "Test mode ON" : "Test mode OFF"));
+
+            }
+            else
+            {
+               resp.sendError(400, "Not enought parameters");
+               return;
+            }
+         }
+         else
+         {
+            resp.sendError(400, "Unknown ajax call");
+            return;
+         }
+      }
+*/
+   }
+
+   private void sendResp(HttpServletResponse resp, String respData)
+         throws IOException
+   {
+      resp.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
+      resp.setDateHeader("Last-Modified", new Date().getTime());
+      resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
+      resp.addHeader("Cache-Control", "post-check=0, pre-check=0");
+      resp.setContentType("text/html");
+
+      resp.getWriter().write(respData);
+   }
+
+}

Modified: trunk/theme/src/resources/portal-ajax-war/WEB-INF/web.xml
===================================================================
--- trunk/theme/src/resources/portal-ajax-war/WEB-INF/web.xml	2006-09-22 15:30:57 UTC (rev 5243)
+++ trunk/theme/src/resources/portal-ajax-war/WEB-INF/web.xml	2006-09-22 17:37:01 UTC (rev 5244)
@@ -1,6 +1,15 @@
 <?xml version="1.0"?>
 <!DOCTYPE web-app PUBLIC
-   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
-   "http://java.sun.com/dtd/web-app_2_3.dtd">
+      "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+      "http://java.sun.com/dtd/web-app_2_3.dtd">
 <web-app>
+   <servlet>
+      <servlet-name>DynaAjaxServlet</servlet-name>
+      <servlet-class>org.jboss.portal.theme.servlet.DynaAjaxServlet</servlet-class>
+      <load-on-startup>0</load-on-startup>
+   </servlet>
+   <servlet-mapping>
+      <servlet-name>DynaAjaxServlet</servlet-name>
+      <url-pattern>/ajax/*</url-pattern>
+   </servlet-mapping>
 </web-app>




More information about the jboss-svn-commits mailing list