comparison app/models/enumeration.rb @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children e248c7af89ec
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
22 22
23 belongs_to :project 23 belongs_to :project
24 24
25 acts_as_list :scope => 'type = \'#{type}\'' 25 acts_as_list :scope => 'type = \'#{type}\''
26 acts_as_customizable 26 acts_as_customizable
27 acts_as_tree :order => 'position ASC' 27 acts_as_tree :order => "#{Enumeration.table_name}.position ASC"
28 28
29 before_destroy :check_integrity 29 before_destroy :check_integrity
30 before_save :check_default 30 before_save :check_default
31 31
32 attr_protected :type 32 attr_protected :type
33 33
34 validates_presence_of :name 34 validates_presence_of :name
35 validates_uniqueness_of :name, :scope => [:type, :project_id] 35 validates_uniqueness_of :name, :scope => [:type, :project_id]
36 validates_length_of :name, :maximum => 30 36 validates_length_of :name, :maximum => 30
37 37
38 scope :shared, where(:project_id => nil) 38 scope :shared, lambda { where(:project_id => nil) }
39 scope :sorted, order("#{table_name}.position ASC") 39 scope :sorted, lambda { order("#{table_name}.position ASC") }
40 scope :active, where(:active => true) 40 scope :active, lambda { where(:active => true) }
41 scope :system, lambda { where(:project_id => nil) }
41 scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} 42 scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
42 43
43 def self.default 44 def self.default
44 # Creates a fake default scope so Enumeration.default will check 45 # Creates a fake default scope so Enumeration.default will check
45 # it's type. STI subclasses will automatically add their own 46 # it's type. STI subclasses will automatically add their own