Mercurial > hg > soundsoftware-site
comparison app/models/enumeration.rb @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | 433d4f72a19b |
children | e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1295:622f24f53b42 |
---|---|
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 |