Project

General

Profile

Feature #21115 ยป 13.patch

Eric Helms, 2015-10-30 14:01

View differences:

lib/redmine/field_format.rb
class LinkFormat < StringFormat
add 'link'
self.multiple_supported = true
self.searchable_supported = false
self.form_partial = 'custom_fields/formats/link'
def formatted_value(view, custom_field, value, customized=nil, html=false)
if html
if custom_field.url_pattern.present?
url = url_from_pattern(custom_field, value, customized)
else
url = value.to_s
unless url =~ %r{\A[a-z]+://}i
# no protocol found, use http by default
url = "http://" + url
values = value.is_a?(Array) ? value : [value]
links = []
values.each do |val|
if html
if custom_field.url_pattern.present?
url = url_from_pattern(custom_field, val, customized)
else
url = val.to_s
unless url =~ %r{\A[a-z]+://}i
# no protocol found, use http by default
url = "http://" + url
end
end
links << view.link_to(val.to_s, url)
else
links << val.to_s
end
view.link_to value.to_s, url
end
links.length == 1 ? links[0] : links
end
def edit_tag(view, tag_id, tag_name, custom_value, options={})
if custom_value.value.is_a?(String)
view_response = view.text_field_tag(tag_name, custom_value.value, options.merge(:id => tag_id, :size => 10))
else
value.to_s
view_response = view.text_field_tag(tag_name, '', options.merge(:id => tag_id, :size => 10))
custom_value.value.each do |value|
view_response += view.text_field_tag(tag_name, value, options.merge(:id => tag_id, :size => 10))
end
end
view_response
end
end
test/unit/lib/redmine/field_format/link_format_test.rb
assert_equal "foo.bar", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo.bar">foo.bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_link_field_with_multiple_values_returns_array_of_links
field = IssueCustomField.new(:field_format => 'link')
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => ["foo.bar", "bar.foo"])
assert_equal ["foo.bar", "bar.foo"], field.format.formatted_custom_value(self, custom_value, false)
assert_equal ['<a href="http://foo.bar">foo.bar</a>', '<a href="http://bar.foo">bar.foo</a>'], field.format.formatted_custom_value(self, custom_value, true)
end
end
    (1-1/1)