Class: Lapillus::AjaxLink

Inherits:
Container show all
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

Pager::PagerButton

Instance Attribute Summary

Attributes inherited from Container

#components

Attributes inherited from Component

#behaviours, #identifier, #model, #property, #visible

Instance Method Summary collapse

Methods inherited from Container

#[], #add, add_component, #component, fileuploadfield, image, label, listview, panel, password_textfield, #post, #render_children, textarea, textfield

Methods inherited from Component

#add_behaviour, #behaviour, #has_behaviour?, #has_model?, #has_parent?, #parent, #path, #response_page=, #session, #value, #webpage

Methods inherited from RenderableComponent

#on_render, #render_behaviours, #render_children, #render_container, #visible?

Constructor Details

#initialize(id, options = {}) ⇒ AjaxLink

Returns a new instance of AjaxLink.



172
173
174
175
# File 'lib/lapillus/behaviours.rb', line 172

def initialize(id, options={})
  super(id, options)
  value.add_behaviour(UniqueIdentifier.new) if has_model?
end

Instance Method Details

#on_clickObject



195
196
197
# File 'lib/lapillus/behaviours.rb', line 195

def on_click
  instance_eval(&@function)
end

#on_click_handler=(function) ⇒ Object



191
192
193
# File 'lib/lapillus/behaviours.rb', line 191

def on_click_handler=function
  @function=function
end

#render_componentObject



199
200
201
# File 'lib/lapillus/behaviours.rb', line 199

def render_component
  value.render_component if has_model?
end

#render_to_element(element) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/lapillus/behaviours.rb', line 177

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