headmin 0.2.7 → 0.2.9
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/Gemfile.lock +1 -1
- data/app/views/examples/admin.html.erb +1 -1
- data/app/views/headmin/_card.html.erb +3 -1
- data/app/views/headmin/_filters.html.erb +2 -2
- data/app/views/headmin/_pagination.html.erb +2 -4
- data/app/views/headmin/_table.html.erb +9 -3
- data/app/views/headmin/filters/_date.html.erb +5 -3
- data/app/views/headmin/filters/_flatpickr.html.erb +57 -0
- data/app/views/headmin/forms/_base.html.erb +12 -11
- data/app/views/headmin/forms/_blocks.html.erb +1 -1
- data/app/views/headmin/forms/_date.html.erb +24 -12
- data/app/views/headmin/forms/_date_range.html.erb +84 -0
- data/app/views/headmin/forms/_flatpickr.html.erb +55 -0
- data/app/views/headmin/forms/_flatpickr_range.html.erb +61 -0
- data/app/views/headmin/forms/_hidden.html.erb +23 -0
- data/app/views/headmin/forms/_label.html.erb +3 -1
- data/app/views/headmin/forms/_select.html.erb +14 -11
- data/app/views/headmin/forms/_text.html.erb +7 -9
- data/app/views/headmin/layout/_main.html.erb +11 -5
- data/app/views/headmin/table/_actions.html.erb +1 -3
- data/app/views/headmin/table/body/_row.html.erb +14 -6
- data/dist/css/headmin.css +4 -1
- data/dist/js/headmin.js +40 -5
- data/lib/headmin/version.rb +1 -1
- data/src/js/headmin/controllers/date_range_controller.js +34 -0
- data/src/js/headmin/controllers/flatpickr_controller.js +38 -0
- data/src/js/headmin/controllers/repeater_controller.js +0 -1
- data/src/js/headmin/controllers/table_actions_controller.js +7 -37
- data/src/js/headmin/controllers/table_controller.js +23 -3
- data/src/js/headmin/headmin.js +36 -19
- data/src/scss/headmin/form.scss +4 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f00655cf10c9398fe82786cf51138112cc74641ed1c667be3145fa69e106bd9
|
4
|
+
data.tar.gz: 3935a1edcd31415561f2e0f0427ba4b34d4202af0fd6542ba50ceee8f6e51173
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 568b793e037b802ce4ead966b9bb317d3bfbcdae7e1611586fd0d98c5af5a65441d4bab62e63b59f5677f501a680f008e085b0120edfa1a302109f4810b8fec2
|
7
|
+
data.tar.gz: ed5cf371109df5c8874b334154d1a34e1a6d9e6e526e94a849b17f10bb034789de106de3ba09a905dde88bfb34632ac7291c03549987507ef60e8de3db13e617
|
data/Gemfile.lock
CHANGED
@@ -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
|
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
|
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> -
|
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"
|
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
|
17
|
+
class: "form-control",
|
18
18
|
required: true,
|
19
|
-
|
20
|
-
|
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>
|
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>
|
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
|
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 %>
|
@@ -29,7 +29,7 @@
|
|
29
29
|
<%= block_form.hidden_field :name, value: name %>
|
30
30
|
|
31
31
|
<!-- Render block form fields -->
|
32
|
-
<% view_path = BlockService.form_view(name, path: path).gsub('/_', '/') %>
|
32
|
+
<% view_path = BlockService.form_view(name, path: path).gsub('/_', '/').split('.').first %>
|
33
33
|
<%= render view_path, form: block_form %>
|
34
34
|
|
35
35
|
<!-- Label -->
|
@@ -2,19 +2,22 @@
|
|
2
2
|
# headmin/forms/date
|
3
3
|
#
|
4
4
|
# ==== Options
|
5
|
-
# * <tt>
|
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>
|
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>
|
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: :
|
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:
|
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',
|
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
|
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>
|
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>
|
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>
|
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>
|
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 :
|
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,
|
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:
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
</datalist>
|
55
|
+
<% if collection %>
|
56
|
+
<datalist id="<%= "#{attribute}_list" %>">
|
57
|
+
<%= options_for_select(collection) %>
|
58
|
+
</datalist>
|
59
|
+
<% end %>
|
62
60
|
<% end %>
|