class ActiveScaffold::DataStructures::ActionLink
Attributes
the action-path for this link. what page to request? this is required!
nested action_links are referencing a column
the controller for this action link. if nil, the current controller should be assumed.
the crud type of the (eventual?) action. different than :method, because this crud action may not be imminent. this is used to determine record-level authorization (e.g. record.authorized_for?(:crud_type => link.crud_type). options are :create, :read, :update, and :delete
if the action uses a DHTML based (i.e. 2-phase) confirmation
a block for #dynamic_parameters
html options for the link
what method to call on the controller to see if this action_link should be visible if method return true, link won't be displayed
image to use {:name => 'arrow.png', :size => '16x16'}
don't close the panel when another action link is open
what string to use to represent this action
the RESTful method
a hash of request parameters
where the result of this action should insert in the display. for :type => :collection, supported values are:
:top :bottom :replace (for updating the entire table) false (no attempt at positioning)
for :type => :member, supported values are:
:before :replace :after false (no attempt at positioning)
enable it to refresh the parent row when the view is closed
what method to call on the controller to see if this action_link should be visible if method return false, link will be disabled note that this is only the UI part of the security. to prevent URL hax0rz, you also need security on requests (e.g. don't execute update method unless authorized).
if active class is added to link when current request matches link enabled automatically for links to index with parameters or dynamic parameters disable when is not needed so current request match check is skipped
what type of link this is. currently supported values are :collection and :member.
the weight for this link in the action links collection, it will be used to sort the collection
Public Class Methods
provides a quick way to set any property of the object from a hash
# File lib/active_scaffold/data_structures/action_link.rb, line 4 def initialize(action, options = {}) # set defaults self.action = action self.label = action self.confirm = false self.type = :collection self.inline = true self.method = :get self.crud_type = :delete if [:destroy].include?(action.try(:to_sym)) self.crud_type = :create if [:create, :new].include?(action.try(:to_sym)) self.crud_type = :update if [:edit, :update].include?(action.try(:to_sym)) self.crud_type ||= :read self.column = nil self.image = nil self.dynamic_parameters = nil self.weight = 0 # apply quick properties options.each_pair do |k, v| setter = "#{k}=" send(setter, v) if self.respond_to? setter end self.toggle = self.action.try(:to_sym) == :index && (parameters.present? || dynamic_parameters) unless options.include? :toggle end
Public Instance Methods
# File lib/active_scaffold/data_structures/action_link.rb, line 84 def confirm(label = '') @confirm.is_a?(String) ? @confirm : as_(@confirm, :label => label) end
if the action requires confirmation
# File lib/active_scaffold/data_structures/action_link.rb, line 79 def confirm=(value) @dhtml_confirm = nil if value @confirm = value end
# File lib/active_scaffold/data_structures/action_link.rb, line 88 def confirm? @confirm.present? end
# File lib/active_scaffold/data_structures/action_link.rb, line 43 def controller @controller = @controller.call if @controller.is_a?(Proc) @controller end
# File lib/active_scaffold/data_structures/action_link.rb, line 94 def dhtml_confirm=(value) @confirm = nil if value @dhtml_confirm = value end
# File lib/active_scaffold/data_structures/action_link.rb, line 99 def dhtml_confirm? @dhtml_confirm.present? end
# File lib/active_scaffold/data_structures/action_link.rb, line 189 def html_options @html_options ||= {} end
# File lib/active_scaffold/data_structures/action_link.rb, line 29 def initialize_copy(action_link) self.parameters = parameters.clone if action_link.instance_variable_get(:@parameters) self.html_options = html_options.clone if action_link.instance_variable_get(:@html_options) end
an “inline” link is inserted into the existing page exclusive with popup? and page?
# File lib/active_scaffold/data_structures/action_link.rb, line 129 def inline=(val) @inline = (val == true) self.popup = self.page = false if @inline end
# File lib/active_scaffold/data_structures/action_link.rb, line 134 def inline? @inline end
# File lib/active_scaffold/data_structures/action_link.rb, line 198 def keep_open? @keep_open end
# File lib/active_scaffold/data_structures/action_link.rb, line 71 def label @label.is_a?(Symbol) ? as_(@label) : @label end
# File lib/active_scaffold/data_structures/action_link.rb, line 207 def name_to_cache @name_to_cache ||= "#{controller || 'self'}_#{type}_#{action}#{'_' if parameters.present?}#{parameters.map { |k, v| "#{k}=#{v.is_a?(Array) ? v.join(',') : v}" }.join('_')}" end
indicates that this a nested_link
# File lib/active_scaffold/data_structures/action_link.rb, line 203 def nested_link? @column || (parameters && parameters[:named_scope]) end
a “page” link displays by reloading the current page exclusive with inline? and popup?
# File lib/active_scaffold/data_structures/action_link.rb, line 156 def page=(val) @page = (val == true) self.inline = self.popup = false if @page end
# File lib/active_scaffold/data_structures/action_link.rb, line 161 def page? @page end
# File lib/active_scaffold/data_structures/action_link.rb, line 54 def parameters @parameters ||= {} end
a “popup” link displays in a separate (browser?) window. this will eventually take arguments. exclusive with inline? and page?
# File lib/active_scaffold/data_structures/action_link.rb, line 140 def popup=(val) @popup = (val == true) return unless @popup self.inline = self.page = false # the :method parameter doesn't mix with the :popup parameter # when/if we start using DHTML popups, we can bring :method back self.method = nil end
# File lib/active_scaffold/data_structures/action_link.rb, line 150 def popup? @popup end
# File lib/active_scaffold/data_structures/action_link.rb, line 177 def position return @position unless @position.nil? || @position == true return :replace if type == :member return :top if type == :collection raise "what should the default position be for #{type}?" end
# File lib/active_scaffold/data_structures/action_link.rb, line 107 def security_method @security_method || "#{action}_authorized?" end
# File lib/active_scaffold/data_structures/action_link.rb, line 111 def security_method_set? @security_method.present? end
# File lib/active_scaffold/data_structures/action_link.rb, line 48 def static_controller? !(@controller.is_a?(Proc) || (@controller == :polymorph)) end