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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 432b1bf79ccce9af126f1d991c7a00a926a80d2e6aa3544c93650a2860591628
4
- data.tar.gz: 71d1daeb82bb9c9631c5e947a98437478b6c347d0e55846c84b5d653dbe02aaf
3
+ metadata.gz: e4368e7df9fc3882efa34baf6e16a26913563e5fe65d22a25c713183de60c415
4
+ data.tar.gz: e12d8dc10ba44101a9dd0e75cab9d0cf1a3390d328e03018a10d0817057bcec0
5
5
  SHA512:
6
- metadata.gz: 9969c5d1b405bbc2f00530a08b97c182a35460295f3929befc05a6288756fc908df1a8e2ad9ce9d281667b65d3bd698452248cfe712cce94fb563a0f3ba1b348
7
- data.tar.gz: 9778aaf69204141275c167df461034b75c40033c9ab91b92db45d1a00138f573251090d0b40f5a5934e43d6dbe45e5befca8a3c28d05e9b47f7313bdfbe5e89a
6
+ metadata.gz: b387a6fa2a3e0088cb86050043d02453dde1b895980e2c84695c582d74d26d84a19ac5e366919b1443ac7a407c9f454b79f96afd7e2a77ed54d7170f3c3bf918
7
+ data.tar.gz: e30bbc17a4c2a9ee5119b55f7cce80b0a324332da3d93821ce5a49097b5c3da8d3ff2b74f16b550872bf1ca01aa45e79f4e57cd97858abf0470b5c2cea89aff6
@@ -1,7 +1,8 @@
1
- const setupReorderable = ({ table, onUpdate }) => {
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
- onUpdate(dragSrc)
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
- onUpdate: (row) => {
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
  }
@@ -1,3 +1,3 @@
1
1
  module ActiveadminReorderable
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "activeadmin_reorderable",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Drag and drop to reorder your ActiveAdmin tables.",
5
5
  "main": "app/assets/javascripts/activeadmin_reorderable.js",
6
6
  "files": [
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.1
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-15 00:00:00.000000000 Z
13
+ date: 2024-07-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activeadmin