public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added button_to_remote helper

Ticket originally from http://dev.rubyonrails.org/ticket/3641

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Tarmo Tänav (author)
Fri Aug 29 16:08:16 -0700 2008
jeremy (committer)
Fri Aug 29 16:22:01 -0700 2008
commit  6450d6ca76603bc5d1b1a6cdcb77e33e35f53d83
tree    cfe8467e3a16c5a90a4e6aa09a2e99319966bcff
parent  5a6e20b60702fbe86fa84c1b7b5a25f33cec5945
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *Edge*
0
 
0
+* Added button_to_remote helper.  #3641 [Donald Piret, Tarmo Tänav]
0
+
0
 * Deprecate render_component. Please use render_component plugin from http://github.com/rails/render_component/tree/master [Pratik]
0
 
0
 * Routes may be restricted to lists of HTTP methods instead of a single method or :any.  #407 [Brennan Dunn, Gaius Centus Novus]
...
255
256
257
 
 
 
 
 
 
 
 
258
259
260
...
255
256
257
258
259
260
261
262
263
264
265
266
267
268
0
@@ -255,6 +255,14 @@ module ActionView
0
         link_to_function(name, remote_function(options), html_options || options.delete(:html))
0
       end
0
 
0
+      # Creates a button with an onclick event which calls a remote action
0
+      # via XMLHttpRequest
0
+      # The options for specifying the target with :url
0
+      # and defining callbacks is the same as link_to_remote.
0
+      def button_to_remote(name, options = {}, html_options = {})
0
+        button_to_function(name, remote_function(options), html_options)
0
+      end
0
+
0
       # Periodically calls the specified url (<tt>options[:url]</tt>) every
0
       # <tt>options[:frequency]</tt> seconds (default is 10). Usually used to
0
       # update a specified div (<tt>options[:update]</tt>) with the results
...
91
92
93
 
 
 
 
 
 
 
 
 
 
 
 
 
94
95
96
...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
0
@@ -91,6 +91,19 @@ class PrototypeHelperTest < PrototypeHelperBaseTest
0
       link_to_remote("Remote", { :url => { :action => "whatnot's" } })
0
   end
0
 
0
+  def test_button_to_remote
0
+    assert_dom_equal %(<input class=\"fine\" type=\"button\" value=\"Remote outpost\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true});\" />),
0
+      button_to_remote("Remote outpost", { :url => { :action => "whatnot"  }}, { :class => "fine"  })
0
+    assert_dom_equal %(<input type=\"button\" value=\"Remote outpost\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onComplete:function(request){alert(request.reponseText)}});\" />),
0
+      button_to_remote("Remote outpost", :complete => "alert(request.reponseText)", :url => { :action => "whatnot"  })
0
+    assert_dom_equal %(<input type=\"button\" value=\"Remote outpost\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onSuccess:function(request){alert(request.reponseText)}});\" />),
0
+      button_to_remote("Remote outpost", :success => "alert(request.reponseText)", :url => { :action => "whatnot"  })
0
+    assert_dom_equal %(<input type=\"button\" value=\"Remote outpost\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.reponseText)}});\" />),
0
+      button_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot"  })
0
+    assert_dom_equal %(<input type=\"button\" value=\"Remote outpost\" onclick=\"new Ajax.Request('http://www.example.com/whatnot?a=10&amp;b=20', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.reponseText)}});\" />),
0
+      button_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot", :a => '10', :b => '20' })
0
+  end
0
+
0
   def test_periodically_call_remote
0
     assert_dom_equal %(<script type="text/javascript">\n//<![CDATA[\nnew PeriodicalExecuter(function() {new Ajax.Updater('schremser_bier', 'http://www.example.com/mehr_bier', {asynchronous:true, evalScripts:true})}, 10)\n//]]>\n</script>),
0
       periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" })

Comments