comparison app/helpers/custom_fields_helper.rb @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents e248c7af89ec
children
comparison
equal deleted inserted replaced
1516:b450a9d58aed 1517:dffacf8a6908
38 :label => IssuePriority::OptionName}, 38 :label => IssuePriority::OptionName},
39 {:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index', 39 {:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index',
40 :label => DocumentCategory::OptionName} 40 :label => DocumentCategory::OptionName}
41 ] 41 ]
42 42
43 def custom_fields_tabs 43 def render_custom_fields_tabs(types)
44 CUSTOM_FIELDS_TABS 44 tabs = CUSTOM_FIELDS_TABS.select {|h| types.include?(h[:name]) }
45 render_tabs tabs
46 end
47
48 def custom_field_type_options
49 CUSTOM_FIELDS_TABS.map {|h| [l(h[:label]), h[:name]]}
50 end
51
52 def render_custom_field_format_partial(form, custom_field)
53 partial = custom_field.format.form_partial
54 if partial
55 render :partial => custom_field.format.form_partial, :locals => {:f => form, :custom_field => custom_field}
56 end
57 end
58
59 def custom_field_tag_name(prefix, custom_field)
60 name = "#{prefix}[custom_field_values][#{custom_field.id}]"
61 name << "[]" if custom_field.multiple?
62 name
63 end
64
65 def custom_field_tag_id(prefix, custom_field)
66 "#{prefix}_custom_field_values_#{custom_field.id}"
45 end 67 end
46 68
47 # Return custom field html tag corresponding to its format 69 # Return custom field html tag corresponding to its format
48 def custom_field_tag(name, custom_value) 70 def custom_field_tag(prefix, custom_value)
49 custom_field = custom_value.custom_field 71 custom_value.custom_field.format.edit_tag self,
50 field_name = "#{name}[custom_field_values][#{custom_field.id}]" 72 custom_field_tag_id(prefix, custom_value.custom_field),
51 field_name << "[]" if custom_field.multiple? 73 custom_field_tag_name(prefix, custom_value.custom_field),
52 field_id = "#{name}_custom_field_values_#{custom_field.id}" 74 custom_value,
53 75 :class => "#{custom_value.custom_field.field_format}_cf"
54 tag_options = {:id => field_id, :class => "#{custom_field.field_format}_cf"}
55
56 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
57 case field_format.try(:edit_as)
58 when "date"
59 text_field_tag(field_name, custom_value.value, tag_options.merge(:size => 10)) +
60 calendar_for(field_id)
61 when "text"
62 text_area_tag(field_name, custom_value.value, tag_options.merge(:rows => 3))
63 when "bool"
64 hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, tag_options)
65 when "list"
66 blank_option = ''.html_safe
67 unless custom_field.multiple?
68 if custom_field.is_required?
69 unless custom_field.default_value.present?
70 blank_option = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '')
71 end
72 else
73 blank_option = content_tag('option')
74 end
75 end
76 s = select_tag(field_name, blank_option + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value),
77 tag_options.merge(:multiple => custom_field.multiple?))
78 if custom_field.multiple?
79 s << hidden_field_tag(field_name, '')
80 end
81 s
82 else
83 text_field_tag(field_name, custom_value.value, tag_options)
84 end
85 end 76 end
86 77
87 # Return custom field label tag 78 # Return custom field label tag
88 def custom_field_label_tag(name, custom_value, options={}) 79 def custom_field_label_tag(name, custom_value, options={})
89 required = options[:required] || custom_value.custom_field.is_required? 80 required = options[:required] || custom_value.custom_field.is_required?
81 title = custom_value.custom_field.description.presence
82 content = content_tag 'span', custom_value.custom_field.name, :title => title
90 83
91 content_tag "label", h(custom_value.custom_field.name) + 84 content_tag "label", content +
92 (required ? " <span class=\"required\">*</span>".html_safe : ""), 85 (required ? " <span class=\"required\">*</span>".html_safe : ""),
93 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}" 86 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}"
94 end 87 end
95 88
96 # Return custom field tag with its label tag 89 # Return custom field tag with its label tag
97 def custom_field_tag_with_label(name, custom_value, options={}) 90 def custom_field_tag_with_label(name, custom_value, options={})
98 custom_field_label_tag(name, custom_value, options) + custom_field_tag(name, custom_value) 91 custom_field_label_tag(name, custom_value, options) + custom_field_tag(name, custom_value)
99 end 92 end
100 93
101 def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil, value='') 94 # Returns the custom field tag for when bulk editing objects
102 field_name = "#{name}[custom_field_values][#{custom_field.id}]" 95 def custom_field_tag_for_bulk_edit(prefix, custom_field, objects=nil, value='')
103 field_name << "[]" if custom_field.multiple? 96 custom_field.format.bulk_edit_tag self,
104 field_id = "#{name}_custom_field_values_#{custom_field.id}" 97 custom_field_tag_id(prefix, custom_field),
105 98 custom_field_tag_name(prefix, custom_field),
106 tag_options = {:id => field_id, :class => "#{custom_field.field_format}_cf"} 99 custom_field,
107 100 objects,
108 unset_tag = '' 101 value,
109 unless custom_field.is_required? 102 :class => "#{custom_field.field_format}_cf"
110 unset_tag = content_tag('label',
111 check_box_tag(field_name, '__none__', (value == '__none__'), :id => nil, :data => {:disables => "##{field_id}"}) + l(:button_clear),
112 :class => 'inline'
113 )
114 end
115
116 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
117 case field_format.try(:edit_as)
118 when "date"
119 text_field_tag(field_name, value, tag_options.merge(:size => 10)) +
120 calendar_for(field_id) +
121 unset_tag
122 when "text"
123 text_area_tag(field_name, value, tag_options.merge(:rows => 3)) +
124 '<br />'.html_safe +
125 unset_tag
126 when "bool"
127 select_tag(field_name, options_for_select([[l(:label_no_change_option), ''],
128 [l(:general_text_yes), '1'],
129 [l(:general_text_no), '0']], value), tag_options)
130 when "list"
131 options = []
132 options << [l(:label_no_change_option), ''] unless custom_field.multiple?
133 options << [l(:label_none), '__none__'] unless custom_field.is_required?
134 options += custom_field.possible_values_options(projects)
135 select_tag(field_name, options_for_select(options, value), tag_options.merge(:multiple => custom_field.multiple?))
136 else
137 text_field_tag(field_name, value, tag_options) +
138 unset_tag
139 end
140 end 103 end
141 104
142 # Return a string used to display a custom value 105 # Return a string used to display a custom value
143 def show_value(custom_value) 106 def show_value(custom_value, html=true)
144 return "" unless custom_value 107 format_object(custom_value, html)
145 format_value(custom_value.value, custom_value.custom_field.field_format)
146 end 108 end
147 109
148 # Return a string used to display a custom value 110 # Return a string used to display a custom value
149 def format_value(value, field_format) 111 def format_value(value, custom_field)
150 if value.is_a?(Array) 112 format_object(custom_field.format.formatted_value(self, custom_field, value, false), false)
151 value.collect {|v| format_value(v, field_format)}.compact.sort.join(', ')
152 else
153 Redmine::CustomFieldFormat.format_value(value, field_format)
154 end
155 end 113 end
156 114
157 # Return an array of custom field formats which can be used in select_tag 115 # Return an array of custom field formats which can be used in select_tag
158 def custom_field_formats_for_select(custom_field) 116 def custom_field_formats_for_select(custom_field)
159 Redmine::CustomFieldFormat.as_select(custom_field.class.customized_class.name) 117 Redmine::FieldFormat.as_select(custom_field.class.customized_class.name)
160 end 118 end
161 119
162 # Renders the custom_values in api views 120 # Renders the custom_values in api views
163 def render_api_custom_values(custom_values, api) 121 def render_api_custom_values(custom_values, api)
164 api.array :custom_fields do 122 api.array :custom_fields do
177 end 135 end
178 end 136 end
179 end 137 end
180 end unless custom_values.empty? 138 end unless custom_values.empty?
181 end 139 end
140
141 def edit_tag_style_tag(form, options={})
142 select_options = [[l(:label_drop_down_list), ''], [l(:label_checkboxes), 'check_box']]
143 if options[:include_radio]
144 select_options << [l(:label_radio_buttons), 'radio']
145 end
146 form.select :edit_tag_style, select_options, :label => :label_display
147 end
182 end 148 end