spree_backend 4.3.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +222 -0
  3. data/.codeclimate.yml +36 -0
  4. data/.editorconfig +22 -0
  5. data/.eslintignore +7 -0
  6. data/.eslintrc.cjs +29 -0
  7. data/.gem_release.yml +4 -0
  8. data/.github/CONTRIBUTING.md +1 -0
  9. data/.github/ISSUE_TEMPLATE/bug_report.md +47 -0
  10. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  11. data/.github/ISSUE_TEMPLATE.md +39 -0
  12. data/.github/dependabot.yml +7 -0
  13. data/.github/workflows/spelling_lint.yml +34 -0
  14. data/.gitignore +64 -0
  15. data/.rubocop.yml +197 -0
  16. data/.solargraph.yml +20 -0
  17. data/.stylelintignore +4 -0
  18. data/.stylelintrc +6 -0
  19. data/CODE_OF_CONDUCT.md +22 -0
  20. data/Gemfile +59 -3
  21. data/README.md +123 -0
  22. data/SECURITY.md +1 -0
  23. data/app/assets/config/spree_backend_manifest.js +1 -1
  24. data/app/assets/images/backend-cloud-arrow-up.svg +4 -0
  25. data/app/assets/images/backend-eye-open.svg +1 -1
  26. data/app/assets/images/backend-file-earmark-font.svg +4 -0
  27. data/app/assets/images/backend-file-earmark-image.svg +4 -0
  28. data/app/assets/images/backend-file-earmark-music.svg +4 -0
  29. data/app/assets/images/backend-file-earmark-pdf.svg +4 -0
  30. data/app/assets/images/backend-file-earmark-play.svg +4 -0
  31. data/app/assets/images/backend-file-earmark-spreadsheet.svg +3 -0
  32. data/app/assets/images/backend-file-earmark-zip.svg +4 -0
  33. data/app/assets/images/backend-file-earmark.svg +3 -0
  34. data/app/assets/images/backend-hdd.svg +4 -0
  35. data/app/assets/images/backend-link.svg +4 -0
  36. data/app/assets/images/backend-view.svg +1 -1
  37. data/app/assets/javascripts/spree/backend/address_states.es6 +2 -0
  38. data/app/assets/javascripts/spree/backend/adjustments.js +5 -5
  39. data/app/assets/javascripts/spree/backend/admin.js +4 -6
  40. data/app/assets/javascripts/spree/backend/calculator.js +1 -1
  41. data/app/assets/javascripts/spree/backend/checkouts/edit.js +1 -1
  42. data/app/assets/javascripts/spree/backend/cms/links.es6 +1 -1
  43. data/app/assets/javascripts/spree/backend/cms/live_preview.es6 +1 -1
  44. data/app/assets/javascripts/spree/backend/cms/page.es6 +22 -40
  45. data/app/assets/javascripts/spree/backend/cms/section.es6 +1 -1
  46. data/app/assets/javascripts/spree/backend/gateway.js +1 -1
  47. data/app/assets/javascripts/spree/backend/general_settings.js +1 -1
  48. data/app/assets/javascripts/spree/backend/global/_index.js +3 -1
  49. data/app/assets/javascripts/spree/backend/global/alerts.es6 +1 -1
  50. data/app/assets/javascripts/spree/backend/global/animate_css.es6 +19 -0
  51. data/app/assets/javascripts/spree/backend/global/fetch_request_utility.es6 +114 -0
  52. data/app/assets/javascripts/spree/backend/global/flatpickr.es6 +8 -1
  53. data/app/assets/javascripts/spree/backend/global/info_alert.es6 +1 -1
  54. data/app/assets/javascripts/spree/backend/global/radio_panel_toggle.es6 +1 -1
  55. data/app/assets/javascripts/spree/backend/global/ransack.es6 +7 -5
  56. data/app/assets/javascripts/spree/backend/global/responsive_menus.es6 +1 -1
  57. data/app/assets/javascripts/spree/backend/global/select2_autocomplete.es6 +11 -4
  58. data/app/assets/javascripts/spree/backend/global/select2_populate.es6 +2 -2
  59. data/app/assets/javascripts/spree/backend/global/side_scroll_indication.es6 +2 -2
  60. data/app/assets/javascripts/spree/backend/global/sortable.es6 +1 -1
  61. data/app/assets/javascripts/spree/backend/global/tinymce.es6 +3 -2
  62. data/app/assets/javascripts/spree/backend/line_items.js +7 -9
  63. data/app/assets/javascripts/spree/backend/line_items_on_order_edit.js +23 -28
  64. data/app/assets/javascripts/spree/backend/menus/_index.es6 +0 -1
  65. data/app/assets/javascripts/spree/backend/menus/menu_item.es6 +1 -1
  66. data/app/assets/javascripts/spree/backend/multi_currency.js +2 -2
  67. data/app/assets/javascripts/spree/backend/option_type_autocomplete.js +1 -1
  68. data/app/assets/javascripts/spree/backend/orders/edit.js +1 -1
  69. data/app/assets/javascripts/spree/backend/payments/edit.js +32 -22
  70. data/app/assets/javascripts/spree/backend/payments/new.js +1 -1
  71. data/app/assets/javascripts/spree/backend/product_picker.js +16 -25
  72. data/app/assets/javascripts/spree/backend/progress.js +5 -3
  73. data/app/assets/javascripts/spree/backend/promotions.js +3 -1
  74. data/app/assets/javascripts/spree/backend/returns/expedited_exchanges_warning.js +1 -1
  75. data/app/assets/javascripts/spree/backend/returns/return_item_selection.js +1 -1
  76. data/app/assets/javascripts/spree/backend/shipments.js +80 -79
  77. data/app/assets/javascripts/spree/backend/spree-select2.js +8 -1
  78. data/app/assets/javascripts/spree/backend/states.js +1 -1
  79. data/app/assets/javascripts/spree/backend/stock_location.js +1 -1
  80. data/app/assets/javascripts/spree/backend/stock_management.js +1 -1
  81. data/app/assets/javascripts/spree/backend/stock_movement.js +58 -13
  82. data/app/assets/javascripts/spree/backend/stock_transfer.js +62 -32
  83. data/app/assets/javascripts/spree/backend/taxon_autocomplete.js +9 -8
  84. data/app/assets/javascripts/spree/backend/taxons.js +17 -14
  85. data/app/assets/javascripts/spree/backend/user_picker.js +1 -1
  86. data/app/assets/javascripts/spree/backend/users/edit.js +1 -1
  87. data/app/assets/javascripts/spree/backend/variant_autocomplete.js +19 -11
  88. data/app/assets/javascripts/spree/backend/variant_management.js +1 -1
  89. data/app/assets/javascripts/spree/backend/zone.js +1 -1
  90. data/app/assets/javascripts/spree/backend.js +13 -33
  91. data/app/assets/javascripts/spree.js +2 -9
  92. data/app/assets/stylesheets/spree/backend/components/_main.scss +8 -0
  93. data/app/assets/stylesheets/spree/backend/plugins/_nav_x.scss +1 -1
  94. data/app/assets/stylesheets/spree/backend/plugins/_select2_custom.scss +1 -1
  95. data/app/assets/stylesheets/spree/backend/shared/_forms.scss +1 -1
  96. data/app/assets/stylesheets/spree/backend/shared/_sortable_tree.scss +62 -0
  97. data/app/assets/stylesheets/spree/backend/spree_admin.css.scss +3 -0
  98. data/app/assets/stylesheets/spree/backend/views/_digitals.scss +33 -0
  99. data/app/assets/stylesheets/spree/backend/views/{prototypes.scss → _prototypes.scss} +0 -0
  100. data/app/assets/stylesheets/spree/backend/views/_taxonomies.scss +3 -0
  101. data/app/controllers/spree/admin/base_controller.rb +4 -13
  102. data/app/controllers/spree/admin/digitals_controller.rb +33 -0
  103. data/app/controllers/spree/admin/general_settings_controller.rb +0 -5
  104. data/app/controllers/spree/admin/images_controller.rb +1 -1
  105. data/app/controllers/spree/admin/oauth_applications_controller.rb +17 -0
  106. data/app/controllers/spree/admin/orders/customer_details_controller.rb +2 -2
  107. data/app/controllers/spree/admin/orders_controller.rb +10 -2
  108. data/app/controllers/spree/admin/payment_methods_controller.rb +2 -2
  109. data/app/controllers/spree/admin/payments_controller.rb +1 -1
  110. data/app/controllers/spree/admin/products_controller.rb +4 -2
  111. data/app/controllers/spree/admin/promotions_controller.rb +1 -1
  112. data/app/controllers/spree/admin/properties_controller.rb +1 -1
  113. data/app/controllers/spree/admin/resource_controller.rb +9 -4
  114. data/app/controllers/spree/admin/return_index_controller.rb +3 -4
  115. data/app/controllers/spree/admin/stock_transfers_controller.rb +2 -2
  116. data/app/controllers/spree/admin/store_credits_controller.rb +2 -2
  117. data/app/controllers/spree/admin/stores_controller.rb +2 -2
  118. data/app/controllers/spree/admin/taxons_controller.rb +23 -38
  119. data/app/controllers/spree/admin/users_controller.rb +6 -19
  120. data/app/controllers/spree/admin/variants_controller.rb +1 -2
  121. data/app/controllers/spree/admin/webhooks_subscribers_controller.rb +48 -0
  122. data/app/helpers/spree/admin/base_helper.rb +27 -9
  123. data/app/helpers/spree/admin/digital_helper.rb +28 -0
  124. data/app/helpers/spree/admin/menu_helper.rb +0 -21
  125. data/app/helpers/spree/admin/navigation_helper.rb +19 -9
  126. data/app/helpers/spree/admin/sortable_tree_helper.rb +31 -0
  127. data/app/helpers/spree/admin/stores_helper.rb +1 -1
  128. data/app/helpers/spree/admin/webhooks_subscribers_helper.rb +31 -0
  129. data/app/javascript/spree/dashboard/controllers/clipboard_controller.js +12 -0
  130. data/app/javascript/spree/dashboard/controllers/password_toggle_controller.js +14 -0
  131. data/app/javascript/spree/dashboard/controllers/sortable_tree_controller.js +55 -0
  132. data/app/javascript/spree/dashboard/controllers/spree_controller.js +25 -0
  133. data/app/javascript/spree/dashboard/controllers/upload_button_controller.js +13 -0
  134. data/app/javascript/spree/dashboard/controllers/webhooks_subscriber_events_controller.js +19 -0
  135. data/app/javascript/spree/dashboard/index.js +49 -0
  136. data/app/{assets/javascripts/spree/backend/global/bootstrap.es6 → javascript/spree/dashboard/utilities/bootstrap.js} +6 -2
  137. data/app/javascript/spree/dashboard/utilities/request_utility.js +54 -0
  138. data/app/models/spree/backend_configuration.rb +11 -0
  139. data/app/views/spree/admin/adjustments/_form.html.erb +2 -2
  140. data/app/views/spree/admin/adjustments/index.html.erb +1 -0
  141. data/app/views/spree/admin/cms_pages/_form.html.erb +8 -8
  142. data/app/views/spree/admin/cms_pages/edit.html.erb +1 -6
  143. data/app/views/spree/admin/cms_sections/_form.html.erb +2 -2
  144. data/app/views/spree/admin/cms_sections/types/_featured_article.html.erb +6 -6
  145. data/app/views/spree/admin/cms_sections/types/_hero_image.html.erb +6 -6
  146. data/app/views/spree/admin/cms_sections/types/_image_gallery.html.erb +12 -12
  147. data/app/views/spree/admin/cms_sections/types/_rich_text_content.html.erb +1 -1
  148. data/app/views/spree/admin/cms_sections/types/_side_by_side_images.html.erb +12 -12
  149. data/app/views/spree/admin/countries/_form.html.erb +4 -4
  150. data/app/views/spree/admin/customer_returns/new.html.erb +1 -1
  151. data/app/views/spree/admin/digitals/_form.html.erb +35 -0
  152. data/app/views/spree/admin/digitals/index.html.erb +25 -0
  153. data/app/views/spree/admin/general_settings/edit.html.erb +1 -22
  154. data/app/views/spree/admin/menu_items/_form.html.erb +6 -6
  155. data/app/views/spree/admin/menus/_form.html.erb +3 -3
  156. data/app/views/spree/admin/menus/edit.html.erb +18 -18
  157. data/app/views/spree/admin/oauth_applications/_form.html.erb +22 -0
  158. data/app/views/spree/admin/oauth_applications/create.turbo_stream.erb +38 -0
  159. data/app/views/spree/admin/oauth_applications/edit.html.erb +13 -0
  160. data/app/views/spree/admin/oauth_applications/index.html.erb +51 -0
  161. data/app/views/spree/admin/oauth_applications/new.html.erb +15 -0
  162. data/app/views/spree/admin/option_types/_form.html.erb +3 -3
  163. data/app/views/spree/admin/option_types/_option_value_fields.html.erb +2 -2
  164. data/app/views/spree/admin/orders/_channel_form.html.erb +1 -1
  165. data/app/views/spree/admin/orders/_form.html.erb +1 -0
  166. data/app/views/spree/admin/orders/_line_items_edit_form.html.erb +1 -0
  167. data/app/views/spree/admin/orders/_order_actions.html.erb +6 -0
  168. data/app/views/spree/admin/orders/_search.html.erb +151 -0
  169. data/app/views/spree/admin/orders/index.html.erb +2 -151
  170. data/app/views/spree/admin/payment_methods/_form.html.erb +2 -2
  171. data/app/views/spree/admin/payments/_list.html.erb +1 -1
  172. data/app/views/spree/admin/products/_form.html.erb +19 -20
  173. data/app/views/spree/admin/products/index.html.erb +2 -1
  174. data/app/views/spree/admin/products/new.html.erb +6 -6
  175. data/app/views/spree/admin/promotion_actions/create.js.erb +1 -1
  176. data/app/views/spree/admin/promotion_categories/_form.html.erb +2 -2
  177. data/app/views/spree/admin/promotions/_form.html.erb +5 -5
  178. data/app/views/spree/admin/properties/_form.html.erb +3 -3
  179. data/app/views/spree/admin/prototypes/_form.html.erb +4 -4
  180. data/app/views/spree/admin/refunds/new.html.erb +2 -2
  181. data/app/views/spree/admin/reimbursement_types/_form.html.erb +2 -2
  182. data/app/views/spree/admin/return_authorizations/_form.html.erb +3 -3
  183. data/app/views/spree/admin/roles/_form.html.erb +1 -1
  184. data/app/views/spree/admin/shared/_account_nav.html.erb +1 -1
  185. data/app/views/spree/admin/shared/_address_form.html.erb +4 -4
  186. data/app/views/spree/admin/shared/_head.html.erb +4 -8
  187. data/app/views/spree/admin/shared/_main_menu.html.erb +12 -0
  188. data/app/views/spree/admin/shared/_new_resource_links.html.erb +1 -1
  189. data/app/views/spree/admin/shared/_product_tabs.html.erb +8 -0
  190. data/app/views/spree/admin/shared/_version.html.erb +1 -1
  191. data/app/views/spree/admin/shared/cms/_spree_product.html.erb +2 -2
  192. data/app/views/spree/admin/shared/cms/_spree_taxon.html.erb +2 -2
  193. data/app/views/spree/admin/shared/linkables/_spree_cms_page.erb +2 -2
  194. data/app/views/spree/admin/shared/linkables/_spree_product.html.erb +2 -2
  195. data/app/views/spree/admin/shared/linkables/_spree_taxon.html.erb +2 -2
  196. data/app/views/spree/admin/shared/linkables/_url.html.erb +1 -1
  197. data/app/views/spree/admin/shared/named_types/_form.html.erb +1 -1
  198. data/app/views/spree/admin/{menus/nested_menu_items/_item_bar.html.erb → shared/sortable_tree/_menu.html.erb} +10 -7
  199. data/app/views/spree/admin/shared/sortable_tree/_taxonomy.html.erb +34 -0
  200. data/app/views/spree/admin/shared/sub_menu/_apps.html.erb +3 -0
  201. data/app/views/spree/admin/shared/sub_menu/_integrations.html.erb +3 -0
  202. data/app/views/spree/admin/shipping_categories/_form.html.erb +1 -1
  203. data/app/views/spree/admin/shipping_methods/_form.html.erb +8 -8
  204. data/app/views/spree/admin/states/_form.html.erb +2 -2
  205. data/app/views/spree/admin/stock_locations/_form.html.erb +2 -2
  206. data/app/views/spree/admin/stock_movements/_form.html.erb +3 -3
  207. data/app/views/spree/admin/store_credit_categories/_form.html.erb +1 -1
  208. data/app/views/spree/admin/store_credits/_form.html.erb +4 -4
  209. data/app/views/spree/admin/stores/_form.html.erb +280 -227
  210. data/app/views/spree/admin/tax_categories/_form.html.erb +4 -4
  211. data/app/views/spree/admin/tax_rates/_form.html.erb +4 -3
  212. data/app/views/spree/admin/taxonomies/_form.html.erb +2 -2
  213. data/app/views/spree/admin/taxonomies/edit.html.erb +34 -29
  214. data/app/views/spree/admin/taxons/_form.html.erb +101 -57
  215. data/app/views/spree/admin/taxons/edit.html.erb +6 -3
  216. data/app/views/spree/admin/taxons/index.html.erb +1 -1
  217. data/app/views/spree/admin/taxons/new.html.erb +16 -0
  218. data/app/views/spree/admin/users/_form.html.erb +3 -3
  219. data/app/views/spree/admin/users/edit.html.erb +0 -40
  220. data/app/views/spree/admin/variants/_autocomplete.js.erb +5 -5
  221. data/app/views/spree/admin/variants/_autocomplete_line_items_stock.js.erb +2 -2
  222. data/app/views/spree/admin/variants/_autocomplete_stock.js.erb +6 -6
  223. data/app/views/spree/admin/variants/_split.js.erb +1 -1
  224. data/app/views/spree/admin/variants/index.html.erb +4 -1
  225. data/app/views/spree/admin/webhooks_subscribers/_form.html.erb +101 -0
  226. data/app/views/spree/admin/webhooks_subscribers/edit.html.erb +13 -0
  227. data/app/views/spree/admin/webhooks_subscribers/index.html.erb +47 -0
  228. data/app/views/spree/admin/webhooks_subscribers/new.html.erb +13 -0
  229. data/app/views/spree/admin/webhooks_subscribers/show.html.erb +59 -0
  230. data/app/views/spree/admin/zones/_country_members.html.erb +1 -1
  231. data/app/views/spree/admin/zones/_form.html.erb +2 -2
  232. data/app/views/spree/admin/zones/_state_members.html.erb +1 -1
  233. data/app/views/spree/layouts/admin.html.erb +1 -11
  234. data/codespell.txt +8 -0
  235. data/config/locales/en.yml +273 -0
  236. data/config/routes.rb +6 -2
  237. data/lib/generators/spree/backend/install/install_generator.rb +4 -2
  238. data/lib/generators/spree/backend/install/templates/app/javascript/spree-dashboard.js +7 -0
  239. data/lib/spree/backend/engine.rb +2 -1
  240. data/lib/spree/backend/testing_support/capybara_utils.rb +53 -0
  241. data/lib/spree/backend/testing_support/flash.rb +38 -0
  242. data/lib/spree/backend/testing_support/flatpickr_capybara.rb +126 -0
  243. data/lib/spree/backend/version.rb +9 -0
  244. data/lib/spree/backend.rb +2 -1
  245. data/lib/spree_backend.rb +17 -0
  246. data/license.md +13 -0
  247. data/package.json +45 -0
  248. data/rollup.config.js +41 -0
  249. data/spree_backend.gemspec +17 -16
  250. data/vendor/assets/javascripts/purify.js +1 -1
  251. data/vendor/assets/stylesheets/animate.css +2 -4
  252. data/yarn.lock +944 -0
  253. metadata +118 -36
  254. data/app/assets/javascripts/spree/backend/menus/menu.es6 +0 -57
  255. data/app/assets/javascripts/spree/backend/taxon_permalink_preview.js +0 -11
  256. data/app/assets/javascripts/spree/backend/taxon_tree_menu.js +0 -35
  257. data/app/assets/javascripts/spree/backend/taxonomy.js +0 -178
  258. data/app/views/spree/admin/taxonomies/_js_head.html.erb +0 -7
  259. data/vendor/assets/javascripts/jquery.jstree/jquery.jstree.js +0 -4564
  260. data/vendor/assets/javascripts/js.cookie.js +0 -163
  261. data/vendor/assets/javascripts/modernizr.js +0 -3
  262. data/vendor/assets/stylesheets/jquery.jstree/themes/spree/style.scss +0 -230
  263. data/vendor/assets/stylesheets/jquery.jstree/themes/spree/throbber.gif +0 -0
