headmin 0.1.2 → 0.2.3

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 (212) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -15
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +24 -2
  5. data/README.md +15 -43
  6. data/app/controllers/concerns/headmin/authentication.rb +0 -8
  7. data/app/controllers/concerns/headmin/pagination.rb +1 -1
  8. data/app/helpers/headmin/admin_helper.rb +4 -4
  9. data/app/models/concerns/headmin/block.rb +11 -0
  10. data/app/models/concerns/headmin/blockable.rb +10 -0
  11. data/app/models/concerns/headmin/field.rb +17 -0
  12. data/app/models/concerns/headmin/fieldable.rb +44 -0
  13. data/app/services/block_service.rb +68 -0
  14. data/app/views/{layouts → examples}/admin.html.erb +0 -0
  15. data/app/views/{layouts/admin → examples}/auth.html.erb +0 -0
  16. data/app/views/headmin/_blocks.html.erb +24 -0
  17. data/app/views/headmin/_breadcrumbs.html.erb +9 -5
  18. data/app/views/headmin/_card.html.erb +48 -0
  19. data/app/views/headmin/_dropdown.html.erb +18 -0
  20. data/app/views/headmin/_filters.html.erb +56 -34
  21. data/app/views/headmin/_form.html.erb +60 -6
  22. data/app/views/headmin/_heading.html.erb +8 -4
  23. data/app/views/headmin/_index.html.erb +9 -8
  24. data/app/views/headmin/_notifications.html.erb +8 -0
  25. data/app/views/headmin/_pagination.html.erb +11 -7
  26. data/app/views/headmin/_popup.html.erb +26 -0
  27. data/app/views/headmin/_table.html.erb +11 -4
  28. data/app/views/headmin/dropdown/_button.html.erb +13 -0
  29. data/app/views/headmin/dropdown/_devise.html.erb +21 -0
  30. data/app/views/headmin/{layout/dropdown → dropdown}/_divider.html.erb +1 -1
  31. data/app/views/headmin/dropdown/_item.html.erb +18 -0
  32. data/app/views/headmin/dropdown/_list.html.erb +11 -0
  33. data/app/views/headmin/dropdown/_locale.html.erb +17 -0
  34. data/app/views/headmin/filters/_date.html.erb +21 -16
  35. data/app/views/headmin/filters/_search.html.erb +18 -18
  36. data/app/views/headmin/filters/_select.html.erb +28 -23
  37. data/app/views/headmin/filters/filter/_button.html.erb +15 -6
  38. data/app/views/headmin/filters/filter/_menu_item.html.erb +2 -2
  39. data/app/views/headmin/filters/filter/_template.html.erb +2 -2
  40. data/app/views/headmin/forms/_actions.html.erb +4 -8
  41. data/app/views/headmin/forms/_base.html.erb +60 -0
  42. data/app/views/headmin/forms/_blocks.html.erb +32 -0
  43. data/app/views/headmin/forms/_checkbox.html.erb +39 -0
  44. data/app/views/headmin/forms/_ckeditor.html.erb +42 -0
  45. data/app/views/headmin/forms/_date.html.erb +45 -0
  46. data/app/views/headmin/forms/_email.html.erb +39 -0
  47. data/app/views/headmin/forms/_file.html.erb +40 -0
  48. data/app/views/headmin/forms/_image.html.erb +55 -0
  49. data/app/views/headmin/forms/_label.html.erb +24 -0
  50. data/app/views/headmin/forms/_number.html.erb +50 -0
  51. data/app/views/headmin/forms/_password.html.erb +69 -0
  52. data/app/views/headmin/forms/_redactorx.html.erb +49 -0
  53. data/app/views/headmin/forms/_repeater.html.erb +133 -0
  54. data/app/views/headmin/forms/_select.html.erb +70 -0
  55. data/app/views/headmin/forms/_text.html.erb +62 -0
  56. data/app/views/headmin/forms/_textarea.html.erb +39 -0
  57. data/app/views/headmin/forms/_url.html.erb +39 -0
  58. data/app/views/headmin/forms/_validation.html.erb +21 -0
  59. data/app/views/headmin/forms/actions/_destroy.html.erb +13 -0
  60. data/app/views/headmin/forms/actions/_save.html.erb +12 -0
  61. data/app/views/headmin/forms/actions/_view.html.erb +15 -0
  62. data/app/views/headmin/forms/fields/_base.html.erb +25 -0
  63. data/app/views/headmin/forms/fields/_file.html.erb +15 -22
  64. data/app/views/headmin/forms/fields/_group.html.erb +38 -0
  65. data/app/views/headmin/forms/fields/_image.html.erb +15 -35
  66. data/app/views/headmin/forms/fields/_list.html.erb +26 -0
  67. data/app/views/headmin/forms/fields/_text.html.erb +15 -37
  68. data/app/views/headmin/forms/repeater/_row.html.erb +51 -0
  69. data/app/views/headmin/heading/_title.html.erb +1 -1
  70. data/app/views/headmin/layout/_body.html.erb +1 -1
  71. data/app/views/headmin/layout/_content.html.erb +1 -1
  72. data/app/views/headmin/layout/_footer.html.erb +1 -1
  73. data/app/views/headmin/layout/_header.html.erb +1 -1
  74. data/app/views/headmin/layout/_main.html.erb +2 -2
  75. data/app/views/headmin/layout/_sidebar.html.erb +1 -1
  76. data/app/views/headmin/layout/sidebar/{_menu.html.erb → _nav.html.erb} +1 -1
  77. data/app/views/headmin/nav/_item.html.erb +21 -0
  78. data/app/views/headmin/nav/item/_devise.html.erb +21 -0
  79. data/app/views/headmin/nav/item/_locale.html.erb +17 -0
  80. data/app/views/headmin/pagination/_per_page.html.erb +18 -0
  81. data/app/views/headmin/{kaminari → pagination/kaminari}/_first_page.html.erb +0 -0
  82. data/app/views/headmin/{kaminari → pagination/kaminari}/_gap.html.erb +0 -0
  83. data/app/views/headmin/{kaminari → pagination/kaminari}/_last_page.html.erb +0 -0
  84. data/app/views/headmin/{kaminari → pagination/kaminari}/_next_page.html.erb +0 -0
  85. data/app/views/headmin/{kaminari → pagination/kaminari}/_page.html.erb +1 -1
  86. data/app/views/headmin/{kaminari → pagination/kaminari}/_paginator.html.erb +0 -0
  87. data/app/views/headmin/{kaminari → pagination/kaminari}/_prev_page.html.erb +0 -0
  88. data/app/views/headmin/table/_actions.html.erb +24 -17
  89. data/app/views/headmin/table/_body.html.erb +12 -10
  90. data/app/views/headmin/table/_foot.html.erb +8 -4
  91. data/app/views/headmin/table/_footer.html.erb +3 -7
  92. data/app/views/headmin/table/_head.html.erb +3 -1
  93. data/app/views/headmin/table/_header.html.erb +3 -7
  94. data/app/views/headmin/table/actions/_action.html.erb +26 -9
  95. data/app/views/headmin/table/actions/_delete.html.erb +11 -7
  96. data/app/views/headmin/table/actions/_export.html.erb +11 -7
  97. data/app/views/headmin/table/body/_association.html.erb +1 -1
  98. data/app/views/headmin/table/body/_boolean.erb +1 -1
  99. data/app/views/headmin/table/body/_currency.html.erb +1 -1
  100. data/app/views/headmin/table/body/_date.html.erb +1 -1
  101. data/app/views/headmin/table/body/_id.html.erb +2 -2
  102. data/app/views/headmin/table/body/_row.html.erb +1 -1
  103. data/app/views/headmin/table/body/_string.html.erb +1 -1
  104. data/app/views/headmin/table/body/_text.html.erb +1 -1
  105. data/app/views/headmin/table/foot/_cell.html.erb +1 -1
  106. data/app/views/headmin/table/foot/_id.html.erb +2 -2
  107. data/app/views/headmin/table/head/_cell.html.erb +1 -1
  108. data/app/views/headmin/table/head/_id.html.erb +3 -3
  109. data/app/views/headmin/views/devise/confirmations/_new.html.erb +9 -0
  110. data/app/views/headmin/views/devise/passwords/_edit.html.erb +12 -0
  111. data/app/views/headmin/views/devise/passwords/_new.html.erb +9 -0
  112. data/app/views/{admin/users/registrations/edit.html.erb → headmin/views/devise/registrations/_edit.html.erb} +5 -5
  113. data/app/views/headmin/views/devise/registrations/_new.html.erb +11 -0
  114. data/app/views/headmin/views/devise/sessions/_new.html.erb +13 -0
  115. data/app/views/{admin/users → headmin/views/devise}/shared/_error_messages.html.erb +0 -0
  116. data/app/views/{admin/users → headmin/views/devise}/shared/_links.html.erb +0 -0
  117. data/app/views/headmin/views/devise/unlocks/_new.html.erb +10 -0
  118. data/config/initializers/customize_input_error.rb +9 -0
  119. data/config/locales/devise/en.yml +65 -0
  120. data/config/locales/en.yml +2 -134
  121. data/config/locales/headmin/filters/en.yml +13 -0
  122. data/config/locales/headmin/filters/nl.yml +13 -0
  123. data/config/locales/headmin/forms/en.yml +34 -0
  124. data/config/locales/headmin/forms/nl.yml +33 -0
  125. data/config/locales/headmin/heading/en.yml +5 -0
  126. data/config/locales/headmin/heading/nl.yml +5 -0
  127. data/config/locales/headmin/layout/en.yml +14 -0
  128. data/config/locales/headmin/layout/nl.yml +14 -0
  129. data/config/locales/headmin/pagination/en.yml +21 -0
  130. data/config/locales/headmin/pagination/nl.yml +21 -0
  131. data/config/locales/headmin/table/en.yml +23 -0
  132. data/config/locales/headmin/table/nl.yml +23 -0
  133. data/config/locales/headmin/views/en.yml +58 -0
  134. data/config/locales/headmin/views/nl.yml +58 -0
  135. data/config/locales/nl.yml +2 -135
  136. data/dist/css/headmin.css +3182 -743
  137. data/dist/js/headmin.js +729 -33
  138. data/docs/README.md +2 -1
  139. data/docs/blocks.md +70 -85
  140. data/docs/devise.md +1 -60
  141. data/docs/fields.md +57 -0
  142. data/headmin.gemspec +1 -0
  143. data/lib/generators/headmin/blocks_generator.rb +19 -0
  144. data/lib/generators/headmin/fields_generator.rb +19 -0
  145. data/lib/generators/templates/migrations/create_blocks.rb +10 -0
  146. data/lib/generators/templates/migrations/create_fields.rb +13 -0
  147. data/lib/generators/templates/models/block.rb +3 -0
  148. data/lib/generators/templates/models/field.rb +3 -0
  149. data/lib/headmin/engine.rb +2 -0
  150. data/lib/headmin/version.rb +1 -1
  151. data/package.json +6 -6
  152. data/src/js/headmin/controllers/blocks_controller.js +103 -0
  153. data/src/js/headmin/controllers/filters_controller.js +23 -12
  154. data/src/js/headmin/controllers/popup_controller.js +68 -0
  155. data/src/js/headmin/controllers/repeater_controller.js +117 -11
  156. data/src/js/headmin/controllers/table_actions_controller.js +16 -5
  157. data/src/js/headmin/controllers/table_controller.js +84 -1
  158. data/src/js/headmin/headmin.js +29 -56
  159. data/src/scss/headmin/filters.scss +0 -14
  160. data/src/scss/headmin/form.scss +43 -3
  161. data/src/scss/headmin/popup.scss +17 -0
  162. data/src/scss/headmin/table.scss +9 -6
  163. data/src/scss/headmin.scss +7 -4
  164. data/src/scss/vendor/redactorx/override.css +3 -0
  165. data/src/scss/vendor/redactorx/redactorx.css +1460 -0
  166. data/yarn.lock +105 -2210
  167. metadata +108 -62
  168. data/app/controllers/admin/users/confirmations_controller.rb +0 -31
  169. data/app/controllers/admin/users/omniauth_callbacks_controller.rb +0 -31
  170. data/app/controllers/admin/users/passwords_controller.rb +0 -35
  171. data/app/controllers/admin/users/registrations_controller.rb +0 -63
  172. data/app/controllers/admin/users/sessions_controller.rb +0 -28
  173. data/app/controllers/admin/users/unlocks_controller.rb +0 -31
  174. data/app/views/admin/users/confirmations/new.html.erb +0 -9
  175. data/app/views/admin/users/mailer/confirmation_instructions.html.erb +0 -5
  176. data/app/views/admin/users/mailer/email_changed.html.erb +0 -7
  177. data/app/views/admin/users/mailer/password_change.html.erb +0 -3
  178. data/app/views/admin/users/mailer/reset_password_instructions.html.erb +0 -8
  179. data/app/views/admin/users/mailer/unlock_instructions.html.erb +0 -7
  180. data/app/views/admin/users/passwords/edit.html.erb +0 -12
  181. data/app/views/admin/users/passwords/new.html.erb +0 -9
  182. data/app/views/admin/users/registrations/new.html.erb +0 -11
  183. data/app/views/admin/users/sessions/new.html.erb +0 -13
  184. data/app/views/admin/users/unlocks/new.html.erb +0 -10
  185. data/app/views/headmin/forms/_group.html.erb +0 -36
  186. data/app/views/headmin/forms/fields/_checkbox.html.erb +0 -23
  187. data/app/views/headmin/forms/fields/_ckeditor.html.erb +0 -28
  188. data/app/views/headmin/forms/fields/_currency.html.erb +0 -24
  189. data/app/views/headmin/forms/fields/_date.html.erb +0 -36
  190. data/app/views/headmin/forms/fields/_email.html.erb +0 -39
  191. data/app/views/headmin/forms/fields/_label.html.erb +0 -9
  192. data/app/views/headmin/forms/fields/_multiple_select.html.erb +0 -37
  193. data/app/views/headmin/forms/fields/_password.html.erb +0 -39
  194. data/app/views/headmin/forms/fields/_repeater.html.erb +0 -48
  195. data/app/views/headmin/forms/fields/_select.html.erb +0 -36
  196. data/app/views/headmin/forms/fields/_select_tags.html.erb +0 -32
  197. data/app/views/headmin/forms/fields/_textarea.html.erb +0 -29
  198. data/app/views/headmin/forms/fields/_url.html.erb +0 -38
  199. data/app/views/headmin/forms/fields/_validation.html.erb +0 -12
  200. data/app/views/headmin/forms/fields/repeater/_row.html.erb +0 -16
  201. data/app/views/headmin/layout/dropdown/_item.html.erb +0 -17
  202. data/app/views/headmin/layout/header/_account.html.erb +0 -25
  203. data/app/views/headmin/layout/header/_locale.html.erb +0 -19
  204. data/app/views/headmin/layout/sidebar/menu/_account.html.erb +0 -25
  205. data/app/views/headmin/layout/sidebar/menu/_item.html.erb +0 -16
  206. data/app/views/headmin/layout/sidebar/menu/_locale.html.erb +0 -18
  207. data/src/js/headmin/controllers/index_controller.js +0 -79
  208. data/src/js/headmin/controllers/repeater_row_controller.js +0 -54
  209. data/src/scss/vendor/choices/cross-inverse.svg +0 -6
  210. data/src/scss/vendor/choices/cross.svg +0 -6
  211. data/src/scss/vendor/choices/custom.scss +0 -28
  212. data/src/scss/vendor/choices/variables.scss +0 -16
