From 73dba2ac044f9ff5de1917fd2457fd1a7b3f3377 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 5 Oct 2007 17:44:15 +0000 Subject: 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 --- app/models/enumeration.rb | 12 ++++++++---- app/models/issue.rb | 14 +++++++++++--- app/views/enumerations/_form.rhtml | 3 +++ app/views/enumerations/list.rhtml | 1 + 4 files changed, 23 insertions(+), 7 deletions(-) (limited to 'app') 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 diff --git a/app/views/enumerations/_form.rhtml b/app/views/enumerations/_form.rhtml index 637605939..3f98f5213 100644 --- a/app/views/enumerations/_form.rhtml +++ b/app/views/enumerations/_form.rhtml @@ -5,5 +5,8 @@

<%= text_field 'enumeration', 'name' %>

+ +

+<%= check_box 'enumeration', 'is_default' %>

\ No newline at end of file diff --git a/app/views/enumerations/list.rhtml b/app/views/enumerations/list.rhtml index f92ca0a31..bab4df830 100644 --- a/app/views/enumerations/list.rhtml +++ b/app/views/enumerations/list.rhtml @@ -9,6 +9,7 @@ <% enumerations.each do |enumeration| %> <%= link_to enumeration.name, :action => 'edit', :id => enumeration %> + <%= image_tag('true.png') if enumeration.is_default? %> <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => enumeration, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %> <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => enumeration, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> - -- cgit v1.2.3