Sha256: 0bfaf875a5d63699131b3fe8774c968ec8fe3404d41748e87279bf45535ca96e

Contents?: true

Size: 1.93 KB

Versions: 7

Compression:

Stored size: 1.93 KB

Contents

module Netzke
  module Basepack
    # A Form with paging toolbar. Allows browsing and editing records one-by-one.
    #
    # == Configuration
    # Besides +Netzke::Form::Base+ config options, accepts:
    # * +scope+ - specifies how the data should be filtered.
    #   When it's a symbol, it's used as a scope name.
    #   When it's a string, it's a SQL statement (passed directly to +ActiveRecord::Relation#where+).
    #   When it's a hash, it's a conditions hash (passed directly to +ActiveRecord::Relation#where+).
    #   When it's an array, it's expanded into an SQL statement with arguments (passed directly to +ActiveRecord::Relation#where+), e.g.:
    #
    #     :scope => ["id > ?", 100])
    #
    #   When it's a Proc, it's passed the model class, and is expected to return an ActiveRecord::Relation, e.g.:
    #
    #     :scope => { |rel| rel.where(:id.gt => 100).order(:created_at) }
    #
    # == ToDo
    # * Update the number of records after form submit
    class PagingForm < Form
      # override
      def record
        @record ||= model_adapter.first
      end

      def configure_client(c)
        super
        # Pass total records amount and the first record to the JS constructor
        c.total_records = total_records
      end

      endpoint :get_data do |params|
        @record = model_adapter.get_records(params).first
        record_hash = @record && js_record_data
        client.merge!(:records => record_hash && [record_hash] || [], :total => total_records(params))
      end

      action :search do |a|
        a.icon = :find
        a.select = true
      end

      def configure_bbar(c)
        super
        c[:bbar] << :search
      end

      component :search_form do |c|
        c.klass = SearchWindow
        c.model = config[:model]
        c.fields = fields
      end

    protected

      def total_records(params = {})
        @total_records ||= model_adapter.count_records(params, [])
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
netzke-basepack-6.5.0.0.rc1 lib/netzke/basepack/paging_form.rb
netzke-basepack-1.0.1.0 lib/netzke/basepack/paging_form.rb
netzke-basepack-1.0.0.1 lib/netzke/basepack/paging_form.rb
netzke-basepack-1.0.0.0 lib/netzke/basepack/paging_form.rb
netzke-basepack-1.0.0.0.pre3 lib/netzke/basepack/paging_form.rb
netzke-basepack-1.0.0.0.pre2 lib/netzke/basepack/paging_form.rb
netzke-basepack-1.0.0.0.pre lib/netzke/basepack/paging_form.rb