Skip to content

Commit

Permalink
Spree.SortableTable.refresh to reload the component
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoao86 committed Sep 8, 2020
1 parent 7f0c3aa commit fb4f841
Showing 1 changed file with 28 additions and 26 deletions.
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);

0 comments on commit fb4f841

Please sign in to comment.