class ActiveScaffold::DataStructures::ActionLink

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.

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

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

dynamic_parameters[RW]

a block for #dynamic_parameters

eid[RW]

Internal use: generated eid for this action_link

html_options[RW]

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’}

label[W]

what string to use to represent this action

method[RW]

the RESTful method

parameters[RW]

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

type[RW]

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

Public Instance Methods

confirm(label = '') click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 67
def confirm(label = '')
  @confirm.is_a?(String) ? @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 63
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 70
def confirm?
  !!@confirm
end
controller() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 35
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 76
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 80
def dhtml_confirm?
  !!@dhtml_confirm
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 110
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 114
def inline?; @inline end
label() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 55
def label
  @label.is_a?(Symbol) ? as_(@label) : @label
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 132
def page=(val)
  @page = (val == true)
  if @page
    self.inline = self.popup = false

    # when :method is defined, ActionView adds an onclick to use a form ...
    # so it's best to just empty out :method whenever possible.
    # we only ever need to know @method = :get for things that default to POST.
    # the only things that default to POST are forms and ajax calls.
    # when @page = true, we don't use ajax.
    self.method = nil if method == :get
  end
end
page?() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 145
def page?; @page 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 159
def position
  return @position unless @position.nil? or @position == true
  return :replace if self.type == :member
  return :top if self.type == :collection
  raise "what should the default position be for #{self.type}?"
end
security_method() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 88
def security_method
  @security_method || "#{self.action}_authorized?"
end
security_method_set?() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 92
def security_method_set?
  !!@security_method
end
static_controller?() click to toggle source
# File lib/active_scaffold/data_structures/action_link.rb, line 40
def static_controller?
  !(@controller.is_a?(Proc) || (@controller == :polymorph))
end

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 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.parameters = {}
  self.html_options = {}
  self.column = nil
  self.image = nil
  self.dynamic_parameters = nil

  # apply quick properties
  options.each_pair do |k, v|
    setter = "#{k}="
    self.send(setter, v) if self.respond_to? setter
  end
end