spree_backend 4.2.0.rc2 → 4.2.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree/backend.js +0 -1
  3. data/app/assets/javascripts/spree/backend/address_states.js +20 -9
  4. data/app/assets/javascripts/spree/backend/calculator.js +2 -0
  5. data/app/assets/javascripts/spree/backend/checkouts/edit.js +99 -71
  6. data/app/assets/javascripts/spree/backend/line_items_on_order_edit.js +1 -1
  7. data/app/assets/javascripts/spree/backend/option_type_autocomplete.js +31 -37
  8. data/app/assets/javascripts/spree/backend/option_value_picker.js +50 -23
  9. data/app/assets/javascripts/spree/backend/product_picker.js +35 -19
  10. data/app/assets/javascripts/spree/backend/promotions.js +32 -27
  11. data/app/assets/javascripts/spree/backend/shipments.js +28 -37
  12. data/app/assets/javascripts/spree/backend/spree-select2.js +33 -14
  13. data/app/assets/javascripts/spree/backend/stock_transfer.js +32 -13
  14. data/app/assets/javascripts/spree/backend/taxon_autocomplete.js +30 -43
  15. data/app/assets/javascripts/spree/backend/taxons.js +60 -47
  16. data/app/assets/javascripts/spree/backend/user_picker.js +16 -18
  17. data/app/assets/javascripts/spree/backend/variant_autocomplete.js +23 -22
  18. data/app/assets/stylesheets/spree/backend/components/_badges.scss +1 -1
  19. data/app/assets/stylesheets/spree/backend/components/_tables.scss +2 -2
  20. data/app/assets/stylesheets/spree/backend/global/_variables.scss +1 -1
  21. data/app/assets/stylesheets/spree/backend/plugins/_select2_custom.scss +11 -0
  22. data/app/assets/stylesheets/spree/backend/plugins/select2_bootstrap4.scss +622 -0
  23. data/app/assets/stylesheets/spree/backend/spree_admin.css.scss +2 -1
  24. data/app/controllers/spree/admin/orders_controller.rb +15 -2
  25. data/app/controllers/spree/admin/products_controller.rb +2 -2
  26. data/app/controllers/spree/admin/states_controller.rb +1 -1
  27. data/app/controllers/spree/admin/taxons_controller.rb +15 -5
  28. data/app/helpers/spree/admin/base_helper.rb +21 -5
  29. data/app/helpers/spree/admin/navigation_helper.rb +11 -1
  30. data/app/helpers/spree/admin/payments_helper.rb +3 -3
  31. data/app/helpers/spree/admin/stock_movements_helper.rb +2 -0
  32. data/app/views/spree/admin/countries/index.html.erb +6 -6
  33. data/app/views/spree/admin/customer_returns/_return_item_decision.html.erb +3 -1
  34. data/app/views/spree/admin/customer_returns/_return_item_selection.html.erb +3 -1
  35. data/app/views/spree/admin/customer_returns/index.html.erb +2 -2
  36. data/app/views/spree/admin/customer_returns/new.html.erb +1 -1
  37. data/app/views/spree/admin/general_settings/edit.html.erb +25 -2
  38. data/app/views/spree/admin/option_types/index.html.erb +1 -1
  39. data/app/views/spree/admin/orders/_add_line_item.html.erb +1 -1
  40. data/app/views/spree/admin/orders/_add_product.html.erb +1 -1
  41. data/app/views/spree/admin/orders/_channel_form.html.erb +18 -0
  42. data/app/views/spree/admin/orders/_shipment.html.erb +3 -1
  43. data/app/views/spree/admin/orders/channel.html.erb +7 -0
  44. data/app/views/spree/admin/orders/customer_details/_autocomplete.js.erb +35 -12
  45. data/app/views/spree/admin/orders/customer_details/_form.html.erb +2 -2
  46. data/app/views/spree/admin/orders/customer_details/edit.html.erb +1 -1
  47. data/app/views/spree/admin/orders/index.html.erb +10 -11
  48. data/app/views/spree/admin/payment_methods/_form.html.erb +65 -46
  49. data/app/views/spree/admin/payment_methods/index.html.erb +1 -1
  50. data/app/views/spree/admin/products/_form.html.erb +4 -4
  51. data/app/views/spree/admin/products/index.html.erb +2 -1
  52. data/app/views/spree/admin/products/new.html.erb +2 -2
  53. data/app/views/spree/admin/promotion_rules/create.js.erb +1 -1
  54. data/app/views/spree/admin/promotions/_form.html.erb +1 -1
  55. data/app/views/spree/admin/promotions/actions/_create_line_items.html.erb +1 -1
  56. data/app/views/spree/admin/promotions/rules/_option_value.html.erb +8 -7
  57. data/app/views/spree/admin/promotions/rules/_product.html.erb +1 -1
  58. data/app/views/spree/admin/promotions/rules/_taxon.html.erb +1 -1
  59. data/app/views/spree/admin/promotions/rules/_user.html.erb +1 -1
  60. data/app/views/spree/admin/refunds/new.html.erb +1 -1
  61. data/app/views/spree/admin/reimbursements/edit.html.erb +4 -2
  62. data/app/views/spree/admin/reimbursements/show.html.erb +3 -1
  63. data/app/views/spree/admin/return_authorizations/_form.html.erb +7 -5
  64. data/app/views/spree/admin/return_authorizations/index.html.erb +2 -2
  65. data/app/views/spree/admin/return_index/customer_returns.html.erb +2 -2
  66. data/app/views/spree/admin/return_index/return_authorizations.html.erb +2 -2
  67. data/app/views/spree/admin/shared/_account_nav.html.erb +1 -1
  68. data/app/views/spree/admin/shared/_address_form.html.erb +7 -7
  69. data/app/views/spree/admin/shared/_head.html.erb +4 -0
  70. data/app/views/spree/admin/shared/_order_summary.html.erb +25 -21
  71. data/app/views/spree/admin/shared/_order_tabs.html.erb +9 -0
  72. data/app/views/spree/admin/shared/_refunds.html.erb +1 -1
  73. data/app/views/spree/admin/shared/_translations.html.erb +1 -0
  74. data/app/views/spree/admin/shared/_update_order_state.js.erb +6 -2
  75. data/app/views/spree/admin/shared/named_types/_index.html.erb +1 -1
  76. data/app/views/spree/admin/shipping_methods/_form.html.erb +2 -2
  77. data/app/views/spree/admin/shipping_methods/index.html.erb +5 -1
  78. data/app/views/spree/admin/stock_locations/_form.html.erb +1 -1
  79. data/app/views/spree/admin/stock_locations/index.html.erb +2 -2
  80. data/app/views/spree/admin/stock_transfers/_stock_movements.html.erb +1 -1
  81. data/app/views/spree/admin/stock_transfers/index.html.erb +42 -37
  82. data/app/views/spree/admin/stock_transfers/new.html.erb +1 -1
  83. data/app/views/spree/admin/stores/_form.html.erb +64 -11
  84. data/app/views/spree/admin/stores/index.html.erb +11 -6
  85. data/app/views/spree/admin/tax_categories/index.html.erb +1 -1
  86. data/app/views/spree/admin/tax_rates/index.html.erb +2 -2
  87. data/app/views/spree/admin/taxons/_form.html.erb +39 -35
  88. data/app/views/spree/admin/taxons/index.html.erb +1 -1
  89. data/app/views/spree/admin/users/_addresses_form.html.erb +4 -6
  90. data/app/views/spree/admin/variants/_form.html.erb +2 -2
  91. data/app/views/spree/admin/zones/index.html.erb +1 -1
  92. data/config/routes.rb +7 -1
  93. data/spree_backend.gemspec +1 -1
  94. metadata +15 -14
  95. data/app/assets/javascripts/spree/backend/tag_picker.js +0 -52
  96. data/app/assets/stylesheets/spree/backend/plugins/_select2.scss +0 -190
  97. data/app/views/spree/admin/general_settings/_form.html.erb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: caac247ae4531a6f5a3a6801e0bccfb61a89534db3db870157fd4fbc369e6f4a
