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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/helpers/carload/dashboard_helper.rb', line 3
def generate_input form, model_name, attribute_name, options = {}
if options[:polymorphic]
form.input attribute_name,
collection: @model_class.send(attribute_name.to_s.pluralize),
selected: options[:value],
input_html: { class: 'use-select2' }
elsif attribute_name =~ /_id$/
class_name, association_name = associated_model_name model_name, attribute_name
association = Dashboard.model(model_name).associations[association_name]
label_attribute = association[:choose_by]
form.association association_name,
label_method: label_attribute,
label: t("activerecord.models.#{class_name}"),
input_html: {
class: 'use-select2',
data: {
placeholder: t('carload.placeholder.select', thing: t("activerecord.attributes.#{class_name}.#{label_attribute}"))
}
}
elsif attribute_name =~ /_ids$/
class_name, association_name = associated_model_name model_name, attribute_name
association = Dashboard.model(model_name).associations[association_name]
label_attribute = association[:choose_by]
form.input attribute_name,
label: t("activerecord.attributes.#{class_name}.#{label_attribute}") + " (#{t("activerecord.models.#{class_name}")})",
collection: class_name.to_s.camelize.constantize.all,
label_method: label_attribute,
value_method: :id,
input_html: {
class: 'use-select2',
multiple: true,
data: {
placeholder: t('carload.placeholder.select', thing: t("activerecord.attributes.#{class_name}.#{label_attribute}"))
}
}
elsif needs_upload?(model_name, attribute_name) and image?(attribute_name)
upload_image form: form, image_name: attribute_name, width: 150, height: 150
elsif options[:type] == :text
form.input(attribute_name, label: raw(" <span class=\"control-label string optional\">\#{t(\"activerecord.attributes.\#{@model_name}.\#{attribute_name}\")}</span>\n <a id='preview-\#{attribute_name}-button' class='btn btn-xs' data-toggle='on'>\#{t('carload.action.preview')} (Markdown)</a>\n EOT\n )) + raw(<<-EOT\n <script>\n $('.\#{@model_name}_\#{attribute_name}').append(\"<div id='preview-\#{attribute_name}-content' class='markdown-preview'></div>\")\n $('#preview-\#{attribute_name}-button').click(function() {\n if ($(this).data('toggle') == 'on') {\n var md = new Remarkable()\n var marked_content = md.render($('#\#{@model_name}_\#{attribute_name}').val())\n $('#\#{@model_name}_\#{attribute_name}').hide()\n $('#preview-\#{attribute_name}-content').html(marked_content)\n $('#preview-\#{attribute_name}-content').show()\n $(this).data('toggle', 'off')\n $(this).html('\#{t('carload.action.edit')} (Markdown)')\n } else if ($(this).data('toggle') == 'off') {\n $('#\#{@model_name}_\#{attribute_name}').show()\n $('#preview-\#{attribute_name}-content').hide()\n $(this).data('toggle', 'on')\n $(this).html('\#{t('carload.action.preview')} (Markdown)')\n }\n })\n </script>\n EOT\n )\n else\n form.input attribute_name\n end\nend\n"
|