65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/netzke/active_record/basepack.rb', line 65
def options_for(column, query = "")
NetzkePreference.widget_name = self.name
options = NetzkePreference[:combobox_options] || {}
if options[column]
options[column].select{ |o| o.index(/^#{query}/) }
elsif respond_to?("#{column}_combobox_options")
send("#{column}_combobox_options", query)
else
if (assoc_name, *assoc_method = column.split('__')).size > 1
assoc_method = assoc_method.join('__') association = reflect_on_association(assoc_name.to_sym) || raise(NameError, "Association #{assoc_name} not known for class #{name}")
association.klass.options_for(assoc_method, query)
else
column = assoc_name
if self.column_names.include?(column)
records = query.empty? ? find_by_sql("select distinct #{column} from #{table_name}") : find_by_sql("select distinct #{column} from #{table_name} where #{column} like '#{query}%'")
records.map{|r| r.send(column)}
else
records = self.find(:all).map{|r| r.send(column)}.uniq
query.empty? ? records : records.select{|r| r.index(/^#{query}/)}
end
end
end
end
|