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.
-
#eid ⇒ Object
Internal use: generated eid for this action_link.
-
#html_options ⇒ Object
html options for the link.
-
#ignore_method ⇒ Object
Returns the value of attribute ignore_method.
-
#image ⇒ Object
image to use => ‘arrow.png’, :size => ‘16x16’.
- #label ⇒ Object
-
#method ⇒ Object
the RESTful method.
-
#parameters ⇒ Object
a hash of request parameters.
- #position ⇒ Object
- #security_method ⇒ Object
-
#type ⇒ Object
what type of link this is.
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.
-
#inline=(val) ⇒ Object
an “inline” link is inserted into the existing page exclusive with popup? and page?.
- #inline? ⇒ Boolean
-
#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.parameters = {} self. = {} self.column = nil self.image = nil self.dynamic_parameters = nil # apply quick properties .each_pair do |k, v| setter = "#{k}=" self.send(setter, v) if self.respond_to? setter end end |
Instance Attribute Details
#action ⇒ Object
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 |
#column ⇒ Object
nested action_links are referencing a column
167 168 169 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 167 def column @column end |
#controller ⇒ Object
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_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
100 101 102 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 100 def crud_type @crud_type end |
#dhtml_confirm ⇒ Object
if the action uses a DHTML based (i.e. 2-phase) confirmation
75 76 77 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 75 def dhtml_confirm @dhtml_confirm end |
#dynamic_parameters ⇒ Object
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 |
#eid ⇒ Object
Internal use: generated eid for this action_link
170 171 172 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 170 def eid @eid end |
#html_options ⇒ Object
html options for the link
164 165 166 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 164 def @html_options end |
#ignore_method ⇒ Object
Returns the value of attribute ignore_method.
95 96 97 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 95 def ignore_method @ignore_method end |
#image ⇒ Object
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 |
#label ⇒ Object
55 56 57 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 55 def label @label.is_a?(Symbol) ? as_(@label) : @label end |
#method ⇒ Object
the RESTful method
51 52 53 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 51 def method @method end |
#parameters ⇒ Object
a hash of request parameters
45 46 47 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 45 def parameters @parameters end |
#position ⇒ Object
153 154 155 156 157 158 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 153 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_method ⇒ Object
87 88 89 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 87 def security_method @security_method || "#{self.action}_authorized?" end |
#type ⇒ Object
what type of link this is. currently supported values are :collection and :member.
161 162 163 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 161 def type @type end |
Instance Method Details
#confirm(label = '') ⇒ Object
67 68 69 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 67 def confirm(label = '') @confirm.is_a?(String) ? @confirm : as_(@confirm, :label => label) end |
#confirm=(value) ⇒ Object
if the action requires confirmation
63 64 65 66 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 63 def confirm=(value) @dhtml_confirm = nil if value @confirm = value end |
#confirm? ⇒ Boolean
70 71 72 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 70 def confirm? !!@confirm end |
#dhtml_confirm? ⇒ Boolean
80 81 82 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 80 def dhtml_confirm? !!@dhtml_confirm end |
#inline=(val) ⇒ Object
an “inline” link is inserted into the existing page exclusive with popup? and page?
104 105 106 107 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 104 def inline=(val) @inline = (val == true) self.popup = self.page = false if @inline end |
#inline? ⇒ Boolean
108 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 108 def inline?; @inline end |
#page=(val) ⇒ Object
a “page” link displays by reloading the current page exclusive with inline? and popup?
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 126 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
139 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 139 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?
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 112 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
122 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 122 def popup?; @popup end |
#security_method_set? ⇒ Boolean
91 92 93 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 91 def security_method_set? !!@security_method end |
#static_controller? ⇒ Boolean
40 41 42 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 40 def static_controller? !@controller.is_a?(Proc) end |