diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-10-05 17:44:15 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-10-05 17:44:15 +0000 |
commit | 73dba2ac044f9ff5de1917fd2457fd1a7b3f3377 (patch) | |
tree | 8ec8a0c78d11565ede2e1e15715b65cf7c326ed1 /app/models | |
parent | fd7910efc9e2620b77028153bb7a34fc4e66c4a7 (diff) | |
download | redmine-73dba2ac044f9ff5de1917fd2457fd1a7b3f3377.tar.gz redmine-73dba2ac044f9ff5de1917fd2457fd1a7b3f3377.zip |
Added default value for enumerations.
Only default issue priority is actually used.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@803 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/enumeration.rb | 12 | ||||
-rw-r--r-- | app/models/issue.rb | 14 |
2 files changed, 19 insertions, 7 deletions
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb index b0ad48bc7..744bc1a88 100644 --- a/app/models/enumeration.rb +++ b/app/models/enumeration.rb @@ -34,14 +34,18 @@ class Enumeration < ActiveRecord::Base def self.get_values(option) find(:all, :conditions => {:opt => option}, :order => 'position') end + + def self.default(option) + find(:first, :conditions => {:opt => option, :is_default => true}, :order => 'position') + end def option_name OPTIONS[self.opt] end - - #def <=>(enumeration) - # position <=> enumeration.position - #end + + def before_save + Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt}) if is_default? + end def to_s; name end diff --git a/app/models/issue.rb b/app/models/issue.rb index 7d214de8a..52e21b416 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -46,9 +46,17 @@ class Issue < ActiveRecord::Base validates_numericality_of :estimated_hours, :allow_nil => true validates_associated :custom_values, :on => :update - # set default status for new issues - def before_validation - self.status = IssueStatus.default if status.nil? + def after_initialize + if new_record? + # set default values for new records only + self.status ||= IssueStatus.default + self.priority ||= Enumeration.default('IPRI') + end + end + + def priority_id=(pid) + self.priority = nil + write_attribute(:priority_id, pid) end def validate |