Class: Lapillus::AjaxLink
- Defined in:
- lib/lapillus/behaviours.rb
Overview
value is the component to rerender when a link is clicked the component should have an id attribute which is set to its path
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Container
Attributes inherited from Component
#behaviours, #identifier, #model, #property, #visible
Instance Method Summary collapse
-
#initialize(id, value = nil) ⇒ AjaxLink
constructor
A new instance of AjaxLink.
- #on_click ⇒ Object
- #on_click_handler=(function) ⇒ Object
- #render_component ⇒ Object
- #render_to_element(element) ⇒ Object
Methods inherited from Container
#[], #add, add_component, #component, fileuploadfield, image, label, listview, panel, password_textfield, #post, #render_container, textarea, textfield
Methods inherited from Component
#add_behaviour, #behaviour, #has_behaviour?, #has_model?, #has_parent?, #on_render, #parent, #path, #response_page=, #session, #value, #visible?, #webpage
Constructor Details
#initialize(id, value = nil) ⇒ AjaxLink
Returns a new instance of AjaxLink.
150 151 152 153 |
# File 'lib/lapillus/behaviours.rb', line 150 def initialize(id, value=nil) super(id, value) value.add_behaviour(UniqueIdentifier.new) if has_model? end |
Instance Method Details
#on_click ⇒ Object
173 174 175 |
# File 'lib/lapillus/behaviours.rb', line 173 def on_click instance_eval(&@function) end |
#on_click_handler=(function) ⇒ Object
169 170 171 |
# File 'lib/lapillus/behaviours.rb', line 169 def on_click_handler=function @function=function end |
#render_component ⇒ Object
177 178 179 |
# File 'lib/lapillus/behaviours.rb', line 177 def render_component value.render_component if has_model? end |
#render_to_element(element) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/lapillus/behaviours.rb', line 155 def render_to_element(element) if has_model? javascript = "new Ajax.Updater('#{value.path}', '', { evalScripts: true, method:'get', parameters: { listener:'#{path}' }}); return false;" else javascript = "new Ajax.Request('', { method: 'get', parameters: { listener:'#{path}' }}); return false;" end attribute = REXML::Attribute.new("onclick", javascript) def attribute.to_string return "#@expanded_name=\"#@value\"" end element.add_attribute(attribute) element.add_attribute("href","#") end |