Class: ActiveScaffold::DataStructures::ActionLink
- Defined in:
- lib/active_scaffold/data_structures/action_link.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
the action-path for this link.
-
#column ⇒ Object
nested action_links are referencing a column.
- #controller ⇒ Object
-
#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 ⇒ 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
-
#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
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, = {}) # 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 .each_pair do |k, v| setter = "#{k}=" send(setter, v) if self.respond_to? setter end self.toggle = self.action.try(:to_sym) == :index && (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!
38 39 40 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 38 def action @action end |
#column ⇒ Object
nested action_links are referencing a column
194 195 196 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 194 def column @column end |
#controller ⇒ Object
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_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
125 126 127 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 125 def crud_type @crud_type end |
#dhtml_confirm ⇒ Object
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_parameters ⇒ Object
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_options ⇒ Object
189 190 191 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 189 def @html_options ||= {} 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
120 121 122 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 120 def ignore_method @ignore_method end |
#image ⇒ Object
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
197 198 199 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 197 def keep_open=(value) @keep_open = value end |
#label ⇒ Object
71 72 73 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 71 def label @label.is_a?(Symbol) ? as_(@label) : @label end |
#method ⇒ Object
the RESTful method
67 68 69 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 67 def method @method end |
#parameters ⇒ Object
54 55 56 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 54 def parameters @parameters ||= {} end |
#position ⇒ Object
177 178 179 180 181 182 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 177 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
116 117 118 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 116 def refresh_on_close @refresh_on_close end |
#security_method ⇒ Object
107 108 109 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 107 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
61 62 63 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 61 def toggle @toggle end |
#type ⇒ Object
what type of link this is. currently supported values are :collection and :member.
185 186 187 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 185 def type @type end |
#weight ⇒ Object
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
88 89 90 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 88 def confirm? @confirm.present? end |
#dhtml_confirm? ⇒ 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. = .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
134 135 136 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 134 def inline? @inline end |
#keep_open? ⇒ Boolean
198 199 200 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 198 def keep_open? @keep_open end |
#name_to_cache ⇒ Object
207 208 209 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 207 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
203 204 205 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 203 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
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
150 151 152 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 150 def popup? @popup end |
#security_method_set? ⇒ 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
48 49 50 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 48 def static_controller? !(@controller.is_a?(Proc) || (@controller == :polymorph)) end |