Class: Wee::Examples::EditableCounter
- Defined in:
- lib/wee/examples/editable_counter.rb
Instance Attribute Summary
Attributes inherited from Counter
Instance Method Summary collapse
-
#initialize(initial_count = 0) ⇒ EditableCounter
constructor
A new instance of EditableCounter.
- #render_count ⇒ Object
- #submit ⇒ Object
Methods inherited from Counter
#backtrack_state, #dec, #inc, #render
Methods inherited from Component
#add_decoration, #backtrack_state, #backtrack_state_chain, #decoration, #decoration=, #do_render_chain, #each_decoration, #process_callbacks, #process_callbacks_chain, #remove_decoration, #remove_decoration_if, #render
Methods inherited from Presenter
#backtrack_state, #do_render, #get_property, #lookup_property, #process_callbacks, #properties, #properties=, #render, #session, template, uses_property
Constructor Details
#initialize(initial_count = 0) ⇒ EditableCounter
Returns a new instance of EditableCounter.
7 8 9 10 |
# File 'lib/wee/examples/editable_counter.rb', line 7 def initialize(initial_count=0) super @show_edit_field = false end |
Instance Method Details
#render_count ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/wee/examples/editable_counter.rb', line 12 def render_count if @show_edit_field r.text_input.callback(:count=).value(@count).size(6) r..callback(:submit).value('S') else r.anchor.callback(:submit).with(@count) end end |
#submit ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/wee/examples/editable_counter.rb', line 21 def submit if @count.to_s !~ /^\d+$/ call Wee::MessageBox.new("You entered an invalid counter! Please try again!") @count = 0 else @show_edit_field = !@show_edit_field end @count = @count.to_i end |