4
- data.tar.gz: 1e6d1992b4ef3922e5581618ad3e3dd8217834d7cdfbdf9e037b8e6f04b77474
3
+ metadata.gz: 6ea801a7a77488cba4283f0bb1d99d237d7a5e9b180c98092837cb39f86ca794
4
+ data.tar.gz: 0b2fe5d30019037e6712b7c4cbb19def4ea4096d7b81224cc2d762654b50fd1a
5
5
  SHA512:
6
- metadata.gz: dce86a37e8ee568b809acaec411c7845c321a4850d39047167e5101fd594ade748f235d00fe4a3bec5915078c1cebe0e44bc01a1b9e9d022e3dfb4859ad20186
7
- data.tar.gz: 4e901dd7190ef44b43065ee007aa696c9d89c3e3f6acf7eb6c643712973309cdf6860bf8233c17d10ecd861358562c146e5cbe5f73256f1f307cefc20294cef1
6
+ metadata.gz: 8ce23c93f231611913fffa2accf3cb5934a53f400d3f5cb03a72db40541502e44a66b64cf6b79e74a15f27e8496fa8e696b1d65d425c95e90f86515b4deb54e2
7
+ data.tar.gz: ad48197a9b626b2cfd07d2094e94165b62e01d265054ba12755932efef8cc267071e0c9ef67e04564c14adb61a898ccb6c6ec6be94496ddcb95d02500924df63
@@ -50,7 +50,6 @@
50
50
  //= require spree/backend/taxons
