diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-06-09 07:27:43 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-06-09 07:27:43 +0000 |
commit | 2314e41474b8d15fa7fa496de2b93875429adb5e (patch) | |
tree | 0d2c81700e858805a15ec900dd4b30a6686e4af3 /lib/plugins | |
parent | 77bac4b14d3bdf0ec53d88ee4aef05471bd8d198 (diff) | |
download | redmine-2314e41474b8d15fa7fa496de2b93875429adb5e.tar.gz redmine-2314e41474b8d15fa7fa496de2b93875429adb5e.zip |
Priorities have the same position and can't be reordered (#11098).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9781 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/acts_as_list/lib/active_record/acts/list.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/plugins/acts_as_list/lib/active_record/acts/list.rb b/lib/plugins/acts_as_list/lib/active_record/acts/list.rb index 01b414a1c..cd4658c59 100644 --- a/lib/plugins/acts_as_list/lib/active_record/acts/list.rb +++ b/lib/plugins/acts_as_list/lib/active_record/acts/list.rb @@ -131,6 +131,15 @@ module ActiveRecord when 'lowest' move_to_bottom end + reset_positions_in_list + end + + def reset_positions_in_list + acts_as_list_class.where(scope_condition).reorder("#{position_column} ASC, id ASC").each_with_index do |item, i| + unless item.send(position_column) == (i + 1) + acts_as_list_class.update_all({position_column => (i + 1)}, {:id => item.id}) + end + end end # Removes the item from the list. @@ -209,7 +218,7 @@ module ActiveRecord def bottom_item(except = nil) conditions = scope_condition conditions = "#{conditions} AND #{self.class.primary_key} != #{except.id}" if except - acts_as_list_class.find(:first, :conditions => conditions, :order => "#{position_column} DESC") + acts_as_list_class.where(conditions).reorder("#{position_column} DESC").first end # Forces item to assume the bottom position in the list. |