-# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Enumeration < ActiveRecord::Base
default_scope :order => "#{Enumeration.table_name}.position ASC"
-
+
belongs_to :project
-
+
acts_as_list :scope => 'type = \'#{type}\''
acts_as_customizable
acts_as_tree :order => 'position ASC'
before_destroy :check_integrity
-
+
validates_presence_of :name
validates_uniqueness_of :name, :scope => [:type, :project_id]
validates_length_of :name, :maximum => 30
find(:first, :conditions => { :is_default => true })
end
end
-
+
# Overloaded on concrete classes
def option_name
nil
Enumeration.update_all("is_default = #{connection.quoted_false}", {:type => type})
end
end
-
+
# Overloaded on concrete classes
def objects_count
0
end
-
+
def in_use?
self.objects_count != 0
end
def is_override?
!self.parent.nil?
end
-
+
alias :destroy_without_reassign :destroy
-
+
# Destroy the enumeration
# If a enumeration is specified, objects are reassigned
def destroy(reassign_to = nil)
end
destroy_without_reassign
end
-
+
def <=>(enumeration)
position <=> enumeration.position
end
-
+
def to_s; name end
# Returns the Subclasses of Enumeration. Each Subclass needs to be
return true
end
-
+
# Are the new and previous fields equal?
def self.same_active_state?(new, previous)
new = (new == "1" ? true : false)
return new == previous
end
-
+
private
def check_integrity
raise "Can't delete enumeration" if self.in_use?