module ActiveScaffold::Actions::Mark

Public Instance Methods

mark() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 10
def mark
  if mark? || mark_all_scope_forced?
    do_mark
  else
    do_demark
  end
  if marked_records.length > 0
    count = marked_records.length
    flash[:info] = as_(:records_marked, :count => count, :model => active_scaffold_config.label(:count => count))
  end
  respond_to_action(:mark)
end

Protected Instance Methods

assign_marked_records_to_model() click to toggle source

We need to give the ActiveRecord classes a handle to currently marked records. We don’t want to just pass the object, because the object may change. So we give ActiveRecord a proc that ties to the marked_records_method on this ApplicationController.

# File lib/active_scaffold/actions/mark.rb, line 42
def assign_marked_records_to_model
  active_scaffold_config.model.marked_records = marked_records
end
do_demark() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 64
def do_demark
  if params[:id]
    find_if_allowed(params[:id], :read).as_marked = false
  elsif active_scaffold_config.mark.mark_all_mode == :page
    each_record_in_page { |record| record.as_marked = false }
  else
    each_record_in_scope { |record| record.as_marked = false }
  end
end
do_destroy() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 74
def do_destroy
  super
  @record.as_marked = false if successful?
end
do_mark() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 54
def do_mark
  if params[:id]
    find_if_allowed(params[:id], :read).as_marked = true
  elsif active_scaffold_config.mark.mark_all_mode == :page && !mark_all_scope_forced?
    each_record_in_page { |record| record.as_marked = true }
  else
    each_record_in_scope { |record| record.as_marked = true }
  end
end
mark?() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 46
def mark?
  @mark ||= [true, 'true', 1, '1', 'T', 't'].include?(params[:value].class == String ? params[:value].downcase : params[:value])
end
mark_all_scope_forced?() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 50
def mark_all_scope_forced?
  params[:mark_target] == 'scope' unless params[:id]
end
mark_authorized?() click to toggle source

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

# File lib/active_scaffold/actions/mark.rb, line 81
def mark_authorized?
  authorized_for?(:crud_type => :read)
end
mark_formats() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 85
def mark_formats
  (default_formats + active_scaffold_config.formats).uniq
end
mark_respond_to_html() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 24
def mark_respond_to_html
  do_list
  list_respond_to_html
end
mark_respond_to_js() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 29
def mark_respond_to_js
  if params[:id]
    do_search if respond_to? :do_search
    set_includes_for_list_columns
    @page = find_page(:pagination => active_scaffold_config.mark.mark_all_mode != :page)
    render :action => 'on_mark'
  else
    render :action => 'on_mark', :locals => {:checked => mark?}
  end
end

Public Class Methods

included(base) click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 4
def self.included(base)
  base.before_filter :mark_authorized?, :only => :mark
  base.before_filter :assign_marked_records_to_model
  base.helper_method :marked_records
end