summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/enumeration.rb12
-rw-r--r--app/models/issue.rb14
-rw-r--r--app/views/enumerations/_form.rhtml3
-rw-r--r--app/views/enumerations/list.rhtml1
4 files changed, 23 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
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 @@
<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> \ 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| %>
<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) %> -