headmin 0.2.7 → 0.2.8

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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/app/views/examples/admin.html.erb +1 -1
  4. data/app/views/headmin/_card.html.erb +3 -1
  5. data/app/views/headmin/_filters.html.erb +2 -2
  6. data/app/views/headmin/_pagination.html.erb +2 -4
  7. data/app/views/headmin/_table.html.erb +9 -3
  8. data/app/views/headmin/filters/_date.html.erb +5 -3
  9. data/app/views/headmin/filters/_flatpickr.html.erb +57 -0
  10. data/app/views/headmin/forms/_base.html.erb +12 -11
  11. data/app/views/headmin/forms/_date.html.erb +24 -12
  12. data/app/views/headmin/forms/_date_range.html.erb +84 -0
  13. data/app/views/headmin/forms/_flatpickr.html.erb +55 -0
  14. data/app/views/headmin/forms/_flatpickr_range.html.erb +61 -0
  15. data/app/views/headmin/forms/_hidden.html.erb +23 -0
  16. data/app/views/headmin/forms/_label.html.erb +3 -1
  17. data/app/views/headmin/forms/_select.html.erb +14 -11
  18. data/app/views/headmin/forms/_text.html.erb +7 -9
  19. data/app/views/headmin/layout/_main.html.erb +11 -5
  20. data/app/views/headmin/table/_actions.html.erb +1 -3
  21. data/app/views/headmin/table/body/_row.html.erb +14 -6
  22. data/dist/css/headmin.css +4 -1
  23. data/dist/js/headmin.js +40 -5
  24. data/lib/headmin/version.rb +1 -1
  25. data/src/js/headmin/controllers/date_range_controller.js +34 -0
  26. data/src/js/headmin/controllers/flatpickr_controller.js +38 -0
  27. data/src/js/headmin/controllers/repeater_controller.js +0 -1
  28. data/src/js/headmin/controllers/table_actions_controller.js +7 -37
  29. data/src/js/headmin/controllers/table_controller.js +23 -3
  30. data/src/js/headmin/headmin.js +36 -19
  31. data/src/scss/headmin/form.scss +4 -0
  32. metadata +9 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75079b879cee8f51cc97f715f1714d29554519f30ad046aa5c391ae663fb5ea0
4
- data.tar.gz: b7e38afe69ddfb236653170172d8bfa74ddb972071cfb6644d460a89a0581b48
3
+ metadata.gz: 97d58b9cf116a2017929bd0460593bedc48a2be8e8d53011b6db46fc3ee1df5f
4
+ data.tar.gz: 379caa2715bb6c22efe961996420ce9fe0c8a6dc17ee88847d0d9661da768328
5
5
  SHA512:
6
- metadata.gz: 052d363086709d82b0f526dec7a9a80fb05845d3da62b8aee65f35d3b5e5c7e6a4431c3a9f079491d12eca8387fabf06338cc6a14c950728db910605409195dd
7
- data.tar.gz: b83c34883e5ca7719e14a1282412b836e8bbf706071283c07d2ec6dcd0a2317737c43044f5e0fe138d406fd14b930b6d72a1b9cac11d9ed6237477d3b4220083
6
+ metadata.gz: 5d0452d83d31e5ac38ce1d75fc3d189d0400343d1f0ca82690e9d4c284a5acdae9dba36862b0a2aeba0784ca1c6cb1241970752de836b03cf62a08cbedf32b23
7
+ data.tar.gz: 01e9857909d763690fbf63ab0efe901f49894594060e3945b777b025414a5c294c2a5af475f47d1cc21ac9757cd5341610ee555a197eb30340e949219ac1accf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- headmin (0.2.6)
4
+ headmin (0.2.7)
5
5
  closure_tree
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html>
2
- <html>
2
+ <html lang="<%= I18n.locale %>">
3
3
  <head>
4
4
  <title>Admin</title>
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
@@ -4,6 +4,7 @@
4
4
  # ==== Options
5
5
  # * <tt>title</tt> - Title for card
6
6
  # * <tt>description</tt> - Description for card
7
+ # * <tt>id</tt> - HTML Id Attribute
7
8
  # * <tt>padded</tt> - Set to true if you want to render the block content inside the card-body element
8
9
  #
9
10
  # ==== Examples
@@ -17,12 +18,13 @@
17
18
  # Your content
18
19
  # <% end %#>
19
20
 
