##// END OF EJS Templates
Fixed test broken by r11787 (#13943)....
Jean-Philippe Lang -
r11559:afa9100453a0
parent child
Show More
@@ -1,149 +1,149
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2013 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 module CustomFieldsHelper
21 21
22 22 def custom_fields_tabs
23 23 CustomField::CUSTOM_FIELDS_TABS
24 24 end
25 25
26 26 # Return custom field html tag corresponding to its format
27 27 def custom_field_tag(name, custom_value)
28 28 custom_field = custom_value.custom_field
29 29 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
30 30 field_name << "[]" if custom_field.multiple?
31 31 field_id = "#{name}_custom_field_values_#{custom_field.id}"
32 32
33 33 tag_options = {:id => field_id, :class => "#{custom_field.field_format}_cf"}
34 34
35 35 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
36 36 case field_format.try(:edit_as)
37 37 when "date"
38 38 text_field_tag(field_name, custom_value.value, tag_options.merge(:size => 10)) +
39 39 calendar_for(field_id)
40 40 when "text"
41 41 text_area_tag(field_name, custom_value.value, tag_options.merge(:rows => 3))
42 42 when "bool"
43 43 hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, tag_options)
44 44 when "list"
45 45 blank_option = ''.html_safe
46 46 unless custom_field.multiple?
47 47 if custom_field.is_required?
48 48 unless custom_field.default_value.present?
49 49 blank_option = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '')
50 50 end
51 51 else
52 52 blank_option = content_tag('option')
53 53 end
54 54 end
55 55 s = select_tag(field_name, blank_option + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value),
56 56 tag_options.merge(:multiple => custom_field.multiple?))
57 57 if custom_field.multiple?
58 58 s << hidden_field_tag(field_name, '')
59 59 end
60 60 s
61 61 else
62 62 text_field_tag(field_name, custom_value.value, tag_options)
63 63 end
64 64 end
65 65
66 66 # Return custom field label tag
67 67 def custom_field_label_tag(name, custom_value, options={})
68 68 required = options[:required] || custom_value.custom_field.is_required?
69 69
70 70 content_tag "label", h(custom_value.custom_field.name) +
71 71 (required ? " <span class=\"required\">*</span>".html_safe : ""),
72 72 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}"
73 73 end
74 74
75 75 # Return custom field tag with its label tag
76 76 def custom_field_tag_with_label(name, custom_value, options={})
77 77 custom_field_label_tag(name, custom_value, options) + custom_field_tag(name, custom_value)
78 78 end
79 79
80 def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil, value=nil)
80 def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil, value='')
81 81 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
82 82 field_name << "[]" if custom_field.multiple?
83 83 field_id = "#{name}_custom_field_values_#{custom_field.id}"
84 84
85 85 tag_options = {:id => field_id, :class => "#{custom_field.field_format}_cf"}
86 86
87 87 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
88 88 case field_format.try(:edit_as)
89 89 when "date"
90 90 text_field_tag(field_name, value, tag_options.merge(:size => 10)) +
91 91 calendar_for(field_id)
92 92 when "text"
93 93 text_area_tag(field_name, value, tag_options.merge(:rows => 3))
94 94 when "bool"
95 95 select_tag(field_name, options_for_select([[l(:label_no_change_option), ''],
96 96 [l(:general_text_yes), '1'],
97 97 [l(:general_text_no), '0']], value), tag_options)
98 98 when "list"
99 99 options = []
100 100 options << [l(:label_no_change_option), ''] unless custom_field.multiple?
101 101 options << [l(:label_none), '__none__'] unless custom_field.is_required?
102 102 options += custom_field.possible_values_options(projects)
103 103 select_tag(field_name, options_for_select(options, value), tag_options.merge(:multiple => custom_field.multiple?))
104 104 else
105 105 text_field_tag(field_name, value, tag_options)
106 106 end
107 107 end
108 108
109 109 # Return a string used to display a custom value
110 110 def show_value(custom_value)
111 111 return "" unless custom_value
112 112 format_value(custom_value.value, custom_value.custom_field.field_format)
113 113 end
114 114
115 115 # Return a string used to display a custom value
116 116 def format_value(value, field_format)
117 117 if value.is_a?(Array)
118 118 value.collect {|v| format_value(v, field_format)}.compact.sort.join(', ')
119 119 else
120 120 Redmine::CustomFieldFormat.format_value(value, field_format)
121 121 end
122 122 end
123 123
124 124 # Return an array of custom field formats which can be used in select_tag
125 125 def custom_field_formats_for_select(custom_field)
126 126 Redmine::CustomFieldFormat.as_select(custom_field.class.customized_class.name)
127 127 end
128 128
129 129 # Renders the custom_values in api views
130 130 def render_api_custom_values(custom_values, api)
131 131 api.array :custom_fields do
132 132 custom_values.each do |custom_value|
133 133 attrs = {:id => custom_value.custom_field_id, :name => custom_value.custom_field.name}
134 134 attrs.merge!(:multiple => true) if custom_value.custom_field.multiple?
135 135 api.custom_field attrs do
136 136 if custom_value.value.is_a?(Array)
137 137 api.array :value do
138 138 custom_value.value.each do |value|
139 139 api.value value unless value.blank?
140 140 end
141 141 end
142 142 else
143 143 api.value custom_value.value
144 144 end
145 145 end
146 146 end
147 147 end unless custom_values.empty?
148 148 end
149 149 end
General Comments 0
You need to be logged in to leave comments. Login now