Class: Tgios::SearchController
Constant Summary
collapse
- Events =
[:record_selected, :search, :after_layout, :load_more]
Instance Attribute Summary collapse
Instance Method Summary
collapse
#add_full_table_view_to, #add_title_to_table_header, #add_title_to_view
#dealloc, #dismissViewControllerAnimated, #hook, #prepareForRelease, #unhook, #viewDidDisappear
Instance Attribute Details
#field_name ⇒ Object
Returns the value of attribute field_name.
5
6
7
|
# File 'lib/tgios/search_controller.rb', line 5
def field_name
@field_name
end
|
#hide_keyboard ⇒ Object
Returns the value of attribute hide_keyboard.
5
6
7
|
# File 'lib/tgios/search_controller.rb', line 5
def hide_keyboard
@hide_keyboard
end
|
#instant_search ⇒ Object
Returns the value of attribute instant_search.
5
6
7
|
# File 'lib/tgios/search_controller.rb', line 5
def instant_search
@instant_search
end
|
#pop_after_selected ⇒ Object
Returns the value of attribute pop_after_selected.
5
6
7
|
# File 'lib/tgios/search_controller.rb', line 5
def pop_after_selected
@pop_after_selected
end
|
#table_list_binding_options ⇒ Object
Returns the value of attribute table_list_binding_options.
5
6
7
|
# File 'lib/tgios/search_controller.rb', line 5
def table_list_binding_options
@table_list_binding_options
end
|
Instance Method Details
#call_search(text, select_one = false) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/tgios/search_controller.rb', line 52
def call_search(text, select_one=false)
unless @events.nil? || @events[:search].nil?
@events[:search].call(text) do |success, result|
if success
@result=result
if @result.count == 1 && select_one
select_record(@result.first)
else
@search_result_table_binding.reload(@result) unless @search_result_table_binding.nil?
end
end
end
end
end
|
#init ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/tgios/search_controller.rb', line 77
def init
super
@events={}
@result=[]
@pop_after_selected=true
self
end
|
#on(event_name, &block) ⇒ Object
7
8
9
10
11
|
# File 'lib/tgios/search_controller.rb', line 7
def on(event_name, &block)
raise ArgumentError.new("Event not found, valid events are: [#{Events.join(', ')}]") unless Events.include?(event_name)
@events[event_name]=block.weak!
self
end
|
#onPrepareForRelease ⇒ Object
85
86
87
88
89
90
|
# File 'lib/tgios/search_controller.rb', line 85
def onPrepareForRelease
@events=nil
@search_result_table_binding.prepareForRelease
@search_result_table_binding=nil
self.navigationItem.rightBarButtonItem = nil
end
|
#result=(value) ⇒ Object
13
14
15
16
|
# File 'lib/tgios/search_controller.rb', line 13
def result=(value)
@result=value
@search_result_table_binding.reload(@result) unless @search_result_table_binding.nil?
end
|
#searchBar(searchBar, textDidChange: searchText) ⇒ Object
48
49
50
|
# File 'lib/tgios/search_controller.rb', line 48
def searchBar(searchBar, textDidChange: searchText)
call_search(searchText) if @instant_search
end
|
43
44
45
46
|
# File 'lib/tgios/search_controller.rb', line 43
def searchBarSearchButtonClicked(searchBar)
searchBar.resignFirstResponder
call_search(searchBar.text, true)
end
|
#select_record(record) ⇒ Object
18
19
20
21
|
# File 'lib/tgios/search_controller.rb', line 18
def select_record(record)
@events[:record_selected].call(record)
self.navigationController.popViewControllerAnimated(true) if @pop_after_selected
end
|
#viewDidLoad ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/tgios/search_controller.rb', line 23
def viewDidLoad
super
@search_result_table = add_full_table_view_to(self.view, :plain)
@search_result_table_binding=UITableViewListBinding.new.bind(@search_result_table, @result, @field_name, @table_list_binding_options)
@search_result_table_binding.on(:touch_row) do |record, event|
select_record(record)
end.on(:load_more) do |page, index_path, &block|
@events[:load_more].call(@search_bar.text, page, index_path, &block) unless @events[:load_more].nil?
end
@search_bar=UISearchBar.alloc.init
@search_bar.frame=[[0,0],['100',0]]
@search_bar.sizeToFit
@search_bar.delegate=self
@search_result_table.=@search_bar
@search_bar.performSelector('becomeFirstResponder', withObject: nil, afterDelay: 0.0) unless @hide_keyboard
@events[:after_layout].call(@search_bar, @search_result_table) unless @events[:after_layout].nil?
end
|
#viewWillAppear(animated) ⇒ Object
67
68
69
70
|
# File 'lib/tgios/search_controller.rb', line 67
def viewWillAppear(animated)
super
@search_result_table_binding.listen_to_keyboard
end
|
#viewWillDisappear(animated) ⇒ Object
72
73
74
75
|
# File 'lib/tgios/search_controller.rb', line 72
def viewWillDisappear(animated)
@search_result_table_binding.stop_listen_to_keyboard
super
end
|