Class: Inputs::EffectivePanelSelect::Input
Instance Method Summary
collapse
#field_name, #html_options, #initialize, #js_options, #options, #value
Instance Method Details
#_initialize_group_and_option ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 71
def _initialize_group_and_option
collection.each do |group, items|
items.each do |item|
if item.send(options[:option_key_method]) == value
@group_label = group.send(options[:group_label_method])
@group_value = group.send(options[:group_method])
@option_label = item.send(options[:option_value_method])
return
end
end
end
end
|
#ajax? ⇒ Boolean
32
33
34
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 32
def ajax?
return true if js_options[:ajax]
end
|
#collection ⇒ Object
This is a grouped polymorphic collection
- [‘Active’, [[‘Post A’, 1], [‘Post B’, 2]]], [‘Past’, [[‘Post C’, 3], [‘Post D’, 4]]
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 86
def collection
@collection ||= begin
collection = options.delete(:collection) || []
grouped = collection[0].kind_of?(Array) && collection[0][1].respond_to?(:to_a) && (collection[0][1] != nil)
if !grouped && collection.present?
raise "Grouped collection expecting a Hash {'Posts' => Post.all, 'Events' => Event.all} or a Hash {'Posts' => [['Post A', 1], ['Post B', 2]], 'Events' => [['Event A', 1], ['Event B', 2]]}"
end
collection.each_with_index do |(name, group), index|
collection[index][1] = group.respond_to?(:call) ? group.call : group.to_a
end
if collection[0][0].kind_of?(String)
options[:group_label_method] = :to_s
options[:group_method] = :to_s
end
collection.respond_to?(:call) ? collection.call : collection.to_a
end
end
|
20
21
22
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 20
def default_input_html
{ class: 'effective_panel_select' }
end
|
16
17
18
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 16
def default_input_js
{ placeholder: 'Please choose', invade: '.row', collapseOnSelect: true, resetOnCollapse: true, showCount: false, showSearch: true }
end
|
#default_options ⇒ Object
12
13
14
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 12
def default_options
{ label_method: :to_s, value_method: :to_s, group_label_method: :first, group_method: :second, option_value_method: :first, option_key_method: :second, sidebar_class: 'nav-stacked' }
end
|
#group_label ⇒ Object
60
61
62
63
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 60
def group_label
return nil unless value.present?
@group_label || (_initialize_group_and_option; @group_label)
end
|
#group_value ⇒ Object
66
67
68
69
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 66
def group_value
return nil unless value.present?
@group_value || (_initialize_group_and_option; @group_value)
end
|
#method_name ⇒ Object
28
29
30
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 28
def method_name
@method_name ||= @method.to_s.titleize.downcase
end
|
#option_label ⇒ Object
54
55
56
57
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 54
def option_label
return nil unless value.present?
@option_label || (_initialize_group_and_option; @option_label)
end
|
#option_value ⇒ Object
49
50
51
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 49
def option_value
value
end
|
#show_count? ⇒ Boolean
36
37
38
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 36
def show_count?
return true if js_options[:showCount]
end
|
#show_search? ⇒ Boolean
40
41
42
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 40
def show_search?
return true if js_options[:showSearch]
end
|
#to_html ⇒ Object
24
25
26
|
# File 'app/models/inputs/effective_panel_select/input.rb', line 24
def to_html
render('effective/effective_panel_select/input', input: self)
end
|