spree_backend 4.2.7 → 4.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/app/assets/config/spree_backend_manifest.js +129 -0
  4. data/app/assets/images/backend-arrows-fullscreen.svg +3 -0
  5. data/app/assets/images/backend-box.svg +3 -0
  6. data/app/assets/images/backend-circle-fill.svg +3 -0
  7. data/app/assets/images/backend-circle.svg +3 -0
  8. data/app/assets/images/backend-default-layout.svg +6 -0
  9. data/app/assets/images/backend-eye-slash-fill.svg +4 -0
  10. data/app/assets/images/backend-file-richtext.svg +4 -0
  11. data/app/assets/images/backend-fullscreen-exit.svg +3 -0
  12. data/app/assets/images/backend-fullscreen.svg +3 -0
  13. data/app/assets/images/backend-mobile.svg +5 -0
  14. data/app/assets/images/backend-pages.svg +10 -0
  15. data/app/assets/images/backend-phone.svg +4 -0
  16. data/app/assets/images/backend-reversed-layout.svg +6 -0
  17. data/app/assets/images/backend-spree-icon.svg +1 -0
  18. data/app/assets/images/backend-spree-logo.svg +6 -0
  19. data/app/assets/images/backend-store.svg +2 -13
  20. data/app/assets/images/backend-translate.svg +4 -0
  21. data/app/assets/images/backend-users.svg +2 -5
  22. data/app/assets/images/backend-window-sidebar.svg +4 -0
  23. data/app/assets/images/noimage/large.png +0 -0
  24. data/app/assets/images/noimage/mini.png +0 -0
  25. data/app/assets/images/noimage/product.png +0 -0
  26. data/app/assets/images/noimage/small.png +0 -0
  27. data/app/assets/javascripts/spree/backend/address_states.es6 +44 -0
  28. data/app/assets/javascripts/spree/backend/admin.js +45 -307
  29. data/app/assets/javascripts/spree/backend/checkouts/edit.js +22 -13
  30. data/app/assets/javascripts/spree/backend/cms/_index.es6 +4 -0
  31. data/app/assets/javascripts/spree/backend/cms/links.es6 +25 -0
  32. data/app/assets/javascripts/spree/backend/cms/live_preview.es6 +34 -0
  33. data/app/assets/javascripts/spree/backend/cms/page.es6 +133 -0
  34. data/app/assets/javascripts/spree/backend/cms/section.es6 +43 -0
  35. data/app/assets/javascripts/spree/backend/global/_index.js +11 -0
  36. data/app/assets/javascripts/spree/backend/global/alerts.es6 +66 -0
  37. data/app/assets/javascripts/spree/backend/global/api_functions.es6 +5 -0
  38. data/app/assets/javascripts/spree/backend/global/bootstrap.es6 +15 -0
  39. data/app/assets/javascripts/spree/backend/global/flatpickr.es6 +22 -0
  40. data/app/assets/javascripts/spree/backend/global/info_alert.es6 +38 -0
  41. data/app/assets/javascripts/spree/backend/global/radio_panel_toggle.es6 +18 -0
  42. data/app/assets/javascripts/spree/backend/global/ransack.es6 +108 -0
  43. data/app/assets/javascripts/spree/backend/global/responsive_menus.es6 +56 -0
  44. data/app/assets/javascripts/spree/backend/global/select2_autocomplete.es6 +143 -0
  45. data/app/assets/javascripts/spree/backend/global/select2_populate.es6 +61 -0
  46. data/app/assets/javascripts/spree/backend/global/side_scroll_indication.es6 +137 -0
  47. data/app/assets/javascripts/spree/backend/global/sortable.es6 +35 -0
  48. data/app/assets/javascripts/spree/backend/global/tinymce.es6 +11 -0
  49. data/app/assets/javascripts/spree/backend/menus/_index.es6 +2 -0
  50. data/app/assets/javascripts/spree/backend/menus/menu.es6 +58 -0
  51. data/app/assets/javascripts/spree/backend/menus/menu_item.es6 +26 -0
  52. data/app/assets/javascripts/spree/backend/option_type_autocomplete.js +7 -17
  53. data/app/assets/javascripts/spree/backend/option_value_picker.js +10 -22
  54. data/app/assets/javascripts/spree/backend/payments/edit.js +1 -1
  55. data/app/assets/javascripts/spree/backend/payments/new.js +18 -5
  56. data/app/assets/javascripts/spree/backend/spree-select2.js +19 -1
  57. data/app/assets/javascripts/spree/backend/stock_location.js +1 -2
  58. data/app/assets/javascripts/spree/backend/taxons.js +74 -73
  59. data/app/assets/javascripts/spree/backend/user_picker.js +7 -10
  60. data/app/assets/javascripts/spree/backend.js +28 -1
  61. data/app/assets/javascripts/spree.js +78 -0
  62. data/app/assets/stylesheets/spree/backend/components/_filters.scss +1 -3
  63. data/app/assets/stylesheets/spree/backend/components/_main.scss +0 -1
  64. data/app/assets/stylesheets/spree/backend/components/_navbar.scss +35 -0
  65. data/app/assets/stylesheets/spree/backend/components/_navigation.scss +13 -0
  66. data/app/assets/stylesheets/spree/backend/components/_sidebar.scss +0 -1
  67. data/app/assets/stylesheets/spree/backend/components/_tables.scss +4 -5
  68. data/app/assets/stylesheets/spree/backend/global/_mixins.scss +59 -0
  69. data/app/assets/stylesheets/spree/backend/plugins/_nav_x.scss +95 -0
  70. data/app/assets/stylesheets/spree/backend/plugins/_sweetalert2_custom.scss +100 -0
  71. data/app/assets/stylesheets/spree/backend/plugins/_tinymce_custom.scss +4 -0
  72. data/app/assets/stylesheets/spree/backend/shared/_base.scss +28 -26
  73. data/app/assets/stylesheets/spree/backend/shared/_forms.scss +8 -0
  74. data/app/assets/stylesheets/spree/backend/spree_admin.css.scss +5 -0
  75. data/app/assets/stylesheets/spree/backend/views/_cms_pages.scss +148 -0
  76. data/app/assets/stylesheets/spree/backend/views/_menus.scss +61 -0
  77. data/app/controllers/concerns/spree/admin/order_concern.rb +24 -0
  78. data/app/controllers/concerns/spree/admin/product_concern.rb +11 -0
  79. data/app/controllers/spree/admin/base_controller.rb +63 -3
  80. data/app/controllers/spree/admin/cms_pages_controller.rb +29 -0
  81. data/app/controllers/spree/admin/cms_sections_controller.rb +15 -0
  82. data/app/controllers/spree/admin/customer_returns_controller.rb +4 -5
  83. data/app/controllers/spree/admin/errors_controller.rb +11 -0
  84. data/app/controllers/spree/admin/general_settings_controller.rb +1 -1
  85. data/app/controllers/spree/admin/images_controller.rb +8 -22
  86. data/app/controllers/spree/admin/log_entries_controller.rb +4 -3
  87. data/app/controllers/spree/admin/menu_items_controller.rb +33 -0
  88. data/app/controllers/spree/admin/menus_controller.rb +32 -0
  89. data/app/controllers/spree/admin/option_types_controller.rb +1 -1
  90. data/app/controllers/spree/admin/orders/customer_details_controller.rb +6 -11
  91. data/app/controllers/spree/admin/orders_controller.rb +22 -30
  92. data/app/controllers/spree/admin/payment_methods_controller.rb +17 -4
  93. data/app/controllers/spree/admin/payments_controller.rb +5 -10
  94. data/app/controllers/spree/admin/prices_controller.rb +2 -2
  95. data/app/controllers/spree/admin/products_controller.rb +21 -10
  96. data/app/controllers/spree/admin/promotion_actions_controller.rb +1 -1
  97. data/app/controllers/spree/admin/promotion_rules_controller.rb +1 -1
  98. data/app/controllers/spree/admin/promotions_controller.rb +3 -3
  99. data/app/controllers/spree/admin/prototypes_controller.rb +1 -1
  100. data/app/controllers/spree/admin/reimbursements_controller.rb +1 -1
  101. data/app/controllers/spree/admin/reports_controller.rb +5 -1
  102. data/app/controllers/spree/admin/resource_controller.rb +35 -5
  103. data/app/controllers/spree/admin/return_index_controller.rb +1 -1
  104. data/app/controllers/spree/admin/state_changes_controller.rb +2 -7
  105. data/app/controllers/spree/admin/stock_items_controller.rb +2 -2
  106. data/app/controllers/spree/admin/stock_locations_controller.rb +2 -2
  107. data/app/controllers/spree/admin/stock_movements_controller.rb +1 -1
  108. data/app/controllers/spree/admin/stock_transfers_controller.rb +1 -1
  109. data/app/controllers/spree/admin/store_credits_controller.rb +13 -8
  110. data/app/controllers/spree/admin/stores_controller.rb +14 -17
  111. data/app/controllers/spree/admin/taxons_controller.rb +9 -5
  112. data/app/controllers/spree/admin/users_controller.rb +9 -7
  113. data/app/controllers/spree/admin/variants_controller.rb +16 -15
  114. data/app/helpers/spree/admin/base_helper.rb +52 -14
  115. data/app/helpers/spree/admin/cms_helper.rb +15 -0
  116. data/app/helpers/spree/admin/menu_helper.rb +30 -0
  117. data/app/helpers/spree/admin/stores_helper.rb +21 -0
  118. data/app/models/spree/backend_configuration.rb +2 -0
  119. data/app/views/spree/admin/adjustments/_adjustment.html.erb +7 -5
  120. data/app/views/spree/admin/adjustments/_adjustments_table.html.erb +2 -2
  121. data/app/views/spree/admin/cms_pages/_form.html.erb +135 -0
  122. data/app/views/spree/admin/cms_pages/_live_preview_area.html.erb +61 -0
  123. data/app/views/spree/admin/cms_pages/_section_template.html.erb +16 -0
  124. data/app/views/spree/admin/cms_pages/edit.html.erb +21 -0
  125. data/app/views/spree/admin/cms_pages/index.html.erb +84 -0
  126. data/app/views/spree/admin/cms_pages/new.html.erb +8 -0
  127. data/app/views/spree/admin/cms_sections/_form.html.erb +69 -0
  128. data/app/views/spree/admin/cms_sections/edit.html.erb +19 -0
  129. data/app/views/spree/admin/cms_sections/new.html.erb +11 -0
  130. data/app/views/spree/admin/cms_sections/types/_featured_article.html.erb +50 -0
  131. data/app/views/spree/admin/cms_sections/types/_hero_image.html.erb +62 -0
  132. data/app/views/spree/admin/cms_sections/types/_image_gallery.html.erb +177 -0
  133. data/app/views/spree/admin/cms_sections/types/_product_carousel.html.erb +5 -0
  134. data/app/views/spree/admin/cms_sections/types/_rich_text_content.html.erb +4 -0
  135. data/app/views/spree/admin/cms_sections/types/_side_by_side_images.html.erb +121 -0
  136. data/app/views/spree/admin/countries/index.html.erb +5 -3
  137. data/app/views/spree/admin/customer_returns/_reimbursements_table.html.erb +6 -4
  138. data/app/views/spree/admin/customer_returns/_return_item_decision.html.erb +9 -7
  139. data/app/views/spree/admin/customer_returns/index.html.erb +4 -2
  140. data/app/views/spree/admin/errors/forbidden.html.erb +0 -0
  141. data/app/views/spree/admin/images/index.html.erb +5 -3
  142. data/app/views/spree/admin/menu_items/_form.html.erb +115 -0
  143. data/app/views/spree/admin/menu_items/edit.html.erb +11 -0
  144. data/app/views/spree/admin/menu_items/new.html.erb +11 -0
  145. data/app/views/spree/admin/menus/_form.html.erb +19 -0
  146. data/app/views/spree/admin/menus/edit.html.erb +57 -0
  147. data/app/views/spree/admin/menus/index.html.erb +90 -0
  148. data/app/views/spree/admin/menus/nested_menu_items/_item_bar.html.erb +30 -0
  149. data/app/views/spree/admin/menus/new.html.erb +22 -0
  150. data/app/views/spree/admin/option_types/_form.html.erb +3 -0
  151. data/app/views/spree/admin/option_types/_option_value_fields.html.erb +5 -1
  152. data/app/views/spree/admin/option_types/index.html.erb +5 -3
  153. data/app/views/spree/admin/orders/_channel_form.html.erb +2 -2
  154. data/app/views/spree/admin/orders/_line_items.html.erb +9 -7
  155. data/app/views/spree/admin/orders/_shipment.html.erb +26 -18
  156. data/app/views/spree/admin/orders/_shipment_manifest.html.erb +10 -8
  157. data/app/views/spree/admin/orders/customer_details/_autocomplete.js.erb +2 -2
  158. data/app/views/spree/admin/orders/index.html.erb +100 -101
  159. data/app/views/spree/admin/payment_methods/_form.html.erb +6 -4
  160. data/app/views/spree/admin/payment_methods/edit.html.erb +1 -1
  161. data/app/views/spree/admin/payment_methods/index.html.erb +22 -3
  162. data/app/views/spree/admin/payment_methods/new.html.erb +1 -1
  163. data/app/views/spree/admin/payments/_list.html.erb +9 -7
  164. data/app/views/spree/admin/prices/_variant_prices.html.erb +7 -14
  165. data/app/views/spree/admin/product_properties/_product_property_fields.html.erb +9 -7
  166. data/app/views/spree/admin/products/_autocomplete.js.erb +5 -5
  167. data/app/views/spree/admin/products/_form.html.erb +24 -5
  168. data/app/views/spree/admin/products/index.html.erb +14 -13
  169. data/app/views/spree/admin/products/new.html.erb +6 -1
  170. data/app/views/spree/admin/products/stock.html.erb +71 -68
  171. data/app/views/spree/admin/promotion_categories/index.html.erb +5 -3
  172. data/app/views/spree/admin/promotions/_form.html.erb +7 -0
  173. data/app/views/spree/admin/promotions/actions/_create_item_adjustments.html.erb +1 -0
  174. data/app/views/spree/admin/promotions/calculators/_default_fields.html.erb +2 -1
  175. data/app/views/spree/admin/promotions/index.html.erb +33 -34
  176. data/app/views/spree/admin/properties/_form.html.erb +6 -0
  177. data/app/views/spree/admin/properties/index.html.erb +9 -3
  178. data/app/views/spree/admin/prototypes/_form.html.erb +1 -1
  179. data/app/views/spree/admin/prototypes/_prototypes.html.erb +8 -6
  180. data/app/views/spree/admin/prototypes/index.html.erb +5 -3
  181. data/app/views/spree/admin/reimbursement_types/index.html.erb +5 -3
  182. data/app/views/spree/admin/reports/index.html.erb +1 -1
  183. data/app/views/spree/admin/reports/sales_total.html.erb +1 -1
  184. data/app/views/spree/admin/return_authorizations/_form.html.erb +2 -2
  185. data/app/views/spree/admin/return_authorizations/index.html.erb +7 -5
  186. data/app/views/spree/admin/return_index/customer_returns.html.erb +4 -2
  187. data/app/views/spree/admin/return_index/return_authorizations.html.erb +5 -3
  188. data/app/views/spree/admin/roles/index.html.erb +5 -3
  189. data/app/views/spree/admin/shared/_account_nav.html.erb +5 -5
  190. data/app/views/spree/admin/shared/_address_form.html.erb +5 -4
  191. data/app/views/spree/admin/shared/_content_header.html.erb +20 -6
  192. data/app/views/spree/admin/shared/_head.html.erb +2 -1
  193. data/app/views/spree/admin/shared/_header.html.erb +7 -10
  194. data/app/views/spree/admin/shared/_link_fields.html.erb +22 -0
  195. data/app/views/spree/admin/shared/_main_menu.html.erb +19 -4
  196. data/app/views/spree/admin/shared/_order_tabs.html.erb +1 -10
  197. data/app/views/spree/admin/shared/_paths.html.erb +8 -0
  198. data/app/views/spree/admin/shared/_refunds.html.erb +4 -2
  199. data/app/views/spree/admin/shared/_sidebar.html.erb +1 -1
  200. data/app/views/spree/admin/shared/_store_switcher.html.erb +23 -0
  201. data/app/views/spree/admin/shared/_table_filter.html.erb +6 -6
  202. data/app/views/spree/admin/shared/_translations.html.erb +2 -0
  203. data/app/views/spree/admin/shared/cms/_spree_product.html.erb +14 -0
  204. data/app/views/spree/admin/shared/cms/_spree_taxon.html.erb +14 -0
  205. data/app/views/spree/admin/shared/linkables/_home_page.html.erb +3 -0
  206. data/app/views/spree/admin/shared/linkables/_spree_cms_page.erb +28 -0
  207. data/app/views/spree/admin/shared/linkables/_spree_product.html.erb +20 -0
  208. data/app/views/spree/admin/shared/linkables/_spree_taxon.html.erb +22 -0
  209. data/app/views/spree/admin/shared/linkables/_url.html.erb +16 -0
  210. data/app/views/spree/admin/shared/named_types/_index.html.erb +7 -5
  211. data/app/views/spree/admin/shared/sub_menu/_configuration.html.erb +1 -3
  212. data/app/views/spree/admin/shared/sub_menu/_content.html.erb +4 -0
  213. data/app/views/spree/admin/shared/sub_menu/_stock.html.erb +4 -0
  214. data/app/views/spree/admin/shipping_categories/index.html.erb +5 -3
  215. data/app/views/spree/admin/shipping_methods/index.html.erb +5 -3
  216. data/app/views/spree/admin/states/_state_list.html.erb +5 -3
  217. data/app/views/spree/admin/stock_locations/index.html.erb +5 -3
  218. data/app/views/spree/admin/stock_transfers/index.html.erb +5 -4
  219. data/app/views/spree/admin/stock_transfers/new.html.erb +9 -7
  220. data/app/views/spree/admin/store_credit_categories/index.html.erb +5 -3
  221. data/app/views/spree/admin/store_credits/index.html.erb +7 -5
  222. data/app/views/spree/admin/stores/_form.html.erb +12 -2
  223. data/app/views/spree/admin/stores/index.html.erb +12 -10
  224. data/app/views/spree/admin/tax_categories/index.html.erb +5 -3
  225. data/app/views/spree/admin/tax_rates/index.html.erb +5 -3
  226. data/app/views/spree/admin/taxonomies/_list.html.erb +5 -3
  227. data/app/views/spree/admin/taxons/_form.html.erb +1 -1
  228. data/app/views/spree/admin/users/_addresses_form.html.erb +2 -4
  229. data/app/views/spree/admin/users/index.html.erb +5 -3
  230. data/app/views/spree/admin/variants/_autocomplete_line_items_stock.js.erb +18 -12
  231. data/app/views/spree/admin/variants/_autocomplete_stock.js.erb +12 -8
  232. data/app/views/spree/admin/variants/_split.js.erb +9 -7
  233. data/app/views/spree/admin/variants/index.html.erb +8 -5
  234. data/app/views/spree/admin/zones/index.html.erb +5 -3
  235. data/app/views/spree/layouts/admin.html.erb +16 -16
  236. data/config/initializers/assets.rb +5 -1
  237. data/config/routes.rb +16 -4
  238. data/lib/generators/spree/backend/install/install_generator.rb +22 -0
  239. data/lib/generators/spree/backend/install/templates/vendor/assets/javascripts/spree/backend/all.js +8 -0
  240. data/lib/generators/spree/backend/install/templates/vendor/assets/stylesheets/spree/backend/all.css +9 -0
  241. data/lib/spree/backend/engine.rb +4 -11
  242. data/lib/spree/backend.rb +7 -4
  243. data/lib/spree_backend.rb +0 -2
  244. data/spec/fixtures/files/favicon.ico +0 -0
  245. data/spec/fixtures/files/icon_512x512.png +0 -0
  246. data/spree_backend.gemspec +9 -4
  247. data/vendor/assets/javascripts/cleave.js +8 -0
  248. data/vendor/assets/javascripts/jsonapi-serializer.min.js +8 -0
  249. data/vendor/assets/javascripts/jsuri.js +458 -0
  250. data/vendor/assets/javascripts/sortable.js +2 -3709
  251. data/vendor/assets/javascripts/sweetalert2.js +2 -0
  252. metadata +193 -22
  253. data/app/assets/javascripts/spree/backend/address_states.js +0 -44
  254. data/app/assets/javascripts/spree/frontend/backend.js +0 -1
  255. data/app/assets/stylesheets/spree/frontend/backend.css +0 -1
  256. data/app/views/spree/admin/orders/_store_form.html.erb +0 -18
  257. /data/app/assets/stylesheets/spree/backend/plugins/{select2_bootstrap4.scss → _select2_bootstrap4.scss} +0 -0
