From 06dd23d67133601f2639695a0fadab81213f6200 Mon Sep 17 00:00:00 2001 From: "Erik St. Martin" Date: Sun, 24 Jan 2010 14:32:55 -0500 Subject: removing Prototype inline js for attributes for :with and :condition, it now is free form js that can be placed there, also moved :submit out into AjaxHelper, updated tests to reflect changes --- actionpack/lib/action_view/helpers/ajax_helper.rb | 28 ++++++++++----------- actionpack/test/template/ajax_helper_test.rb | 30 ++++++++++++++++++----- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/actionpack/lib/action_view/helpers/ajax_helper.rb b/actionpack/lib/action_view/helpers/ajax_helper.rb index fac7b8c44b..b29dc50c8d 100644 --- a/actionpack/lib/action_view/helpers/ajax_helper.rb +++ b/actionpack/lib/action_view/helpers/ajax_helper.rb @@ -503,6 +503,10 @@ module ActionView attributes.merge!(extract_request_attributes!(options)) attributes["data-remote"] = true + if submit = options.delete(:submit) + attributes["data-submit"] = submit + end + attributes end @@ -563,12 +567,13 @@ module ActionView def link_to_remote(name, options, html_options = {}) set_callbacks(options, html_options) - set_conditions(options, html_options) + set_with_and_condition_attributes(options, html_options) super end def button_to_remote(name, options = {}, html_options = {}) set_callbacks(options, html_options) + set_with_and_condition_attributes(options, html_options) super end @@ -581,7 +586,7 @@ module ActionView def observe_field(name, options = {}) html = {} - set_conditions(options, html) + set_with_and_condition_attributes(options, html) options.merge!(:callbacks => html) super end @@ -599,18 +604,13 @@ module ActionView end end - def set_conditions(options, html) - #TODO: Remove all references to prototype - BR - if options.delete(:form) - html["data-parameters"] = 'Form.serialize(this)' - elsif submit = options.delete(:submit) - html["data-parameters"] = "Form.serialize('#{submit}')" - elsif with = options.delete(:with) - if with !~ /[\{=(.]/ - html["data-with"] = "'#{with}=' + encodeURIComponent(value)" - else - html["data-with"] = with - end + def set_with_and_condition_attributes(options, html) + if with = options.delete(:with) + html["data-with"] = with + end + + if condition = options.delete(:condition) + html["data-condition"] = condition end end end diff --git a/actionpack/test/template/ajax_helper_test.rb b/actionpack/test/template/ajax_helper_test.rb index 6fa8a95d42..c688b25f70 100644 --- a/actionpack/test/template/ajax_helper_test.rb +++ b/actionpack/test/template/ajax_helper_test.rb @@ -92,9 +92,18 @@ class AjaxHelperTest < AjaxHelperBaseTest end test "link_to_remote using :with expression" do - expected = %(Remote outauthor) - assert_dom_equal expected, link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :with => "id") - assert_dom_equal expected, link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :with => "'id=' + encodeURIComponent(value)") + expected = %(Remote outauthor) + assert_dom_equal expected, link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :with => "id=123") + end + + test "link_to_remote using :condition expression" do + expected = %(Remote outauthor) + assert_dom_equal expected, link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :condition => '$(\'foo\').val() == true') + end + + test "link_to_remote using :submit" do + expected = %(Remote outauthor) + assert_dom_equal expected, link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :submit => 'myForm') end test "link_to_remote with method delete" do @@ -135,6 +144,11 @@ class AjaxHelperTest < AjaxHelperBaseTest button_to_remote("Remote outpost", { :url => { :action => "whatnot" }, :confirm => "Are you sure?"}, { :class => "fine" }) end + test "button_to_remote with :submit" do + assert_dom_equal %(), + button_to_remote("Remote outpost", { :url => { :action => "whatnot" }, :submit => "myForm"}, { :class => "fine" }) + end + test "periodically_call_remote" do assert_dom_equal %(), periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" }) @@ -258,9 +272,13 @@ class AjaxHelperTest < AjaxHelperBaseTest end test "observe_field using with option" do - expected = %() - assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => 'id') - assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "'id=' + encodeURIComponent(value)") + expected = %() + assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => 'id=123') + end + + test "observe_field using condition option" do + expected = %() + assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :condition => '$(\'foo\').val() == true') end test "observe_field using json in with option" do -- cgit v1.2.3