<p><%= f.select :default_value, [[]]+@custom_field.possible_values_options %></p>
+<p><%= f.text_field :url_pattern, :size => 50, :label => :label_link_values_to %></p>
<p><%= edit_tag_style_tag f %></p>
<p><%= f.text_field(:default_value, :size => 10) %></p>
<%= calendar_for('custom_field_default_value') %>
+<p><%= f.text_field :url_pattern, :size => 50, :label => :label_link_values_to %></p>
<em class="info"><%= l(:text_custom_field_possible_values_info) %></em>
</p>
<p><%= f.text_field(:default_value) %></p>
+<p><%= f.text_field :url_pattern, :size => 50, :label => :label_link_values_to %></p>
<p><%= edit_tag_style_tag f %></p>
<%= render :partial => 'custom_fields/formats/regexp', :locals => {:f => f, :custom_field => custom_field} %>
<p><%= f.text_field(:default_value) %></p>
+<p><%= f.text_field :url_pattern, :size => 50, :label => :label_link_values_to %></p>
<%= render :partial => 'custom_fields/formats/regexp', :locals => {:f => f, :custom_field => custom_field} %>
-<p><%= f.check_box :text_formatting, {:label => :setting_text_formatting}, 'full', '' %></p>
+<p><%= f.check_box :text_formatting, {:label => :setting_text_formatting, :data => {:disables => '#custom_field_url_pattern'}}, 'full', '' %></p>
<p><%= f.text_field(:default_value) %></p>
+<p><%= f.text_field :url_pattern, :size => 50, :label => :label_link_values_to %></p>
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
description_date_from: Въведете начална дата
description_date_to: Въведете крайна дата
text_repository_identifier_info: 'Позволени са малки букви (a-z), цифри, тирета и _.<br />Промяна след създаването му не е възможна.'
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
button_login: Login
button_submit: Submit
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: seulement
label_drop_down_list: liste déroulante
label_checkboxes: cases à cocher
+ label_link_values_to: Lier les valeurs vers l'URL
button_login: Connexion
button_submit: Soumettre
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
description_date_from: 輸入起始日期
description_date_to: 輸入結束日期
text_repository_identifier_info: '僅允許使用小寫英文字母 (a-z), 阿拉伯數字, 虛線與底線。<br />一旦儲存之後, 代碼便無法再次被更改。'
+ label_link_values_to: Link values to URL
label_only: only
label_drop_down_list: drop-down list
label_checkboxes: checkboxes
+ label_link_values_to: Link values to URL
CustomField.store_accessor :format_store, *args
end
+ field_attributes :url_pattern
+
def name
self.class.format_name
end
end
def formatted_value(view, custom_field, value, customized=nil, html=false)
- cast_value(custom_field, value, customized)
+ casted = cast_value(custom_field, value, customized)
+ if custom_field.url_pattern.present?
+ texts_and_urls = Array.wrap(casted).map do |single_value|
+ text = view.format_object(single_value, false).to_s
+ url = url_from_pattern(custom_field, single_value, customized)
+ [text, url]
+ end
+ links = texts_and_urls.sort_by(&:first).map {|text, url| view.link_to text, url}
+ links.join(', ').html_safe
+ else
+ casted
+ end
end
+ # Returns an URL generated with the custom field URL pattern
+ # and variables substitution:
+ # %value% => the custom field value
+ # %id% => id of the customized object
+ # %project_id% => id of the project of the customized object if defined
+ # %project_identifier% => identifier of the project of the customized object if defined
+ # %m1%, %m2%... => capture groups matches of the custom field regexp if defined
+ def url_from_pattern(custom_field, value, customized)
+ url = custom_field.url_pattern.to_s.dup
+ url.gsub!('%value%') {value.to_s}
+ url.gsub!('%id%') {customized.id.to_s}
+ url.gsub!('%project_id%') {(customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s}
+ url.gsub!('%project_identifier%') {(customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s}
+ if custom_field.regexp.present?
+ url.gsub!(%r{%m(\d+)%}) do
+ m = $1.to_i
+ if matches ||= value.to_s.match(Regexp.new(custom_field.regexp))
+ matches[m].to_s
+ end
+ end
+ end
+ url
+ end
+ protected :url_from_pattern
+
def edit_tag(view, tag_id, tag_name, custom_value, options={})
view.text_field_tag(tag_name, custom_value.value, options.merge(:id => tag_id))
end
field_attributes :text_formatting
def formatted_value(view, custom_field, value, customized=nil, html=false)
- if html && custom_field.text_formatting == 'full'
- view.textilizable(value, :object => customized)
+ if html
+ if custom_field.url_pattern.present?
+ super
+ elsif custom_field.text_formatting == 'full'
+ view.textilizable(value, :object => customized)
+ else
+ value.to_s
+ end
else
value.to_s
end
add 'link'
self.searchable_supported = false
self.form_partial = 'custom_fields/formats/link'
- field_attributes :url_pattern
def formatted_value(view, custom_field, value, customized=nil, html=false)
if html
if custom_field.url_pattern.present?
- url = custom_field.url_pattern.to_s.dup
- url.gsub!('%value%') {value.to_s}
- url.gsub!('%id%') {customized.id.to_s}
- url.gsub!('%project_id%') {(customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s}
- url.gsub!('%project_identifier%') {(customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s}
- if custom_field.regexp.present?
- url.gsub!(%r{%m(\d+)%}) do
- m = $1.to_i
- matches ||= value.to_s.match(Regexp.new(custom_field.regexp))
- matches[m].to_s if matches
- end
- end
+ url = url_from_pattern(custom_field, value, customized)
else
url = value.to_s
unless url =~ %r{\A[a-z]+://}i
end
end
+ def test_field_with_url_pattern_should_link_value
+ field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
+ formatted = field.format.formatted_value(self, field, 'foo', Issue.new, true)
+ assert_equal '<a href="http://localhost/foo">foo</a>', formatted
+ assert formatted.html_safe?
+ end
+
+ def test_field_with_url_pattern_and_multiple_values_should_link_values
+ field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
+ formatted = field.format.formatted_value(self, field, ['foo', 'bar'], Issue.new, true)
+ assert_equal '<a href="http://localhost/bar">bar</a>, <a href="http://localhost/foo">foo</a>', formatted
+ assert formatted.html_safe?
+ end
+
+ def test_field_with_url_pattern_should_not_link_blank_value
+ field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
+ formatted = field.format.formatted_value(self, field, '', Issue.new, true)
+ assert_equal '', formatted
+ assert formatted.html_safe?
+ end
+
def test_edit_tag_with_check_box_style_and_multiple_should_select_current_values
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar', 'Baz'], :is_required => false,
:multiple => true, :edit_tag_style => 'check_box')