class ActiveScaffold::DataStructures::ActionLink

Constants

NO_OPTIONS

Attributes

action[RW]

the action-path for this link. what page to request? this is required!

column[RW]

nested action_links are referencing a column

controller[W]

the controller for this action link. if nil, the current controller should be assumed.

controller_actions[RW]

for links in singular associations, copied from column.actions_for_association_links, excluding actions not available in association’s controller

crud_type[RW]

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

dhtml_confirm[R]

if the action uses a DHTML based (i.e. 2-phase) confirmation

dynamic_parameters[RW]

a block for dynamic_parameters

html_options[W]

html options for the link

ignore_method[RW]

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[RW]

image to use {:name => ‘arrow.png’, :size => ‘16x16’}

keep_open[W]

don’t close the panel when another action link is open

label[W]

what string to use to represent this action

method[RW]

the RESTful method

parameters[W]

a hash of request parameters

position[W]

where the result of this action should insert in the display. for :type => :collection, supported values are:

:top
: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)
refresh_on_close[RW]

enable it to refresh the parent row when the view is closed

security_method[W]

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).

toggle[RW]

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

type[RW]

what type of link this is. currently supported values are :collection and :member.

weight[RW]

the weight for this link in the action links collection, it will be used to sort the collection

Public Class Methods

new(action, options = {}) click to toggle source

provides a quick way to set any property of the object from a hash

# File lib/active_scaffold/data_structures/action_link.rb, line 6
def initialize(action, options = {})
  # set defaults
  @action = action
  @label = action
  @confirm = false
  @type = :collection
  @method = :get
  @crud_type =
    case action&.to_sym
    when :destroy then :delete
    when :create, :new then :create
    when :update, :edit then :update
    else :read
    end
  @column = nil
  @image = nil
  @controller = nil
  @parameters = nil
  @dynamic_parameters = nil
  @html_options = nil
  @weight = 0
  self.inline = true

  # apply quick properties
  options.each_pair do |k, v|
    setter = "#{k}="
    send(setter, v) if respond_to? setter
  end
  self.toggle = self.action&.to_sym == :index && !position && (parameters.present? || dynamic_parameters) unless options.include? :toggle
end

Public Instance Methods

confirm(label = '') click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 93
def confirm(label = '')
  return @confirm if !confirm? || @confirm.is_a?(String)
  ActiveScaffold::Registry.cache(:translations, @confirm) { as_(@confirm) } % {label: label}
end
confirm=(value) click to toggle source

if the action requires confirmation

# File lib/active_scaffold/data_structures/action_link.rb, line 88
def confirm=(value)
  @dhtml_confirm = nil if value
  @confirm = value
end
confirm?() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 98
def confirm?
  @confirm.present?
end
controller() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 51
def controller
  @controller = @controller.call if @controller.is_a?(Proc)
  @controller
end
dhtml_confirm=(value) click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 104
def dhtml_confirm=(value)
  @confirm = nil if value
  @dhtml_confirm = value
end
dhtml_confirm?() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 109
def dhtml_confirm?
  @dhtml_confirm.present?
end
freeze() click to toggle source
Calls superclass method
# File lib/active_scaffold/data_structures/action_link.rb, line 234
def freeze
  # force generating cache_key, except for column's link without action, or polymorphic associations
  name_to_cache if action && !column&.association&.polymorphic?
  super
end
html_options() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 198
def html_options
  return @html_options || NO_OPTIONS if frozen?
  @html_options ||= NO_OPTIONS.dup
end
initialize_copy(action_link) click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 37
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
inline=(val) click to toggle source

an “inline” link is inserted into the existing page exclusive with popup? and page?

# File lib/active_scaffold/data_structures/action_link.rb, line 139
def inline=(val)
  @inline = (val == true)
  self.popup = self.page = false if @inline
end
inline?() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 144
def inline?
  @inline
end
keep_open?() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 208
def keep_open?
  @keep_open
end
label() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 80
def label
  @label.is_a?(Symbol) ? ActiveScaffold::Registry.cache(:translations, @label) { as_(@label) } : @label
end
name_to_cache() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 222
def name_to_cache
  return @name_to_cache if defined? @name_to_cache
  [
    controller || 'self',
    type,
    action,
    *parameters.map { |k, v| "#{k}=#{v.is_a?(Array) ? v.join(',') : v}" }
  ].compact.join('_').tap do |name_to_cache|
    @name_to_cache = name_to_cache unless frozen?
  end
end
page=(val) click to toggle source

a “page” link displays by reloading the current page exclusive with inline? and popup?

# File lib/active_scaffold/data_structures/action_link.rb, line 166
def page=(val)
  @page = (val == true)
  self.inline = self.popup = false if @page
end
page?() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 171
def page?
  @page
end
parameters() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 62
def parameters
  return @parameters || NO_OPTIONS if frozen?
  @parameters ||= NO_OPTIONS.dup
end
popup=(val) click to toggle source

a “popup” link displays in a separate (browser?) window. this will eventually take arguments. exclusive with inline? and page?

popup?() click to toggle source
position() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 186
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
security_method() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 117
def security_method
  @security_method || "#{action}_authorized?"
end
security_method_set?() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 121
def security_method_set?
  @security_method.present?
end
static_controller?() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 56
def static_controller?
  !(@controller.is_a?(Proc) || (@controller == :polymorph))
end