21
+ id = local_assigns.has_key?(:id) ? id : nil
20
22
  title = local_assigns.has_key?(:title) ? title : nil
21
23
  description = local_assigns.has_key?(:description) ? description : nil
22
24
  padded = local_assigns.has_key?(:padded) ? padded : true
23
25
  %>
24
26
 
25
- <div class="card mb-3 shadow-sm">
27
+ <div class="card mb-3 shadow-sm" id="<%= id %>">
26
28
 
27
29
  <% if padded || title || description %>
28
30
  <div class="card-body">
@@ -31,14 +31,14 @@
31
31
  <%= content_for :filters_search %>
32
32
 
33
33
  <!-- Separator -->
34
- <% if content_for(:filters_menu) && content_for(:filters_search) %>
34
+ <% if content_for?(:filters_menu) && content_for?(:filters_search) %>
35
35
  <div class="vr mx-2"></div>
36
36
  <% end %>
37
37
  </div>
38
38
 
39
39
  <!-- Menu -->
40
40
  <div class="h-filters-menu d-flex align-items-center w-auto my-1">
41
- <% if content_for :filters_menu %>
41
+ <% if content_for?(:filters_menu) %>
42
42
  <div class="btn-group">
43
43
  <button type="button" class="btn h-btn-outline-light dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
44
44
  <%= bootstrap_icon('funnel') %>
@@ -10,11 +10,9 @@
10
10
  %>
11
11
 
12
12
  <div class="d-flex flex-row-reverse flex-md-row align-items-center justify-content-between justify-content-md-end my-1">
13
- <% content_for :collection_total_count do %>
14
- <%= collection.total_count %>
15
- <% end %>
13
+ <% content_for :collection_total_count, collection.total_count.to_s unless content_for?(:collection_total_count) %>
16
14
  <div class="ms-2 me-md-2 text-secondary">
17
- <%= t('.items', count: content_for(:collection_total_count)) %>
15
+ <%= t('.items', count: content_for(:collection_total_count).to_i) %>
18
16
  </div>
19
17
  <%= paginate collection, views_prefix: 'headmin/pagination' %>
20
18
  </div>
@@ -2,18 +2,24 @@
2
2
  # headmin/table
3
3
  #
4
4
  # ==== Options
5
- # * <tt>sort_url</tt> - U
5
+ # * <tt>sort_url</tt> - Url to post object ids to in the order of positions
6
6
  #
7
7
  # ==== Examples
8
8
  # <%= render 'headmin/table', sort_url: positions_admin_categories_path do %#>
9
9
  # table content here
10
10
  # <% end %#>
11
+
12
+ sort_url = local_assigns.has_key?(:sort_url) ? sort_url : nil
13
+ total_count = content_for(:collection_total_count).to_i || nil
11
14
  %>
12
15
 
13
- <% sort_url = local_assigns.has_key?(:sort_url) ? sort_url : nil %>
14
16
  <div class="h-table card my-2 shadow-sm <%= 'table-drag-sort' if sort_url %>" data-sort-url="<%= sort_url %>">
15
17
  <div class="table-responsive">
16
- <table class="table table-hover m-0" data-controller="table" data-table-target="table" data-table-url-value="<%= sort_url %>">
18
+ <table class="table table-hover m-0"
19
+ data-controller="table"
20
+ data-table-target="table"
21
+ data-table-url-value="<%= sort_url %>"
22
+ data-table-count-value="<%= total_count %>">
17
23
  <%= yield if block_given? %>
18
24
  </table>
19
25
  </div>
@@ -14,10 +14,12 @@
14
14
 
15
15
  input_options = {
16
16
  placeholder: 'dd/mm/yyyy',
17
- class: "form-control flatpickr",
17
+ class: "form-control",
18
18
  required: true,
19
- 'data-filters-target': 'input',
20
- 'data-action': "change->filters#update"
19
+ data: {
20
+ 'filters-target': 'input',
21
+ 'action': 'change->filters#update',
22
+ }
21
23
  }
22
24
  %>
23
25
 
