headmin 0.3.3 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +27 -0
- data/.gitignore +14 -0
- data/.nvmrc +1 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +171 -3
- data/README.md +9 -1
- data/Rakefile +1 -7
- data/app/assets/javascripts/headmin/config/i18n.js +9 -9
- data/app/assets/javascripts/headmin/controllers/autocomplete_controller.js +318 -0
- data/app/assets/javascripts/headmin/controllers/blocks_controller.js +74 -79
- data/app/assets/javascripts/headmin/controllers/date_range_controller.js +24 -24
- data/app/assets/javascripts/headmin/controllers/dropzone_controller.js +23 -25
- data/app/assets/javascripts/headmin/controllers/file_preview_controller.js +237 -237
- data/app/assets/javascripts/headmin/controllers/filter_controller.js +44 -44
- data/app/assets/javascripts/headmin/controllers/filters_controller.js +57 -61
- data/app/assets/javascripts/headmin/controllers/flatpickr_controller.js +29 -29
- data/app/assets/javascripts/headmin/controllers/hello_controller.js +3 -3
- data/app/assets/javascripts/headmin/controllers/notification_controller.js +7 -6
- data/app/assets/javascripts/headmin/controllers/popup_controller.js +57 -51
- data/app/assets/javascripts/headmin/controllers/redactorx_controller.js +36 -9
- data/app/assets/javascripts/headmin/controllers/repeater_controller.js +122 -125
- data/app/assets/javascripts/headmin/controllers/select_controller.js +40 -39
- data/app/assets/javascripts/headmin/controllers/table_actions_controller.js +88 -77
- data/app/assets/javascripts/headmin/controllers/table_controller.js +115 -116
- data/app/assets/javascripts/headmin/index.js +38 -35
- data/app/assets/javascripts/headmin.js +309 -42
- data/app/assets/stylesheets/headmin/forms/autocomplete.scss +21 -0
- data/app/assets/stylesheets/headmin/forms/file.scss +46 -0
- data/app/assets/stylesheets/headmin/forms/repeater.scss +62 -0
- data/app/assets/stylesheets/headmin/forms/search.scss +12 -0
- data/app/assets/stylesheets/headmin/forms.scss +11 -0
- data/app/assets/stylesheets/headmin/general.scss +14 -0
- data/app/assets/stylesheets/headmin/overrides/bootstrap.scss +5 -3
- data/app/assets/stylesheets/headmin/overrides/redactorx.scss +74 -0
- data/app/assets/stylesheets/headmin/popup.scss +1 -0
- data/app/assets/stylesheets/headmin/syntax.scss +36 -349
- data/app/assets/stylesheets/headmin/table.scss +1 -1
- data/app/assets/stylesheets/headmin/utilities/buttons.scss +19 -0
- data/app/assets/stylesheets/headmin/utilities/dropzone.scss +72 -0
- data/app/assets/stylesheets/headmin/utilities.scss +2 -68
- data/app/assets/stylesheets/headmin.css +209 -205
- data/app/assets/stylesheets/headmin.scss +1 -1
- data/app/helpers/headmin/admin_helper.rb +0 -1
- data/app/helpers/headmin/form_helper.rb +2 -8
- data/app/models/concerns/headmin/blockable.rb +1 -1
- data/app/models/concerns/headmin/field.rb +1 -0
- data/app/models/concerns/headmin/form/autocompletable.rb +38 -0
- data/app/models/concerns/headmin/form/hintable.rb +19 -0
- data/app/models/concerns/headmin/form/input_groupable.rb +23 -0
- data/app/models/concerns/headmin/form/labelable.rb +33 -0
- data/app/models/concerns/headmin/form/listable.rb +28 -0
- data/app/models/concerns/headmin/form/placeholderable.rb +13 -0
- data/app/models/concerns/headmin/form/validatable.rb +40 -0
- data/app/models/concerns/headmin/form/wrappable.rb +21 -0
- data/app/models/headmin/.DS_Store +0 -0
- data/app/models/headmin/blocks_view.rb +15 -0
- data/app/models/headmin/form/blocks_view.rb +29 -0
- data/app/models/headmin/form/checkbox_view.rb +52 -0
- data/app/models/headmin/form/date_range_view.rb +25 -0
- data/app/models/headmin/form/date_view.rb +45 -0
- data/app/models/headmin/form/email_view.rb +48 -0
- data/app/models/headmin/form/file_view.rb +116 -0
- data/app/models/headmin/form/flatpickr_range_view.rb +102 -0
- data/app/models/headmin/form/flatpickr_view.rb +37 -0
- data/app/models/headmin/form/hidden_view.rb +10 -0
- data/app/models/headmin/form/hint_view.rb +6 -0
- data/app/models/headmin/form/input_group_view.rb +19 -0
- data/app/models/headmin/form/label_view.rb +24 -0
- data/app/models/headmin/form/number_view.rb +49 -0
- data/app/models/headmin/form/password_view.rb +44 -0
- data/app/models/headmin/form/redactorx_view.rb +59 -0
- data/app/models/headmin/form/search_view.rb +48 -0
- data/app/models/headmin/form/select_view.rb +62 -0
- data/app/models/headmin/form/switch_view.rb +23 -0
- data/app/models/headmin/form/text_view.rb +48 -0
- data/app/models/headmin/form/textarea_view.rb +44 -0
- data/app/models/headmin/form/url_view.rb +48 -0
- data/app/models/headmin/form/wrapper_view.rb +19 -0
- data/app/models/headmin/form/wysiwyg_view.rb +17 -0
- data/app/models/headmin/{thumbnail.rb → thumbnail_view.rb} +6 -1
- data/app/models/view_model.rb +58 -0
- data/app/views/headmin/_blocks.html.erb +13 -9
- data/app/views/headmin/_heading.html.erb +7 -1
- data/app/views/headmin/_thumbnail.html.erb +1 -37
- data/app/views/headmin/forms/_autocomplete.html.erb +11 -0
- data/app/views/headmin/forms/_blocks.html.erb +16 -17
- data/app/views/headmin/forms/_checkbox.html.erb +24 -29
- data/app/views/headmin/forms/_datalist.html.erb +3 -0
- data/app/views/headmin/forms/_date.html.erb +24 -24
- data/app/views/headmin/forms/_date_range.html.erb +19 -21
- data/app/views/headmin/forms/_email.html.erb +27 -32
- data/app/views/headmin/forms/_errors.html.erb +2 -3
- data/app/views/headmin/forms/_file.html.erb +84 -181
- data/app/views/headmin/forms/_flatpickr.html.erb +19 -20
- data/app/views/headmin/forms/_flatpickr_range.html.erb +28 -37
- data/app/views/headmin/forms/_hidden.html.erb +9 -10
- data/app/views/headmin/forms/_hint.html.erb +16 -0
- data/app/views/headmin/forms/_input_group.html.erb +21 -0
- data/app/views/headmin/forms/_label.html.erb +5 -13
- data/app/views/headmin/forms/_number.html.erb +23 -35
- data/app/views/headmin/forms/_password.html.erb +21 -30
- data/app/views/headmin/forms/_redactorx.html.erb +21 -40
- data/app/views/headmin/forms/_repeater.html.erb +55 -60
- data/app/views/headmin/forms/_search.html.erb +43 -0
- data/app/views/headmin/forms/_select.html.erb +24 -49
- data/app/views/headmin/forms/_switch.html.erb +29 -0
- data/app/views/headmin/forms/_text.html.erb +42 -96
- data/app/views/headmin/forms/_textarea.html.erb +21 -32
- data/app/views/headmin/forms/_url.html.erb +26 -31
- data/app/views/headmin/forms/_validation.html.erb +10 -13
- data/app/views/headmin/forms/_wrapper.html.erb +9 -0
- data/app/views/headmin/forms/_wysiwyg.html.erb +28 -0
- data/app/views/headmin/forms/autocomplete/_item.html.erb +3 -0
- data/app/views/headmin/forms/autocomplete/_list.html.erb +3 -0
- data/app/views/headmin/forms/fields/_group.html.erb +9 -2
- data/app/views/headmin/forms/repeater/_row.html.erb +4 -4
- data/app/views/headmin/table/_actions.html.erb +1 -1
- data/app/views/headmin/table/actions/_action.html.erb +2 -1
- data/app/views/headmin/table/actions/_delete.html.erb +1 -1
- data/bin/console +0 -1
- data/config/locales/headmin/forms/en.yml +1 -12
- data/config/locales/headmin/forms/nl.yml +1 -12
- data/esbuild-css.js +18 -18
- data/esbuild-js.js +8 -8
- data/headmin.gemspec +1 -3
- data/lib/generators/templates/controllers/auth/confirmations_controller.rb +0 -2
- data/lib/generators/templates/controllers/auth/omniauth_callbacks_controller.rb +0 -2
- data/lib/generators/templates/controllers/auth/passwords_controller.rb +0 -2
- data/lib/generators/templates/controllers/auth/registrations_controller.rb +0 -2
- data/lib/generators/templates/controllers/auth/sessions_controller.rb +0 -2
- data/lib/generators/templates/controllers/auth/unlocks_controller.rb +0 -2
- data/lib/headmin/version.rb +1 -3
- data/lib/headmin.rb +0 -2
- data/package-lock.json +5359 -0
- data/package.json +13 -6
- data/view_model_benchmark.rb +74 -0
- data/yarn-error.log +367 -0
- data/yarn.lock +1575 -31
- metadata +63 -24
- data/app/assets/stylesheets/headmin/form.scss +0 -132
- data/app/assets/stylesheets/headmin/overrides/redactorx.css +0 -3
- data/app/helpers/headmin/documentation_helper.rb +0 -35
- data/app/models/headmin/documentation_renderer.rb +0 -32
- data/app/models/headmin/form/base.rb +0 -78
- data/app/models/headmin/form/text.rb +0 -51
- data/app/services/block_service.rb +0 -72
- data/app/views/headmin/_card.html.erb +0 -52
- data/app/views/headmin/forms/_actions.html.erb +0 -28
- data/app/views/headmin/forms/_base.html.erb +0 -114
- data/app/views/headmin/forms/_image.html.erb +0 -21
- data/app/views/headmin/forms/_video.html.erb +0 -21
- data/app/views/headmin/forms/actions/_destroy.html.erb +0 -13
- data/app/views/headmin/forms/actions/_save.html.erb +0 -12
- data/app/views/headmin/forms/actions/_view.html.erb +0 -15
- data/docs/blocks-and-fields.md +0 -54
- data/docs/blocks.md +0 -48
- data/docs/devise.md +0 -41
- data/docs/fields.md +0 -79
@@ -1,39 +1,34 @@
|
|
1
1
|
<%
|
2
2
|
# headmin/forms/checkbox
|
3
3
|
#
|
4
|
-
# ====
|
5
|
-
# * +form+ - Form object
|
4
|
+
# ==== Required parameters
|
6
5
|
# * +attribute+ - Name of the attribute of the form model
|
7
|
-
# * +
|
6
|
+
# * +form+ - Form object
|
7
|
+
#
|
8
|
+
# ==== Optional parameters
|
9
|
+
# * +checked_value+ - Value for checked state
|
10
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
11
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
12
|
+
# * +unchecked_value+ - Value for unchecked state
|
13
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
14
|
+
#
|
15
|
+
# ==== References
|
16
|
+
# https://headmin.dev/docs/forms/checkbox
|
17
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox
|
18
|
+
# https://apidock.com/rails/ActionView/Helpers/FormHelper/check_box
|
8
19
|
#
|
9
20
|
# ==== Examples
|
10
21
|
# Basic version
|
11
|
-
# <%=
|
12
|
-
|
13
|
-
|
14
|
-
data = local_assigns.has_key?(:data) ? data : nil
|
15
|
-
disabled = local_assigns.has_key?(:disabled) ? disabled : false
|
16
|
-
label = local_assigns.has_key?(:label) ? label : nil
|
17
|
-
readonly = local_assigns.has_key?(:readonly) ? readonly : false
|
18
|
-
required = local_assigns.has_key?(:required) ? required : false
|
19
|
-
|
20
|
-
options = {
|
21
|
-
'aria-describedby': form_field_validation_id(form, attribute),
|
22
|
-
class: "form-checkbox-input #{form_field_validation_class(form, attribute)} #{class_names}",
|
23
|
-
data: data,
|
24
|
-
disabled: disabled,
|
25
|
-
placeholder: attribute,
|
26
|
-
readonly: readonly,
|
27
|
-
required: required,
|
28
|
-
}
|
22
|
+
# <%= form_with do |form| %#>
|
23
|
+
# <%= render "headmin/forms/checkbox", form: form, attribute: :active %#>
|
24
|
+
# <% end %#>
|
29
25
|
|
30
|
-
|
26
|
+
checkbox = Headmin::Form::CheckboxView.new(local_assigns)
|
31
27
|
%>
|
32
28
|
|
33
|
-
|
34
|
-
<%= form.check_box(attribute,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
</div>
|
29
|
+
<%= render "headmin/forms/wrapper", checkbox.wrapper_options do %>
|
30
|
+
<%= form.check_box(checkbox.attribute, checkbox.input_options, checkbox.checked_value, checkbox.unchecked_value) %>
|
31
|
+
<%= render "headmin/forms/label", checkbox.label_options if checkbox.label? %>
|
32
|
+
<%= render "headmin/forms/validation", checkbox.validation_options if checkbox.validate? %>
|
33
|
+
<%= render "headmin/forms/hint", checkbox.hint_options if checkbox.hint? %>
|
34
|
+
<% end %>
|
@@ -2,40 +2,40 @@
|
|
2
2
|
# headmin/forms/date
|
3
3
|
#
|
4
4
|
# ==== Required parameters
|
5
|
-
# * +form+ - Form object
|
6
5
|
# * +attribute+ - Name of the attribute of the form model
|
6
|
+
# * +form+ - Form object
|
7
7
|
#
|
8
8
|
# ==== Optional parameters
|
9
|
-
# * +
|
10
|
-
# * +
|
11
|
-
# * +
|
12
|
-
# * +
|
13
|
-
# * +
|
14
|
-
# * +
|
15
|
-
# * +
|
16
|
-
# * +
|
17
|
-
# * +required+ - Set to true to mark as required
|
18
|
-
# * +step+ - The acceptable value granularity
|
19
|
-
# * +value+ - Overrides the value of the form
|
20
|
-
#
|
21
|
-
# ==== Extra parameters
|
22
|
-
# Listed in 'headmin/forms/base'
|
9
|
+
# * +append+ - Display as input group with text on the right-hand side
|
10
|
+
# * +float+ - Use floating labels. Defaults to false
|
11
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
12
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
13
|
+
# * +list+ - Options are passed through options_for_select
|
14
|
+
# * +plaintext+ - Render input as plain text.
|
15
|
+
# * +prepend+ - Display as input group with text on the left-hand side
|
16
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
23
17
|
#
|
24
18
|
# ==== References
|
19
|
+
# https://headmin.dev/docs/forms/date
|
25
20
|
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
|
26
21
|
# https://apidock.com/rails/ActionView/Helpers/FormHelper/date_field
|
27
22
|
#
|
28
23
|
# ==== Examples
|
29
24
|
# Basic version
|
30
|
-
# <%=
|
25
|
+
# <%= form_with do |form| %#>
|
26
|
+
# <%= render "headmin/forms/date", form: form, attribute: :date_of_birth %#>
|
27
|
+
# <% end %#>
|
31
28
|
|
32
|
-
|
33
|
-
options = local_assigns.slice(*option_keys).merge(
|
34
|
-
aria: { describedby: form_field_validation_id(form, attribute) },
|
35
|
-
class: ['form-control', form_field_validation_class(form, attribute)].join(' '),
|
36
|
-
)
|
29
|
+
date = Headmin::Form::DateView.new(local_assigns)
|
37
30
|
%>
|
38
31
|
|
39
|
-
<%= render
|
40
|
-
<%=
|
41
|
-
|
32
|
+
<%= render "headmin/forms/wrapper", date.wrapper_options do %>
|
33
|
+
<%= render "headmin/forms/label", date.label_options if date.prepend_label? %>
|
34
|
+
<%= render "headmin/forms/input_group", date.input_group_options do %>
|
35
|
+
<%= form.date_field(date.attribute, date.input_options) %>
|
36
|
+
<%= render "headmin/forms/datalist", date.datalist_options if date.datalist? %>
|
37
|
+
<% end %>
|
38
|
+
<%= render "headmin/forms/validation", date.validation_options if date.validate? %>
|
39
|
+
<%= render "headmin/forms/hint", date.hint_options if date.hint? %>
|
40
|
+
<%= render "headmin/forms/label", date.label_options if date.append_label? %>
|
41
|
+
<% end %>
|
@@ -3,40 +3,38 @@
|
|
3
3
|
#
|
4
4
|
# ==== Required parameters
|
5
5
|
# * +form+ - Form object
|
6
|
-
# * +
|
7
|
-
# * +
|
6
|
+
# * +start+ - Hash with all options for the start date input (:attribute is required)
|
7
|
+
# * +end+ - Hash with all options for the end date input (:attribute is required)
|
8
8
|
#
|
9
9
|
# ==== Optional parameters
|
10
|
-
# * +
|
11
|
-
# * +
|
10
|
+
# * +append+ - Display as input group with text on the right-hand side
|
11
|
+
# * +float+ - Use floating labels. Defaults to false
|
12
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
13
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
14
|
+
# * +plaintext+ - Render input as plain text.
|
15
|
+
# * +prepend+ - Display as input group with text on the left-hand side
|
16
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
12
17
|
#
|
13
|
-
# ====
|
14
|
-
#
|
15
|
-
#
|
18
|
+
# ==== References
|
19
|
+
# https://headmin.dev/docs/forms/date_range
|
20
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/date
|
21
|
+
# https://apidock.com/rails/ActionView/Helpers/FormHelper/date_field
|
16
22
|
#
|
17
23
|
# ==== Examples
|
18
24
|
# Basic version
|
19
|
-
# <%=
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# <%= render 'headmin/forms/date_range', form: form, start_attribute: :start_date_2, start_label: :start_date, end_attribute: :end_date_2, end_label: :end_date %#>
|
25
|
+
# <%= form_with do |form| %#>
|
26
|
+
# <%= render 'headmin/forms/date_range', form: form, start: {attribute: :start_date}, end: {attribute: :end_date} %#>
|
27
|
+
# <% end %#>
|
23
28
|
|
24
|
-
|
25
|
-
attribute: local_assigns[:start_attribute],
|
26
|
-
label: local_assigns[:start_label]
|
27
|
-
)
|
28
|
-
end_date_options = local_assigns.merge(
|
29
|
-
attribute: local_assigns[:end_attribute],
|
30
|
-
label: local_assigns[:end_label]
|
31
|
-
)
|
29
|
+
date_range = Headmin::Form::DateRangeView.new(local_assigns)
|
32
30
|
%>
|
33
31
|
|
34
32
|
<div class="row">
|
35
33
|
<div class="col">
|
36
|
-
<%= render 'headmin/forms/date',
|
34
|
+
<%= render 'headmin/forms/date', date_range.start_options %>
|
37
35
|
</div>
|
38
36
|
<div class="col">
|
39
|
-
<%= render 'headmin/forms/date',
|
37
|
+
<%= render 'headmin/forms/date', date_range.end_options %>
|
40
38
|
</div>
|
41
39
|
</div>
|
42
40
|
|
@@ -2,47 +2,42 @@
|
|
2
2
|
# headmin/forms/email
|
3
3
|
#
|
4
4
|
# ==== Required parameters
|
5
|
-
# * +form+ - Form object
|
6
5
|
# * +attribute+ - Name of the attribute of the form model
|
6
|
+
# * +form+ - Form object
|
7
7
|
#
|
8
8
|
# ==== Optional parameters
|
9
|
-
# * +
|
10
|
-
# * +
|
11
|
-
# * +
|
12
|
-
# * +
|
13
|
-
# * +
|
14
|
-
# * +list+ -
|
15
|
-
# * +
|
16
|
-
# * +
|
17
|
-
# * +
|
18
|
-
# * +pattern+ -a A regular expression that the input's value must match
|
19
|
-
# * +placeholder+ - Sets the placeholder of the field
|
20
|
-
# * +readonly+ - Sets the placeholder of the field
|
21
|
-
# * +required+ - Set to true to mark as required
|
22
|
-
# * +size+ - How much of the input should be shown
|
23
|
-
# * +value+ - Overrides the value of the form
|
24
|
-
#
|
25
|
-
# ==== Extra parameters
|
26
|
-
# Listed in 'headmin/forms/base'
|
9
|
+
# * +append+ - Display as input group with text on the right-hand side
|
10
|
+
# * +collection+ - Values to be suggested while typing. Can be an collection array or a remote URL.
|
11
|
+
# * +float+ - Use floating labels. Defaults to false
|
12
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
13
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
14
|
+
# * +list+ - Options are passed through options_for_select
|
15
|
+
# * +plaintext+ - Render input as plain text.
|
16
|
+
# * +prepend+ - Display as input group with text on the left-hand side
|
17
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
27
18
|
#
|
28
19
|
# ==== References
|
29
|
-
# https://
|
30
|
-
# https://
|
20
|
+
# https://headmin.dev/docs/forms/email
|
21
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email
|
22
|
+
# https://apidock.com/rails/ActionView/Helpers/FormHelper/email_field
|
31
23
|
#
|
32
24
|
# ==== Examples
|
33
25
|
# Basic version
|
34
|
-
# <%=
|
35
|
-
|
36
|
-
|
26
|
+
# <%= form_with do |form| %#>
|
27
|
+
# <%= render "headmin/forms/email", form: form, attribute: :email_address %#>
|
28
|
+
# <% end %#>
|
37
29
|
|
38
|
-
|
39
|
-
options = local_assigns.slice(*option_keys).merge(
|
40
|
-
aria: { describedby: form_field_validation_id(form, attribute) },
|
41
|
-
class: ['form-control', form_field_validation_class(form, attribute)].join(' '),
|
42
|
-
placeholder: placeholder
|
43
|
-
)
|
30
|
+
email = Headmin::Form::EmailView.new(local_assigns)
|
44
31
|
%>
|
45
32
|
|
46
|
-
<%= render
|
47
|
-
|
33
|
+
<%= render "headmin/forms/wrapper", email.wrapper_options do %>
|
34
|
+
<%= render "headmin/forms/label", email.label_options if email.prepend_label? %>
|
35
|
+
<%= render "headmin/forms/input_group", email.input_group_options do %>
|
36
|
+
<%= form.email_field(email.attribute, email.input_options) %>
|
37
|
+
<%= render "headmin/forms/datalist", email.datalist_options if email.datalist? %>
|
38
|
+
<%= render "headmin/forms/autocomplete", email.autocomplete_options if email.autocomplete? %>
|
39
|
+
<% end %>
|
40
|
+
<%= render "headmin/forms/validation", email.validation_options if email.validate? %>
|
41
|
+
<%= render "headmin/forms/hint", email.hint_options if email.hint? %>
|
42
|
+
<%= render "headmin/forms/label", email.label_options if email.append_label? %>
|
48
43
|
<% end %>
|
@@ -8,12 +8,11 @@
|
|
8
8
|
<% if form.object.errors.any? %>
|
9
9
|
<div class="alert alert-danger" role="alert">
|
10
10
|
<h5 class="alert-heading d-flex align-items-center">
|
11
|
-
<%= bootstrap_icon('exclamation-triangle-fill', class: 'me-2') %>
|
12
11
|
<%= t('errors.template.header', count: form.object.errors.size, model: form.object.model_name.human) %>
|
13
12
|
</h5>
|
14
|
-
<ul>
|
13
|
+
<ul class="mb-0">
|
15
14
|
<% form.object.errors.full_messages.each do |message| %>
|
16
|
-
|
15
|
+
<li><%= message %></li>
|
17
16
|
<% end %>
|
18
17
|
</ul>
|
19
18
|
</div>
|
@@ -1,192 +1,95 @@
|
|
1
|
-
<!--
|
2
|
-
<% documentation do %>
|
3
|
-
# File
|
4
|
-
This is a wrapper around the form helper `file_field()`.
|
5
|
-
You can pass all valid input attributes as parameters to this template and
|
6
|
-
they will be added directly to the input field.
|
7
|
-
|
8
|
-
```erbx
|
9
|
-
<%= form_with do |form| %>
|
10
|
-
<%= render "headmin/forms/file", form: form, attribute: "basic_example" %>
|
11
|
-
<% end %>
|
12
|
-
```
|
13
|
-
|
14
|
-
## Parameters
|
15
|
-
| Name | Required | Type | Description |
|
16
|
-
| ------------ | -------- | ---------------- | ----------- |
|
17
|
-
| form | yes | Object | Form object |
|
18
|
-
| attribute | yes | String, Symbol | Name of the attribute of the form model |
|
19
|
-
| accept | no | String | A comma-separated list of allowed file extensions or MIME types |
|
20
|
-
| aria | no | Hash | Provide a hash to define all aria attributes |
|
21
|
-
| autocomplete | no | String | Hint for form autofill feature |
|
22
|
-
| autofocus | no | Boolean | Automatically focus the form control when the page is loaded |
|
23
|
-
| capture | no | String | Allows selection of capturing device. Accepted: user, environment |
|
24
|
-
| data | no | Hash | Provide a hash to define all data attributes |
|
25
|
-
| disabled | no | Boolean | Whether the form control is disabled |
|
26
|
-
| destroy | no | Boolean | Adds delete buttons to the preview thumbnails |
|
27
|
-
| dropzone | no | Boolean | Add drag&drop interface. This setting automatically enables previews |
|
28
|
-
| id | no | String | Input identifier |
|
29
|
-
| multiple | no | Boolean | Allows the user to select more than one file. |
|
30
|
-
| preview | no | Boolean | Show file previews after selection and after upload |
|
31
|
-
| required | no | Boolean | A value is required or must be check for the form to be submittable |
|
32
|
-
| value | no | String | The initial value of the control |
|
33
|
-
|
34
|
-
**Additional parameters**
|
35
|
-
|
36
|
-
This view makes use of [headmin/forms/base](https://headmin.test/forms/base) for labels and appendages.
|
37
|
-
Take a look at its documentation to get a complete overview of all additional parameters.
|
38
|
-
|
39
|
-
## Examples
|
40
|
-
|
41
|
-
### Preview
|
42
|
-
```erbx
|
43
|
-
<%= form_with do |form| %>
|
44
|
-
<div class="row">
|
45
|
-
<div class="col-md-4">
|
46
|
-
<%= render "headmin/forms/file", form: form, attribute: "single", preview: true %>
|
47
|
-
</div>
|
48
|
-
<div class="col-md-4">
|
49
|
-
<%= render "headmin/forms/file", form: form, attribute: "multiple", preview: true, multiple: true %>
|
50
|
-
</div>
|
51
|
-
<div class="col-md-4">
|
52
|
-
<%= render "headmin/forms/file", form: form, attribute: "with_delete_button", preview: true, multiple: true, destroy: true %>
|
53
|
-
</div>
|
54
|
-
</div>
|
55
|
-
<% end %>
|
56
|
-
```
|
57
|
-
|
58
|
-
### Drag & Drop
|
59
|
-
```erbx
|
60
|
-
<%= form_with do |form| %>
|
61
|
-
<%= render "headmin/forms/file", form: form, attribute: "single", dropzone: true %>
|
62
|
-
<%= render "headmin/forms/file", form: form, attribute: "multiple", dropzone: true, multiple: true %>
|
63
|
-
<%= render "headmin/forms/file", form: form, attribute: "with_delete_button", dropzone: true, multiple: true, destroy: true %>
|
64
|
-
<% end %>
|
65
|
-
```
|
66
|
-
|
67
|
-
### States
|
68
|
-
```erbx
|
69
|
-
<%= form_with do |form| %>
|
70
|
-
<%= render "headmin/forms/file", form: form, attribute: "disabled", disabled: true %>
|
71
|
-
<%= render "headmin/forms/file", form: form, attribute: "readonly", readonly: true %>
|
72
|
-
<%= render "headmin/forms/file", form: form, attribute: "disabled_and_readonly", disabled: true, readonly: true %>
|
73
|
-
<% end %>
|
74
|
-
```
|
75
|
-
|
76
|
-
## References
|
77
|
-
- [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file)
|
78
|
-
- [APIdock](https://apidock.com/rails/v5.2.3/ActionView/Helpers/FormHelper/file_field)
|
79
|
-
<% end %>
|
80
|
-
-->
|
81
1
|
<%
|
82
|
-
#
|
83
|
-
# Limit file types (e.g. only Microsoft Word files)
|
84
|
-
# <%= render 'headmin/forms/file', form: form, attribute: :file, accept: '.doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document' %#>
|
2
|
+
# headmin/forms/file
|
85
3
|
#
|
86
|
-
#
|
87
|
-
#
|
4
|
+
# ==== Required parameters
|
5
|
+
# * +attribute+ - Name of the attribute of the form model
|
6
|
+
# * +form+ - Form object
|
88
7
|
#
|
89
|
-
#
|
90
|
-
#
|
8
|
+
# ==== Optional parameters
|
9
|
+
# * +append+ - Display as input group with text on the right-hand side
|
10
|
+
# * +destroy+ - Adds delete buttons to the preview thumbnails
|
11
|
+
# * +dropzone+ - Add drag&drop interface. This setting automatically enables previews
|
12
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
13
|
+
# * +multiple+ - Add drag&drop interface. This setting automatically enables previews
|
14
|
+
# * +preview+ - Show file previews after selection and after upload
|
15
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
16
|
+
# * +prepend+ - Display as input group with text on the left-hand side
|
17
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
91
18
|
#
|
92
|
-
#
|
93
|
-
#
|
19
|
+
# ==== References
|
20
|
+
# https://headmin.dev/docs/forms/file
|
21
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file
|
22
|
+
# https://apidock.com/rails/ActionView/Helpers/FormHelper/file_field
|
94
23
|
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
attachments = attached&.attachments || []
|
101
|
-
dropzone = local_assigns[:dropzone]
|
102
|
-
preview = local_assigns[:preview] || dropzone
|
103
|
-
destroy = local_assigns[:destroy] || false
|
104
|
-
number_of_files = local_assigns[:multiple] ? 2 : 1
|
105
|
-
|
106
|
-
nested_attribute = attached.is_a?(ActiveStorage::Attached::Many) ? :"#{attribute.to_s}_attachments" : :"#{attribute.to_s}_attachment"
|
107
|
-
|
108
|
-
option_keys = %i(accept aria autocomplete autofocus capture data disabled id multiple required value)
|
109
|
-
options = local_assigns.slice(*option_keys).merge(
|
110
|
-
aria: { describedby: form_field_validation_id(form, attribute) },
|
111
|
-
class: ['form-control', form_field_validation_class(form, attribute)].join(' '),
|
112
|
-
list: local_assigns[:list] ? "#{attribute}_list" : nil,
|
113
|
-
placeholder: placeholder,
|
114
|
-
required: attached ? false : local_assigns[:required]
|
115
|
-
)
|
116
|
-
|
117
|
-
if preview
|
118
|
-
local_assigns = local_assigns.merge(
|
119
|
-
data: {
|
120
|
-
controller: 'file-preview'
|
121
|
-
}
|
122
|
-
)
|
123
|
-
options = options.merge(
|
124
|
-
data: {
|
125
|
-
'file-preview-target': 'input',
|
126
|
-
'dropzone-target': 'input',
|
127
|
-
action: 'change->file-preview#preview dropEnd->file-preview#preview'
|
128
|
-
}
|
129
|
-
)
|
130
|
-
end
|
24
|
+
# ==== Examples
|
25
|
+
# Basic version
|
26
|
+
# <%= form_with do |form| %#>
|
27
|
+
# <%= render "headmin/forms/file", form: form, attribute: :file %#>
|
28
|
+
# <% end %#>
|
131
29
|
|
132
|
-
|
133
|
-
thumbnail_height = 100
|
30
|
+
file = Headmin::Form::FileView.new(local_assigns)
|
134
31
|
%>
|
135
32
|
|
136
|
-
<%= render
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
<%=
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
33
|
+
<%= render "headmin/forms/wrapper", file.wrapper_options do %>
|
34
|
+
<%= render "headmin/forms/label", file.label_options if file.prepend_label? %>
|
35
|
+
<div <%= tag.attributes(file.dropzone_options) %>>
|
36
|
+
<%= render "headmin/forms/input_group", file.input_group_options do %>
|
37
|
+
|
38
|
+
<% if file.preview %>
|
39
|
+
<div class="h-form-file-thumbnails" data-file-preview-target="thumbnails">
|
40
|
+
|
41
|
+
<!-- Render previews for attachments -->
|
42
|
+
<%= form.fields_for(file.nested_attribute) do |ff| %>
|
43
|
+
<%
|
44
|
+
attachment = ff.object
|
45
|
+
next unless attachment
|
46
|
+
filename = attachment.blob.filename.to_s
|
47
|
+
size = number_to_human_size(attachment.blob.byte_size)
|
48
|
+
src = attachment.image? ? url_for(attachment.variant(resize_to_fill: [file.thumbnail_width, file.thumbnail_height])) : url_for(attachment)
|
49
|
+
%>
|
50
|
+
<div class="h-form-file-thumbnail" title="<%= "#{filename} (#{size})" %>" data-file-preview-target="thumbnail">
|
51
|
+
<%= ff.hidden_field(:id, disabled: file.destroy) %>
|
52
|
+
<%= ff.hidden_field(:_destroy, data: {'file-preview-target': 'thumbnailDestroy'}, disabled: file.destroy) %>
|
53
|
+
<%= render 'headmin/thumbnail', src: src, width: file.thumbnail_width, height: file.thumbnail_height %>
|
54
|
+
|
55
|
+
<% if file.destroy %>
|
56
|
+
<div class="h-form-file-thumbnail-remove" data-action="click->file-preview#remove" data-file-preview-name-param="<%= filename %>">
|
57
|
+
<%= bootstrap_icon('x') %>
|
58
|
+
</div>
|
59
|
+
<% end %>
|
60
|
+
</div>
|
61
|
+
<% end %>
|
62
|
+
|
63
|
+
<!-- Placeholder -->
|
64
|
+
<% if file.dropzone %>
|
65
|
+
<div class="h-dropzone-placeholder <%= 'd-none' if file.attachments.any? %>" data-file-preview-target="placeholder" style="height: <%= file.thumbnail_height %>px;">
|
66
|
+
<%= t('headmin.forms.file.placeholder', count: file.number_of_files) %>
|
67
|
+
</div>
|
68
|
+
<% else %>
|
69
|
+
<div class="h-form-file-thumbnail <%= 'd-none' if file.attachments.any? %>" title="<%= t('headmin.forms.file.not_found') %>" data-file-preview-target="placeholder">
|
70
|
+
<%= render 'headmin/thumbnail', width: file.thumbnail_width, height: file.thumbnail_height, icon: "plus" %>
|
71
|
+
</div>
|
72
|
+
<% end %>
|
73
|
+
</div>
|
74
|
+
<% end %>
|
75
|
+
|
76
|
+
<!-- Template -->
|
77
|
+
<template data-file-preview-target="template">
|
78
|
+
<div class="h-form-file-thumbnail" title="" data-file-preview-target="thumbnail">
|
79
|
+
<%= render 'headmin/thumbnail', src: nil, width: file.thumbnail_width, height: file.thumbnail_height %>
|
80
|
+
|
81
|
+
<% if file.destroy %>
|
82
|
+
<div class="h-form-file-thumbnail-remove" data-action="click->file-preview#remove">
|
83
|
+
<%= bootstrap_icon('x') %>
|
84
|
+
</div>
|
85
|
+
<% end %>
|
86
|
+
</div>
|
87
|
+
</template>
|
88
|
+
|
89
|
+
<%= form.file_field(attribute, file.input_options) %>
|
175
90
|
<% end %>
|
176
|
-
|
177
|
-
<!-- Template -->
|
178
|
-
<template data-file-preview-target="template">
|
179
|
-
<div class="h-form-file-thumbnail" title="" data-file-preview-target="thumbnail">
|
180
|
-
<%= render 'headmin/thumbnail', src: nil, width: thumbnail_width, height: thumbnail_height %>
|
181
|
-
|
182
|
-
<% if destroy %>
|
183
|
-
<div class="h-form-file-thumbnail-remove" data-action="click->file-preview#remove">
|
184
|
-
<%= bootstrap_icon('x') %>
|
185
|
-
</div>
|
186
|
-
<% end %>
|
187
|
-
</div>
|
188
|
-
</template>
|
189
|
-
|
190
|
-
<%= form.file_field(attribute, options) %>
|
191
91
|
</div>
|
92
|
+
<%= render "headmin/forms/validation", file.validation_options if file.validate? %>
|
93
|
+
<%= render "headmin/forms/hint", file.hint_options if file.hint? %>
|
94
|
+
<%= render "headmin/forms/label", file.label_options if file.append_label? %>
|
192
95
|
<% end %>
|
@@ -2,33 +2,32 @@
|
|
2
2
|
# headmin/forms/flatpickr
|
3
3
|
#
|
4
4
|
# ==== Required parameters
|
5
|
-
# * +form+ - Form object
|
6
5
|
# * +attribute+ - Name of the attribute of the form model
|
6
|
+
# * +form+ - Form object
|
7
7
|
#
|
8
8
|
# ==== Optional parameters
|
9
|
-
# * +
|
10
|
-
# * +
|
11
|
-
# * +
|
12
|
-
# * +
|
13
|
-
# * +
|
9
|
+
# * +append+ - Display as input group with text on the right-hand side
|
10
|
+
# * +float+ - Use floating labels. Defaults to false
|
11
|
+
# * +flatpickr+ - Hash with all options you can pass to flatpickr JS config
|
12
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
13
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
14
|
+
# * +list+ - Options are passed through options_for_select
|
15
|
+
# * +plaintext+ - Render input as plain text.
|
16
|
+
# * +prepend+ - Display as input group with text on the left-hand side
|
17
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
14
18
|
#
|
15
|
-
# ====
|
16
|
-
#
|
19
|
+
# ==== References
|
20
|
+
# https://headmin.dev/docs/forms/date
|
21
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
|
22
|
+
# https://apidock.com/rails/ActionView/Helpers/FormHelper/date_field
|
17
23
|
#
|
18
24
|
# ==== Examples
|
19
25
|
# Basic version
|
20
|
-
# <%=
|
26
|
+
# <%= form_with do |form| %#>
|
27
|
+
# <%= render "headmin/forms/date", form: form, attribute: :date_of_birth %#>
|
28
|
+
# <% end %#>
|
21
29
|
|
22
|
-
|
23
|
-
data: {
|
24
|
-
'flatpickr-target': 'input',
|
25
|
-
'flatpickr-options': {
|
26
|
-
defaultDate: form.object&.send(attribute)&.strftime('%d/%m/%Y')
|
27
|
-
}
|
28
|
-
}
|
29
|
-
)
|
30
|
+
flatpickr = Headmin::Form::FlatpickrView.new(local_assigns)
|
30
31
|
%>
|
31
32
|
|
32
|
-
|
33
|
-
<%= render 'headmin/forms/date', options %>
|
34
|
-
</div>
|
33
|
+
<%= render 'headmin/forms/date', flatpickr.options %>
|