Sha256: 1be86f2497d66fa8c84c0d79dfd640387e17ec482112b8107883bbd4f7987459

Contents?: true

Size: 952 Bytes

Versions: 15

Compression:

Stored size: 952 Bytes

Contents

module Rails3JQueryAutocomplete
	module Orm
		module MongoMapper
			def get_autocomplete_order(method, options, model=nil)
        order = options[:order]
        if order
          order.split(',').collect do |fields|
            sfields = fields.split
            [sfields[0].downcase.to_sym, sfields[1].downcase.to_sym]
          end
        else
          [[method.to_sym, :asc]]
        end
			end

			def get_autocomplete_items(parameters)
        model          = parameters[:model]
        method         = parameters[:method]
        options        = parameters[:options]
        is_full_search = options[:full]
        term           = parameters[:term]
        limit          = get_autocomplete_limit(options)
        order          = get_autocomplete_order(method, options)

        search = (is_full_search ? '.*' : '^') + term + '.*'
				items  = model.where(method.to_sym => /#{search}/i).limit(limit).sort(order)
			end
		end	
	end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rails3-jquery-autocomplete-1.0.12 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.11 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.10 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.9 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.8 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.7 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.6 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.5 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.4 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.3 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.2 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.1 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-1.0.0 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-0.9.1 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
rails3-jquery-autocomplete-0.9.0 lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb