##// END OF EJS Templates
Fixed: Undefined Method (l_YesNo) Being Called (#2867)....
Jean-Philippe Lang -
r2473:b78349d2caab
parent child
Show More
@@ -0,0 +1,29
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../../test_helper'
19
20 class CustomFieldsHelperTest < HelperTestCase
21 include CustomFieldsHelper
22 include Redmine::I18n
23
24 def test_format_boolean_value
25 I18n.locale = 'en'
26 assert_equal 'Yes', format_value('1', 'bool')
27 assert_equal 'No', format_value('0', 'bool')
28 end
29 end
@@ -1,88 +1,88
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', :label => :label_issue_plural},
22 22 {:name => 'TimeEntryCustomField', :label => :label_spent_time},
23 23 {:name => 'ProjectCustomField', :label => :label_project_plural},
24 24 {:name => 'UserCustomField', :label => :label_user_plural}
25 25 ]
26 26 end
27 27
28 28 # Return custom field html tag corresponding to its format
29 29 def custom_field_tag(name, custom_value)
30 30 custom_field = custom_value.custom_field
31 31 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
32 32 field_id = "#{name}_custom_field_values_#{custom_field.id}"
33 33
34 34 case custom_field.field_format
35 35 when "date"
36 36 text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) +
37 37 calendar_for(field_id)
38 38 when "text"
39 39 text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%')
40 40 when "bool"
41 41 check_box_tag(field_name, '1', custom_value.true?, :id => field_id) + hidden_field_tag(field_name, '0')
42 42 when "list"
43 43 blank_option = custom_field.is_required? ?
44 44 (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') :
45 45 '<option></option>'
46 46 select_tag(field_name, blank_option + options_for_select(custom_field.possible_values, custom_value.value), :id => field_id)
47 47 else
48 48 text_field_tag(field_name, custom_value.value, :id => field_id)
49 49 end
50 50 end
51 51
52 52 # Return custom field label tag
53 53 def custom_field_label_tag(name, custom_value)
54 54 content_tag "label", custom_value.custom_field.name +
55 55 (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),
56 56 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}",
57 57 :class => (custom_value.errors.empty? ? nil : "error" )
58 58 end
59 59
60 60 # Return custom field tag with its label tag
61 61 def custom_field_tag_with_label(name, custom_value)
62 62 custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
63 63 end
64 64
65 65 # Return a string used to display a custom value
66 66 def show_value(custom_value)
67 67 return "" unless custom_value
68 68 format_value(custom_value.value, custom_value.custom_field.field_format)
69 69 end
70 70
71 71 # Return a string used to display a custom value
72 72 def format_value(value, field_format)
73 73 return "" unless value && !value.empty?
74 74 case field_format
75 75 when "date"
76 76 begin; format_date(value.to_date); rescue; value end
77 77 when "bool"
78 l_YesNo(value == "1")
78 l(value == "1" ? :general_text_Yes : :general_text_No)
79 79 else
80 80 value
81 81 end
82 82 end
83 83
84 84 # Return an array of custom field formats which can be used in select_tag
85 85 def custom_field_formats_for_select
86 86 CustomField::FIELD_FORMATS.sort {|a,b| a[1][:order]<=>b[1][:order]}.collect { |k| [ l(k[1][:name]), k[0] ] }
87 87 end
88 88 end
General Comments 0
You need to be logged in to leave comments. Login now