Commit 73dba2ac authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

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
parent fd7910ef
...@@ -34,14 +34,18 @@ class Enumeration < ActiveRecord::Base ...@@ -34,14 +34,18 @@ class Enumeration < ActiveRecord::Base
def self.get_values(option) def self.get_values(option)
find(:all, :conditions => {:opt => option}, :order => 'position') find(:all, :conditions => {:opt => option}, :order => 'position')
end end
def self.default(option)
find(:first, :conditions => {:opt => option, :is_default => true}, :order => 'position')
end
def option_name def option_name
OPTIONS[self.opt] OPTIONS[self.opt]
end end
#def <=>(enumeration) def before_save
# position <=> enumeration.position Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt}) if is_default?
#end end
def to_s; name end def to_s; name end
......
...@@ -46,9 +46,17 @@ class Issue < ActiveRecord::Base ...@@ -46,9 +46,17 @@ class Issue < ActiveRecord::Base
validates_numericality_of :estimated_hours, :allow_nil => true validates_numericality_of :estimated_hours, :allow_nil => true
validates_associated :custom_values, :on => :update validates_associated :custom_values, :on => :update
# set default status for new issues def after_initialize
def before_validation if new_record?
self.status = IssueStatus.default if status.nil? # 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 end
def validate def validate
......
...@@ -5,5 +5,8 @@ ...@@ -5,5 +5,8 @@
<p><label for="enumeration_name"><%=l(:field_name)%></label> <p><label for="enumeration_name"><%=l(:field_name)%></label>
<%= text_field 'enumeration', 'name' %></p> <%= text_field 'enumeration', 'name' %></p>
<p><label for="enumeration_is_default"><%=l(:field_is_default)%></label>
<%= check_box 'enumeration', 'is_default' %></p>
<!--[eoform:optvalue]--> <!--[eoform:optvalue]-->
</div> </div>
\ No newline at end of file
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<% enumerations.each do |enumeration| %> <% enumerations.each do |enumeration| %>
<tr class="<%= cycle('odd', 'even') %>"> <tr class="<%= cycle('odd', 'even') %>">
<td><%= link_to enumeration.name, :action => 'edit', :id => enumeration %></td> <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%;"> <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('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) %> - <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => enumeration, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
......
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
...@@ -106,7 +106,7 @@ field_issue: Issue ...@@ -106,7 +106,7 @@ field_issue: Issue
field_status: Status field_status: Status
field_notes: Notes field_notes: Notes
field_is_closed: Issue closed field_is_closed: Issue closed
field_is_default: Default status field_is_default: Default value
field_html_color: Color field_html_color: Color
field_tracker: Tracker field_tracker: Tracker
field_subject: Subject field_subject: Subject
......
...@@ -106,7 +106,7 @@ field_issue: Demande ...@@ -106,7 +106,7 @@ field_issue: Demande
field_status: Statut field_status: Statut
field_notes: Notes field_notes: Notes
field_is_closed: Demande fermée 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_html_color: Couleur
field_tracker: Tracker field_tracker: Tracker
field_subject: Sujet field_subject: Sujet
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment