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,35 @@
1
+ document.addEventListener('DOMContentLoaded', function() {
2
+ var parentEl = document.getElementsByClassName('sortable')[0];
3
+ if (parentEl) {
4
+ var element = parentEl.querySelector('tbody')
5
+ }
6
+
7
+ if (element) {
8
+ Sortable.create(element, {
9
+ handle: '.move-handle',
10
+ animation: 550,
11
+ ghostClass: 'bg-light',
12
+ dragClass: 'sortable-drag-v',
13
+ easing: 'cubic-bezier(1, 0, 0, 1)',
14
+ swapThreshold: 0.9,
15
+ forceFallback: true,
16
+ onEnd: function(evt) {
17
+ var itemEl = evt.item
18
+ var positions = { authenticity_token: AUTH_TOKEN }
19
+ $.each($('tr', element), function(position, obj) {
20
+ var reg = /spree_(\w+_?)+_(\d+)/
21
+ var parts = reg.exec($(obj).prop('id'))
22
+ if (parts) {
23
+ positions['positions[' + parts[2] + ']'] = position + 1
24
+ }
25
+ })
26
+ $.ajax({
27
+ type: 'POST',
28
+ dataType: 'json',
29
+ url: $(itemEl).closest('table.sortable').data('sortable-link'),
30
+ data: positions
31
+ })
32
+ }
33
+ })
34
+ }
35
+ })
@@ -0,0 +1,11 @@
1
+ document.addEventListener('DOMContentLoaded', function() {
2
+ // eslint-disable-next-line no-undef
3
+ tinymce.init({
4
+ selector: '.spree-rte',
5
+ plugins: [
6
+ 'image table paste code link table'
7
+ ],
8
+ menubar: false,
9
+ toolbar: 'undo redo | styleselect | bold italic link forecolor backcolor | alignleft aligncenter alignright alignjustify | table | bullist numlist outdent indent | code '
10
+ });
11
+ })
@@ -0,0 +1,2 @@
1
+ //= require spree/backend/menus/menu
2
+ //= require spree/backend/menus/menu_item
@@ -0,0 +1,57 @@
1
+ /* eslint-disable no-new */
2
+
3
+ document.addEventListener('DOMContentLoaded', function() {
4
+ const menuItemSortable = {
5
+ group: {
6
+ name: 'sortable-menu',
7
+ pull: true,
8
+ put: true
9
+ },
10
+ handle: '.move-handle',
11
+ swapThreshold: 0.5,
12
+ emptyInsertThreshold: 8,
13
+ dragClass: 'menu-item-dragged',
14
+ draggable: '.dragable',
15
+ animation: 350,
16
+ forceFallback: false,
17
+ onEnd: function (evt) {
18
+ handleMenuItemMove(evt)
19
+ }
20
+ }
21
+
22
+ let containers = null;
23
+ containers = document.querySelectorAll('.menu-container');
24
+
25
+ for (let i = 0; i < containers.length; i++) {
26
+ new Sortable(containers[i], menuItemSortable);
27
+ }
28
+ })
29
+
30
+ function handleMenuItemMove(evt) {
31
+ const data = {
32
+ new_parent_id: parseInt(evt.to.dataset.parentId, 10) || null,
33
+ new_position_idx: parseInt(evt.newIndex, 10)
34
+ }
35
+
36
+ fetch(`${Spree.routes.menus_items_api_v2}/${evt.item.dataset.itemId}/reposition`, {
37
+ method: 'PATCH',
38
+ headers: {
39
+ Authorization: 'Bearer ' + OAUTH_TOKEN,
40
+ 'Content-Type': 'application/json'
41
+ },
42
+ body: JSON.stringify(data)
43
+ })
44
+ .then(response => {
45
+ if (response.ok !== true) {
46
+ handleMenuItemMoveError()
47
+ }
48
+ })
49
+ .catch(err => {
50
+ console.error(err);
51
+ });
52
+ }
53
+
54
+ function handleMenuItemMoveError () {
55
+ // eslint-disable-next-line no-undef
56
+ show_flash('error', Spree.translations.move_could_not_be_saved)
57
+ }
@@ -0,0 +1,26 @@
1
+ document.addEventListener('DOMContentLoaded', function() {
2
+ const menuItemType = $('#menu_item_item_type').select2()
3
+
4
+ updateContainerMessage()
5
+
6
+ menuItemType.on('change', function() {
7
+ updateContainerMessage()
8
+ });
9
+
10
+ function updateContainerMessage () {
11
+ const linkSettingsPanel = document.getElementById('LinkSettings')
12
+
13
+ if (!linkSettingsPanel) return
14
+
15
+ const selectedLinkType = $('#menu_item_item_type').val()
16
+ const usingConainerMessage = document.getElementById('usingContainerInfo')
17
+
18
+ if (selectedLinkType === 'Container') {
19
+ linkSettingsPanel.classList.add('d-none')
20
+ usingConainerMessage.classList.remove('d-none')
21
+ } else {
22
+ linkSettingsPanel.classList.remove('d-none')
23
+ usingConainerMessage.classList.add('d-none')
24
+ }
25
+ }
26
+ })
@@ -1,37 +1,33 @@
1
1
  $.fn.optionTypeAutocomplete = function () {
2
2
  'use strict'
3
3
 
4
+ console.warn('optionTypeAutocomplete is deprecated and will be removed in Spree 5.0')
5
+
4
6
  this.select2({
5
7
  minimumInputLength: 2,
6
8
  multiple: true,
7
9
  ajax: {
8
- url: Spree.routes.option_types_api,
10
+ url: Spree.routes.option_types_api_v2,
9
11
  datatype: 'json',
12
+ headers: Spree.apiV2Authentication(),
10
13
  data: function (params) {
11
- var query = {
12
- q: {
13
- name_cont: params.term
14
- },
15
- token: Spree.api_key
14
+ return {
15
+ filter: {
16
+ name_i_cont: params.term
17
+ }
16
18
  }
17
-
18
- return query
19
19
  },
20
20
  processResults: function (data) {
21
- return {
22
- results: data
23
- }
21
+ return formatSelect2Options(data)
24
22
  }
25
- },
26
- templateResult: function (optionType) {
27
- return optionType.name
28
- },
29
- templateSelection: function (optionType) {
30
- return optionType.text
31
23
  }
32
24
  })
33
25
  }
34
26
 
35
27
  $(document).ready(function () {
28
+ var productOptionTypeSelector = document.getElementById('product_option_type_ids')
29
+ if (productOptionTypeSelector == null) return
30
+ if (productOptionTypeSelector.hasAttribute('data-autocomplete-url-value')) return
31
+
36
32
  $('#product_option_type_ids').optionTypeAutocomplete()
37
33
  })
@@ -9,26 +9,20 @@ $.fn.optionValueAutocomplete = function (options) {
9
9
  var values = options.values
10
10
  var clearSelection = options.clearSelection
11
11
 
12
- function formatOptionValueList(values) {
13
- return values.map(function(obj) {
14
- return { id: obj.id, text: obj.name }
15
- })
16
- }
17
-
18
12
  function addOptions(select, productId, values) {
19
13
  $.ajax({
20
14
  type: 'GET',
21
- url: Spree.routes.option_values_api,
15
+ url: Spree.routes.option_values_api_v2,
16
+ headers: Spree.apiV2Authentication(),
22
17
  dataType: 'json',
23
18
  data: {
24
- token: Spree.api_key,
25
- q: {
19
+ filter: {
26
20
  id_in: values,
27
21
  variants_product_id_eq: productId
28
22
  }
29
23
  }
30
24
  }).then(function (data) {
31
- select.addSelect2Options(data)
25
+ select.addSelect2Options(data.data)
32
26
  })
33
27
  }
34
28
 
@@ -36,27 +30,21 @@ $.fn.optionValueAutocomplete = function (options) {
36
30
  multiple: multiple,
37
31
  minimumInputLength: 1,
38
32
  ajax: {
39
- url: Spree.routes.option_values_api,
33
+ url: Spree.routes.option_values_api_v2,
40
34
  dataType: 'json',
35
+ headers: Spree.apiV2Authentication(),
41
36
  data: function (params) {
42
37
  var selectedProductId = typeof (productSelect) !== 'undefined' ? productSelect.val() : null
43
38
 
44
- var query = {
45
- q: {
39
+ return {
40
+ filter: {
46
41
  name_cont: params.term,
47
42
  variants_product_id_eq: selectedProductId
48
- },
49
- token: Spree.api_key
43
+ }
50
44
  }
51
-
52
- return query;
53
45
  },
54
46
  processResults: function(data) {
55
- var results = formatOptionValueList(data)
56
-
57
- return {
58
- results: results
59
- }
47
+ return formatSelect2Options(data)
60
48
  }
61
49
  }
62
50
  })
@@ -115,7 +115,7 @@ jQuery(function ($) {
115
115
  }
116
116
 
117
117
  PaymentView.prototype.$actions = function () {
118
- return this.$el.find('.actions')
118
+ return this.$el.find('.payment-action-buttons')
119
119
  }
120
120
 
121
121
  PaymentView.prototype.$amount = function () {
@@ -2,11 +2,29 @@
2
2
 
3
3
  $(document).ready(function () {
4
4
  if ($('#new_payment').length) {
5
+ var cardCodeCleave;
6
+ var updateCardCodeCleave = function (length) {
7
+ if (cardCodeCleave) cardCodeCleave.destroy()
8
+
9
+ cardCodeCleave = new Cleave('.cardCode', {
10
+ numericOnly: true,
11
+ blocks: [length]
12
+ })
13
+ }
14
+
15
+ updateCardCodeCleave(3)
16
+
5
17
  /* eslint-disable no-new */
6
18
  new Cleave('.cardNumber', {
7
19
  creditCard: true,
8
20
  onCreditCardTypeChanged: function (type) {
9
21
  $('.ccType').val(type)
22
+
23
+ if (type === 'amex') {
24
+ updateCardCodeCleave(4)
25
+ } else {
26
+ updateCardCodeCleave(3)
27
+ }
10
28
  }
11
29
  })
12
30
  /* eslint-disable no-new */
@@ -14,11 +32,6 @@ $(document).ready(function () {
14
32
  date: true,
15
33
  datePattern: ['m', 'Y']
16
34
  })
17
- /* eslint-disable no-new */
18
- new Cleave('.cardCode', {
19
- numericOnly: true,
20
- blocks: [3]
21
- })
22
35
 
23
36
  $('.payment_methods_radios').click(
24
37
  function () {
@@ -16,7 +16,14 @@ $.fn.addSelect2Options = function (data) {
16
16
  var select = this
17
17
 
18
18
  function appendOption(select, data) {
19
- var option = new Option(data.name, data.id, true, true)
19
+ var option = null;
20
+ if (data.attributes) {
21
+ // API v2
22
+ option = new Option(data.attributes.name, data.id, true, true)
23
+ } else {
24
+ // API v1
25
+ option = new Option(data.name, data.id, true, true)
26
+ }
20
27
  select.append(option).trigger('change')
21
28
  }
22
29
 
@@ -38,3 +45,14 @@ $.fn.addSelect2Options = function (data) {
38
45
  $.fn.select2.defaults.set('width', 'style')
39
46
  $.fn.select2.defaults.set('dropdownAutoWidth', false)
40
47
  $.fn.select2.defaults.set('theme', 'bootstrap4')
48
+
49
+ function formatSelect2Options(data) {
50
+ var results = data.data.map(function (obj) {
51
+ return {
52
+ id: obj.id,
53
+ text: obj.attributes.name
54
+ }
55
+ })
56
+
57
+ return { results: results }
58
+ }
@@ -1,4 +1,3 @@
1
- /* global update_state */
2
1
  $(document).ready(function () {
3
- $('[data-hook=stock_location_country] span#country .select2').on('change', function () { update_state('') })
2
+ $('[data-hook=stock_location_country] span#country .select2').on('change', function () { updateAddressState('') })
4
3
  })
@@ -2,6 +2,8 @@ $.fn.taxonAutocomplete = function() {
2
2
  'use strict'
3
3
 
4
4
  function formatTaxonList(values) {
5
+ console.warn('taxonAutocomplete is deprecated and will be removed in Spree 5.0')
6
+
5
7
  return values.map(function (obj) {
6
8
  return {
7
9
  id: obj.id,
@@ -20,7 +22,7 @@ $.fn.taxonAutocomplete = function() {
20
22
  data: function (params) {
21
23
  return {
22
24
  q: {
23
- name_cont: params.term,
25
+ name_cont: params.term
24
26
  },
25
27
  token: Spree.api_key
26
28
  }
@@ -35,5 +37,9 @@ $.fn.taxonAutocomplete = function() {
35
37
  }
36
38
 
37
39
  $(document).ready(function () {
40
+ var productTaxonSelector = document.getElementById('product_taxon_ids')
41
+ if (productTaxonSelector == null) return
42
+ if (productTaxonSelector.hasAttribute('data-autocomplete-url-value')) return
43
+
38
44
  $('#product_taxon_ids').taxonAutocomplete()
39
45
  })
@@ -1,4 +1,4 @@
1
- /* global productTemplate, Sortable */
1
+ /* global productTemplate */
2
2
  $(function () {
3
3
  window.productTemplate = Handlebars.compile($('#product_template').text())
4
4
  var taxonProducts = $('#taxon_products')
@@ -14,17 +14,17 @@ $(function () {
14
14
  swapThreshold: 0.9,
15
15
  forceFallback: true,
16
16
  onEnd: function (evt) {
17
- var itemEl = evt.item.getAttribute('data-product-id')
18
- var newin = evt.newIndex
17
+ var classificationId = evt.item.getAttribute('data-classification-id')
18
+ var newIndex = evt.newIndex
19
19
  return $.ajax({
20
- url: Spree.routes.classifications_api,
20
+ url: Spree.routes.classifications_api_v2 + '/' + classificationId.toString() + '/reposition',
21
+ headers: Spree.apiV2Authentication(),
21
22
  method: 'PUT',
22
23
  dataType: 'json',
23
24
  data: {
24
- token: Spree.api_key,
25
- product_id: itemEl,
26
- taxon_id: $('#taxon_id').val(),
27
- position: newin
25
+ classification: {
26
+ position: newIndex
27
+ }
28
28
  }
29
29
  })
30
30
  }
@@ -37,22 +37,27 @@ $(function () {
37
37
  minimumInputLength: 3,
38
38
  multiple: false,
39
39
  ajax: {
40
- url: Spree.routes.taxons_api,
40
+ url: Spree.routes.taxons_api_v2,
41
41
  datatype: 'json',
42
+ headers: Spree.apiV2Authentication(),
42
43
  data: function (params, page) {
43
44
  return {
44
45
  per_page: 50,
45
46
  page: page,
46
- without_children: true,
47
- q: {
47
+ filter: {
48
48
  name_cont: params.term
49
- },
50
- token: Spree.api_key
49
+ }
51
50
  }
52
51
  },
53
52
  processResults: function (data, page) {
54
- var more = page < data.pages
55
- var results = formatTaxonList(data.taxons)
53
+ var more = page < data.meta.total_pages
54
+
55
+ var results = data.data.map(function (obj) {
56
+ return {
57
+ id: obj.id,
58
+ text: obj.attributes.pretty_name
59
+ }
60
+ })
56
61
 
57
62
  return {
58
63
  results: results,
@@ -61,40 +66,61 @@ $(function () {
61
66
  }
62
67
  }
63
68
  }
64
- },
65
- templateResult: formatTaxon,
66
- templateSelection: formatTaxon
69
+ }
67
70
  }).on('select2:select', function (e) {
68
- var el = $('#taxon_products')
69
71
  $.ajax({
70
- url: Spree.routes.taxon_products_api,
71
- data: { id: e.params.data.id, token: Spree.api_key }
72
- }).done(function (data) {
73
- var i, j, len, len1, product, ref, ref1, results, variant
74
- el.empty()
75
- if (data.products.length === 0) {
76
- return $('#taxon_products').html('<div class="alert alert-info">' + Spree.translations.no_results + '</div>')
72
+ url: Spree.routes.classifications_api_v2,
73
+ headers: Spree.apiV2Authentication(),
74
+ data: {
75
+ filter: {
76
+ taxon_id_eq: e.params.data.id
77
+ },
78
+ include: 'product.images',
79
+ per_page: 150,
80
+ sort: 'position'
81
+ }
82
+ }).done(function (json) {
83
+ taxonProducts.empty()
84
+
85
+ if (json.meta.total_count === 0) {
86
+ return taxonProducts.html('<p class="text-center w-100 p-4">' + Spree.translations.no_results + '</p>')
77
87
  } else {
78
- ref = data.products
79
- results = []
80
- for (i = 0, len = ref.length; i < len; i++) {
81
- product = ref[i]
82
- if (product.master.images[0] !== void 0 && product.master.images[0].small_url !== void 0) {
83
- product.image = product.master.images[0].small_url
84
- } else {
85
- ref1 = product.variants
86
- for (j = 0, len1 = ref1.length; j < len1; j++) {
87
- variant = ref1[j]
88
- if (variant.images[0] !== void 0 && variant.images[0].small_url !== void 0) {
89
- product.image = variant.images[0].small_url
90
- break
88
+ var results = []
89
+
90
+ json.data.forEach(function (classification) {
91
+ var productId = classification.relationships.product.data.id.toString()
92
+
93
+ var product = json.included.find(function(included) {
94
+ if (included.type === 'product' && included.id === productId) {
95
+ return included
96
+ }
97
+ })
98
+
99
+ if (product && classification) {
100
+ var imageUrl = null
101
+
102
+ if (product.relationships.images.data.length > 0) {
103
+ var imageId = product.relationships.images.data[0].id
104
+
105
+ var image = json.included.find(function(included) {
106
+ if (included.type === 'image' && included.id === imageId) {
107
+ return included
108
+ }
109
+ })
110
+
111
+ if (image && image.attributes && image.attributes.styles) {
112
+ imageUrl = image.attributes.styles[2].url
91
113
  }
92
114
  }
115
+
116
+ results.push(taxonProducts.append(productTemplate({
117
+ product: product,
118
+ classification: classification,
119
+ image: imageUrl
120
+ })))
93
121
  }
94
- results.push(el.append(productTemplate({
95
- product: product
96
- })))
97
- }
122
+ })
123
+
98
124
  return results
99
125
  }
100
126
  })
@@ -102,43 +128,18 @@ $(function () {
102
128
  }
103
129
 
104
130
  taxonProducts.on('click', '.js-delete-product', function (e) {
105
- var currentTaxonId = $('#taxon_id').val()
106
131
  var product = $(this).parents('.product')
107
- var productId = product.data('product-id')
108
- var productTaxons = String(product.data('taxons')).split(',').map(Number)
109
- var productIndex = productTaxons.indexOf(parseFloat(currentTaxonId))
110
- productTaxons.splice(productIndex, 1)
111
- var taxonIds = productTaxons.length > 0 ? productTaxons : ['']
132
+ var classificationId = product.data('classification-id')
112
133
  $.ajax({
113
- url: Spree.routes.products_api + '/' + productId,
114
- data: {
115
- product: {
116
- taxon_ids: taxonIds
117
- },
118
- token: Spree.api_key
119
- },
120
- type: 'PUT'
134
+ url: Spree.routes.classifications_api_v2 + '/' + classificationId.toString(),
135
+ headers: Spree.apiV2Authentication(),
136
+ type: 'DELETE'
121
137
  }).done(function () {
122
138
  product.fadeOut(400, function (e) {
123
139
  product.remove()
124
140
  })
125
141
  })
126
142
  })
127
- $('.variant_autocomplete').variantAutocomplete()
128
143
 
129
- function formatTaxon (taxon) {
130
- if (taxon.loading) {
131
- return taxon.text;
132
- }
133
- return taxon.pretty_name
134
- }
135
-
136
- function formatTaxonList(values) {
137
- return values.map(function (obj) {
138
- return {
139
- id: obj.id,
140
- pretty_name: obj.pretty_name
141
- }
142
- })
143
- }
144
+ $('.variant_autocomplete').variantAutocomplete()
144
145
  })