Class: Nemo::Components::MultipleAttributeContainer
- Inherits:
-
Wee::Component
- Object
- Wee::Component
- Nemo::Components::MultipleAttributeContainer
- Defined in:
- lib/nemo/components/multiattr.rb
Overview
Multiple Attribute container
Interface to Add/Edit/Delete/View the related data of the given attribute.
Instance Attribute Summary collapse
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#components ⇒ Object
Returns the value of attribute components.
Instance Method Summary collapse
- #backtrack_state(snapshot) ⇒ Object
- #children ⇒ Object
- #create_empty_editor ⇒ Object
- #delete(component) ⇒ Object
- #editor_for(metaobject) ⇒ Object
-
#initialize(a) ⇒ MultipleAttributeContainer
constructor
A new instance of MultipleAttributeContainer.
- #on_edit(obj) ⇒ Object
- #render ⇒ Object
- #switch_to_edit_mode(viewer) ⇒ Object
- #viewer_for(metaobject) ⇒ Object
Constructor Details
#initialize(a) ⇒ MultipleAttributeContainer
Returns a new instance of MultipleAttributeContainer.
9 10 11 12 13 14 15 |
# File 'lib/nemo/components/multiattr.rb', line 9 def initialize(a) super() @attribute = a @components = Array.new a.cache.each { |obj| @components << viewer_for(obj.) } @components << create_empty_editor end |
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
7 8 9 |
# File 'lib/nemo/components/multiattr.rb', line 7 def attribute @attribute end |
#components ⇒ Object
Returns the value of attribute components.
7 8 9 |
# File 'lib/nemo/components/multiattr.rb', line 7 def components @components end |
Instance Method Details
#backtrack_state(snapshot) ⇒ Object
21 22 23 24 |
# File 'lib/nemo/components/multiattr.rb', line 21 def backtrack_state(snapshot) super snapshot.add(self.children) end |
#children ⇒ Object
17 18 19 |
# File 'lib/nemo/components/multiattr.rb', line 17 def children @components end |
#create_empty_editor ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nemo/components/multiattr.rb', line 39 def create_empty_editor = @attribute.base_class.new. if @components.size < @attribute.item_limit editor = editor_for() answer = Wee::AnswerDecoration.new answer.on_answer = method(:on_edit) editor.add_decoration(answer) editor else Nemo::Visitors::Visitor.new() # placeholder end end |
#delete(component) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/nemo/components/multiattr.rb', line 26 def delete(component) @attribute.remove_from_cache(component..baseobject) @components.delete(component) @components.pop @components << create_empty_editor end |
#editor_for(metaobject) ⇒ Object
64 65 66 67 68 |
# File 'lib/nemo/components/multiattr.rb', line 64 def editor_for() obj = Nemo::Visitors::Editor.new() obj.subform = true obj end |
#on_edit(obj) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/nemo/components/multiattr.rb', line 52 def on_edit(obj) if obj.nil? @components.pop @components << create_empty_editor else @attribute.add_to_cache(obj) @components.pop @components << viewer_for(obj.) @components << create_empty_editor end end |
#render ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/nemo/components/multiattr.rb', line 74 def render @components.each do |component| if component.viewer? r.render(component) r..value('edit').callback{ switch_to_edit_mode(component) } if @attribute.item_delete? r.space r..value('delete').callback { delete(component) } end if @attribute.item_limit > 1 r.break r.break end else r.render(component) end end end |
#switch_to_edit_mode(viewer) ⇒ Object
33 34 35 36 37 |
# File 'lib/nemo/components/multiattr.rb', line 33 def switch_to_edit_mode(viewer) viewer.viewer = false viewer.call( editor_for(viewer.) ) viewer.viewer = true end |