module ActiveScaffold::Actions::List
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 base.helper_method :save_current_page_num end
Public Instance Methods
index()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 9 def index list end
list()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 19 def list do_list do_new if active_scaffold_config.list.always_show_create @record ||= new_model if active_scaffold_config.list.always_show_search @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 14 def row @record = find_if_allowed(params[:id], :read) 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 do_search if respond_to? :do_search, true do_list redirect_to :action => 'index' end
action_update_respond_to_js()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 163 def action_update_respond_to_js render(:action => 'on_action_update') end
action_update_respond_to_json()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 172 def action_update_respond_to_json column_names = successful? ? list_columns_names : error_object_attributes render :text => response_object.to_json(:only => column_names, :methods => virtual_columns(column_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 167 def action_update_respond_to_xml column_names = successful? ? list_columns_names : error_object_attributes render :xml => response_object.to_xml(:only => column_names, :methods => virtual_columns(column_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 177 def action_update_respond_to_yaml column_names = successful? ? list_columns_names : error_object_attributes render :text => Hash.from_xml(response_object.to_xml(:only => column_names, :methods => virtual_columns(column_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 65 def do_list 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 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].to_s) 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 if active_scaffold_config.model.respond_to?(:tableless?) && active_scaffold_config.model.tableless? @records = Kaminari.paginate_array(active_scaffold_config.model.all) @records = @records.page(options[:page]).per(options[:per_page]) if options[:pagination] else @records = find_page(options); end @records end
each_record_in_page() { |record| ... }
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 89 def each_record_in_page _page = active_scaffold_config.list.user.page do_search if respond_to? :do_search, true 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 97 def each_record_in_scope do_search if respond_to? :do_search, true finder_options = { :reorder => "#{active_scaffold_config.model.connection.quote_table_name(active_scaffold_config.model.table_name)}.#{active_scaffold_config.model.primary_key} ASC", :where => all_conditions, :joins => joins_for_finder} finder_options.merge! custom_finder_options finder_options.merge! :includes => (active_scaffold_includes.blank? ? nil : active_scaffold_includes) klass = beginning_of_chain append_to_query(klass, finder_options) klass.find_each {|record| yield record} end
list_respond_to_html()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 28 def list_respond_to_html if params.delete(: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 35 def list_respond_to_js if params.delete(:embedded) render(:partial => 'list_with_header') else render :action => 'list.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 column_names = successful? ? list_columns_names : error_object_attributes response_text = response_object.to_json(:only => column_names + [active_scaffold_config.model.primary_key], :include => association_columns(column_names), :methods => virtual_columns(column_names)) render :text => response_text, :content_type => Mime::JSON, :status => response_status end
list_respond_to_xml()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 42 def list_respond_to_xml column_names = successful? ? list_columns_names : error_object_attributes render :xml => response_object.to_xml(:only => column_names, :methods => virtual_columns(column_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 51 def list_respond_to_yaml column_names = successful? ? list_columns_names : error_object_attributes render :text => Hash.from_xml(response_object.to_xml(:only => column_names, :methods => virtual_columns(column_names))).to_yaml, :content_type => Mime::YAML, :status => response_status end
process_action_link_action(render_action = :action_update) { |record| ... }
click to toggle source
call this method in your action_link action to simplify processing of actions eg for member action_link :fire process_action_link_action
do |record|
record.update_attributes(:fired => true) self.successful = true flash[:info] = 'Player fired'
end
# File lib/active_scaffold/actions/list.rb, line 122 def process_action_link_action(render_action = :action_update) if request.get? # someone has disabled javascript, we have to show confirmation form first @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0 respond_to_action(:action_confirmation) else begin if params[:id] && params[:id] && params[:id].to_i > 0 @record = find_if_allowed(params[:id], (request.post? || request.put?) ? :update : :delete) unless @record.nil? yield @record else self.successful = false flash[:error] = as_(:no_authorization_for_action, :action => action_name) end else yield end rescue ActiveRecord::RecordInvalid rescue ActiveRecord::StaleObjectError @record.errors.add(:base, as_(:version_inconsistency)) unless @record.nil? self.successful=false rescue ActiveRecord::RecordNotSaved @record.errors.add(:base, as_(:record_not_saved)) if !@record.nil? && @record.errors.empty? self.successful = false end respond_to_action(render_action) end end
row_respond_to_html()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 56 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 60 def row_respond_to_js render(:partial => 'row', :locals => {:record => @record}) end
save_current_page_num()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 182 def save_current_page_num active_scaffold_config.list.user.page = @records.current_page unless active_scaffold_config.list.pagination == false end
Private Instance Methods
action_confirmation_formats()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 200 def action_confirmation_formats (default_formats + active_scaffold_config.formats).uniq end
action_update_formats()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 196 def action_update_formats (default_formats + active_scaffold_config.formats).uniq end
list_columns()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 204 def list_columns active_scaffold_config.list.columns.collect_visible end
list_columns_names()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 208 def list_columns_names list_columns.collect(&:name) end
list_formats()
click to toggle source
# File lib/active_scaffold/actions/list.rb, line 191 def list_formats (default_formats + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq end
Also aliased as: row_formats