1 2 module ApplicationHelper
3
4 def in_place_editor_field_with_local_autocomplete(object, method, tag_options = {},
5 in_place_editor_options = {}, autocomplete_options = {})
6 tag = ::ActionView::Helpers::InstanceTag.new(object, method, self)
7 tag_options = { :tag => "span",
8 :id => "#{object}_#{method}_#{tag.object.id}_in_place_editor",
9 :class => "in_place_editor_field"}.merge!(tag_options)
10 in_place_editor_options[:url] =
11 in_place_editor_options[:url] ||
12 url_for({ :action => "set_#{object}_#{method}", :id => tag.object.id })
13 tag.to_content_tag(tag_options.delete(:tag), tag_options) +
14 in_place_editor_with_local_autocomplete(tag_options[:id], in_place_editor_options, autocomplete_options)
15 end
16
17 def in_place_editor_with_local_autocomplete(field_id, options = {}, autocomplete_options = {})
18 function = "new Ajax.InPlaceEditorWithLocalAutocomplete("
19 function << "'#{field_id}', "
20 function << "'#{url_for(options[:url])}', "
21 function << options_for_javascript(
22 {
23 'catalog' => autocomplete_options.delete(:catalog),
24 'autocomplete_options' => options_for_javascript( autocomplete_options )
25 }
26 )
27 function << ')'
28 javascript_tag(function)
29 end
30
31 end
32