]> source.dussan.org Git - redmine.git/commitdiff
Adds support for links on values for various custom field formats (#1358).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 22 Dec 2013 14:09:33 +0000 (14:09 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 22 Dec 2013 14:09:33 +0000 (14:09 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12442 e93f8b46-1217-0410-a6f0-8f06a7374b81

55 files changed:
app/views/custom_fields/formats/_bool.html.erb
app/views/custom_fields/formats/_date.html.erb
app/views/custom_fields/formats/_list.html.erb
app/views/custom_fields/formats/_numeric.html.erb
app/views/custom_fields/formats/_string.html.erb
config/locales/ar.yml
config/locales/az.yml
config/locales/bg.yml
config/locales/bs.yml
config/locales/ca.yml
config/locales/cs.yml
config/locales/da.yml
config/locales/de.yml
config/locales/el.yml
config/locales/en-GB.yml
config/locales/en.yml
config/locales/es.yml
config/locales/et.yml
config/locales/eu.yml
config/locales/fa.yml
config/locales/fi.yml
config/locales/fr.yml
config/locales/gl.yml
config/locales/he.yml
config/locales/hr.yml
config/locales/hu.yml
config/locales/id.yml
config/locales/it.yml
config/locales/ja.yml
config/locales/ko.yml
config/locales/lt.yml
config/locales/lv.yml
config/locales/mk.yml
config/locales/mn.yml
config/locales/nl.yml
config/locales/no.yml
config/locales/pl.yml
config/locales/pt-BR.yml
config/locales/pt.yml
config/locales/ro.yml
config/locales/ru.yml
config/locales/sk.yml
config/locales/sl.yml
config/locales/sq.yml
config/locales/sr-YU.yml
config/locales/sr.yml
config/locales/sv.yml
config/locales/th.yml
config/locales/tr.yml
config/locales/uk.yml
config/locales/vi.yml
config/locales/zh-TW.yml
config/locales/zh.yml
lib/redmine/field_format.rb
test/unit/lib/redmine/field_format/list_format_test.rb

index 25c464fb9a11a624cadbd4629132c97e2b8d1863..81aa64afee2f905801d3bd152cbb0f0d6208f8d3 100644 (file)
@@ -1,2 +1,3 @@
 <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>
index 807a9269e67bf2de5411c20facfc6868753667b5..df3ba078920ea29a8e8f01100f48ad9d2ff1e646 100644 (file)
@@ -1,2 +1,3 @@
 <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>
index 9bbd6a243aa7e200215ff82d1659d1ca75cba3db..675bbbf8db7cdfbac50fb137a05fe31f5fedd1d8 100644 (file)
@@ -3,4 +3,5 @@
   <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>
index 06187485dbbb3537f032061a28e77d1fccfc0027..cc0c798a6155f6940c3f989756c4358caf1ec7a2 100644 (file)
@@ -1,2 +1,3 @@
 <%= 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>
index 0c71243a889eee037c5596fa8b34c4810ab51f09..08aac8eb28aeb6c8a5cfbdb617e2f81b9a522aad 100644 (file)
@@ -1,3 +1,4 @@
 <%= 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>
index 215e561c0624568543c16c2d1de0aad3cffdf4e2..9a68117e27e03d1dde59aa180cb627cbcdd9ea8d 100644 (file)
@@ -1105,3 +1105,4 @@ ar:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 8d8c224e2e765037ccf660553be9d1b3ec8caf64..5afad226748756a7d48f3116465d8c0fbb315033 100644 (file)
@@ -1202,3 +1202,4 @@ az:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 07e2bbc49a488fe2f2e7c7b0ca4bc16543b0f3cc..e3e7787b1d83148dfc329542cbfd338cecd43000 100644 (file)
@@ -1102,3 +1102,4 @@ bg:
   description_date_from: Въведете начална дата
   description_date_to: Въведете крайна дата
   text_repository_identifier_info: 'Позволени са малки букви (a-z), цифри, тирета и _.<br />Промяна след създаването му не е възможна.'
+  label_link_values_to: Link values to URL
index 728c750a1fc9de69f4980222b14c3eec91e88a9c..e410cc245928cd40a3736d24a5d6b1dd4360c929 100644 (file)
@@ -1118,3 +1118,4 @@ bs:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index a2c4aed0e05ab485df0450da46913ba0430ea6b2..3ff81dbe14e05946d6f397629d6f3a9a9e7fdcac 100644 (file)
@@ -1107,3 +1107,4 @@ ca:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index ae432c9150e08bcf84d7ad452e4a46f770780488..171a00a2cb83c6137356f12a0f0e4fadbc8f163b 100644 (file)
@@ -1108,3 +1108,4 @@ cs:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index cdf583db0113b38fa422bde5f3564913e3e56f01..9d427561623879143d69a5b1b1a2ac072598ab91 100644 (file)
@@ -1122,3 +1122,4 @@ da:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index abb4a541b52f6fb606c86d8d922e41a772e1b0e1..8fa1a36fbf4c386da0ed7a36c68a11f495d27c30 100644 (file)
@@ -1117,3 +1117,4 @@ de:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 92f9f5e6aed8da757fa2146d509a83c61d675781..4840b020e01de7e4763b73c0757a572ce28518ce 100644 (file)
@@ -1105,3 +1105,4 @@ el:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 68aff008358739f610e5135c4c01a9d43481d077..b42e20a2b44268ec720e12bf7cd9d2132551114e 100644 (file)
@@ -1107,3 +1107,4 @@ en-GB:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index bbfea75c313630af6f81ea88668daa899f59e495..f9b459577eecca47064980f48901c74cfcb237a2 100644 (file)
@@ -907,6 +907,7 @@ en:
   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
index 7fc39bef3317f3e301e833f92489583f8f55ff95..8673d769159070817fb780f10dd2c6f084f66c3f 100644 (file)
@@ -1140,3 +1140,4 @@ es:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index bebbc36221137cab555ef781aea0ba9cc74708aa..73fa299d9aae7129595c3c744689051e5e659fb5 100644 (file)
@@ -1118,3 +1118,4 @@ et:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index ecde2cf330e78321511cfc821aff0bf82d212ed9..693041bd7d2e0b0e377441f3bc99e8e2a57fa310 100644 (file)
@@ -1106,3 +1106,4 @@ eu:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 780a525bafa774689face95983eeb0b713b4c59a..ed110679c16868d1e8199fc2c7d2c161856324ff 100644 (file)
@@ -1107,3 +1107,4 @@ fa:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 162325eea8b48dc76bcb5643f3c2505a180dc208..e8834331a1f21cb0ee6b7346c8488fc004f85660 100644 (file)
@@ -1126,3 +1126,4 @@ fi:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 48217e7f126b4cca45a1633420f8735555d47acf..29bb0842821ee73755cc923bcc1ae0247a79f80c 100644 (file)
@@ -883,6 +883,7 @@ fr:
   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
index 904a47e12c31576061ec809c44f156bdbe2b394d..8278cd89d42c5a6f9ee3b35bb828dcdf3681771b 100644 (file)
@@ -1116,3 +1116,4 @@ gl:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 3178a5eafdad34d597aeabff110a2c3c18ed5772..f5c8ee126fb28f0e8467108789ba6a63e6d66e3e 100644 (file)
@@ -1110,3 +1110,4 @@ he:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index b3931178f1c6b677a6fbfdd1f7af888e2260790c..568fbe6026216cf544b51b2635bc4ee39de1345a 100644 (file)
@@ -1106,3 +1106,4 @@ hr:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index b462b3ba969b755c79e94c20daccf63d224d6f26..444f57a56e0af62d171a91ea817716f64d57ee35 100644 (file)
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index c7e434b248325440306a7e0be1d94d70bfe224fc..5e6b316d4e735026b1910c5a7ee2a12a0721b302 100644 (file)
@@ -1109,3 +1109,4 @@ id:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index dfa525ff2b6a70b8815cb78ee766b256109c6b97..8e00f9b8393f3782ea586a744925baa2930c8a70 100644 (file)
@@ -1104,3 +1104,4 @@ it:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index f13280f972f49cb6ede7b3fc25039d4dd70f7ff2..0455100f41caaaeedcd744b0aa97ecc836d985c3 100644 (file)
@@ -1132,3 +1132,4 @@ ja:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 07cacddc00dfbdb5a4fc81f45584fb914e11fa9d..85f71ae3fa7ae0b88a9de0302f7db05f5f48d2f9 100644 (file)
@@ -1154,3 +1154,4 @@ ko:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 4f678906923b2aa7efbeddba17d1c8b25d7aca23..2772fc1a776c537e7561b15594142a61855e5ef1 100644 (file)
@@ -1164,3 +1164,4 @@ lt:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 30bd5fe1afa64e170c710f22196aa2989c82d32a..525bd0473e2d6672757a14f022d04b24859ba145 100644 (file)
@@ -1099,3 +1099,4 @@ lv:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index d9e42393c7faf58b0dc0ce8a3cf5c8c8e32ce3c8..15bbd5dd55410c7136510fb14cd7b46599ec8d8d 100644 (file)
@@ -1105,3 +1105,4 @@ mk:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 28e0457835043868840165a18ed317cbd0a10f5c..222702f195e8ab87b57331cbf7118a6cc9a48b19 100644 (file)
@@ -1106,3 +1106,4 @@ mn:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 156ac86fd97d678cb5a72a7a855f9c3ebf184dfb..6a48cc131ec2e74f1855817c74d2e9595fb1681d 100644 (file)
@@ -1084,3 +1084,4 @@ nl:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 255fca3c5202af6247605197deecb919e0484a5a..85d42763733d2d9957da834851a75f77164f54c7 100644 (file)
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index e097ab05943f54251900e5a8cdc7300925a08ff1..443dbd20b8260d03e1d44a5ff4c0b53adbfcce40 100644 (file)
@@ -1127,3 +1127,4 @@ pl:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 4637ece0f7ee5e72674effb25455df3f87eb5c8b..e7754b2c36cb1e2dc3ef2f28f41da020c2c877b9 100644 (file)
@@ -1125,3 +1125,4 @@ pt-BR:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 5038bdfb89a28fe469da740b3394e998e7e9ffa5..d3a69a419dc7f7d7f5760d43ed473389d32ffba1 100644 (file)
@@ -1111,3 +1111,4 @@ pt:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 0d13077505a95de391999ac9fcd9c178fc00a546..1248330cb190a048176e1eeef0655bcc0ca2c8f4 100644 (file)
@@ -1100,3 +1100,4 @@ ro:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index c19da11bd40b76c602ee97adf616cfb8021d2a0b..cf1f7f287bb3490cf4c91ad27533651121c6b04e 100644 (file)
@@ -1214,3 +1214,4 @@ ru:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 388d1a16819683e1913853738be49fef9723015a..cf1d03979f69b4584af58f6c6535e2256477c715 100644 (file)
@@ -1095,3 +1095,4 @@ sk:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 4e5263a4de188bf673f43d0fa01b94e483625738..6b4da564a7a17eb5f6821d149d88fc1ac98b88e0 100644 (file)
@@ -1105,3 +1105,4 @@ sl:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index fc829f5f3144729c65dc749068dd568ae3663d59..74bac035fad108bd6abd1517e645935e6c11ebcf 100644 (file)
@@ -1101,3 +1101,4 @@ sq:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 4650a8c45079848e0aba1d6b0bcab3131febc63a..0a4de326781c2421ef68dec987d1b50efc130bf9 100644 (file)
@@ -1107,3 +1107,4 @@ sr-YU:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 7e103c4ea45bf26df17fc9193fe76b34b32df6f5..8008086b15cebfe2d96f4fc6ac1be94b723ea377 100644 (file)
@@ -1106,3 +1106,4 @@ sr:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 90d6be24cd65b9deae6f3ea8c440f7006cbe87eb..73bf3aefca1e25ce3851355551b5b7093b104a10 100644 (file)
@@ -1143,3 +1143,4 @@ sv:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index e97c22aa50406bc4bf7e37500ebf2e2996b88b80..c490b213a34b88234553fb5f19302d9391b32a80 100644 (file)
@@ -1102,3 +1102,4 @@ th:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 59a792401d224884d6c69befe40d30d38a24ec6f..40e9d22ea86f9ea18e914d0db5b698c0b0106fef 100644 (file)
@@ -1114,3 +1114,4 @@ tr:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index aa9a3ec9e1e97ee4458c0045f870ba6e346a064d..87c96a61656a01c7df57063d6d3d13eb796a9057 100644 (file)
@@ -1100,3 +1100,4 @@ uk:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index ef43b4aaa531ceb13744743da976224248dbcad2..482ef8f91d8eb09570a450e21beec927dd58b960 100644 (file)
@@ -1158,3 +1158,4 @@ vi:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 241f29c0c4332b589f74e19d46c1d6a9d1171d39..636351bf95cd83ae4c672eaca1d9e196c4114e9e 100644 (file)
   description_date_from: 輸入起始日期
   description_date_to: 輸入結束日期
   text_repository_identifier_info: '僅允許使用小寫英文字母 (a-z), 阿拉伯數字, 虛線與底線。<br />一旦儲存之後, 代碼便無法再次被更改。'
+  label_link_values_to: Link values to URL
index 51f757ab3f8c60ca58a9fc925a51134f68136e6e..a3b8ef1d66e3ca9cb1a1219d420a3167ebb7afab 100644 (file)
@@ -1106,3 +1106,4 @@ zh:
   label_only: only
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
+  label_link_values_to: Link values to URL
index 799fcf610453309ae151f66acba711137e4fe6dc..d0e2e4d7cd56452de9c3a94550726025aef91234 100644 (file)
@@ -80,6 +80,8 @@ module Redmine
         CustomField.store_accessor :format_store, *args
       end
 
+      field_attributes :url_pattern
+
       def name
         self.class.format_name
       end
@@ -144,9 +146,45 @@ module Redmine
       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
@@ -236,8 +274,14 @@ module Redmine
       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
@@ -280,23 +324,11 @@ module Redmine
       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
index 738b273029e8fb9f94c4533bbcf40ef45c124657..187895ebe5c27c23bb0b66415b84938e26b1ba3d 100644 (file)
@@ -116,6 +116,27 @@ class Redmine::ListFieldFormatTest < ActionView::TestCase
     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')