-
-
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.
Merge pull request #3754 from penrosehill/js-expose-refresh-sortable-…
…tables Expose js function: Spree.SortableTable.refresh
- Loading branch information
Showing
1 changed file
with
30 additions
and
26 deletions.
There are no files selected for viewing
56 changes: 30 additions & 26 deletions
56
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,32 +1,36 @@ | ||
//= require solidus_admin/Sortable | ||
/* eslint no-unused-vars: "off" */ | ||
|
||
Spree.ready(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.SortableTable.refresh); |