From: Jean-Philippe Lang Date: Fri, 16 Jan 2009 21:02:03 +0000 (+0000) Subject: Use a textarea for custom fields possible values (#2472). X-Git-Tag: 0.9.0~799 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a276926f420d0369a3f9d0fe69e972d07ef74363;p=redmine.git Use a textarea for custom fields possible values (#2472). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2267 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 79d12376a..f277dc349 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -41,8 +41,6 @@ class CustomField < ActiveRecord::Base end def before_validation - # remove empty values - self.possible_values = self.possible_values.collect{|v| v unless v.empty?}.compact # make sure these fields are not searchable self.searchable = false if %w(int float date bool).include?(field_format) true @@ -60,6 +58,15 @@ class CustomField < ActiveRecord::Base errors.add(:default_value, :activerecord_error_invalid) unless v.valid? end + # Makes possible_values accept a multiline string + def possible_values=(arg) + if arg.is_a?(Array) + write_attribute(:possible_values, arg.compact.collect(&:strip).select {|v| !v.blank?}) + else + self.possible_values = arg.to_s.split(/[\n\r]+/) + end + end + # Returns a ORDER BY clause that can used to sort customized # objects by their value of the custom field. # Returns false, if the custom field can not be used for sorting. diff --git a/app/views/custom_fields/_form.rhtml b/app/views/custom_fields/_form.rhtml index f4aee6870..43ed5feb9 100644 --- a/app/views/custom_fields/_form.rhtml +++ b/app/views/custom_fields/_form.rhtml @@ -49,23 +49,6 @@ function toggle_custom_field_format() { } } -function addValueField() { - var f = $$('p#custom_field_possible_values span'); - p = document.getElementById("custom_field_possible_values"); - var v = f[0].cloneNode(true); - v.childNodes[0].value = ""; - p.appendChild(v); -} - -function deleteValueField(e) { - var f = $$('p#custom_field_possible_values span'); - if (f.length == 1) { - e.parentNode.childNodes[0].value = ""; - } else { - Element.remove(e.parentNode); - } -} - //]]> @@ -76,11 +59,10 @@ function deleteValueField(e) { <%= f.text_field :min_length, :size => 5, :no_label => true %> - <%= f.text_field :max_length, :size => 5, :no_label => true %>
(<%=l(:text_min_max_length_info)%>)

<%= f.text_field :regexp, :size => 50 %>
(<%=l(:text_regexp_info)%>)

-

-<% (@custom_field.possible_values.to_a + [""]).each do |value| %> -<%= text_field_tag 'custom_field[possible_values][]', value, :size => 30 %> <%= image_to_function "delete.png", "deleteValueField(this);return false" %>
-<% end %> -

+

<%= f.text_area :possible_values, :value => @custom_field.possible_values.to_a.join("\n"), + :cols => 20, + :rows => 15 %> +
<%= l(:text_custom_field_possible_values_info) %>

<%= @custom_field.field_format == 'bool' ? f.check_box(:default_value) : f.text_field(:default_value) %>

diff --git a/lang/bg.yml b/lang/bg.yml index 61f75209d..c73752bd2 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -699,3 +699,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/ca.yml b/lang/ca.yml index 0ce265f9f..6585617c2 100644 --- a/lang/ca.yml +++ b/lang/ca.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/cs.yml b/lang/cs.yml index 534da679a..9e34ab9d5 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -704,3 +704,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/da.yml b/lang/da.yml index 2edbc5243..e447d4c7a 100644 --- a/lang/da.yml +++ b/lang/da.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/de.yml b/lang/de.yml index c403b4817..a0098a120 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -701,3 +701,4 @@ enumeration_activities: Aktivitäten (Zeiterfassung) text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/en.yml b/lang/en.yml index 01ac078cf..7ea1b150b 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -676,6 +676,7 @@ text_enumeration_category_reassign_to: 'Reassign them to this value:' text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." text_repository_usernames_mapping: "Select or update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped." text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.' +text_custom_field_possible_values_info: 'One line for each value' default_role_manager: Manager default_role_developper: Developer diff --git a/lang/es.yml b/lang/es.yml index 1729292e7..36b1f4686 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -684,3 +684,4 @@ text_workflow_edit: Seleccionar un flujo de trabajo para actualizar text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/fi.yml b/lang/fi.yml index 244f858eb..2bae1f84d 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -699,3 +699,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/fr.yml b/lang/fr.yml index 374a0d868..6465f9bd4 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -676,6 +676,7 @@ text_enumeration_category_reassign_to: 'Réaffecter les objets à cette valeur:' text_email_delivery_not_configured: "L'envoi de mail n'est pas configuré, les notifications sont désactivées.\nConfigurez votre serveur SMTP dans config/email.yml et redémarrez l'application pour les activer." text_repository_usernames_mapping: "Vous pouvez sélectionner ou modifier l'utilisateur Redmine associé à chaque nom d'utilisateur figurant dans l'historique du dépôt.\nLes utilisateurs avec le même identifiant ou la même adresse mail seront automatiquement associés." text_diff_truncated: '... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.' +text_custom_field_possible_values_info: 'Une ligne par valeur' default_role_manager: Manager default_role_developper: Développeur diff --git a/lang/he.yml b/lang/he.yml index b10b73296..f2bdd9217 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -699,3 +699,4 @@ text_plugin_assets_writable: Plugin assets directory writable text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.' warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/hu.yml b/lang/hu.yml index 059b3ee68..be6bb0eb0 100644 --- a/lang/hu.yml +++ b/lang/hu.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: A megjelenítendő sorok száma (maximum) a di text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/it.yml b/lang/it.yml index f3798b477..85c8c6ae3 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -699,3 +699,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/ja.yml b/lang/ja.yml index c1279b3f9..b215c0118 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/ko.yml b/lang/ko.yml index f7958f97b..285646761 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -699,3 +699,4 @@ setting_diff_max_lines_displayed: 차이점보기에 표시할 최대 줄수 text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/lt.yml b/lang/lt.yml index 3cdbcf09c..8f530e5eb 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -701,3 +701,4 @@ enumeration_activities: Veiklos (laiko sekimas) text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/nl.yml b/lang/nl.yml index ed10b4db6..b61829bb7 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -701,3 +701,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/no.yml b/lang/no.yml index c8f131ff9..3689d8df1 100644 --- a/lang/no.yml +++ b/lang/no.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/pl.yml b/lang/pl.yml index 6b28f0e0d..98b2197d4 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -718,3 +718,4 @@ setting_diff_max_lines_displayed: Maksymalna liczba linii różnicy do pokazania text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/pt-br.yml b/lang/pt-br.yml index ecbbc0ce5..846b4d93e 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/pt.yml b/lang/pt.yml index ec42386de..6ed741584 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -701,3 +701,4 @@ setting_diff_max_lines_displayed: Número máximo de linhas de diff mostradas text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/ro.yml b/lang/ro.yml index b0df48d26..6799b4f1b 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -699,3 +699,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/ru.yml b/lang/ru.yml index 4943eea0f..6bfc64b62 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -733,3 +733,4 @@ text_workflow_edit: Выберите роль и трекер для редак text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/sk.yml b/lang/sk.yml index ffae2d644..4d4d49e80 100644 --- a/lang/sk.yml +++ b/lang/sk.yml @@ -705,3 +705,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/sr.yml b/lang/sr.yml index 7070c4a22..c045d5540 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/sv.yml b/lang/sv.yml index 852c7fe50..a7262356a 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -700,3 +700,4 @@ enumeration_activities: Aktiviteter (tidsuppföljning) text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/th.yml b/lang/th.yml index c0a38592b..0e6e3646c 100644 --- a/lang/th.yml +++ b/lang/th.yml @@ -702,3 +702,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/tr.yml b/lang/tr.yml index 81363678c..fe214049d 100644 --- a/lang/tr.yml +++ b/lang/tr.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/uk.yml b/lang/uk.yml index be121cb5c..55d642b31 100644 --- a/lang/uk.yml +++ b/lang/uk.yml @@ -701,3 +701,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/vn.yml b/lang/vn.yml index 908e2326d..15b62e1d3 100644 --- a/lang/vn.yml +++ b/lang/vn.yml @@ -702,3 +702,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml index 50eccf434..6f6740b75 100644 --- a/lang/zh-tw.yml +++ b/lang/zh-tw.yml @@ -701,3 +701,4 @@ enumeration_activities: 活動 (時間追蹤) text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/zh.yml b/lang/zh.yml index 989f329c6..cceaff0f9 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -701,3 +701,4 @@ enumeration_activities: 活动(时间跟踪) text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb index 1b9c9aea9..2f17d99cf 100644 --- a/test/unit/custom_field_test.rb +++ b/test/unit/custom_field_test.rb @@ -25,6 +25,24 @@ class CustomFieldTest < Test::Unit::TestCase assert field.save end + def test_possible_values_should_accept_an_array + field = CustomField.new + field.possible_values = ["One value", ""] + assert_equal ["One value"], field.possible_values + end + + def test_possible_values_should_accept_a_string + field = CustomField.new + field.possible_values = "One value" + assert_equal ["One value"], field.possible_values + end + + def test_possible_values_should_accept_a_multiline_string + field = CustomField.new + field.possible_values = "One value\nAnd another one \r\n \n" + assert_equal ["One value", "And another one"], field.possible_values + end + def test_destroy field = CustomField.find(1) assert field.destroy