From c3baf8b767bdfb27b90b2120f9512d9697e5e932 Mon Sep 17 00:00:00 2001 From: "Erik St. Martin" Date: Sun, 24 Jan 2010 09:57:09 -0500 Subject: link_to_remote and button_to_remote now support :confirm --- actionpack/lib/action_view/helpers/ajax_helper.rb | 12 ++++++++++++ actionpack/test/template/ajax_helper_test.rb | 10 ++++++++++ 2 files changed, 22 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/ajax_helper.rb b/actionpack/lib/action_view/helpers/ajax_helper.rb index 06a57efd95..79e4167292 100644 --- a/actionpack/lib/action_view/helpers/ajax_helper.rb +++ b/actionpack/lib/action_view/helpers/ajax_helper.rb @@ -293,6 +293,7 @@ module ActionView attributes = {} attributes.merge!(:rel => "nofollow") if options[:method] && options[:method].downcase == "delete" attributes.merge!(extract_remote_attributes!(options)) + attributes.merge!(extract_confirm_attributes!(options)) attributes.merge!(html_options) content_tag(:a, name, attributes.merge(:href => "#")) @@ -304,6 +305,7 @@ module ActionView # and defining callbacks is the same as link_to_remote. def button_to_remote(name, options = {}, html_options = {}) attributes = html_options.merge!(:type => "button", :value => name) + attributes.merge!(extract_confirm_attributes!(options)) attributes.merge!(extract_remote_attributes!(options)) tag(:input, attributes) @@ -483,6 +485,16 @@ module ActionView private + def extract_confirm_attributes!(options) + attributes = {} + + if options && options[:confirm] + attributes["data-confirm"] = options.delete(:confirm) + end + + attributes + end + def extract_remote_attributes!(options) attributes = options.delete(:html) || {} diff --git a/actionpack/test/template/ajax_helper_test.rb b/actionpack/test/template/ajax_helper_test.rb index 77d1510bab..095454977e 100644 --- a/actionpack/test/template/ajax_helper_test.rb +++ b/actionpack/test/template/ajax_helper_test.rb @@ -101,6 +101,11 @@ class AjaxHelperTest < AjaxHelperBaseTest link_to_remote("Remote", { :url => { :action => "whatnot's" } }) end + test "link_to_remote with confirm" do + assert_dom_equal %(Remote confirm), + link_to_remote("Remote confirm", { :url => { :action => "whatnot" }, :method => "delete", :confirm => "Are you sure?"}, { :class => "fine" }) + end + test "button_to_remote" do assert_dom_equal %(), button_to_remote("Remote outpost", { :url => { :action => "whatnot" }}, { :class => "fine" }) @@ -114,6 +119,11 @@ class AjaxHelperTest < AjaxHelperBaseTest button_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot", :a => '10', :b => '20' }) end + test "button_to_remote with confirm" do + assert_dom_equal %(), + button_to_remote("Remote outpost", { :url => { :action => "whatnot" }, :confirm => "Are you sure?"}, { :class => "fine" }) + end + test "periodically_call_remote" do assert_dom_equal %(), periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" }) -- cgit v1.2.3