Class: ActiveScaffold::DataStructures::ActionLink
- Defined in:
- lib/active_scaffold/data_structures/action_link.rb
Constant Summary collapse
- NO_OPTIONS =
{}.freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
the action-path for this link.
-
#column ⇒ Object
nested action_links are referencing a column.
- #controller ⇒ Object
-
#controller_actions ⇒ Object
for links in singular associations, copied from column.actions_for_association_links, excluding actions not available in association’s controller.
-
#crud_type ⇒ Object
the crud type of the (eventual?) action.
-
#dhtml_confirm ⇒ Object
if the action uses a DHTML based (i.e. 2-phase) confirmation.
-
#dynamic_parameters ⇒ Object
a block for dynamic_parameters.
- #html_options ⇒ Object
-
#ignore_method ⇒ Object
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 ⇒ Object
image to use ‘arrow.png’, size: ‘16x16’.
-
#keep_open ⇒ Object
writeonly
don’t close the panel when another action link is open.
- #label(record = nil) ⇒ Object
-
#method ⇒ Object
the RESTful method.
- #parameters ⇒ Object
- #position ⇒ Object
-
#refresh_on_close ⇒ Object
enable it to refresh the parent row when the view is closed.
- #security_method ⇒ Object
-
#toggle ⇒ Object
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.
-
#type ⇒ Object
what type of link this is.
-
#weight ⇒ Object
the weight for this link in the action links collection, it will be used to sort the collection.
Instance Method Summary collapse
- #confirm(label = '') ⇒ Object
-
#confirm=(value) ⇒ Object
if the action requires confirmation.
- #confirm? ⇒ Boolean
- #dhtml_confirm? ⇒ Boolean
- #freeze ⇒ Object
-
#initialize(action, options = {}) ⇒ ActionLink
constructor
provides a quick way to set any property of the object from a hash.
- #initialize_copy(action_link) ⇒ Object
-
#inline=(val) ⇒ Object
an “inline” link is inserted into the existing page exclusive with popup? and page?.
- #inline? ⇒ Boolean
- #keep_open? ⇒ Boolean
- #name_to_cache ⇒ Object
-
#nested_link? ⇒ Boolean
indicates that this a nested_link.
-
#page=(val) ⇒ Object
a “page” link displays by reloading the current page exclusive with inline? and popup?.
- #page? ⇒ Boolean
-
#popup=(val) ⇒ Object
a “popup” link displays in a separate (browser?) window.
- #popup? ⇒ Boolean
- #security_method_set? ⇒ Boolean
- #static_controller? ⇒ Boolean
Constructor Details
#initialize(action, options = {}) ⇒ ActionLink
provides a quick way to set any property of the object from a hash
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 6 def initialize(action, = {}) # set defaults @action = action @label = action @confirm = false @type = :collection @method = :get @crud_type = case action&.to_sym when :destroy then :delete when :create, :new then :create when :update, :edit then :update else :read end @column = nil @image = nil @controller = nil @parameters = nil @dynamic_parameters = nil @html_options = nil @weight = 0 self.inline = true # apply quick properties .each_pair do |k, v| setter = "#{k}=" send(setter, v) if respond_to? setter end self.toggle = self.action&.to_sym == :index && !position && (parameters.present? || dynamic_parameters) unless .include? :toggle end |
Instance Attribute Details
#action ⇒ Object
the action-path for this link. what page to request? this is required!
46 47 48 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 46 def action @action end |
#column ⇒ Object
nested action_links are referencing a column
225 226 227 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 225 def column @column end |
#controller ⇒ Object
51 52 53 54 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 51 def controller @controller = @controller.call if @controller.is_a?(Proc) @controller end |
#controller_actions ⇒ Object
for links in singular associations, copied from column.actions_for_association_links, excluding actions not available in association’s controller
237 238 239 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 237 def controller_actions @controller_actions end |
#crud_type ⇒ Object
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
148 149 150 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 148 def crud_type @crud_type end |
#dhtml_confirm ⇒ Object
if the action uses a DHTML based (i.e. 2-phase) confirmation
114 115 116 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 114 def dhtml_confirm @dhtml_confirm end |
#dynamic_parameters ⇒ Object
a block for dynamic_parameters
75 76 77 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 75 def dynamic_parameters @dynamic_parameters end |
#html_options ⇒ Object
218 219 220 221 222 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 218 def return @html_options || NO_OPTIONS if frozen? @html_options ||= NO_OPTIONS.dup end |
#ignore_method ⇒ Object
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
143 144 145 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 143 def ignore_method @ignore_method end |
#image ⇒ Object
image to use ‘arrow.png’, size: ‘16x16’
95 96 97 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 95 def image @image end |
#keep_open=(value) ⇒ Object (writeonly)
don’t close the panel when another action link is open
228 229 230 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 228 def keep_open=(value) @keep_open = value end |
#label(record = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 83 def label(record = nil) case @label when Symbol ActiveScaffold::Registry.cache(:translations, @label) { as_(@label) } when Proc @label.call(record) else @label end end |
#method ⇒ Object
the RESTful method
78 79 80 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 78 def method @method end |
#parameters ⇒ Object
63 64 65 66 67 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 63 def parameters return @parameters || NO_OPTIONS if frozen? @parameters ||= NO_OPTIONS.dup end |
#position ⇒ Object
204 205 206 207 208 209 210 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 204 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_close ⇒ Object
enable it to refresh the parent row when the view is closed
139 140 141 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 139 def refresh_on_close @refresh_on_close end |
#security_method ⇒ Object
130 131 132 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 130 def security_method @security_method || "#{action}_authorized?" end |
#toggle ⇒ Object
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
72 73 74 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 72 def toggle @toggle end |
#type ⇒ Object
what type of link this is. currently supported values are :collection and :member.
213 214 215 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 213 def type @type end |
#weight ⇒ Object
the weight for this link in the action links collection, it will be used to sort the collection
43 44 45 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 43 def weight @weight end |
Instance Method Details
#confirm(label = '') ⇒ Object
103 104 105 106 107 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 103 def confirm(label = '') return @confirm if !confirm? || @confirm.is_a?(String) ActiveScaffold::Registry.cache(:translations, @confirm) { as_(@confirm) } % {label: label} end |
#confirm=(value) ⇒ Object
if the action requires confirmation
98 99 100 101 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 98 def confirm=(value) @dhtml_confirm = nil if value @confirm = value end |
#confirm? ⇒ Boolean
109 110 111 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 109 def confirm? @confirm.present? end |
#dhtml_confirm? ⇒ Boolean
121 122 123 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 121 def dhtml_confirm? @dhtml_confirm.present? end |
#freeze ⇒ Object
257 258 259 260 261 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 257 def freeze # force generating cache_key, except for column's link without action, or polymorphic associations name_to_cache if action && !column&.association&.polymorphic? super end |
#initialize_copy(action_link) ⇒ Object
37 38 39 40 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 37 def initialize_copy(action_link) self.parameters = parameters.clone if action_link.instance_variable_get(:@parameters) self. = .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?
152 153 154 155 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 152 def inline=(val) @inline = (val == true) self.popup = self.page = false if @inline end |
#inline? ⇒ Boolean
157 158 159 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 157 def inline? @inline end |
#keep_open? ⇒ Boolean
230 231 232 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 230 def keep_open? @keep_open end |
#name_to_cache ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 244 def name_to_cache return @name_to_cache if defined? @name_to_cache [ controller || 'self', type, action, *parameters.map { |k, v| "#{k}=#{v.is_a?(Array) ? v.join(',') : v}" } ].compact.join('_').tap do |name_to_cache| @name_to_cache = name_to_cache unless frozen? end end |
#nested_link? ⇒ Boolean
indicates that this a nested_link
240 241 242 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 240 def nested_link? @column || parameters&.dig(:named_scope) end |
#page=(val) ⇒ Object
a “page” link displays by reloading the current page exclusive with inline? and popup?
180 181 182 183 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 180 def page=(val) @page = (val == true) self.inline = self.popup = false if @page end |
#page? ⇒ Boolean
185 186 187 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 185 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?
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 163 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
174 175 176 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 174 def popup? @popup end |
#security_method_set? ⇒ Boolean
134 135 136 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 134 def security_method_set? @security_method.present? end |
#static_controller? ⇒ Boolean
56 57 58 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 56 def static_controller? !(@controller.is_a?(Proc) || (@controller == :polymorph)) end |