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.
- #confirm(label = '') ⇒ Object
- #controller ⇒ Object
-
#crud_type ⇒ Object
the crud type of the (eventual?) action.
- #dhtml_confirm ⇒ Object
-
#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? ⇒ 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
-
#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.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
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 |
#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
96 97 98 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 96 def crud_type @crud_type end |
#dhtml_confirm ⇒ Object
73 74 75 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 73 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
171 172 173 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 171 def eid @eid end |
#html_options ⇒ Object
html options for the link
160 161 162 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 160 def @html_options end |
#ignore_method ⇒ Object
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 |
#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
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_method ⇒ Object
83 84 85 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 83 def security_method @security_method || "#{self.action}_authorized?" end |
#type ⇒ Object
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
67 68 69 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 67 def confirm? @confirm ? true : false end |
#dhtml_confirm? ⇒ 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
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
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
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
118 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 118 def popup?; @popup end |
#security_method_set? ⇒ 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
40 41 42 |
# File 'lib/active_scaffold/data_structures/action_link.rb', line 40 def static_controller? !(@controller.is_a?(Proc) || (@controller == :polymorph)) end |