Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3641: button_to_remote_helper.2.diff

File button_to_remote_helper.2.diff, 3.8 kB (added by josh, 3 years ago)

Updated patch against [6372].

  • actionpack/test/template/prototype_helper_test.rb

    old new  
    5151    assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot?a=10&amp;b=20', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>), 
    5252      link_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot", :a => '10', :b => '20' }) 
    5353  end 
    54    
     54 
     55  def test_button_to_remote 
     56    assert_dom_equal %(<input class=\"fine\" type=\"button\" value=\"Remote outpost\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true});\" />), 
     57      button_to_remote("Remote outpost", { :url => { :action => "whatnot"  }}, { :class => "fine"  })                  
     58    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)}});\" />), 
     59      button_to_remote("Remote outpost", :complete => "alert(request.reponseText)", :url => { :action => "whatnot"  })  
     60    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)}});\" />), 
     61      button_to_remote("Remote outpost", :success => "alert(request.reponseText)", :url => { :action => "whatnot"  }) 
     62    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)}});\" />), 
     63      button_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot"  }) 
     64    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)}});\" />), 
     65      button_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot", :a => '10', :b => '20' })  
     66  end 
     67 
    5568  def test_periodically_call_remote 
    5669    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>), 
    5770      periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" }) 
  • actionpack/lib/action_view/helpers/prototype_helper.rb

    old new  
    133133        link_to_function(name, remote_function(options), html_options) 
    134134      end 
    135135 
     136      # Creates a button with an onclick event which calls a remote action 
     137      # via XMLHttpRequest  
     138      # The options for specifying the target with :url  
     139      # and defining callbacks is the same as link_to_remote. 
     140      def button_to_remote(name, options = {}, html_options = {})   
     141        button_to_function(name, remote_function(options), html_options) 
     142      end 
     143 
    136144      # Periodically calls the specified url (<tt>options[:url]</tt>) every  
    137145      # <tt>options[:frequency]</tt> seconds (default is 10). Usually used to 
    138146      # update a specified div (<tt>options[:update]</tt>) with the results