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