activeadmin_reorderable 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/activeadmin_reorderable.js +17 -6
- data/lib/activeadmin_reorderable/version.rb +1 -1
- data/package.json +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4368e7df9fc3882efa34baf6e16a26913563e5fe65d22a25c713183de60c415
|
4
|
+
data.tar.gz: e12d8dc10ba44101a9dd0e75cab9d0cf1a3390d328e03018a10d0817057bcec0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b387a6fa2a3e0088cb86050043d02453dde1b895980e2c84695c582d74d26d84a19ac5e366919b1443ac7a407c9f454b79f96afd7e2a77ed54d7170f3c3bf918
|
7
|
+
data.tar.gz: e30bbc17a4c2a9ee5119b55f7cce80b0a324332da3d93821ce5a49097b5c3da8d3ff2b74f16b550872bf1ca01aa45e79f4e57cd97858abf0470b5c2cea89aff6
|
@@ -1,7 +1,8 @@
|
|
1
|
-
const setupReorderable = ({ table,
|
1
|
+
const setupReorderable = ({ table, onDragover, onDragEnd }) => {
|
2
2
|
const rows = table.getElementsByTagName('tbody')[0].rows
|
3
3
|
|
4
4
|
let dragSrc = null
|
5
|
+
let srcIndex = null
|
5
6
|
|
6
7
|
for (var i = 0; i < rows.length; i++) {
|
7
8
|
const row = rows[i]
|
@@ -15,6 +16,7 @@ const setupReorderable = ({ table, onUpdate }) => {
|
|
15
16
|
e.dataTransfer.effectAllowed = "move"
|
16
17
|
|
17
18
|
dragSrc = row
|
19
|
+
srcIndex = row.rowIndex
|
18
20
|
|
19
21
|
// Apply styling a millisecond later, so the dragging image shows up correctly
|
20
22
|
setTimeout(() => { row.classList.add("dragged-row") }, 1)
|
@@ -34,7 +36,7 @@ const setupReorderable = ({ table, onUpdate }) => {
|
|
34
36
|
} else {
|
35
37
|
table.tBodies[0].insertBefore(dragSrc, row)
|
36
38
|
}
|
37
|
-
|
39
|
+
onDragover(dragSrc)
|
38
40
|
}
|
39
41
|
})
|
40
42
|
|
@@ -42,7 +44,13 @@ const setupReorderable = ({ table, onUpdate }) => {
|
|
42
44
|
// Disable dragging, so only the handle can start the dragging again
|
43
45
|
row.setAttribute("draggable", "false")
|
44
46
|
row.classList.remove("dragged-row")
|
47
|
+
|
48
|
+
if (srcIndex != row.rowIndex) {
|
49
|
+
onDragEnd(dragSrc)
|
50
|
+
}
|
51
|
+
|
45
52
|
dragSrc = null
|
53
|
+
srcIndex = null
|
46
54
|
})
|
47
55
|
}
|
48
56
|
}
|
@@ -85,11 +93,8 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
85
93
|
document.querySelectorAll("table.aa-reorderable").forEach((table) => {
|
86
94
|
setupReorderable({
|
87
95
|
table,
|
88
|
-
|
96
|
+
onDragover: (_row) => {
|
89
97
|
const allRows = table.getElementsByTagName('tbody')[0].rows
|
90
|
-
const handle = row.querySelector(".reorder-handle")
|
91
|
-
const url = handle.dataset["reorderUrl"]
|
92
|
-
const rowIndex = Array.prototype.indexOf.call(allRows, row)
|
93
98
|
|
94
99
|
for (var i = 0; i < allRows.length; i++) {
|
95
100
|
const loopRow = allRows[i]
|
@@ -97,6 +102,12 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
97
102
|
updateEvenOddClasses(loopRow, index)
|
98
103
|
updatePositionText(loopRow, index)
|
99
104
|
}
|
105
|
+
},
|
106
|
+
onDragEnd: (row) => {
|
107
|
+
const handle = row.querySelector(".reorder-handle")
|
108
|
+
const url = handle.dataset["reorderUrl"]
|
109
|
+
const allRows = table.getElementsByTagName('tbody')[0].rows
|
110
|
+
const rowIndex = Array.prototype.indexOf.call(allRows, row)
|
100
111
|
|
101
112
|
updateBackend(url, rowIndex + 1)
|
102
113
|
}
|
data/package.json
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_reorderable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Kniffin
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-07-
|
13
|
+
date: 2024-07-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activeadmin
|