[Jifty-commit] r2486 - in jifty/branches/template-declare: .

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu Jan 11 00:13:54 EST 2007


Author: trs
Date: Thu Jan 11 00:13:53 2007
New Revision: 2486

Modified:
   jifty/branches/template-declare/   (props changed)
   jifty/branches/template-declare/share/web/static/js/bps_util.js

Log:
Mergedown from trunk

 r18795 at zot (orig r2485):  trs | 2007-01-11 00:12:28 -0500
  r18794 at zot:  tom | 2007-01-11 00:12:10 -0500
  Fix buttonToLink to deal with normal, non-ajaxy buttons that we want to turn into links
 


Modified: jifty/branches/template-declare/share/web/static/js/bps_util.js
==============================================================================
--- jifty/branches/template-declare/share/web/static/js/bps_util.js	(original)
+++ jifty/branches/template-declare/share/web/static/js/bps_util.js	Thu Jan 11 00:13:53 2007
@@ -16,18 +16,39 @@
     return Jifty.Calendar.registerDateWidget( id );
 }
 
+JSAN.use("DOM.Events");
+
 function buttonToLink(e) {
     var link = document.createElement("a");
     link.setAttribute("href","#");
-    link.setAttribute("onclick",e.getAttribute("onclick"));
     link.setAttribute("name",e.getAttribute("name"));
+
+    var form = Form.Element.getForm(e);
+    var onclick = e.getAttribute("onclick");
+
+    /* Simple buttons that don't use any JS need us to create an onclick
+       for them that makes sure the original button's name gets passed
+       and the form submitted normally (without any Ajax-ness)
+    */
+    if ( !onclick ) {
+        DOM.Events.addListener( link, "click", function(ev) {
+            var a = ev.target;
+            var hidden = document.createElement("input");
+            hidden.setAttribute("type", "hidden");
+            hidden.setAttribute("name", a.getAttribute("name"));
+            a["virtualform"].appendChild( hidden );
+            a["virtualform"].submit();
+        });
+    }
+    link.setAttribute("onclick", onclick);
+
     link.className = e.className;
-    link['virtualform'] = Form.Element.getForm(e);
+    link["virtualform"] = form;
     link.appendChild(document.createTextNode(e.getAttribute("value")));
 
     e.parentNode.insertBefore(link, e.nextSibling);
     e.parentNode.removeChild(e);
-    return true;
+    return link;
 }
 
 // onload handlers


More information about the Jifty-commit mailing list