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.column = nil
  self.image = nil
  self.dynamic_parameters = nil
  self.weight = 0

  # apply quick properties
  options.each_pair do |k, v|
    setter = "#{k}="
    self.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

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



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

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



122
123
124
# File 'lib/active_scaffold/data_structures/action_link.rb', line 122

def crud_type
  @crud_type
end

#dhtml_confirmObject

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



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

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



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

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



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

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



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

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



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

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



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

def refresh_on_close
  @refresh_on_close
end

#security_methodObject



104
105
106
# File 'lib/active_scaffold/data_structures/action_link.rb', line 104

def security_method
  @security_method || "#{self.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.



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

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



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

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)


86
87
88
# File 'lib/active_scaffold/data_structures/action_link.rb', line 86

def confirm?
  !!@confirm
end

#dhtml_confirm?Boolean

Returns:

  • (Boolean)


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

def dhtml_confirm?
  !!@dhtml_confirm
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 = self.parameters.clone if action_link.instance_variable_get(:@parameters)
  self.html_options = self.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?



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

def inline=(val)
  @inline = (val == true)
  self.popup = self.page = false if @inline
end

#inline?Boolean

Returns:

  • (Boolean)


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

def inline?; @inline end

#keep_open?Boolean

Returns:

  • (Boolean)


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

def keep_open?
  @keep_open
end

#name_to_cacheObject



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

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)


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

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?



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/active_scaffold/data_structures/action_link.rb', line 148

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)


161
# 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?



134
135
136
137
138
139
140
141
142
143
# File 'lib/active_scaffold/data_structures/action_link.rb', line 134

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)


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

def popup?; @popup end

#security_method_set?Boolean

Returns:

  • (Boolean)


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

def security_method_set?
  !!@security_method
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