@@ -0,0 +1,57 @@
1
+ <%
2
+ # headmin/filters/flatpickr
3
+ #
4
+ # ==== Options
5
+ # * <tt>name</tt> - Name of the filter parameter
6
+ # * <tt>label</tt> - Display name
7
+ #
8
+ # ==== Examples
9
+ # Basic version
10
+ # <%= render "headmin/filters/flatpickr", name: :created_at, label: 'Created at' %#>
11
+
12
+ label = local_assigns.has_key?(:label) ? label : nil
13
+ name = local_assigns.has_key?(:name) ? name : nil
14
+
15
+ input_options = {
16
+ placeholder: 'dd/mm/yyyy',
17
+ class: "form-control",
18
+ required: true,
19
+ data: {
20
+ 'filters-target': 'input',
21
+ 'flatpickr-target': 'input',
22
+ 'action': 'change->filters#update',
23
+ 'flatpickr-options': {
24
+ defaultDate: params[name]
25
+ }
26
+ }
27
+ }
28
+ %>
29
+
30
+ <%= content_for :filters_menu do %>
31
+ <%= render 'headmin/filters/filter/menu_item', name: name, label: label %>
32
+ <% end %>
33
+
34
+ <%= content_for :filters_templates do %>
35
+ <%= render 'headmin/filters/filter/template', name: name, label: label do %>
36
+ <div class="input-group" data-controller="flatpickr">
37
+ <span class="input-group-text">
38
+ <%= bootstrap_icon('calendar') %>
39
+ </span>
40
+ <%= date_field_tag(name, nil, input_options) %>
41
+ </div>
42
+ <% end %>
43
+ <% end %>
44
+
45
+ <%= content_for :filters_buttons do %>
46
+ <% if filter_param_exists?(name) %>
47
+ <% value_formatted = Date.parse(params[name]).strftime('%d/%m/%Y') %>
48
+ <%= render 'headmin/filters/filter/button', id: "filter-#{name}", name: name, label: label, value: value_formatted do %>
49
+ <div class="input-group" data-controller="flatpickr">
50
+ <span class="input-group-text">
51
+ <%= bootstrap_icon('calendar') %>
52
+ </span>
53
+ <%= date_field_tag(name, params[name], input_options) %>
54
+ </div>
55
+ <% end %>
56
+ <% end %>
57
+ <% end %>
@@ -2,14 +2,14 @@
2
2
  # headmin/forms/base
3
3
  #
4
4
  # ==== Options
5
- # * <tt>form<tt> - Form object
5
+ # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
6
6
  # * <tt>attribute<tt> - Name of the attribute of the form model
7
- # * <tt>options<tt> - Hash with all HTML options to pass to
8
- # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
9
- # * <tt>required<tt> - Set to true to mark as required
10
7
  # * <tt>float<tt> - Set to true if you want to show floating labels
11
- # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
8
+ # * <tt>form<tt> - Form object
9
+ # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
10
+ # * <tt>options<tt> - Hash with all HTML options to pass to
12
11
  # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
12
+ # * <tt>required<tt> - Set to true to mark as required
13
13
  #
14
14
  # ==== Examples
15
15
  # Basic version
@@ -19,9 +19,10 @@
19
19
  # <%= render 'headmin/forms/text', form: form, attribute: :title, datepicker: true %#>
20
20
 
21
21
  append = local_assigns.has_key?(:append) ? append : nil
22
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
23
+ group = append || prepend
22
24
  float = local_assigns.has_key?(:float) ? float : false
23
25
  label = local_assigns.has_key?(:label) ? label : nil
24
- prepend = local_assigns.has_key?(:prepend) ? prepend : nil
25
26
  required = local_assigns.has_key?(:required) ? required : false
26
27
 
27
28
  show_label = label != false
@@ -32,10 +33,7 @@
32
33
  <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
33
34
  <% end %>
34
35
 
35
- <% if float %>
36
- <%= yield form %>
37
- <%= render 'headmin/forms/validation', form: form, attribute: attribute %>
38
- <% else %>
36
+ <% if group %>
39
37
  <div class="input-group w-100">
40
38
  <% if prepend %>
41
39
  <span class="input-group-text">
@@ -44,7 +42,7 @@
44
42
  <% end %>
45
43
 
46
44
  <%= yield form %>
47
- <%= render 'headmin/forms/validation', form: form, attribute: attribute %>
45
+ <%= render 'headmin/forms/validation', form: form, attribute: attribute if form.object.respond_to?(:errors) %>
48
46
 
49
47
  <% if append %>
50
48
  <span class="input-group-text">
@@ -52,6 +50,9 @@
52
50
  </span>
53
51
  <% end %>
54
52
  </div>
