Module: ActionView::Helpers::JavaScriptMacrosHelper

Defined in:
lib/smklib/somekool_scaffold.rb

Instance Method Summary collapse

Instance Method Details

#in_place_collection_dropdown(field_id, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/smklib/somekool_scaffold.rb', line 16

def in_place_collection_dropdown(field_id, options = {})
	function =  "new Ajax.InPlaceCollectionEditor("
	function << "'#{field_id}', "
	function << "'#{url_for(options[:url])}'"

	js_options = {}
	js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text]
	js_options['okText'] = %('#{options[:save_text]}') if options[:save_text]
	js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text]
	#js_options['rows'] = options[:rows] if options[:rows]
	#js_options['cols'] = options[:cols] if options[:cols]
	#js_options['size'] = options[:size] if options[:size]
	js_options['collection'] = options[:collection] if options[:collection]
	js_options['value'] = options[:value] if options[:value]
	js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control]
	js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url]
	js_options['ajaxOptions'] = options[:options] if options[:options]
	js_options['evalScripts'] = options[:script] if options[:script]
	js_options['callback']   = "function(form) { return #{options[:with]} }" if options[:with]
	function << (', ' + options_for_javascript(js_options)) unless js_options.empty?

	function << ')'

	javascript_tag(function)
end

#in_place_editor_dropdown(object, method, tag_options = {}, in_place_editor_options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/smklib/somekool_scaffold.rb', line 43

def in_place_editor_dropdown(object, method, tag_options = {}, in_place_editor_options = {})
	tag = ::ActionView::Helpers::InstanceTag.new(object, method, self)
raise tag.inspect if tag_options[:crash]
	front_val = tag_options.delete(:front_val)
	tag_options = {:tag => "span", :id => "#{object}_#{method}_#{tag.object.id}_in_place_editor", :class => "in_place_editor_field"}.merge!(tag_options)
	in_place_editor_options[:url] = in_place_editor_options[:url] || url_for({ :action => "set_#{object}_#{method}", :id => tag.object.id })
	(front_val.to_s.empty? ? tag.(tag_options.delete(:tag), tag_options) : tag.(tag_options.delete(:tag), front_val, tag_options)) +
	in_place_collection_dropdown(tag_options[:id], in_place_editor_options)
end