para 0.11.4 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/para/admin/main.scss +31 -0
  3. data/app/assets/stylesheets/para/admin/src/_affix.scss +7 -0
  4. data/app/assets/stylesheets/para/admin/src/_alert.scss +35 -0
  5. data/app/assets/stylesheets/para/admin/src/_base.scss +63 -0
  6. data/app/assets/stylesheets/para/admin/src/_bootstrap-variables.scss +766 -379
  7. data/app/assets/stylesheets/para/admin/src/_breadcrumb.scss +37 -0
  8. data/app/assets/stylesheets/para/admin/src/_buttons.scss +128 -0
  9. data/app/assets/stylesheets/para/admin/src/_checkable.scss +106 -0
  10. data/app/assets/stylesheets/para/admin/src/_common.scss +250 -0
  11. data/app/assets/stylesheets/para/admin/src/_dropdown.scss +52 -0
  12. data/app/assets/stylesheets/para/admin/src/_form.scss +359 -0
  13. data/app/assets/stylesheets/para/admin/src/_list.scss +96 -0
  14. data/app/assets/stylesheets/para/admin/src/_mixins.scss +109 -0
  15. data/app/assets/stylesheets/para/admin/src/_multi-select.scss +110 -0
  16. data/app/assets/stylesheets/para/admin/src/_navigation.scss +210 -0
  17. data/app/assets/stylesheets/para/admin/src/_navtabs.scss +68 -0
  18. data/app/assets/stylesheets/para/admin/src/_nested-many.scss +87 -0
  19. data/app/assets/stylesheets/para/admin/src/_nested_one.scss +26 -0
  20. data/app/assets/stylesheets/para/admin/src/_orderable.scss +48 -0
  21. data/app/assets/stylesheets/para/admin/src/_page-loading.scss +40 -0
  22. data/app/assets/stylesheets/para/admin/src/_pagination.scss +39 -0
  23. data/app/assets/stylesheets/para/admin/src/_panel.scss +61 -0
  24. data/app/assets/stylesheets/para/admin/src/_responsive.scss +133 -0
  25. data/app/assets/stylesheets/para/admin/src/_sorting.scss +43 -0
  26. data/app/assets/stylesheets/para/admin/src/_statcard.scss +46 -0
  27. data/app/assets/stylesheets/para/admin/src/_table.scss +36 -0
  28. data/app/assets/stylesheets/para/admin/src/_tree.scss +60 -0
  29. data/app/assets/stylesheets/para/admin/src/{_variables.sass → _variables.scss} +7 -7
  30. data/app/assets/stylesheets/para/admin/src/{_well.sass → _well.scss} +5 -4
  31. data/app/assets/stylesheets/para/admin.scss +15 -0
  32. data/app/assets/stylesheets/para/index.scss +1 -0
  33. data/app/assets/stylesheets/para/lib/datetimepicker.scss +15 -0
  34. data/app/assets/stylesheets/para/lib/fuelux.scss +46 -0
  35. data/app/assets/stylesheets/para/lib/jasny-bootstrap.scss +100 -0
  36. data/app/assets/stylesheets/para/lib/selectize.scss +129 -0
  37. data/app/assets/stylesheets/para/lib/slider.scss +14 -0
  38. data/app/controllers/para/admin/crud_resources_controller.rb +16 -9
  39. data/app/controllers/para/admin/imports_controller.rb +9 -9
  40. data/app/controllers/para/admin/jobs_controller.rb +7 -1
  41. data/app/controllers/para/admin/resources_controller.rb +17 -18
  42. data/app/controllers/para/admin/settings_component_controller.rb +2 -2
  43. data/app/helpers/para/admin/base_helper.rb +36 -25
  44. data/app/helpers/para/admin/page_helper.rb +8 -9
  45. data/app/helpers/para/flash_helper.rb +7 -28
  46. data/app/helpers/para/model_helper.rb +5 -8
  47. data/app/helpers/para/tree_helper.rb +4 -4
  48. data/app/javascripts/para/admin/async-progress.js +58 -0
  49. data/app/javascripts/para/admin/filters-form.js +12 -0
  50. data/app/javascripts/para/admin/job-tracker.js +33 -0
  51. data/app/javascripts/para/admin/table.js +58 -0
  52. data/app/javascripts/para/admin/tabs.js +110 -0
  53. data/app/javascripts/para/admin/theme_actions.js +39 -0
  54. data/app/javascripts/para/admin/tree.js +124 -0
  55. data/app/javascripts/para/application.js +2 -0
  56. data/app/javascripts/para/controllers/application.js +17 -0
  57. data/app/javascripts/para/controllers/index.js +10 -0
  58. data/app/javascripts/para/controllers/para_admin_flash_message_controller.js +48 -0
  59. data/app/javascripts/para/controllers/para_admin_modal_controller.js +43 -0
  60. data/app/javascripts/para/controllers/selectize_field_controller.js +142 -0
  61. data/app/javascripts/para/index.js +31 -0
  62. data/app/javascripts/para/inputs/material-input.js +7 -0
  63. data/app/javascripts/para/inputs/multi-select-input.js +343 -0
  64. data/app/javascripts/para/inputs/nested_many.js +151 -0
  65. data/app/javascripts/para/lib/fetch.js +41 -0
  66. data/app/javascripts/para/lib/page-loading.js +42 -0
  67. data/app/javascripts/para/simple_form_extension/colorpicker.js +30 -0
  68. data/app/javascripts/para/simple_form_extension/datetimepicker.js +115 -0
  69. data/app/javascripts/para/simple_form_extension/fileinput.js +57 -0
  70. data/app/javascripts/para/simple_form_extension/index.js +12 -0
  71. data/app/javascripts/para/simple_form_extension/selectize.js +160 -0
  72. data/app/javascripts/para/simple_form_extension/simple_form_extension_initialization.js +62 -0
  73. data/app/javascripts/para/simple_form_extension/slider.js +43 -0
  74. data/app/javascripts/para/simple_form_extension/spinbox.js +35 -0
  75. data/app/javascripts/para/vendor/bootstrap-colorpicker.js +1025 -0
  76. data/app/javascripts/para/vendor/bootstrap-slider.js +1610 -0
  77. data/app/javascripts/para/vendor/cocoon.js +150 -0
  78. data/app/javascripts/para/vendor/jquery.datetimepicker.js +2156 -0
  79. data/app/javascripts/para/vendor/jquery.js +3 -0
  80. data/app/javascripts/para/vendor/spinbox.js +438 -0
  81. data/app/javascripts/para/vendor/vertebra.js +224 -0
  82. data/app/views/admin/para/exporter/bases/_completed.html.haml +1 -1
  83. data/app/views/layouts/para/admin.html.haml +4 -2
  84. data/app/views/para/admin/imports/new.html.haml +12 -11
  85. data/app/views/para/admin/jobs/_completed.html.haml +1 -1
  86. data/app/views/para/admin/jobs/_failed.html.haml +1 -1
  87. data/app/views/para/admin/jobs/_job.html.haml +11 -0
  88. data/app/views/para/admin/jobs/show.html.haml +1 -10
  89. data/app/views/para/admin/resources/_add_button.html.haml +1 -1
  90. data/app/views/para/admin/resources/_exports_menu.html.haml +2 -2
  91. data/app/views/para/admin/resources/_filters.html.haml +1 -1
  92. data/app/views/para/admin/resources/_imports_menu.html.haml +2 -2
  93. data/app/views/para/admin/resources/_list.html.haml +27 -26
  94. data/app/views/para/admin/resources/_navigation.html.haml +10 -11
  95. data/app/views/para/admin/resources/_subclassable_add_button.html.haml +1 -1
  96. data/app/views/para/admin/shared/_flash.html.haml +18 -0
  97. data/app/views/para/admin/shared/_header.html.haml +1 -1
  98. data/app/views/para/form/_tabs.html.haml +1 -1
  99. data/app/views/para/inputs/_nested_many.html.haml +3 -3
  100. data/app/views/para/inputs/nested_many/_add.html.haml +1 -1
  101. data/app/views/para/inputs/nested_many/_add_with_subclasses.html.haml +2 -2
  102. data/app/views/para/inputs/nested_many/_container.html.haml +1 -1
  103. data/config/locales/fr.yml +1 -0
  104. data/lib/generators/para/install/install_generator.rb +10 -14
  105. data/lib/para/attribute_field/base.rb +3 -0
  106. data/lib/para/attribute_field/wysiwyg_editor.rb +15 -0
  107. data/lib/para/attribute_field.rb +1 -1
  108. data/lib/para/components_configuration.rb +1 -1
  109. data/lib/para/engine.rb +20 -22
  110. data/lib/para/ext/turbo_stream.rb +13 -0
  111. data/lib/para/ext.rb +1 -1
  112. data/lib/para/form_builder/containers.rb +33 -22
  113. data/lib/para/form_builder/nested_form.rb +6 -5
  114. data/lib/para/inputs/nested_many_input.rb +5 -0
  115. data/lib/para/markup/modal.rb +30 -15
  116. data/lib/para/markup/resources_buttons.rb +15 -11
  117. data/lib/para/model_field_parsers/wysiwyg_editor.rb +19 -0
  118. data/lib/para/model_field_parsers.rb +1 -1
  119. data/lib/para/version.rb +1 -1
  120. data/lib/para.rb +2 -8
  121. data/lib/simple_form_extension/components/icons.rb +13 -0
  122. data/lib/simple_form_extension/components/popovers.rb +46 -0
  123. data/lib/simple_form_extension/components.rb +8 -0
  124. data/lib/simple_form_extension/ext/form_builder.rb +20 -0
  125. data/lib/simple_form_extension/file_concern.rb +74 -0
  126. data/lib/simple_form_extension/inputs/boolean_input.rb +16 -0
  127. data/lib/simple_form_extension/inputs/collection_check_boxes_input.rb +15 -0
  128. data/lib/simple_form_extension/inputs/collection_radio_buttons_input.rb +15 -0
  129. data/lib/simple_form_extension/inputs/color_input.rb +37 -0
  130. data/lib/simple_form_extension/inputs/date_time_input.rb +48 -0
  131. data/lib/simple_form_extension/inputs/file_input.rb +41 -0
  132. data/lib/simple_form_extension/inputs/image_input.rb +110 -0
  133. data/lib/simple_form_extension/inputs/numeric_input.rb +27 -0
  134. data/lib/simple_form_extension/inputs/selectize_input.rb +210 -0
  135. data/lib/simple_form_extension/inputs/slider_input.rb +30 -0
  136. data/lib/simple_form_extension/inputs.rb +16 -0
  137. data/lib/simple_form_extension/railtie.rb +21 -0
  138. data/lib/simple_form_extension/resource_name_helper.rb +9 -0
  139. data/lib/simple_form_extension/translations.rb +7 -0
  140. data/lib/simple_form_extension/version.rb +3 -0
  141. data/lib/simple_form_extension.rb +30 -0
  142. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/alpha-horizontal.png +0 -0
  143. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/alpha.png +0 -0
  144. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/hue-horizontal.png +0 -0
  145. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/hue.png +0 -0
  146. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/saturation.png +0 -0
  147. data/vendor/assets/stylesheets/bootstrap-colorpicker.scss +227 -0
  148. data/vendor/assets/stylesheets/bootstrap-slider.scss +246 -0
  149. data/vendor/assets/stylesheets/bootstrap.scss +6032 -0
  150. data/vendor/assets/stylesheets/jquery.datetimepicker.scss +568 -0
  151. metadata +120 -188
  152. data/app/assets/javascripts/admin/app.coffee +0 -1
  153. data/app/assets/javascripts/para/admin/async-progress.coffee +0 -29
  154. data/app/assets/javascripts/para/admin/filters-form.coffee +0 -11
  155. data/app/assets/javascripts/para/admin/job-tracker.coffee +0 -39
  156. data/app/assets/javascripts/para/admin/table.coffee +0 -44
  157. data/app/assets/javascripts/para/admin/tabs.coffee +0 -63
  158. data/app/assets/javascripts/para/admin/theme_actions.coffee +0 -25
  159. data/app/assets/javascripts/para/admin/tree.coffee +0 -105
  160. data/app/assets/javascripts/para/admin.coffee +0 -22
  161. data/app/assets/javascripts/para/application.js +0 -13
  162. data/app/assets/javascripts/para/inputs/material-input.coffee +0 -4
  163. data/app/assets/javascripts/para/inputs/multi-select-input.coffee +0 -174
  164. data/app/assets/javascripts/para/inputs/nested_many.coffee +0 -108
  165. data/app/assets/javascripts/para/lib/ajax.coffee +0 -11
  166. data/app/assets/javascripts/para/lib/remote-file-forms.coffee +0 -59
  167. data/app/assets/javascripts/para/lib/turbolinks-forms.coffee +0 -23
  168. data/app/assets/javascripts/para/lib/turbolinks-loading.coffee +0 -25
  169. data/app/assets/javascripts/para/lib/turbolinks-reloader.coffee +0 -19
  170. data/app/assets/stylesheets/para/admin/main.sass +0 -33
  171. data/app/assets/stylesheets/para/admin/src/_affix.sass +0 -4
  172. data/app/assets/stylesheets/para/admin/src/_alert.sass +0 -17
  173. data/app/assets/stylesheets/para/admin/src/_base.sass +0 -54
  174. data/app/assets/stylesheets/para/admin/src/_breadcrumb.sass +0 -32
  175. data/app/assets/stylesheets/para/admin/src/_buttons.sass +0 -107
  176. data/app/assets/stylesheets/para/admin/src/_checkable.sass +0 -94
  177. data/app/assets/stylesheets/para/admin/src/_common.sass +0 -202
  178. data/app/assets/stylesheets/para/admin/src/_dropdown.sass +0 -40
  179. data/app/assets/stylesheets/para/admin/src/_form.sass +0 -299
  180. data/app/assets/stylesheets/para/admin/src/_list.sass +0 -89
  181. data/app/assets/stylesheets/para/admin/src/_mixins.sass +0 -113
  182. data/app/assets/stylesheets/para/admin/src/_multi-select.sass +0 -91
  183. data/app/assets/stylesheets/para/admin/src/_navigation.sass +0 -171
  184. data/app/assets/stylesheets/para/admin/src/_navtabs.sass +0 -58
  185. data/app/assets/stylesheets/para/admin/src/_nested-many.sass +0 -75
  186. data/app/assets/stylesheets/para/admin/src/_nested_one.sass +0 -22
  187. data/app/assets/stylesheets/para/admin/src/_orderable.sass +0 -44
  188. data/app/assets/stylesheets/para/admin/src/_page-loading.sass +0 -39
  189. data/app/assets/stylesheets/para/admin/src/_pagination.sass +0 -34
  190. data/app/assets/stylesheets/para/admin/src/_panel.sass +0 -55
  191. data/app/assets/stylesheets/para/admin/src/_responsive.sass +0 -117
  192. data/app/assets/stylesheets/para/admin/src/_sorting.sass +0 -36
  193. data/app/assets/stylesheets/para/admin/src/_statcard.sass +0 -41
  194. data/app/assets/stylesheets/para/admin/src/_table.sass +0 -33
  195. data/app/assets/stylesheets/para/admin/src/_tree.sass +0 -52
  196. data/app/assets/stylesheets/para/admin.sass +0 -12
  197. data/app/assets/stylesheets/para/lib/compass/_support.scss +0 -447
  198. data/app/assets/stylesheets/para/lib/compass/css3/_box-shadow.scss +0 -88
  199. data/app/assets/stylesheets/para/lib/compass/css3/_images.scss +0 -152
  200. data/app/assets/stylesheets/para/lib/compass/css3/_inline-block.scss +0 -31
  201. data/app/assets/stylesheets/para/lib/compass/css3/_text-shadow.scss +0 -82
  202. data/app/assets/stylesheets/para/lib/compass/css3/_transform.scss +0 -590
  203. data/app/assets/stylesheets/para/lib/compass/css3/_transition.scss +0 -190
  204. data/app/assets/stylesheets/para/lib/compass/css3/_user-interface.scss +0 -71
  205. data/app/assets/stylesheets/para/lib/compass/utilities/general/_hacks.scss +0 -65
  206. data/app/assets/stylesheets/para/lib/datetimepicker.sass +0 -15
  207. data/app/assets/stylesheets/para/lib/fuelux.sass +0 -40
  208. data/app/assets/stylesheets/para/lib/jasny-bootstrap.sass +0 -97
  209. data/app/assets/stylesheets/para/lib/redactor.sass +0 -86
  210. data/app/assets/stylesheets/para/lib/selectize.sass +0 -111
  211. data/app/assets/stylesheets/para/lib/slider.sass +0 -12
  212. data/app/assets/stylesheets/para/plugins-includes.sass.erb +0 -1
  213. data/lib/para/attribute_field/redactor.rb +0 -22
  214. data/lib/para/ext/request_iframe_xhr.rb +0 -17
  215. data/lib/para/iframe_transport/middleware.rb +0 -58
  216. data/lib/para/iframe_transport.rb +0 -7
  217. data/lib/para/model_field_parsers/redactor.rb +0 -19
  218. data/vendor/assets/javascripts/jquery.iframe-transport.js +0 -260
  219. data/vendor/assets/javascripts/jquery.remote-modal-form.coffee +0 -145
  220. /data/app/assets/stylesheets/admin/{app.sass → app.scss} +0 -0
  221. /data/app/{assets/javascripts → javascripts}/para/plugins-includes.js.erb +0 -0
  222. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/Sortable.js +0 -0
  223. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/jasny-bootstrap.js +0 -0
  224. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/jquery.scrollto.js +0 -0
  225. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/jquery.sortable.js +0 -0
  226. /data/vendor/assets/stylesheets/{animate.css → animate.scss} +0 -0
  227. /data/vendor/assets/stylesheets/{hint.css → hint.scss} +0 -0
  228. /data/vendor/assets/stylesheets/{jasny-bootstrap.css → jasny-bootstrap.scss} +0 -0
