Class: BookListController
- Inherits:
-
UIViewController
- Object
- UIViewController
- BookListController
- Defined in:
- app/controllers/book_list_controller.rb
Instance Attribute Summary collapse
-
#meteor ⇒ Object
Returns the value of attribute meteor.
Instance Method Summary collapse
- #add_book ⇒ Object
- #build_book_form(book) ⇒ Object
- #tableView(tableView, didSelectRowAtIndexPath: indexPath) ⇒ Object
- #viewDidLoad ⇒ Object
Instance Attribute Details
#meteor ⇒ Object
Returns the value of attribute meteor.
2 3 4 |
# File 'app/controllers/book_list_controller.rb', line 2 def meteor @meteor end |
Instance Method Details
#add_book ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/book_list_controller.rb', line 22 def add_book book = {} form = build_book_form( book ) bookController = BookController.alloc.initWithForm(form) bookController.meteor = @meteor bookController._id = nil self..pushViewController(bookController, animated: true) end |
#build_book_form(book) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/book_list_controller.rb', line 66 def build_book_form book form = Formotion::Form.new form.build_section do |section| section.title = "Book Details" section.build_row do |row| row.title = "Title" row.key = :title row.type = :string row.placeholder = 'Book title' row.value = book['title'] end section.build_row do |row| row.title = "Author" row.key = :author row.type = :string row.placeholder = 'Book author' row.value = book['author'] end section.build_row do |row| row.title = "Year" row.key = :year row.type = :string row.placeholder = 'Book year' row.value = book['year'] end section.build_row do |row| row.title = 'Save Changes' row.type = :submit end end return form end |
#tableView(tableView, didSelectRowAtIndexPath: indexPath) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/book_list_controller.rb', line 34 def tableView(tableView, cellForRowAtIndexPath: indexPath) @reuseIdentifier ||= "CELL_IDENTIFIER" cell = tableView.dequeueReusableCellWithIdentifier(@reuseIdentifier) || begin UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:@reuseIdentifier) end cell.textLabel.text = @books.all[indexPath.row]['title'] cell end |
#viewDidLoad ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/book_list_controller.rb', line 4 def viewDidLoad super self.view.backgroundColor = UIColor.whiteColor self.title = "Books" @table = UITableView.alloc.initWithFrame(self.view.bounds) self.view.addSubview @table @table.dataSource = self @table.delegate = self @books = @meteor.collections['books'] @books.add_observer(@table.method(:reloadData)) = UIBarButtonItem.alloc.initWithTitle("Add Book", style: UIBarButtonItemStyleDone, target:self, action:'add_book') self..rightBarButtonItem = end |