Module: ProMotion::MotionTable::SearchableTable

Included in:
PlainTable, TableScreenModule
Defined in:
lib/ProMotion/screen_helpers/_tables/_searchable_table.rb

Instance Method Summary collapse

Instance Method Details

#make_searchable(params = {}) ⇒ Object Also known as: makeSearchable



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ProMotion/screen_helpers/_tables/_searchable_table.rb', line 3

def make_searchable(params={})
  params[:content_controller] ||= params[:contentController]
  params[:data_source] ||= params[:searchResultsDataSource]
  params[:search_results_delegate] ||= params[:searchResultsDelegate]

  params[:frame] ||= CGRectMake(0, 0, 320, 44) # TODO: Don't hardcode this...
  params[:content_controller] ||= self
  params[:delegate] ||= self
  params[:data_source] ||= self
  params[:search_results_delegate] ||= self

  search_bar = UISearchBar.alloc.initWithFrame(params[:frame])
  search_bar.autoresizingMask = UIViewAutoresizingFlexibleWidth

  if params[:search_bar] && params[:search_bar][:placeholder]
    search_bar.placeholder = params[:search_bar][:placeholder]
  end

  @contacts_search_display_controller = UISearchDisplayController.alloc.initWithSearchBar(search_bar, contentsController: params[:content_controller])
  @contacts_search_display_controller.delegate = params[:delegate]
  @contacts_search_display_controller.searchResultsDataSource = params[:data_source]
  @contacts_search_display_controller.searchResultsDelegate = params[:search_results_delegate]

  self.table_view.tableHeaderView = search_bar
end

#searchDisplayController(controller, shouldReloadTableForSearchString: search_string) ⇒ Object

iOS methods, headless camel case #######



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ProMotion/screen_helpers/_tables/_searchable_table.rb', line 32

def searchDisplayController(controller, shouldReloadTableForSearchString:search_string)
  @mt_filtered_data = nil
  @mt_filtered_data = []

  @mt_table_view_groups.each do |section|
    new_section = {}
    new_section[:cells] = []

    section[:cells].each do |cell|
      if cell[:title].to_s.downcase.strip.include?(search_string.downcase.strip)
        new_section[:cells] << cell
      end
    end

    if new_section[:cells] && new_section[:cells].length > 0
      new_section[:title] = section[:title]
      @mt_filtered_data << new_section
    end
  end
  true
end

#searchDisplayControllerWillBeginSearch(controller) ⇒ Object



60
61
62
63
64
# File 'lib/ProMotion/screen_helpers/_tables/_searchable_table.rb', line 60

def searchDisplayControllerWillBeginSearch(controller)
  @mt_filtered = true
  @mt_filtered_data = []
  self.table_view.setScrollEnabled false
end

#searchDisplayControllerWillEndSearch(controller) ⇒ Object



54
55
56
57
58
# File 'lib/ProMotion/screen_helpers/_tables/_searchable_table.rb', line 54

def searchDisplayControllerWillEndSearch(controller)
  @mt_filtered = false
  @mt_filtered_data = nil
  self.table_view.setScrollEnabled true
end