Sha256: 5e43066f860f464b2c788a7f53f5a2e3e434a61cb6867bff1ab2d3aa6d851e82

Contents?: true

Size: 1.63 KB

Versions: 39

Compression:

Stored size: 1.63 KB

Contents

module Effective
  module EffectiveDatatable
    module Dsl
      module Filters
        def filter(name = nil, value = :_no_value, as: nil, label: nil, parse: nil, required: false, **input_html)
          return datatable.filter if (name == nil && value == :_no_value) # This lets block methods call 'filter' and get the values

          raise 'expected second argument to be a value' if value == :_no_value
          raise 'parse must be a Proc' if parse.present? && !parse.kind_of?(Proc)

          datatable._filters[name.to_sym] = {
            value: value,
            as: as,
            label: label || name.to_s.titleize,
            name: name.to_sym,
            parse: parse,
            required: required,
            input_html: input_html
          }
        end

        def scope(name = nil, *args, default: nil, label: nil)
          return datatable.scope unless name # This lets block methods call 'scope' and get the values

          datatable._scopes[name.to_sym] = {
            default: default,
            label: label || name.to_s.titleize,
            name: name.to_sym,
            args: args.presence
          }
        end

        # This changes the filters from using an AJAX, to a POST or GET
        def form(url: nil, verb: nil)
          url ||= request.path
          verb ||= (Rails.application.routes.recognize_path(url, method: :post).present? rescue false) ? :post : :get

          datatable._form[:url] = url
          datatable._form[:verb] = verb
        end

        def changes_columns_count
          form()
        end
        alias_method :changes_column_count, :changes_columns_count

      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
effective_datatables-3.3.9 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.3.8 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.3.7 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.3.6 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.3.5 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.3.4 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.3.3 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.3.2 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.3.1 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.3.0 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.2.7 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.2.6 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.2.5 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.2.4 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.2.3 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.2.2 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.2.1 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.2 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.1.3 app/models/effective/effective_datatable/dsl/filters.rb
effective_datatables-3.1.2 app/models/effective/effective_datatable/dsl/filters.rb