@@ -0,0 +1,45 @@
1
+ <%
2
+ # headmin/forms/date
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
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
8
+ # * <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
10
+ # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
11
+ #
12
+ # ==== Examples
13
+ # 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 %#>
18
+
19
+ append = local_assigns.has_key?(:append) ? append : nil
20
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
21
+ data = local_assigns.has_key?(:data) ? data : nil
22
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
23
+ float = local_assigns.has_key?(:float) ? float : false
24
+ label = local_assigns.has_key?(:label) ? label : nil
25
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
26
+ readonly = local_assigns.has_key?(:readonly) ? readonly : false
27
+ 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} flatpicker" if datepicker
31
+
32
+ options = {
33
+ 'aria-describedby': form_field_validation_id(form, attribute),
34
+ class: "form-control #{form_field_validation_class(form, attribute)} #{class_names}",
35
+ data: data,
36
+ disabled: disabled,
37
+ placeholder: attribute,
38
+ readonly: readonly,
39
+ required: required,
40
+ }
41
+ %>
42
+
43
+ <%= render 'headmin/forms/base', form: form, attribute: attribute, append: append, prepend: prepend, float: float, label: label, required: required do |form| %>
44
+ <%= form.date_field(attribute, options) %>
45
+ <% end %>
@@ -0,0 +1,39 @@
1
+ <%
2
+ # headmin/forms/email
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
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
8
+ # * <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
10
+ # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
11
+ #
12
+ # ==== Examples
13
+ # Basic version
14
+ # <%= render 'headmin/forms/email', form: form, attribute: :email_address %#>
15
+
16
+ append = local_assigns.has_key?(:append) ? append : nil
17
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
18
+ data = local_assigns.has_key?(:data) ? data : nil
19
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
20
+ float = local_assigns.has_key?(:float) ? float : false
21
+ label = local_assigns.has_key?(:label) ? label : nil
22
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
23
+ readonly = local_assigns.has_key?(:readonly) ? readonly : false
24
+ required = local_assigns.has_key?(:required) ? required : false
25
+
26
+ options = {
27
+ 'aria-describedby': form_field_validation_id(form, attribute),
28
+ class: "form-control #{form_field_validation_class(form, attribute)} #{class_names}",
29
+ data: data,
30
+ disabled: disabled,
31
+ placeholder: attribute,
32
+ readonly: readonly,
33
+ required: required,
34
+ }
35
+ %>
36
+
37
+ <%= render 'headmin/forms/base', form: form, attribute: attribute, append: append, prepend: prepend, float: float, label: label, required: required do |form| %>
38
+ <%= form.email_field(attribute, options) %>
39
+ <% end %>
@@ -0,0 +1,40 @@
1
+ <%
2
+ # name: headmin/forms/file
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
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
8
+ #
9
+ # ==== Examples
10
+ # Basic version
11
+ # <%= render 'headmin/forms/image', form: form, attribute: :image %#>
12
+
13
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
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-control #{form_field_validation_class(form, attribute)} #{class_names}",
23
+ data: data,
24
+ disabled: disabled,
25
+ placeholder: attribute,
26
+ readonly: readonly,
27
+ required: required,
28
+ }
29
+
30
+ show_label = label != false
31
+ %>
32
+
33
+ <div class="<%= ('mb-3 text-start' if show_label) %>">
34
+ <% if show_label %>
35
+ <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
36
+ <% end %>
37
+
38
+ <%= form.file_field(attribute, options) %>
39
+ <%= render 'headmin/forms/validation', form: form, attribute: attribute %>
40
+ </div>
@@ -0,0 +1,55 @@
1
+ <%
2
+ # name: headmin/forms/image
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
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
8
+ #
9
+ # ==== Examples
10
+ # Basic version
11
+ # <%= render 'headmin/forms/image', form: form, attribute: :image %#>
12
+
13
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
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
+ has_image = form.object.send(attribute).attached?
21
+
22
+ options = {
23
+ 'aria-describedby': form_field_validation_id(form, attribute),
24
+ class: "form-control #{form_field_validation_class(form, attribute)} #{class_names}",
25
+ data: data,
26
+ disabled: disabled,
27
+ placeholder: attribute,
28
+ readonly: readonly,
29
+ required: has_image ? false : required,
30
+ }
31
+
32
+ show_label = label != false
33
+ %>
34
+
35
+ <div class="<%= ('mb-3 text-start' if show_label) %>">
36
+
37
+ <% if show_label %>
38
+ <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
39
+ <% end %>
40
+
41
+ <div class="mb-2">
42
+ <% if has_image %>
43
+ <%= image_tag(form.object.send(attribute).variant(resize_to_limit: [200, 200], quality: 70), class: 'img-thumbnail') %>
44
+ <% else %>
45
+ <svg class="img-thumbnail" width="200" height="200" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="A generic square placeholder image with a white border around it, making it resemble a photograph taken with an old instant camera: 200x200" preserveAspectRatio="xMidYMid slice" focusable="false">
46
+ <title>A generic square placeholder image with a white border around it, making it resemble a photograph taken with an old instant camera</title>
47
+ <rect width="100%" height="100%" fill="#e9ecef"></rect>
48
+ <text x="35%" y="50%" fill="#212529" dy=".3em">200x200</text>
49
+ </svg>
50
+ <% end %>
51
+ </div>
52
+
53
+ <%= form.file_field(attribute, options) %>
54
+ <%= render 'headmin/forms/validation', form: form, attribute: attribute %>
55
+ </div>
@@ -0,0 +1,24 @@
1
+ <%
2
+ # name: headmin/forms/label
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
6
+ # * <tt>attribute<tt> - Name of the attribute of the form model
7
+ # * <tt>name<tt> - Custom label to be used instead of the attribute
8
+ # * <tt>required<tt> - Set to true if you want to highlight the requirement
9
+ #
10
+ # ==== Examples
11
+ # Basic version
12
+ # <%= render 'headmin/forms/label', form: form, attribute: :image %#>
13
+
14
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
15
+ name = local_assigns.has_key?(:name) && name ? name.to_s.humanize : attribute
16
+ required = local_assigns.has_key?(:required) ? required : false
17
+
18
+ options = {
19
+ class: "form-label #{class_names}",
20
+ required: required,
21
+ }
22
+ %>
23
+
24
+ <%= form.label name, options %>
@@ -0,0 +1,50 @@
1
+ <%
2
+ # headmin/forms/number
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
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
8
+ # * <tt>float<tt> - Set to true if you want to show floating labels
9
+ # * <tt>collection<tt> - Add array of options to show in a data list
10
+ # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
11
+ # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
12
+ #
13
+ # ==== Examples
14
+ # Basic version
15
+ # <%= render 'headmin/forms/number', form: form, attribute: :amount %#>
16
+
17
+ append = local_assigns.has_key?(:append) ? append : nil
18
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
19
+ collection = local_assigns.has_key?(:collection) ? collection : nil
20
+ data = local_assigns.has_key?(:data) ? data : nil
21
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
22
+ float = local_assigns.has_key?(:float) ? float : false
23
+ label = local_assigns.has_key?(:label) ? label : nil
24
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
25
+ readonly = local_assigns.has_key?(:readonly) ? readonly : false
26
+ required = local_assigns.has_key?(:required) ? required : false
27
+
28
+ options = {
29
+ 'aria-describedby': form_field_validation_id(form, attribute),
30
+ class: "form-control #{form_field_validation_class(form, attribute)} #{class_names}",
31
+ data: data,
32
+ disabled: disabled,
33
+ list: collection ? attribute : nil,
34
+ placeholder: attribute,
35
+ readonly: readonly,
36
+ required: required,
37
+ }
38
+ %>
39
+
40
+ <%= render 'headmin/forms/base', form: form, attribute: attribute, append: append, prepend: prepend, float: float, label: label, required: required do |form| %>
41
+ <%= form.number_field(attribute, options) %>
42
+ <% end %>
43
+
44
+ <% if collection %>
45
+ <datalist id="<%= attribute %>">
46
+ <% collection.each do |key, value| %>
47
+ <option value="<%= value %>"><%= key %></option>
48
+ <% end %>
49
+ </datalist>
50
+ <% end %>
@@ -0,0 +1,69 @@
1
+ <%
2
+ # headmin/forms/password
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
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
8
+ # * <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
10
+ # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
11
+ #
12
+ # ==== Examples
13
+ # Basic version
14
+ # <%= render 'headmin/forms/password', form: form, attribute: :password %#>
15
+
16
+ append = local_assigns.has_key?(:append) ? append : nil
17
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
18
+ data = local_assigns.has_key?(:data) ? data : nil
19
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
20
+ float = local_assigns.has_key?(:float) ? float : false
21
+ label = local_assigns.has_key?(:label) ? label : nil
22
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
23
+ readonly = local_assigns.has_key?(:readonly) ? readonly : false
24
+ required = local_assigns.has_key?(:required) ? required : false
25
+
26
+ options = {
27
+ 'aria-describedby': form_field_validation_id(form, attribute),
28
+ class: "form-control #{form_field_validation_class(form, attribute)} #{class_names}",
29
+ data: data,
30
+ disabled: disabled,
31
+ placeholder: attribute,
32
+ readonly: readonly,
33
+ required: required,
34
+ }
35
+
36
+ show_label = label != false
37
+ %>
38
+
39
+ <div class="<%= 'form-floating' if float %> <%= ('mb-3 text-start' if show_label) %>">
40
+ <% if show_label && !float %>
41
+ <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
42
+ <% end %>
43
+
44
+ <% if float %>
45
+ <%= form.password_field(attribute, options) %>
46
+ <%= render 'headmin/forms/validation', form: form, attribute: attribute %>
47
+ <% else %>
48
+ <div class="input-group">
49
+ <% if prepend %>
50
+ <span class="input-group-text">
51
+ <%= prepend %>
52
+ </span>
53
+ <% end %>
54
+
55
+ <%= form.password_field(attribute, options) %>
56
+ <%= render 'headmin/forms/validation', form: form, attribute: attribute %>
57
+
58
+ <% if append %>
59
+ <span class="input-group-text">
60
+ <%= append %>
61
+ </span>
62
+ <% end %>
63
+ </div>
64
+ <% end %>
65
+
66
+ <% if show_label && float %>
67
+ <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
68
+ <% end %>
69
+ </div>
@@ -0,0 +1,49 @@
1
+ <%
2
+ # headmin/forms/redactorx
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
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
8
+ # * <tt>addbar<tt> - Items to show in the addbar
9
+ # * <tt>topbar<tt> - Items to show in the topbar
10
+ # * <tt>plugins<tt> - Plugin items to work with
11
+ #
12
+ # ==== Examples
13
+ # Basic version
14
+ # <%= render 'headmin/forms/textarea', form: form, attribute: :title %#>
15
+
16
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
17
+ data = local_assigns.has_key?(:data) ? data : {}
18
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
19
+ label = local_assigns.has_key?(:label) ? label : nil
20
+ readonly = local_assigns.has_key?(:readonly) ? readonly : false
21
+ required = local_assigns.has_key?(:required) ? required : false
22
+ addbar = local_assigns.has_key?(:addbar) ? addbar : ['paragraph', 'image', 'embed', 'table', 'quote', 'pre', 'line']
23
+ plugins = local_assigns.has_key?(:plugins) ? plugins : ['shortcut']
24
+ topbar = local_assigns.has_key?(:topbar) ? topbar : []
25
+
26
+ data = data.merge(
27
+ 'redactor-options': {
28
+ buttons: {
29
+ addbar: addbar,
30
+ plugins: plugins,
31
+ topbar: topbar,
32
+ }
33
+ }
34
+ )
35
+
36
+ options = {
37
+ 'aria-describedby': form_field_validation_id(form, attribute),
38
+ class: "form-control redactorx #{form_field_validation_class(form, attribute)} #{class_names}",
39
+ data: data,
40
+ disabled: disabled,
41
+ placeholder: attribute,
42
+ readonly: readonly,
43
+ required: required,
44
+ }
45
+ %>
46
+
47
+ <%= render 'headmin/forms/base', form: form, attribute: attribute, label: label, required: required do |form| %>
48
+ <%= form.text_area(attribute, options) %>
49
+ <% end %>
@@ -0,0 +1,133 @@
1
+ <%
2
+ # headmin/forms/repeater
3
+ #
4
+ # ==== Options
5
+ # * <tt>form</tt> - Form object
6
+ # * <tt>attribute</tt> - Name of the attribute of the form model
7
+ # * <tt>header</tt> - Name of the template to use as header
8
+ # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
9
+ # * <tt>templates</tt> - List of all views that can be used as a template for a new block
10
+ # * <tt>flush</tt> - Set to true if you want the list items to sit flush with its parent.
11
+ #
12
+ # ==== Examples
13
+ # # Basic version
14
+ # <% render 'headmin/forms/repeater', form: form, attribute: :questions do |question| %#>
15
+ # <% render 'admin/questions/fields, form: :question' %#>
16
+ # <% end %#>
17
+ #
18
+ # # Let list group sit flush within its container
19
+ # <% render 'headmin/forms/repeater', form: form, attribute: :questions, flush: true do |question| %#>
20
+ # <% render 'admin/questions/fields, form: :question' %#>
21
+ # <% end %#>
22
+ #
23
+ # # With fixed header row. A header row can be used to show the labels, so you can omit them in the repeated fields
24
+ # <% render 'headmin/forms/repeater', form: form, attribute: :questions, header: 'admin/questions/header' do |question| %#>
25
+ # <% render 'admin/questions/fields, form: :question' %#>
26
+ # <% end %#>
27
+ #
28
+ # # Allow more than one type of fields to be inserted. You must specify the templates as an array of view paths
29
+ # <% templates = ['admin/questions/fields/_type_1.html.erb', 'admin/questions/fields/_type_2.html.erb'] %#>
30
+ # <% render 'headmin/forms/repeater', form: form, attribute: :questions, templates: templates do |question| %#>
31
+ # <% render 'admin/questions/fields, form: :question' %#>
32
+ # <% end %#>
33
+
34
+ label = local_assigns.has_key?(:label) ? label : nil
35
+ required = local_assigns.has_key?(:required) ? required : false
36
+ header = local_assigns.has_key?(:header) ? header : nil
37
+ templates = local_assigns.has_key?(:templates) ? templates : []
38
+ flush = local_assigns.has_key?(:flush) ? flush : true
39
+
40
+ template_names = templates.map { |template| File.basename(template, '.html.erb') }
41
+ template_names = template_names.any? ? template_names : ['new']
42
+ multiple_templates = template_names.count > 1
43
+ object_model = form.object.class
44
+ association_model = object_model.reflect_on_association(attribute).class_name.constantize
45
+ with_positions = association_model.new.attributes.keys.include?('position')
46
+ associations = form.object.send(attribute)
47
+ associations = with_positions ? associations.order(:position) : associations
48
+ repeater_id = form.object_id
49
+ pass_thru = multiple_templates ? nil : '[data-template-name="new"]'
50
+ show_label = label != false
51
+ %>
52
+
53
+ <div class="repeater" data-controller="repeater" data-repeater-id-value="<%= repeater_id %>">
54
+
55
+ <!-- Label -->
56
+ <% if show_label %>
57
+ <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
58
+ <% end %>
59
+
60
+ <ul class="list-group <%= 'list-group-flush' if flush %>" data-repeater-target="list">
61
+
62
+ <!-- Header -->
63
+ <% if header %>
64
+ <li class="list-group-item">
65
+ <%= render header %>
66
+ </li>
67
+ <% end %>
68
+
69
+ <!-- Rows -->
70
+ <%= form.fields_for attribute, associations do |ff| %>
71
+ <%= render 'headmin/forms/repeater/row', pass_thru: pass_thru, form: ff, repeater_id: repeater_id do %>
72
+ <%= yield(ff) %>
73
+ <% end %>
74
+ <% end %>
75
+
76
+ <!-- Footer -->
77
+ <li class="list-group-item d-flex justify-content-between align-items-center" data-repeater-target="footer">
78
+
79
+ <!-- Empty notice -->
80
+ <div class="text-secondary invisible" data-repeater-target="empty">
81
+ <%= t('.empty') %>
82
+ </div>
83
+
84
+ <!-- Button -->
85
+ <a href="#"
86
+ class="btn btn-sm h-btn-outline-light"
87
+ data-repeater-target="addButton"
88
+ data-popup-target="button"
89
+ data-popup-id="<%= "repeater-buttons-#{repeater_id}" %>"
90
+ data-popup-pass-thru="<%= pass_thru %>"
91
+ data-action="click->repeater#resetButtonIndices click->popup#open"
92
+ >
93
+ <%= bootstrap_icon('plus') %>
94
+ <%= t('.add', name: association_model.model_name.human) %>
95
+ </a>
96
+
97
+ <!-- Popup -->
98
+ <%= render 'headmin/popup', id: "repeater-buttons-#{repeater_id}" do %>
99
+ <div class="d-grid gap-2">
100
+ <% template_names.each do |name| %>
101
+ <a href="#"
102
+ class="btn btn-sm h-btn-outline-light"
103
+ data-popup-target="button"
104
+ data-popup-id="<%= "repeater-buttons-#{repeater_id}" %>"
105
+ data-action="click->repeater#addRow click->popup#close"
106
+ data-row-index=""
107
+ data-template-name="<%= name %>"
108
+ >
109
+ <%= name.humanize %>
110
+ </a>
111
+ <% end %>
112
+ </div>
113
+ <% end %>
114
+ </li>
115
+
116
+ <!-- Templates -->
117
+ <% template_names.each do |name| %>
118
+ <template data-repeater-target="template" data-template-name="<%= name %>">
119
+ <%= form.fields_for attribute, association_model.new, child_index: 'template_id' do |ff| %>
120
+ <%= render 'headmin/forms/repeater/row', form: ff, pass_thru: pass_thru, repeater_id: repeater_id do %>
121
+ <% template = templates.detect { |t| t.include?("/#{name}.") } %>
122
+ <% if template %>
123
+ <%= render(template.gsub('/_', '/'), form: ff) %>
124
+ <% else %>
125
+ <% yield(ff) %>
126
+ <% end %>
127
+ <% end %>
128
+ <% end %>
129
+ </template>
130
+ <% end %>
131
+
132
+ </ul>
133
+ </div>
@@ -0,0 +1,70 @@
1
+ <%
2
+ # headmin/forms/select
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
6
+ # * <tt>attribute<tt> - Name of the attribute of the form model
7
+ # * <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
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"
12
+ # * <tt>include_blank<tt> - Set to true or prompt string if the first option tag is a blank
13
+ # * <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
16
+ # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
17
+ #
18
+ # ==== Examples
19
+ # Basic version
20
+ # <%= render 'headmin/forms/select', form: form, attribute: :color, collection: ['red', 'green', 'blue'] %#>
21
+ #
22
+ # Specify options to be disabled
23
+ # <%= render 'headmin/forms/select', form: form, attribute: :color, collection: ['red', 'green', 'blue'], disabled: ['red'] %#>
24
+ #
25
+ # Show blank option
26
+ # <%= render 'headmin/forms/select', form: form, attribute: :color, collection: ['red', 'green', 'blue'], include_blank: 'Pick a color' %#>
27
+ #
28
+ # Select a given option by default
29
+ # <%= render 'headmin/forms/select', form: form, attribute: :color, collection: ['red', 'green', 'blue'], selected: 'green' %#>
30
+ #
31
+ # Allow multiple options to be selected
32
+ # <%= render 'headmin/forms/select', form: form, attribute: :color, collection: ['red', 'green', 'blue'], multiple: true %#>
33
+ #
34
+ # Allow multiple options to be selected and new options to be created
35
+ # <%= render 'headmin/forms/select', form: form, attribute: :color, collection: ['red', 'green', 'blue'], tags: true %#>
36
+
37
+ append = local_assigns.has_key?(:append) ? append : nil
38
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
39
+ data = local_assigns.has_key?(:data) ? data : {}
40
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
41
+ float = local_assigns.has_key?(:float) ? float : false
42
+ include_blank = local_assigns.has_key?(:include_blank) ? include_blank : nil
43
+ label = local_assigns.has_key?(:label) ? label : nil
44
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
45
+ multiple = local_assigns.has_key?(:multiple) ? multiple : false
46
+ required = local_assigns.has_key?(:required) ? required : false
47
+ selected = local_assigns.has_key?(:selected) ? selected : nil
48
+ tags = local_assigns.has_key?(:tags) ? tags : false
49
+
50
+ data = data.merge({ tags: true }) if tags
51
+
52
+ choices = options_for_select(collection, form.object.send(attribute))
53
+ options = {
54
+ include_blank: include_blank,
55
+ disabled: disabled,
56
+ selected: selected
57
+ }
58
+ html_options = {
59
+ 'aria-describedby': form_field_validation_id(form, attribute),
60
+ class: "form-select #{form_field_validation_class(form, attribute)} #{class_names}",
61
+ data: data,
62
+ multiple: tags ? true : multiple,
63
+ required: required,
64
+ }
65
+
66
+ %>
67
+
68
+ <%= render 'headmin/forms/base', form: form, attribute: attribute, append: append, prepend: prepend, float: float, label: label, required: required do |form| %>
69
+ <%= form.select(attribute, choices, options, html_options) %>
70
+ <% end %>
@@ -0,0 +1,62 @@
1
+ <%
2
+ # headmin/forms/text
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
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
8
+ # * <tt>float<tt> - Set to true if you want to show floating labels
9
+ # * <tt>collection<tt> - Add array of options to show in a data list
10
+ # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
11
+ # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
12
+ #
13
+ # ==== Examples
14
+ # Basic version
15
+ # <%= render 'headmin/forms/text', form: form, attribute: :title %#>
16
+ #
17
+ # Input without label
18
+ # <%= render 'headmin/forms/text', form: form, attribute: :title, label: false %#>
19
+ #
20
+ # Input with custom label
21
+ # <%= render 'headmin/forms/text', form: form, attribute: :title, label: 'Intro' %#>
22
+ #
23
+ # Input with floating label
24
+ # <%= render 'headmin/forms/text', form: form, attribute: :title, float: true %#>
25
+ #
26
+ # Provide a data-list
27
+ # <%= render 'headmin/forms/text', form: form, attribute: :title, collection: ['option 1', 'option 2', 'options 3'] %#>
28
+
29
+ append = local_assigns.has_key?(:append) ? append : nil
30
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
31
+ collection = local_assigns.has_key?(:collection) ? collection : nil
32
+ data = local_assigns.has_key?(:data) ? data : nil
33
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
34
+ float = local_assigns.has_key?(:float) ? float : false
35
+ label = local_assigns.has_key?(:label) ? label : nil
36
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
37
+ readonly = local_assigns.has_key?(:readonly) ? readonly : false
38
+ required = local_assigns.has_key?(:required) ? required : false
39
+
40
+ options = {
41
+ 'aria-describedby': form_field_validation_id(form, attribute),
42
+ class: "form-control #{form_field_validation_class(form, attribute)} #{class_names}",
43
+ data: data,
44
+ disabled: disabled,
45
+ list: collection ? attribute : nil,
46
+ placeholder: attribute,
47
+ readonly: readonly,
48
+ required: required,
49
+ }
50
+ %>
51
+
52
+ <%= render 'headmin/forms/base', form: form, attribute: attribute, append: append, prepend: prepend, float: float, label: label, required: required do |form| %>
53
+ <%= form.text_field(attribute, options) %>
54
+ <% end %>
55
+
56
+ <% if collection %>
57
+ <datalist id="<%= attribute %>">
58
+ <% collection.each do |key, value| %>
59
+ <option value="<%= value %>"><%= key %></option>
60
+ <% end %>
61
+ </datalist>
62
+ <% end %>