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