51
51
  //= require spree/backend/users/edit
52
52
  //= require spree/backend/user_picker
53
- //= require spree/backend/tag_picker
54
53
  //= require spree/backend/variant_autocomplete
55
54
  //= require spree/backend/variant_management
56
55
  //= require spree/backend/zone
@@ -1,31 +1,42 @@
1
1
  // eslint-disable-next-line camelcase, no-unused-vars
2
- function update_state (region, done) {
2
+ function update_state(region, done) {
3
3
  'use strict'
4
4
 
5
- var country = $('span#' + region + 'country .select2').select2('val')
6
- var stateSelect = $('span#' + region + 'state select.select2')
7
- var stateInput = $('span#' + region + 'state input.state_name')
5
+ var countryId = $('#' + region + 'country select').val()
6
+ var stateContainer = $('#' + region + 'state').parent()
7
+ var stateSelect = $('#' + region + 'state select')
8
+ var stateInput = $('#' + region + 'state input.state_name')
8
9
 
9
- $.get(Spree.routes.states_search + '?country_id=' + country, function (data) {
10
+ $.get(Spree.routes.states_search + '?country_id=' + countryId, function (data) {
10
11
  var states = data.states
12
+ var statesRequired = data.states_required
11
13
  if (states.length > 0) {
12
14
  stateSelect.html('')
13
15
  var statesWithBlank = [{
14
16
  name: '',
15
17
  id: ''
16
18
  }].concat(states)
17
- $.each(statesWithBlank, function (pos, state) {
19
+ $.each(statesWithBlank, function (_pos, state) {
18
20
  var opt = $(document.createElement('option'))
19
21
  .prop('value', state.id)
20
22
  .html(state.name)
21
- stateSelect.append(opt)
23
+ stateSelect.append(opt).trigger('change')
22
24
  })
23
25
  stateSelect.prop('disabled', false).show()
24
26
  stateSelect.select2()
25
27
  stateInput.hide().prop('disabled', true)
28
+ stateContainer.show()
26
29
  } else {
27
- stateInput.prop('disabled', false).show()
28
- stateSelect.select2('destroy').hide()
30
+ stateSelect.val(null).trigger('change')
31
+ if (stateSelect.data('select2')) {
32
+ stateSelect.select2('destroy')
33
+ }
34
+ stateSelect.hide()
35
+ if (statesRequired) {
36
+ stateInput.prop('disabled', false).show()
37
+ } else {
38
+ stateContainer.hide()
39
+ }
29
40
  }
30
41
 
31
42
  if (done) done()
@@ -6,10 +6,12 @@ $(function () {
6
6
  // eslint-disable-next-line
7
7
  if (calculatorSelect.prop('value') == originalCalcType) {
8
8
  $('div.calculator-settings').show()
9
+ $('#shipping_method_calculator_attributes_preferred_currency').removeAttr('disabled')
9
10
  $('.calculator-settings-warning').hide()
10
11
  $('.calculator-settings').find('input, textarea').prop('disabled', false)
11
12
  } else {
12
13
  $('div.calculator-settings').hide()
14
+ $('#shipping_method_calculator_attributes_preferred_currency').attr('disabled', 'disabled')
13
15
  $('.calculator-settings-warning').show()
14
16
  $('.calculator-settings').find('input, textarea').prop('disabled', true)
15
17
  }
@@ -1,85 +1,109 @@
1
- //= require_self
2
- /* global customerTemplate, update_state */
3
- // eslint-disable-next-line camelcase
4
- var clear_address_fields = function () {
5
- var fields = ['firstname', 'lastname', 'company', 'address1', 'address2', 'city', 'zipcode', 'state_id', 'country_id', 'phone']
6
- $.each(fields, function (i, field) {
7
- $('#order_bill_address_attributes_' + field).val('')
8
- $('#order_ship_address_attributes_' + field).val('')
1
+ function clearAddressFields(addressKinds) {
2
+ if (addressKinds === undefined) {
3
+ addressKinds = ['ship', 'bill']
4
+ }
5
+ addressKinds.forEach(function(addressKind) {
6
+ ADDRESS_FIELDS.forEach(function(field) {
7
+ $('#order_' + addressKind + '_address_attributes_' + field).val('')
8
+ })
9
9
  })
10
10
  }
11
11
 
12
- $(document).ready(function () {
13
- if ($('#customer_autocomplete_template').length > 0) {
14
- window.customerTemplate = Handlebars.compile($('#customer_autocomplete_template').text())
12
+ function formatCustomerResult(customer) {
13
+ var escapedResult = window.customerTemplate({
14
+ customer: customer,
15
+ bill_address: customer.bill_address,
16
+ ship_address: customer.ship_address
17
+ })
18
+ return $(escapedResult)
19
+ }
20
+
21
+ function formatCustomerAddress(address, kind) {
22
+ $('#order_' + kind + '_address_attributes_firstname').val(address.firstname)
23
+ $('#order_' + kind + '_address_attributes_lastname').val(address.lastname)
24
+ $('#order_' + kind + '_address_attributes_address1').val(address.address1)
25
+ $('#order_' + kind + '_address_attributes_company').val(address.company)
26
+ $('#order_' + kind + '_address_attributes_address2').val(address.address2)
27
+ $('#order_' + kind + '_address_attributes_city').val(address.city)
28
+ $('#order_' + kind + '_address_attributes_zipcode').val(address.zipcode)
29
+ $('#order_' + kind + '_address_attributes_phone').val(address.phone)
30
+ $('#order_' + kind + '_address_attributes_phone').val(address.phone)
31
+ $('#order_' + kind + '_address_attributes_country_id').val(address.country_id)
32
+ $('#order_' + kind + '_address_attributes_country_id').trigger('change')
33
+
34
+ var stateSelect = $('#order_' + kind + '_address_attributes_state_id')
35
+
36
+ update_state(kind.charAt(0), function() {
37
+ stateSelect.val(address.state_id).trigger('change')
38
+ })
39
+ }
40
+
41
+ function formatCustomerSelection(customer) {
42
+ $('#order_email').val(customer.email)
43
+ $('#order_user_id').val(customer.id)
44
+ $('#guest_checkout_true').prop('checked', false)
45
+ $('#guest_checkout_false').prop('checked', true)
46
+ $('#guest_checkout_false').prop('disabled', false)
47
+
48
+ var billAddress = customer.bill_address
49
+ var shipAddress = customer.ship_address
50
+
51
+ if (billAddress) {
52
+ formatCustomerAddress(billAddress, 'bill')
53
+ } else {
54
+ clearAddressFields(['bill'])
15
55
  }
16
56
 
17
- var formatCustomerResult = function (customer) {
18
- return customerTemplate({
19
- customer: customer,
20
- bill_address: customer.bill_address,
21
- ship_address: customer.ship_address
22
- })
57
+ if (shipAddress) {
58
+ formatCustomerAddress(shipAddress, 'ship')
59
+ } else {
60
+ clearAddressFields(['ship'])
23
61
  }
24
62
 
25
- if ($('#customer_search').length > 0) {
26
- $('#customer_search').select2({
27
- placeholder: Spree.translations.choose_a_customer,
28
- ajax: {
29
- url: Spree.routes.users_api,
30
- datatype: 'json',
31
- cache: true,
32
- data: function (term, page) {
33
- return {
34
- q: {
35
- 'm': 'or',
36
- 'email_start': term,
37
- 'ship_address_firstname_start': term,
38
- 'ship_address_lastname_start': term,
39
- 'bill_address_firstname_start': term,
40
- 'bill_address_lastname_start': term
41
- },
42
- token: Spree.api_key
43
- }
44
- },
45
- results: function (data, page) {
46
- return { results: data.users }
63
+ return customer.email
64
+ }
65
+
66
+ $.fn.customerAutocomplete = function() {
67
+ this.select2({
68
+ minimumInputLength: 3,
69
+ placeholder: Spree.translations.choose_a_customer,
70
+ ajax: {
71
+ url: Spree.routes.users_api,
72
+ datatype: 'json',
73
+ data: function (params) {
74
+ return {
75
+ q: {
76
+ 'm': 'or',
77
+ email_start: params.term,
78
+ ship_address_firstname_start: params.term,
79
+ ship_address_lastname_start: params.term,
80
+ bill_address_firstname_start: params.term,
81
+ bill_address_lastname_start: params.term
82
+ },
83
+ token: Spree.api_key
47
84
  }
48
85
  },
49
- dropdownCssClass: 'customer_search',
50
- formatResult: formatCustomerResult,
51
- formatSelection: function (customer) {
52
- $('#order_email').val(customer.email)
53
- $('#order_user_id').val(customer.id)
54
- $('#guest_checkout_true').prop('checked', false)
55
- $('#guest_checkout_false').prop('checked', true)
56
- $('#guest_checkout_false').prop('disabled', false)
57
-
58
- var billAddress = customer.bill_address
59
- if (billAddress) {
60
- $('#order_bill_address_attributes_firstname').val(billAddress.firstname)
61
- $('#order_bill_address_attributes_lastname').val(billAddress.lastname)
62
- $('#order_bill_address_attributes_company').val(billAddress.company)
63
- $('#order_bill_address_attributes_address1').val(billAddress.address1)
64
- $('#order_bill_address_attributes_address2').val(billAddress.address2)
65
- $('#order_bill_address_attributes_city').val(billAddress.city)
66
- $('#order_bill_address_attributes_zipcode').val(billAddress.zipcode)
67
- $('#order_bill_address_attributes_phone').val(billAddress.phone)
68
-
69
- $('#order_bill_address_attributes_country_id').select2('val', billAddress.country_id).promise().done(function () {
70
- update_state('b', function () {
71
- $('#order_bill_address_attributes_state_id').select2('val', billAddress.state_id)
72
- })
73
- })
74
- } else {
75
- clear_address_fields()
76
- }
77
- return Select2.util.escapeMarkup(customer.email)
86
+ processResults: function (data) {
87
+ return { results: data.users }
78
88
  }
79
- })
89
+ },
90
+ templateResult: formatCustomerResult
91
+ }).on('select2:select', function (e) {
92
+ var data = e.params.data;
93
+ formatCustomerSelection(data)
94
+ })
95
+ }
96
+
97
+ document.addEventListener('DOMContentLoaded', function() {
98
+ $('#customer_search').customerAutocomplete()
99
+
100
+ if ($('#customer_autocomplete_template').length > 0) {
101
+ window.customerTemplate = Handlebars.compile($('#customer_autocomplete_template').text())
80
102
  }
81
103
 
104
+ // Handle Billing Shipping Address
82
105
  var orderUseBillingInput = $('input#order_use_billing')
106
+
83
107
  var orderUseBilling = function () {
84
108
  if (!orderUseBillingInput.is(':checked')) {
85
109
  $('#shipping').show()
@@ -88,13 +112,17 @@ $(document).ready(function () {
88
112
  }
89
113
  }
90
114
 
91
- orderUseBillingInput.click(orderUseBilling)
115
+ // On page load hide shipping address from
92
116
  orderUseBilling()
93
117
 
118
+ // On click togggle shipping address from
119
+ orderUseBillingInput.click(orderUseBilling)
120
+
121
+ // If guest checkout clear fields
94
122
  $('#guest_checkout_true').change(function () {
95
123
  $('#customer_search').val('')
96
124
  $('#order_user_id').val('')
97
125
  $('#order_email').val('')
98
- clear_address_fields()
126
+ clearAddressFields()
99
127
  })
100
128
  })
@@ -19,7 +19,7 @@ $(document).ready(function () {
19
19
 
20
20
  function addVariant () {
21
21
  $('#stock_details').hide()
22
- var variantId = $('input.variant_autocomplete').val()
22
+ var variantId = $('select.variant_autocomplete').val()
23
23
  var quantity = $('input#variant_quantity').val()
24
24
 
25
25
  adjustLineItems(order_number, variantId, quantity)
@@ -1,43 +1,37 @@
1
- $(document).ready(function () {
1
+ $.fn.optionTypeAutocomplete = function () {
2
2
  'use strict'
3
3
 
4
- function formatOptionType (optionType) {
5
- return Select2.util.escapeMarkup(optionType.presentation + ' (' + optionType.name + ')')
6
- }
7
-
8
- if ($('#product_option_type_ids').length > 0) {
9
- $('#product_option_type_ids').select2({
10
- placeholder: Spree.translations.option_type_placeholder,
11
- multiple: true,
12
- initSelection: function (element, callback) {
13
- var url = Spree.url(Spree.routes.option_types_api, {
14
- ids: element.val(),
4
+ this.select2({
5
+ minimumInputLength: 2,
6
+ multiple: true,
7
+ ajax: {
8
+ url: Spree.routes.option_types_api,
9
+ datatype: 'json',
10
+ data: function (params) {
11
+ var query = {
12
+ q: {
13
+ name_cont: params.term
14
+ },
15
15
  token: Spree.api_key
16
- })
17
- return $.getJSON(url, null, function (data) {
18
- return callback(data)
19
- })
20
- },
21
- ajax: {
22
- url: Spree.routes.option_types_api,
23
- quietMillis: 200,
24
- datatype: 'json',
25
- data: function (term) {
26
- return {
27
- q: {
28
- name_cont: term
29
- },
30
- token: Spree.api_key
31
- }
32
- },
33
- results: function (data) {
34
- return {
35
- results: data
36
- }
37
16
  }
17
+
18
+ return query
38
19
  },
39
- formatResult: formatOptionType,
40
- formatSelection: formatOptionType
41
- })
42
- }
20
+ processResults: function (data) {
21
+ return {
22
+ results: data
23
+ }
24
+ }
25
+ },
26
+ templateResult: function (optionType) {
27
+ return optionType.name
28
+ },
29
+ templateSelection: function (optionType) {
30
+ return optionType.text
31
+ }
32
+ })
33
+ }
34
+
35
+ $(document).ready(function () {
36
+ $('#product_option_type_ids').optionTypeAutocomplete()
43
37
  })
@@ -5,40 +5,67 @@ $.fn.optionValueAutocomplete = function (options) {
5
5
  options = options || {}
6
6
  var multiple = typeof (options.multiple) !== 'undefined' ? options.multiple : true
7
7
  var productSelect = options.productSelect
8
+ var productId = options.productId
9
+ var values = options.values
10
+ var clearSelection = options.clearSelection
11
+
12
+ function formatOptionValueList(values) {
13
+ return values.map(function(obj) {
14
+ return { id: obj.id, text: obj.name }
15
+ })
16
+ }
17
+
18
+ function addOptions(select, productId, values) {
19
+ $.ajax({
20
+ type: 'GET',
21
+ url: Spree.routes.option_values_api,
22
+ dataType: 'json',
23
+ data: {
24
+ token: Spree.api_key,
25
+ q: {
26
+ id_in: values,
27
+ variants_product_id_eq: productId
28
+ }
29
+ }
30
+ }).then(function (data) {
31
+ select.addSelect2Options(data)
32
+ })
33
+ }
8
34
 
9
35
  this.select2({
10
- minimumInputLength: 3,
11
36
  multiple: multiple,
12
- initSelection: function (element, callback) {
13
- $.get(Spree.routes.option_values_api, {
14
- ids: element.val().split(','),
15
- token: Spree.api_key
16
- }, function (data) {
17
- callback(multiple ? data : data[0])
18
- })
19
- },
37
+ minimumInputLength: 1,
20
38
  ajax: {
21
39
  url: Spree.routes.option_values_api,
22
- datatype: 'json',
23
- data: function (term) {
24
- var productId = typeof (productSelect) !== 'undefined' ? $(productSelect).select2('val') : null
25
- return {
40
+ dataType: 'json',
41
+ data: function (params) {
42
+ var selectedProductId = typeof (productSelect) !== 'undefined' ? productSelect.val() : null
43
+
44
+ var query = {
26
45
  q: {
27
- name_cont: term,
28
- variants_product_id_eq: productId
46
+ name_cont: params.term,
47
+ variants_product_id_eq: selectedProductId
29
48
  },
30
49
  token: Spree.api_key
31
50
  }
51
+
52
+ return query;
32
53
  },
33
- results: function (data) {
34
- return { results: data }
54
+ processResults: function(data) {
55
+ var results = formatOptionValueList(data)
56
+
57
+ return {
58
+ results: results
59
+ }
35
60
  }
36
- },
37
- formatResult: function (optionValue) {
38
- return optionValue.name
39
- },
40
- formatSelection: function (optionValue) {
41
- return optionValue.name
42
61
  }
43
62
  })
63
+
64
+ if (values && productId && !clearSelection) {
65
+ addOptions(this, productId, values)
66
+ }
67
+
68
+ if (clearSelection) {
69
+ this.val(null).trigger('change')
70
+ }
44
71
  }