module ApplicationHelper def select_dropover_field(object_name, method, tag_options = {}, dropover_options = {}, object = nil) tag = ::ActionView::Helpers::InstanceTag.new(object_name, method, self, nil, object) tag_options = { :tag => "span", :id => "#{object_name}_#{method}_#{tag.object.id}_select_dropover", :class => "select_dropover_field", }.merge!(tag_options) dropover_options = { :id => "#{object_name}_#{method}_#{tag.object.id}_SDO", :backgroundcolor => "getBackgroundColor('#{tag_options[:id]}')", }.merge!(dropover_options) dropover_options[:url] = dropover_options[:url] || url_for({:controller => "/" + object_name.to_s.pluralize, :action => "set_#{object_name}_#{method}", :id => tag.object.id }) content_tag(tag_options.delete(:tag), tag_options.delete(:content), tag_options) + select_dropover(tag_options[:id], dropover_options.delete(:id), dropover_options) end def select_dropover(field_id, object_id, options = {}) function = "var #{object_id} = " function << "new SelectDropOver(" function << "'#{field_id}', " function << "'#{url_for(options[:url])}', " [:options, :url, :current].each { |k| options[k] = options[k].to_json if options[k] } function << options_for_javascript(options) function << ')' javascript_tag(function) end end