active_scaffold_sortable 3.2.4 → 3.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_scaffold/actions/sortable.rb +11 -9
- data/lib/active_scaffold_sortable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
|
4
|
-
|
3
|
+
data.tar.gz: 29f2059c445752f852c6589e5477bf02b5198f00
|
4
|
+
metadata.gz: e78ba9e92f9bcf097b6b478e0876121e9d62947c
|
5
5
|
SHA512:
|
6
|
-
|
7
|
-
|
6
|
+
data.tar.gz: 2366be6e69888f911a3c59b882a4df4de26ba5509e8271e3d2702d55de7969976bd8809d3e3b3f08ddcd61f90f4ea825a908457fe713b9a32bc8425676bfbcbe
|
7
|
+
metadata.gz: bf80be7ee099ae651ad39fa51b3260a03220d08cbab61b3508e93a326fe69df6f88e3bd54d7c0bbae238bfab91d6ca439b0405596941aeed4160c8a691b158b4
|
@@ -59,20 +59,22 @@ module ActiveScaffold::Actions
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def reorder_children_in_tree(model)
|
62
|
-
|
62
|
+
full_order = model.find(params[active_scaffold_tbody_id].first).try(:self_and_siblings)
|
63
63
|
new_order = params[active_scaffold_tbody_id].collect {|item_id| item_id.to_i}
|
64
|
+
current_order = full_order.length == new_order.length ? full_order : full_order.select{ |r| new_order.include? r.id }
|
65
|
+
|
64
66
|
new_order.each_with_index do |record_id, new_position|
|
65
|
-
|
66
|
-
|
67
|
+
child = full_order.find {|child| child.id == record_id}
|
68
|
+
while record_id != current_order[new_position].id do
|
69
|
+
full_order = move_child(child, current_order.index(child), new_position)
|
70
|
+
current_order = full_order.length == new_order.length ? full_order : full_order.select{ |r| new_order.include? r.id }
|
67
71
|
end
|
68
72
|
end if new_order.length == current_order.length
|
69
73
|
end
|
70
|
-
|
71
|
-
def move_child(child,
|
72
|
-
|
73
|
-
(old_position - new_position).abs.times
|
74
|
-
child.send((old_position - new_position) > 0 ? :move_left : :move_right)
|
75
|
-
end
|
74
|
+
|
75
|
+
def move_child(child, old_position, new_position)
|
76
|
+
method = (old_position - new_position) > 0 ? :move_left : :move_right
|
77
|
+
(old_position - new_position).abs.times { |_| child.send(method) }
|
76
78
|
child.self_and_siblings
|
77
79
|
end
|
78
80
|
|