Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorize uuid for existing object in sortable table #4287

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
//= require solidus_admin/Sortable
/* eslint no-unused-vars: "off" */

/* Check if string is valid UUID */
function isAValidUUID(str) {
// https://stackoverflow.com/a/13653180/8170555
const regexExp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

return regexExp.test(str);
}

Spree.SortableTable = {
refresh: function() {
var sortable_tables = document.querySelectorAll('table.sortable');
Expand All @@ -16,7 +24,7 @@ Spree.SortableTable = {
var idAttr = el.id;
if (idAttr) {
var objId = idAttr.split('_').slice(-1);
if (!isNaN(objId)) {
if (!isNaN(objId) || isAValidUUID(objId)) {
positions['positions['+objId+']'] = index + 1;
}
}
Expand Down