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 %i[create new].include?(action.try(:to_sym))
  self.crud_type = :update if %i[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 respond_to? setter
  end
  self.toggle = self.action.try(:to_sym) == :index && (parameters.present? || dynamic_parameters) unless options.include? :toggle
end

Instance Attribute Details

#actionObject

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



38
39
40
# File 'lib/active_scaffold/data_structures/action_link.rb', line 38

def action
  @action
end

#columnObject

nested action_links are referencing a column



193
194
195
# File 'lib/active_scaffold/data_structures/action_link.rb', line 193

def column
  @column
end

#controllerObject



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

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



125
126
127
# File 'lib/active_scaffold/data_structures/action_link.rb', line 125

def crud_type
  @crud_type
end

#dhtml_confirmObject

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



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

def dhtml_confirm
  @dhtml_confirm
end

#dynamic_parametersObject

a block for dynamic_parameters



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

def dynamic_parameters
  @dynamic_parameters
end

#html_optionsObject



188
189
190
# File 'lib/active_scaffold/data_structures/action_link.rb', line 188

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



120
121
122
# File 'lib/active_scaffold/data_structures/action_link.rb', line 120

def ignore_method
  @ignore_method
end

#imageObject

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



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

def image
  @image
end

#keep_open=(value) ⇒ Object (writeonly)

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



196
197
198
# File 'lib/active_scaffold/data_structures/action_link.rb', line 196

def keep_open=(value)
  @keep_open = value
end

#labelObject



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

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

#methodObject

the RESTful method



67
68
69
# File 'lib/active_scaffold/data_structures/action_link.rb', line 67

def method
  @method
end

#parametersObject



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

def parameters
  @parameters ||= {}
end

#positionObject



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

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

#refresh_on_closeObject

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



116
117
118
# File 'lib/active_scaffold/data_structures/action_link.rb', line 116

def refresh_on_close
  @refresh_on_close
end

#security_methodObject



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

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

#toggleObject

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



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

def toggle
  @toggle
end

#typeObject

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



184
185
186
# File 'lib/active_scaffold/data_structures/action_link.rb', line 184

def type
  @type
end

#weightObject

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



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

def weight
  @weight
end

Instance Method Details

#confirm(label = '') ⇒ Object



84
85
86
# File 'lib/active_scaffold/data_structures/action_link.rb', line 84

def confirm(label = '')
  @confirm.is_a?(String) ? @confirm : as_(@confirm, :label => label)
end

#confirm=(value) ⇒ Object

if the action requires confirmation



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

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

#confirm?Boolean

Returns:

  • (Boolean)


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

def confirm?
  @confirm.present?
end

#dhtml_confirm?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/active_scaffold/data_structures/action_link.rb', line 99

def dhtml_confirm?
  @dhtml_confirm.present?
end

#initialize_copy(action_link) ⇒ Object



29
30
31
32
# 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

#inline=(val) ⇒ Object

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



129
130
131
132
# 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

#inline?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/active_scaffold/data_structures/action_link.rb', line 134

def inline?
  @inline
end

#keep_open?Boolean

Returns:

  • (Boolean)


197
198
199
# File 'lib/active_scaffold/data_structures/action_link.rb', line 197

def keep_open?
  @keep_open
end

#name_to_cacheObject



206
207
208
# File 'lib/active_scaffold/data_structures/action_link.rb', line 206

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

#nested_link?Boolean

indicates that this a nested_link

Returns:

  • (Boolean)


202
203
204
# File 'lib/active_scaffold/data_structures/action_link.rb', line 202

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?



156
157
158
159
# 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

#page?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/active_scaffold/data_structures/action_link.rb', line 161

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?



140
141
142
143
144
145
146
147
148
# 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

#popup?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/active_scaffold/data_structures/action_link.rb', line 150

def popup?
  @popup
end

#security_method_set?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/active_scaffold/data_structures/action_link.rb', line 111

def security_method_set?
  @security_method.present?
end

#static_controller?Boolean

Returns:

  • (Boolean)


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

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