aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorStephen St. Martin <kuprishuz@gmail.com>2010-01-24 13:33:07 -0500
committerStefan Penner <stefan.penner@gmail.com>2010-01-27 12:44:33 -0600
commitd9af0dfac4c4935097671ff0d8b21876ff6c019a (patch)
treeee6d10e34d24171ee73c5253d515e064d29de434 /actionpack
parenta5e9d033e81152e1b2280042ba6289c8a231e8bf (diff)
downloadrails-d9af0dfac4c4935097671ff0d8b21876ff6c019a.tar.gz
rails-d9af0dfac4c4935097671ff0d8b21876ff6c019a.tar.bz2
rails-d9af0dfac4c4935097671ff0d8b21876ff6c019a.zip
refactor params and with into copat module
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/ajax_helper.rb39
1 files changed, 26 insertions, 13 deletions
diff --git a/actionpack/lib/action_view/helpers/ajax_helper.rb b/actionpack/lib/action_view/helpers/ajax_helper.rb
index e8dd960e6b..fac7b8c44b 100644
--- a/actionpack/lib/action_view/helpers/ajax_helper.rb
+++ b/actionpack/lib/action_view/helpers/ajax_helper.rb
@@ -464,8 +464,11 @@ module ActionView
#
#
def observe_field(name, options = {})
+ html_options = options.delete(:callbacks)
+
options[:observed] = name
attributes = extract_observer_attributes!(options)
+ attributes.merge!(html_options) if html_options
script_decorator(attributes)
end
@@ -512,19 +515,6 @@ module ActionView
url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)
attributes["data-url"] = escape_javascript(url_for(url_options))
- #TODO: Remove all references to prototype - BR
- if options.delete(:form)
- attributes["data-parameters"] = 'Form.serialize(this)'
- elsif submit = options.delete(:submit)
- attributes["data-parameters"] = "Form.serialize('#{submit}')"
- elsif with = options.delete(:with)
- if with !~ /[\{=(.]/
- attributes["data-with"] = "'#{with}=' + encodeURIComponent(value)"
- else
- attributes["data-with"] = with
- end
- end
-
purge_unused_attributes!(attributes)
end
@@ -573,6 +563,7 @@ module ActionView
def link_to_remote(name, options, html_options = {})
set_callbacks(options, html_options)
+ set_conditions(options, html_options)
super
end
@@ -588,6 +579,13 @@ module ActionView
super
end
+ def observe_field(name, options = {})
+ html = {}
+ set_conditions(options, html)
+ options.merge!(:callbacks => html)
+ super
+ end
+
private
def set_callbacks(options, html)
[:before, :after, :uninitialized, :complete, :failure, :success, :interactive, :loaded, :loading].each do |type|
@@ -600,6 +598,21 @@ module ActionView
end
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
+ end
+ end
end
end
end