Mercurial > hg > soundsoftware-site
comparison app/models/enumeration.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 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. |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 class Enumeration < ActiveRecord::Base | 18 class Enumeration < ActiveRecord::Base |
19 include Redmine::SubclassFactory | |
20 | |
19 default_scope :order => "#{Enumeration.table_name}.position ASC" | 21 default_scope :order => "#{Enumeration.table_name}.position ASC" |
20 | 22 |
21 belongs_to :project | 23 belongs_to :project |
22 | 24 |
23 acts_as_list :scope => 'type = \'#{type}\'' | 25 acts_as_list :scope => 'type = \'#{type}\'' |
25 acts_as_tree :order => 'position ASC' | 27 acts_as_tree :order => 'position ASC' |
26 | 28 |
27 before_destroy :check_integrity | 29 before_destroy :check_integrity |
28 before_save :check_default | 30 before_save :check_default |
29 | 31 |
32 attr_protected :type | |
33 | |
30 validates_presence_of :name | 34 validates_presence_of :name |
31 validates_uniqueness_of :name, :scope => [:type, :project_id] | 35 validates_uniqueness_of :name, :scope => [:type, :project_id] |
32 validates_length_of :name, :maximum => 30 | 36 validates_length_of :name, :maximum => 30 |
33 | 37 |
34 named_scope :shared, :conditions => { :project_id => nil } | 38 scope :shared, where(:project_id => nil) |
35 named_scope :active, :conditions => { :active => true } | 39 scope :sorted, order("#{table_name}.position ASC") |
36 named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} | 40 scope :active, where(:active => true) |
41 scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} | |
37 | 42 |
38 def self.default | 43 def self.default |
39 # Creates a fake default scope so Enumeration.default will check | 44 # Creates a fake default scope so Enumeration.default will check |
40 # it's type. STI subclasses will automatically add their own | 45 # it's type. STI subclasses will automatically add their own |
41 # types to the finder. | 46 # types to the finder. |
42 if self.descends_from_active_record? | 47 if self.descends_from_active_record? |
43 find(:first, :conditions => { :is_default => true, :type => 'Enumeration' }) | 48 where(:is_default => true, :type => 'Enumeration').first |
44 else | 49 else |
45 # STI classes are | 50 # STI classes are |
46 find(:first, :conditions => { :is_default => true }) | 51 where(:is_default => true).first |
47 end | 52 end |
48 end | 53 end |
49 | 54 |
50 # Overloaded on concrete classes | 55 # Overloaded on concrete classes |
51 def option_name | 56 def option_name |
52 nil | 57 nil |
53 end | 58 end |
54 | 59 |
55 def check_default | 60 def check_default |
56 if is_default? && is_default_changed? | 61 if is_default? && is_default_changed? |
57 Enumeration.update_all("is_default = #{connection.quoted_false}", {:type => type}) | 62 Enumeration.update_all({:is_default => false}, {:type => type}) |
58 end | 63 end |
59 end | 64 end |
60 | 65 |
61 # Overloaded on concrete classes | 66 # Overloaded on concrete classes |
62 def objects_count | 67 def objects_count |
92 # Returns the Subclasses of Enumeration. Each Subclass needs to be | 97 # Returns the Subclasses of Enumeration. Each Subclass needs to be |
93 # required in development mode. | 98 # required in development mode. |
94 # | 99 # |
95 # Note: subclasses is protected in ActiveRecord | 100 # Note: subclasses is protected in ActiveRecord |
96 def self.get_subclasses | 101 def self.get_subclasses |
97 @@subclasses[Enumeration] | 102 subclasses |
98 end | 103 end |
99 | 104 |
100 # Does the +new+ Hash override the previous Enumeration? | 105 # Does the +new+ Hash override the previous Enumeration? |
101 def self.overridding_change?(new, previous) | 106 def self.overridding_change?(new, previous) |
102 if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new,previous) | 107 if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new,previous) |