Class: Nemo::Examples::PersonEditor::Root
- Inherits:
-
Wee::Component
- Object
- Wee::Component
- Nemo::Examples::PersonEditor::Root
- Defined in:
- lib/nemo/examples/person_editor.rb
Overview
Display a list of persons for editing or deletion
Instance Attribute Summary collapse
-
#views ⇒ Object
Returns the value of attribute views.
Instance Method Summary collapse
-
#add_new ⇒ Object
Add a new Person.
-
#backtrack_state(snapshot) ⇒ Object
Enable Wee backtracking for views.
-
#delete(obj) ⇒ Object
Delete a Person.
-
#edit(obj) ⇒ Object
Edit a Person.
-
#initialize ⇒ Root
constructor
Create a ListItemViewer for each record.
-
#render ⇒ Object
Render the page.
-
#viewer_for(obj) ⇒ Object
Create a new ListItemViewer for a given metaobject.
Constructor Details
#initialize ⇒ Root
Create a ListItemViewer for each record
123 124 125 126 127 |
# File 'lib/nemo/examples/person_editor.rb', line 123 def initialize super @views = Wee::Session.current.domainmodel.persons.collect { |p| viewer_for(p) } @views.each { |view| @children << view } end |
Instance Attribute Details
#views ⇒ Object
Returns the value of attribute views.
119 120 121 |
# File 'lib/nemo/examples/person_editor.rb', line 119 def views @views end |
Instance Method Details
#add_new ⇒ Object
Add a new Person
176 177 178 179 180 181 |
# File 'lib/nemo/examples/person_editor.rb', line 176 def add_new if obj = call( Nemo::Examples::PersonEditor::Editor.new(Nemo::Examples::PersonEditor::Person.new.) ) session.domainmodel.add_person(obj) @views << viewer_for(obj) end end |
#backtrack_state(snapshot) ⇒ Object
Enable Wee backtracking for views
131 132 133 134 |
# File 'lib/nemo/examples/person_editor.rb', line 131 def backtrack_state(snapshot) super snapshot.add(self.children) end |
#delete(obj) ⇒ Object
Delete a Person. Requires confirmation: Are you sure you want to delete? [OK] [Cancel]
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/nemo/examples/person_editor.rb', line 192 def delete(obj) if call( Nemo::Components::ConfirmDialog.new("Are you sure you want to delete #{obj.name}?") ) session.domainmodel.remove_person(obj) session.domainmodel.persons.each do |person| person.father = nil if person.father == obj person.mother = nil if person.mother == obj end @views.delete_if { |view| view..baseobject == obj } end end |
#edit(obj) ⇒ Object
Edit a Person
185 186 187 |
# File 'lib/nemo/examples/person_editor.rb', line 185 def edit(obj) call( Nemo::Examples::PersonEditor::Editor.new(obj.) ) # will auto-commit end |
#render ⇒ Object
Render the page
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/nemo/examples/person_editor.rb', line 144 def render r.html do r.head { r.title('Person Editor') } r.link.type('text/css').rel('stylesheet').href('/nemo/person_editor.css') r.body do r.h1('Person Editor') r.table.width('100%').with do if @views.empty? r.table_row { r.table_header('No persons found.') } else labels = @views.first..visible_attributes.collect { |a| a.label } r.table_row { labels.each { |label| r.table_header(label) }; r.table_header { r.space } } @views.each do |view| r.table_row do r.render(view) r.table_header do r.anchor.callback{ edit(view..baseobject) }.with('edit') r.space; r.text('|'); r.space r.anchor.callback{ delete(view..baseobject) }.with('delete') end end end end end r.break r.anchor.callback{ add_new }.with('create new person') end end end |
#viewer_for(obj) ⇒ Object
Create a new ListItemViewer for a given metaobject
138 139 140 |
# File 'lib/nemo/examples/person_editor.rb', line 138 def viewer_for(obj) Nemo::Examples::PersonEditor::ListItemViewer.new(obj..hide!(:password, :interests)) end |