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
This commit is contained in:
Jean-Philippe Lang 2007-10-05 17:44:15 +00:00
parent fd7910efc9
commit 73dba2ac04
7 changed files with 34 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -5,5 +5,8 @@
<p><label for="enumeration_name"><%=l(:field_name)%></label>
<%= text_field 'enumeration', 'name' %></p>
<p><label for="enumeration_is_default"><%=l(:field_is_default)%></label>
<%= check_box 'enumeration', 'is_default' %></p>
<!--[eoform:optvalue]-->
</div>

View File

@ -9,6 +9,7 @@
<% enumerations.each do |enumeration| %>
<tr class="<%= cycle('odd', 'even') %>">
<td><%= link_to enumeration.name, :action => 'edit', :id => enumeration %></td>
<td style="width:15%;"><%= image_tag('true.png') if enumeration.is_default? %></td>
<td style="width:15%;">
<%= 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) %> -

View File

@ -0,0 +1,9 @@
class AddEnumerationsIsDefault < ActiveRecord::Migration
def self.up
add_column :enumerations, :is_default, :boolean, :default => false, :null => false
end
def self.down
remove_column :enumerations, :is_default
end
end

View File

@ -106,7 +106,7 @@ field_issue: Issue
field_status: Status
field_notes: Notes
field_is_closed: Issue closed
field_is_default: Default status
field_is_default: Default value
field_html_color: Color
field_tracker: Tracker
field_subject: Subject

View File

@ -106,7 +106,7 @@ field_issue: Demande
field_status: Statut
field_notes: Notes
field_is_closed: Demande fermée
field_is_default: Statut par défaut
field_is_default: Valeur par défaut
field_html_color: Couleur
field_tracker: Tracker
field_subject: Sujet