53
+ <% else %>
54
+ <%= yield form %>
55
+ <%= render 'headmin/forms/validation', form: form, attribute: attribute if form.object.respond_to?(:errors) %>
55
56
  <% end %>
56
57
 
57
58
  <% if show_label && float %>
@@ -2,19 +2,22 @@
2
2
  # headmin/forms/date
3
3
  #
4
4
  # ==== Options
5
- # * <tt>form<tt> - Form object
5
+ # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
6
6
  # * <tt>attribute<tt> - Name of the attribute of the form model
7
- # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
7
+ # * <tt>class<tt> - Optional HTML class attribute
8
+ # * <tt>data<tt> - Optional HTML data attributes
9
+ # * <tt>disabled<tt> - Set to true if the input should be shown as disabled
8
10
  # * <tt>float<tt> - Set to true if you want to show floating labels
9
- # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
11
+ # * <tt>form<tt> - Form object
12
+ # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
13
+ # * <tt>name<tt> - The name of the field
10
14
  # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
15
+ # * <tt>readonly<tt> - Set to true if the value of the field can only be read and not be modified
16
+ # * <tt>required<tt> - Set to true to show a HTML5 validation message when left blank
11
17
  #
12
18
  # ==== Examples
13
19
  # Basic version
14
- # <%= render 'headmin/forms/date', form: form, attribute: :title %#>
15
- #
16
- # With datepicker
17
- # <%= render 'headmin/forms/text', form: form, attribute: :title, datepicker: true %#>
20
+ # <%= render 'headmin/forms/date', form: form, attribute: :date %#>
18
21
 
19
22
  append = local_assigns.has_key?(:append) ? append : nil
20
23
  class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
@@ -25,21 +28,30 @@
25
28
  prepend = local_assigns.has_key?(:prepend) ? prepend : nil
26
29
  readonly = local_assigns.has_key?(:readonly) ? readonly : false
27
30
  required = local_assigns.has_key?(:required) ? required : false
28
- datepicker = local_assigns.has_key?(:datepicker) ? local_assigns[:datepicker] : false
29
-
30
- class_names = "#{class_names} flatpickr" if datepicker
31
31
 
32
32
  options = {
33
33
  'aria-describedby': form_field_validation_id(form, attribute),
34
34
  class: "form-control #{form_field_validation_class(form, attribute)} #{class_names}",
35
35
  data: data,
36
36
  disabled: disabled,
37
- placeholder: attribute,
37
+ placeholder: label ? label.to_s.humanize : nil,
38
38
  readonly: readonly,
39
39
  required: required,
40
40
  }
41
+
42
+ options[:name] = name if local_assigns.has_key?(:name)
43
+
44
+ template_locals = {
45
+ append: append,
46
+ attribute: attribute,
47
+ float: float,
48
+ form: form,
49
+ label: label,
50
+ prepend: prepend,
51
+ required: required
52
+ }
41
53
  %>
42
54
 
43
- <%= render 'headmin/forms/base', form: form, attribute: attribute, append: append, prepend: prepend, float: float, label: label, required: required do |form| %>
55
+ <%= render 'headmin/forms/base', template_locals do |form| %>
44
56
  <%= form.date_field(attribute, options) %>
45
57
  <% end %>
