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



163
164
165
# File 'lib/active_scaffold/data_structures/action_link.rb', line 163

def column
  @column
end

#confirm(label = '') ⇒ Object



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

def confirm(label = '')
  @confirm.is_a?(String) ? @confirm : as_(@confirm, :label => label)
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



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

def crud_type
  @crud_type
end

#dhtml_confirmObject



73
74
75
# File 'lib/active_scaffold/data_structures/action_link.rb', line 73

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



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

def eid
  @eid
end

#html_optionsObject

html options for the link



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

def html_options
  @html_options
end

#ignore_methodObject

Returns the value of attribute ignore_method.



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

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



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

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_methodObject



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

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

#typeObject

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



157
158
159
# File 'lib/active_scaffold/data_structures/action_link.rb', line 157

def type
  @type
end

Instance Method Details

#confirm?Boolean

Returns:

  • (Boolean)


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

def confirm?
  @confirm ? true : false
end

#dhtml_confirm?Boolean

Returns:

  • (Boolean)


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

def dhtml_confirm?
  @dhtml_confirm
end

#inline=(val) ⇒ Object

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



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

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

#inline?Boolean

Returns:

  • (Boolean)


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

def inline?; @inline end

#nested_link?Boolean

indicates that this a nested_link

Returns:

  • (Boolean)


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

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?



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/active_scaffold/data_structures/action_link.rb', line 122

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)


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

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?



108
109
110
111
112
113
114
115
116
117
# File 'lib/active_scaffold/data_structures/action_link.rb', line 108

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)


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

def popup?; @popup end

#security_method_set?Boolean

Returns:

  • (Boolean)


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

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