spree_backend 4.2.4 → 4.3.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) 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/backend-missing-image.svg +4 -0
  24. data/app/assets/images/noimage/large.png +0 -0
  25. data/app/assets/images/noimage/mini.png +0 -0
  26. data/app/assets/images/noimage/product.png +0 -0
  27. data/app/assets/images/noimage/small.png +0 -0
  28. data/app/assets/javascripts/spree/backend/address_states.es6 +44 -0
  29. data/app/assets/javascripts/spree/backend/admin.js +45 -307
  30. data/app/assets/javascripts/spree/backend/checkouts/edit.js +22 -13
  31. data/app/assets/javascripts/spree/backend/cms/_index.es6 +4 -0
  32. data/app/assets/javascripts/spree/backend/cms/links.es6 +25 -0
  33. data/app/assets/javascripts/spree/backend/cms/live_preview.es6 +34 -0
  34. data/app/assets/javascripts/spree/backend/cms/page.es6 +133 -0
  35. data/app/assets/javascripts/spree/backend/cms/section.es6 +43 -0
  36. data/app/assets/javascripts/spree/backend/global/_index.js +11 -0
  37. data/app/assets/javascripts/spree/backend/global/alerts.es6 +66 -0
  38. data/app/assets/javascripts/spree/backend/global/api_functions.es6 +5 -0
  39. data/app/assets/javascripts/spree/backend/global/bootstrap.es6 +15 -0
  40. data/app/assets/javascripts/spree/backend/global/flatpickr.es6 +22 -0
  41. data/app/assets/javascripts/spree/backend/global/info_alert.es6 +38 -0
  42. data/app/assets/javascripts/spree/backend/global/radio_panel_toggle.es6 +18 -0
  43. data/app/assets/javascripts/spree/backend/global/ransack.es6 +108 -0
  44. data/app/assets/javascripts/spree/backend/global/responsive_menus.es6 +56 -0
  45. data/app/assets/javascripts/spree/backend/global/select2_autocomplete.es6 +156 -0
  46. data/app/assets/javascripts/spree/backend/global/select2_populate.es6 +61 -0
  47. data/app/assets/javascripts/spree/backend/global/side_scroll_indication.es6 +137 -0
  48. data/app/assets/javascripts/spree/backend/global/sortable.es6 +35 -0
  49. data/app/assets/javascripts/spree/backend/global/tinymce.es6 +11 -0
  50. data/app/assets/javascripts/spree/backend/menus/_index.es6 +2 -0
  51. data/app/assets/javascripts/spree/backend/menus/menu.es6 +57 -0
  52. data/app/assets/javascripts/spree/backend/menus/menu_item.es6 +26 -0
  53. data/app/assets/javascripts/spree/backend/option_type_autocomplete.js +13 -17
  54. data/app/assets/javascripts/spree/backend/option_value_picker.js +10 -22
  55. data/app/assets/javascripts/spree/backend/payments/edit.js +1 -1
  56. data/app/assets/javascripts/spree/backend/payments/new.js +18 -5
  57. data/app/assets/javascripts/spree/backend/spree-select2.js +19 -1
  58. data/app/assets/javascripts/spree/backend/stock_location.js +1 -2
  59. data/app/assets/javascripts/spree/backend/taxon_autocomplete.js +7 -1
  60. data/app/assets/javascripts/spree/backend/taxons.js +74 -73
  61. data/app/assets/javascripts/spree/backend/user_picker.js +7 -10
  62. data/app/assets/javascripts/spree/backend.js +28 -1
  63. data/app/assets/javascripts/spree.js +78 -0
  64. data/app/assets/stylesheets/spree/backend/components/_filters.scss +1 -3
  65. data/app/assets/stylesheets/spree/backend/components/_main.scss +0 -1
  66. data/app/assets/stylesheets/spree/backend/components/_navbar.scss +35 -0
  67. data/app/assets/stylesheets/spree/backend/components/_navigation.scss +13 -0
  68. data/app/assets/stylesheets/spree/backend/components/_sidebar.scss +0 -1
  69. data/app/assets/stylesheets/spree/backend/components/_tables.scss +4 -5
  70. data/app/assets/stylesheets/spree/backend/global/_mixins.scss +59 -0
  71. data/app/assets/stylesheets/spree/backend/plugins/_nav_x.scss +95 -0
  72. data/app/assets/stylesheets/spree/backend/plugins/{select2_bootstrap4.scss → _select2_bootstrap4.scss} +0 -0
  73. data/app/assets/stylesheets/spree/backend/plugins/_sweetalert2_custom.scss +100 -0
  74. data/app/assets/stylesheets/spree/backend/plugins/_tinymce_custom.scss +4 -0
  75. data/app/assets/stylesheets/spree/backend/shared/_base.scss +75 -25
  76. data/app/assets/stylesheets/spree/backend/shared/_forms.scss +8 -0
  77. data/app/assets/stylesheets/spree/backend/spree_admin.css.scss +5 -0
  78. data/app/assets/stylesheets/spree/backend/views/_cms_pages.scss +148 -0
  79. data/app/assets/stylesheets/spree/backend/views/_menus.scss +61 -0
  80. data/app/controllers/concerns/spree/admin/order_concern.rb +24 -0
  81. data/app/controllers/concerns/spree/admin/product_concern.rb +11 -0
  82. data/app/controllers/spree/admin/base_controller.rb +63 -3
  83. data/app/controllers/spree/admin/cms_pages_controller.rb +29 -0
  84. data/app/controllers/spree/admin/cms_sections_controller.rb +15 -0
  85. data/app/controllers/spree/admin/customer_returns_controller.rb +4 -5
  86. data/app/controllers/spree/admin/errors_controller.rb +11 -0
  87. data/app/controllers/spree/admin/general_settings_controller.rb +1 -1
  88. data/app/controllers/spree/admin/images_controller.rb +8 -22
  89. data/app/controllers/spree/admin/log_entries_controller.rb +4 -3
  90. data/app/controllers/spree/admin/menu_items_controller.rb +33 -0
  91. data/app/controllers/spree/admin/menus_controller.rb +32 -0
  92. data/app/controllers/spree/admin/option_types_controller.rb +1 -1
  93. data/app/controllers/spree/admin/orders/customer_details_controller.rb +6 -11
  94. data/app/controllers/spree/admin/orders_controller.rb +23 -31
  95. data/app/controllers/spree/admin/payment_methods_controller.rb +17 -4
  96. data/app/controllers/spree/admin/payments_controller.rb +5 -10
  97. data/app/controllers/spree/admin/prices_controller.rb +2 -2
  98. data/app/controllers/spree/admin/products_controller.rb +21 -10
  99. data/app/controllers/spree/admin/promotion_actions_controller.rb +1 -1
  100. data/app/controllers/spree/admin/promotion_rules_controller.rb +1 -1
  101. data/app/controllers/spree/admin/promotions_controller.rb +3 -3
  102. data/app/controllers/spree/admin/prototypes_controller.rb +1 -1
  103. data/app/controllers/spree/admin/reimbursements_controller.rb +1 -1
  104. data/app/controllers/spree/admin/reports_controller.rb +5 -1
  105. data/app/controllers/spree/admin/resource_controller.rb +32 -5
  106. data/app/controllers/spree/admin/return_index_controller.rb +1 -1
  107. data/app/controllers/spree/admin/state_changes_controller.rb +2 -7
  108. data/app/controllers/spree/admin/stock_items_controller.rb +2 -2
  109. data/app/controllers/spree/admin/stock_locations_controller.rb +2 -2
  110. data/app/controllers/spree/admin/stock_movements_controller.rb +1 -1
  111. data/app/controllers/spree/admin/stock_transfers_controller.rb +1 -1
  112. data/app/controllers/spree/admin/store_credits_controller.rb +13 -8
  113. data/app/controllers/spree/admin/stores_controller.rb +14 -17
  114. data/app/controllers/spree/admin/taxons_controller.rb +9 -5
  115. data/app/controllers/spree/admin/users_controller.rb +9 -7
  116. data/app/controllers/spree/admin/variants_controller.rb +16 -15
  117. data/app/helpers/spree/admin/base_helper.rb +52 -14
  118. data/app/helpers/spree/admin/cms_helper.rb +15 -0
  119. data/app/helpers/spree/admin/menu_helper.rb +30 -0
  120. data/app/helpers/spree/admin/stores_helper.rb +21 -0
  121. data/app/models/spree/backend_configuration.rb +2 -0
  122. data/app/views/spree/admin/adjustments/_adjustment.html.erb +7 -5
  123. data/app/views/spree/admin/cms_pages/_form.html.erb +135 -0
  124. data/app/views/spree/admin/cms_pages/_live_preview_area.html.erb +61 -0
  125. data/app/views/spree/admin/cms_pages/_section_template.html.erb +16 -0
  126. data/app/views/spree/admin/cms_pages/edit.html.erb +21 -0
  127. data/app/views/spree/admin/cms_pages/index.html.erb +84 -0
  128. data/app/views/spree/admin/cms_pages/new.html.erb +8 -0
  129. data/app/views/spree/admin/cms_sections/_form.html.erb +69 -0
  130. data/app/views/spree/admin/cms_sections/edit.html.erb +19 -0
  131. data/app/views/spree/admin/cms_sections/new.html.erb +11 -0
  132. data/app/views/spree/admin/cms_sections/types/_featured_article.html.erb +50 -0
  133. data/app/views/spree/admin/cms_sections/types/_hero_image.html.erb +62 -0
  134. data/app/views/spree/admin/cms_sections/types/_image_gallery.html.erb +177 -0
  135. data/app/views/spree/admin/cms_sections/types/_product_carousel.html.erb +5 -0
  136. data/app/views/spree/admin/cms_sections/types/_rich_text_content.html.erb +4 -0
  137. data/app/views/spree/admin/cms_sections/types/_side_by_side_images.html.erb +121 -0
  138. data/app/views/spree/admin/countries/index.html.erb +5 -3
  139. data/app/views/spree/admin/customer_returns/_reimbursements_table.html.erb +6 -4
  140. data/app/views/spree/admin/customer_returns/_return_item_decision.html.erb +9 -7
  141. data/app/views/spree/admin/customer_returns/index.html.erb +4 -2
  142. data/app/views/spree/admin/errors/forbidden.html.erb +0 -0
  143. data/app/views/spree/admin/images/index.html.erb +8 -4
  144. data/app/views/spree/admin/menu_items/_form.html.erb +115 -0
  145. data/app/views/spree/admin/menu_items/edit.html.erb +11 -0
  146. data/app/views/spree/admin/menu_items/new.html.erb +11 -0
  147. data/app/views/spree/admin/menus/_form.html.erb +19 -0
  148. data/app/views/spree/admin/menus/edit.html.erb +57 -0
  149. data/app/views/spree/admin/menus/index.html.erb +90 -0
  150. data/app/views/spree/admin/menus/nested_menu_items/_item_bar.html.erb +30 -0
  151. data/app/views/spree/admin/menus/new.html.erb +22 -0
  152. data/app/views/spree/admin/option_types/_form.html.erb +3 -0
  153. data/app/views/spree/admin/option_types/_option_value_fields.html.erb +5 -1
  154. data/app/views/spree/admin/option_types/index.html.erb +5 -3
  155. data/app/views/spree/admin/orders/_channel_form.html.erb +2 -2
  156. data/app/views/spree/admin/orders/_line_items.html.erb +10 -8
  157. data/app/views/spree/admin/orders/_shipment.html.erb +26 -18
  158. data/app/views/spree/admin/orders/_shipment_manifest.html.erb +11 -9
  159. data/app/views/spree/admin/orders/customer_details/_autocomplete.js.erb +2 -2
  160. data/app/views/spree/admin/orders/index.html.erb +100 -101
  161. data/app/views/spree/admin/payment_methods/_form.html.erb +6 -4
  162. data/app/views/spree/admin/payment_methods/edit.html.erb +1 -1
  163. data/app/views/spree/admin/payment_methods/index.html.erb +22 -3
  164. data/app/views/spree/admin/payment_methods/new.html.erb +1 -1
  165. data/app/views/spree/admin/payments/_list.html.erb +9 -7
  166. data/app/views/spree/admin/prices/_variant_prices.html.erb +7 -14
  167. data/app/views/spree/admin/product_properties/_product_property_fields.html.erb +9 -7
  168. data/app/views/spree/admin/products/_autocomplete.js.erb +10 -6
  169. data/app/views/spree/admin/products/_form.html.erb +35 -5
  170. data/app/views/spree/admin/products/index.html.erb +15 -14
  171. data/app/views/spree/admin/products/new.html.erb +6 -1
  172. data/app/views/spree/admin/products/stock.html.erb +71 -68
  173. data/app/views/spree/admin/promotion_categories/index.html.erb +5 -3
  174. data/app/views/spree/admin/promotions/_form.html.erb +7 -0
  175. data/app/views/spree/admin/promotions/actions/_create_item_adjustments.html.erb +1 -0
  176. data/app/views/spree/admin/promotions/calculators/_default_fields.html.erb +2 -1
  177. data/app/views/spree/admin/promotions/index.html.erb +33 -34
  178. data/app/views/spree/admin/properties/_form.html.erb +6 -0
  179. data/app/views/spree/admin/properties/index.html.erb +19 -3
  180. data/app/views/spree/admin/prototypes/_form.html.erb +1 -1
  181. data/app/views/spree/admin/prototypes/_prototypes.html.erb +8 -6
  182. data/app/views/spree/admin/prototypes/index.html.erb +5 -3
  183. data/app/views/spree/admin/reimbursement_types/index.html.erb +5 -3
  184. data/app/views/spree/admin/reports/index.html.erb +1 -1
  185. data/app/views/spree/admin/reports/sales_total.html.erb +1 -1
  186. data/app/views/spree/admin/return_authorizations/_form.html.erb +2 -2
  187. data/app/views/spree/admin/return_authorizations/index.html.erb +7 -5
  188. data/app/views/spree/admin/return_index/customer_returns.html.erb +4 -2
  189. data/app/views/spree/admin/return_index/return_authorizations.html.erb +5 -3
  190. data/app/views/spree/admin/roles/index.html.erb +5 -3
  191. data/app/views/spree/admin/shared/_account_nav.html.erb +5 -5
  192. data/app/views/spree/admin/shared/_address_form.html.erb +5 -4
  193. data/app/views/spree/admin/shared/_content_header.html.erb +20 -6
  194. data/app/views/spree/admin/shared/_head.html.erb +2 -1
  195. data/app/views/spree/admin/shared/_header.html.erb +7 -10
  196. data/app/views/spree/admin/shared/_link_fields.html.erb +22 -0
  197. data/app/views/spree/admin/shared/_main_menu.html.erb +19 -4
  198. data/app/views/spree/admin/shared/_order_tabs.html.erb +1 -10
  199. data/app/views/spree/admin/shared/_paths.html.erb +8 -0
  200. data/app/views/spree/admin/shared/_refunds.html.erb +4 -2
  201. data/app/views/spree/admin/shared/_sidebar.html.erb +1 -1
  202. data/app/views/spree/admin/shared/_store_switcher.html.erb +23 -0
  203. data/app/views/spree/admin/shared/_table_filter.html.erb +6 -6
  204. data/app/views/spree/admin/shared/_translations.html.erb +2 -0
  205. data/app/views/spree/admin/shared/cms/_spree_product.html.erb +14 -0
  206. data/app/views/spree/admin/shared/cms/_spree_taxon.html.erb +14 -0
  207. data/app/views/spree/admin/shared/linkables/_home_page.html.erb +3 -0
  208. data/app/views/spree/admin/shared/linkables/_spree_cms_page.erb +28 -0
  209. data/app/views/spree/admin/shared/linkables/_spree_product.html.erb +20 -0
  210. data/app/views/spree/admin/shared/linkables/_spree_taxon.html.erb +22 -0
  211. data/app/views/spree/admin/shared/linkables/_url.html.erb +16 -0
  212. data/app/views/spree/admin/shared/named_types/_index.html.erb +7 -5
  213. data/app/views/spree/admin/shared/sub_menu/_configuration.html.erb +1 -3
  214. data/app/views/spree/admin/shared/sub_menu/_content.html.erb +4 -0
  215. data/app/views/spree/admin/shared/sub_menu/_stock.html.erb +4 -0
  216. data/app/views/spree/admin/shipping_categories/index.html.erb +5 -3
  217. data/app/views/spree/admin/shipping_methods/index.html.erb +5 -3
  218. data/app/views/spree/admin/states/_state_list.html.erb +5 -3
  219. data/app/views/spree/admin/stock_locations/index.html.erb +5 -3
  220. data/app/views/spree/admin/stock_transfers/index.html.erb +5 -4
  221. data/app/views/spree/admin/stock_transfers/new.html.erb +9 -7
  222. data/app/views/spree/admin/store_credit_categories/index.html.erb +5 -3
  223. data/app/views/spree/admin/store_credits/index.html.erb +7 -5
  224. data/app/views/spree/admin/stores/_form.html.erb +12 -2
  225. data/app/views/spree/admin/stores/index.html.erb +12 -10
  226. data/app/views/spree/admin/tax_categories/index.html.erb +5 -3
  227. data/app/views/spree/admin/tax_rates/index.html.erb +5 -3
  228. data/app/views/spree/admin/taxonomies/_list.html.erb +5 -3
  229. data/app/views/spree/admin/taxons/_form.html.erb +1 -1
  230. data/app/views/spree/admin/users/_addresses_form.html.erb +2 -4
  231. data/app/views/spree/admin/users/_lifetime_stats.html.erb +16 -4
  232. data/app/views/spree/admin/users/index.html.erb +5 -3
  233. data/app/views/spree/admin/users/items.html.erb +1 -1
  234. data/app/views/spree/admin/variants/_autocomplete.js.erb +6 -2
  235. data/app/views/spree/admin/variants/_autocomplete_line_items_stock.js.erb +18 -12
  236. data/app/views/spree/admin/variants/_autocomplete_stock.js.erb +12 -8
  237. data/app/views/spree/admin/variants/_split.js.erb +9 -7
  238. data/app/views/spree/admin/variants/index.html.erb +8 -5
  239. data/app/views/spree/admin/zones/index.html.erb +5 -3
  240. data/app/views/spree/layouts/admin.html.erb +16 -16
  241. data/config/initializers/assets.rb +5 -1
  242. data/config/routes.rb +14 -2
  243. data/lib/generators/spree/backend/install/install_generator.rb +22 -0
  244. data/lib/generators/spree/backend/install/templates/vendor/assets/javascripts/spree/backend/all.js +8 -0
  245. data/lib/generators/spree/backend/install/templates/vendor/assets/stylesheets/spree/backend/all.css +9 -0
  246. data/lib/spree/backend/engine.rb +4 -11
  247. data/lib/spree/backend.rb +7 -4
  248. data/lib/spree_backend.rb +0 -2
  249. data/spec/fixtures/files/favicon.ico +0 -0
  250. data/spec/fixtures/files/icon_512x512.png +0 -0
  251. data/spree_backend.gemspec +16 -11
  252. data/vendor/assets/javascripts/cleave.js +8 -0
  253. data/vendor/assets/javascripts/jsonapi-serializer.min.js +8 -0
  254. data/vendor/assets/javascripts/jsuri.js +458 -0
  255. data/vendor/assets/javascripts/sortable.js +2 -3709
  256. data/vendor/assets/javascripts/sweetalert2.js +2 -0
  257. metadata +208 -42
  258. data/app/assets/javascripts/spree/backend/address_states.js +0 -44
  259. data/app/assets/javascripts/spree/frontend/backend.js +0 -1
  260. data/app/assets/stylesheets/spree/frontend/backend.css +0 -1
  261. data/app/views/spree/admin/orders/_store_form.html.erb +0 -18