@@ -0,0 +1,84 @@
1
+ <%
2
+ # headmin/forms/date_range
3
+ #
4
+ # ==== Options
5
+ # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
6
+ # * <tt>class<tt> - Optional HTML class attribute
7
+ # * <tt>data<tt> - Optional HTML data attributes
8
+ # * <tt>end_attribute<tt> - Name of the end date attribute of the form model
9
+ # * <tt>end_label<tt> - Label for the end attribute
10
+ # * <tt>float<tt> - Set to true if you want to show floating labels
11
+ # * <tt>form<tt> - Form object
12
+ # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
13
+ # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
14
+ # * <tt>readonly<tt> - Set to true if the value of the field can only be read and not be modified
15
+ # * <tt>required<tt> - Set to true to show a HTML5 validation message when left blank
16
+ # * <tt>single<tt> - Set to true if only one field should be displayed
17
+ # * <tt>start_attribute<tt> - Name of the start date attribute of the form model
18
+ # * <tt>start_label<tt> - Label for the start attribute
19
+ #
20
+ # ==== Examples
21
+ # Basic version
22
+ # <%= render 'headmin/forms/date_range', form: form, start_attribute: :start_date, end_attribute: :end_date %#>
23
+ #
24
+ # With custom labels
25
+ # <%= 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 %#>
26
+
27
+ append = local_assigns.has_key?(:append) ? append : nil
28
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
29
+ data = local_assigns.has_key?(:data) ? data : {}
30
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
31
+ end_attribute = local_assigns.has_key?(:end_attribute) ? end_attribute : nil
32
+ end_label = local_assigns.has_key?(:end_label) ? end_label : nil
33
+ float = local_assigns.has_key?(:float) ? float : false
34
+ label = local_assigns.has_key?(:label) ? label : nil
35
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
36
+ readonly = local_assigns.has_key?(:readonly) ? readonly : false
37
+ required = local_assigns.has_key?(:required) ? required : false
38
+ start_attribute = local_assigns.has_key?(:start_attribute) ? start_attribute : nil
39
+ start_label = local_assigns.has_key?(:start_label) ? start_label : nil
40
+ single = local_assigns.has_key?(:single) ? single : false
41
+
42
+ template_locals = {
43
+ form: form,
44
+ append: append,
45
+ prepend: prepend,
46
+ float: float,
47
+ label: label,
48
+ class: class_names,
49
+ data: data.merge(action: 'change->date-range#update'),
50
+ disabled: disabled,
51
+ readonly: readonly,
52
+ required: required
53
+ }
54
+
55
+ start_template_locals = template_locals.merge(
56
+ attribute: start_attribute,
57
+ placeholder: start_attribute,
58
+ label: start_label
59
+ )
60
+
61
+ end_template_locals = template_locals.merge(
62
+ attribute: end_attribute,
63
+ placeholder: end_attribute,
64
+ label: end_label
65
+ )
66
+ %>
67
+
68
+ <% if single %>
69
+ <div data-controller="date-range">
70
+ <%= render 'headmin/forms/hidden', start_template_locals.merge(class: nil, data: { 'date-range-target': 'startDateInput' }) %>
71
+ <%= render 'headmin/forms/hidden', end_template_locals.merge(class: nil, data: { 'date-range-target': 'endDateInput' }) %>
72
+ <%= render 'headmin/forms/date', template_locals.merge(attribute: :date, name: nil) %>
73
+ </div>
74
+ <% else %>
75
+ <div class="row">
76
+ <div class="col">
77
+ <%= render 'headmin/forms/date', start_template_locals %>
78
+ </div>
79
+ <div class="col">
80
+ <%= render 'headmin/forms/date', end_template_locals %>
81
+ </div>
82
+ </div>
83
+ <% end %>
84
+
@@ -0,0 +1,55 @@
1
+ <%
2
+ # headmin/forms/flatpickr
3
+ #
4
+ # ==== Options
5
+ # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
6
+ # * <tt>attribute<tt> - Name of the attribute of the form model
7
+ # * <tt>class<tt> - Optional HTML class attribute
8
+ # * <tt>data<tt> - Optional HTML data attributes
9
+ # * <tt>disabled<tt> - Set to true if the input should be shown as disabled
10
+ # * <tt>float<tt> - Set to true if you want to show floating labels
11
+ # * <tt>form<tt> - Form object
12
+ # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
13
+ # * <tt>name<tt> - The name of the field
14
+ # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
15
+ # * <tt>readonly<tt> - Set to true if the value of the field can only be read and not be modified
16
+ # * <tt>required<tt> - Set to true to show a HTML5 validation message when left blank
17
+ #
18
+ # ==== Examples
19
+ # Basic version
20
+ # <%= render 'headmin/forms/flatpickr', form: form, attribute: :date %#>
21
+
22
+ append = local_assigns.has_key?(:append) ? append : nil
23
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
24
+ data = local_assigns.has_key?(:data) ? data : {}
25
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
26
+ float = local_assigns.has_key?(:float) ? float : false
27
+ label = local_assigns.has_key?(:label) ? label : nil
28
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
29
+ readonly = local_assigns.has_key?(:readonly) ? readonly : false
30
+ required = local_assigns.has_key?(:required) ? required : false
31
+
32
+ template_locals = {
33
+ form: form,
34
+ append: append,
35
+ prepend: prepend,
36
+ float: float,
37
+ label: label,
38
+ class: class_names,
39
+ disabled: disabled,
40
+ readonly: readonly,
41
+ required: required,
42
+ attribute: attribute,
43
+ data: data.merge(
44
+ 'flatpickr-target': 'input',
45
+ 'flatpickr-options': {
46
+ defaultDate: form.object&.send(attribute)&.strftime('%d/%m/%Y')
47
+ }
48
+ ),
49
+ }
50
+
51
+ %>
52
+
53
+ <div data-controller="flatpickr">
54
+ <%= render 'headmin/forms/date', template_locals %>
55
+ </div>
@@ -0,0 +1,61 @@
1
+ <%
2
+ # headmin/forms/flatpickr_range
3
+ #
4
+ # ==== Options
5
+ # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
6
+ # * <tt>class<tt> - Optional HTML class attribute
7
+ # * <tt>data<tt> - Optional HTML data attributes
8
+ # * <tt>end_attribute<tt> - Name of the end date attribute of the form model
9
+ # * <tt>float<tt> - Set to true if you want to show floating labels
10
+ # * <tt>form<tt> - Form object
11
+ # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
12
+ # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
13
+ # * <tt>readonly<tt> - Set to true if the value of the field can only be read and not be modified
14
+ # * <tt>required<tt> - Set to true to show a HTML5 validation message when left blank
15
+ # * <tt>start_attribute<tt> - Name of the start date attribute of the form model
16
+ #
17
+ # ==== Examples
18
+ # Basic version
19
+ # <%= render 'headmin/forms/flatpickr_range', form: form, start_attribute: :start_date, end_attribute: :end_date %#>
20
+
21
+ append = local_assigns.has_key?(:append) ? append : nil
22
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
23
+ data = local_assigns.has_key?(:data) ? data : {}
24
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
25
+ end_attribute = local_assigns.has_key?(:end_attribute) ? end_attribute : nil
26
+ float = local_assigns.has_key?(:float) ? float : false
27
+ label = local_assigns.has_key?(:label) ? label : nil
28
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
29
+ readonly = local_assigns.has_key?(:readonly) ? readonly : false
30
+ required = local_assigns.has_key?(:required) ? required : false
31
+ start_attribute = local_assigns.has_key?(:start_attribute) ? start_attribute : nil
32
+
33
+ start_date = form.object&.send(start_attribute)&.strftime('%d/%m/%Y')
34
+ end_date = form.object&.send(end_attribute)&.strftime('%d/%m/%Y')
35
+
36
+ template_locals = {
37
+ form: form,
38
+ append: append,
39
+ prepend: prepend,
40
+ float: float,
41
+ label: label,
42
+ class: class_names,
43
+ disabled: disabled,
44
+ readonly: readonly,
45
+ required: required,
46
+ start_attribute: start_attribute,
47
+ end_attribute: end_attribute,
48
+ data: data.merge(
49
+ 'flatpickr-target': 'input',
50
+ 'flatpickr-options': {
51
+ mode: 'range',
52
+ defaultDate: [start_date, end_date]
53
+ }
54
+ ),
55
+ single: true
56
+ }
57
+ %>
58
+
59
+ <div data-controller="flatpickr">
60
+ <%= render 'headmin/forms/date_range', template_locals %>
61
+ </div>
@@ -0,0 +1,23 @@
1
+ <%
2
+ # headmin/forms/hidden
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
6
+ # * <tt>attribute<tt> - Name of the attribute of the form model
7
+ # * <tt>data<tt> - Optional HTML data attributes
8
+ # * <tt>class<tt> - Optional HTML class attribute
9
+ #
10
+ # ==== Examples
11
+ # Basic version
12
+ # <%= render 'headmin/forms/hidden', form: form, attribute: :title %#>
13
+
14
+ data = local_assigns.has_key?(:data) ? data : nil
15
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
16
+
17
+ options = {
18
+ data: data,
19
+ class: class_names,
20
+ }
21
+ %>
22
+
23
+ <%= form.hidden_field(attribute, options) %>
@@ -12,11 +12,13 @@
12
12
  # <%= render 'headmin/forms/label', form: form, attribute: :image %#>
