-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathnested_level_input.rb
More file actions
52 lines (43 loc) · 1.64 KB
/
Copy pathnested_level_input.rb
File metadata and controls
52 lines (43 loc) · 1.64 KB
1
2
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class NestedLevelInput < ActiveAdminAddons::InputBase
include ActiveAdminAddons::SelectHelpers
def render_custom_input
concat(label_html)
select_control = builder.select(
method, initial_collection_to_select_options, {}, input_html_options
)
concat(select_control)
end
private
def load_control_attributes
load_class(@options[:class])
load_data_attr(:fields, default: ["name"], formatter: :to_json)
load_data_attr(:predicate, default: "cont")
load_data_attr(:filters)
load_data_attr(:model, value: model_name)
load_data_attr(:display_name, default: "name")
load_data_attr(:minimum_input_length, default: 1)
load_data_attr(:url, default: url_from_method)
load_data_attr(:response_root, default: tableize_method)
load_data_attr(:width, default: "80%")
load_data_attr(:primary_key, default: "id")
load_data_attr(:order,
value: @options[:order_by],
default: get_data_attr_value(:fields).first.to_s + "_desc")
load_parent_data_options
load_collection_data
end
def load_parent_data_options
return unless @options[:parent_attribute]
load_data_attr(:parent, value: @options[:parent_attribute])
load_data_attr(:parent_id, value: @object.send(@options[:parent_attribute]), default: -1)
end
def load_collection_data
return unless @options[:collection]
collection_options = collection_to_select_options do |item, option|
if !!@options[:parent_attribute]
option[@options[:parent_attribute]] = item.send(@options[:parent_attribute])
end
end
load_data_attr(:collection, value: collection_options, formatter: :to_json)
end
end