@@ -0,0 +1,110 @@
1
+ module SimpleFormExtension
2
+ module Inputs
3
+ class ImageInput < SimpleForm::Inputs::Base
4
+ include SimpleFormExtension::Translations
5
+ include SimpleFormExtension::FileConcern
6
+
7
+ delegate :content_tag, :image_tag, to: :template
8
+
9
+ def input(_wrapper_options = nil)
10
+ input_html_options[:class] << 'image-upload'
11
+ input_html_options[:accept] ||= SimpleFormExtension.default_image_input_accept
12
+
13
+ input_markup
14
+ end
15
+
16
+ private
17
+
18
+ def input_markup
19
+ content_tag(:div, class: 'fileinput fileinput-new', data: { provides: 'fileinput' }) do
20
+ content_tag(:div) do
21
+ content_tag(:div, class: 'btn btn-default btn-file') do
22
+ content_tag(:div, _translate('image.select'), class: 'fileinput-new') +
23
+ content_tag(:div, _translate('image.change'), class: 'fileinput-exists') +
24
+ @builder.file_field(attribute_name, input_html_options)
25
+ end +
26
+ content_tag(:button, class: 'btn btn-danger fileinput-exists', type: 'button',
27
+ data: { dismiss: 'fileinput' }) do
28
+ content_tag(:i, '', class: 'fa fa-times')
29
+ end
30
+ end +
31
+ existing_image_tag
32
+ end
33
+ end
34
+
35
+ def existing_image_tag
36
+ # If an existing paperclip image is found
37
+ if file_exists?
38
+ file_preview_and_remove_button
39
+ else
40
+ content_tag(:div, class: 'fileinput-preview thumbnail') do
41
+ content_tag(:div, '', class: 'empty-thumbnail')
42
+ end
43
+ end
44
+ end
45
+
46
+ def image
47
+ @image ||= object.try(attribute_name)
48
+ end
49
+
50
+ def file_preview_and_remove_button
51
+ return super unless displayable?(image)
52
+
53
+ container_style = 'position: relative; height: 100%; width: 100%; min-height: 50px;min-width: 58px; display: block;'
54
+
55
+ content_tag(:div, class: 'fileinput-preview thumbnail') do
56
+ content_tag(:div, style: container_style, data: { provides: 'existing-file' }) do
57
+ image_tag(
58
+ file_url,
59
+ style: 'height: 100%; width: 100%; display: block;', data: { toggle: 'existing-file' }
60
+ ) + remove_image_button
61
+ end
62
+ end
63
+ end
64
+
65
+ # Ensure the image is displayable and stored into the backend, otherwise we cannot
66
+ # generate a preview and/or URL for it.
67
+ #
68
+ def displayable?(image)
69
+ (image.variable? || image.previewable?) && image.persisted?
70
+ end
71
+
72
+ # Returns the paperclip or active_storage attachment url to show in the
73
+ # preview thumbnail
74
+ #
75
+ def file_url
76
+ if paperclip_attachment_attached?
77
+ object.send(attribute_name).url(image_style)
78
+ elsif activestorage_attachment_attached?
79
+ attachment = object.send(attribute_name)
80
+
81
+ if attachment.representable?
82
+ attachment.representation(resize: '400x150>')
83
+ else
84
+ attachment.service_url
85
+ end
86
+ end
87
+ end
88
+
89
+ def remove_image_button
90
+ return unless object.respond_to?(:"#{remove_attachment_method}=")
91
+
92
+ button_style = 'position: absolute; top: 10px; left: 10px;'
93
+
94
+ content_tag(:button, class: 'btn btn-danger', style: button_style, type: 'button',
95
+ data: { dismiss: 'existing-file' }) do
96
+ content_tag(:i, '', class: 'fa fa-remove', data: { 'removed-class': 'fa fa-refresh' }) +
97
+ @builder.hidden_field(remove_attachment_method, class: 'remove-file-input', value: nil)
98
+ end
99
+ end
100
+
101
+ def image_style
102
+ styles = object.send(attribute_name).styles.map(&:first)
103
+ # Check if there's a :thumb or :thumbnail style in attachment definition
104
+ thumb = styles.find { |s| %w[thumb thumbnail].include?(s.to_s) }
105
+ # Return the potentially smallest size !
106
+ thumb || styles.first || :original
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,27 @@
1
+ module SimpleFormExtension
2
+ module Inputs
3
+ class NumericInput < SimpleForm::Inputs::Base
4
+ def input(wrapper_options = nil)
5
+ input_html_options[:class] << "form-control spinbox-input"
6
+ if options.fetch(:spinner, true)
7
+ "<div class=\"input-group spinbox\">
8
+ #{@builder.text_field(attribute_name, input_html_options)}
9
+ <span class=\"input-group-btn\">
10
+ <span class=\"spinbox-buttons btn-group-vertical\">
11
+ <button class=\"btn btn-default spinbox-up\" type=\"button\" tabindex=\"-1\">
12
+ <i class=\"fa fa-chevron-up\"></i>
13
+ </button>
14
+ <button class=\"btn btn-default spinbox-down\" type=\"button\" tabindex=\"-1\">
15
+ <i class=\"fa fa-chevron-down\"></i>
16
+ </button>
17
+ </span>
18
+ </span>
19
+ </div> ".html_safe
20
+
21
+ else
22
+ @builder.number_field(attribute_name, input_html_options)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,210 @@
1
+ module SimpleFormExtension
2
+ module Inputs
3
+ class SelectizeInput < SimpleForm::Inputs::Base
4
+ include SimpleFormExtension::Translations
5
+ include SimpleFormExtension::ResourceNameHelper
6
+
7
+ # This field only allows local select options (serialized into JSON)
8
+ # Searching for remote ones will be implemented later.
9
+ #
10
+ # Data attributes that may be useful :
11
+ #
12
+ # :'search-url' => search_url,
13
+ # :'search-param' => search_param,
14
+ # :'preload' => preload,
15
+ #
16
+ def input(_wrapper_options = {})
17
+ @attribute_name = foreign_key if relation?
18
+
19
+ input_html_options[:data] ||= {}
20
+
21
+ input_html_options[:data].merge!(
22
+ controller: 'selectize-field',
23
+ 'selectize-field-input-value': Array.wrap(serialized_value),
24
+ 'selectize-field-creatable-value': creatable?,
25
+ 'selectize-field-multi-value': multi?,
26
+ 'selectize-field-add-translation-value': _translate('selectize.add'),
27
+ 'selectize-field-collection-value': collection,
28
+ 'selectize-field-max-items-value': max_items,
29
+ 'selectize-field-sort-field-value': sort_field,
30
+ 'selectize-field-search-url-value': search_url,
31
+ 'selectize-field-search-param-value': search_param,
32
+ 'selectize-field-escape-value': escape.nil? ? true : escape
33
+ )
34
+
35
+ @builder.text_field attribute_name, input_html_options
36
+ end
37
+
38
+ def search_param
39
+ options[:search_param] ||= 'q'
40
+ end
41
+
42
+ def search_url
43
+ options[:search_url]
44
+ end
45
+
46
+ def creatable?
47
+ !!options[:creatable]
48
+ end
49
+
50
+ def escape
51
+ options[:escape]
52
+ end
53
+
54
+ def multi?
55
+ (options.key?(:multi) && !!options[:multi]) ||
56
+ enumerable?(value)
57
+ end
58
+
59
+ def max_items
60
+ options[:max_items]
61
+ end
62
+
63
+ def sort_field
64
+ if (sort_field = options[:sort_field]).present?
65
+ sort_field
66
+ elsif enum?
67
+ 'position'
68
+ else
69
+ 'text'
70
+ end
71
+ end
72
+
73
+ def collection
74
+ return if search_url
75
+
76
+ if (collection = options[:collection])
77
+ if enumerable?(collection)
78
+ collection.map(&method(:serialize_option))
79
+ else
80
+ (object.send(collection) || []).map(&method(:serialize_option))
81
+ end
82
+ elsif relation?
83
+ reflection.klass.all.map(&method(:serialize_option))
84
+ elsif enum?
85
+ enum_options
86
+ else
87
+ []
88
+ end
89
+ end
90
+
91
+ def serialized_value
92
+ return input_html_options[:data][:value] if input_html_options[:data][:value]
93
+
94
+ if multi?
95
+ if relation?
96
+ value.map do |item|
97
+ if (resource = relation.find { |r| r.id == item.to_i }) && (text = text_from(resource))
98
+ serialize_value(item, text)
99
+ else
100
+ serialize_value(item)
101
+ end
102
+ end
103
+ else
104
+ value.map(&method(:serialize_value))
105
+ end
106
+ elsif relation? && relation && (text = text_from(relation))
107
+ serialize_value(value, text)
108
+ else
109
+ serialize_value(value)
110
+ end
111
+ end
112
+
113
+ def value
114
+ @value ||= options_fetch(:value) { object.send(attribute_name) }
115
+ end
116
+
117
+ def serialize_value(value, text = nil)
118
+ { text: (text || value), value: value }
119
+ end
120
+
121
+ private
122
+
123
+ def serialize_option(option)
124
+ if option.is_a?(Hash) && option.key?(:text) && option.key?(:value)
125
+ option
126
+ elsif option.is_a?(ActiveRecord::Base)
127
+ { text: name_for(option), value: option.id }
128
+ elsif !option.is_a?(Hash)
129
+ { text: option.to_s, value: option }
130
+ else
131
+ raise ArgumentError, 'The individual collection items should ' \
132
+ 'either be single items or a hash with :text and :value fields'
133
+ end
134
+ end
135
+
136
+ def options_fetch(key, &block)
137
+ [options, input_html_options].each do |hash|
138
+ return hash[key] if hash.key?(key)
139
+ end
140
+
141
+ # Return default block value or nil if no block was given
142
+ block ? block.call : nil
143
+ end
144
+
145
+ # Check if the given target object is enumerable. Used internally to
146
+ # check wether :collection or :value arguments are collections.
147
+ #
148
+ def enumerable?(target)
149
+ target.class.include?(Enumerable) || target.is_a?(ActiveRecord::Relation)
150
+ end
151
+
152
+ def name_for(option)
153
+ resource_name_for(option) || option.to_s
154
+ end
155
+
156
+ def relation
157
+ @relation ||= object.send(reflection.name) if relation?
158
+ end
159
+
160
+ def relation?
161
+ !!reflection
162
+ end
163
+
164
+ def reflection
165
+ @reflection ||= if object_class.respond_to?(:reflect_on_association)
166
+ object_class.reflect_on_association(attribute_name)
167
+ end
168
+ end
169
+
170
+ def enum?
171
+ object_class.respond_to?(:defined_enums) &&
172
+ object_class.defined_enums.key?(attribute_name.to_s)
173
+ end
174
+
175
+ def enum_options
176
+ object_class.defined_enums[attribute_name.to_s].map do |key, value|
177
+ path = [object.model_name.i18n_key, attribute_name, key].join('.')
178
+ translation = ::I18n.t("activerecord.enums.#{path}", default: '')
179
+
180
+ { text: translation.presence || key, value: key, position: value }
181
+ end
182
+ end
183
+
184
+ def foreign_key
185
+ @foreign_key ||= case reflection.macro
186
+ when :belongs_to then reflection.foreign_key
187
+ when :has_one then :"#{reflection.name}_id"
188
+ when :has_many then :"#{reflection.name.to_s.singularize}_ids"
189
+ end
190
+ end
191
+
192
+ def text_from(resource)
193
+ resource_name_for(resource)
194
+ end
195
+
196
+ # Retrieve actual model class even when the form object is a proxy like
197
+ # for Ransack::Search or ActiveRecord::Relation classes
198
+ #
199
+ def object_class
200
+ @object_class ||= if (object_class = object.class) < ActiveRecord::Base
201
+ object_class
202
+ elsif (klass = object.try(:klass))
203
+ klass
204
+ else
205
+ object_class
206
+ end
207
+ end
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,30 @@
1
+ module SimpleFormExtension
2
+ module Inputs
3
+ class SliderInput < SimpleForm::Inputs::Base
4
+ def input(wrapper_options = nil)
5
+ input_html_options[:class] << 'form-control'
6
+
7
+ input_html_options[:data] ||= {}
8
+ input_html_options[:data][:'simple-form-slider'] = true
9
+
10
+ [:min, :max, :step, :orientation, :range, :value].each do |key|
11
+ if options.key?(key)
12
+ input_html_options[:data][:"slider-#{ key }"] = options[key]
13
+ end
14
+ end
15
+
16
+ input_html_options[:data][:'slider-value'] ||= object.send(attribute_name)
17
+
18
+ if options[:disabled]
19
+ input_html_options[:data][:'slider-enabled'] = false
20
+ end
21
+
22
+ if options[:ticks]
23
+ input_html_options[:data][:ticks] = options[:ticks].to_json
24
+ end
25
+
26
+ @builder.hidden_field(attribute_name, input_html_options)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ module SimpleFormExtension
2
+ module Inputs
3
+ extend ActiveSupport::Autoload
4
+
5
+ autoload :DateTimeInput
6
+ autoload :BooleanInput
7
+ autoload :NumericInput
8
+ autoload :CollectionCheckBoxesInput
9
+ autoload :CollectionRadioButtonsInput
10
+ autoload :ColorInput
11
+ autoload :FileInput
12
+ autoload :ImageInput
13
+ autoload :SelectizeInput
14
+ autoload :SliderInput
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ module SimpleFormExtension
2
+ class Railtie < Rails::Railtie
3
+ initializer 'add vendor path to assets pipeline' do |app|
4
+ %w(javascripts stylesheets images).each do |folder|
5
+ app.config.assets.paths << vendor_asset_path_for(folder)
6
+ end
7
+ end
8
+
9
+ initializer 'add images to precompile hook' do |app|
10
+ Dir[vendor_asset_path_for('images/**/*.*')].each do |image_path|
11
+ app.config.assets.precompile << image_path.split('/images/').pop
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def vendor_asset_path_for(sub_path)
18
+ File.expand_path("../../../vendor/assets/#{ sub_path }", __FILE__)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module SimpleFormExtension
2
+ module ResourceNameHelper
3
+ def resource_name_for(resource)
4
+ SimpleFormExtension.resource_name_methods.each do |method_name|
5
+ if (value = resource.try(method_name)) then return value end
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module SimpleFormExtension
2
+ module Translations
3
+ def _translate(key, options = {})
4
+ I18n.translate(['simple_form.extension', key].join('.'))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleFormExtension
2
+ VERSION = '1.5.1'
3
+ end
@@ -0,0 +1,30 @@
1
+ require 'simple_form_extension/version'
2
+ require 'simple_form'
3
+
4
+ module SimpleFormExtension
5
+ extend ActiveSupport::Autoload
6
+
7
+ eager_autoload do
8
+ autoload :Translations
9
+ autoload :ResourceNameHelper
10
+ autoload :FileConcern
11
+ autoload :Components
12
+ autoload :Inputs
13
+ end
14
+
15
+ # Allows overriding which methods are used by the fields that try to fetch
16
+ # the name of a resource to display it instead of calling #to_s
17
+ #
18
+ mattr_accessor :resource_name_methods
19
+ @@resource_name_methods = %i[name title]
20
+
21
+ mattr_accessor :default_image_input_accept
22
+ @@default_image_input_accept = 'image/jpeg,image/png,image/gif'
23
+ end
24
+
25
+ SimpleForm::Inputs::Base.include SimpleFormExtension::Components::Icons
26
+ SimpleForm::Inputs::Base.include SimpleFormExtension::Components::Popovers
27
+
28
+ SimpleForm.custom_inputs_namespaces << 'SimpleFormExtension::Inputs'
29
+
30
+ require 'simple_form_extension/railtie' if defined?(Rails)