Class: Locomotive::DocumentPickerInput
Instance Method Summary
collapse
#translate_from_namespace
#col_wrapping, #row_wrapping
Instance Method Details
#document_label(label_method) ⇒ Object
45
46
47
|
# File 'app/inputs/locomotive/document_picker_input.rb', line 45
def document_label(label_method)
selected_document.try(label_method.to_sym)
end
|
38
39
40
41
42
43
|
# File 'app/inputs/locomotive/document_picker_input.rb', line 38
def
options[:picker].tap do |data|
data[:per_page] ||= Locomotive.config.ui[:per_page]
data[:label] = document_label(data[:label_method])
end
end
|
7
8
9
10
11
12
13
14
15
16
17
|
# File 'app/inputs/locomotive/document_picker_input.rb', line 7
def input(wrapper_options)
data =
row_wrapping do
(col_wrapping('field col-xs-9', 11) do
select_field(data)
end) + (col_wrapping('button col-xs-3 text-right', 1) do
link_to_edit
end)
end
end
|
#link_to_edit ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'app/inputs/locomotive/document_picker_input.rb', line 27
def link_to_edit
label = options[:edit][:label]
css_class = 'btn btn-primary btn-sm edit'
if url = options[:edit][:url]
template.content_tag(:a, label, href: url, class: css_class)
else
''
end
end
|
#select_field(data) ⇒ Object
19
20
21
22
23
24
25
|
# File 'app/inputs/locomotive/document_picker_input.rb', line 19
def select_field(data)
@builder.collection_select(
:"#{attribute_name}_id", [selected_document].compact,
:_id, data[:label_method],
{ include_blank: true }, { class: 'form-control', data: data }
)
end
|
#selected_document ⇒ Object
49
50
51
52
53
54
|
# File 'app/inputs/locomotive/document_picker_input.rb', line 49
def selected_document
return @selected_document if @selected_document_done
@selected_document_done = true
@selected_document = self.object.send(attribute_name.to_sym)
end
|