Class: SWS::ImageButton
- Inherits:
-
FormElement
- Object
- Component
- FormElement
- SWS::ImageButton
- Defined in:
- lib/sws/Core/components/ImageButton/ImageButton.rb
Overview
Represents <INPUT type=image HTML tag Bindings:
-
value (required,default: “Submit”) - string to be displayed on the button.
-
action - method to be called on button click
-
other_tag_string - generic string to add to the tag
-
src - URL to image source
-
resource - name of the resource to be used as the image
-
framework - the framework the resource resides in
Instance Attribute Summary
Attributes inherited from Component
#action_components, #definition_component, #encoding, #html_attrs, #method_to_call, #name, #parameters, #parent, #request, #request_number, #slots, #subcomponents, #tokens
Instance Method Summary collapse
-
#append_to_response(response) ⇒ Object
Appends #generate_html() output to response.
-
#generate_html ⇒ Object
Generates HTML output containing <INPUT type=“submit” tag.
-
#initialize(*args) ⇒ ImageButton
constructor
A new instance of ImageButton.
-
#perform_action ⇒ Object
If the action has been set up (see #update_binding( key,value )) it is called now.
-
#update_binding(key, value) ⇒ Object
Overriden method from Component class - sets the action to perform if the “value” parameter is not empty.
Methods inherited from FormElement
Methods inherited from Component
#api_filename, #app, #awake, #container?, #content?, create, #create_component_tree, #definition_filename, #page, #process_bindings, #process_parameters, #process_request, #remove_subcomponents, #session, #set_request_subcomponents, #sleep, #slot_bound?, #subcomponent_for_name, synchronize_slot, #synchronize_slot?, #synchronize_slots, #template_filename, #tokenize_binding, #url_string
Constructor Details
#initialize(*args) ⇒ ImageButton
Returns a new instance of ImageButton.
14 15 16 17 |
# File 'lib/sws/Core/components/ImageButton/ImageButton.rb', line 14 def initialize (*args) super @action = nil end |
Instance Method Details
#append_to_response(response) ⇒ Object
Appends #generate_html() output to response
45 46 47 |
# File 'lib/sws/Core/components/ImageButton/ImageButton.rb', line 45 def append_to_response ( response ) response << generate_html() end |
#generate_html ⇒ Object
Generates HTML output containing <INPUT type=“submit” tag
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sws/Core/components/ImageButton/ImageButton.rb', line 51 def generate_html () string = "<INPUT TYPE=\"image\" NAME=\"#{element_name()}\" VALUE=\"#{@slots["value"].value}\"#{generic_attr_string()}" if ( slot_bound?( "resource" ) ) framework = slot_bound?("framework") ? @slots["framework"].value : "app" src = app().adaptor.base_path() + app().resource_request_handler_key + "/" + framework + "/" + @slots["resource"].value elsif ( slot_bound?("src") ) src = @slots["src"].value() end string << " src=\"#{src}\"" ["alt", "title"].each do |attr| if ( slot_bound?(attr) ) string << " #{@slots[attr].to_tag_attribute}" end end string << ">" return string end |
#perform_action ⇒ Object
If the action has been set up (see #update_binding( key,value )) it is called now. Otherwise just nil is returned.
33 34 35 36 37 38 39 40 41 |
# File 'lib/sws/Core/components/ImageButton/ImageButton.rb', line 33 def perform_action () if ( @action ) return @action.call() else return nil end end |
#update_binding(key, value) ⇒ Object
Overriden method from Component class - sets the action to perform if the “value” parameter is not empty
21 22 23 24 25 26 27 28 |
# File 'lib/sws/Core/components/ImageButton/ImageButton.rb', line 21 def update_binding ( key, value ) #TODO: make these params accessible by user if ( key == "x" || key == "y" ) @action = @slots["action"].bound_object() end end |