13
13
 
14
14
  class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
15
- custom_name = local_assigns.has_key?(:name) && name ? name.to_s.humanize : nil
15
+ custom_name = local_assigns.has_key?(:name) && name ? t("attributes.#{name}") : nil
16
16
  required = local_assigns.has_key?(:required) ? required : false
17
+ form_id = form.options.has_key?(:id) ? form.options[:id] : nil
17
18
 
18
19
  options = {
19
20
  class: "form-label #{class_names}",
21
+ form: form_id,
20
22
  required: required,
21
23
  }
22
24
  %>
@@ -2,18 +2,22 @@
2
2
  # headmin/forms/select
3
3
  #
4
4
  # ==== Options
5
- # * <tt>form<tt> - Form object
5
+ # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
6
6
  # * <tt>attribute<tt> - Name of the attribute of the form model
7
+ # * <tt>class<tt> - Optional HTML class attribute
7
8
  # * <tt>collection<tt> - Values to create option tags for
8
- # * <tt>multiple<tt> - Set to true if multiple selections are allowed
9
- # * <tt>tags<tt> - Set to true if new options are allowed to be created
9
+ # * <tt>data<tt> - Optional HTML data attributes
10
10
  # * <tt>disabled<tt> - One or more values to be disabled in the option tags
11
- # * <tt>selected<tt> - Value to be marked as "selected"
11
+ # * <tt>float<tt> - Set to true if you want to show floating labels
12
+ # * <tt>form<tt> - Form object
12
13
  # * <tt>include_blank<tt> - Set to true or prompt string if the first option tag is a blank
