-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple models #42
base: master
Are you sure you want to change the base?
Multiple models #42
Changes from 12 commits
d076658
41f5a44
2b5a44f
79fdd56
e238eb8
2f5aa5e
9408d66
da5c46e
78acac4
6a0a337
de031c9
743777c
38f59e5
71abe4c
4697867
9794d25
bc153a3
b5e7803
065247f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ def self.included(target) | |
# end | ||
# | ||
module ClassMethods | ||
def autocomplete(object, method, options = {}, &block) | ||
def autocomplete(name, object_method_hash, options = {}, &block) | ||
|
||
define_method("get_prefix") do |model| | ||
if defined?(Mongoid::Document) && model.include?(Mongoid::Document) | ||
|
@@ -49,30 +49,36 @@ def autocomplete(object, method, options = {}, &block) | |
'active_record' | ||
end | ||
end | ||
define_method("get_autocomplete_order") do |method, options, model=nil| | ||
method("#{get_prefix(get_object(options[:class_name] || object))}_get_autocomplete_order").call(method, options, model) | ||
define_method("get_autocomplete_order") do |object, method, options, model=nil| | ||
method("#{get_prefix(get_object(object))}_get_autocomplete_order").call(method, options, model) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [105/80] |
||
end | ||
|
||
define_method("get_autocomplete_items") do |parameters| | ||
method("#{get_prefix(get_object(options[:class_name] || object))}_get_autocomplete_items").call(parameters) | ||
define_method("get_autocomplete_items") do |object, parameters| | ||
method("#{get_prefix(get_object(object))}_get_autocomplete_items").call(parameters) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [93/80] |
||
end | ||
|
||
define_method("autocomplete_#{object}_#{method}") do | ||
# var = {:object => :method, "class_name" => "column_id", \ | ||
# :object => "column_id", "class_name" => :method} | ||
# #Pass parameters as autocomplete :name, var | ||
# :name creates the name of the action | ||
define_method("autocomplete_#{name}") do | ||
|
||
method = options[:column_name] if options.has_key?(:column_name) | ||
json = Array.new | ||
|
||
term = params[:term] | ||
|
||
if term && !term.blank? | ||
#allow specifying fully qualified class name for model object | ||
class_name = options[:class_name] || object | ||
items = get_autocomplete_items(:model => get_object(class_name), \ | ||
:options => options, :term => term, :method => method) | ||
else | ||
items = {} | ||
|
||
object_method_hash.each do |object, method| | ||
#allow specifying fully qualified class name for model object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space after #. |
||
#both object and method can be specified by object or id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space after #. |
||
items = get_autocomplete_items(object, :model => get_object(object), \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [84/80] |
||
:options => options, :term => term, :method => method) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the elements of a hash literal if they span more than one line. |
||
json += json_for_autocomplete(items, options[:display_value] ||= method, options[:extra_data], &block) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [117/80] |
||
end | ||
end | ||
|
||
render :json => json_for_autocomplete(items, options[:display_value] ||= method, options[:extra_data], &block), root: false | ||
render :json => json, root: false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
end | ||
end | ||
end | ||
|
@@ -98,7 +104,7 @@ def get_object(model_sym) | |
# | ||
def json_for_autocomplete(items, method, extra_data=[]) | ||
items = items.collect do |item| | ||
hash = {"id" => item.id.to_s, "label" => item.send(method), "value" => item.send(method)} | ||
hash = { "id" => item.id.to_s, "label" => item.send(method), "value" => item.send(method) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [99/80] |
||
extra_data.each do |datum| | ||
hash[datum] = item.send(datum) | ||
end if extra_data | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shadowing outer local variable -
options
.Line is too long. [87/80]
Surrounding space missing in default value assignment.