Skip to content

Commit

Permalink
Created PM::TableScreen#set_up_accessibility, #editable? and moved ta…
Browse files Browse the repository at this point in the history
…bleView:commitEditingStyle:forRowAtIndexPath to a new PM::TableScreen::Editable module
  • Loading branch information
austinseraphin committed Apr 27, 2015
1 parent 1c39217 commit f88864f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions lib/ProMotion/table/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def screen_setup
set_up_refreshable
set_up_longpressable
set_up_row_height
set_up_accessibility
end

def check_table_data
Expand Down Expand Up @@ -89,6 +90,19 @@ def set_up_row_height
end
end

def editable?
self.promotion_table_data.sections.each do |section|
section[:cells].each do |cell|
return true if [:insert,:delete].include?(cell[:editing_style])
end
end
false
end

def set_up_accessibility
self.extend(Editable) if editable?
end

def searching?
self.promotion_table_data.filtered
end
Expand Down Expand Up @@ -235,11 +249,13 @@ def tableView(_, editingStyleForRowAtIndexPath: index_path)
map_cell_editing_style(data_cell[:editing_style])
end

module Editable
def tableView(_, commitEditingStyle: editing_style, forRowAtIndexPath: index_path)
if editing_style == UITableViewCellEditingStyleDelete
delete_row(index_path)
end
end
end

def tableView(_, canMoveRowAtIndexPath:index_path)
data_cell = self.promotion_table_data.cell(index_path: index_path, unfiltered: true)
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/tables/table_screen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class NoneditableTableScreen < PM::TableScreen
def on_load
end
def table_data
[{title: test,
[{title: "test",
cells: [{title: "Non-editable test"}]}]
end
end
Expand All @@ -77,7 +77,7 @@ def table_data
noneditable.editable?.should==false
index_path=NSIndexPath.indexPathForRow(0, inSection: 0)
lambda {noneditable.tableView(noneditable, commitEditingStyle: UITableViewCellEditingStyleDelete, forRowAtIndexPath: index_path)}.should.raise NoMethodError
@screen.editable?.must==true
@screen.editable?.should==true
@screen.should.respond_to(:"tableView:commitEditingStyle:forRowAtIndexPath")
end

Expand Down

0 comments on commit f88864f

Please sign in to comment.