Class: ActiveScaffold::DataStructures::ActionLink

Inherits:
Object
  • Object
show all
Defined in:
lib/active_scaffold/data_structures/action_link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, options = {}) ⇒ ActionLink

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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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

Instance Attribute Details

#actionObject

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



30
31
32
# File 'lib/active_scaffold/data_structures/action_link.rb', line 30

def action
  @action
end

#columnObject

nested action_links are referencing a column



173
174
175
# File 'lib/active_scaffold/data_structures/action_link.rb', line 173

def column
  @column
end

#controllerObject



35
36
37
38
# File 'lib/active_scaffold/data_structures/action_link.rb', line 35

def controller
  @controller = @controller.call if @controller.is_a?(Proc)
  @controller
end

#crud_typeObject

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



106
107
108
# File 'lib/active_scaffold/data_structures/action_link.rb', line 106

def crud_type
  @crud_type
end

#dhtml_confirmObject

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



75
76
77
# File 'lib/active_scaffold/data_structures/action_link.rb', line 75

def dhtml_confirm
  @dhtml_confirm
end

#dynamic_parametersObject

a block for dynamic_parameters



48
49
50
# File 'lib/active_scaffold/data_structures/action_link.rb', line 48

def dynamic_parameters
  @dynamic_parameters
end

#eidObject

Internal use: generated eid for this action_link



181
182
183
# File 'lib/active_scaffold/data_structures/action_link.rb', line 181

def eid
  @eid
end

#html_optionsObject

html options for the link



170
171
172
# File 'lib/active_scaffold/data_structures/action_link.rb', line 170

def html_options
  @html_options
end

#ignore_methodObject

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



101
102
103
# File 'lib/active_scaffold/data_structures/action_link.rb', line 101

def ignore_method
  @ignore_method
end

#imageObject

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



60
61
62
# File 'lib/active_scaffold/data_structures/action_link.rb', line 60

def image
  @image
end

#labelObject



55
56
57
# File 'lib/active_scaffold/data_structures/action_link.rb', line 55

def label
  @label.is_a?(Symbol) ? as_(@label) : @label
end

#methodObject

the RESTful method



51
52
53
# File 'lib/active_scaffold/data_structures/action_link.rb', line 51

def method
  @method
end

#parametersObject

a hash of request parameters



45
46
47
# File 'lib/active_scaffold/data_structures/action_link.rb', line 45

def parameters
  @parameters
end

#positionObject



159
160
161
162
163
164
# 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

#refresh_on_closeObject

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



97
98
99
# File 'lib/active_scaffold/data_structures/action_link.rb', line 97

def refresh_on_close
  @refresh_on_close
end

#security_methodObject



88
89
90
# File 'lib/active_scaffold/data_structures/action_link.rb', line 88

def security_method
  @security_method || "#{self.action}_authorized?"
end

#typeObject

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



167
168
169
# File 'lib/active_scaffold/data_structures/action_link.rb', line 167

def type
  @type
end

Instance Method Details

#confirm(label = '') ⇒ Object



67
68
69
# 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) ⇒ Object

if the action requires confirmation



63
64
65
66
# File 'lib/active_scaffold/data_structures/action_link.rb', line 63

def confirm=(value)
  @dhtml_confirm = nil if value
  @confirm = value
end

#confirm?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/active_scaffold/data_structures/action_link.rb', line 70

def confirm?
  !!@confirm
end

#dhtml_confirm?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/active_scaffold/data_structures/action_link.rb', line 80

def dhtml_confirm?
  !!@dhtml_confirm
end

#inline=(val) ⇒ Object

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



110
111
112
113
# 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?Boolean

Returns:

  • (Boolean)


114
# File 'lib/active_scaffold/data_structures/action_link.rb', line 114

def inline?; @inline end

#nested_link?Boolean

indicates that this a nested_link

Returns:

  • (Boolean)


176
177
178
# File 'lib/active_scaffold/data_structures/action_link.rb', line 176

def nested_link?
  @column || (parameters && parameters[:named_scope])
end

#page=(val) ⇒ Object

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



132
133
134
135
136
137
138
139
140
141
142
143
144
# 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?Boolean

Returns:

  • (Boolean)


145
# File 'lib/active_scaffold/data_structures/action_link.rb', line 145

def page?; @page end

#popup=(val) ⇒ Object

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



118
119
120
121
122
123
124
125
126
127
# File 'lib/active_scaffold/data_structures/action_link.rb', line 118

def popup=(val)
  @popup = (val == true)
  if @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
end

#popup?Boolean

Returns:

  • (Boolean)


128
# File 'lib/active_scaffold/data_structures/action_link.rb', line 128

def popup?; @popup end

#security_method_set?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/active_scaffold/data_structures/action_link.rb', line 92

def security_method_set?
  !!@security_method
end

#static_controller?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/active_scaffold/data_structures/action_link.rb', line 40

def static_controller?
  !(@controller.is_a?(Proc) || (@controller == :polymorph))
end