Class: BookController
- Inherits:
-
Formotion::FormController
- Object
- Formotion::FormController
- BookController
- Defined in:
- app/controllers/book_controller.rb
Instance Attribute Summary collapse
-
#_id ⇒ Object
Returns the value of attribute _id.
-
#meteor ⇒ Object
Returns the value of attribute meteor.
Instance Method Summary collapse
- #handle_remove(action, result) ⇒ Object
- #handle_update(action, result) ⇒ Object
- #remove ⇒ Object
- #update_form(action, id) ⇒ Object
- #viewDidLoad ⇒ Object
- #viewWillAppear(animated) ⇒ Object
- #viewWillDisappear(animated) ⇒ Object
Instance Attribute Details
#_id ⇒ Object
Returns the value of attribute _id.
2 3 4 |
# File 'app/controllers/book_controller.rb', line 2 def _id @_id end |
#meteor ⇒ Object
Returns the value of attribute meteor.
2 3 4 |
# File 'app/controllers/book_controller.rb', line 2 def meteor @meteor end |
Instance Method Details
#handle_remove(action, result) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/book_controller.rb', line 73 def handle_remove action, result if action == :error alert = UIAlertView.new alert. = "Error: #{result['reason'].to_s}" alert.addButtonWithTitle "OK" alert.show elsif action == :result alert = UIAlertView.new alert. = "Book removed sucessfully" alert.addButtonWithTitle "OK" alert.show end end |
#handle_update(action, result) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/book_controller.rb', line 52 def handle_update action, result if action == :error alert = UIAlertView.new alert. = "Error: #{result['reason'].to_s}" alert.addButtonWithTitle "OK" alert.show elsif action == :result alert = UIAlertView.new if @_id != nil alert. = "Book updated sucessfully" alert.addButtonWithTitle "OK" alert.show else alert. = "Book added sucessfully" alert.addButtonWithTitle "OK" alert.show self..popViewControllerAnimated(true) end end end |
#remove ⇒ Object
88 89 90 |
# File 'app/controllers/book_controller.rb', line 88 def remove @meteor.call('/books/remove', self.method(:handle_remove), [{_id: @_id}]) end |
#update_form(action, id) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/book_controller.rb', line 39 def update_form action, id if id == @_id if action == :removed self..popViewControllerAnimated(true) elsif action == :changed book = @books.find(id) self.form.row(:title).value = book['title'] self.form.row(:author).value = book['author'] self.form.row(:year).value = book['year'] end end end |
#viewDidLoad ⇒ Object
4 5 6 7 |
# File 'app/controllers/book_controller.rb', line 4 def viewDidLoad super self.title = "Details" end |
#viewWillAppear(animated) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/book_controller.rb', line 9 def viewWillAppear animated super @books = @meteor.collections['books'] @books.add_observer( self.method(:update_form) ) self.form.on_submit do |form| data = form.render self.view.endEditing(true) if @_id != nil @meteor.call('/books/update', self.method(:handle_update), [{_id: @_id},{title: data[:title], author: data[:author],year: data[:year]}]) else new_id = SecureRandom.hex @meteor.call('/books/insert', self.method(:handle_update), [{_id: new_id,title: data[:title], author: data[:author],year: data[:year]}]) end end if @_id != nil = UIBarButtonItem.alloc.initWithTitle("Remove", style: UIBarButtonItemStyleDone, target:self, action:'remove') self..rightBarButtonItem = end end |
#viewWillDisappear(animated) ⇒ Object
33 34 35 36 |
# File 'app/controllers/book_controller.rb', line 33 def viewWillDisappear animated super @books.remove_observer( self.method(:update_form) ) end |