active_scaffold_sortable 3.2.4 → 3.2.5

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
  SHA1:
3
- metadata.gz: 666d92caced88e95e8c98bf4ed2cd815d31425b5
4
- data.tar.gz: a4e865644f6d648ad1efb607aa01ac6b826b0473
3
+ data.tar.gz: 29f2059c445752f852c6589e5477bf02b5198f00
4
+ metadata.gz: e78ba9e92f9bcf097b6b478e0876121e9d62947c
5
5
  SHA512:
6
- metadata.gz: 03c17a7e0d497d11633ea691723d0d6436e44046ae1d0a6909ebbf58e9ac9bb882bec6f2d4444b35fc4f992425ab7bf7357f7ddd16ef5e951a231652bf66ad54
7
- data.tar.gz: 0167d621ad24ef17534739a6f2ffe94ffddd79554903757eea345b58dcb195fffc3ead9be29a82adf2e0371ae60b1af986324a506cfe949164668b16e23673ab
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
- current_order = model.find(params[active_scaffold_tbody_id].first).try(:self_and_siblings)
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
- if record_id != current_order[new_position].id
66
- current_order = move_child(current_order.find {|child| child.id == record_id}, new_position, current_order)
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, new_position, children)
72
- old_position = children.index(child)
73
- (old_position - new_position).abs.times do |step|
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
 
@@ -2,7 +2,7 @@ module ActiveScaffoldSortable
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 2
5
- PATCH = 4
5
+ PATCH = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold_sortable
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.4
4
+ version: 3.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Cambra