13
14
  # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
14
- # * <tt>float<tt> - Set to true if you want to show floating labels
15
- # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
15
+ # * <tt>multiple<tt> - Set to true if multiple selections are allowed
16
16
  # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
17
+ # * <tt>readonly<tt> - Set to true if the value of the field can only be read and not be modified
18
+ # * <tt>required<tt> - Set to true to show a HTML5 validation message when left blank
19
+ # * <tt>selected<tt> - Value to be marked as "selected"
20
+ # * <tt>tags<tt> - Set to true if new options are allowed to be created
17
21
  #
18
22
  # ==== Examples
19
23
  # Basic version
@@ -41,19 +45,17 @@
41
45
  float = local_assigns.has_key?(:float) ? float : false
42
46
  include_blank = local_assigns.has_key?(:include_blank) ? include_blank : nil
43
47
  label = local_assigns.has_key?(:label) ? label : nil
44
- prepend = local_assigns.has_key?(:prepend) ? prepend : nil
45
48
  multiple = local_assigns.has_key?(:multiple) ? multiple : false
49
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
46
50
  required = local_assigns.has_key?(:required) ? required : false
47
- selected = local_assigns.has_key?(:selected) ? selected : nil
51
+ selected = local_assigns.has_key?(:selected) ? selected : form.object&.send(attribute)
48
52
  tags = local_assigns.has_key?(:tags) ? tags : false
49
53
 
50
54
  data = data.merge({ tags: true }) if tags
51
55
 
52
- choices = options_for_select(collection, form.object.send(attribute))
56
+ choices = options_for_select(collection, selected: selected, disabled: disabled)
53
57
  options = {
54
58
  include_blank: include_blank,
55
- disabled: disabled,
56
- selected: selected
57
59
  }
58
60
  html_options = {
59
61
  'aria-describedby': form_field_validation_id(form, attribute),
@@ -61,6 +63,7 @@
61
63
  data: data,
62
64
  multiple: tags ? true : multiple,
63
65
  required: required,
66
+ disabled: disabled == true,
64
67
  }
65
68
 
66
69
  %>
@@ -42,8 +42,8 @@
42
42
  class: "form-control #{form_field_validation_class(form, attribute)} #{class_names}",
43
43
  data: data,
44
44
  disabled: disabled,
45
- list: collection ? attribute : nil,
46
- placeholder: attribute,
45
+ list: collection ? "#{attribute}_list" : nil,
46
+ placeholder: label ? label.to_s.humanize : nil,
47
47
  readonly: readonly,
48
48
  required: required,
49
49
  }
@@ -51,12 +51,10 @@
51
51
 
52
52
  <%= render 'headmin/forms/base', form: form, attribute: attribute, append: append, prepend: prepend, float: float, label: label, required: required do |form| %>
53
53
  <%= form.text_field(attribute, options) %>
54
- <% end %>
55
54
 
56
- <% if collection %>
57
- <datalist id="<%= attribute %>">
58
- <% collection.each do |key, value| %>
59
- <option value="<%= value %>"><%= key %></option>
60
- <% end %>
61
- </datalist>
55
+ <% if collection %>
56
+ <datalist id="<%= "#{attribute}_list" %>">
57
+ <%= options_for_select(collection) %>
58
+ </datalist>
59
+ <% end %>
62
60
  <% end %>