summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-09-30 18:35:50 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-09-30 18:35:50 +0000
commit043264b6510cabc7b40b0c124483f9e486798858 (patch)
treeac23f72eb6f4d41458e410b71b887fec8e66681a /app
parent44644679908ca0d292a9aa5113d5d93d2aa754f6 (diff)
downloadredmine-043264b6510cabc7b40b0c124483f9e486798858.tar.gz
redmine-043264b6510cabc7b40b0c124483f9e486798858.zip
Forces enumeration override position to the same as its parent (#19657).
git-svn-id: http://svn.redmine.org/redmine/trunk@14627 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/enumeration.rb28
1 files changed, 27 insertions, 1 deletions
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index e53ee1fd4..4f5e1e377 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -22,7 +22,7 @@ class Enumeration < ActiveRecord::Base
belongs_to :project
- acts_as_list :scope => 'type = \'#{type}\''
+ acts_as_list :scope => 'type = \'#{type}\' AND #{parent_id ? "parent_id = #{parent_id}" : "parent_id IS NULL"}'
acts_as_customizable
acts_as_tree
@@ -129,11 +129,37 @@ class Enumeration < ActiveRecord::Base
return new == previous
end
+ # Overrides acts_as_list reset_positions_in_list so that enumeration overrides
+ # get the same position as the overriden enumeration
+ def reset_positions_in_list
+ super
+ self.class.
+ where("parent_id IS NOT NULL").
+ update_all("position = (SELECT MIN(position) FROM #{self.class.table_name} p WHERE p.id = #{self.class.table_name}.parent_id)")
+ end
+
private
def check_integrity
raise "Cannot delete enumeration" if self.in_use?
end
+ # Overrides acts_as_list add_to_list_bottom so that enumeration overrides
+ # get the same position as the overriden enumeration
+ def add_to_list_bottom
+ if parent
+ self[position_column] = parent.position
+ else
+ super
+ end
+ end
+
+ # Overrides acts_as_list remove_from_list so that enumeration overrides
+ # get the same position as the overriden enumeration
+ def remove_from_list
+ if parent_id.blank?
+ super
+ end
+ end
end
# Force load the subclasses in development mode