Module InPlaceMacrosHelper
In: lib/in_place_with_auto_complete.rb

Methods

Public Instance methods

Renders the value of the specified object and method with in-place and autocomplete editing capabilities.

[Source]

    # File lib/in_place_with_auto_complete.rb, line 44
44:   def in_place_editor_field_with_auto_complete(object, method, tag_options = {}, in_place_editor_options = {}, completion_options = {})
45:     tag = ::ActionView::Helpers::InstanceTag.new(object, method, self)
46:     tag_options = {:nil_content_replacement => "--", :tag => "span", :id => "#{object}_#{method}_#{tag.object.id}_in_place_editor", :class => "in_place_editor_field"}.merge!(tag_options)
47: 
48:     value = tag.value(tag.object)
49:     if (value.blank?)
50:       value = tag_options.delete(:nil_content_replacement)
51:     end
52:     
53:     in_place_editor_options[:url] = in_place_editor_options[:url] || url_for({ :action => "set_#{object}_#{method}", :id => tag.object.id })
54:     in_place_editor_options[:cancel_text] ||= 'cancelar'
55:     in_place_editor_options[:click_to_edit_text] ||= 'click para modificar'
56:     in_place_editor_options[:loading_text] ||= 'leyendo ...'
57:     in_place_editor_options[:saving_text] ||= 'guardando ...'
58:     
59:     completion_options = completion_options.merge({:input_id => "#{object}_#{method}", :autocompleter_url => url_for(:action => "auto_complete_for_#{object}_#{method}", :id => tag.object.id)})
60:     
61:     tag.content_tag(tag_options.delete(:tag), value, tag_options) + 
62:     content_tag("div", "", :id => "#{object}_#{method}_auto_complete", :class => "auto_complete") +
63:     in_place_editor_with_autocompleter(tag_options[:id], in_place_editor_options.merge(completion_options))
64:   end

[Source]

    # File lib/in_place_with_auto_complete.rb, line 3
 3:   def in_place_editor_with_autocompleter(field_id, options = {})
 4:     function =  "new Ajax.InPlaceEditorWithAutocompleter("
 5:     function << "'#{field_id}', "
 6:     function << "'#{url_for(options[:url])}'"
 7:     js_options = {}
 8: 
 9:     if protect_against_forgery?
10:       options[:with] ||= "Form.serialize(form)"
11:       options[:with] += " + '&authenticity_token=' + encodeURIComponent('#{form_authenticity_token}')"
12:     end
13:     js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text]
14:     js_options['okText'] = %('#{options[:save_text]}') if options[:save_text]    
15:     js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text]
16:     js_options['savingText'] = %('#{options[:saving_text]}') if options[:saving_text]
17:     js_options['rows'] = options[:rows] if options[:rows]
18:     js_options['cols'] = options[:cols] if options[:cols]
19:     js_options['size'] = options[:size] if options[:size]
20:     js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control]
21:     js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url]       
22:  
23:     js_options['ajaxOptions'] = options[:options] if options[:options]
24:     js_options['htmlResponse'] = !options[:script] if options[:script]
25:     js_options['callback']   = "function(form) { return #{options[:with]} }" if options[:with]
26:     js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text]
27:     js_options['textBetweenControls'] = %('#{options[:text_between_controls]}') if options[:text_between_controls]
28:     
29:     js_options['onComplete'] = "function(form) { return #{options[:complete]} }" if options[:complete]
30:     
31:     js_options['inputID'] = %('#{options[:input_id]}') if options[:input_id]
32:     js_options['autocompleterUrl'] = %('#{options[:autocompleter_url]}') if options[:autocompleter_url]
33:     js_options['indicator'] = %('#{options[:indicator]}') if options[:indicator]
34: 
35:     function << (', ' + options_for_javascript(js_options)) unless js_options.empty?
36:     
37:     function << ')'
38:     
39:     javascript_tag(function)
40:   end

[Validate]