323 |
323 |
|
324 |
324 |
class LinkFormat < StringFormat
|
325 |
325 |
add 'link'
|
|
326 |
self.multiple_supported = true
|
326 |
327 |
self.searchable_supported = false
|
327 |
328 |
self.form_partial = 'custom_fields/formats/link'
|
328 |
329 |
|
329 |
330 |
def formatted_value(view, custom_field, value, customized=nil, html=false)
|
330 |
|
if html
|
331 |
|
if custom_field.url_pattern.present?
|
332 |
|
url = url_from_pattern(custom_field, value, customized)
|
333 |
|
else
|
334 |
|
url = value.to_s
|
335 |
|
unless url =~ %r{\A[a-z]+://}i
|
336 |
|
# no protocol found, use http by default
|
337 |
|
url = "http://" + url
|
|
331 |
values = value.is_a?(Array) ? value : [value]
|
|
332 |
links = []
|
|
333 |
|
|
334 |
values.each do |val|
|
|
335 |
if html
|
|
336 |
if custom_field.url_pattern.present?
|
|
337 |
url = url_from_pattern(custom_field, val, customized)
|
|
338 |
else
|
|
339 |
url = val.to_s
|
|
340 |
unless url =~ %r{\A[a-z]+://}i
|
|
341 |
# no protocol found, use http by default
|
|
342 |
url = "http://" + url
|
|
343 |
end
|
338 |
344 |
end
|
|
345 |
links << view.link_to(val.to_s, url)
|
|
346 |
else
|
|
347 |
links << val.to_s
|
339 |
348 |
end
|
340 |
|
view.link_to value.to_s, url
|
|
349 |
end
|
|
350 |
|
|
351 |
links.length == 1 ? links[0] : links
|
|
352 |
end
|
|
353 |
|
|
354 |
def edit_tag(view, tag_id, tag_name, custom_value, options={})
|
|
355 |
if custom_value.value.is_a?(String)
|
|
356 |
view_response = view.text_field_tag(tag_name, custom_value.value, options.merge(:id => tag_id, :size => 10))
|
341 |
357 |
else
|
342 |
|
value.to_s
|
|
358 |
view_response = view.text_field_tag(tag_name, '', options.merge(:id => tag_id, :size => 10))
|
|
359 |
|
|
360 |
custom_value.value.each do |value|
|
|
361 |
view_response += view.text_field_tag(tag_name, value, options.merge(:id => tag_id, :size => 10))
|
|
362 |
end
|
343 |
363 |
end
|
|
364 |
|
|
365 |
view_response
|
344 |
366 |
end
|
345 |
367 |
end
|
346 |
368 |
|