##// END OF EJS Templates
Change the order of checkboxes for boolean custom fields....
Eric Davis -
r2828:739e11702a81
parent child
Show More
@@ -1,89 +1,89
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 module CustomFieldsHelper
19 19
20 20 def custom_fields_tabs
21 21 tabs = [{:name => 'IssueCustomField', :partial => 'custom_fields/index', :label => :label_issue_plural},
22 22 {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
23 23 {:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
24 24 {:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
25 25 {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural}
26 26 ]
27 27 end
28 28
29 29 # Return custom field html tag corresponding to its format
30 30 def custom_field_tag(name, custom_value)
31 31 custom_field = custom_value.custom_field
32 32 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
33 33 field_id = "#{name}_custom_field_values_#{custom_field.id}"
34 34
35 35 case custom_field.field_format
36 36 when "date"
37 37 text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) +
38 38 calendar_for(field_id)
39 39 when "text"
40 40 text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%')
41 41 when "bool"
42 check_box_tag(field_name, '1', custom_value.true?, :id => field_id) + hidden_field_tag(field_name, '0')
42 hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, :id => field_id)
43 43 when "list"
44 44 blank_option = custom_field.is_required? ?
45 45 (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
46 46 '<option></option>'
47 47 select_tag(field_name, blank_option + options_for_select(custom_field.possible_values, custom_value.value), :id => field_id)
48 48 else
49 49 text_field_tag(field_name, custom_value.value, :id => field_id)
50 50 end
51 51 end
52 52
53 53 # Return custom field label tag
54 54 def custom_field_label_tag(name, custom_value)
55 55 content_tag "label", custom_value.custom_field.name +
56 56 (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),
57 57 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}",
58 58 :class => (custom_value.errors.empty? ? nil : "error" )
59 59 end
60 60
61 61 # Return custom field tag with its label tag
62 62 def custom_field_tag_with_label(name, custom_value)
63 63 custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
64 64 end
65 65
66 66 # Return a string used to display a custom value
67 67 def show_value(custom_value)
68 68 return "" unless custom_value
69 69 format_value(custom_value.value, custom_value.custom_field.field_format)
70 70 end
71 71
72 72 # Return a string used to display a custom value
73 73 def format_value(value, field_format)
74 74 return "" unless value && !value.empty?
75 75 case field_format
76 76 when "date"
77 77 begin; format_date(value.to_date); rescue; value end
78 78 when "bool"
79 79 l(value == "1" ? :general_text_Yes : :general_text_No)
80 80 else
81 81 value
82 82 end
83 83 end
84 84
85 85 # Return an array of custom field formats which can be used in select_tag
86 86 def custom_field_formats_for_select
87 87 CustomField::FIELD_FORMATS.sort {|a,b| a[1][:order]<=>b[1][:order]}.collect { |k| [ l(k[1][:name]), k[0] ] }
88 88 end
89 89 end
General Comments 0
You need to be logged in to leave comments. Login now