@@ -1,5 +1,5 @@
1
1
  /* global show_flash */
2
- jQuery(function ($) {
2
+ document.addEventListener("spree:load", function() {
3
3
  var extend = function (child, parent) {
4
4
  for (var key in parent) {
5
5
  if (hasProp.call(parent, key)) child[key] = parent[key]
@@ -13,54 +13,61 @@ jQuery(function ($) {
13
13
  return child
14
14
  }
15
15
  var hasProp = {}.hasOwnProperty
16
- var EditPaymentView, Payment, PaymentView, ShowPaymentView, orderId
17
- orderId = $('#payments').data('order-id')
16
+ var EditPaymentView, Payment, PaymentView, ShowPaymentView
18
17
  Payment = (function () {
19
- function Payment (number) {
20
- this.url = Spree.url(((Spree.routes.payments_api(orderId)) + '/' + number + '.json') + '?token=' + Spree.api_key)
21
- this.json = $.getJSON(this.url.toString(), function (data) {
22
- this.data = data
23
- }.bind(this))
18
+ function Payment (id) {
19
+ this.url = Spree.routes.payments_api_v2 + '/' + id
20
+ this.json = $.ajax({
21
+ dataType: "json",
22
+ url: this.url,
23
+ headers: Spree.apiV2Authentication(),
24
+ success: function (data) {
25
+ this.data = data.data
26
+ }.bind(this)
27
+ })
24
28
  this.updating = false
25
29
  }
26
30
 
27
31
  Payment.prototype.if_editable = function (callback) {
28
32
  return this.json.done(function (data) {
29
33
  var ref
30
- if ((ref = data.state) === 'checkout' || ref === 'pending') {
34
+ if ((ref = data.data.attributes.state) === 'checkout' || ref === 'pending') {
31
35
  return callback()
32
36
  }
33
37
  })
34
38
  }
35
39
 
36
- Payment.prototype.update = function (attributes) {
40
+ Payment.prototype.update = function (attributes, onDone) {
37
41
  this.updating = true
38
42
  var jqXHR = $.ajax({
39
- type: 'PUT',
40
- url: this.url.toString(),
43
+ type: 'PATCH',
44
+ url: this.url,
41
45
  data: {
42
46
  payment: attributes
43
- }
47
+ },
48
+ headers: Spree.apiV2Authentication()
44
49
  })
45
50
  jqXHR.always(function () {
46
51
  this.updating = false
47
52
  }.bind(this))
48
53
  jqXHR.done(function (data) {
49
- this.data = data
54
+ this.data = data.data
55
+ onDone()
50
56
  }.bind(this))
51
57
  jqXHR.fail(function () {
52
58
  var response = (jqXHR.responseJSON && jqXHR.responseJSON.error) || jqXHR.statusText
53
59
  show_flash('error', response)
60
+ onDone()
54
61
  })
55
62
  return jqXHR
56
63
  }
57
64
 
58
65
  Payment.prototype.amount = function () {
59
- return this.data.amount
66
+ return this.data.attributes.amount
60
67
  }
61
68
 
62
69
  Payment.prototype.display_amount = function () {
63
- return this.data.display_amount
70
+ return this.data.attributes.display_amount
64
71
  }
65
72
  return Payment
66
73
  })()
@@ -189,11 +196,14 @@ jQuery(function ($) {
189
196
 
190
197
  EditPaymentView.prototype.save = function () {
191
198
  if (!this.payment.updating) {
192
- return this.payment.update({
193
- amount: this.$input().val()
194
- }).done(function () {
195
- return this.show()
196
- }.bind(this))
199
+ return this.payment.update(
200
+ {
201
+ amount: this.$input().val()
202
+ },
203
+ function () {
204
+ this.show()
205
+ }.bind(this)
206
+ )
197
207
  }
198
208
  }
199
209
 
@@ -223,7 +233,7 @@ jQuery(function ($) {
223
233
  })(PaymentView)
224
234
  return $('.admin tr[data-hook=payments_row]').each(function () {
225
235
  var $el = $(this)
226
- var payment = new Payment($el.attr('data-number'))
236
+ var payment = new Payment($el.attr('data-id'))
227
237
  return payment.if_editable(function () {
228
238
  return new ShowPaymentView($el, payment)
229
239
  })
@@ -1,6 +1,6 @@
1
1
  /* global Cleave */
2
2
 
3
- $(document).ready(function () {
3
+ document.addEventListener("spree:load", function() {
4
4
  if ($('#new_payment').length) {
5
5
  var cardCodeCleave;
6
6
  var updateCardCodeCleave = function (length) {
@@ -6,24 +6,21 @@ $.fn.productAutocomplete = function (options) {
6
6
  var multiple = typeof (options.multiple) !== 'undefined' ? options.multiple : true
7
7
  var values = typeof (options.values) !== 'undefined' ? options.values : null
8
8
 
9
- function formatProductList(products) {
10
- return products.map(function(obj) {
11
- return { id: obj.id, text: obj.name }
12
- })
13
- }
14
-
15
9
  function addOptions(select, values) {
16
10
  $.ajax({
17
- url: Spree.routes.products_api,
11
+ url: Spree.routes.products_api_v2,
18
12
  dataType: 'json',
19
13
  data: {
20
- q: {
14
+ filter: {
21
15
  id_in: values
22
16
  },
23
- token: Spree.api_key
24
- }
17
+ fields: {
18
+ product: 'name'
19
+ }
20
+ },
21
+ headers: Spree.apiV2Authentication(),
25
22
  }).then(function (data) {
26
- select.addSelect2Options(data.products)
23
+ select.addSelect2Options(data.data)
27
24
  })
28
25
  }
29
26
 
@@ -31,28 +28,22 @@ $.fn.productAutocomplete = function (options) {
31
28
  multiple: multiple,
32
29
  minimumInputLength: 3,
33
30
  ajax: {
34
- url: Spree.routes.products_api,
31
+ url: Spree.routes.products_api_v2,
35
32
  dataType: 'json',
36
33
  data: function (params) {
37
34
  return {
38
- q: {
35
+ filter: {
39
36
  name_or_master_sku_cont: params.term
40
37
  },
41
- m: 'OR',
42
- token: Spree.api_key
38
+ fields: {
39
+ product: 'name'
40
+ }
43
41
  }
44
42
  },
43
+ headers: Spree.apiV2Authentication(),
45
44
  processResults: function(data) {
46
- var products = data.products ? data.products : []
47
- var results = formatProductList(products)
48
-
49
- return {
50
- results: results
51
- }
45
+ return formatSelect2Options(data)
52
46
  }
53
- },
54
- templateSelection: function(data, _container) {
55
- return data.text
56
47
  }
57
48
  })
58
49
 
@@ -61,6 +52,6 @@ $.fn.productAutocomplete = function (options) {
61
52
  }
62
53
  }
63
54
 
64
- $(document).ready(function () {
55
+ document.addEventListener("spree:load", function() {
65
56
  $('.product_picker').productAutocomplete()
66
57
  })
@@ -1,8 +1,10 @@
1
- $(function () {
1
+ document.addEventListener("spree:load", function() {
2
2
  $(document).ajaxStart(function () {
3
- $('#progress').stop(true, true).fadeIn()
3
+ Turbo.navigator.delegate.adapter.progressBar.setValue(0)
4
+ Turbo.navigator.delegate.adapter.progressBar.show()
4
5
  })
5
6
  $(document).ajaxStop(function () {
6
- $('#progress').fadeOut()
7
+ Turbo.navigator.delegate.adapter.progressBar.setValue(1)
8
+ Turbo.navigator.delegate.adapter.progressBar.hide()
7
9
  })
8
10
  })
@@ -16,10 +16,12 @@ function initProductActions () {
16
16
  $warning.hide()
17
17
  $settings.show()
18
18
  $settings.find('input').removeProp('disabled')
19
+ $settings.find('select').removeProp('disabled')
19
20
  } else {
20
21
  $warning.show()
21
22
  $settings.hide()
22
23
  $settings.find('input').prop('disabled', 'disabled')
24
+ $settings.find('select').prop('disabled', 'disabled')
23
25
  }
24
26
  })
25
27
  })
@@ -161,7 +163,7 @@ function initProductActions () {
161
163
  })()
162
164
  }
163
165
 
164
- $(document).ready(function () {
166
+ document.addEventListener("spree:load", function() {
165
167
  var promotion_form = $('form.edit_promotion')
166
168
 
167
169
  if (promotion_form.length) {
@@ -1,4 +1,4 @@
1
- $(function () {
1
+ document.addEventListener("spree:load", function() {
2
2
  $(document).on('change', '.return-items-table .return-item-exchange-selection', function () {
3
3
  $('.expedited-exchanges-warning').fadeIn()
4
4
  })
@@ -1,4 +1,4 @@
1
- $(document).ready(function () {
1
+ document.addEventListener("spree:load", function() {
2
2
  var formFields = $("[data-hook='admin_customer_return_form_fields'], [data-hook='admin_return_authorization_form_fields']")
3
3
 
4
4
  function checkAddItemBox () {
@@ -1,13 +1,13 @@
1
- /* global shipments, variantStockTemplate, order_number */
1
+ /* global shipments, variantStockTemplate, order_number, order_id */
2
2
  // Shipments AJAX API
3
- $(document).ready(function () {
3
+ document.addEventListener("spree:load", function() {
4
4
  'use strict'
5
5
 
6
6
  // handle variant selection, show stock level.
7
7
  $('#add_variant_id').change(function () {
8
- var variantId = parseInt($(this).val())
8
+ var variantId = $(this).val().toString()
9
9
  var variant = _.find(window.variants, function (variant) {
10
- return variant.id === variantId
10
+ return variant.id.toString() === variantId
11
11
  })
12
12
 
13
13
  $('#stock_details').html(variantStockTemplate({ variant: variant }))
@@ -45,22 +45,23 @@ $(document).ready(function () {
45
45
  var shipmentNumber = del.data('shipment-number')
46
46
  var variantId = del.data('variant-id')
47
47
  // eslint-disable-next-line
48
- var shipment = _.findWhere(shipments, { number: shipmentNumber + '' })
49
- var url = Spree.routes.shipments_api + '/' + shipmentNumber + '/remove'
48
+ var url = Spree.routes.shipments_api_v2 + '/' + shipmentNumber + '/remove_item'
50
49
 
51
50
  toggleItemEdit()
52
51
 
53
52
  $.ajax({
54
- type: 'PUT',
53
+ type: 'PATCH',
55
54
  url: Spree.url(url),
56
55
  data: {
57
- variant_id: variantId,
58
- token: Spree.api_key
59
- }
56
+ shipment: {
57
+ variant_id: variantId
58
+ }
59
+ },
60
+ headers: Spree.apiV2Authentication()
60
61
  }).done(function (msg) {
61
62
  window.location.reload()
62
63
  }).fail(function (msg) {
63
- alert(msg.responseJSON.message || msg.responseJSON.exception)
64
+ alert(msg.responseJSON.error)
64
65
  })
65
66
  }
66
67
  return false
@@ -69,18 +70,15 @@ $(document).ready(function () {
69
70
  // handle ship click
70
71
  $('[data-hook=admin_shipment_form] a.ship').on('click', function () {
71
72
  var link = $(this)
72
- var shipmentNumber = link.data('shipment-number')
73
- var url = Spree.url(Spree.routes.shipments_api + '/' + shipmentNumber + '/ship.json')
73
+ var url = Spree.url(Spree.routes.shipments_api_v2 + '/' + link.data('shipment-number') + '/ship')
74
74
  $.ajax({
75
- type: 'PUT',
75
+ type: 'PATCH',
76
76
  url: url,
77
- data: {
78
- token: Spree.api_key
79
- }
77
+ headers: Spree.apiV2Authentication()
80
78
  }).done(function () {
81
79
  window.location.reload()
82
80
  }).fail(function (msg) {
83
- alert(msg.responseJSON.message || msg.responseJSON.exception)
81
+ alert(msg.responseJSON.error)
84
82
  })
85
83
  })
86
84
 
@@ -96,22 +94,22 @@ $(document).ready(function () {
96
94
  var shipmentNumber = link.data('shipment-number')
97
95
  var selectedShippingRateId = link.parents('tbody').find("select#selected_shipping_rate_id[data-shipment-number='" + shipmentNumber + "']").val()
98
96
  var unlock = link.parents('tbody').find("input[name='open_adjustment'][data-shipment-number='" + shipmentNumber + "']:checked").val()
99
- var url = Spree.url(Spree.routes.shipments_api + '/' + shipmentNumber + '.json')
97
+ var url = Spree.url(Spree.routes.shipments_api_v2 + '/' + shipmentNumber + '.json')
100
98
 
101
99
  $.ajax({
102
- type: 'PUT',
100
+ type: 'PATCH',
103
101
  url: url,
104
102
  data: {
105
103
  shipment: {
106
104
  selected_shipping_rate_id: selectedShippingRateId,
107
105
  unlock: unlock
108
106
  },
109
- token: Spree.api_key
110
- }
107
+ },
108
+ headers: Spree.apiV2Authentication()
111
109
  }).done(function () {
112
110
  window.location.reload()
113
111
  }).fail(function (msg) {
114
- alert(msg.responseJSON.message || msg.responseJSON.exception)
112
+ alert(msg.responseJSON.error)
115
113
  })
116
114
  })
117
115
 
@@ -128,16 +126,11 @@ $(document).ready(function () {
128
126
  $('a.cancel-tracking').click(toggleTrackingEdit)
129
127
 
130
128
  function createTrackingValueContent(data) {
131
- var selectedShippingMethod = data.shipping_methods.filter(function (method) {
132
- return method.id === data.selected_shipping_rate.shipping_method_id
133
- })[0]
134
-
135
- if (selectedShippingMethod && selectedShippingMethod.tracking_url) {
136
- var shipmentTrackingUrl = selectedShippingMethod.tracking_url.replace(/:tracking/, data.tracking)
137
- return '<a target="_blank" href="' + shipmentTrackingUrl + '">' + data.tracking + '<a>'
129
+ if (data.attributes.tracking_url && data.attributes.tracking) {
130
+ return '<a target="_blank" href="' + data.attributes.tracking_url + '">' + data.attributes.tracking + '<a>'
138
131
  }
139
132
 
140
- return data.tracking
133
+ return data.attributes.tracking
141
134
  }
142
135
 
143
136
  // handle tracking save
@@ -147,25 +140,25 @@ $(document).ready(function () {
147
140
  var link = $(this)
148
141
  var shipmentNumber = link.data('shipment-number')
149
142
  var tracking = link.parents('tbody').find('input#tracking').val()
150
- var url = Spree.url(Spree.routes.shipments_api + '/' + shipmentNumber + '.json')
143
+ var url = Spree.url(Spree.routes.shipments_api_v2 + '/' + shipmentNumber + '.json')
151
144
 
152
145
  $.ajax({
153
- type: 'PUT',
146
+ type: 'PATCH',
154
147
  url: url,
155
148
  data: {
156
149
  shipment: {
157
150
  tracking: tracking
158
- },
159
- token: Spree.api_key
160
- }
161
- }).done(function (data) {
151
+ }
152
+ },
153
+ headers: Spree.apiV2Authentication()
154
+ }).done(function (json) {
162
155
  link.parents('tbody').find('tr.edit-tracking').toggle()
163
156
 
164
157
  var show = link.parents('tbody').find('tr.show-tracking')
165
158
  show.toggle()
166
159
 
167
- if (data.tracking) {
168
- show.find('.tracking-value').html($('<strong>').html(Spree.translations.tracking + ': ')).append(createTrackingValueContent(data))
160
+ if (json.data.attributes.tracking) {
161
+ show.find('.tracking-value').html($('<strong>').html(Spree.translations.tracking + ': ')).append(createTrackingValueContent(json.data))
169
162
  } else {
170
163
  show.find('.tracking-value').html(Spree.translations.no_tracking_present)
171
164
  }
@@ -176,34 +169,36 @@ $(document).ready(function () {
176
169
  function adjustShipmentItems(shipmentNumber, variantId, quantity) {
177
170
  var shipment = _.findWhere(shipments, { number: shipmentNumber + '' })
178
171
  var inventoryUnits = _.where(shipment.inventory_units, { variant_id: variantId })
179
- var url = Spree.routes.shipments_api + '/' + shipmentNumber
172
+ var url = Spree.routes.shipments_api_v2 + '/' + shipmentNumber
180
173
  var previousQuantity = inventoryUnits.reduce(function (accumulator, currentUnit, _index, _array) {
181
174
  return accumulator + currentUnit.quantity
182
175
  }, 0)
183
176
  var newQuantity = 0
184
177
 
185
178
  if (previousQuantity < quantity) {
186
- url += '/add'
179
+ url += '/add_item'
187
180
  newQuantity = (quantity - previousQuantity)
188
181
  } else if (previousQuantity > quantity) {
189
- url += '/remove'
182
+ url += '/remove_item'
190
183
  newQuantity = (previousQuantity - quantity)
191
184
  }
192
185
  url += '.json'
193
186
 
194
187
  if (newQuantity !== 0) {
195
188
  $.ajax({
196
- type: 'PUT',
189
+ type: 'PATCH',
197
190
  url: Spree.url(url),
198
191
  data: {
199
- variant_id: variantId,
200
- quantity: newQuantity,
201
- token: Spree.api_key
202
- }
192
+ shipment: {
193
+ variant_id: variantId,
194
+ quantity: newQuantity,
195
+ }
196
+ },
197
+ headers: Spree.apiV2Authentication()
203
198
  }).done(function (msg) {
204
199
  window.location.reload()
205
200
  }).fail(function (msg) {
206
- alert(msg.responseJSON.message || msg.responseJSON.exception)
201
+ alert(msg.responseJSON.error)
207
202
  })
208
203
  }
209
204
  }
@@ -245,26 +240,28 @@ function startItemSplit(event) {
245
240
  $.ajax({
246
241
  type: 'GET',
247
242
  async: false,
248
- url: Spree.url(Spree.routes.variants_api),
243
+ url: Spree.routes.variants_api_v2 + '/' + variantId,
249
244
  data: {
250
- q: {
251
- 'id_eq': variantId
252
- },
253
- token: Spree.api_key
254
- }
255
- }).done(function (data) {
256
- variant = data['variants'][0]
245
+ include: 'stock_items.stock_location'
246
+ },
247
+ headers: Spree.apiV2Authentication()
248
+ }).done(function (json) {
249
+ var JSONAPIDeserializer = require('jsonapi-serializer').Deserializer
250
+ new JSONAPIDeserializer({ keyForAttribute: 'snake_case' }).deserialize(json, function (_err, deserializedJson) {
251
+ variant = deserializedJson
252
+
253
+ var maxQuantity = link.closest('tr').data('item-quantity')
254
+ var splitItemTemplate = Handlebars.compile($('#variant_split_template').text())
255
+
256
+ link.closest('tr').after(splitItemTemplate({ variant: variant, shipments: shipments, max_quantity: maxQuantity }))
257
+ $('a.cancel-split').click(cancelItemSplit)
258
+ $('a.save-split').click(completeItemSplit)
259
+
260
+ $('#item_stock_location').select2({ width: 'resolve', placeholder: Spree.translations.item_stock_placeholder })
261
+ })
257
262
  }).fail(function (msg) {
258
- alert(msg.responseJSON.message || msg.responseJSON.exception)
263
+ alert(msg.responseJSON.error)
259
264
  })
260
-
261
- var maxQuantity = link.closest('tr').data('item-quantity')
262
- var splitItemTemplate = Handlebars.compile($('#variant_split_template').text())
263
- link.closest('tr').after(splitItemTemplate({ variant: variant, shipments: shipments, max_quantity: maxQuantity }))
264
- $('a.cancel-split').click(cancelItemSplit)
265
- $('a.save-split').click(completeItemSplit)
266
-
267
- $('#item_stock_location').select2({ width: 'resolve', placeholder: Spree.translations.item_stock_placeholder })
268
265
  }
269
266
 
270
267
  function completeItemSplit(event) {
@@ -301,19 +298,20 @@ function completeItemSplit(event) {
301
298
  }
302
299
 
303
300
  var data = {
304
- original_shipment_number: originalShipmentNumber,
305
301
  variant_id: variantId,
306
- quantity: quantity,
307
- token: Spree.api_key
302
+ quantity: quantity
308
303
  }
309
304
 
310
305
  $.ajax({
311
- type: 'POST',
306
+ type: 'PATCH',
312
307
  async: false,
313
- url: Spree.url(Spree.routes.shipments_api + path),
314
- data: $.extend(data, additionalData)
308
+ url: Spree.url(Spree.routes.shipments_api_v2 + '/' + originalShipmentNumber + path),
309
+ data: {
310
+ shipment: $.extend(data, additionalData)
311
+ },
312
+ headers: Spree.apiV2Authentication()
315
313
  }).fail(function (msg) {
316
- alert(msg.responseJSON.message || msg.responseJSON.exception)
314
+ alert(msg.responseJSON.error)
317
315
  }).done(function (msg) {
318
316
  window.location.reload()
319
317
  })
@@ -347,17 +345,20 @@ function addVariantFromStockLocation(event) {
347
345
  $.ajax({
348
346
  type: 'POST',
349
347
  // eslint-disable-next-line camelcase
350
- url: Spree.url(Spree.routes.shipments_api + '?shipment[order_id]=' + order_number),
348
+ url: Spree.routes.shipments_api_v2,
351
349
  data: {
352
- variant_id: variantId,
353
- quantity: quantity,
354
- stock_location_id: stockLocationId,
355
- token: Spree.api_key
356
- }
350
+ shipment: {
351
+ order_id: order_id,
352
+ variant_id: variantId,
353
+ quantity: quantity,
354
+ stock_location_id: stockLocationId
355
+ }
356
+ },
357
+ headers: Spree.apiV2Authentication()
357
358
  }).done(function (msg) {
358
359
  window.location.reload()
359
360
  }).fail(function (msg) {
360
- alert(msg.responseJSON.message || msg.responseJSON.exception)
361
+ alert(msg.responseJSON.error)
361
362
  })
362
363
  } else {
363
364
  // add to existing shipment
@@ -1,4 +1,11 @@
1
- document.addEventListener('DOMContentLoaded', function() {
1
+ // we need to delete select2 instances before document is saved to cache
2
+ // https://stackoverflow.com/questions/36497723/select2-with-ajax-gets-initialized-several-times-with-rails-turbolinks-events
3
+ document.addEventListener("turbo:before-cache", function() {
4
+ $('select.select2').select2('destroy')
5
+ $('select.select2-clear').select2('destroy')
6
+ })
7
+
8
+ document.addEventListener("spree:load", function() {
2
9
  // Initiate a standard Select2 on any select element with the class .select2
3
10
  // Remember to add a place holder in the HTML as needed.
4
11
  $('select.select2').select2({})
@@ -1,4 +1,4 @@
1
- $(document).ready(function () {
1
+ document.addEventListener("spree:load", function() {
2
2
  'use strict'
3
3
 
4
4
  if ($('#new_state_link').length) {
@@ -1,3 +1,3 @@
1
- $(document).ready(function () {
1
+ document.addEventListener("spree:load", function() {
2
2
  $('[data-hook=stock_location_country] span#country .select2').on('change', function () { updateAddressState('') })
3
3
  })
@@ -1,4 +1,4 @@
1
- $(function () {
1
+ document.addEventListener("spree:load", function() {
2
2
  $('.stock_item_backorderable').on('click', function () {
3
3
  $(this).parent('form').submit()
4
4
  })