[portal-commits] JBoss Portal SVN: r12964 - in branches/JBoss_Portal_Branch_2_7: theme/src/bin/portal-ajax-war/dyna and 1 other directory.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Fri Mar 6 15:30:12 EST 2009


Author: wesleyhales
Date: 2009-03-06 15:30:12 -0500 (Fri, 06 Mar 2009)
New Revision: 12964

Modified:
   branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/PortletSessionPortlet.java
   branches/JBoss_Portal_Branch_2_7/theme/src/bin/portal-ajax-war/dyna/dyna.js
   branches/JBoss_Portal_Branch_2_7/theme/src/bin/portal-ajax-war/dyna/prototype.js
Log:
JBPORTAL-2336

Modified: branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/PortletSessionPortlet.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/PortletSessionPortlet.java	2009-03-06 16:55:15 UTC (rev 12963)
+++ branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/PortletSessionPortlet.java	2009-03-06 20:30:12 UTC (rev 12964)
@@ -44,8 +44,7 @@
    {
       String name = req.getParameter("name");
       String value = req.getParameter("value");
-      String scope = req.getParameter("scope");
-      boolean portletScope = "portlet".equals(scope);
+      boolean portletScope = req.getParameter("portlet") != null;
       if (name != null && value != null)
       {
          req.getPortletSession().setAttribute(name, value, portletScope ? PortletSession.PORTLET_SCOPE : PortletSession.APPLICATION_SCOPE);
@@ -86,19 +85,19 @@
       }
 
       //
-      writer.println("<script type='text/javascript'>\n" +
-         "function processForm(value) {" +
-         "var form = document.getElementById('sessionForm');\n" +
-         "var hidden = document.getElementById('sessionHidden');\n" +
-         "hidden.value = value;\n" +
-         "form.submit();}\n" +
-         "</script>");
+//      writer.println("<script type='text/javascript'>\n" +
+//         "function processForm(value) {" +
+//         "var form = document.getElementById('sessionForm');\n" +
+//         "var hidden = document.getElementById('sessionHidden');\n" +
+//         "hidden.value = value;\n" +
+//         "form.submit();}\n" +
+//         "</script>");
       writer.println("<form id='sessionForm' action=\"" + purl.toString() + "\" method=\"post\">");
       writer.println("<input type=\"text\" name=\"name\"/>");
       writer.println("<input type=\"text\" name=\"value\"/>");
-      writer.println("<input type=\"button\" name=\"portlet\" value=\"Add to portlet scope\" onclick=\"processForm('portlet')\"/>");
-      writer.println("<input type=\"button\" name=\"application\" value=\"Add to application scope\" onclick=\"processForm('application')\"/>");
-      writer.println("<input id='sessionHidden' name='scope' type='hidden'/>");
+      writer.println("<input type=\"submit\" name=\"portlet\" value=\"Add to portlet scope\" />");
+      writer.println("<input type=\"submit\" name=\"application\" value=\"Add to application scope\" />");
+     // writer.println("<input id='sessionHidden' name='scope' type='hidden'/>");
       writer.println("</form><br/>");
 
       //

Modified: branches/JBoss_Portal_Branch_2_7/theme/src/bin/portal-ajax-war/dyna/dyna.js
===================================================================
--- branches/JBoss_Portal_Branch_2_7/theme/src/bin/portal-ajax-war/dyna/dyna.js	2009-03-06 16:55:15 UTC (rev 12963)
+++ branches/JBoss_Portal_Branch_2_7/theme/src/bin/portal-ajax-war/dyna/dyna.js	2009-03-06 20:30:12 UTC (rev 12964)
@@ -21,53 +21,8 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
  ******************************************************************************/
 
-/*var currentSubmit = null;
+var currentSubmit;
 
- function decorateSubmits()
- {
- var submits = $$('input[type=submit]');
- for(var i = 0; i < submits.length; i++)
- {
- var submit = submits[i];
- var oldonclick = submit.onclick;
-
- if(typeof oldonclick != 'function')
- {
- submit.onclick = function()
- {
- currentSubmit = this.name;
- };
- }
- else
- {
- submit.onclick = function ()
- {
- oldonclick();
- currentSubmit = this.name;
- };
- }
- }
- }
-
-
- function addLoadEvent(func)
- {
- var oldonload = window.onload;
- if (typeof window.onload != 'function')
- {
- window.onload = func;
- }
- else
- {
- window.onload = function()
- {
- oldonload();
- func();
- };
- }
- }
- addLoadEvent(decorateSubmits());*/
-
 function sendData(action, windowId, fromPos, fromRegionId, toPos, toRegionId)
 {
    var options = {
@@ -153,6 +108,11 @@
    var source = Event.element(event);
    var container = Element.up(source, "div.dyna-window");
 
+   //attach onclick observer to all submit buttons
+   $$('input[type=submit]').invoke('observe', 'click', function(e) {
+      currentSubmit = e.findElement();
+   });
+
    // We found the window
    if (container != null)
    {
@@ -205,7 +165,6 @@
                   // Check we can handle this URL
                   if (isURLAccepted(current.action))
                   {
-
                      // Set URL
                      url = current.action;
 
@@ -213,9 +172,7 @@
                      options.enctype = enctype;
                      options.asynchronous = false;
                      options.method = "post"
-                     // TODO: inject currentSubmit value in serialization instead of only getting the value of the first submit input
-                     // see http://groups.google.com/group/prototype-core/browse_thread/thread/b3ced6a52dd5968b?pli=1
-                     options.postBody = Form.serialize(current);
+                     options.postBody = Form.serialize(current,'',currentSubmit);
                   }
                }
             }

Modified: branches/JBoss_Portal_Branch_2_7/theme/src/bin/portal-ajax-war/dyna/prototype.js
===================================================================
--- branches/JBoss_Portal_Branch_2_7/theme/src/bin/portal-ajax-war/dyna/prototype.js	2009-03-06 16:55:15 UTC (rev 12963)
+++ branches/JBoss_Portal_Branch_2_7/theme/src/bin/portal-ajax-war/dyna/prototype.js	2009-03-06 20:30:12 UTC (rev 12964)
@@ -2609,7 +2609,9 @@
       "FORM":     Object.clone(Form.Methods),
       "INPUT":    Object.clone(Form.Element.Methods),
       "SELECT":   Object.clone(Form.Element.Methods),
-      "TEXTAREA": Object.clone(Form.Element.Methods)
+      "TEXTAREA": Object.clone(Form.Element.Methods),
+       //[SERIALIZE_ERROR]
+      "BUTTON":   Object.clone(Form.Element.Methods)
     });
   }
 
@@ -3475,8 +3477,21 @@
 };
 
 Form.Methods = {
-  serialize: function(form, options) {
-    return Form.serializeElements(Form.getElements(form), options);
+  serialize: function(form, options, buttonPressed) {
+  //[SERIALIZE_ERROR] Implements additional functionality to support <button> and ensure other button-type
+  // <inputs> are not serialized
+  var elements = Form.getElements(form);
+    if (buttonPressed) {
+       elements = elements.findAll(
+         function(element) {
+           return element == $(buttonPressed) ||
+             (element.tagName.toLowerCase() != "button" &&
+             (element.tagName.toLowerCase() != "input" ||
+             (element.type != "submit" && element.type != "button" && element.type != "image" && element.type != "reset")));
+         }
+       );
+     };
+  return Form.serializeElements(elements, options);
   },
 
   getElements: function(form) {
@@ -3657,6 +3672,11 @@
     else element.value = value;
   },
 
+  //[SERIALIZE_ERROR]
+  button: function(element) {
+     return element.value;
+   },
+
   select: function(element, value) {
     if (Object.isUndefined(value))
       return this[element.type == 'select-one' ?




More information about the portal-commits mailing list