module ActiveScaffold::Actions::Mark

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_all]
  base.prepend_before_filter :assign_marked_records_to_model
  base.helper_method :marked_records
end

Public Instance Methods

mark_all() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 10
def mark_all
  if mark_all? || mark_all_scope_forced?
    do_mark_all
  else
    do_demark_all
  end
  respond_to_action(:mark_all)
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 33
def assign_marked_records_to_model
  active_scaffold_config.model.marked_records = marked_records
end
do_demark_all() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 57
def do_demark_all
  if active_scaffold_config.mark.mark_all_mode == :page then
    each_record_in_page {|record| marked_records.delete(record.id)}
  else
    each_record_in_scope {|record| marked_records.delete(record.id)}
  end
end
do_mark_all() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 49
def do_mark_all
  if active_scaffold_config.mark.mark_all_mode == :page && !mark_all_scope_forced? then
    each_record_in_page {|record| marked_records << record.id}
  else
    each_record_in_scope {|record| marked_records << record.id}
  end
end
mark_all?() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 41
def mark_all?
  @mark_all ||= [true, 'true', 1, '1', 'T', 't'].include?(params[:value].class == String ? params[:value].downcase : params[:value])
end
mark_all_formats() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 71
def mark_all_formats
  (default_formats + active_scaffold_config.formats).uniq
end
mark_all_respond_to_html() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 20
def mark_all_respond_to_html
  do_list
  list_respond_to_html
end
mark_all_respond_to_js() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 25
def mark_all_respond_to_js
  do_list
  render :action => 'on_mark_all', :locals => {:mark_all => mark_all?}
end
mark_all_scope_forced?() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 45
def mark_all_scope_forced?
  !params[:mark_target].nil? && params[:mark_target]=='scope'
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 67
def mark_authorized?
  authorized_for?(:action => :read)
end
marked_records() click to toggle source
# File lib/active_scaffold/actions/mark.rb, line 37
def marked_records
  active_scaffold_session_storage[:marked_records] ||= Set.new
end