@@ -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,156 @@
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
+ loadAutoCompleteParams()
38
+ })
39
+
40
+ // eslint-disable-next-line no-unused-vars
41
+ function loadAutoCompleteParams() {
42
+ const select2Autocompletes = document.querySelectorAll('select[data-autocomplete-url-value]')
43
+ select2Autocompletes.forEach(element => buildParamsFromDataAttrs(element))
44
+ }
45
+
46
+ function buildParamsFromDataAttrs(element) {
47
+ $(element).select2Autocomplete({
48
+ // Required Attributes
49
+ apiUrl: Spree.routes[element.dataset.autocompleteUrlValue],
50
+
51
+ // Optional Attributes
52
+ placeholder: element.dataset.autocompletePlaceholderValue,
53
+ allow_clear: element.dataset.autocompleteClearValue,
54
+ multiple: element.dataset.autocompleteMultipleValue,
55
+ return_attribute: element.dataset.autocompleteReturnAttrValue,
56
+ minimum_input: element.dataset.autocompleteMinInputValue,
57
+ search_query: element.dataset.autocompleteSearchQueryValue,
58
+ custom_return_id: element.dataset.autocompleteCustomReturnIdValue,
59
+
60
+ // Hard coded additional filter for those edge cases.
61
+ additional_query: element.dataset.autocompleteAdditionalQueryValue,
62
+ additional_term: element.dataset.autocompleteAdditionalTermValue
63
+ })
64
+ }
65
+
66
+ // Can also be called directly as javastript.
67
+ $.fn.select2Autocomplete = function(params) {
68
+ // Required params
69
+ const apiUrl = params.apiUrl || null
70
+ const resourcePlural = apiUrl.match(/([^/]*)\/*$/)[1]
71
+ const resourceSingular = resourcePlural.slice(0, -1)
72
+
73
+ // Optional Params
74
+ const select2placeHolder = params.placeholder || Spree.translations.search
75
+ const select2Multiple = params.multiple || false
76
+ const select2allowClear = params.allow_clear || false
77
+ const returnAttribute = params.return_attribute || 'name'
78
+ const minimumInput = params.minimum_input || 3
79
+ const searchQuery = params.search_query || 'name_i_cont'
80
+ const customReturnId = params.custom_return_id || null
81
+ const additionalQuery = params.additional_query || null
82
+ const additionalTerm = params.additional_term || null
83
+
84
+ function formatList(values) {
85
+ if (customReturnId) {
86
+ return values.map(function(obj) {
87
+ return {
88
+ id: obj.attributes[customReturnId],
89
+ text: obj.attributes[returnAttribute]
90
+ }
91
+ })
92
+ } else {
93
+ return values.map(function(obj) {
94
+ return {
95
+ id: obj.id,
96
+ text: obj.attributes[returnAttribute]
97
+ }
98
+ })
99
+ }
100
+ }
101
+
102
+ if (additionalQuery == null && additionalTerm == null) {
103
+ this.select2({
104
+ multiple: select2Multiple,
105
+ allowClear: select2allowClear,
106
+ placeholder: select2placeHolder,
107
+ minimumInputLength: minimumInput,
108
+ ajax: {
109
+ url: apiUrl,
110
+ headers: Spree.apiV2Authentication(),
111
+ data: function(params) {
112
+ return {
113
+ fields: {
114
+ [resourceSingular]: returnAttribute
115
+ },
116
+ filter: {
117
+ [searchQuery]: params.term
118
+ }
119
+ }
120
+ },
121
+ processResults: function(json) {
122
+ return {
123
+ results: formatList(json.data)
124
+ }
125
+ }
126
+ }
127
+ })
128
+ } else {
129
+ this.select2({
130
+ multiple: select2Multiple,
131
+ allowClear: select2allowClear,
132
+ placeholder: select2placeHolder,
133
+ minimumInputLength: minimumInput,
134
+ ajax: {
135
+ url: apiUrl,
136
+ headers: Spree.apiV2Authentication(),
137
+ data: function(params) {
138
+ return {
139
+ fields: {
140
+ [resourceSingular]: returnAttribute
141
+ },
142
+ filter: {
143
+ [searchQuery]: params.term,
144
+ [additionalQuery]: additionalTerm
145
+ }
146
+ }
147
+ },
148
+ processResults: function(json) {
149
+ return {
150
+ results: formatList(json.data)
151
+ }
152
+ }
153
+ }
154
+ })
155
+ }
156
+ }
@@ -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
+ }
@@ -0,0 +1,137 @@
1
+ document.addEventListener('DOMContentLoaded', function () {
2
+ const navWrapper = document.querySelectorAll('[data-nav-x-wrapper]')
3
+ navWrapper.forEach(el => initHorizontalNav(el))
4
+ })
5
+
6
+ const SETTINGS = {
7
+ navBarTravelling: false,
8
+ navBarTravelDirection: '',
9
+ navBarTravelDistance: 150
10
+ }
11
+
12
+ function initHorizontalNav (containerEl) {
13
+ const navAdvanceLeft = containerEl.querySelector('.nav-x_Advancer_Left')
14
+ const navAdvanceRight = containerEl.querySelector('.nav-x_Advancer_Right')
15
+ const navContainer = containerEl.querySelector('[data-nav-x-container]')
16
+ const navContent = navContainer.querySelector('[data-nav-x-content]')
17
+ const activeNavItem = navContent.querySelector('.active')
18
+
19
+ // Trigger on DOMContentLoaded
20
+ setOverscrollIndicators()
21
+
22
+ if (activeNavItem) focusActiveItem(navContainer, activeNavItem)
23
+
24
+ window.addEventListener('resize', function () {
25
+ // Trigger on window resize
26
+ setOverscrollIndicators()
27
+ focusActiveItem(navContainer, activeNavItem)
28
+ })
29
+
30
+ navContainer.addEventListener('scroll', function () {
31
+ // Trigger on Side Scrolling
32
+ setOverscrollIndicators()
33
+ })
34
+
35
+ function setOverscrollIndicators () {
36
+ navContainer.setAttribute('data-overflowing', determineOverflow(navContent, navContainer))
37
+ }
38
+
39
+ navAdvanceLeft.addEventListener('click', function () {
40
+ // If in the middle of a move return
41
+ if (SETTINGS.navBarTravelling === true) return
42
+
43
+ // If we have content overflowing both sides or on the left
44
+ if (determineOverflow(navContent, navContainer) === 'left' || determineOverflow(navContent, navContainer) === 'both') {
45
+ // Find how far this panel has been scrolled
46
+ const availableScrollLeft = navContainer.scrollLeft
47
+ // If the space available is less than two lots of our desired distance, just move the whole amount
48
+ // otherwise, move by the amount in the settings
49
+ if (availableScrollLeft < SETTINGS.navBarTravelDistance * 2) {
50
+ navContent.style.transform = `translateX(${availableScrollLeft}px)`
51
+ } else {
52
+ navContent.style.transform = `translateX(${SETTINGS.navBarTravelDistance}px)`
53
+ }
54
+ // We do want a transition (this is set in CSS) when moving so remove the class that would prevent that
55
+ navContent.classList.remove('nav-x_Transition_None')
56
+ // Update our settings
57
+ SETTINGS.navBarTravelDirection = 'left'
58
+ SETTINGS.navBarTravelling = true
59
+ }
60
+ // Now update the attribute in the DOM
61
+ navContainer.setAttribute('data-overflowing', determineOverflow(navContent, navContainer))
62
+ })
63
+
64
+ navAdvanceRight.addEventListener('click', function () {
65
+ // If in the middle of a move return
66
+ if (SETTINGS.navBarTravelling === true) return
67
+
68
+ // If we have content overflowing both sides or on the right
69
+ if (determineOverflow(navContent, navContainer) === 'right' || determineOverflow(navContent, navContainer) === 'both') {
70
+ // Get the right edge of the container and content
71
+ const navBarRightEdge = navContent.getBoundingClientRect().right
72
+ const navBarScrollerRightEdge = navContainer.getBoundingClientRect().right
73
+ // Now we know how much space we have available to scroll
74
+ const availableScrollRight = Math.floor(navBarRightEdge - navBarScrollerRightEdge)
75
+ // If the space available is less than two lots of our desired distance, just move the whole amount
76
+ // otherwise, move by the amount in the settings
77
+ if (availableScrollRight < SETTINGS.navBarTravelDistance * 2) {
78
+ navContent.style.transform = `translateX(-${availableScrollRight}px)`
79
+ } else {
80
+ navContent.style.transform = `translateX(-${SETTINGS.navBarTravelDistance}px)`
81
+ }
82
+ // We do want a transition (this is set in CSS) when moving so remove the class that would prevent that
83
+ navContent.classList.remove('nav-x_Transition_None')
84
+ // Update our settings
85
+ SETTINGS.navBarTravelDirection = 'right'
86
+ SETTINGS.navBarTravelling = true
87
+ }
88
+ // Now update the attribute in the DOM
89
+ navContainer.setAttribute('data-overflowing', determineOverflow(navContent, navContainer))
90
+ })
91
+
92
+ navContent.addEventListener('transitionend', function () {
93
+ // get the value of the transform, apply that to the current scroll position (so get the scroll pos first) and then remove the transform
94
+ const styleOfTransform = window.getComputedStyle(navContent, null)
95
+ const tr = styleOfTransform.getPropertyValue('transform') || styleOfTransform.getPropertyValue('transform')
96
+ // If there is no transition we want to default to 0 and not null
97
+
98
+ const amount = Math.abs(parseInt(tr.split(',')[4]) || 0)
99
+
100
+ navContent.style.transform = 'none'
101
+ navContent.classList.add('nav-x_Transition_None')
102
+ // Now lets set the scroll position
103
+ if (SETTINGS.navBarTravelDirection === 'left') {
104
+ navContainer.scrollLeft = navContainer.scrollLeft - amount
105
+ } else {
106
+ navContainer.scrollLeft = navContainer.scrollLeft + amount
107
+ }
108
+ SETTINGS.navBarTravelling = false
109
+ })
110
+ }
111
+
112
+ // Set active link into view
113
+ function focusActiveItem (containerEl, activeEl) {
114
+ if (!activeEl) return
115
+
116
+ containerEl.scrollLeft = activeEl.offsetLeft - 45
117
+ }
118
+
119
+ // Determine Scroll status
120
+ function determineOverflow (content, container) {
121
+ const containerMetrics = container.getBoundingClientRect()
122
+ const containerMetricsRight = Math.floor(containerMetrics.right)
123
+ const containerMetricsLeft = Math.floor(containerMetrics.left)
124
+ const contentMetrics = content.getBoundingClientRect()
125
+ const contentMetricsRight = Math.floor(contentMetrics.right)
126
+ const contentMetricsLeft = Math.floor(contentMetrics.left)
127
+
128
+ if (containerMetricsLeft > contentMetricsLeft && containerMetricsRight < contentMetricsRight) {
129
+ return 'both'
130
+ } else if (contentMetricsLeft < containerMetricsLeft) {
131
+ return 'left'
132
+ } else if (contentMetricsRight > containerMetricsRight) {
133
+ return 'right'
134
+ } else {
135
+ return 'none'
136
+ }
137
+ }