@@ -0,0 +1,43 @@
1
+ document.addEventListener('DOMContentLoaded', function() {
2
+ const sectionKindSelector = $('#cms_section_type').select2()
3
+ const layoutSwitcher = $('#cms_section_layout_style').select2()
4
+
5
+ sectionKindSelector.on('change', function() {
6
+ const selectedValue = $(sectionKindSelector).val()
7
+ const message = document.getElementById('alertToClickUpdate')
8
+ const activeSectionKind = document.getElementById('CmsSectionType')
9
+
10
+ if (!activeSectionKind) return
11
+
12
+ const panelType = activeSectionKind.dataset.panelSectionType
13
+
14
+ if (selectedValue === panelType) {
15
+ activeSectionKind.classList = ''
16
+ activeSectionKind.classList.add('d-block')
17
+
18
+ message.classList = ''
19
+ message.classList.add('d-none')
20
+ } else {
21
+ activeSectionKind.classList = ''
22
+ activeSectionKind.classList.add('d-none')
23
+
24
+ message.classList = ''
25
+ message.classList.add('d-block')
26
+ }
27
+ });
28
+
29
+ if (!layoutSwitcher) return
30
+
31
+ layoutSwitcher.on('change', function() {
32
+ const layoutDefault = document.querySelector('#Default')
33
+ const layoutReverse = document.querySelector('#Reversed')
34
+
35
+ if (this.value === 'Default') {
36
+ layoutDefault.classList = 'd-block'
37
+ layoutReverse.classList = 'd-none'
38
+ } else {
39
+ layoutDefault.classList = 'd-none'
40
+ layoutReverse.classList = 'd-block'
41
+ }
42
+ })
43
+ })
@@ -0,0 +1,11 @@
1
+ //= require spree/backend/global/alerts
2
+ //= require spree/backend/global/bootstrap
3
+ //= require spree/backend/global/flatpickr
4
+ //= require spree/backend/global/ransack
5
+ //= require spree/backend/global/info_alert
6
+ //= require spree/backend/global/radio_panel_toggle
7
+ //= require spree/backend/global/responsive_menus
8
+ //= require spree/backend/global/select2_autocomplete
9
+ //= require spree/backend/global/select2_populate
10
+ //= require spree/backend/global/sortable
11
+ //= require spree/backend/global/side_scroll_indication
@@ -0,0 +1,66 @@
1
+ /* global Swal */
2
+
3
+ document.addEventListener('DOMContentLoaded', function() {
4
+ const alertEl = document.querySelectorAll('[data-alert-type]')
5
+
6
+ if (!alertEl) return
7
+
8
+ alertEl.forEach(function (elem) {
9
+ const alertType = elem.dataset.alertType
10
+ const alertMessage = elem.innerHTML
11
+
12
+ show_flash(alertType, alertMessage)
13
+ })
14
+ })
15
+
16
+ // eslint-disable-next-line camelcase
17
+ function show_flash(type, message) {
18
+ let sanitizedType = DOMPurify.sanitize(type)
19
+ const sanitizedMessage = DOMPurify.sanitize(message)
20
+
21
+ if (sanitizedType === 'notice') sanitizedType = 'info'
22
+
23
+ // Set up Swal toast alert defaults
24
+ const Toast = Swal.mixin({
25
+ toast: true,
26
+ position: 'bottom',
27
+ showConfirmButton: false,
28
+ showCloseButton: true,
29
+ timer: 4500,
30
+ timerProgressBar: false,
31
+ showClass: {
32
+ popup: 'animate__animated animate__fadeInUp animate__faster',
33
+ backdrop: '-',
34
+ icon: '-'
35
+ },
36
+ hideClass: {
37
+ popup: 'animate__animated animate__fadeOutDown animate__faster',
38
+ backdrop: '-',
39
+ icon: '-'
40
+ }
41
+ })
42
+
43
+ Toast.fire({
44
+ icon: sanitizedType,
45
+ title: sanitizedMessage
46
+ })
47
+
48
+ appendToFlashAlertsContainer(sanitizedMessage, sanitizedType)
49
+ }
50
+
51
+ function appendToFlashAlertsContainer (message, type) {
52
+ if (type === 'info') type = 'notice'
53
+
54
+ const parnetNode = document.querySelector('#FlashAlertsContainer')
55
+ const node = document.createElement('SPAN');
56
+ const textNode = document.createTextNode(message);
57
+
58
+ // Only the most recent alert should be left in the #FlashAlertsContainer.
59
+ parnetNode.innerHTML = ''
60
+
61
+ node.classList.add('d-none')
62
+ node.setAttribute('data-alert-type', type);
63
+ node.appendChild(textNode)
64
+
65
+ parnetNode.appendChild(node);
66
+ }
@@ -0,0 +1,5 @@
1
+ // eslint-disable-next-line no-unused-vars
2
+ function spreeHandleApiRequestError (response) {
3
+ // eslint-disable-next-line no-undef
4
+ show_flash('error', `API Error: ${response}`)
5
+ }
@@ -0,0 +1,15 @@
1
+ // Use this file for Boostrap customization applied across the Spree Backend
2
+
3
+ document.addEventListener('DOMContentLoaded', function() {
4
+ $('.with-tip').each(function() {
5
+ $(this).tooltip({
6
+ container: $(this)
7
+ })
8
+ })
9
+
10
+ $('.with-tip').on('show.bs.tooltip', function(event) {
11
+ if (('ontouchstart' in window)) {
12
+ event.preventDefault()
13
+ }
14
+ })
15
+ })
@@ -0,0 +1,22 @@
1
+ document.addEventListener('DOMContentLoaded', function() {
2
+ flatpickr.setDefaults({
3
+ altInput: true,
4
+ time_24hr: true,
5
+ altInputClass: 'flatpickr-alt-input',
6
+ locale: Spree.translations.flatpickr_locale
7
+ })
8
+
9
+ var dateFrom = flatpickr('.datePickerFrom', {
10
+ onChange: function(selectedDates) {
11
+ dateTo.set('minDate', selectedDates[0])
12
+ }
13
+ })
14
+
15
+ var dateTo = flatpickr('.datePickerTo', {
16
+ onChange: function(selectedDates) {
17
+ dateFrom.set('maxDate', selectedDates[0])
18
+ }
19
+ })
20
+
21
+ flatpickr('.datepicker', {})
22
+ })
@@ -0,0 +1,38 @@
1
+ /* global Swal */
2
+ document.addEventListener('DOMContentLoaded', function() {
3
+ const infoToggle = document.querySelectorAll('[data-show-info]')
4
+
5
+ infoToggle.forEach(function(infoElem) {
6
+ infoElem.addEventListener('click', function() {
7
+ const alertType = infoElem.dataset.alertKind
8
+ const alertTitle = infoElem.dataset.alertTitle
9
+ const alertHtml = infoElem.dataset.alertHtml
10
+ const alertMessage = infoElem.dataset.alertMessage
11
+
12
+ showInfoAlert(alertType, alertTitle, alertMessage, alertHtml)
13
+ })
14
+ })
15
+ })
16
+
17
+ // eslint-disable-next-line no-unused-vars
18
+ function showInfoAlert(type = null, title = null, message = null, html = null) {
19
+ const infoAlert = Swal.mixin({
20
+ showConfirmButton: false,
21
+ showCloseButton: true,
22
+ timer: null,
23
+ timerProgressBar: false,
24
+ showClass: {
25
+ popup: 'animate__animated animate__fadeInUp animate__faster'
26
+ },
27
+ hideClass: {
28
+ popup: 'animate__animated animate__fadeOutDown animate__faster'
29
+ }
30
+ })
31
+
32
+ infoAlert.fire({
33
+ icon: type,
34
+ title: title,
35
+ text: message,
36
+ html: html
37
+ })
38
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ radioControlsVisibilityOfElement:
3
+ Apply to individual radio button that makes another element visible when checked
4
+ **/
5
+ document.addEventListener('DOMContentLoaded', function() {
6
+ $.fn.radioControlsVisibilityOfElement = function(dependentElementSelector) {
7
+ if (!this.get(0)) { return }
8
+ var showValue = this.get(0).value
9
+ var radioGroup = $("input[name='" + this.get(0).name + "']")
10
+ radioGroup.each(function() {
11
+ $(this).click(function() {
12
+ // eslint-disable-next-line eqeqeq
13
+ $(dependentElementSelector).visible(this.checked && this.value == showValue)
14
+ })
15
+ if (this.checked) { this.click() }
16
+ })
17
+ }
18
+ })
@@ -0,0 +1,108 @@
1
+ document.addEventListener('DOMContentLoaded', function() {
2
+ const QuickSearchInput = document.getElementById('quick_search')
3
+
4
+ if (QuickSearchInput) {
5
+ const QuickSearchPlaceHolder = QuickSearchInput.placeholder
6
+ const TargetSearchFieldId = document.querySelector('input.js-quick-search-target').id
7
+ const AssociatedLabelName = document.querySelector(`label[for="${TargetSearchFieldId}"]`).innerHTML
8
+
9
+ QuickSearchInput.placeholder = `${QuickSearchPlaceHolder} ${AssociatedLabelName}`
10
+ }
11
+
12
+ $('.js-show-index-filters').click(function() {
13
+ $('.filter-well').slideToggle()
14
+ $(this).parents('.filter-wrap').toggleClass('collapsed')
15
+ })
16
+
17
+ // TODO: remove this js temp behaviour and fix this decent
18
+ // Temp quick search
19
+ // When there was a search term, copy it
20
+ $('.js-quick-search').val($('.js-quick-search-target').val())
21
+
22
+ // Catch the quick search form submit and submit the real form
23
+ $('#quick-search').submit(function() {
24
+ $('.js-quick-search-target').val($('.js-quick-search').val())
25
+ $('#table-filter form').submit()
26
+ return false
27
+ })
28
+
29
+ // Clickable ransack filters
30
+ $('.js-add-filter').click(function() {
31
+ var ransackField = $(this).data('ransack-field')
32
+ var ransackValue = $(this).data('ransack-value')
33
+
34
+ $('#' + ransackField).val(ransackValue)
35
+ $('#table-filter form').submit()
36
+ })
37
+
38
+ $(document).on('click', '.js-delete-filter', function() {
39
+ var ransackField = $(this).parents('.js-filter').data('ransack-field')
40
+
41
+ $('#' + ransackField).val('')
42
+ $('#table-filter form').submit()
43
+ })
44
+
45
+ function ransackField(value) {
46
+ switch (value) {
47
+ case 'Date Range':
48
+ return 'Start'
49
+ case '':
50
+ return 'Stop'
51
+ default:
52
+ return value.trim()
53
+ }
54
+ }
55
+
56
+ // To appear in the filtered options, the elements id attribute must start with 'q_',
57
+ // and it must have the class'.js-filterable'.
58
+ $('[id^="q_"].js-filterable').each(function() {
59
+ var $this = $(this)
60
+
61
+ if ($this.val() !== null && $this.val() !== '' && $this.val().length !== 0) {
62
+ var ransackValue, filter
63
+ var ransackFieldId = $this.attr('id')
64
+ var label = $('label[for="' + ransackFieldId + '"]')
65
+
66
+ if ($this.is('select')) {
67
+ ransackValue = $this.find('option:selected').toArray().map(function(option) {
68
+ return option.text;
69
+ }).join(', ')
70
+ } else {
71
+ ransackValue = $this.val()
72
+ }
73
+
74
+ label = ransackField(label.text()) + ': ' + ransackValue
75
+
76
+ var cleanLabel = DOMPurify.sanitize(label)
77
+
78
+ filter = '<span class="js-filter badge badge-secondary d-inline-flex align-items-center" data-ransack-field="' + ransackFieldId + '">' + cleanLabel + '<i class="icon icon-cancel ml-2 js-delete-filter"></i></span>'
79
+ $('.js-filters').append(filter).show()
80
+ }
81
+ })
82
+
83
+ // per page dropdown
84
+ // preserves all selected filters / queries supplied by user
85
+ // changes only per_page value
86
+ $('.js-per-page-select').change(function() {
87
+ var form = $(this).closest('.js-per-page-form')
88
+ var url = form.attr('action')
89
+ var value = $(this).val().toString()
90
+ if (url.match(/\?/)) {
91
+ url += '&per_page=' + value
92
+ } else {
93
+ url += '?per_page=' + value
94
+ }
95
+ window.location = url
96
+ })
97
+
98
+ // injects per_page settings to all available search forms
99
+ // so when user changes some filters / queries per_page is preserved
100
+ $(document).ready(function() {
101
+ var perPageDropdown = $('.js-per-page-select:first')
102
+ if (perPageDropdown.length) {
103
+ var perPageValue = perPageDropdown.val().toString()
104
+ var perPageInput = '<input type="hidden" name="per_page" value=' + perPageValue + ' />'
105
+ $('#table-filter form').append(perPageInput)
106
+ }
107
+ })
108
+ })
@@ -0,0 +1,56 @@
1
+ document.addEventListener('DOMContentLoaded', function() {
2
+ var body = $('body')
3
+ var modalBackdrop = $('#multi-backdrop')
4
+
5
+ // Fail safe on screen resize
6
+ var resizeTimer;
7
+ window.addEventListener('resize', function() {
8
+ document.body.classList.remove('modal-open', 'sidebar-open', 'contextualSideMenu-open');
9
+ document.body.classList.add('resize-animation-stopper');
10
+ clearTimeout(resizeTimer);
11
+ resizeTimer = setTimeout(function() {
12
+ document.body.classList.remove('resize-animation-stopper');
13
+ }, 400);
14
+ });
15
+
16
+ function closeAllMenus() {
17
+ body.removeClass()
18
+ body.addClass('admin')
19
+ modalBackdrop.removeClass('show')
20
+ }
21
+
22
+ modalBackdrop.click(closeAllMenus)
23
+
24
+ // Main Menu Functionality
25
+ var sidebarOpen = $('#sidebar-open')
26
+ var sidebarClose = $('#sidebar-close')
27
+ var activeItem = $('#main-sidebar').find('.selected')
28
+
29
+ activeItem.closest('.nav-sidebar').addClass('active-option')
30
+ activeItem.closest('.nav-pills').addClass('in show')
31
+
32
+ function openMenu() {
33
+ closeAllMenus()
34
+ body.addClass('sidebar-open modal-open')
35
+ modalBackdrop.addClass('show')
36
+ }
37
+ sidebarOpen.click(openMenu)
38
+ sidebarClose.click(closeAllMenus)
39
+
40
+ // Contextual Sidebar Menu
41
+ var contextualSidebarMenuToggle = $('#contextual-menu-toggle')
42
+ var contextualSidebarMenuClose = $('#contextual-menu-close')
43
+
44
+ function toggleContextualMenu() {
45
+ if (document.body.classList.contains('contextualSideMenu-open')) {
46
+ closeAllMenus()
47
+ } else {
48
+ closeAllMenus()
49
+ body.addClass('contextualSideMenu-open modal-open')
50
+ modalBackdrop.addClass('show')
51
+ }
52
+ }
53
+
54
+ contextualSidebarMenuToggle.click(toggleContextualMenu)
55
+ contextualSidebarMenuClose.click(toggleContextualMenu)
56
+ })
@@ -0,0 +1,143 @@
1
+ // SELECT2 AUTOCOMPLETE JS
2
+ // This JavaScript file allows Spree developers to set up Select2 autocomplete search
3
+ // using the API v2 by simply adding data attributes to a select element with the class: 'select2autocomplete'
4
+ // as shown here: <select class="select2autocomplete"></select>.
5
+
6
+ // REQUIRED ATTRIBUTES
7
+ // You must provide a URL for the API V2, use the format shown below.
8
+ // See the backend.js file for other API V2 URL's.
9
+ //
10
+ // Example:
11
+ // data-autocomplete-url-value="products_api_v2"
12
+
13
+ // OPTIONAL ATTRIBUTES
14
+ // These optional attributes have sensible defaults, you many not need to use them in many cases,
15
+ // but they do provide a powerful toolkit to refine your autocomplete search as required.
16
+ //
17
+ // Examples:
18
+ // data-autocomplete-placeholder-value="Seach Pages" <- Sets the placeholder | DEFAULT is: 'Search'
19
+ // data-autocomplete-clear-value="boolean" <- Allow select2 to be cleared | DEFAULT is: false (no clear button)
20
+ // data-autocomplete-multiple-value="boolean" <- Multiple or Single select | DEFAULT is: false (single)
21
+ // data-autocomplete-return-attr-value="pretty_name" <- Return Attribute. | DEFAULT is: 'name'
22
+ // data-autocomplete-min-input-value="4" <- Minimum input for search | DEFAULT is: 3
23
+ // data-autocomplete-search-query-value="title_i_cont" <- Custom search query | DEFAULT is: 'name_i_cont'
24
+ // data-autocomplete-custom-return-id-value="permalink" <- Return a custom attribute rather than the ID | DEFAULT: returns id
25
+ //
26
+ // SECOND HARD CODED FILTER - (OPTIONAL)
27
+ // Use a second hard coded search filter param and term if you require a little more curation
28
+ // than just all results returning, an example of this in use can be seen in the menu_item search for Pages,
29
+ // here we only want to retuen Pages that have linkable slugs, not homepages, and so we filter those using the
30
+ // data attributes shown below.
31
+ //
32
+ // Examples:
33
+ // data-autocomplete-additional-query-value="type_not_eq" <- Additional hard coded query | DEFAULT: null (not used)
34
+ // data-autocomplete-additional-term-value="Spree::Cms::Pages::Homepage" <- Additional hard coded term | DEFAULT: null (not used)
35
+
36
+ document.addEventListener('DOMContentLoaded', function() {
37
+ const select2Autocompletes = document.querySelectorAll('select.select2autocomplete')
38
+ select2Autocompletes.forEach(element => buildParamsFromDataAttrs(element))
39
+ })
40
+
41
+ function buildParamsFromDataAttrs (element) {
42
+ $(element).select2Autocomplete({
43
+ // Required Attributes
44
+ apiUrl: Spree.routes[element.dataset.autocompleteUrlValue],
45
+
46
+ // Optional Attributes
47
+ placeholder: element.dataset.autocompletePlaceholderValue,
48
+ allow_clear: element.dataset.autocompleteClearValue,
49
+ multiple: element.dataset.autocompleteMultipleValue,
50
+ return_attribute: element.dataset.autocompleteReturnAttrValue,
51
+ minimum_input: element.dataset.autocompleteMinInputValue,
52
+ search_query: element.dataset.autocompleteSearchQueryValue,
53
+ custom_return_id: element.dataset.autocompleteCustomReturnIdValue,
54
+
55
+ // Hard coded additional filter for those edge cases.
56
+ additional_query: element.dataset.autocompleteAdditionalQueryValue,
57
+ additional_term: element.dataset.autocompleteAdditionalTermValue
58
+ })
59
+ }
60
+
61
+ // Can also be called directly as javastript.
62
+ $.fn.select2Autocomplete = function(params) {
63
+ // Required params
64
+ const apiUrl = params.apiUrl || null
65
+
66
+ // Optional Params
67
+ const select2placeHolder = params.placeholder || Spree.translations.search
68
+ const select2Multiple = params.multiple || false
69
+ const select2allowClear = params.allow_clear || false
70
+ const returnAttribute = params.return_attribute || 'name'
71
+ const minimumInput = params.minimum_input || 3
72
+ const searchQuery = params.search_query || 'name_i_cont'
73
+ const customReturnId = params.custom_return_id || null
74
+ const additionalQuery = params.additional_query || null
75
+ const additionalTerm = params.additional_term || null
76
+
77
+ function formatList(values) {
78
+ if (customReturnId) {
79
+ return values.map(function (obj) {
80
+ return {
81
+ id: obj.attributes[customReturnId],
82
+ text: obj.attributes[returnAttribute]
83
+ }
84
+ })
85
+ } else {
86
+ return values.map(function (obj) {
87
+ return {
88
+ id: obj.id,
89
+ text: obj.attributes[returnAttribute]
90
+ }
91
+ })
92
+ }
93
+ }
94
+
95
+ if (additionalQuery == null && additionalTerm == null) {
96
+ this.select2({
97
+ multiple: select2Multiple,
98
+ allowClear: select2allowClear,
99
+ placeholder: select2placeHolder,
100
+ minimumInputLength: minimumInput,
101
+ ajax: {
102
+ url: apiUrl,
103
+ headers: Spree.apiV2Authentication(),
104
+ data: function (params) {
105
+ return {
106
+ filter: {
107
+ [searchQuery]: params.term
108
+ }
109
+ }
110
+ },
111
+ processResults: function(json) {
112
+ return {
113
+ results: formatList(json.data)
114
+ }
115
+ }
116
+ }
117
+ })
118
+ } else {
119
+ this.select2({
120
+ multiple: select2Multiple,
121
+ allowClear: select2allowClear,
122
+ placeholder: select2placeHolder,
123
+ minimumInputLength: minimumInput,
124
+ ajax: {
125
+ url: apiUrl,
126
+ headers: Spree.apiV2Authentication(),
127
+ data: function (params) {
128
+ return {
129
+ filter: {
130
+ [searchQuery]: params.term,
131
+ [additionalQuery]: additionalTerm
132
+ }
133
+ }
134
+ },
135
+ processResults: function(json) {
136
+ return {
137
+ results: formatList(json.data)
138
+ }
139
+ }
140
+ }
141
+ })
142
+ }
143
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ populateSelectOptionsFromApi(params)
3
+
4
+ Allows you to easily fetch data from API (Platfrom v2)
5
+ and populate an empty <select> with <option> tags,
6
+ including a selected <option> tag.
7
+
8
+ ## EXAMPLE USE CASE called from ERB view file:
9
+
10
+ populateSelectOptionsFromApi({
11
+ targetElement: '#mySelectElement',
12
+ apiUrl: Spree.routes.taxons_api_v2,
13
+ returnAttribute: 'pretty_name',
14
+
15
+ <% if @menu_item.linked_resource_id %>
16
+ selectedOption: <%= @menu_item.linked_resource_id %>
17
+ <% end %>
18
+ })
19
+ **/
20
+
21
+ // eslint-disable-next-line no-unused-vars
22
+ const populateSelectOptionsFromApi = function(params) {
23
+ createRequest(params, updateSelectSuccess, updateSelectError)
24
+ }
25
+
26
+ const handleErrors = function(response) {
27
+ if (!response.ok) throw new Error((response.status + ': ' + response.statusText))
28
+
29
+ return response.json()
30
+ }
31
+
32
+ const createRequest = function(params, succeed, fail) {
33
+ const targetElement = params.targetElement
34
+ const apiUrl = params.apiUrl
35
+ const returnAttribute = params.returnAttribute
36
+ const selectedOption = params.selectedOption
37
+ const selectEl = document.querySelector(targetElement)
38
+
39
+ fetch(apiUrl, { headers: Spree.apiV2Authentication() })
40
+ .then((response) => handleErrors(response))
41
+ .then((json) => succeed(json.data, returnAttribute, selectEl, selectedOption))
42
+ .catch((error) => fail(error, selectEl))
43
+ }
44
+
45
+ const updateSelectSuccess = function(parsedData, returnAttribute, selectEl, selectedOption) {
46
+ parsedData.forEach((object) => {
47
+ const optionEl = document.createElement('option')
48
+ optionEl.value = object.id
49
+ optionEl.innerHTML = object.attributes[returnAttribute]
50
+
51
+ if (parseInt(selectedOption, 10) === parseInt(object.id, 10)) optionEl.selected = true
52
+
53
+ selectEl.appendChild(optionEl)
54
+ })
55
+ }
56
+
57
+ const updateSelectError = function(error, selectEl) {
58
+ selectEl.disabled = true
59
+
60
+ console.log(error)
61
+ }