##// END OF EJS Templates
Merged r1503 from trunk....
Jean-Philippe Lang -
r1517:9c5ec2974d1b
parent child
Show More
@@ -1,67 +1,66
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Enumeration < ActiveRecord::Base
18 class Enumeration < ActiveRecord::Base
19 acts_as_list :scope => 'opt = \'#{opt}\''
19 acts_as_list :scope => 'opt = \'#{opt}\''
20
20
21 before_destroy :check_integrity
21 before_destroy :check_integrity
22
22
23 validates_presence_of :opt, :name
23 validates_presence_of :opt, :name
24 validates_uniqueness_of :name, :scope => [:opt]
24 validates_uniqueness_of :name, :scope => [:opt]
25 validates_length_of :name, :maximum => 30
25 validates_length_of :name, :maximum => 30
26 validates_format_of :name, :with => /^[\w\s\'\-]*$/i
27
26
28 OPTIONS = {
27 OPTIONS = {
29 "IPRI" => :enumeration_issue_priorities,
28 "IPRI" => :enumeration_issue_priorities,
30 "DCAT" => :enumeration_doc_categories,
29 "DCAT" => :enumeration_doc_categories,
31 "ACTI" => :enumeration_activities
30 "ACTI" => :enumeration_activities
32 }.freeze
31 }.freeze
33
32
34 def self.get_values(option)
33 def self.get_values(option)
35 find(:all, :conditions => {:opt => option}, :order => 'position')
34 find(:all, :conditions => {:opt => option}, :order => 'position')
36 end
35 end
37
36
38 def self.default(option)
37 def self.default(option)
39 find(:first, :conditions => {:opt => option, :is_default => true}, :order => 'position')
38 find(:first, :conditions => {:opt => option, :is_default => true}, :order => 'position')
40 end
39 end
41
40
42 def option_name
41 def option_name
43 OPTIONS[self.opt]
42 OPTIONS[self.opt]
44 end
43 end
45
44
46 def before_save
45 def before_save
47 Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt}) if is_default?
46 Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt}) if is_default?
48 end
47 end
49
48
50 def <=>(enumeration)
49 def <=>(enumeration)
51 position <=> enumeration.position
50 position <=> enumeration.position
52 end
51 end
53
52
54 def to_s; name end
53 def to_s; name end
55
54
56 private
55 private
57 def check_integrity
56 def check_integrity
58 case self.opt
57 case self.opt
59 when "IPRI"
58 when "IPRI"
60 raise "Can't delete enumeration" if Issue.find(:first, :conditions => ["priority_id=?", self.id])
59 raise "Can't delete enumeration" if Issue.find(:first, :conditions => ["priority_id=?", self.id])
61 when "DCAT"
60 when "DCAT"
62 raise "Can't delete enumeration" if Document.find(:first, :conditions => ["category_id=?", self.id])
61 raise "Can't delete enumeration" if Document.find(:first, :conditions => ["category_id=?", self.id])
63 when "ACTI"
62 when "ACTI"
64 raise "Can't delete enumeration" if TimeEntry.find(:first, :conditions => ["activity_id=?", self.id])
63 raise "Can't delete enumeration" if TimeEntry.find(:first, :conditions => ["activity_id=?", self.id])
65 end
64 end
66 end
65 end
67 end
66 end
@@ -1,28 +1,28
1 <h2><%=l(:label_enumerations)%></h2>
1 <h2><%=l(:label_enumerations)%></h2>
2
2
3 <% Enumeration::OPTIONS.each do |option, name| %>
3 <% Enumeration::OPTIONS.each do |option, name| %>
4 <h3><%= l(name) %></h3>
4 <h3><%= l(name) %></h3>
5
5
6 <% enumerations = Enumeration.get_values(option) %>
6 <% enumerations = Enumeration.get_values(option) %>
7 <% if enumerations.any? %>
7 <% if enumerations.any? %>
8 <table class="list">
8 <table class="list">
9 <% enumerations.each do |enumeration| %>
9 <% enumerations.each do |enumeration| %>
10 <tr class="<%= cycle('odd', 'even') %>">
10 <tr class="<%= cycle('odd', 'even') %>">
11 <td><%= link_to enumeration.name, :action => 'edit', :id => enumeration %></td>
11 <td><%= link_to h(enumeration), :action => 'edit', :id => enumeration %></td>
12 <td style="width:15%;"><%= image_tag('true.png') if enumeration.is_default? %></td>
12 <td style="width:15%;"><%= image_tag('true.png') if enumeration.is_default? %></td>
13 <td style="width:15%;">
13 <td style="width:15%;">
14 <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => enumeration, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
14 <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => enumeration, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
15 <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => enumeration, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
15 <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => enumeration, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
16 <%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:action => 'move', :id => enumeration, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %>
16 <%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:action => 'move', :id => enumeration, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %>
17 <%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:action => 'move', :id => enumeration, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %>
17 <%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:action => 'move', :id => enumeration, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %>
18 </td>
18 </td>
19 </tr>
19 </tr>
20 <% end %>
20 <% end %>
21 </table>
21 </table>
22 <% reset_cycle %>
22 <% reset_cycle %>
23 <% end %>
23 <% end %>
24
24
25 <p><%= link_to l(:label_enumeration_new), { :action => 'new', :opt => option } %></p>
25 <p><%= link_to l(:label_enumeration_new), { :action => 'new', :opt => option } %></p>
26 <% end %>
26 <% end %>
27
27
28 <% html_title(l(:label_enumerations)) -%>
28 <% html_title(l(:label_enumerations)) -%>
@@ -1,19 +1,19
1 <% @hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value| %>
1 <% @hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value| %>
2 <% hours_for_value = select_hours(hours, criterias[level], value) -%>
2 <% hours_for_value = select_hours(hours, criterias[level], value) -%>
3 <% next if hours_for_value.empty? -%>
3 <% next if hours_for_value.empty? -%>
4 <tr class="<%= cycle('odd', 'even') %> <%= 'last-level' unless criterias.length > level+1 %>">
4 <tr class="<%= cycle('odd', 'even') %> <%= 'last-level' unless criterias.length > level+1 %>">
5 <%= '<td></td>' * level %>
5 <%= '<td></td>' * level %>
6 <td><%= format_criteria_value(criterias[level], value) %></td>
6 <td><%= h(format_criteria_value(criterias[level], value)) %></td>
7 <%= '<td></td>' * (criterias.length - level - 1) -%>
7 <%= '<td></td>' * (criterias.length - level - 1) -%>
8 <% total = 0 -%>
8 <% total = 0 -%>
9 <% @periods.each do |period| -%>
9 <% @periods.each do |period| -%>
10 <% sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s)); total += sum -%>
10 <% sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s)); total += sum -%>
11 <td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
11 <td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
12 <% end -%>
12 <% end -%>
13 <td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
13 <td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
14 </tr>
14 </tr>
15 <% if criterias.length > level+1 -%>
15 <% if criterias.length > level+1 -%>
16 <%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
16 <%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
17 <% end -%>
17 <% end -%>
18
18
19 <% end %>
19 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now