module ActiveScaffold::Actions::List

Public Instance Methods

index() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 8
def index
  list
end
list() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 18
def list
  if %w(index list).include? action_name
    do_list
  else
    do_refresh_list
  end
  @nested_auto_open = active_scaffold_config.list.nested_auto_open
  respond_to_action(:list)
end
row() click to toggle source

get just a single row

# File lib/active_scaffold/actions/list.rb, line 13
def row
  get_row
  respond_to_action(:row)
end

Protected Instance Methods

action_confirmation_respond_to_html(confirm_action = action_name.to_sym) click to toggle source
# File lib/active_scaffold/actions/list.rb, line 152
def action_confirmation_respond_to_html(confirm_action = action_name.to_sym)
  link = active_scaffold_config.action_links[confirm_action]
  render :action => 'action_confirmation', :locals => {:record => @record, :link => link}
end
action_update_respond_to_html() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 157
def action_update_respond_to_html
  redirect_to :action => 'index'
end
action_update_respond_to_js() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 161
def action_update_respond_to_js
  do_refresh_list unless @record.present?
  render(:action => 'on_action_update')
end
action_update_respond_to_json() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 170
def action_update_respond_to_json
  render :text => successful? ? "" : response_object.to_json(:only => list_columns_names), :content_type => Mime::JSON, :status => response_status
end
action_update_respond_to_xml() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 166
def action_update_respond_to_xml
  render :xml => successful? ? "" : response_object.to_xml(:only => list_columns_names), :content_type => Mime::XML, :status => response_status
end
action_update_respond_to_yaml() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 174
def action_update_respond_to_yaml
  render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
end
do_list() click to toggle source

The actual algorithm to prepare for the list view

# File lib/active_scaffold/actions/list.rb, line 75
def do_list
  set_includes_for_list_columns

  options = { :sorting => active_scaffold_config.list.user.sorting,
    :count_includes => active_scaffold_config.list.user.count_includes }
  paginate = (params[:format].nil?) ? (accepts? :html, :js) : ['html', 'js'].include?(params[:format])
  if paginate
    options.merge!({
        :per_page => active_scaffold_config.list.user.per_page,
        :page => active_scaffold_config.list.user.page,
        :pagination => active_scaffold_config.list.pagination
      })
  end

  page = find_page(options)
  total_pages = page.pager.number_of_pages
  if !page.pager.infinite? && !total_pages.zero? && page.number > total_pages
    page = page.pager.last
    active_scaffold_config.list.user.page = page.number
  end
  @page, @records = page, page.items
end
do_refresh_list() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 98
def do_refresh_list
  do_search if respond_to? :do_search
  do_list
end
each_record_in_page() { |record| ... } click to toggle source
# File lib/active_scaffold/actions/list.rb, line 103
def each_record_in_page
  _page = active_scaffold_config.list.user.page
  do_search if respond_to? :do_search
  active_scaffold_config.list.user.page = _page
  do_list
  @page.items.each {|record| yield record}
end
each_record_in_scope() { |record| ... } click to toggle source
# File lib/active_scaffold/actions/list.rb, line 111
def each_record_in_scope
  do_search if respond_to? :do_search
  append_to_query(beginning_of_chain, finder_options).all.each {|record| yield record}
end
get_row() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 68
def get_row
  set_includes_for_list_columns
  klass = beginning_of_chain.includes(active_scaffold_includes)
  @record = find_if_allowed(params[:id], :read, klass)
end
list_authorized?() click to toggle source

The default security delegates to ActiveRecordPermissions. You may override the method to customize.

# File lib/active_scaffold/actions/list.rb, line 118
def list_authorized?
  authorized_for?(:crud_type => :read)
end
list_respond_to_html() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 29
def list_respond_to_html
  if embedded?
    render :action => 'list', :layout => false
  else
    render :action => 'list'
  end
end
list_respond_to_js() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 36
def list_respond_to_js
  if params[:adapter] || embedded?
    render(:partial => 'list_with_header')
  else
    render :partial => 'refresh_list', :formats => [:js]
  end
end
list_respond_to_json() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 46
def list_respond_to_json
  render :text => response_object.to_json(:only => list_columns_names), :content_type => Mime::JSON, :status => response_status
end
list_respond_to_xml() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 43
def list_respond_to_xml
  render :xml => response_object.to_xml(:only => list_columns_names), :content_type => Mime::XML, :status => response_status
end
list_respond_to_yaml() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 49
def list_respond_to_yaml
  render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
end
row_respond_to_html() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 53
def row_respond_to_html
  render(:partial => 'row', :locals => {:record => @record})
end
row_respond_to_js() click to toggle source
# File lib/active_scaffold/actions/list.rb, line 57
def row_respond_to_js
  render
end
set_includes_for_list_columns() click to toggle source

The actual algorithm to prepare for the list view

# File lib/active_scaffold/actions/list.rb, line 62
def set_includes_for_list_columns
  @cache_associations = true
  includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact
  self.active_scaffold_includes.concat includes_for_list_columns
end

Public Class Methods

included(base) click to toggle source
# File lib/active_scaffold/actions/list.rb, line 3
def self.included(base)
  base.before_filter :list_authorized_filter, :only => [:index, :row]
  base.helper_method :list_columns
end