Sha256: cad331c6d0ae92097bf0f1f5b7f57f64dc33bacbb2c4e55a6d6127503a5e0de7

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 KB

Contents

module Rails3JQueryAutocomplete
  module Orm
    module Mongoid
      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)

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rails3-jquery-autocomplete-1.0.10 lib/rails3-jquery-autocomplete/orm/mongoid.rb
rails3-jquery-autocomplete-1.0.9 lib/rails3-jquery-autocomplete/orm/mongoid.rb
rails3-jquery-autocomplete-1.0.8 lib/rails3-jquery-autocomplete/orm/mongoid.rb
rails3-jquery-autocomplete-1.0.7 lib/rails3-jquery-autocomplete/orm/mongoid.rb
rails3-jquery-autocomplete-1.0.6 lib/rails3-jquery-autocomplete/orm/mongoid.rb
rails3-jquery-autocomplete-1.0.5 lib/rails3-jquery-autocomplete/orm/mongoid.rb
rails3-jquery-autocomplete-1.0.4 lib/rails3-jquery-autocomplete/orm/mongoid.rb
rails3-jquery-autocomplete-1.0.3 lib/rails3-jquery-autocomplete/orm/mongoid.rb
rails3-jquery-autocomplete-1.0.2 lib/rails3-jquery-autocomplete/orm/mongoid.rb
rails3-jquery-autocomplete-1.0.1 lib/rails3-jquery-autocomplete/orm/mongoid.rb
rails3-jquery-autocomplete-1.0.0 lib/rails3-jquery-autocomplete/orm/mongoid.rb