-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spree.SortableTable.refresh to reload the component
- Loading branch information
Showing
1 changed file
with
28 additions
and
26 deletions.
There are no files selected for viewing
54 changes: 28 additions & 26 deletions
54
backend/app/assets/javascripts/spree/backend/components/sortable_table.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,36 @@ | ||
//= require solidus_admin/Sortable | ||
/* eslint no-unused-vars: "off" */ | ||
|
||
Spree.refresh_sortable_tables = function() { | ||
var sortable_tables = document.querySelectorAll('table.sortable'); | ||
Spree.SortableTable = { | ||
refresh: function() { | ||
var sortable_tables = document.querySelectorAll('table.sortable'); | ||
|
||
_.each(sortable_tables, function(table) { | ||
var url = table.getAttribute('data-sortable-link'); | ||
var tbody = table.querySelector('tbody'); | ||
var sortable = Sortable.create(tbody,{ | ||
handle: ".handle", | ||
onEnd: function(e) { | ||
var positions = {}; | ||
_.each(e.to.querySelectorAll('tr'), function(el, index) { | ||
var idAttr = el.id; | ||
if (idAttr) { | ||
var objId = idAttr.split('_').slice(-1); | ||
if (!isNaN(objId)) { | ||
positions['positions['+objId+']'] = index + 1; | ||
_.each(sortable_tables, function(table) { | ||
var url = table.getAttribute('data-sortable-link'); | ||
var tbody = table.querySelector('tbody'); | ||
var sortable = Sortable.create(tbody,{ | ||
handle: ".handle", | ||
onEnd: function(e) { | ||
var positions = {}; | ||
_.each(e.to.querySelectorAll('tr'), function(el, index) { | ||
var idAttr = el.id; | ||
if (idAttr) { | ||
var objId = idAttr.split('_').slice(-1); | ||
if (!isNaN(objId)) { | ||
positions['positions['+objId+']'] = index + 1; | ||
} | ||
} | ||
} | ||
}); | ||
Spree.ajax({ | ||
type: 'POST', | ||
dataType: 'json', | ||
url: url, | ||
data: positions, | ||
}); | ||
} | ||
}); | ||
Spree.ajax({ | ||
type: 'POST', | ||
dataType: 'json', | ||
url: url, | ||
data: positions, | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
Spree.ready(Spree.refresh_sortable_tables); | ||
Spree.ready(Spree.SortableTable.refresh); |