app/assets/javascripts/spree/backend/taxons.js in spree_backend-4.3.3 vs app/assets/javascripts/spree/backend/taxons.js in spree_backend-4.4.0.rc1
- old
+ new
@@ -1,7 +1,7 @@
/* global productTemplate */
-$(function () {
+document.addEventListener("spree:load", function() {
window.productTemplate = Handlebars.compile($('#product_template').text())
var taxonProducts = $('#taxon_products')
var taxonId = $('#taxon_id')
var el = document.getElementById('taxon_products')
@@ -12,24 +12,27 @@
animation: 550,
easing: 'cubic-bezier(1, 0, 0, 1)',
swapThreshold: 0.9,
forceFallback: true,
onEnd: function (evt) {
- var classificationId = evt.item.getAttribute('data-classification-id')
- var newIndex = evt.newIndex
- return $.ajax({
- url: Spree.routes.classifications_api_v2 + '/' + classificationId.toString() + '/reposition',
- headers: Spree.apiV2Authentication(),
- method: 'PUT',
- dataType: 'json',
- data: {
- classification: {
- position: newIndex
- }
- }
- })
+ handleClassificationReposition(evt)
}
})
+ }
+
+ function handleClassificationReposition(evt) {
+ var classificationId = evt.item.getAttribute('data-classification-id')
+ var data = {
+ classification: {
+ position: parseInt(evt.newIndex, 10) + 1
+ }
+ }
+ var requestData = {
+ uri: Spree.routes.classifications_api_v2 + '/' + classificationId,
+ method: 'PATCH',
+ dataBody: data,
+ }
+ spreeFetchRequest(requestData)
}
if (taxonId.length > 0) {
taxonId.select2({
placeholder: Spree.translations.find_a_taxon,