Permalink
Browse files

refactor params and with into copat module

  • Loading branch information...
1 parent a5e9d03 commit d9af0dfac4c4935097671ff0d8b21876ff6c019a @stevestmartin stevestmartin committed with stefanpenner Jan 24, 2010
Showing with 26 additions and 13 deletions.
  1. +26 −13 actionpack/lib/action_view/helpers/ajax_helper.rb
@@ -464,8 +464,11 @@ def periodically_call_remote(options = {})
#
#
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 @@ def extract_request_attributes!(options)
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 AjaxHelperCompat
def link_to_remote(name, options, html_options = {})
set_callbacks(options, html_options)
+ set_conditions(options, html_options)
super
end
@@ -588,6 +579,13 @@ def form_remote_tag(options, &block)
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 @@ def set_callbacks(options, html)
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

0 comments on commit d9af0df

Please sign in to comment.